summaryrefslogtreecommitdiffhomepage
path: root/nGenEx/ActiveWindow.h
blob: b08cd266fafd4939d2fab55d60bd9220326bfa5e (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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*  Project nGenEx
	Destroyer Studios LLC
	Copyright © 1997-2004. All Rights Reserved.

	SUBSYSTEM:    nGenEx.lib
	FILE:         ActiveWindow.h
	AUTHOR:       John DiCamillo


	OVERVIEW
	========
	Active Window class (a window that knows how to draw itself)
*/

#ifndef ActiveWindow_h
#define ActiveWindow_h

#include <vector>
#include "Types.h"
#include "Color.h"
#include "Geometry.h"
#include "Bitmap.h"
#include "Window.h"
#include "EventTarget.h"
#include "List.h"
#include "Text.h"

// +--------------------------------------------------------------------+

struct Poly;
struct Material;
struct VertexSet;
class  Layout;

// +--------------------------------------------------------------------+

enum {
	WIN_NO_FRAME      = 0x0000,
	WIN_BLACK_FRAME   = 0x0001,
	WIN_WHITE_FRAME   = 0x0002,
	WIN_THIN_FRAME    = 0x0004,
	WIN_THICK_FRAME   = 0x0008,
	WIN_RAISED_FRAME  = 0x0010,
	WIN_SUNK_FRAME    = 0x0020,
	WIN_TEXT_SHADOW   = 0x0040,
	WIN_FRAME_ONLY    = 0x0080
};

enum {
	EID_CREATE,
	EID_DESTROY,
	EID_MOUSE_MOVE,
	EID_CLICK,
	EID_SELECT,
	EID_LBUTTON_DOWN,
	EID_LBUTTON_UP,
	EID_RBUTTON_DOWN,
	EID_RBUTTON_UP,
	EID_KEY_DOWN,
	EID_SET_FOCUS,
	EID_KILL_FOCUS,
	EID_MOUSE_ENTER,
	EID_MOUSE_EXIT,
	EID_MOUSE_WHEEL,
	EID_DRAG_START,
	EID_DRAG_DROP,

	EID_USER_1,
	EID_USER_2,
	EID_USER_3,
	EID_USER_4,

	EID_NUM_EVENTS
};

// +--------------------------------------------------------------------+

class ActiveWindow;

struct AWEvent
{
	static const char* TYPENAME() { return "AWEvent"; }

	AWEvent() : window(0), eid(0), x(0), y(0) { }
	AWEvent(ActiveWindow* w, int e, int ax=0, int ay=0) : window(w), eid(e), x(ax), y(ay) { }

	int operator == (const AWEvent& e) const { return (window == e.window) &&
		(eid    == e.eid)    &&
		(x      == e.x)      &&
		(y      == e.y); }

	ActiveWindow*  window;
	int            eid;
	int            x;
	int            y;
};

typedef void (*PFVAWE)(ActiveWindow*, AWEvent*);

struct AWMap
{
	static const char* TYPENAME() { return "AWMap"; }

	AWMap() : eid(0), client(0), func(0) { }
	AWMap(int e, ActiveWindow* w, PFVAWE f) : eid(e), client(w), func(f) { }

	int operator == (const AWMap& m) const { return (eid    == m.eid) &&
		(client == m.client); }

	int            eid;
	ActiveWindow*  client;
	PFVAWE         func;
};

// +--------------------------------------------------------------------+

class ActiveWindow : public Window,
public EventTarget
{
public:
	static const char* TYPENAME() { return "ActiveWindow"; }

	ActiveWindow(Screen* s, int ax, int ay, int aw, int ah,
	DWORD id=0, DWORD style=0, ActiveWindow* parent=0);
	virtual ~ActiveWindow();

	int operator == (const ActiveWindow& w) const { return id == w.id; }

	// Operations:
	virtual void      Paint();    // blt to screen
	virtual void      Draw();     // refresh backing store
	virtual void      Show();
	virtual void      Hide();
	virtual void      MoveTo(const Rect& r);
	virtual void      UseLayout(const std::vector<DWORD>& min_x,
		const std::vector<DWORD>& min_y,
		const std::vector<float>& weight_x,
		const std::vector<float>& weight_y);
	virtual void      UseLayout(const std::vector<float>& min_x,
		const std::vector<float>& min_y,
		const std::vector<float>& weight_x,
		const std::vector<float>& weight_y);
	virtual void      UseLayout(int     ncols,
		int     nrows,
		int*    min_x,
		int*    min_y,
		float*  weight_x,
		float*  weight_y);
	virtual void      DoLayout();

	// Event Target Interface:
	virtual int       OnMouseMove(int x, int y);
	virtual int       OnLButtonDown(int x, int y);
	virtual int       OnLButtonUp(int x, int y);
	virtual int       OnClick();
	virtual int       OnSelect();
	virtual int       OnRButtonDown(int x, int y);
	virtual int       OnRButtonUp(int x, int y);
	virtual int       OnMouseEnter(int x, int y);
	virtual int       OnMouseExit(int x, int y);
	virtual int       OnMouseWheel(int wheel);

	virtual int       OnKeyDown(int vk, int flags);

	virtual const char* GetDescription() const { return desc; }

	// pseudo-events:
	virtual int       OnDragStart(int x, int y);
	virtual int       OnDragDrop(int x, int y, ActiveWindow* source);

	virtual ActiveWindow*   FindControl(int x, int y) { return 0; }
	virtual Rect      TargetRect() const;

	virtual ActiveWindow* GetCapture();
	virtual int       SetCapture();
	virtual int       ReleaseCapture();

	// Property accessors:
	virtual void      SetFocus();
	virtual void      KillFocus();
	virtual bool      HasFocus() const { return focus; }

	void              SetEnabled(bool e=true) { enabled = e;        }
	bool              IsEnabled() const       { return enabled;     }
	bool              IsVisible() const       { return shown;       }

	DWORD             GetID() const           { return id;          }
	void              SetStyle(DWORD s)       { style = s;          }
	DWORD             GetStyle() const        { return style;       }

	void              SetText(const char* t);
	void              SetText(const Text& t);
	void              AddText(const char* t);
	void              AddText(const Text& t);
	const Text&       GetText() const         { return text;        }

	void              SetAltText(const char* t) { alt_text = t;     }
	void              SetAltText(const Text& t) { alt_text = t;     }
	const Text&       GetAltText() const      { return alt_text;    }

	void              SetTexture(Bitmap* bmp) { texture = bmp;      }
	Bitmap*           GetTexture()            { return texture;     }
	void              SetMargins(const Insets& m);
	Insets&           GetMargins()            { return margins;     }
	void              SetTextInsets(const Insets& t);
	Insets&           GetTextInsets()         { return text_insets; }

	List<ActiveWindow>& GetChildren()         { return children;    }
	void              SetCellInsets(const Insets& c);
	Insets&           GetCellInsets()         { return cell_insets; }
	void              SetCells(int cx, int cy, int cw=1, int ch=1);
	void              SetCells(const Rect& r) { cells = r;          }
	Rect&             GetCells()              { return cells;       }
	void              SetFixedWidth(int w)    { fixed_width = w;    }
	int               GetFixedWidth()  const  { return fixed_width; }
	void              SetFixedHeight(int h)   { fixed_height = h;   }
	int               GetFixedHeight() const  { return fixed_height;}

	void              SetAlpha(double a);
	double            GetAlpha()        const { return alpha;       }
	void              SetBackColor(Color c)   { back_color = c;     }
	Color             GetBackColor()    const { return back_color;  }
	void              SetBaseColor(Color c)   { base_color = c;     }
	Color             GetBaseColor()    const { return base_color;  }
	void              SetForeColor(Color c)   { fore_color = c;     }
	Color             GetForeColor()    const { return fore_color;  }
	void              SetSingleLine(bool a)   { single_line = a;    }
	bool              GetSingleLine()   const { return single_line; }
	void              SetTextAlign(DWORD a);
	DWORD             GetTextAlign()    const { return text_align;  }
	void              SetTransparent(bool t)  { transparent = t;    }
	bool              GetTransparent()  const { return transparent; }
	void              SetHidePartial(bool a)  { hide_partial = a;   }
	bool              GetHidePartial()  const { return hide_partial;}

	void              SetTabStop(int n, int x);
	int               GetTabStop(int n) const;

	void              DrawText(const char* txt, int count, Rect& txt_rect, DWORD flags);

	// class properties:
	static void       SetSystemFont(Font* f);
	static void       SetSystemBackColor(Color c);
	static void       SetSystemForeColor(Color c);

	// callback function registration:
	virtual void      RegisterClient(int EID, ActiveWindow* client, PFVAWE callback);
	virtual void      UnregisterClient(int EID, ActiveWindow* client);
	virtual void      ClientEvent(int EID, int x=0, int y=0);

	// form context:
	virtual ActiveWindow*   GetForm()                  { return form; }
	virtual void            SetForm(ActiveWindow* f)   { form = f;    }
	virtual bool            IsFormActive()       const;
	virtual bool            IsTopMost()          const { return topmost; }
	virtual void            SetTopMost(bool t)         { topmost = t;    }

	virtual ActiveWindow*   FindChild(DWORD id);
	virtual ActiveWindow*   FindChild(int x, int y);

protected:
	virtual Color     ShadeColor(Color c, double shade);
	virtual void      AddChild(ActiveWindow* child);
	virtual void      DrawStyleRect(const Rect& r, int style);
	virtual void      DrawStyleRect(int x1, int y1, int x2, int y2, int style);
	virtual void      DrawTabbedText();
	virtual void      DrawTextureGrid();
	virtual void      CalcGrid();

	DWORD             id;
	DWORD             style;
	DWORD             text_align;
	bool              single_line;
	bool              focus;
	bool              enabled;
	bool              hide_partial;
	float             alpha;
	Color             back_color;
	Color             base_color;
	Color             fore_color;
	Text              text;
	Text              alt_text;
	Text              desc;
	Bitmap*           texture;
	Insets            margins;
	Insets            text_insets;
	Insets            cell_insets;
	Rect              cells;
	int               fixed_width;
	int               fixed_height;
	int               tab[10];

	ActiveWindow*     parent;
	ActiveWindow*     form;
	bool              transparent;
	bool              topmost;

	Layout*              layout;
	List<ActiveWindow>   children;
	List<AWMap>          clients;
	AWEvent              event;

	int               rows;
	int               cols;
	Poly*             polys;
	VertexSet*        vset;
	Material*         mtl;

	static Font*      sys_font;
	static Color      sys_back_color;
	static Color      sys_fore_color;
};

#define DEF_MAP_CLIENT(cname, fname)\
	void Map##cname##fname(ActiveWindow* client, AWEvent* event) \
	{ cname* c = (cname*) client; c->fname(event); }

#define REGISTER_CLIENT(eid, ctrl, cname, fname)\
	if (ctrl) ctrl->RegisterClient(eid, this, Map##cname##fname);

#define UNREGISTER_CLIENT(eid, ctrl, cname)\
	if (ctrl) ctrl->UnregisterClient(eid, this);

#endif ActiveWindow_h