Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/vaclgui/dspar.cpp @ 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.cpp | |
7 */ | |
8 | |
9 #include <ifontdlg.hpp> | |
10 #include <ifonthdr.hpp> | |
11 #include <windows.h> | |
12 | |
13 #include "agcstack.h" | |
14 #include "cint.h" | |
15 #include "dspar.hpp" | |
16 #include "helpview.hpp" | |
17 #include "myalloc.h" | |
18 #include "vaclgui.hpp" | |
19 | |
20 //#define INCLUDE_LOGGING | |
21 #include "log.h" | |
22 | |
23 | |
24 FontDialog::FontDialog() | |
25 : AgFrame( IFrameWindow::border | |
26 | dialogBackground | |
27 | IFrameWindow::systemMenu) | |
28 , canvas(nextChildId(), this, this, IRectangle(), | |
29 IMultiCellCanvas::classDefaultStyle | |
30 | IWindow::clipChildren) | |
31 , fontChoices(nextChildId(), &canvas, &canvas, IRectangle(), | |
32 ISetCanvas::horizontalDecks | |
33 | ISetCanvas::packEven | |
34 | ISetCanvas::rightAlign | |
35 | ISetCanvas::centerVerticalAlign | |
36 | IWindow::clipChildren | |
37 | IWindow::visible) | |
38 , buttons(nextChildId(), &canvas, &canvas, IRectangle(), | |
39 ISetCanvas::horizontalDecks | |
40 | ISetCanvas::packExpanded | |
41 | ISetCanvas::rightAlign | |
42 | ISetCanvas::topAlign | |
43 | IWindow::clipChildren | |
44 | IWindow::visible) | |
45 , undoButton(undoCommand, &buttons, &buttons) | |
46 , defaultButton(defaultCommand, &buttons, &buttons) | |
47 , cancelButton(cancelCommand, &buttons, &buttons) | |
48 , helpButton(helpCommand, &buttons, &buttons) | |
49 , fontDialogActive(0) | |
50 { | |
51 LOGSECTION("FontDialog::FontDialog"); | |
52 IPaintHandler::handleEventsFor(&canvas); | |
53 IPaintHandler::handleEventsFor(&fontChoices); | |
54 IPaintHandler::handleEventsFor(&buttons); | |
55 setClient(&canvas); | |
56 { | |
57 int i; | |
58 IStaticText *text; | |
59 IPushButton *button; | |
60 | |
61 for (i = 0; i < nFontSpecs; i++) { | |
62 LOGV(i); | |
63 text = new IStaticText(nextChildId(), &fontChoices, &fontChoices); | |
64 LOGV((int) text); | |
65 button = new IPushButton(i+1, &fontChoices, &fontChoices); | |
66 LOGV((int) button); | |
67 text->setText(specRecord[i].title); | |
68 text->setAlignment(IStaticText::centerRight); | |
69 | |
70 LOGV(specRecord[i].title); | |
71 button->setText(specRecord[i].pointer->description().pointer()); | |
72 button->enableTabStop(); | |
73 LOGV((int) &optionRecord[i]); | |
74 optionRecord[i].text = text; | |
75 optionRecord[i].button = button; | |
76 LOGV((int) optionRecord[i].button); | |
77 } | |
78 optionRecord[0].button->setText("100 point New Times Roman bold italic"); | |
79 ISize buttonSize = optionRecord[0].button->minimumSize(); | |
80 LOGV(buttonSize.asString()); | |
81 optionRecord[0].button->setText( | |
82 specRecord[0].pointer->description().pointer() | |
83 ); | |
84 for (i = 0; i < nFontSpecs; i++) { | |
85 LOGV(i); | |
86 LOGV((int) optionRecord[i].button); | |
87 optionRecord[i].button->setMinimumSize(buttonSize); | |
88 } | |
89 | |
90 fontChoices.setDeckCount(nFontSpecs); | |
91 buttons.setDeckCount(1); | |
92 { | |
93 undoButton.setText("Undo").enableTabStop(); | |
94 defaultButton.setText("Default").enableTabStop(); | |
95 cancelButton.setText("Close").enableTabStop(); | |
96 helpButton.setText("Help").enableTabStop(); | |
97 } | |
98 } | |
99 windowTitle.setText("AnaGram - Set Fonts"); | |
100 registerTitle("Set Fonts"); | |
101 int choicesWidth = fontChoices.size().width(); | |
102 int buttonsWidth = buttons.size().width(); | |
103 canvas.setColumnWidth(1, choicesWidth - buttonsWidth); | |
104 canvas.setColumnWidth(2, buttonsWidth); | |
105 canvas.addToCell(&fontChoices, 1, 1, 2); | |
106 canvas.addToCell(&buttons, 2, 2); | |
107 ISize minSize = canvas.minimumSize(); | |
108 sizeTo(frameRectFor(minSize).size()); | |
109 positionFrame(); | |
110 show().setFocus(); | |
111 LOGV(isVisible()); | |
112 LOGV(isShowing()); | |
113 LOGV(rect().asString()); | |
114 } | |
115 | |
116 FontDialog::~FontDialog() { | |
117 IPaintHandler::stopHandlingEventsFor(&canvas); | |
118 IPaintHandler::stopHandlingEventsFor(&fontChoices); | |
119 IPaintHandler::stopHandlingEventsFor(&buttons); | |
120 } | |
121 | |
122 Boolean FontDialog::paintWindow(IPaintEvent &event) { | |
123 LOGSECTION("FontDialog::paintWindow"); | |
124 event.clearBackground(IGUIColor::dialogBgnd); | |
125 return false; | |
126 } | |
127 | |
128 RGBSelector::RGBSelector(IWindow *owner, IColor color) | |
129 : ISetCanvas(nextChildId(), owner, owner, IRectangle(), | |
130 horizontalDecks | |
131 | centerAlign | |
132 | packEven | |
133 | visible) | |
134 , redSpinner(nextChildId(), this, this) | |
135 , greenSpinner(nextChildId(), this, this) | |
136 , blueSpinner(nextChildId(), this, this) | |
137 , redText(nextChildId(), this, this) | |
138 , greenText(nextChildId(), this, this) | |
139 , blueText(nextChildId(), this, this) | |
140 { | |
141 LOGSECTION("RGBSelector::RGBSelector"); | |
142 redText.setText("Red").setAlignment(IStaticText::topCenter); | |
143 greenText.setText("Green").setAlignment(IStaticText::topCenter); | |
144 blueText.setText("Blue").setAlignment(IStaticText::topCenter); | |
145 IRange range(0, 255); | |
146 LOGV(color.redMix()) LCV(color.greenMix()) LCV(color.blueMix()); | |
147 redSpinner | |
148 . setRange(range) | |
149 . spinTo(color.redMix()) | |
150 . setLimit(3) | |
151 . enableTabStop() | |
152 ; | |
153 | |
154 greenSpinner | |
155 . setRange(range) | |
156 . spinTo(color.greenMix()) | |
157 . setLimit(3) | |
158 . enableTabStop() | |
159 ; | |
160 | |
161 blueSpinner | |
162 . setRange(range) | |
163 . spinTo(color.blueMix()) | |
164 . setLimit(3) | |
165 . enableTabStop() | |
166 ; | |
167 | |
168 setDeckCount(2); | |
169 ISpinHandler::handleEventsFor(&redSpinner); | |
170 ISpinHandler::handleEventsFor(&greenSpinner); | |
171 ISpinHandler::handleEventsFor(&blueSpinner); | |
172 IEditHandler::handleEventsFor(&redSpinner); | |
173 IEditHandler::handleEventsFor(&greenSpinner); | |
174 IEditHandler::handleEventsFor(&blueSpinner); | |
175 show(); | |
176 } | |
177 | |
178 RGBSelector::~RGBSelector() { | |
179 ISpinHandler::stopHandlingEventsFor(&redSpinner); | |
180 ISpinHandler::stopHandlingEventsFor(&greenSpinner); | |
181 ISpinHandler::stopHandlingEventsFor(&blueSpinner); | |
182 IEditHandler::stopHandlingEventsFor(&redSpinner); | |
183 IEditHandler::stopHandlingEventsFor(&greenSpinner); | |
184 IEditHandler::stopHandlingEventsFor(&blueSpinner); | |
185 } | |
186 | |
187 Boolean RGBSelector::edit(IControlEvent &event) { | |
188 //controlWindow()->spinTo(controlWindow()->value()); | |
189 changeAction.perform(); | |
190 return false; | |
191 } | |
192 | |
193 | |
194 AgString ColorPair::string() { | |
195 char buf[100]; | |
196 sprintf(buf, "(%x,%x)", fg.asRGBLong(), bg.asRGBLong()); | |
197 return buf; | |
198 } | |
199 | |
200 void ColorPair::setValue(char *s) { | |
201 sscanf(s, "(%d,%d)", &fg, &bg); | |
202 } | |
203 | |
204 | |
205 ColorSelector::ColorSelector(ColorDialog *owner_, ColorPair &colorPair_) | |
206 : AgDialog(owner_) | |
207 , ownerDialog(owner_) | |
208 , colorPair(colorPair_) | |
209 , canvas(nextChildId(), this, this, IRectangle(), | |
210 IMultiCellCanvas::classDefaultStyle | |
211 | IWindow::clipChildren) | |
212 , workArea(nextChildId(), &canvas, &canvas, IRectangle(), | |
213 ISetCanvas::verticalDecks | |
214 | ISetCanvas::packEven | |
215 | ISetCanvas::centerAlign | |
216 | ISetCanvas::centerVerticalAlign | |
217 | IWindow::clipChildren | |
218 | IWindow::visible) | |
219 , sampleText(nextChildId(), &workArea, &workArea) | |
220 , selectorCanvas(nextChildId(), &workArea, &workArea, IRectangle(), | |
221 ISetCanvas::verticalDecks | |
222 | ISetCanvas::packEven | |
223 | ISetCanvas::leftAlign | |
224 | IWindow::clipChildren | |
225 | IWindow::visible) | |
226 , foregroundSelector(&selectorCanvas, colorPair_.fg) | |
227 , backgroundSelector(&selectorCanvas, colorPair_.bg) | |
228 , buttonCanvas(&canvas) | |
229 , okButton(okCommand, &buttonCanvas, | |
230 IPushButton::defaultButton | |
231 | IWindow::visible) | |
232 , cancelButton(cancelCommand, &buttonCanvas) | |
233 { | |
234 LOGSECTION("ColorSelector::ColorSelector"); | |
235 foregroundSelector.setText("Foreground:"); | |
236 backgroundSelector.setText("Background:"); | |
237 sampleText.setText("Sample Text").setAlignment(IStaticText::centerCenter); | |
238 sampleText.setForegroundColor(colorPair.fg); | |
239 sampleText.setBackgroundColor(colorPair.bg); | |
240 sampleText.setMinimumSize(foregroundSelector.minimumSize()); | |
241 setClient(&canvas); | |
242 selectorCanvas.setDeckCount(1); | |
243 workArea.setDeckCount(1); | |
244 | |
245 cancelButton.setText("Cancel"); | |
246 | |
247 int width = workArea.minimumSize().width(); | |
248 int buttonCanvasWidth = buttonCanvas.minimumSize().width(); | |
249 LOGV(width); | |
250 LOGV(buttonCanvasWidth); | |
251 canvas.setColumnWidth(1, width - buttonCanvasWidth); | |
252 canvas.setColumnWidth(2, buttonCanvasWidth); | |
253 canvas.addToCell(&workArea, 1, 1, 2); | |
254 canvas.addToCell(&buttonCanvas, 2, 2, 1); | |
255 | |
256 | |
257 foregroundSelector.setChangeAction(actionObject(this, changeForeground)); | |
258 backgroundSelector.setChangeAction(actionObject(this, changeBackground)); | |
259 | |
260 removeDefaultHandler(); | |
261 IFrameHandler::handleEventsFor(this); | |
262 IPaintHandler::handleEventsFor(&canvas); | |
263 IPaintHandler::handleEventsFor(&workArea); | |
264 IPaintHandler::handleEventsFor(&selectorCanvas); | |
265 IPaintHandler::handleEventsFor(&buttonCanvas); | |
266 | |
267 ISize size = canvas.minimumSize(); | |
268 LOGV(size); | |
269 sizeTo(frameRectFor(IRectangle(size)).size()); | |
270 setFocus(); | |
271 } | |
272 | |
273 ColorSelector::~ColorSelector() { | |
274 IFrameHandler::stopHandlingEventsFor(this); | |
275 IPaintHandler::stopHandlingEventsFor(&canvas); | |
276 IPaintHandler::stopHandlingEventsFor(&workArea); | |
277 IPaintHandler::stopHandlingEventsFor(&selectorCanvas); | |
278 IPaintHandler::stopHandlingEventsFor(&buttonCanvas); | |
279 } | |
280 | |
281 Boolean ColorSelector::paintWindow(IPaintEvent &event) { | |
282 LOGSECTION("ColorSelector::paintWindow"); | |
283 event.clearBackground(IGUIColor::dialogBgnd); | |
284 return false; | |
285 } | |
286 | |
287 | |
288 Boolean ColorSelector::command(ICommandEvent &event) { | |
289 LOGSECTION("ColorSelector::command"); | |
290 switch (event.commandId()) { | |
291 case okCommand: | |
292 colorPair = ColorPair(foregroundSelector.value(), | |
293 backgroundSelector.value()); | |
294 dismiss(1); | |
295 return true; | |
296 case cancelCommand: | |
297 dismiss(0); | |
298 return true; | |
299 } | |
300 return false; | |
301 } | |
302 | |
303 ColoredButton::ColoredButton(long id, IWindow *owner, | |
304 ColorSpec *colorPair, char *text) | |
305 : IPushButton(id, owner, owner) | |
306 , fgColor(colorPair->fg()) | |
307 , bgColor(colorPair->bg()) | |
308 { | |
309 LOGSECTION("ColoredButton::ColoredButton"); | |
310 LOGV(fgColor.redMix()) LCV(fgColor.greenMix()) LCV(fgColor.blueMix()); | |
311 LOGV(bgColor.redMix()) LCV(bgColor.greenMix()) LCV(bgColor.blueMix()); | |
312 setText(text); | |
313 enableTabStop(); | |
314 } | |
315 | |
316 ColorDialog::ColorDialog() | |
317 : AgFrame(IFrameWindow::border | IFrameWindow::systemMenu) | |
318 , canvas(nextChildId(), this, this, IRectangle(), | |
319 ISetCanvas::verticalDecks | |
320 | ISetCanvas::packEven | |
321 | ISetCanvas::rightAlign | |
322 | ISetCanvas::centerVerticalAlign | |
323 | IWindow:: clipChildren | |
324 | IWindow::visible) | |
325 , colorChoices(nextChildId(), &canvas, &canvas, IRectangle(), | |
326 ISetCanvas::verticalDecks | |
327 | ISetCanvas::packExpanded | |
328 | ISetCanvas::centerAlign | |
329 | ISetCanvas::bottomAlign | |
330 | IWindow::clipChildren | |
331 | IWindow::visible) | |
332 , buttons(&canvas) | |
333 , undoButton(undoCommand, &buttons) | |
334 , defaultButton(defaultCommand, &buttons) | |
335 , cancelButton(cancelCommand, &buttons) | |
336 , helpButton(helpCommand, &buttons) | |
337 //, activeDialog(0) | |
338 { | |
339 LOGSECTION("ColorDialog::ColorDialog"); | |
340 IPaintHandler::handleEventsFor(&colorChoices); | |
341 IPaintHandler::handleEventsFor(&buttons); | |
342 setClient(&canvas); | |
343 int i; | |
344 | |
345 int maxWidth = 0; | |
346 for (i = 0; i < nColorSpecs; i++) { | |
347 LOGV(i); | |
348 ColorSpec *colorSpec = specRecord[i].pointer; | |
349 IColor fg = colorSpec->fg(); | |
350 IColor bg = colorSpec->bg(); | |
351 LOGV(fg.redMix()) LCV(fg.greenMix()) LCV(fg.blueMix()); | |
352 LOGV(bg.redMix()) LCV(bg.greenMix()) LCV(bg.blueMix()); | |
353 buttonList[i] = new ColoredButton(i+1, &colorChoices, | |
354 specRecord[i].pointer, | |
355 specRecord[i].title); | |
356 int width = buttonList[i]->minimumSize().width(); | |
357 if (maxWidth < width) { | |
358 maxWidth = width; | |
359 } | |
360 } | |
361 canvas.setDeckCount(1); | |
362 colorChoices.setDeckCount(2); | |
363 windowTitle.setText("AnaGram - Set Colors"); | |
364 registerTitle("Set Colors"); | |
365 canvas.setBackgroundColor(IGUIColor(IGUIColor::dialogBgnd)); | |
366 ISize choicesSize = colorChoices.size(); | |
367 int choicesWidth = choicesSize.width(); | |
368 int buttonsWidth = buttons.size().width(); | |
369 if (choicesWidth < buttonsWidth) { | |
370 choicesWidth = buttonsWidth; | |
371 choicesSize.setWidth(choicesWidth); | |
372 colorChoices.sizeTo(choicesSize); | |
373 } | |
374 LOGV(colorChoices.minimumSize()); | |
375 LOGV(buttons.minimumSize()); | |
376 ISize size = canvas.minimumSize(); | |
377 LOGV(size); | |
378 sizeTo(frameRectFor(IRectangle(size)).size()); | |
379 positionFrame(); | |
380 show().setFocus(); | |
381 LOGV(isVisible()); | |
382 LOGV(isShowing()); | |
383 LOGV(rect().asString()); | |
384 } | |
385 | |
386 ColorDialog::~ColorDialog() { | |
387 IPaintHandler::stopHandlingEventsFor(&canvas); | |
388 IPaintHandler::stopHandlingEventsFor(&colorChoices); | |
389 IPaintHandler::stopHandlingEventsFor(&buttons); | |
390 } | |
391 | |
392 Boolean ColorDialog::paintWindow(IPaintEvent &event) { | |
393 LOGSECTION("ColorDialog::paintWindow"); | |
394 event.clearBackground(IGUIColor::dialogBgnd); | |
395 return false; | |
396 } | |
397 | |
398 | |
399 Boolean ColorSelector::activated(IFrameEvent &event) { | |
400 AgFrame::windowRegistry.markActive(ownerDialog->windowId); | |
401 return false; | |
402 } | |
403 | |
404 Boolean ColorDialog::command(ICommandEvent &event) { | |
405 LOGSECTION("ColorDialog::command"); | |
406 LOGV(event.commandId()); | |
407 switch (event.commandId()) { | |
408 case undoCommand: { | |
409 LOGS("undo"); | |
410 if (undoStack.size() == 0) { | |
411 messageBeep(); | |
412 return true; | |
413 } | |
414 undoStack.pop(undoRecord); | |
415 ColorSpec &colorSpec = *undoRecord.pointer; | |
416 //int option = undoRecord.buttonNumber; | |
417 ColorPair colorPair = undoRecord.colorPair; | |
418 colorSpec = undoRecord.colorPair; | |
419 return true; | |
420 } | |
421 case defaultCommand: { | |
422 int i; | |
423 for (i = 0; i < nColorSpecs; i++) { | |
424 undoRecord.pointer = specRecord[i].pointer; | |
425 undoRecord.colorPair = *undoRecord.pointer; | |
426 undoRecord.buttonNumber =i; | |
427 | |
428 undoRecord.pointer->reset(); | |
429 undoStack.push(undoRecord); | |
430 } | |
431 return true; | |
432 } | |
433 case cancelCommand: { | |
434 AgFrame::windowRegistry.remove(windowId); | |
435 close(); | |
436 return true; | |
437 } | |
438 case helpCommand: { | |
439 LOGSECTION("ColorDialog::helpCommand"); | |
440 AgHelpWindow::showHelp("Set Colors"); | |
441 return true; | |
442 } | |
443 default: if (event.commandId() <= nColorSpecs) { | |
444 int option = event.commandId() - 1; | |
445 LOGS(specRecord[option].title); | |
446 undoRecord.pointer = specRecord[option].pointer; | |
447 ColorPair colorPair= *undoRecord.pointer; | |
448 undoRecord.colorPair = colorPair; | |
449 undoRecord.buttonNumber = option; | |
450 | |
451 ColorSelector colorSelector(this, colorPair); | |
452 char *title = specRecord[option].title; | |
453 colorSelector.windowTitle.setText(title); | |
454 LOGS("Ready to show modal dialog"); | |
455 /* | |
456 #ifdef AG_WINDOWS | |
457 RECT r; | |
458 SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0); | |
459 ISize size(r.right - r.left, r.bottom - r.top); | |
460 #else | |
461 ISize size = IWindow::desktopWindow()->size(); | |
462 #endif | |
463 IPoint where = (IPair) place(size, colorSelector.size(), 22); | |
464 */ | |
465 IPoint where = placeOnDesktop(colorSelector.size(), 22); | |
466 IPoint buttonWhere = buttonList[option]->position(); | |
467 int height = buttonList[option]->size().height(); | |
468 buttonWhere += position() + ISize(0,height); | |
469 buttonWhere += canvas.position(); | |
470 buttonWhere += colorChoices.position(); | |
471 where = where.minimum(buttonWhere); | |
472 colorSelector.moveTo(where); | |
473 modalDialog = &colorSelector; | |
474 int flag = colorSelector.showModally(); | |
475 modalDialog = 0; | |
476 LOGV(flag); | |
477 if (!flag) { | |
478 return true; | |
479 } | |
480 *undoRecord.pointer = colorPair; | |
481 | |
482 | |
483 undoStack.push(undoRecord); | |
484 } | |
485 else { | |
486 return AgFrame::command(event); | |
487 } | |
488 } | |
489 return true; | |
490 } | |
491 | |
492 static IColor makeColor(int x) { | |
493 LOGSECTION("makeColor"); | |
494 int red, green, blue; | |
495 red = x & 0xff; | |
496 x >>= 8; | |
497 green = x & 0xff; | |
498 x >>= 8; | |
499 blue = x & 0xff; | |
500 LOGV(x) LCV(red) LCV(green) LCV(blue); | |
501 IColor value(red, green, blue); | |
502 LOGV(value.asRGBLong()); | |
503 return value; | |
504 } | |
505 | |
506 void ColorDialog::initColor(AgString name, cint p) { | |
507 LOGSECTION("ColorDialog::initColor"); | |
508 //int f = p.x; | |
509 IColor fg = makeColor(p.x); | |
510 IColor bg = makeColor(p.y); | |
511 LOGV(name) LCV(fg.asRGBLong()) LCV(bg.asRGBLong()); | |
512 for (int i = 0; i < nColorSpecs; i++) { | |
513 if (name != specRecord[i].title) { | |
514 continue; | |
515 } | |
516 specRecord[i].pointer->initialize(ColorPair(fg,bg)); | |
517 return; | |
518 } | |
519 } | |
520 | |
521 Boolean FontSpec::reset() { | |
522 contents = defaultFont; | |
523 notify(); | |
524 return 1; | |
525 } | |
526 | |
527 Boolean ColorSpec::reset() { | |
528 contents = defaultValue; | |
529 notify(); | |
530 return 1; | |
531 } | |
532 | |
533 FontDialog::SpecRecord FontDialog::specRecord[FontDialog::nFontSpecs] = { | |
534 &FontSpec::dataTable, "Data Tables", | |
535 &FontSpec::columnHead, "Column headings", | |
536 &FontSpec::markedToken, "Marked tokens", | |
537 &FontSpec::syntaxFile, "Syntax file text", | |
538 &FontSpec::traceFile, "File trace text", | |
539 &FontSpec::help, "Help window text", | |
540 &FontSpec::helpTitle, "Help window titles" | |
541 }; | |
542 | |
543 class AFontDialogHandler | |
544 : public IFontDialogHandler | |
545 //, public IFrameHandler | |
546 { | |
547 private: | |
548 FontDialog *dialog; | |
549 | |
550 public: | |
551 AFontDialogHandler(FontDialog *d) : dialog(d) {} | |
552 Boolean dispatchHandlerEvent(IEvent &e); | |
553 Boolean modelessResults(IFontDialog *); | |
554 //Boolean activated(IFrameEvent &event); | |
555 }; | |
556 | |
557 /* | |
558 Boolean AFontDialogHandler::activated(IFrameEvent &event) { | |
559 LOGSECTION("AFontDialogHandler::activated"); | |
560 LOGV((int) dialog) LCV(dialog->windowId); | |
561 //AgFrame::windowRegistry.bubbleUp(dialog->windowId); | |
562 AgFrame::windowRegistry.markActive(dialog->windowId); | |
563 return false; | |
564 } | |
565 */ | |
566 | |
567 Boolean AFontDialogHandler::dispatchHandlerEvent(IEvent &e) { | |
568 LOGSECTION("AFontDialogHandler::dispatchHandlerEvent"); | |
569 //IWindow *pWindow = IWindow::windowWithHandle(dialog->dialogHandle); | |
570 if (dialog->fontDialogActive == 1 && e.controlHandle().isValid()) { | |
571 LOGS("Valid handle found"); | |
572 dialog->dialogHandle = e.controlHandle(); | |
573 dialog->fontDialogActive = 2; | |
574 //IWindow *pWindow = IWindow::windowWithHandle(dialog->dialogHandle); | |
575 //IFrameHandler::handleEventsFor(pWindow); | |
576 } | |
577 if (e.eventId() == WM_SETFOCUS || e.eventId() == WM_ACTIVATE) { | |
578 //AgFrame::windowRegistry.bubbleUp(dialog->windowId); | |
579 AgFrame::windowRegistry.markActive(dialog->windowId); | |
580 } | |
581 if (e.eventId() == WM_DESTROY) { | |
582 LOGS("Destroy message seen"); | |
583 dialog->fontDialogActive = 3; | |
584 //IWindow *pWindow = IWindow::windowWithHandle(dialog->dialogHandle); | |
585 //IFrameHandler::stopHandlingEventsFor(pWindow); | |
586 } | |
587 LOGV(e.eventId()) LCV((int) e.parameter1()); | |
588 return IFontDialogHandler::dispatchHandlerEvent(e); | |
589 } | |
590 | |
591 Boolean AFontDialogHandler::modelessResults(IFontDialog *) { | |
592 LOGSECTION("AFontDialogHandler::modelessResults"); | |
593 assert(dialog->dialogHandle.isValid()); | |
594 IWindow *pWindow = IWindow::windowWithHandle(dialog->dialogHandle); | |
595 LOGV((int) pWindow); | |
596 IFontDialogHandler::stopHandlingEventsFor(pWindow); | |
597 IFrameHandler::stopHandlingEventsFor(pWindow); | |
598 return false; | |
599 } | |
600 | |
601 FontDialog &FontDialog::closeModalDialog() { | |
602 LOGSECTION("FontDialog::closeModalDialog"); | |
603 LOGV(fontDialogActive); | |
604 if (fontDialogActive == 0) { | |
605 return *this; | |
606 } | |
607 | |
608 IWindow *pWindow = windowWithHandle(dialogHandle); | |
609 LOGV((int) pWindow); | |
610 if (pWindow) { | |
611 //pWindow->sendEvent(WM_COMMAND, IDABORT); | |
612 pWindow->sendEvent(WM_COMMAND, IDCANCEL); | |
613 return *this; | |
614 } | |
615 return *this; | |
616 } | |
617 | |
618 void FontDialog::closeFrame() { | |
619 LOGSECTION("FontDialog::closeFrame"); | |
620 if (fontDialogActive) { | |
621 closeAction.performDeferred(); | |
622 return; | |
623 } | |
624 close(); | |
625 } | |
626 | |
627 FontDialog &FontDialog::mySetFocus() { | |
628 LOGSECTION("FontDialog::mySetFocus"); | |
629 switch (fontDialogActive) { | |
630 case 0: | |
631 case 3: { | |
632 setFocus(); | |
633 return *this; | |
634 } | |
635 case 1: | |
636 case 2: { | |
637 IWindow *pWindow = windowWithHandle(dialogHandle); | |
638 LOGV((int) pWindow); | |
639 if (pWindow) { | |
640 pWindow->setFocus(); | |
641 return *this; | |
642 } | |
643 } | |
644 } | |
645 return *this; | |
646 } | |
647 | |
648 void FontDialog::popUp() { | |
649 LOGSECTION("FontDialog::popUp"); | |
650 switch (fontDialogActive) { | |
651 case 0: | |
652 case 3: { | |
653 if (isMinimized()) { | |
654 restore(); | |
655 } | |
656 show().setFocus(); | |
657 return; | |
658 } | |
659 case 1: | |
660 case 2: { | |
661 IWindow *pWindow = windowWithHandle(dialogHandle); | |
662 LOGV((int) pWindow); | |
663 if (pWindow) { | |
664 pWindow->setFocus(); | |
665 return; | |
666 } | |
667 } | |
668 } | |
669 } | |
670 | |
671 Boolean FontDialog::command(ICommandEvent &event) { | |
672 LOGSECTION("FontDialog::command"); | |
673 LOGV(event.commandId()); | |
674 switch (event.commandId()) { | |
675 case undoCommand: { | |
676 LOGS("undo"); | |
677 if (undoStack.size() == 0) { | |
678 messageBeep(); | |
679 return true; | |
680 } | |
681 undoStack.pop(undoRecord); | |
682 LOGV(undoRecord.pointer->description()); | |
683 FontSpec &fontSpec = *undoRecord.pointer; | |
684 fontSpec = undoRecord.font; | |
685 undoRecord.button->setText(fontSpec.description().pointer()); | |
686 LOGV(undoRecord.pointer->description()); | |
687 return true; | |
688 } | |
689 case defaultCommand: { | |
690 int i; | |
691 for (i = 0; i < nFontSpecs; i++) { | |
692 undoRecord.pointer = specRecord[i].pointer; | |
693 undoRecord.button = optionRecord[i].button; | |
694 undoRecord.font = *undoRecord.pointer; | |
695 | |
696 LOGV(undoRecord.pointer->description()); | |
697 undoRecord.pointer->reset(); | |
698 LOGV(undoRecord.pointer->description()); | |
699 undoStack.push(undoRecord); | |
700 undoRecord.button->setText( | |
701 undoRecord.pointer->description().pointer() | |
702 ); | |
703 } | |
704 return true; | |
705 } | |
706 case cancelCommand: { | |
707 AgFrame::windowRegistry.remove(windowId); | |
708 close(); | |
709 return true; | |
710 } | |
711 case helpCommand: { | |
712 LOGSECTION("FontDialog::helpCommand"); | |
713 AgHelpWindow::showHelp("Set Fonts"); | |
714 return true; | |
715 } | |
716 default: if (event.commandId() <= nFontSpecs) { | |
717 int option = event.commandId() - 1; | |
718 LOGV(option); | |
719 LOGV(specRecord[option].title); | |
720 undoRecord.pointer = specRecord[option].pointer; | |
721 undoRecord.button = optionRecord[option].button; | |
722 IFont font = *undoRecord.pointer; | |
723 undoRecord.font = font; | |
724 LOGV(undoRecord.pointer->description()); | |
725 | |
726 IFontDialog::Settings settings(&font); | |
727 LOGS("Settings object created"); | |
728 AgString title = specRecord[option].title; | |
729 LOGV(title); | |
730 int n = title.size() - 1; | |
731 LOGV(n); | |
732 if (title[n] == ':') { | |
733 title[n] = 0; | |
734 } | |
735 LOGV(title); | |
736 settings.setTitle(AgString::format("AnaGram - Set Fonts - %s", | |
737 title.pointer()).pointer()); | |
738 LOGS("Title set in settings object"); | |
739 fontDialogActive = 1; | |
740 AFontDialogHandler handler(this); | |
741 IFontDialog fontDialog(this, this, (IFontDialogHandler *) &handler, | |
742 IFontDialog::defaultStyle(), settings); | |
743 fontDialogActive = 0; | |
744 if (!fontDialog.pressedOK()) { | |
745 return true; | |
746 } | |
747 LOGS("Return from font dialog"); | |
748 *undoRecord.pointer = font; | |
749 LOGV(undoRecord.pointer->description()); | |
750 undoStack.push(undoRecord); | |
751 undoRecord.button->setText(undoRecord.pointer->description().pointer()); | |
752 } | |
753 else { | |
754 return AgFrame::command(event); | |
755 } | |
756 } | |
757 return true; | |
758 } | |
759 | |
760 void FontDialog::initFont(int field, int flags, int size, AgString name) { | |
761 LOGSECTION("FontDialog::initFont"); | |
762 LOGV(name) LCV(field) LCV(flags) LCV(size); | |
763 if (field >= nFontSpecs) { | |
764 return; | |
765 } | |
766 IFont f(name.pointer(), size); | |
767 LOGV(name); | |
768 if (flags & FontSpec::italic) f.setItalic(); | |
769 if (flags & FontSpec::bold) f.setBold(); | |
770 if (flags & FontSpec::strikeout) f.setStrikeout(); | |
771 if (flags & FontSpec::underscore) f.setUnderscore(); | |
772 specRecord[field].pointer->initialize(f); | |
773 return; | |
774 } | |
775 | |
776 int FontDialog::idField(AgString name) { | |
777 int i; | |
778 for (i = 0; i < nFontSpecs; i++) { | |
779 if (name == specRecord[i].title) { | |
780 break; | |
781 } | |
782 } | |
783 return i; | |
784 } | |
785 | |
786 ColorDialog::SpecRecord ColorDialog::specRecord[ColorDialog::nColorSpecs] = { | |
787 &ColorSpec::syntaxFile, "Syntax File", | |
788 &ColorSpec::data, "Data Tables", | |
789 &ColorSpec::activeTitle, "Active Pane Column Headings", | |
790 &ColorSpec::inactiveTitle, "Inactive Pane Column Headings", | |
791 &ColorSpec::activeCursor, "Active Pane Cursor Bar", | |
792 &ColorSpec::inactiveCursor, "Inactive Pane Cursor Bar", | |
793 &ColorSpec::traceFileUnscanned, "File Trace Text (Unparsed)", | |
794 &ColorSpec::traceFileScanned, "File Trace Text (Parsed)", | |
795 &ColorSpec::traceFileHilite, "File Trace Text (Highlight)", | |
796 &ColorSpec::helpText, "Help Window", | |
797 &ColorSpec::helpLink, "Help Links", | |
798 &ColorSpec::helpUsedLink, "Traversed Links" | |
799 }; | |
800 | |
801 void ColorDialog::stackSettings(AgCharStack &stack) { | |
802 for (int i = 0; i < nColorSpecs; i++) { | |
803 stack << "Color:" << specRecord[i].title << '='; | |
804 stack << specRecord[i].pointer->string() << '\n'; | |
805 } | |
806 } | |
807 | |
808 AgString FontSpec::string() { | |
809 AgCharStack stack; | |
810 if (contents.isBold()) stack << 'B'; | |
811 if (contents.isItalic()) stack << 'I'; | |
812 if (contents.isStrikeout()) stack << 'S'; | |
813 if (contents. isUnderscore()) stack << 'U'; | |
814 char buf[20]; | |
815 itoa(contents.pointSize(), buf, 10); | |
816 stack << buf; | |
817 stack << '.' << (char *) contents.name(); | |
818 return stack.popString(); | |
819 } | |
820 | |
821 void FontDialog::stackSettings(AgCharStack &stack) { | |
822 for (int i = 0; i < nFontSpecs; i++) { | |
823 stack << "Font:" << specRecord[i].title << '='; | |
824 stack << specRecord[i].pointer->string() << '\n'; | |
825 } | |
826 } | |
827 | |
828 ColorSpec ColorSpec::defaultSetting( | |
829 IColor(0,0,0), IColor(255,255,255)); | |
830 | |
831 #ifdef COLOR_SCHEME_1 | |
832 // original scheme | |
833 | |
834 ColorSpec ColorSpec::dialogBackground ( | |
835 IColor(0,0,0), IGUIColor(IGUIColor::dialogBgnd)); | |
836 | |
837 ColorSpec ColorSpec::syntaxFile( | |
838 IColor(0,0,0), IColor(216,252,240)); | |
839 | |
840 ColorSpec ColorSpec::traceFileHilite( | |
841 IColor(255,255,255), IColor(0,125,130)); | |
842 | |
843 ColorSpec ColorSpec::traceFileScanned( | |
844 IColor(0,0,0), IColor(216,252,240)); | |
845 | |
846 ColorSpec ColorSpec::traceFileUnscanned( | |
847 IColor(0,0,0),IColor(184,220,208)); | |
848 | |
849 ColorSpec ColorSpec::activeTitle( | |
850 IColor(0,0,0), IColor(150,213,255)); | |
851 | |
852 ColorSpec ColorSpec::inactiveTitle( | |
853 IColor(0,0,0), IColor(152,196,216)); | |
854 | |
855 ColorSpec ColorSpec::data( | |
856 IColor(0,0,0), IColor(216,252,240)); | |
857 | |
858 ColorSpec ColorSpec::activeCursor( | |
859 IColor(255,255,255), IColor(0, 125, 130)); | |
860 | |
861 ColorSpec ColorSpec::inactiveCursor( | |
862 IColor(255,255,255), IColor(125,165,150)); | |
863 | |
864 | |
865 | |
866 ColorSpec ColorSpec::helpText( | |
867 IColor(0,0,0), IColor(255,255,225)); | |
868 | |
869 ColorSpec ColorSpec::helpLink( | |
870 IColor(0,115,240),IColor(255,255,225)); | |
871 | |
872 ColorSpec ColorSpec::helpUsedLink( | |
873 IColor(0,140,30),IColor(255,255,225)); | |
874 | |
875 #else | |
876 // Renata's scheme 2 | |
877 | |
878 ColorSpec ColorSpec::dialogBackground ( | |
879 IColor(0,0,0), IGUIColor(IGUIColor::dialogBgnd)); | |
880 | |
881 ColorSpec ColorSpec::syntaxFile( | |
882 IColor(0,0,0), IColor(220,245,250)); | |
883 | |
884 ColorSpec ColorSpec::traceFileHilite( | |
885 IColor(255,255,255), IColor(120,45,45)); | |
886 | |
887 ColorSpec ColorSpec::traceFileScanned( | |
888 IColor(0,0,0), IColor(245,245,235)); | |
889 | |
890 ColorSpec ColorSpec::traceFileUnscanned( | |
891 IColor(0,0,0),IColor(222,220,208)); | |
892 | |
893 ColorSpec ColorSpec::activeTitle( | |
894 IColor(0,0,0), IColor(150,213,255)); | |
895 | |
896 ColorSpec ColorSpec::inactiveTitle( | |
897 IColor(0,0,0), IColor(171,203,228)); | |
898 | |
899 ColorSpec ColorSpec::data( | |
900 IColor(0,0,0), IColor(220,245,250)); | |
901 | |
902 ColorSpec ColorSpec::activeCursor( | |
903 IColor(255,255,255), IColor(120, 45, 45)); | |
904 | |
905 ColorSpec ColorSpec::inactiveCursor( | |
906 IColor(255,255,255), IColor(155,110,115)); | |
907 | |
908 | |
909 | |
910 ColorSpec ColorSpec::helpText( | |
911 IColor(0,0,0), IColor(255,255,225)); | |
912 | |
913 ColorSpec ColorSpec::helpLink( | |
914 IColor(0,115,255),IColor(255,255,225)); | |
915 | |
916 ColorSpec ColorSpec::helpUsedLink( | |
917 IColor(0,140,30),IColor(255,255,225)); | |
918 | |
919 #endif | |
920 | |
921 | |
922 FontSpec FontSpec::defaultSetting; | |
923 FontSpec FontSpec::syntaxFile("Courier", 10); | |
924 FontSpec FontSpec::traceFile("Courier", 10); | |
925 | |
926 FontSpec FontSpec::help("MS Sans Serif", 10); | |
927 FontSpec FontSpec::helpTitle("MS Sans Serif", 12, FontSpec::bold); | |
928 | |
929 FontSpec FontSpec::columnHead("MS Sans Serif", 10); | |
930 | |
931 FontSpec FontSpec::dataTable("MS Sans Serif", 10); | |
932 FontSpec FontSpec::markedToken("MS Sans Serif", 10, FontSpec::boldItalic); | |
933 | |
934 | |
935 AgString FontSpec::description() { | |
936 return AgString::format("%d point %s", | |
937 contents.pointSize(), contents.name()); | |
938 } | |
939 |