"Fossies" - the Fresh Open Source Software Archive

Member "gambas-3.16.3/gb.gtk/src/gcontrol.h" (7 Sep 2021, 12586 Bytes) of package /linux/misc/gambas-3.16.3.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "gcontrol.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.16.2_vs_3.16.3.

    1 /***************************************************************************
    2 
    3   gcontrol.h
    4 
    5   (c) 2000-2017 BenoƮt Minisini <g4mba5@gmail.com>
    6 
    7   This program is free software; you can redistribute it and/or modify
    8   it under the terms of the GNU General Public License as published by
    9   the Free Software Foundation; either version 2, or (at your option)
   10   any later version.
   11 
   12   This program is distributed in the hope that it will be useful,
   13   but WITHOUT ANY WARRANTY; without even the implied warranty of
   14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15   GNU General Public License for more details.
   16 
   17   You should have received a copy of the GNU General Public License
   18   along with this program; if not, write to the Free Software
   19   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
   20   MA 02110-1301, USA.
   21 
   22 ***************************************************************************/
   23 
   24 #ifndef __GCONTROL_H
   25 #define __GCONTROL_H
   26 
   27 #include "gcolor.h"
   28 #include "gdrag.h"
   29 
   30 class gContainer;
   31 class gMainWindow;
   32 
   33 #ifdef GTK3
   34 void gt_patch_control(GtkWidget *widget);
   35 #endif
   36 
   37 class gControl
   38 {
   39 public:
   40     gControl();
   41     gControl(gContainer *parent);
   42     virtual ~gControl();
   43 
   44     void *hFree;
   45 
   46     bool isContainer() const { return _is_container; }
   47     bool isWindow() const { return _is_window; }
   48     bool isButton() const { return _is_button; }
   49     bool isDrawingArea() const { return _is_drawingarea; }
   50     bool isTopLevel() const { return pr == NULL; }
   51     bool isDestroyed() const { return _destroyed; }
   52     
   53     gMainWindow *window() const;
   54     gMainWindow *topLevel() const;
   55     
   56     gContainer *parent() const { return pr; }
   57     bool isAncestorOf(gControl *child);
   58 
   59     bool isDesign() const { return _design && !_no_design; }
   60     bool isDesignIgnore() const { return _design_ignore; }
   61 
   62     bool hovered();
   63     virtual long handle();
   64     
   65     int left() const { return bufX; }
   66     int x() const { return left(); }
   67     int top() const { return bufY; }
   68     int y() const { return top(); }
   69     int width() const { return bufW; }
   70     int height() const { return bufH; }
   71     void setLeft(int v) { move(v, y()); }
   72     void setTop(int v) { move(x(), v); }
   73     void setWidth(int w) { resize(w, height()); }
   74     void setHeight(int h) { resize(width(), h); }
   75     virtual void move(int x, int y);
   76     virtual bool resize(int w, int h, bool no_decide = false);
   77     void resize() { resize(width(), height()); }
   78     void moveResize(int x, int y, int w, int h, bool no_decide = false);
   79     void getGeometry(GdkRectangle *rect) const { rect->x = bufX; rect->y = bufY; rect->width = bufW; rect->height = bufH; }
   80     void setGeometry(GdkRectangle *rect) { moveResize(rect->x, rect->y, rect->width, rect->height); }
   81 
   82     bool isVisible() const { return _visible; }
   83     bool isReallyVisible();
   84     virtual void setVisible(bool v);
   85     void hide() { setVisible(false); }
   86     void show() { setVisible(true); }
   87 
   88     void setVisibility(bool v);
   89     void checkVisibility();
   90     
   91     virtual bool isEnabled() const;
   92     virtual void setEnabled(bool vl);
   93 
   94     int mouse();
   95     void setMouse(int m);
   96     gCursor* cursor();
   97     void setCursor(gCursor *vl);
   98     virtual void updateCursor(GdkCursor *cursor);
   99     
  100     gControl *next();
  101     gControl *previous();
  102     gControl *nextFocus();
  103     gControl *previousFocus();
  104     void setPrevious(gControl *prev);
  105     void setNext(gControl *next);
  106     
  107     int screenX();
  108     int screenY();
  109     virtual bool getScreenPos(int *x, int *y);
  110     
  111     bool isExpand() const { return _expand; }
  112     bool isIgnore() const { return _ignore; }
  113     void setExpand (bool vl);
  114     void setIgnore (bool vl);
  115 
  116     bool acceptDrops() const { return _accept_drops; }
  117     void setAcceptDrops(bool vl);
  118     
  119     const char *name() const { return _name; }
  120     void setName(char *name);
  121     
  122     bool action() const { return _action; }
  123     void setAction(bool v) { _action = v; }
  124 
  125     virtual void setDesign(bool ignore = false);
  126     gControl *ignoreDesign();
  127     void updateDesign();
  128     
  129     char *tooltip() { return _tooltip; }
  130     void setTooltip(char *vl);
  131 
  132     bool isTracking() const;
  133     void setTracking(bool vl);
  134     
  135     bool isNoTabFocus() const;
  136     void setNoTabFocus(bool v);
  137 
  138     gColor background() const { return _bg; }
  139     gColor foreground() const { return _fg; }
  140     virtual void setBackground(gColor color = COLOR_DEFAULT);
  141     virtual void setForeground(gColor color = COLOR_DEFAULT);
  142     virtual gColor defaultBackground() const;
  143     gColor realBackground(bool no_default = false);
  144     gColor realForeground(bool no_default = false);
  145     virtual void setRealBackground(gColor color);
  146     virtual void setRealForeground(gColor color);
  147 
  148     virtual gFont *font() const;
  149     void actualFontTo(gFont *ft);
  150     virtual void setFont(gFont *ft);
  151     bool ownFont() { return _font != NULL; }
  152     virtual void updateFont();
  153     virtual void updateSize();
  154     
  155     bool hasNativePopup() const { return _has_native_popup; }
  156     
  157 #ifdef GTK3
  158     void setWidgetName();
  159     virtual GtkWidget *getStyleSheetWidget();
  160     virtual const char *getStyleSheetColorNode();
  161     virtual const char *getStyleSheetFontNode();
  162     void updateStyleSheet(bool dirty);
  163     virtual void customStyleSheet(GString *css);
  164     void setStyleSheetNode(GString *css, const char *node);
  165     virtual void updateColor();
  166 #else
  167     void setColorNames(const char **, const char **) {}
  168 #endif
  169     void setColorBase() { use_base = TRUE; }
  170     void setColorButton() { use_base = FALSE; }
  171 
  172     virtual bool canFocus() const;
  173     bool canFocusOnClick() const;
  174     void setCanFocus(bool vl);
  175 
  176     bool eatReturnKey() const { return _eat_return_key; }
  177     
  178     gControl *proxy() const { return _proxy; }
  179     bool setProxy(gControl *proxy);
  180 
  181     int scrollX();
  182     int scrollY();
  183     void scroll(int x, int y);
  184     void setScrollX(int vl);
  185     void setScrollY(int vl);
  186 
  187     int scrollBar() const { return _scrollbar; }
  188     void setScrollBar(int vl);
  189     virtual void updateScrollBar();
  190     
  191     bool isDragging() const { return _dragging; }
  192     
  193     void dragText(char *txt, char *format = NULL) { gDrag::dragText(this, txt, format); }
  194     void dragImage(gPicture *pic) { gDrag::dragImage(this, pic); }
  195     
  196     virtual void reparent(gContainer *newpr, int x, int y);
  197 
  198     void lower() { restack(false); }
  199     void raise() { restack(true); }
  200     virtual void restack(bool raise);
  201 
  202     virtual void setFocus();
  203     bool hasFocus() const;
  204 #if GTK_CHECK_VERSION(3, 2, 0)
  205     bool hasVisibleFocus() const;
  206 #else
  207     bool hasVisibleFocus() const { return hasFocus(); }
  208 #endif
  209 
  210     void refresh();
  211     void refresh(int x, int y, int w, int h);
  212     virtual void afterRefresh();
  213     
  214     bool grab();
  215     
  216     virtual void destroy();
  217     void destroyNow() { destroy(); postDelete(); }
  218     
  219     void lock() { _locked++; }
  220     void unlock() { _locked--; }
  221     bool locked() const { return _locked; }
  222     
  223     void emit(void *signal);
  224     void emit(void *signal, intptr_t arg);
  225     void emit(void *signal, char *arg) { emit(signal, (intptr_t)arg); }
  226 
  227 // "Signals"
  228     bool (*canRaise)(gControl *sender, int type);
  229     void (*onFinish)(gControl *sender); // Special
  230     void (*onFocusEvent)(gControl *sender, int type);
  231     bool (*onKeyEvent)(gControl *sender, int type);
  232     bool (*onMouseEvent)(gControl *sender, int type);
  233     void (*onEnterLeave)(gControl *sender, int type);
  234     bool (*onDrag)(gControl *sender);
  235     bool (*onDragMove)(gControl *sender);
  236     bool (*onDrop)(gControl *sender);
  237     void (*onDragLeave)(gControl *sender);
  238     //void (*onMove)(gControl *sender);
  239     //void (*onResize)(gControl *sender);
  240 
  241 // "Private"
  242     gint bufW,bufH,bufX,bufY;
  243     int _min_w, _min_h;
  244     gCursor *curs;
  245     gFont *_font;
  246     gFont *_resolved_font;
  247     GtkWidget *widget;
  248     GtkWidget *border;
  249     GtkWidget *frame;
  250     GtkScrolledWindow *_scroll;
  251     short _mouse;
  252     gControl *_proxy, *_proxy_for;
  253     gColor _bg, _fg;
  254     char *_tooltip;
  255 #ifdef GTK3
  256     GtkStyleProvider *_css;
  257     const char *_css_node;
  258 #endif
  259     
  260     unsigned _destroyed : 1;               // If the control has already been added to the destroy list
  261     unsigned _design : 1;
  262     unsigned _design_ignore : 1;
  263     unsigned _no_design : 1;
  264     unsigned _expand : 1;
  265     unsigned _ignore : 1;
  266     unsigned _action : 1;                  // *reserved*
  267     unsigned _inverted : 1;                // if the widget direction has been inverted
  268 
  269     unsigned _accept_drops : 1;            // If the control accepts drops
  270     unsigned _dragging : 1;                // if the control is being dragged
  271     unsigned _drag_get_data : 1;           // If we got information on the dragged data
  272     unsigned _tracking : 1;                // If we are tracking mouse move even if no mouse button is pressed
  273     unsigned _old_tracking : 1;            // real value when Tracking is false
  274     unsigned _bg_set : 1;                  // Have a private background
  275     unsigned _fg_set : 1;                  // Have a private foreground
  276     unsigned have_cursor : 1;              // If gApplication::setBusy() must update the cursor
  277 
  278     unsigned use_base : 1;                 // Use base and text color for foreground and background
  279     unsigned _visible : 1;                 // A control can be hidden if its width or height is zero
  280     unsigned _no_delete : 1;               // Do not delete on destroy signal
  281     unsigned _scrollbar : 2;
  282     unsigned _dirty_pos : 1;               // If the position of the widget has changed
  283     unsigned _dirty_size : 1;              // If the size of the widget has changed
  284     unsigned _inside : 1;                  // if we got an enter event, but not a leave event yet.
  285     
  286     unsigned _locked : 4;                  // For locking events
  287     unsigned frame_border : 4;
  288     
  289     unsigned frame_padding : 8;
  290 
  291     unsigned _has_input_method : 1;        // Has its own input method management
  292     unsigned _no_default_mouse_event : 1;  // No default mouse events
  293     unsigned _grab : 1;                    // control is currently grabbing mouse and keyboard
  294     unsigned _has_border : 1;              // if the control has a border
  295     unsigned _no_tab_focus : 1;            // Don't put inside focus chain
  296     unsigned _no_auto_grab : 1;            // do not automatically grab widget on button press event
  297     unsigned _no_background : 1;           // Don't draw the background automatically
  298     unsigned _use_wheel : 1;               // Do not propagate the mouse wheel event
  299 
  300     unsigned _is_container : 1;            // I am a container
  301     unsigned _is_window : 1;               // I am a window
  302     unsigned _is_button : 1;               // I am a button
  303     unsigned _is_drawingarea : 1;          // I am a drawing area
  304     unsigned _has_native_popup : 1;        // I have a native popup menu
  305     unsigned _eat_return_key : 1;          // If the control eats the return key
  306     unsigned _minimum_size_set : 1;        // If minimum size has been computed
  307     unsigned _hidden_temp : 1;             // Temporarily hidden (must not raise watchers)
  308     unsigned _allow_show : 1;              // Allowed to be visible (after the first resize)
  309     
  310 #ifdef GTK3
  311     unsigned _style_dirty : 1;             // If the style must be refreshed
  312     unsigned _no_style_without_child : 1;  // For containers that do not need a css if they have no children
  313     unsigned _has_css_id : 1;              // If the widget has a css id
  314 #endif
  315     
  316   void removeParent() { pr = NULL; }
  317     void initSignals();
  318     void borderSignals();
  319     void widgetSignals();
  320     void connectParent();
  321     void setParent(gContainer *parent) { pr = parent; }
  322     void initAll(gContainer *pr);
  323     void realize(bool draw_frame = false);
  324     void realizeScrolledWindow(GtkWidget *wid, bool doNotRealize = false);
  325     void registerControl();
  326     void updateGeometry(bool force = false);
  327     bool mustUpdateCursor() { return mouse() != -1 || have_cursor || !parent(); }
  328     
  329     bool hasInputMethod() { return _has_input_method; }
  330     virtual GtkIMContext *getInputMethod();
  331     
  332     GdkCursor *getGdkCursor();
  333     virtual void updateBorder();
  334     int getFrameBorder() const { return frame_border; }
  335     void setFrameBorder(int border);
  336     virtual void setBorder(bool b);
  337     bool hasBorder() const;
  338     int getFramePadding() const { return frame_padding; }
  339     void setFramePadding(int padding);
  340     virtual int getFrameWidth() const;
  341     virtual gColor getFrameColor();
  342 #ifdef GTK3
  343     void drawBorder(cairo_t *cr);
  344     void drawBackground(cairo_t *cr);
  345 #else
  346     void drawBorder(GdkEventExpose *e);
  347     void drawBackground(GdkEventExpose *e);
  348 #endif
  349     
  350     void createBorder(GtkWidget *new_border, bool keep_widget = false);
  351     void createWidget();
  352     virtual void connectBorder();
  353     
  354     int minimumWidth() const { return _min_w; }
  355     int minimumHeight() const { return _min_h; }
  356     virtual void setMinimumSize();
  357 
  358     void resolveFont();
  359 
  360     void emitEnterEvent(bool no_leave = false);
  361     void emitLeaveEvent();
  362 #ifdef GTK3
  363     virtual void onEnterEvent();
  364     virtual void onLeaveEvent();
  365 #endif
  366     
  367     virtual bool setInverted(bool v);
  368     bool isInverted() const { return _inverted; }
  369     
  370     void hideButKeepFocus();
  371     void showButKeepFocus();
  372     bool isTempHidden() const { return _hidden_temp; }
  373     
  374     static void postDelete();
  375 
  376 private:
  377     
  378     gContainer *pr;
  379     char *_name;
  380     GtkIMContext *_input_method;
  381     
  382     void dispose(); 
  383 };
  384 
  385 #define SIGNAL(_signal) ((void *)_signal)
  386 
  387 #endif