]> Dogcows Code - chaz/openbox/blob - otk/widget.hh
change the default titlebar layout
[chaz/openbox] / otk / widget.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef __widget_hh
3 #define __widget_hh
4
5 #include "eventhandler.hh"
6 #include "rect.hh"
7 #include "renderstyle.hh"
8
9 #include <list>
10 #include <algorithm>
11 #include <cassert>
12
13 namespace otk {
14
15 class Surface;
16 class RenderTexture;
17 class RenderColor;
18 class EventDispatcher;
19
20 class Widget : public EventHandler, public StyleNotify {
21 public:
22 enum Direction { Horizontal, Vertical };
23
24 Widget(int screen, EventDispatcher *ed, Direction direction = Horizontal,
25 int bevel = 3, bool overrideredir = false);
26 Widget(Widget *parent, Direction direction = Horizontal, int bevel = 3);
27 virtual ~Widget();
28
29 inline int screen() const { return _screen; }
30 inline Window window() const { return _window; }
31 inline Widget *parent() const { return _parent; }
32 inline Direction direction() const { return _direction; }
33
34 inline RenderStyle::Justify alignment() const { return _alignment; }
35 void setAlignment(RenderStyle::Justify a);
36
37 inline long eventMask() const { return _event_mask; }
38 virtual void setEventMask(long e);
39
40 inline const Rect& area() const { return _area; }
41 inline Rect usableArea() const { return Rect(_area.position(),
42 Size(_area.width() -
43 _borderwidth * 2,
44 _area.height() -
45 _borderwidth * 2));}
46 inline const Size& minSize() const { return _min_size; }
47 inline const Size& maxSize() const { return _max_size; }
48 virtual void setMaxSize(const Size &s);
49
50 virtual void show(bool children = false);
51 virtual void hide();
52 inline bool visible() const { return _visible; }
53
54 virtual void update();
55 virtual void refresh() { _dirty = true; render(); }
56
57 virtual void setBevel(int b);
58 inline int bevel() const { return _bevel; }
59
60 void move(const Point &p)
61 { moveresize(Rect(p, _area.size())); }
62 void resize(const Size &s)
63 { moveresize(Rect(_area.position(), s)); }
64 /*!
65 When a widget has a parent, this won't change the widget directly, but will
66 just cause the parent to re-layout all its children.
67 */
68 virtual void moveresize(const Rect &r);
69
70 inline const RenderColor *borderColor() const { return _bordercolor; }
71 virtual void setBorderColor(const RenderColor *c);
72
73 inline int borderWidth() const { return _borderwidth; }
74 virtual void setBorderWidth(int w);
75
76 const std::list<Widget*>& children() const { return _children; }
77
78 virtual void exposeHandler(const XExposeEvent &e);
79 virtual void configureHandler(const XConfigureEvent &e);
80 virtual void styleChanged(const RenderStyle &style);
81
82 protected:
83 virtual void addChild(Widget *w) { assert(w); _children.push_back(w); }
84 virtual void removeChild(Widget *w) { assert(w); _children.remove(w); }
85
86 //! Find the default min/max sizes for the widget. Useful after the in-use
87 //! style has changed.
88 virtual void calcDefaultSizes();
89
90 virtual void setMinSize(const Size &s);
91
92 //! Arrange the widget's children
93 virtual void layout();
94 virtual void layoutHorz();
95 virtual void layoutVert();
96 virtual void render();
97 virtual void renderForeground(Surface&) {};
98 virtual void renderChildren();
99
100 void createWindow(bool overrideredir);
101
102 RenderTexture *_texture;
103
104 EventDispatcher *dispatcher() const { return _dispatcher; }
105
106 private:
107 void internal_moveresize(int x, int y, int w, int h);
108
109 int _screen;
110 Widget *_parent;
111 Window _window;
112 Surface *_surface;
113 long _event_mask;
114
115 RenderStyle::Justify _alignment;
116 Direction _direction;
117 Rect _area;
118 //! This size is the size *inside* the border, so they won't match the
119 //! actual size of the widget
120 Size _min_size;
121 //! This size is the size *inside* the border, so they won't match the
122 //! actual size of the widget
123 Size _max_size;
124
125 bool _visible;
126
127 const RenderColor *_bordercolor;
128 int _borderwidth;
129 int _bevel;
130 bool _dirty;
131
132 std::list<Widget*> _children;
133
134 EventDispatcher *_dispatcher;
135
136 int _ignore_config;
137 };
138
139 }
140
141 #endif // __widget_hh
This page took 0.042368 seconds and 4 git commands to generate.