Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/vaclgui/dspar.hpp @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, A System for Syntax Directed Programming | |
3 * Copyright 1997-2002 Parsifal Software. All Rights Reserved. | |
4 * See the file COPYING for license and usage terms. | |
5 * | |
6 * dspar.hpp | |
7 */ | |
8 | |
9 #ifndef DSPAR_HPP | |
10 #define DSPAR_HPP | |
11 | |
12 #include <icolor.hpp> | |
13 #include <iedithdr.hpp> | |
14 #include <ifont.hpp> | |
15 //#include <ifonthdr.hpp> | |
16 #include <imcelcv.hpp> | |
17 //#include <ipainevt.hpp> | |
18 #include <ipainhdr.hpp> | |
19 #include <ipushbut.hpp> | |
20 #include <isetcv.hpp> | |
21 #include <ispinhdr.hpp> | |
22 #include <ispinnum.hpp> | |
23 #include <istattxt.hpp> | |
24 //#include <iwindow.hpp> | |
25 | |
26 class AgCharStack; // from agcstack.h | |
27 class AgString; // from agstring.h | |
28 struct cint; // from cint.h | |
29 #include "action.h" | |
30 #include "agnotify.h" | |
31 #include "agstack.h" | |
32 #include "frame.hpp" | |
33 #include "base.h" | |
34 | |
35 struct ColorPair { | |
36 IColor fg; | |
37 IColor bg; | |
38 ColorPair() : fg(0, 0, 0), bg(255, 255, 255) {} | |
39 ColorPair(IColor fg_, IColor bg_) : fg(fg_), bg(bg_) {} | |
40 AgString string(); | |
41 void setValue(char *s); | |
42 }; | |
43 | |
44 struct ColorSpec : public AgNotifier<ColorPair> { | |
45 ColorPair defaultValue; | |
46 ColorSpec(IColor fg, IColor bg) | |
47 : AgNotifier<ColorPair>(ColorPair(fg, bg)) | |
48 , defaultValue(fg, bg) | |
49 {} | |
50 ColorSpec(const ColorSpec &s) | |
51 : AgNotifier<ColorPair>(s.contents) | |
52 , defaultValue(s.defaultValue) | |
53 {} | |
54 | |
55 void set(ColorPair &p) { contents = p; } | |
56 ColorPair &operator = (const ColorPair &p) { | |
57 contents = p; | |
58 notify(); | |
59 return contents; | |
60 } | |
61 | |
62 AgString string() { return contents.string(); } | |
63 | |
64 IColor &fg() { return contents.fg; } | |
65 IColor &bg() { return contents.bg; } | |
66 int reset(); | |
67 | |
68 | |
69 static ColorSpec defaultSetting; | |
70 static ColorSpec dialogBackground; | |
71 | |
72 | |
73 static ColorSpec syntaxFile; | |
74 static ColorSpec traceFileHilite; | |
75 static ColorSpec traceFileScanned; | |
76 static ColorSpec traceFileUnscanned; | |
77 | |
78 static ColorSpec columnHead; | |
79 | |
80 static ColorSpec activeTitle; | |
81 static ColorSpec inactiveTitle; | |
82 static ColorSpec data; | |
83 | |
84 static ColorSpec activeCursor; | |
85 static ColorSpec inactiveCursor; | |
86 | |
87 static ColorSpec helpText; | |
88 static ColorSpec helpLink; | |
89 static ColorSpec helpUsedLink; | |
90 }; | |
91 | |
92 //typedef AgNotifier<IFont> AgNotifierFont; | |
93 | |
94 struct FontSpec : public AgNotifier<IFont> { | |
95 private: | |
96 IFont defaultFont; | |
97 void initItalic() { | |
98 contents.setItalic(); | |
99 defaultFont.setItalic(); | |
100 } | |
101 | |
102 public: | |
103 enum Style { | |
104 normal = 0, italic = 1, | |
105 bold = 2, boldItalic = 3, | |
106 underscore = 4, strikeout = 8 | |
107 }; | |
108 | |
109 void setStyle(Style style) { | |
110 if (style & italic) { | |
111 contents.setItalic(); | |
112 defaultFont.setItalic(); | |
113 } | |
114 if (style & bold) { | |
115 contents.setBold(); | |
116 defaultFont.setBold(); | |
117 } | |
118 if (style & underscore) { | |
119 contents.setUnderscore(); | |
120 defaultFont.setUnderscore(); | |
121 } | |
122 if (style & strikeout) { | |
123 contents.setStrikeout(); | |
124 defaultFont.setStrikeout(); | |
125 } | |
126 } | |
127 | |
128 FontSpec(char *name, int size, Style style = normal) | |
129 : AgNotifier<IFont>(IFont(name, size)) | |
130 , defaultFont(contents) | |
131 { | |
132 setStyle(style); | |
133 } | |
134 FontSpec(const FontSpec &f) | |
135 : AgNotifier<IFont>(f) | |
136 , defaultFont(f.defaultFont) | |
137 {} | |
138 FontSpec(Style style = normal) | |
139 : AgNotifier<IFont>((IWindow *) 0) | |
140 { | |
141 setStyle(style); | |
142 } | |
143 operator IFont &() { return contents; } | |
144 | |
145 AgString string(); | |
146 | |
147 IFont &operator = (const IFont &f) { | |
148 contents = f; | |
149 notify(); | |
150 return contents; | |
151 } | |
152 | |
153 int reset(); | |
154 AgString description(); | |
155 static FontSpec defaultSetting; | |
156 static FontSpec syntaxFile; | |
157 static FontSpec traceFile; | |
158 static FontSpec help; | |
159 static FontSpec helpTitle; | |
160 static FontSpec columnHead; | |
161 static FontSpec dataTable; | |
162 static FontSpec markedToken; | |
163 }; | |
164 | |
165 struct UndoButton : IPushButton { | |
166 UndoButton(long id, IWindow *owner, IPushButton::Style style = visible) | |
167 : IPushButton(id, owner, owner, IRectangle(), style) | |
168 { | |
169 setText("Undo"); | |
170 enableTabStop(); | |
171 } | |
172 }; | |
173 | |
174 struct DefaultButton : IPushButton { | |
175 DefaultButton(long id, IWindow *owner, IPushButton::Style style = visible) | |
176 : IPushButton(id, owner, owner, IRectangle(), style) | |
177 { | |
178 setText("Default"); | |
179 enableTabStop(); | |
180 } | |
181 }; | |
182 | |
183 struct OKButton : IPushButton { | |
184 OKButton(long id, IWindow *owner, IPushButton::Style style = visible) | |
185 : IPushButton(id, owner, owner, IRectangle(), style) | |
186 { | |
187 setText("OK"); | |
188 enableTabStop(); | |
189 } | |
190 }; | |
191 | |
192 struct CancelButton : IPushButton { | |
193 CancelButton(long id, IWindow *owner, IPushButton::Style style = visible) | |
194 : IPushButton(id, owner, owner, IRectangle(), style) | |
195 { | |
196 setText("Close"); | |
197 enableTabStop(); | |
198 } | |
199 }; | |
200 | |
201 struct HelpButton : IPushButton { | |
202 HelpButton(long id, IWindow *owner, IPushButton::Style style = visible) | |
203 : IPushButton(id, owner, owner, IRectangle(), style) | |
204 { | |
205 setText("Help"); | |
206 enableTabStop(); | |
207 } | |
208 }; | |
209 | |
210 class ColoredButton | |
211 : public IPushButton | |
212 { | |
213 private: | |
214 IColor fgColor; | |
215 IColor bgColor; | |
216 | |
217 public: | |
218 ColoredButton(long id, IWindow *owner, ColorSpec *colorPair, char *text); | |
219 }; | |
220 | |
221 | |
222 struct ButtonCanvas : ISetCanvas { | |
223 ButtonCanvas(IWindow *owner) | |
224 : ISetCanvas(nextChildId(), owner, owner, IRectangle(), | |
225 ISetCanvas::horizontalDecks | |
226 | ISetCanvas::packExpanded | |
227 | ISetCanvas::rightAlign | |
228 | ISetCanvas::topAlign | |
229 | IWindow::clipChildren | |
230 | IWindow::visible) | |
231 { | |
232 setDeckCount(1); | |
233 } | |
234 }; | |
235 | |
236 class FontDialog | |
237 : public AgFrame | |
238 , public IPaintHandler | |
239 { | |
240 public: | |
241 enum { nFontSpecs = 7 }; | |
242 | |
243 struct UndoRecord { | |
244 IPushButton *button; FontSpec *pointer; IFont font; | |
245 int operator < (const UndoRecord &x) const { return pointer < x.pointer; } | |
246 }; | |
247 | |
248 struct SpecRecord { FontSpec *pointer; char *title; }; | |
249 | |
250 struct OptionRecord { | |
251 IStaticText *text; IPushButton *button; | |
252 OptionRecord() : text(0), button(0) {} | |
253 OptionRecord(IStaticText *t, IPushButton *b) | |
254 : text(t), button(b) | |
255 {} | |
256 ~OptionRecord() { delete text; delete button; } | |
257 }; | |
258 | |
259 UndoRecord undoRecord; | |
260 OptionRecord optionRecord[nFontSpecs]; | |
261 AgStack<UndoRecord> undoStack; | |
262 | |
263 static SpecRecord specRecord[nFontSpecs]; | |
264 static int idField(AgString name); | |
265 static void initFont(int field, int flags, int size, AgString name); | |
266 | |
267 | |
268 IMultiCellCanvas canvas; | |
269 ISetCanvas fontChoices; | |
270 ISetCanvas buttons; | |
271 IPushButton undoButton; | |
272 IPushButton defaultButton; | |
273 IPushButton cancelButton; | |
274 IPushButton helpButton; | |
275 | |
276 enum { | |
277 undoCommand = nFontSpecs+1, | |
278 defaultCommand, | |
279 cancelCommand, | |
280 helpCommand | |
281 }; | |
282 | |
283 public: | |
284 IWindowHandle dialogHandle; | |
285 int fontDialogActive; | |
286 FontDialog(); | |
287 ~FontDialog(); | |
288 Boolean command(ICommandEvent &); | |
289 Boolean paintWindow(IPaintEvent &); | |
290 //Boolean dispatchHandlerEvent(IEvent &e); | |
291 virtual FontDialog &closeModalDialog(); | |
292 virtual FontDialog &mySetFocus(); | |
293 //IWindow *activeDialog; | |
294 //virtual Boolean gotFocus(IEvent &) { activeDialog.setFocus(); } | |
295 virtual void popUp(); | |
296 virtual void closeFrame(); | |
297 static void initFont(int flags, int size); | |
298 static void stackSettings(AgCharStack &stack); | |
299 }; | |
300 | |
301 class RGBSelector | |
302 : public ISetCanvas | |
303 , public ISpinHandler | |
304 , public IEditHandler | |
305 { | |
306 INumericSpinButton redSpinner; | |
307 INumericSpinButton greenSpinner; | |
308 INumericSpinButton blueSpinner; | |
309 IStaticText redText; | |
310 IStaticText greenText; | |
311 IStaticText blueText; | |
312 AgAction changeAction; | |
313 | |
314 public: | |
315 RGBSelector &setChangeAction(AgAction action) { | |
316 changeAction = action; | |
317 return *this; | |
318 } | |
319 RGBSelector(IWindow *owner, IColor color); | |
320 ~RGBSelector(); | |
321 IColor value() { | |
322 return IColor(redSpinner.value(), | |
323 greenSpinner.value(), | |
324 blueSpinner.value()); | |
325 } | |
326 Boolean spinEnded(IControlEvent &) { changeAction.perform(); return false; } | |
327 //Boolean edit(IControlEvent &) { changeAction.perform(); return true; } | |
328 Boolean edit(IControlEvent &); | |
329 }; | |
330 | |
331 class ColorDialog; | |
332 | |
333 class ColorSelector | |
334 : public AgDialog | |
335 , public ISpinHandler | |
336 , public IFrameHandler | |
337 , public IPaintHandler | |
338 { | |
339 enum { okCommand = 1, cancelCommand }; | |
340 ColorPair &colorPair; | |
341 | |
342 ColorDialog *ownerDialog; | |
343 | |
344 IMultiCellCanvas canvas; | |
345 ISetCanvas workArea; | |
346 IStaticText sampleText; | |
347 ISetCanvas selectorCanvas; | |
348 // IStaticText fgText; | |
349 RGBSelector foregroundSelector; | |
350 // IStaticText bgText; | |
351 RGBSelector backgroundSelector; | |
352 ButtonCanvas buttonCanvas; | |
353 OKButton okButton; | |
354 CancelButton cancelButton; | |
355 | |
356 public: | |
357 //ColorSelector(ColorPair &); | |
358 ColorSelector(ColorDialog *, ColorPair &); | |
359 ~ColorSelector(); | |
360 Boolean command(ICommandEvent &event); | |
361 Boolean activated(IFrameEvent &event); | |
362 Boolean paintWindow(IPaintEvent &); | |
363 void changeForeground() { | |
364 sampleText.setForegroundColor(foregroundSelector.value()).refresh(); | |
365 } | |
366 void changeBackground() { | |
367 sampleText.setBackgroundColor(backgroundSelector.value()).refresh(); | |
368 } | |
369 }; | |
370 | |
371 class ColorDialog | |
372 : public AgFrame | |
373 , public IPaintHandler | |
374 { | |
375 public: | |
376 enum { nColorSpecs = 12 }; | |
377 | |
378 struct UndoRecord { | |
379 int buttonNumber; | |
380 ColorSpec *pointer; | |
381 ColorPair colorPair; | |
382 int operator < (const UndoRecord &r) const { | |
383 return buttonNumber < r.buttonNumber; | |
384 } | |
385 }; | |
386 | |
387 struct SpecRecord { ColorSpec *pointer; char *title; }; | |
388 | |
389 UndoRecord undoRecord; | |
390 ColoredButton *buttonList[nColorSpecs]; | |
391 AgStack<UndoRecord> undoStack; | |
392 | |
393 static SpecRecord specRecord[nColorSpecs]; | |
394 | |
395 ISetCanvas canvas; | |
396 ISetCanvas colorChoices; | |
397 ButtonCanvas buttons; | |
398 UndoButton undoButton; | |
399 DefaultButton defaultButton; | |
400 CancelButton cancelButton; | |
401 HelpButton helpButton; | |
402 | |
403 enum { | |
404 undoCommand = nColorSpecs+1, | |
405 defaultCommand, | |
406 cancelCommand, | |
407 helpCommand | |
408 }; | |
409 | |
410 public: | |
411 ColorDialog(); | |
412 ~ColorDialog(); | |
413 Boolean command(ICommandEvent &); | |
414 Boolean paintWindow(IPaintEvent &); | |
415 static void ColorDialog::setColor(ColorPair p); | |
416 static void ColorDialog::stackSettings(AgCharStack &); | |
417 static void ColorDialog::initColor(AgString name, cint p); | |
418 }; | |
419 | |
420 | |
421 #endif /* DSPAR_HPP */ |