Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

/otk/widget.hh

Go to the documentation of this file.
00001 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
00002 #ifndef __widget_hh
00003 #define __widget_hh
00004 
00005 #include "rect.hh"
00006 #include "point.hh"
00007 #include "rendertexture.hh"
00008 #include "renderstyle.hh"
00009 #include "eventdispatcher.hh"
00010 #include "display.hh"
00011 #include "surface.hh"
00012 
00013 extern "C" {
00014 #include <assert.h>
00015 }
00016 
00017 #include <string>
00018 #include <list>
00019 
00020 namespace otk {
00021 
00022 class Widget : public EventHandler {
00023 
00024 public:
00025 
00026   enum Direction { Horizontal, Vertical };
00027 
00028   typedef std::list<Widget *> WidgetList;
00029 
00030   Widget(Widget *parent, Direction = Horizontal);
00031   Widget(EventDispatcher *event_dispatcher, RenderStyle *style,
00032          Direction direction = Horizontal, Cursor cursor = 0,
00033          int bevel_width = 1, bool override_redirect = false);
00034 
00035   virtual ~Widget();
00036 
00037   virtual void update();
00038 
00039   void exposeHandler(const XExposeEvent &e);
00040   void configureHandler(const XConfigureEvent &e);
00041 
00042   inline Window window(void) const { return _window; }
00043   inline const Widget *parent(void) const { return _parent; }
00044   inline const WidgetList &children(void) const { return _children; }
00045   inline unsigned int screen(void) const { return _screen; }
00046   inline const Rect &rect(void) const { return _rect; }
00047 
00048   void move(const Point &to);
00049   void move(int x, int y);
00050 
00051   virtual void setWidth(int);
00052   virtual void setHeight(int);
00053 
00054   virtual int width() const { return _rect.width(); }
00055   virtual int height() const { return _rect.height(); }
00056 
00057   virtual void resize(const Point &to);
00058   virtual void resize(int x, int y);
00059 
00060   virtual void setGeometry(const Rect &new_geom);
00061   virtual void setGeometry(const Point &topleft, int width, int height);
00062   virtual void setGeometry(int x, int y, int width, int height);
00063 
00064   inline bool isVisible(void) const { return _visible; };
00065   virtual void show(bool recursive = false);
00066   virtual void hide(bool recursive = false);
00067 
00068   inline bool isFocused(void) const { return _focused; };
00069   virtual void focus(void);
00070   virtual void unfocus(void);
00071 
00072   inline bool hasGrabbedMouse(void) const { return _grabbed_mouse; }
00073   bool grabMouse(void);
00074   void ungrabMouse(void);
00075 
00076   inline bool hasGrabbedKeyboard(void) const { return _grabbed_keyboard; }
00077   bool grabKeyboard(void);
00078   void ungrabKeyboard(void);
00079 
00080   inline RenderTexture *texture(void) const { return _texture; }
00081   virtual void setTexture(RenderTexture *texture)
00082     { _texture = texture; _dirty = true; }
00083 
00084   inline const RenderColor *borderColor(void) const { return _bcolor; }
00085   virtual void setBorderColor(const RenderColor *color) {
00086     assert(color); _bcolor = color;
00087     XSetWindowBorder(**display, _window, color->pixel());
00088   }
00089 
00090   inline int borderWidth(void) const { return _bwidth; }
00091   void setBorderWidth(int width) {
00092     _bwidth = width;
00093     XSetWindowBorderWidth(**display, _window, width);
00094   }
00095 
00096   virtual void addChild(Widget *child, bool front = false);
00097   virtual void removeChild(Widget *child);
00098 
00099   inline bool isStretchableHorz(void) const { return _stretchable_horz; }
00100   void setStretchableHorz(bool s_horz = true) { _stretchable_horz = s_horz; }
00101 
00102   inline bool isStretchableVert(void) const { return _stretchable_vert; }
00103   void setStretchableVert(bool s_vert = true)  { _stretchable_vert = s_vert; }
00104 
00105   inline Cursor cursor(void) const { return _cursor; }
00106   void setCursor(Cursor cursor) {
00107     _cursor = cursor;
00108     XDefineCursor(**display, _window, _cursor);
00109   }
00110 
00111   inline int bevelWidth(void) const { return _bevel_width; }
00112   void setBevelWidth(int bevel_width)
00113     { assert(bevel_width > 0); _bevel_width = bevel_width; }
00114 
00115   inline Direction direction(void) const { return _direction; }
00116   void setDirection(Direction dir) { _direction = dir; }
00117 
00118   inline RenderStyle *style(void) const { return _style; }
00119   virtual void setStyle(RenderStyle *style);
00120 
00121   inline EventDispatcher *eventDispatcher(void)
00122     { return _event_dispatcher; }
00123   void setEventDispatcher(EventDispatcher *disp);
00124 
00125 protected:
00126   
00127   bool _dirty;
00128   bool _focused;
00129 
00130   virtual void adjust(void);
00131   virtual void create(bool override_redirect = false);
00132   virtual void adjustHorz(void);
00133   virtual void adjustVert(void);
00134   virtual void internalResize(int width, int height);
00135   virtual void render(void);
00136   virtual void renderForeground() {} // for overriding
00137 
00138   Window _window;
00139 
00140   Widget *_parent;
00141   WidgetList _children;
00142 
00143   RenderStyle *_style;
00144   Direction _direction;
00145   Cursor _cursor;
00146   int _bevel_width;
00147   int _ignore_config;
00148 
00149   bool _visible;
00150 
00151   bool _grabbed_mouse;
00152   bool _grabbed_keyboard;
00153 
00154   bool _stretchable_vert;
00155   bool _stretchable_horz;
00156 
00157   RenderTexture *_texture;
00158   Pixmap _bg_pixmap;
00159   unsigned int _bg_pixel;
00160 
00161   const RenderColor *_bcolor;
00162   unsigned int _bwidth;
00163 
00164   Rect _rect;
00165   unsigned int _screen;
00166 
00167   bool _fixed_width;
00168   bool _fixed_height;
00169 
00170   Surface *_surface;
00171 
00172   EventDispatcher *_event_dispatcher;
00173 };
00174 
00175 }
00176 
00177 #endif // __widget_hh

Generated on Tue Feb 4 22:58:57 2003 for Openbox by doxygen1.3-rc2