summaryrefslogtreecommitdiff
path: root/otk/basewidget.hh
blob: 4dfc28fdd43270a0d52ac8cd2c2c25fba5b4c95b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef __basewidget_hh
#define __basewidget_hh

#include "rect.hh"
#include "point.hh"
#include "texture.hh"
#include "style.hh"
#include "display.hh"
#include "eventdispatcher.hh"

extern "C" {
#include <assert.h>
}

#include <list>

namespace otk {

class OtkBaseWidget : public OtkEventHandler {

public:

  typedef std::list<OtkBaseWidget *> OtkBaseWidgetList;

  OtkBaseWidget(OtkBaseWidget *parent);
  OtkBaseWidget(Style *style, Cursor cursor = 0, int bevel_width = 1);

  virtual ~OtkBaseWidget();

  //! Redraw the widget and all of its children
  virtual void update(void);

  void exposeHandler(const XExposeEvent &e);
  void configureHandler(const XConfigureEvent &e);

  inline Window getWindow(void) const { return _window; }
  inline const OtkBaseWidget *getParent(void) const { return _parent; }
  inline const OtkBaseWidgetList &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(bool recursive = false);
  virtual void hide(bool recursive = false);

  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(OtkBaseWidget *child, bool front = false);
  virtual void removeChild(OtkBaseWidget *child);

  inline Cursor getCursor(void) const { return _cursor; }
  void setCursor(Cursor cursor) {
    _cursor = cursor;
    XDefineCursor(OBDisplay::display, _window, _cursor);
  }

  inline int getBevelWidth(void) const { return _bevel_width; }
  void setBevelWidth(int bevel_width)
  { assert(bevel_width > 0); _bevel_width = bevel_width; }

  inline Style *getStyle(void) const { return _style; }
  virtual void setStyle(Style *style);

protected:

  //! If the widget needs to redraw itself. Watched by all subclasses too!
  bool _dirty;

  Window _window;

  OtkBaseWidget *_parent;
  OtkBaseWidgetList _children;

  Style *_style;
  Cursor _cursor;
  int _bevel_width;
  int _ignore_config;

  bool _visible;
  bool _focused;

  bool _grabbed_mouse;
  bool _grabbed_keyboard;

  BTexture *_texture;
  Pixmap _bg_pixmap;
  unsigned int _bg_pixel;

  Rect _rect;
  unsigned int _screen;

private:

  void create(void);
  void render(void);
};

}

#endif // __basewidget_hh