summaryrefslogtreecommitdiff
path: root/include/widgets.h
blob: 600bcecd1e8a6b53ad354895d2997908683a500a (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*
 *  mogltk
 *  Copyright (C) 1999-2004 Nicolas "Pixel" Noble
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* $Id: widgets.h,v 1.7 2004-10-19 01:27:29 pixel Exp $ */

#ifndef __WIDGETS_H__
#define __WIDGETS_H__

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

namespace mogltk {
    enum event_t {
        E_TIMER,
        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_OUT,
        E_MOUSE_DOWN,
        E_MOUSE_UP,
        E_MOUSE_CLICK,
        E_MOUSE_OUT_CLICK,
        E_MOUSE_DBL_CLICK,
    };
    class widget : public Base {
      public:
	  virtual ~widget();
        virtual void move(int x, int y);
	virtual void resize(int sx, int sy);
	int GetX();
	int GetY();
	int GetH();
	int GetW();
	int GetAX();
	int GetAY();
	int GetAX2();
	int GetAY2();
        virtual mogltk::rect GetDrawRect();
        widget * Father();
        widget * Child();
        widget * Next();
        widget * Prev();
        widget * InnerPanel();
	virtual widget * find_widget(int x, int y);
	void fulldraw();
	shape * Shaper();
        void mainloop();
        void m_event(int x, int y, event_t event);
        bool inside(int x, int y);
        bool GetVisible();
        virtual void SetVisible(bool);
        bool GetEnabled();
        virtual void SetEnabled(bool);
        void MoveOnTop();
        static void check_timed_events();
      protected:
          widget(widget * father, int x, int y, int sx, int sy, int type, String name, shape *);
        virtual void draw();
        virtual bool process_event(int x, int y, event_t event);
        virtual void resize_notify();
        virtual widget * create_panel();
        void set_exclusive(widget *);
        void unset_exclusive(widget *);
        void add_out_move();
        void remove_out_move();
        void add_out_click();
        void remove_out_click();
        void set_timed_event(Uint32);
        void set_absolute_timed_event(Uint32);
        String caption;
      private:
        int x, y, sx, sy, ax, ay, ax2, ay2;
	widget * father, * next, * prev, * child, * last, * root, * panel;
	static widget * focused;
	int type;
	String name;
	shape * sh;
        widget * exclusive;
        bool visible;
        bool enabled;
        class timed_event {
          public:
              timed_event(widget * _w, Uint32 _t) : w(_w), t(_t) { }
            widget * w;
            Uint32 t;
        };
        static std::vector<timed_event> timed_events;

        void computeabs();
        void idraw();
        bool ievent(int x, int y, event_t event);
        void icomputeabs();
        void iresize_notify();
    };

    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 Panel : public widget {
          public:
              Panel(shape *, widget * father, int x, int y, int w, int h);
        };

        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);
            virtual rect GetDrawRect();
          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();
        };

        class Frame : public widget {
          public:
              Frame(shape *, widget * father, int x, int y, int w, int h);
            virtual rect GetDrawRect();
          protected:
            virtual void draw();
        };

        class ContextMenu : public widget {
          public:
              ContextMenu(shape *, widget * father, int x, int y);
              virtual ~ContextMenu();
            void addnode(const String &, action *);
            void addline();
            void addsub(const String &, ContextMenu *);
            ContextMenu * createsub(const String &);
            virtual void move(int x, int y);
            virtual void resize(int w, int h);
            virtual void SetVisible(bool);
            virtual void SetEnabled(int i, bool);
            void StickyDisplay();
          protected:
            virtual void draw();
            virtual bool process_event(int x, int y, event_t event);
            class node : public Base {
              public:
                  node(const String &, int x, int y, int w, int h, action * = 0, ContextMenu * sub = 0, ContextMenu * father = 0, bool = false);
                String GetCaption();
                action * GetAction();
                ContextMenu * GetSub();
                ContextMenu * GetFather();
                bool GetLine();
                bool GetEnabled();
                void SetEnabled(bool);
                int GetX();
                int GetY();
                int GetW();
                int GetH();
              private:
                String caption;
                int x, y, w, h;
                action * a;
                ContextMenu * sub, * father;
                bool line, enabled;
            };

            std::vector<node> nodes;
            int selected;
            ContextMenu * subselected;
          private:
            bool in_click, sticky;

            bool iin_click();
        };

        class Menu : public widget {
          public:
              Menu(shape *, widget * father);
            void addnode(const String &, action *);
            void addsub(const String &, ContextMenu * sub);
            ContextMenu * createsub(const String &);
            virtual void SetEnabled(int i, bool);
            void SetCaption(int i, const String &);
          protected:
            virtual void resize_notify();
            virtual void draw();
            virtual bool process_event(int, int, event_t);
            class node : public Base {
              public:
                  node(const String & caption, ContextMenu * sub, action * a, int x);
                String GetCaption();
                void SetCaption(const String &);
                ContextMenu * GetSub();
                action * GetAction();
                int GetX();
                bool GetEnabled();
                void SetEnabled(bool);
              private:
                String caption;
                ContextMenu * sub;
                action * a;
                int x;
                bool enabled;
            };
          private:
            std::vector<node> nodes;
            int cur_x;
            int selected;
        };
    };
};

#endif