]> icculus.org git repositories - dana/openbox.git/blob - otk/widget.hh
8bpp pseudo color. it's horrid code. the graphics are horrid.
[dana/openbox.git] / 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 private:
105   void internal_moveresize(int x, int y, int w, int h);
106
107   int _screen;
108   Widget *_parent;
109   Window _window;
110   Surface *_surface;
111   long _event_mask;
112   
113   RenderStyle::Justify _alignment;
114   Direction _direction;
115   Rect _area;
116   //! This size is the size *inside* the border, so they won't match the
117   //! actual size of the widget
118   Size _min_size;
119   //! This size is the size *inside* the border, so they won't match the
120   //! actual size of the widget 
121   Size _max_size;
122
123   bool _visible;
124   
125   const RenderColor *_bordercolor;
126   int _borderwidth;
127   int _bevel;
128   bool _dirty;
129
130   std::list<Widget*> _children;
131
132   EventDispatcher *_dispatcher;
133
134   int _ignore_config;
135 };
136
137 }
138
139 #endif // __widget_hh