]> Dogcows Code - chaz/openbox/blobdiff - otk/widget.hh
add a struct for pixmap masks
[chaz/openbox] / otk / widget.hh
index 473aa812588568d093cadffe8fd21fd6f8ab356d..07b6c0845ba1d38039bfa6acab9d6641eb6e0466 100644 (file)
+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
 #ifndef __widget_hh
 #define __widget_hh
 
-#include <string>
-#include <list>
-
-#include "rect.hh"
-#include "point.hh"
-#include "texture.hh"
-#include "style.hh"
 #include "eventhandler.hh"
-#include "application.hh"
+#include "rect.hh"
+#include "renderstyle.hh"
+
+#include <list>
+#include <algorithm>
+#include <cassert>
 
 namespace otk {
 
-class OtkWidget : public OtkEventHandler {
+class Surface;
+class RenderTexture;
+class RenderColor;
+class EventDispatcher;
 
+class Widget : public EventHandler, public StyleNotify {
 public:
-
   enum Direction { Horizontal, Vertical };
 
-  typedef std::list<OtkWidget *> OtkWidgetList;
-
-  OtkWidget(OtkWidget *parent, Direction = Horizontal);
-  OtkWidget(OtkApplication *app, Direction direction = Horizontal,
-            Cursor cursor = 0, int bevel_width = 1);
-  OtkWidget(Style *style, Direction direction = Horizontal,
-            Cursor cursor = 0, int bevel_width = 1);
-
-  virtual ~OtkWidget();
-
-  virtual void update(void);
-
-  int exposeHandler(const XExposeEvent &e);
-  int configureHandler(const XConfigureEvent &e);
-
-  inline Window getWindow(void) const { return _window; }
-  inline const OtkWidget *getParent(void) const { return _parent; }
-  inline const OtkWidgetList &getChildren(void) const { return _children; }
-  inline unsigned int getScreen(void) const { return _screen; }
-  inline const Rect &getRect(void) const { return _rect; }
-
-  void move(const Point &to);
-  void move(int x, int y);
-
-  virtual void setWidth(int);
-  virtual void setHeight(int);
-
-  virtual int width() const { return _rect.width(); }
-  virtual int height() const { return _rect.height(); }
-
-  virtual void resize(const Point &to);
-  virtual void resize(int x, int y);
-
-  virtual void setGeometry(const Rect &new_geom);
-  virtual void setGeometry(const Point &topleft, int width, int height);
-  virtual void setGeometry(int x, int y, int width, int height);
-
-  inline bool isVisible(void) const { return _visible; };
-  virtual void show(void);
-  virtual void hide(void);
-
-  inline bool isFocused(void) const { return _focused; };
-  virtual void focus(void);
-
-  inline bool hasGrabbedMouse(void) const { return _grabbed_mouse; }
-  bool grabMouse(void);
-  void ungrabMouse(void);
-
-  inline bool hasGrabbedKeyboard(void) const { return _grabbed_keyboard; }
-  bool grabKeyboard(void);
-  void ungrabKeyboard(void);
-
-  inline BTexture *getTexture(void) const { return _texture; }
-  virtual void setTexture(BTexture *texture)
-  { _texture = texture; _dirty = true; }
-
-  virtual void addChild(OtkWidget *child, bool front = false);
-  virtual void removeChild(OtkWidget *child);
-
-  inline bool isStretchableHorz(void) const { return _stretchable_horz; }
-  void setStretchableHorz(bool s_horz) { _stretchable_horz = s_horz; }
-
-  inline bool isStretchableVert(void) const { return _stretchable_vert; }
-  void setStretchableVert(bool s_vert)  { _stretchable_vert = s_vert; }
-
-  inline Cursor getCursor(void) const { return _cursor; }
-
-  inline int getBevelWidth(void) const { return _bevel_width; }
-  void setBevelWidth(int bevel_width)
-  { assert(bevel_width > 0); _bevel_width = bevel_width; }
-
-  inline Direction getDirection(void) const { return _direction; }
-  void setDirection(Direction dir) { _direction = dir; }
-
-  inline Style *getStyle(void) const { return _style; }
-  void setStyle(Style *style) { _style = style; }
-
+  Widget(int screen, EventDispatcher *ed, Direction direction = Horizontal,
+         int bevel = 3, bool overrideredir = false);
+  Widget(Widget *parent, Direction direction = Horizontal, int bevel = 3);
+  virtual ~Widget();
+
+  inline int screen() const { return _screen; }
+  inline Window window() const { return _window; }
+  inline Widget *parent() const { return _parent; }
+  inline Direction direction() const { return _direction; }
+
+  inline RenderStyle::Justify alignment() const { return _alignment; }
+  void setAlignment(RenderStyle::Justify a);
+
+  inline long eventMask() const { return _event_mask; }
+  virtual void setEventMask(long e);
+  
+  inline const Rect& area() const { return _area; }
+  inline Rect usableArea() const { return Rect(_area.position(),
+                                               Size(_area.width() -
+                                                    _borderwidth * 2,
+                                                    _area.height() -
+                                                    _borderwidth * 2));}
+  inline const Size& minSize() const { return _min_size; }
+  inline const Size& maxSize() const { return _max_size; }
+  virtual void setMaxSize(const Size &s);
+
+  virtual void show(bool children = false);
+  virtual void hide();
+  inline bool visible() const { return _visible; }
+
+  virtual void update();
+  virtual void refresh() { if (_visible) { _dirty = true; render(); } }
+  
+  virtual void setBevel(int b);
+  inline int bevel() const { return _bevel; }
+
+  void move(const Point &p)
+    { moveresize(Rect(p, _area.size())); }
+  void resize(const Size &s)
+    { moveresize(Rect(_area.position(), s)); }
+  /*!
+    When a widget has a parent, this won't change the widget directly, but will
+    just cause the parent to re-layout all its children.
+  */
+  virtual void moveresize(const Rect &r);
+
+  inline const RenderColor *borderColor() const { return _bordercolor; }
+  virtual void setBorderColor(const RenderColor *c);
+
+  inline int borderWidth() const { return _borderwidth; }
+  virtual void setBorderWidth(int w);
+
+  const std::list<Widget*>& children() const { return _children; }
+
+  virtual void exposeHandler(const XExposeEvent &e);
+  virtual void configureHandler(const XConfigureEvent &e);
+  virtual void styleChanged(const RenderStyle &style);
+
+protected:
+  virtual void addChild(Widget *w) { assert(w); _children.push_back(w); }
+  virtual void removeChild(Widget *w) { assert(w); _children.remove(w); }
+
+  //! Find the default min/max sizes for the widget. Useful after the in-use
+  //! style has changed.
+  virtual void calcDefaultSizes();
+
+  virtual void setMinSize(const Size &s);
+
+  //! Arrange the widget's children
+  virtual void layout();
+  virtual void layoutHorz();
+  virtual void layoutVert();
+  virtual void render();
+  virtual void renderForeground(Surface&) {};
+  virtual void renderChildren();
+
+  void createWindow(bool overrideredir);
+
+  RenderTexture *_texture;
+
+  EventDispatcher *dispatcher() const { return _dispatcher; }
+  
 private:
+  void internal_moveresize(int x, int y, int w, int h);
 
-  void create(void);
-  void adjust(void);
-  void adjustHorz(void);
-  void adjustVert(void);
-  void internalResize(int width, int height);
-  void render(void);
-
+  int _screen;
+  Widget *_parent;
   Window _window;
-
-  OtkWidget *_parent;
-  OtkWidgetList _children;
-
-  Style *_style;
+  Surface *_surface;
+  long _event_mask;
+  
+  RenderStyle::Justify _alignment;
   Direction _direction;
-  Cursor _cursor;
-  int _bevel_width;
-  int _ignore_config;
+  Rect _area;
+  //! This size is the size *inside* the border, so they won't match the
+  //! actual size of the widget
+  Size _min_size;
+  //! This size is the size *inside* the border, so they won't match the
+  //! actual size of the widget 
+  Size _max_size;
 
   bool _visible;
-  bool _focused;
-
-  bool _grabbed_mouse;
-  bool _grabbed_keyboard;
-
-  bool _stretchable_vert;
-  bool _stretchable_horz;
-
-  BTexture *_texture;
-  Pixmap _bg_pixmap;
-  unsigned int _bg_pixel;
+  
+  const RenderColor *_bordercolor;
+  int _borderwidth;
+  int _bevel;
+  bool _dirty;
 
-  Rect _rect;
-  unsigned int _screen;
+  std::list<Widget*> _children;
 
-  bool _fixed_width;
-  bool _fixed_height;
+  EventDispatcher *_dispatcher;
 
-  bool _dirty;
+  int _ignore_config;
 };
 
 }
This page took 0.024475 seconds and 4 git commands to generate.