]> icculus.org git repositories - mikachu/openbox.git/blob - otk/widget.hh
resizes
[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   virtual bool expose(const XExposeEvent &e);
31   virtual bool configure(const XConfigureEvent &e);
32
33   inline Window getWindow(void) const { return _window; }
34   inline const OtkWidget *getParent(void) const { return _parent; }
35   inline const OtkWidgetList &getChildren(void) const { return _children; }
36   inline unsigned int getScreen(void) const { return _screen; }
37   inline const Rect &getRect(void) const { return _rect; }
38
39   void move(const Point &to);
40   void move(int x, int y);
41
42   virtual void setWidth(int);
43   virtual void setHeight(int);
44
45   virtual int width() const { return _rect.width(); }
46   virtual int height() const { return _rect.height(); }
47
48   virtual void resize(const Point &to);
49   virtual void resize(int x, int y);
50
51   virtual void setGeometry(const Rect &new_geom);
52   virtual void setGeometry(const Point &topleft, int width, int height);
53   virtual void setGeometry(int x, int y, int width, int height);
54
55   inline bool isVisible(void) const { return _visible; };
56   virtual void show(void);
57   virtual void hide(void);
58
59   inline bool isFocused(void) const { return _focused; };
60   virtual void focus(void);
61
62   inline bool hasGrabbedMouse(void) const { return _grabbed_mouse; }
63   bool grabMouse(void);
64   void ungrabMouse(void);
65
66   inline bool hasGrabbedKeyboard(void) const { return _grabbed_keyboard; }
67   bool grabKeyboard(void);
68   void ungrabKeyboard(void);
69
70   inline BTexture *getTexture(void) const { return _texture; }
71   virtual void setTexture(BTexture *texture)
72   { _texture = texture; _dirty = true; }
73
74   virtual void addChild(OtkWidget *child, bool front = false);
75   virtual void removeChild(OtkWidget *child);
76
77   inline bool isStretchableHorz(void) const { return _stretchable_horz; }
78   void setStretchableHorz(bool s_horz) { _stretchable_horz = s_horz; }
79
80   inline bool isStretchableVert(void) const { return _stretchable_vert; }
81   void setStretchableVert(bool s_vert)  { _stretchable_vert = s_vert; }
82
83   inline Cursor getCursor(void) const { return _cursor; }
84
85   inline int getBevelWidth(void) const { return _bevel_width; }
86   void setBevelWidth(int bevel_width)
87   { assert(bevel_width > 0); _bevel_width = bevel_width; }
88
89   inline Direction getDirection(void) const { return _direction; }
90   void setDirection(Direction dir) { _direction = dir; }
91
92   inline Style *getStyle(void) const { return _style; }
93   void setStyle(Style *style) { _style = style; }
94
95 private:
96
97   void create(void);
98   void adjust(void);
99   void adjustHorz(void);
100   void adjustVert(void);
101   void internalResize(int width, int height);
102   void render(void);
103
104   Window _window;
105
106   OtkWidget *_parent;
107   OtkWidgetList _children;
108
109   Style *_style;
110   Direction _direction;
111   Cursor _cursor;
112   int _bevel_width;
113   int _ignore_config;
114
115   bool _visible;
116   bool _focused;
117
118   bool _grabbed_mouse;
119   bool _grabbed_keyboard;
120
121   bool _stretchable_vert;
122   bool _stretchable_horz;
123
124   BTexture *_texture;
125   Pixmap _bg_pixmap;
126   unsigned int _bg_pixel;
127
128   Rect _rect;
129   unsigned int _screen;
130
131   bool _fixed_width;
132   bool _fixed_height;
133
134   bool _dirty;
135 };
136
137 }
138
139 #endif // __widget_hh