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