summaryrefslogtreecommitdiff
path: root/include/widgets.h
blob: 116eef5fa1b30e35a6801508b7fdaad98ebff5cf (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
#ifndef __WIDGETS_H__
#define __WIDGETS_H__

#include <Exceptions.h>
#include <shape.h>

namespace mogltk {
    enum event_t {
        E_MOUSE_START_DRAG,
        E_MOUSE_DRAG,
        E_MOUSE_DRAG_OVER,
        E_MOUSE_END_DRAG,
        E_MOUSE_END_DRAG_OVER,
        E_MOUSE_MOVE,
        E_MOUSE_DOWN,
        E_MOUSE_UP,
        E_MOUSE_CLICK,
        E_MOUSE_DBL_CLICK,
    };
    class widget : public Base {
      public:
	  virtual ~widget();
        void move(int x, int y);
	void resize(int sx, int sy);
	int GetX();
	int GetY();
	int GetH();
	int GetW();
	int GetAX();
	int GetAY();
	int GetAX2();
	int GetAY2();
        widget * Father();
        widget * Child();
        widget * Next();
        widget * Prev();
	void fulldraw();
	shape * Shaper();
        void mainloop();
        void m_event(int x, int y, event_t event);
        bool inside(int x, int y);
      protected:
          widget(widget * father, int x, int y, int sx, int sy, int type, String name, shape *);
        virtual void draw();
        String caption;
        virtual bool process_event(int x, int y, event_t event);
        void set_exclusive(widget *);
        void unset_exclusive(widget *);
      private:
        void computeabs();
        int x, y, sx, sy, ax, ay, ax2, ay2;
	widget * father, * next, * prev, * child, * root;
	static widget * focused;
	int type;
	String name;
	shape * sh;
        widget * exclusive;
	void idraw();
        bool ievent(int x, int y, event_t event);
        void icomputeabs();
    };

    namespace widgets {
        class drawer : public Base {
          public:
            virtual void draw(widget *) = 0;
        };

        class action : public Base {
          public:
            virtual void do_action(widget *) = 0;
        };

        class Root : public widget {
          public:
	      Root(shape *, drawer * = 0);
            void setdrawer(drawer *);
          protected:
            virtual void draw();
	    drawer * dr;
        };

        class Button : public widget {
          public:
              Button(action *, shape *, widget * father, int x, int y, int w, int h, const String & caption);
          protected:
            virtual void draw();
            virtual bool process_event(int, int, event_t);
            bool bevel;
          private:
            bool dragging;
            action * a;
        };

        class Label : public widget {
          public:
              Label(shape *, widget * father, int x, int y, int w, int h, const String & caption, const ColorP & color = BLACK);
          protected:
            virtual void draw();
          private:
            ColorP color;
        };

        class SmartBox : public widget {
          public:
              SmartBox(shape *, widget * father, int x, int y, int w, int h, const String & caption);
          protected:
            virtual void draw();
            virtual bool process_event(int, int, event_t);
          private:
            int ox, oy, oax, oay;
        };

        class MsgBox : public SmartBox {
          public:
              MsgBox(shape *, widget * father, const String & caption, const String & text);
              virtual ~MsgBox();
        };
    };
};

#endif