]> icculus.org git repositories - mikachu/openbox.git/blob - otk/widget.hh
more deps
[mikachu/openbox.git] / otk / widget.hh
1 #ifndef __focus_hh
2 #define __focus_hh
3
4 #include <string>
5 #include <list>
6
7 #include "rect.hh"
8 #include "point.hh"
9 #include "texture.hh"
10 #include "style.hh"
11
12 namespace otk {
13
14 class OtkWidget {
15
16 public:
17
18   enum Direction { Horizontal, Vertical };
19
20   typedef std::list<OtkWidget *> OtkWidgetList;
21
22   OtkWidget(OtkWidget *parent, Direction = Horizontal);
23   OtkWidget(Style *style, Direction direction = Horizontal,
24             Cursor cursor = 0, int bevel_width = 1);
25
26   virtual ~OtkWidget();
27
28   virtual void update(void);
29
30   inline Window getWindow(void) const { return _window; }
31   inline const OtkWidget *getParent(void) const { return _parent; }
32   inline const OtkWidgetList &getChildren(void) const { return _children; }
33   inline unsigned int getScreen(void) const { return _screen; }
34   inline const Rect &getRect(void) const { return _rect; }
35
36   void move(const Point &to);
37   void move(int x, int y);
38
39   virtual void setWidth(int);
40   virtual void setHeight(int);
41
42   virtual void resize(const Point &to);
43   virtual void resize(int x, int y);
44
45   virtual void setGeometry(const Rect &new_geom);
46   virtual void setGeometry(const Point &topleft, int width, int height);
47   virtual void setGeometry(int x, int y, int width, int height);
48
49   inline bool isVisible(void) const { return _visible; };
50   virtual void show(void);
51   virtual void hide(void);
52
53   inline bool isFocused(void) const { return _focused; };
54   virtual void focus(void);
55
56   inline bool hasGrabbedMouse(void) const { return _grabbed_mouse; }
57   bool grabMouse(void);
58   void ungrabMouse(void);
59
60   inline bool hasGrabbedKeyboard(void) const { return _grabbed_keyboard; }
61   bool grabKeyboard(void);
62   void ungrabKeyboard(void);
63
64   inline BTexture *getTexture(void) const { return _texture; }
65   virtual void setTexture(BTexture *texture)
66   { _texture = texture; _dirty = true; }
67
68   virtual void addChild(OtkWidget *child, bool front = false);
69   virtual void removeChild(OtkWidget *child);
70
71   inline bool isStretchableHorz(void) const { return _stretchable_horz; }
72   void setStretchableHorz(bool s_horz) { _stretchable_horz = s_horz; }
73
74   inline bool isStretchableVert(void) const { return _stretchable_vert; }
75   void setStretchableVert(bool s_vert)  { _stretchable_vert = s_vert; }
76
77   inline Cursor getCursor(void) const { return _cursor; }
78
79   inline int getBevelWidth(void) const { return _bevel_width; }
80   void setBevelWidth(int bevel_width)
81   { assert(bevel_width > 0); _bevel_width = bevel_width; }
82
83   inline Direction getDirection(void) const { return _direction; }
84   void setDirection(Direction dir) { _direction = dir; }
85
86   inline Style *getStyle(void) const { return _style; }
87   void setStyle(Style *style) { _style = style; }
88
89 private:
90
91   void create(void);
92   void adjust(void);
93   void adjustHorz(void);
94   void adjustVert(void);
95   void internalResize(int width, int height);
96   void render(void);
97
98   Window _window;
99
100   OtkWidget *_parent;
101   OtkWidgetList _children;
102
103   Style *_style;
104   Direction _direction;
105   Cursor _cursor;
106   int _bevel_width;
107
108   bool _visible;
109   bool _focused;
110
111   bool _grabbed_mouse;
112   bool _grabbed_keyboard;
113
114   bool _stretchable_vert;
115   bool _stretchable_horz;
116
117   BTexture *_texture;
118   Pixmap _bg_pixmap;
119   unsigned int _bg_pixel;
120
121   Rect _rect;
122   unsigned int _screen;
123
124   bool _fixed_width;
125   bool _fixed_height;
126
127   bool _dirty;
128 };
129
130 }
131
132 #endif // __widget_hh