comparison anagram/vaclgui/ctrlpanel.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 1993-2002 Parsifal Software. All Rights Reserved.
4 * See the file COPYING for license and usage terms.
5 *
6 * ctrlpanel.cpp
7 */
8
9 #include <direct.h>
10 #include <fcntl.h>
11 #include <stdio.h>
12 #include "port.h"
13
14 #include <icritsec.hpp>
15 #include <imsgbox.hpp>
16
17 #include "about.hpp"
18 #include "agcstack.h"
19 #include "agfiledialog.hpp"
20 #include "readprofile.h"
21 #include "agrect.hpp"
22 #include "anom.h"
23 #include "bpe3.h"
24 #include "charsdc.h"
25 #include "conflictdc.h"
26 #include "config.h"
27 #include "coveragedc.h"
28 #include "ctrlpanel.hpp"
29 #include "dc.h"
30 #include "dpanel.hpp"
31 #include "error.h"
32 #include "errordc.h"
33 #include "file.h"
34 #include "fileview.hpp"
35 #include "ftview.hpp"
36 #include "gtview.hpp"
37 #include "helpview.hpp"
38 #include "items.h"
39 #include "keytabdc.h"
40 #include "keyword.h"
41 #include "openfile.hpp"
42 #include "operations.h"
43 #include "p.h"
44 #include "symtabdc.h"
45 #include "textfile.h"
46 #include "tokentabdc.h"
47 #include "proctabdc.h"
48 #include "profile-defs.h"
49 #include "q1a.h"
50 #include "rproc.h"
51 #include "ruletabdc.h"
52 #include "vaclgui.hpp"
53 #include "version.h"
54 #include "wm1.h"
55
56 //#define INCLUDE_LOGGING
57 #include "log.h"
58
59
60 #define TILDE '&'
61
62
63 ControlPanel *controlPanel = 0;
64 IPoint controlPanelLocation(-1, -1);
65
66 IRectangle syntaxFileRect;
67 int syntaxFileId = 0;
68
69
70 int ControlPanel::helpCursorSet = 0;
71 IPointerHandle ControlPanel::helpCursor;
72 IPointerHandle ControlPanel::activeCursor;
73 ISystemPointerHandle ControlPanel::waitCursor(ISystemPointerHandle::wait);
74
75 static IGraphicPushButton::Style
76 buttonStyle = IGraphicPushButton::sizeToGraphic
77 | IGraphicPushButton::tabStop
78 | IWindow::visible;
79
80
81 static void showWhatsNew() {
82 AgHelpWindow::showHelpCentered("What's New");
83 }
84
85 ControlPanel::ControlPanel(unsigned long windowId)
86 : IFrameWindow(windowId, AgFrame::frameParent, 0, IRectangle(),
87 IFrameWindow::titleBar
88 | IFrameWindow::systemMenu
89 | IFrameWindow::minimizeButton
90 //| IFrameWindow::border
91 | IFrameWindow::dialogBackground
92 | IFrameWindow::windowList
93 | IFrameWindow::sizingBorder
94 | IFrameWindow::noMoveWithOwner)
95 , menuBar(windowId, this)
96 , systemMenu(this)
97 , systemMenuFont(menuFont = systemMenu.font())
98 , canvas(nextChildId(), this, this, IRectangle(),
99 ISetCanvas::verticalDecks
100 | ISetCanvas::leftAlign
101 | ISetCanvas::packEven
102 | IWindow::clipChildren
103 | visible)
104 , buttonCanvas(nextChildId(), &canvas, &canvas, IRectangle(),
105 ISetCanvas::horizontalDecks
106 | ISetCanvas::centerVerticalAlign
107 | IWindow::clipChildren
108 | ISetCanvas::leftAlign
109 | ISetCanvas::packTight
110 | visible)
111 , agButton(IDI_BMP_AG, &buttonCanvas, &buttonCanvas,
112 IDI_BMP_AG, IRectangle(), buttonStyle)
113 , bpButton(IDI_BMP_BP, &buttonCanvas, &buttonCanvas,
114 IDI_BMP_BP, IRectangle(), buttonStyle)
115 , ftButton(IDI_BMP_FT, &buttonCanvas, &buttonCanvas,
116 IDI_BMP_FT, IRectangle(), buttonStyle)
117 , gtButton(IDI_BMP_GT, &buttonCanvas, &buttonCanvas,
118 IDI_BMP_GT, IRectangle(), buttonStyle)
119 , warnButton(IDI_BMP_WARN, &buttonCanvas, &buttonCanvas,
120 IDI_BMP_WARN, IRectangle(), buttonStyle)
121 , confButton(IDI_BMP_CONF, &buttonCanvas, &buttonCanvas,
122 IDI_BMP_CONF, IRectangle(), buttonStyle)
123 , helpButton(IDI_BMP_HELPICON, &buttonCanvas, &buttonCanvas,
124 IDI_BMP_HELPICON, IRectangle(), buttonStyle)
125 , statusControl(IDI_STATUS, &buttonCanvas, &buttonCanvas, IRectangle(),
126 IStaticText::defaultStyle()
127 | IStaticText::border3D)
128 , statusControlHelp(&statusControl, "Status Indicator")
129 , searchCanvas(nextChildId(), &canvas, &canvas, IRectangle(),
130 ISetCanvas::horizontalDecks
131 | ISetCanvas::leftAlign
132 | ISetCanvas::packTight
133 | IWindow::clipChildren
134 | visible)
135 , searchKeyBox(IDI_SEARCH_KEY, &searchCanvas, "Size of Search key space")
136 , searchKeyHelp(&searchKeyBox, "Search Key")
137 , findNextButton(IDI_BMP_FINDNEXT, &searchCanvas, &searchCanvas,
138 IDI_BMP_FINDNEXT, IRectangle(), buttonStyle)
139 , findPrevButton(IDI_BMP_FINDPREV, &searchCanvas, &searchCanvas,
140 IDI_BMP_FINDPREV, IRectangle(), buttonStyle)
141 , flyText(nextChildId(), this)
142 , flyOver(&flyText)
143 , openFileName()
144 //, busyFlag(false)
145 , windowTitle(this, "AnaGram")
146 , autobuildFlag(0)
147 , showSyntaxFlag(1)
148 , showStatsFlag(1)
149 , stayOnTopFlag(1)
150 //, minimized(0)
151 , topmostFlag(0)
152 , textColorChange(this, onTextColorChange)
153 , linkColorChange(this, onLinkColorChange)
154 , traversedColorChange(this, onTraversedColorChange)
155 , quitAction(actionObject(this, quit))
156 , accelerator(IDW_FRAME_WINDOW, this)
157 , helpRequested(0)
158 {
159 LOGSECTION("ControlPanel::ControlPanel");
160 controlPanel = this;
161
162 AgString initializer = AgFetchProfile("initializationData");
163 LOGS("profile retrieved");
164 if (initializer.exists() && initializeFrom(initializer.pointer())) {
165 LOGS("initialization problem");
166 IMessageBox messageBox(controlPanel);
167 messageBox.setTitle("AnaGram");
168 messageBoxShowing++;
169 messageBox.show("Error initializing from registry",
170 IMessageBox::information);
171 messageBoxShowing--;
172 }
173 LOGV(recentFiles.size());
174
175 analyzeThread.adjustPriority(-1);
176
177 waitCursor = ISystemPointerHandle(ISystemPointerHandle::wait);
178
179 searchKeyBox.enterAction = actionObject(this, findNext);
180
181 flyOver.setHelpText(handle(), IDI_BMP_AG);
182
183 helpCursor = IPointerHandle(LoadCursor(0, IDC_HELP));
184
185 textColorChange.attach(&ColorSpec::helpText);
186 linkColorChange.attach(&ColorSpec::helpLink);
187 traversedColorChange.attach(&ColorSpec::helpUsedLink);
188
189 buttonCanvas.setDeckCount(1);
190 searchCanvas.setDeckCount(1);
191 canvas.setDeckCount(1);
192 buttonCanvas.setText("");
193
194 LOGV(agButton.size().asString());
195
196 ISize padSize = buttonCanvas.pad();
197 padSize.setWidth(4);
198 buttonCanvas.setPad(padSize);
199
200 buttonCanvas.setMargin(ISize(4, 2));
201
202 searchCanvas.setMargin(ISize(4, 2));
203
204 padSize = searchCanvas.pad();
205 padSize.setWidth(4);
206 searchCanvas.setPad(padSize);
207
208 ISize margin = canvas.margin();
209 margin.setHeight(0);
210 canvas.setMargin(margin);
211
212 padSize = canvas.pad();
213 padSize.setHeight(0);
214 canvas.setPad(padSize);
215
216 setClient(&canvas); // Set canvas control for client area
217
218
219 // Set self as command event handler
220
221 flyOver.handleEventsFor(&buttonCanvas);
222 flyOver.handleEventsFor(&searchCanvas);
223 IFrameWindow::removeDefaultHandler();
224 IFrameHandler::handleEventsFor(this);
225 ICommandHandler::handleEventsFor(this);
226 IMouseHandler::handleEventsFor(this);
227 IPaintHandler::handleEventsFor(&canvas);
228 IPaintHandler::handleEventsFor(&buttonCanvas);
229 IPaintHandler::handleEventsFor(&searchCanvas);
230 IKeyboardHandler::handleEventsFor(this);
231 //IResizeHandler::handleEventsFor(this);
232 LOGS("Command handler attached");
233
234 userHandler = new AgUserHandler;
235 userHandler->handleEventsFor(this);
236 AgHelpHandler::handleEventsFor(this);
237
238 IMenuHandler::handleEventsFor(this);
239 IFocusHandler::handleEventsFor(&searchCanvas);
240 IFocusHandler::handleEventsFor(&searchKeyBox);
241
242 systemMenu.deleteItem(ISystemMenu::idMaximize);
243 //systemMenu.deleteItem(ISystemMenu::idSize);
244 systemMenu.disableItem(ISystemMenu::idRestore);
245
246 statusControl.setFont(IFont("Arial", 8));
247
248 menuBar.disableMinimumSizeCaching();
249 static const int menuIdList[] = {
250 IDM_FILE, IDM_BROWSE, IDM_OPTIONS, IDM_WINDOWS, IDM_HELP, 0
251 };
252 int i;
253 int menuWidth = 0;
254 for (i = 0; menuIdList[i]; i++) {
255 int itemWidth = menuBar.itemRect(menuIdList[i]).width();
256 LOGV(itemWidth);
257 menuWidth += itemWidth;
258 }
259 LOGV(menuWidth);
260
261 int statusWidth = statusControl.font().textWidth(" Analyzed ");
262 ISize minSize(statusWidth, agButton.minimumSize().height());
263 statusControl.setMinimumSize(minSize);
264
265 statusControl.setAlignment(IStaticText::centerCenter);
266 setStatus();
267
268 int minWidth = buttonCanvas.minimumSize().width();
269 if (minWidth < menuWidth) {
270 statusWidth += menuWidth - minWidth;
271 minSize.setWidth(statusWidth);
272 statusControl.setMinimumSize(minSize);
273 minWidth = menuWidth;
274 }
275 minSize = searchKeyBox.minimumSize();
276 minWidth -= 2*agButton.size().width();
277 minWidth -= 2*searchCanvas.pad().width();
278 minWidth -= 2*searchCanvas.margin().width();
279
280 minSize.setWidth(minWidth);
281 searchKeyBox.setMinimumSize(minSize);
282
283 LOGV(menuFont.name()) LCV(menuFont.pointSize());
284 LOGV(font().name()) LCV(font().pointSize());
285
286 LOGS("Menu handler attached");
287
288 // Set application icon
289 //setIcon(IDI_ICON);
290 //iconHandle = icon();
291 setIcon(iconHandle);
292
293 LOGS("Icon set");
294 IRectangle desktopRect = desktopWindow()->rect();
295
296 int titleBarHeight = 24;
297 cascadeIncrement = IPoint(titleBarHeight, titleBarHeight);
298 cascadeOrigin = IPoint(0, 0);
299
300 int verticalOffset = 0;
301
302 LOGV(cascadeOrigin.asString());
303
304 cascadeOffset = cascadeOrigin;
305
306 minSize = canvas.minimumSize();
307 LOGV(minSize);
308 IRectangle frameRect = frameRectFor(IRectangle(IPoint(0, 0), minSize));
309 IRectangle clientRect = clientRectFor(frameRect);
310 //minimumSize = frameRect.size();
311 LOGV(frameRect.asString());
312 cint measure = desktopRect.size();
313 cint panelSize = frameRect.size();
314 IPoint where = controlPanelLocation;
315 LOGV(where);
316 if (where.x() < 0) {
317 where = (IPair) place(measure, panelSize, 20);
318 }
319 LOGV(where);
320 frameRect.moveTo(where);
321 frameRect = adjustPos(frameRect);
322 LOGV(frameRect.asString());
323 //sizeTo(frameRect.size());
324 //moveTo(where);
325 moveSizeTo(frameRect);
326 LOGV(menuBar.size().asString());
327 LOGV(canvas.position()) LCV(canvas.size()) LCV(size());
328 LOGV(menuBar.itemRect(IDM_FILE).asString());
329 LOGV(menuBar.itemRect(IDM_HELP).asString());
330 /*
331 i = menuWidth = 0;
332 for (i = 0; menuIdList[i]; i++) {
333 menuWidth += menuBar.itemRect(menuIdList[i]).width();
334 }
335 LOGV(menuWidth);
336 */
337
338 //maxDataPanelWidth = where.x();
339
340 verticalOffset += frameRect.size().height();
341
342 // Set focus to this window and show
343 setFocus();
344 show();
345
346 if (commandLineFile.exists()) {
347 defer(this, openCommandLineFile);
348 }
349 if (!initializer.exists() || lastVersion < INTVERSION) {
350 defer(showWhatsNew);
351 }
352 }
353
354 void closeActionWindow() {
355 LOGSECTION("closeActionWindow");
356 pActionWindow->close();
357 }
358
359
360 /***********************************************************/
361 /* Application main window destructor. It stops the event */
362 /* handling and deletes any objects on the heap. */
363 /***********************************************************/
364 ControlPanel :: ~ControlPanel ()
365 {
366 LOGSECTION("ControlPanel::~ControlPanel");
367 flyOver.stopHandlingEventsFor(&buttonCanvas);
368 flyOver.stopHandlingEventsFor(&searchCanvas);
369 ICommandHandler::stopHandlingEventsFor(this);
370 IFrameHandler::stopHandlingEventsFor(this);
371 IMenuHandler::stopHandlingEventsFor(this);
372 IMouseHandler::stopHandlingEventsFor(this);
373 userHandler->stopHandlingEventsFor(this);
374 AgHelpHandler::stopHandlingEventsFor(this);
375 IPaintHandler::stopHandlingEventsFor(&canvas);
376 IPaintHandler::stopHandlingEventsFor(&buttonCanvas);
377 IPaintHandler::stopHandlingEventsFor(&searchCanvas);
378 IFocusHandler::stopHandlingEventsFor(&searchCanvas);
379 IFocusHandler::stopHandlingEventsFor(&searchKeyBox);
380 IKeyboardHandler::stopHandlingEventsFor(this);
381 //IResizeHandler::stopHandlingEventsFor(this);
382 delete userHandler;
383 controlPanel = 0;
384 defer(closeActionWindow);
385 }
386
387 /*
388 Boolean ControlPanel::windowResize(IResizeEvent &event){
389 LOGSECTION("ControlPanel::windowResize");
390 ok_ptr(this);
391
392 if (event.controlWindow() != this) {
393 return false;
394 }
395 LOGV(event.newSize().asString());
396 if (!isVisible()) {
397 return false;
398 }
399 if (!(event.newSize() >= minimumSize)) {
400 sizeTo(minimumSize);
401 return true;
402 }
403 //canvas.sizeTo(clientRectFor(IRectangle(IPoint(), event.newSize())).size());
404 LOGV(id());
405 return false;
406 }
407 */
408
409 Boolean ControlPanel::ComboBox::enter(IControlEvent &event) {
410 LOGSECTION("ControlPanel::ComboBox::enter");
411 LOGV(listShowing);
412 if (listShowing) {
413 unsigned s = selection();
414 LOGV(s) LCV(IComboBox::notFound);
415 if (s == IComboBox::notFound) {
416 return false;
417 }
418 IString text = itemText(s);
419 LOGV((char *) text);
420 setText(text);
421 listShowing = 0;
422 return false;
423 }
424 else {
425 LOGV(selection());
426 LOGV(IComboBox::notFound);
427 LOGV(isListShowing());
428 LOGV(hasChanged());
429 enterAction.perform();
430 IString contents = text();
431 if (contents.length() == 0) {
432 return false;
433 }
434 int n = count();
435 while (n--) {
436 if (itemText(n) == contents) {
437 remove(n);
438 break;
439 }
440 }
441 addAsFirst(contents);
442 n = count();
443 LOGV(count());
444 if (n < 8 && n > minimumRows()) {
445 setMinimumRows(8);
446 }
447 LOGV(minimumRows());
448 }
449 return true;
450 }
451
452 Boolean ControlPanel::ComboBox::listShown(IControlEvent &event) {
453 LOGSECTION("ControlPanel::ComboBox::listShown");
454 listShowing = 1;
455 return false;
456 }
457
458 void ControlPanel::idSyntaxFile(AgString name) {
459 LOGSECTION("ControlPanel::idSyntaxFile");
460 openFileName = infile_name = name; // Store selected file name
461 errorReportFile = AgString();
462 openFileTimestamp = getFileTimestamp(name.pointer());
463 AgString settingsFileName
464 = openFileName.lastCut("\\/").leftI().concat("*.syn");
465 restoreDirectory();
466 /*
467 char drive[_MAX_DRIVE];
468 _splitpath(openFileName.pointer(), drive, NULL, NULL, NULL);
469 _chdrive(toupper(drive[0]) - 'A' + 1);
470 LOGV(directoryName.pointer());
471 chdir(directoryName.pointer());
472 work_dir_name = directoryName;
473 */
474 AgString fileName = openFileName.lastCut("\\/").rightX();
475
476 simple_file_name = fileName.lastCut('.').leftX();
477
478 LOGV(fileName.pointer());
479 LOGV(simple_file_name.pointer());
480 }
481
482 void ControlPanel::restoreDirectory() {
483 LOGSECTION("ControlPanel::restoreDirectory");
484 AgString directoryName
485 = openFileName.lastCut("\\/").leftX();
486 if (directoryName[directoryName.size() - 1] == ':') {
487 directoryName.concat("\\");
488 }
489 char drive[_MAX_DRIVE];
490 _splitpath(openFileName.pointer(), drive, NULL, NULL, NULL);
491 _chdrive(toupper(drive[0]) - 'A' + 1);
492 LOGV(directoryName.pointer());
493 chdir(directoryName.pointer());
494 work_dir_name = directoryName;
495 }
496
497 void ControlPanel::loadSyntaxFile() {
498 LOGSECTION("ControlPanel::loadSyntaxFile");
499
500 inputFile = text_file(openFileName);
501 reset_parser();
502 errorList.reset();
503
504 setStatus();
505 windowTitle.setViewText(simple_file_name.pointer());
506 if (showSyntaxFlag) {
507 syntaxFileId = nextChildId();
508 FileWindow *fileWindow = new FileWindow(syntaxFileId, inputFile,
509 syntaxFileRect);
510 fileWindow->enableCursorBar();
511 fileWindow->setAutoDeleteObject();
512 fileWindow->syntaxDependent = 1;
513 LOGV(syntax_state);
514 if (syntaxFileRect.area() <= 0) {
515 AgQuadrant quad = findQuadrant(controlPanel);
516 if (quad == lowerRight) {
517 quad = upperRight;
518 }
519 else {
520 quad = lowerRight;
521 }
522 AgRectangle bestRect(
523 AgRectangle::desktop().position(quad),
524 fileWindow->size(),
525 opposite(quad)
526 );
527 IPoint where = (IPair) bestRect.position();
528 fileWindow->moveTo(where);
529 LOGV(where.asString());
530 }
531 //cascadeOffset -= cascadeIncrement;
532 fileWindow->show();
533 }
534 }
535
536 void ControlPanel::makeControlPanel() {
537 LOGSECTION("makeControlPanel");
538 controlPanel = new ControlPanel(IDW_FRAME_WINDOW);
539 controlPanel->setAutoDeleteObject();
540 LOGS("Control panel complete");
541 if (errorList.size()) {
542 defer(controlPanel, showErrors);
543 }
544 }
545
546 ControlPanel &ControlPanel::makeTopmost() {
547 LOGSECTION_OFF("ControlPanel::makeTopmost");
548 if (!stayOnTopFlag || topmostFlag++) {
549 return *this;
550 }
551
552 SetWindowPos(
553 handle(),
554 HWND_TOP, //HWND_TOPMOST,
555 0,0,0,0,
556 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
557
558 topmostFlag = 0;
559 return *this;
560 }
561
562 void ControlPanel::monitor(IThread &thread) {
563 LOGSECTION_OFF("ControlPanel::monitor");
564 StatisticsWindow *window =
565 (StatisticsWindow *) AgFrame::windowRegistry.find("Statistical Summary");
566 if (window == NULL) {
567 window = new StatisticsWindow();
568 window->setAutoDeleteObject();
569 IPoint where = (IPair) placeRelative(window->size(), controlPanel);
570 window->moveTo(where);
571 }
572 window->show().setFocus();
573 {
574 ICritSec cookie;
575 analyzeThreadActive = 1;
576 }
577 IReference<ITimerFn> timerFn = new TimerFn(timer, *window, thread);
578 timer.start(timerFn, 250);
579 }
580
581 void ControlPanel::onLinkColorChange() {
582 LOGSECTION("ControlPanel::onLinkColorChange");
583 ColorSpec::helpText.bg() = ColorSpec::helpLink.bg();
584 ColorSpec::helpUsedLink.bg() = ColorSpec::helpLink.bg();
585 }
586
587 void ControlPanel::onTextColorChange() {
588 LOGSECTION("ControlPanel::onTextColorChange");
589 ColorSpec::helpLink.bg() = ColorSpec::helpText.bg();
590 ColorSpec::helpUsedLink.bg() = ColorSpec::helpText.bg();
591 }
592
593 void ControlPanel::onTraversedColorChange() {
594 LOGSECTION("ControlPanel::onTraversedColorChange");
595 ColorSpec::helpText.bg() = ColorSpec::helpUsedLink.bg();
596 ColorSpec::helpLink.bg() = ColorSpec::helpUsedLink.bg();
597 }
598
599 void ControlPanel::openCommandLineFile() {
600 LOGSECTION("ControlPanel::openCommandLineFile");
601 char *p = commandLineFile.pointer();
602 LOGV(p);
603 FILE *file = fopen(p, "r");
604 if (file == 0) {
605 char *q = strrchr(p, '\\');
606 if (q == 0) {
607 q = p;
608 }
609 LOGV(q);
610 if (strrchr(q, '.') == 0) {
611 commandLineFile = commandLineFile.concat(".syn");
612 p = commandLineFile.pointer();
613 LOGV(p);
614 file = fopen(p, "r");
615 }
616 }
617 if (file == 0) {
618 AgString msg = AgString::format("Cannot open %s",
619 commandLineFile.pointer());
620 IMessageBox messageBox(controlPanel);
621 messageBoxShowing++;
622 messageBox.show(msg.pointer(), IMessageBox::information);
623 messageBoxShowing--;
624 return;
625 }
626 fclose(file);
627 activeCursor = waitCursor;
628 resetCursor();
629 LOGS("Wait cursor set");
630
631 AgString fullpath(_MAX_PATH);
632 _fullpath(fullpath.pointer(), commandLineFile.pointer(), _MAX_PATH);
633 idSyntaxFile(fullpath);
634 monitor(analyzeThread);
635 loadSyntaxFile();
636 //analyzeThread.adjustPriority(-20);
637 //analyzeThread.start(new AnalyzeGrammarFn(this));
638 *buildErrorMsg = 0;
639 rememberFile(fullpath);
640 if (autobuildFlag) {
641 IReference<IThreadFn> fn = new BuildParserFn(this);
642 analyzeThread.start(fn);
643 }
644 else {
645 IReference<IThreadFn> fn = new AnalyzeGrammarFn(this);
646 analyzeThread.start(fn);
647 }
648 }
649
650 char *ControlPanel::removeTilde(char *s) {
651 char *copy = s;
652 char *t = s;
653 while (*s) {
654 if (*s != TILDE) {
655 *t++ = *s;
656 }
657 s++;
658 }
659 *t = 0;
660 return copy;
661 }
662
663 void ControlPanel::selectMenuItem(long id) {
664 menuBar.selectItem(id);
665 }
666
667 void ControlPanel::setStatus() {
668 LOGSECTION("ControlPanel::setStatus");
669 LOGV(simple_file_name);
670 LOGV(syntax_state);
671 LOGV(syntaxStateString[syntax_state]);
672 statusControl.setText(syntaxStateString[syntax_state]);
673 }
674
675 void ControlPanel::showErrors() {
676 dc_ref error_display = new error_display_dc;
677 error_display->des->d_size.y = errorList.size();
678 AgDataViewPlug *connector = new AgDataViewPlug(error_display);
679 error_display->windowConnector = connector;
680 AgDataPanel* newPanel = new AgDataPanel(connector);
681 cascadeOffset -= cascadeIncrement;
682 AgRectangle rect(controlPanel->position(), controlPanel->size());
683 LayoutRef ref(rect);
684 IPoint warningPos = placeWindow(newPanel->size(), ref);
685 newPanel->moveTo(warningPos);
686 newPanel->setAutoDeleteObject();
687 newPanel->show().setFocus();
688 }
689
690 void ControlPanel::TimerFn::timerExpired(unsigned long) {
691 LOGSECTION_ON("Timer expired");
692 LOGV((int) &window);
693 LOGV((int) AgFrame::windowRegistry.find("Statistical Summary"));
694 LOGV(messageBoxShowing);
695 if (messageBoxShowing) {
696 timer.stop();
697 return;
698 }
699 int windowExists(&window ==
700 AgFrame::windowRegistry.find("Statistical Summary"));
701 if (windowExists) {
702 //LOGSECTION("Critical section");
703 ICritSec cookie;
704 window.updateDisplay();
705 }
706 {
707 //LOGSECTION("Critical section");
708 ICritSec cookie;
709 controlPanel->setStatus();
710 }
711 if (!thread.isStarted() || !analyzeThreadActive) {
712 timer.stop();
713 LOGS("Timer stopped");
714 LOGV(controlPanel->showStatsFlag) LCV(windowExists);
715 IPoint warningPos;
716 if (windowExists && !controlPanel->showStatsFlag) {
717 AgFrame::windowRegistry.remove(window.id());
718 window.close();
719 windowExists = false;
720 }
721 else if (windowExists) {
722 window.setFocus();
723 }
724 ControlPanel::activeCursor = IPointerHandle();
725 controlPanel->resetCursor();
726 LOGS("Cursor set to default");
727 LOGV(errorList.size());
728 IFrameWindow *errorWindow = AgFrame::windowRegistry.find("Warnings");
729 if (errorWindow != NULL) {
730 AgFrame::windowRegistry.remove(errorWindow->id());
731 errorWindow->close();
732 }
733 /*
734 AgDataPanel *errorWindow = (AgDataPanel *) AgFrame::windowRegistry.find("Warnings");
735 if (errorWindow != NULL) {
736 LOGS("errorWindow exists");
737 errorWindow->dataView->reset();
738 errorWindow->show().setFocus();
739 }
740 else if (errorList.size()) {
741 */
742 if (errorList.size()) {
743 //pop_up_window(new error_display_dc);
744 dc_ref error_display = new error_display_dc;
745 error_display->des->d_size.y = errorList.size();
746 AgDataViewPlug *connector = new AgDataViewPlug(error_display);
747 error_display->windowConnector = connector;
748 AgDataPanel* newPanel = new AgDataPanel(connector);
749 cascadeOffset -= cascadeIncrement;
750 AgRectangle rect(controlPanel->position(), controlPanel->size());
751 LayoutRef ref(rect);
752 if (windowExists) {
753 rect = AgRectangle(window.position(), window.size());
754 ref.merge(rect);
755 }
756 warningPos = placeWindow(newPanel->size(), ref);
757 newPanel->moveTo(warningPos);
758 newPanel->setAutoDeleteObject();
759 newPanel->show().setFocus();
760 }
761 if (*buildErrorMsg) {
762 IMessageBox messageBox(controlPanel);
763 LOGS("Showing message Box");
764 messageBoxShowing++;
765 messageBox.show(buildErrorMsg, IMessageBox::information);
766 messageBoxShowing--;
767 *buildErrorMsg = 0;
768 LOGS("Done showing message box");
769 }
770 LOGV(thread.variable("Error Message"));
771 if (*(char *) thread.variable("Error Message")) {
772 controlPanel->quitAction.performDeferred();
773 }
774 }
775 LOGV(analyzeThreadActive) LCV(thread.isStarted());
776 }
777
778 Boolean ControlPanel::showHelp(IEvent &event) {
779 LOGSECTION("ControlPanel::showHelp");
780 helpRequested = 1;
781 return AgHelpWindow::showHelp(selectedMenuText);
782 }
783
784 Boolean ControlPanel::gotFocus(IControlEvent &event) {
785 LOGSECTION("ControlPanel::gotFocus");
786 LOGV((int) event.controlWindow()) LCV((int) &searchKeyBox);
787 if (event.controlWindow() != &searchKeyBox) return false;
788 if (helpCursorSet) {
789 ControlPanel::helpCursorSet = 0;
790 AgHelpWindow::showHelp("Search Key");
791 ControlPanel::resetCursor();
792 return true;
793 }
794 agButton.disableDefault();
795 return true;
796 }
797
798 Boolean ControlPanel::virtualKeyPress(IKeyboardEvent &event) {
799 LOGSECTION("ControlPanel::virtualKeyPress");
800 LOGV((int) event.virtualKey());
801 LOGV(event.isShiftDown()) LCV(event.isCtrlDown()) LCV(event.isAltDown());
802 switch (event.virtualKey()) {
803 case IKeyboardEvent::f8: {
804 if (event.isShiftDown() || event.isCtrlDown() || event.isAltDown()) {
805 return false;
806 }
807
808 int first = 0, last = AgFrame::windowRegistry.size();
809 while (first < last) {
810 LOGV(AgFrame::windowRegistry[first].id)
811 LCV(AgFrame::windowRegistry[first].title.pointer());
812 if (AgFrame::windowRegistry[first].isActive) {
813 LOGS("found it");
814 AgFrame::windowRegistry[first].window->setFocus();
815 break;
816 }
817 first++;
818 }
819 return true;
820 }
821 }
822 return false;
823 }
824
825 Boolean ControlPanel::paintWindow(IPaintEvent &event) {
826 LOGSECTION("ControlPanel::paintWindow");
827 LOGV(event.rect().asString());
828 event.clearBackground(IGUIColor::dialogBgnd);
829 return false;
830 }
831
832
833 Boolean ControlPanel::mouseClicked(IMouseClickEvent &event) {
834 LOGSECTION("ControlPanel::mouseClicked");
835 //IWindow *controlWindow = event.controlWindow();
836 //LOGV(controlWindow->id());
837 LOGV(buttonCanvas.id());
838 LOGV(event.mouseAction());
839 IWindow *window = windowWithHandle(event.windowUnderPointer());
840 LOGV(window ? window->id(): 0);
841 if (window) switch (window->id()) {
842 case IDI_BMP_AG :
843 case IDI_BMP_BP :
844 case IDI_BMP_FT :
845 case IDI_BMP_GT :
846 case IDI_BMP_WARN :
847 case IDI_BMP_CONF :
848 case IDI_BMP_HELPICON:
849 case IDI_BMP_FINDNEXT:
850 case IDI_BMP_FINDPREV:
851 case IDI_SEARCH_KEY :
852 return false;
853 }
854 helpCursorSet = 0;
855 resetCursor();
856 return false;
857 }
858
859 void ControlPanel::resetCursor() {
860 LOGSECTION("ControlPanel::resetCursor");
861 int n = AgFrame::windowRegistry.size();
862 while (n--) {
863 AgFrame *frame = AgFrame::windowRegistry[n].window;
864 frame->setMousePointer(activeCursor);
865 }
866 if (controlPanel) {
867 controlPanel->setMousePointer(activeCursor);
868 }
869 LOGS("Cursor reset");
870 }
871
872 ControlPanel &ControlPanel::close() {
873 LOGSECTION("ControlPanel::close");
874 closeRect = rect();
875 IFrameWindow::close();
876 return *this;
877 }
878
879 void ControlPanel::quit() {
880 LOGSECTION("ControlPanel::quit");
881 LOGV(analyzeThreadActive);
882 if (analyzeThread.isStarted() || analyzeThreadActive) {
883 analyzeThread.stop();
884 {
885 ICritSec cookie;
886 analyzeThreadActive = 0;
887 quitAction.performDeferred();
888 }
889 return;
890 }
891 int n = AgFrame::windowRegistry.size();
892 if (n) {
893 closeWindows();
894 defer(reset_parser);
895 quitAction.performDeferred();
896 return;
897 }
898 gatherProfile();
899 close();
900 controlPanel = 0;
901 }
902
903 /***********************************************************/
904 /* ControlPanel main window command event handler */
905 /***********************************************************/
906
907 Boolean ControlPanel::systemCommand(ICommandEvent &event) {
908 LOGSECTION("ControlPanel::systemCommand");
909 LOGV(event.commandId());
910 int commandId = event.commandId() & 0xfff0;
911 LOGV(commandId);
912 if (messageBoxShowing) {
913 messageBeep();
914 return true;
915 }
916 if (commandId == ISystemMenu::idClose) {
917 LOGSECTION("ISystemMenu::idClose");
918 quitAction.performDeferred();
919 return true;
920 }
921 else if (commandId == ISystemMenu::idMinimize) {
922 hideWindows();
923 systemMenu.disableItem(ISystemMenu::idMinimize);
924 systemMenu.disableItem(ISystemMenu::idMove);
925 systemMenu.enableItem(ISystemMenu::idRestore);
926 }
927 else if (commandId == ISystemMenu::idRestore) {
928 LOGSECTION("ISystemMenu::idRestore");
929 restoreWindows();
930 systemMenu.enableItem(ISystemMenu::idMinimize);
931 systemMenu.enableItem(ISystemMenu::idMove);
932 systemMenu.disableItem(ISystemMenu::idRestore);
933 return false;
934 }
935 return false;
936 }
937
938 Boolean ControlPanel::deactivated(IFrameEvent &event) {
939 LOGSECTION_OFF("ControlPanel::deactivated");
940 if (event.controlWindow() != this) {
941 return false;
942 }
943 AgFrame::activeWindowCount--;
944 LOGV(AgFrame::activeWindowCount);
945 return false;
946 }
947
948 Boolean ControlPanel::activated(IFrameEvent &event) {
949 LOGSECTION("ControlPanel::activated");
950 if (event.controlWindow() != this) {
951 return false;
952 }
953 AgFrame::activeWindowCount++;
954 LOGV(AgFrame::activeWindowCount);
955 IWindowHandle previous((void *) event.parameter2());
956 IWindow *previousWindow = windowWithHandle(previous);
957 LOGV((int) previousWindow);
958 if (previousWindow == 0) {
959 int k = AgFrame::windowRegistry.size();
960 while (k--) {
961 if (!AgFrame::windowRegistry[k].isActive) {
962 continue;
963 }
964 LOGV(k);
965 AgFrame::windowRegistry[k].window->setFocus();
966 break;
967 }
968 }
969 setFocus();
970 if (isMinimized()) {
971 return false;
972 }
973 //if (!minimized) return false;
974 //minimized = false;
975 int n = AgFrame::windowRegistry.size();
976 for (int i = 0; i< n; i++) {
977 AgFrame *window = AgFrame::windowRegistry[i].window;
978 LOGV(AgFrame::windowRegistry[i].isShowing);
979 LOGV(AgFrame::windowRegistry[i].title.pointer());
980 if (AgFrame::windowRegistry[i].isShowing) {
981 window->show();
982 }
983 }
984 return false;
985 }
986
987 void ControlPanel::findNext() {
988 LOGSECTION("ControlPanel::findNext");
989 AgString key = (char *) searchKeyBox.text();
990 LOGV(key);
991 int n = AgFrame::windowRegistry.size();
992 LOGV(n);
993 AgFrame *window = 0;
994 while (n--) {
995 if (AgFrame::windowRegistry[n].isActive) {
996 window = AgFrame::windowRegistry[n].window;
997 break;
998 }
999 }
1000 LOGV((int) window);
1001 if (window == 0) {
1002 messageBeep();
1003 return;
1004 }
1005 LOGV((int) window);
1006 if (!window->isVisible() || key.size() == 0) {
1007 messageBeep();
1008 return;
1009 }
1010 window->setFocus();
1011 LOGS("focus has been set");
1012 if (!window->findNext(key)) {
1013 messageBeep();
1014 }
1015 n = searchKeyBox.count();
1016 while (n--) {
1017 if (searchKeyBox.itemText(n) == key.pointer()) {
1018 searchKeyBox.remove(n);
1019 break;
1020 }
1021 }
1022 searchKeyBox.addAsFirst(key.pointer());
1023 searchKeyBox.setText(key.pointer());
1024 searchKeyBox.selectRange();
1025 }
1026
1027 void ControlPanel::findPrev() {
1028 LOGSECTION("ControlPanel::findPrev");
1029 AgString key = (char *) searchKeyBox.text();
1030 LOGV(key);
1031 int n = AgFrame::windowRegistry.size();
1032 AgFrame *window = 0;
1033 while (n--) {
1034 if (AgFrame::windowRegistry[n].isActive) {
1035 window = AgFrame::windowRegistry[n].window;
1036 break;
1037 }
1038 }
1039 if (window == 0) {
1040 messageBeep();
1041 return;
1042 }
1043 LOGV((int) window);
1044 if (!window->isVisible() || key.size() == 0) {
1045 messageBeep();
1046 return;
1047 }
1048 window->setFocus();
1049 LOGS("focus has been set");
1050 if (!window->findPrev(key)) messageBeep();
1051 n = searchKeyBox.count();
1052 while (n--) {
1053 if (searchKeyBox.itemText(n) == key.pointer()) {
1054 searchKeyBox.remove(n);
1055 break;
1056 }
1057 }
1058 searchKeyBox.addAsFirst(key.pointer());
1059 searchKeyBox.setText(key.pointer());
1060 searchKeyBox.selectRange();
1061 }
1062
1063 static AgString ascii(int x) {
1064 char buf[20];
1065 itoa(x, buf, 10);
1066 return buf;
1067 }
1068
1069 void ControlPanel::gatherProfile() {
1070 LOGSECTION("ControlPanel::gatherProfile");
1071 AgCharStack charStack;
1072 ColorDialog::stackSettings(charStack);
1073 FontDialog::stackSettings(charStack);
1074 charStack << "Autobuild=" << ascii(autobuildFlag) << '\n';
1075 charStack << "ShowStatistics=" << ascii(showStatsFlag) << '\n';
1076 charStack << "ShowSyntax=" << ascii(showSyntaxFlag) << '\n';
1077 charStack << "StayOnTop=" << ascii(stayOnTopFlag) << '\n';
1078 charStack << "cpLoc=" << position().asString() << '\n';
1079 IString r = syntaxFileRect.asString();
1080 char *q = strchr((char *)r, '(');
1081 charStack << "sfRect=" << q << '\n';
1082 int n = recentFiles.size();
1083 int i = n - 6;
1084 if (i < 0) i = 0;
1085 while (i < n) {
1086 charStack << "RecentFile:" << recentFiles[i] << '\n';
1087 i++;
1088 }
1089 charStack << "Version=" << ascii(INTVERSION) << "\n";
1090 charStack << "endInitializationData";
1091 AgString string = charStack.popString();
1092 LOGV(string);
1093 AgStoreProfile("initializationData", string.pointer());
1094 }
1095
1096 void ControlPanel::rememberFile(AgString fileName) {
1097 LOGSECTION("ControlPanel::rememberFile");
1098 LOGV(fileName);
1099 int n = recentFiles.size();
1100 for (int i = 0; i < n; i++) {
1101 if (recentFiles[i].iEq(fileName)) {
1102 n--;
1103 while (i < n) {
1104 recentFiles[i] = recentFiles[i+1];
1105 i++;
1106 }
1107 recentFiles[i] = fileName;
1108 LOGV(i) LCV(n);
1109 return;
1110 }
1111 }
1112 LOGS("Not there, add it");
1113 if (n >= 12) {
1114 for (i = 0; i < 11; i++) recentFiles[i] = recentFiles[i+1];
1115 recentFiles[i] = fileName;
1116 return;
1117 }
1118 recentFiles.push(fileName);
1119 LOGV(recentFiles.size());
1120 }
1121
1122 Boolean ControlPanel::command(ICommandEvent &cmdEvent) {
1123 IResourceLibrary resLib;
1124
1125 LOGSECTION("ControlPanel::command");
1126 LOGV(cmdEvent.commandId());
1127
1128 LOGV(helpCursorSet);
1129 if (analyzeThreadActive) return true;
1130 if (messageBoxShowing) {
1131 messageBeep();
1132 return true;
1133 }
1134 if (helpCursorSet) {
1135 //setMousePointer(activeCursor);
1136 activeCursor = IPointerHandle();
1137 resetCursor();
1138 helpCursorSet = 0;
1139 AgString topic;
1140 LOGV(ControlPanel::selectedMenuText);
1141 if (!ControlPanel::selectedMenuText.exists()) {
1142 switch (cmdEvent.commandId()) {
1143 case IDI_BMP_AG : selectedMenuText = "Analyze Grammar"; break;
1144 case IDI_BMP_BP : selectedMenuText = "Build Parser"; break;
1145 case IDI_BMP_FT : selectedMenuText = "File Trace"; break;
1146 case IDI_BMP_GT : selectedMenuText = "Grammar Trace"; break;
1147 case IDI_BMP_WARN : selectedMenuText = "Warnings"; break;
1148 case IDI_BMP_CONF : selectedMenuText = "Conflicts"; break;
1149 case IDI_BMP_HELPICON : selectedMenuText = "Help Cursor"; break;
1150 case IDI_BMP_FINDNEXT : selectedMenuText = "Find Next"; break;
1151 case IDI_BMP_FINDPREV : selectedMenuText = "Find Previous"; break;
1152 }
1153 }
1154 LOGV(selectedMenuText);
1155 AgHelpWindow::showHelp(selectedMenuText);
1156 selectedMenuText.discardData();
1157 return true;
1158 }
1159 if (ControlPanel::selectedMenuText.exists()) {
1160 selectedMenuText.discardData();
1161 }
1162 switch (cmdEvent.commandId()) {
1163 case IDI_BMP_HELPICON: {
1164 //MouseDrop *mouseDrop = new MouseDrop(this);
1165 setMousePointer(helpCursor);
1166 helpCursorSet = 1;
1167 int n = AgFrame::windowRegistry.size();
1168 while (n--) {
1169 AgFrame *frame = AgFrame::windowRegistry[n].window;
1170 if (frame->helpCursorSupported) {
1171 frame->setMousePointer(helpCursor);
1172 }
1173 }
1174 return true;
1175 }
1176 case IDI_BMP_AG:
1177 case IDM_ANALYZE: {
1178 // Create and show File open dialog
1179 LOGSECTION("IDM_ANALYZE");
1180 AgFileDialog dialog(this);
1181 dialog.setFilter("Syntax Files\0*.syn\0All Files\0*.*\0");
1182 dialog.setTitle("Analyze Grammar");
1183 dialog.setExt("syn");
1184 if (dialog.showModally()) {
1185 //IPointerHandle pointerHandle = mousePointer();
1186 LOGSECTION("Starting fileread and analysis");
1187 //ISystemPointerHandle waitPointer(ISystemPointerHandle::wait);
1188 activeCursor = waitCursor;
1189 //setMousePointer(waitCursor);
1190 resetCursor();
1191 LOGS("Wait cursor set");
1192 //close_syntax_windows();
1193 //reset_parser();
1194 LOGS("Parser reset");
1195 //logWindows();
1196
1197 closeSyntaxWindows();
1198 AgString fileName = dialog.fileName();
1199 idSyntaxFile(fileName);
1200 *buildErrorMsg = 0;
1201 monitor(analyzeThread);
1202 loadSyntaxFile();
1203 rememberFile(fileName);
1204 IReference<IThreadFn> fn = new AnalyzeGrammarFn(this);
1205 analyzeThread.start(fn);
1206 }
1207 return true;
1208 }
1209 case IDM_REANALYZE: {
1210 LOGSECTION("IDM_REANALYZE");
1211 activeCursor = waitCursor;
1212 resetCursor();
1213 closeSyntaxWindows();
1214 idSyntaxFile(openFileName);
1215 *buildErrorMsg = 0;
1216 monitor(analyzeThread);
1217 loadSyntaxFile();
1218 IReference<IThreadFn> fn = new AnalyzeGrammarFn(this);
1219 analyzeThread.start(fn);
1220 return true;
1221 }
1222 case IDI_BMP_BP:
1223 case IDM_BUILD_PARSER: {
1224 LOGSECTION("IDM_BUILD_PARSER");
1225 AgFileDialog dialog(this);
1226 dialog.setFilter("Syntax Files\0*.syn\0All Files\0*.*\0");
1227 dialog.setTitle("Build Parser");
1228 dialog.setExt("syn");
1229 if (!dialog.showModally()) {
1230 return true;
1231 }
1232 activeCursor = waitCursor;
1233 resetCursor();
1234 closeSyntaxWindows();
1235 AgString fileName = dialog.fileName();
1236 idSyntaxFile(fileName);
1237 monitor(analyzeThread);
1238 loadSyntaxFile();
1239 buildErrorMsg[0] = 0;
1240 rememberFile(fileName);
1241 IReference<IThreadFn> fn = new BuildParserFn(this);
1242 analyzeThread.start(fn);
1243
1244 return true;
1245
1246 }
1247 case IDM_REBUILD: {
1248 LOGSECTION("IDM_REBUILD");
1249 restoreDirectory();
1250 activeCursor = waitCursor;
1251 closeSyntaxWindows();
1252 idSyntaxFile(openFileName);
1253 monitor(analyzeThread);
1254 loadSyntaxFile();
1255 buildErrorMsg[0] = 0;
1256 IReference<IThreadFn> fn = new BuildParserFn(this);
1257 analyzeThread.start(fn);
1258 return true;
1259 }
1260 case IDM_BUILD: {
1261 LOGSECTION("IDM_BUILD");
1262 restoreDirectory();
1263 monitor(analyzeThread);
1264 activeCursor = waitCursor;
1265 resetCursor();
1266 *buildErrorMsg = 0;
1267 IReference<IThreadFn> fn = new BuildParserFn(this);
1268 analyzeThread.start(fn);
1269 return true;
1270 }
1271 case IDM_COPY: {
1272 IClipboard clipboard(handle());
1273 clipboard.empty();
1274 int n = AgFrame::windowRegistry.size();
1275 while (n--) {
1276 if (AgFrame::windowRegistry[n].isActive) {
1277 LOGS("found it");
1278 AgFrame::windowRegistry[n].window->copyTo(clipboard);
1279 break;
1280 }
1281 }
1282 return true;
1283 }
1284 case IDM_EXIT: {
1285 LOGSECTION("IDM_EXIT");
1286 if (analyzeThread.isStarted()) {
1287 analyzeThread.stop();
1288 }
1289 quitAction.performDeferred();
1290 return true;
1291 }
1292 case IDI_BMP_WARN: {
1293 LOGSECTION("IDI_BMP_WARN");
1294 if (errorList.size()) {
1295 pop_up_window(new error_display_dc);
1296 }
1297 else {
1298 messageBeep();
1299 }
1300 return 1;
1301 }
1302 case IDI_BMP_CONF: {
1303 LOGSECTION("IDI_BMP_CONF");
1304 if (unres_con->nt) {
1305 pop_up_window(new unres_con_dc);
1306 }
1307 else {
1308 messageBeep();
1309 }
1310 return 1;
1311 }
1312 case IDM_ERROR_TRACE: {
1313 LOGSECTION("IDM_ERROR_TRACE");
1314 AgFileDialog dialog(this);
1315 dialog.setFilter("Trace Files\0*.etr\0All Files\0*.*\0");
1316 dialog.setTitle("Select Error Trace File");
1317 dialog.setExt("etr");
1318 if (dialog.showModally()) {
1319 etr_file_name = dialog.fileName();
1320 FILE *ag_file = fopen(etr_file_name.pointer(), "r");
1321 LOGV(etr_file_name.pointer());
1322 LOGV((int) ag_file);
1323 if (ag_file == 0) {
1324 AgString msg = AgString::format("Cannot open %s",
1325 etr_file_name.pointer());
1326 IMessageBox messageBox(controlPanel);
1327 messageBoxShowing++;
1328 messageBox.show(msg.pointer(), IMessageBox::information);
1329 messageBoxShowing--;
1330 return true;
1331 }
1332 if (getFileTimestamp(etr_file_name.pointer()) < openFileTimestamp) {
1333 IMessageBox messageBox(controlPanel);
1334 messageBoxShowing++;
1335 if (messageBox.show("Trace file is older than syntax",
1336 IMessageBox::okCancelButton)
1337 == IMessageBox::cancel) {
1338 return true;
1339 }
1340 messageBoxShowing--;
1341 }
1342 LOGV(etr_file_name.pointer());
1343 LOGV((int) &etr_file_name);
1344 tsd *et = build_et(ag_file);
1345 fclose(ag_file);
1346 GTWindow *trace = new GTWindow(et, "Error Trace", etr_file_name);
1347 delete_tsd(et);
1348 trace->setAutoDeleteObject();
1349 }
1350 return true;
1351 }
1352 case IDI_BMP_GT:
1353 if (syntax_state < syntax_analyzed) {
1354 messageBeep();
1355 return true;
1356 }
1357 case IDM_GRAMMAR_TRACE: {
1358 if (syntax_state < syntax_analyzed) {
1359 return true;
1360 }
1361 LOGSECTION("IDM_GRAMMAR_TRACE");
1362 //GTWindow *trace = new GTWindow(0);
1363 GTWindow *trace = new GTWindow(0, "Grammar Trace");
1364 trace->setAutoDeleteObject();
1365 return true;
1366 }
1367 case IDI_BMP_FT:
1368 if (syntax_state < syntax_analyzed) {
1369 messageBeep();
1370 return true;
1371 }
1372 case IDM_FILE_TRACE: {
1373 if (syntax_state < syntax_analyzed) {
1374 return true;
1375 }
1376 LOGSECTION("IDM_FILE_TRACE");
1377 // Create and show File open dialog
1378 AgFileDialog dialog(this);
1379 //char buf[200];
1380 //if (strcmp(test_file_mask, "*.*") == 0) {
1381 if (test_file_mask == "*.*") {
1382 dialog.setFilter("All Files\0*.*\0");
1383 }
1384 else {
1385 char buf[200];
1386 sprintf(buf, "Test Files%c%s%cAll Files%c*.*%c", 0,
1387 test_file_mask.pointer(), 0, 0, 0);
1388 LOGV(buf);
1389 dialog.setFilter(buf);
1390 /*
1391 sss("Test Files");
1392 acs(0);
1393 ass(test_file_mask.pointer());
1394 acs(0);
1395 ass("All Files");
1396 acs(0);
1397 ass("*.*");
1398 acs(0);
1399 acs(0);
1400 dialog.setFilter(string_base);
1401 rcs();
1402 */
1403 }
1404 dialog.setTitle("Select Test File");
1405 AgString ext = test_file_mask.lastCut('.').rightX();
1406 if (!ext.firstCut('*').exists()) {
1407 dialog.setExt(ext.pointer());
1408 }
1409 if (dialog.showModally()) {
1410 AgString fileName = dialog.fileName();
1411 LOGV(fileName.pointer());
1412
1413 int flags = (test_file_binary ? O_BINARY : O_TEXT) | O_RDONLY;
1414 FileTraceWindow *trace = new FileTraceWindow(fileName, flags);
1415 trace->setAutoDeleteObject();
1416 }
1417 return true;
1418 }
1419 case IDM_EDIT_FIND:
1420 searchKeyBox.setFocus();
1421 return true;
1422 case IDM_EDIT_FINDNEXT:
1423 case IDI_BMP_FINDNEXT: {
1424 LOGSECTION("IDI_BMP_FINDNEXT");
1425 findNext();
1426 return true;
1427 }
1428 case IDM_EDIT_FINDPREV:
1429 case IDI_BMP_FINDPREV: {
1430 LOGSECTION("IDI_BMP_FINDPREV");
1431 findPrev();
1432 return true;
1433 }
1434 case IDM_AUTOBUILD: {
1435 autobuildFlag = !autobuildFlag;
1436 return true;
1437 }
1438 case IDM_SHOW_SYNTAX: {
1439 showSyntaxFlag = !showSyntaxFlag;
1440 return true;
1441 }
1442 case IDM_SHOW_STATS: {
1443 LOGSECTION("IDM_SHOW_STATS");
1444 showStatsFlag = !showStatsFlag;
1445 return true;
1446 }
1447 case IDM_STAY_ON_TOP: {
1448 stayOnTopFlag = !stayOnTopFlag;
1449 return true;
1450 }
1451 case IDM_COLORS: {
1452 LOGSECTION("IDM_COLORS");
1453 ColorDialog *dialog =
1454 (ColorDialog *) AgFrame::windowRegistry.find("Set Colors");
1455 if (dialog == 0) {
1456 dialog = new ColorDialog;
1457 dialog->setAutoDeleteObject();
1458 }
1459 dialog->show();
1460 dialog->mySetFocus();
1461 return true;
1462 }
1463 case IDM_FONT: {
1464 LOGSECTION("IDM_FONT");
1465 FontDialog *dialog =
1466 (FontDialog *) AgFrame::windowRegistry.find("Set Fonts");
1467 if (dialog == 0) {
1468 dialog = new FontDialog;
1469 dialog->setAutoDeleteObject();
1470 }
1471 dialog->show();
1472 dialog->mySetFocus();
1473 return true;
1474 }
1475 case IDM_HELP_PROG_DEV: {
1476 AgHelpWindow::showHelp("Program Development");
1477 return true;
1478 }
1479 case IDM_HELP_START: {
1480 //AgHelpWindow *helpWindow =
1481 // new AgHelpWindow(controlPanel, "Getting Started");
1482 //AgHelpWindow *helpWindow = new AgHelpWindow("Getting Started");
1483 //helpWindow->setAutoDeleteObject();
1484 AgHelpWindow::showHelp("Getting Started");
1485 return true;
1486 }
1487 case IDM_HELP_NEW: {
1488 AgHelpWindow::showHelp("What's New");
1489 return true;
1490 }
1491 case IDM_HELP_LICENSE: {
1492 AgHelpWindow::showHelp("License");
1493 return true;
1494 }
1495 case IDM_HELP_INDEX: {
1496 LOGSECTION("IDM_HELP_INDEX");
1497 help_index_dc *help_index = new help_index_dc;
1498 AgDataViewPlug *connector = new AgDataViewPlug(help_index);
1499 help_index->windowConnector = connector;
1500 AgDataPanel *helpWindow = new AgDataPanel(connector);
1501 helpWindow->dataView->setEnterAction(
1502 actionObject(helpWindow->dataView, AgDataView::showHelp)
1503 );
1504 helpWindow->setAutoDeleteObject();
1505 helpWindow->show().setFocus();
1506 return true;
1507 }
1508 case IDM_HELP_USING: {
1509 AgHelpWindow::showHelp("Using Help");
1510 return true;
1511 }
1512 case IDM_HELP_PRODINFO: {
1513 LOGSECTION("IDM_HELP_PRODINFO");
1514 AgFrame *productInfo = AgFrame::windowRegistry.find("About AnaGram");
1515 if (productInfo == 0) {
1516 productInfo = new AboutBox();
1517 productInfo->setAutoDeleteObject();
1518 IPoint where = (IPair) place(IWindow::desktopWindow()->size(),
1519 productInfo->size(), 11);
1520 productInfo->moveTo(where);
1521 }
1522 productInfo->show().setFocus();
1523 LOGS("About box should be showing");
1524 return true;
1525 }
1526 case IDM_CHAR_MAP:
1527 pop_up_window(new char_map_dc);
1528 return true;
1529 case IDM_CHAR_SETS:
1530 pop_up_window(new char_set_dc);
1531 return true;
1532 case IDM_UNRES_CON:
1533 pop_up_window(new unres_con_dc);
1534 return true;
1535 case IDM_CONFIG_PARAM:
1536 LOGS("Select config params");
1537 pop_up_window(new param_table_dc);
1538 return true;
1539 case IDM_ANOMALY_TABLE:
1540 pop_up_window(new anomaly_table_dc);
1541 return true;
1542 case IDM_KEYWORD_TABLE:
1543 pop_up_window(new keyword_table_dc);
1544 return true;
1545 case IDM_PARTITION_SETS:
1546 pop_up_window(new partition_table_dc);
1547 return true;
1548 case IDM_PROC_TABLE:
1549 pop_up_window(new proc_table_dc);
1550 return true;
1551 case IDM_RES_CON:
1552 pop_up_window(new res_con_dc);
1553 return true;
1554 case IDM_RULE_TABLE:
1555 pop_up_window(new rule_table_dc);
1556 return true;
1557 case IDM_STATE_TABLE:
1558 pop_up_window(new state_table_dc);
1559 return true;
1560 case IDM_SYMBOL_TABLE:
1561 pop_up_window(new symbol_table_dc);
1562 return true;
1563 case IDM_TRACE_COUNTS:
1564 //pop_up_window(new rule_count_dc("Trace Coverage", trace_counts));
1565 pop_up_window(new rule_count_dc("Trace Coverage", traceCounts));
1566 return true;
1567 case IDM_TOKEN_TABLE:
1568 pop_up_window(new token_table_dc);
1569 return true;
1570 case IDM_ERROR_TABLE: {
1571 pop_up_window(new error_display_dc);
1572 return true;
1573 }
1574 case IDM_RULE_COUNTS: {
1575 LOGSECTION("IDM_RULE_COUNTS");
1576 AgFileDialog dialog(this);
1577 dialog.setFilter("Coverage Files\0*.nrc\0All Files\0*.*\0");
1578 dialog.setTitle("Select Rule Coverage File");
1579 dialog.setExt("nrc");
1580 if (dialog.showModally()) {
1581 AgString fileName = dialog.fileName();
1582 FILE *ag_file = fopen(fileName.pointer(), "r");
1583 LOGV(fileName.pointer());
1584 LOGV((int) ag_file);
1585 if (ag_file == 0) {
1586 AgString msg = AgString::format("Cannot open %s",
1587 fileName.pointer());
1588 IMessageBox messageBox(controlPanel);
1589 messageBoxShowing++;
1590 messageBox.show(msg.pointer(), IMessageBox::information);
1591 messageBoxShowing--;
1592 return true;
1593 }
1594 fclose(ag_file);
1595 if (getFileTimestamp(fileName.pointer()) < openFileTimestamp) {
1596 IMessageBox messageBox(controlPanel);
1597 messageBoxShowing++;
1598 IMessageBox::Response response =
1599 messageBox.show("Coverage file is older than syntax",
1600 IMessageBox::okCancelButton);
1601 messageBoxShowing--;
1602 if (response == IMessageBox::cancel) {
1603 return true;
1604 }
1605 }
1606 LOGV(fileName.pointer());
1607 dc_ref windowData = read_counts(fileName);
1608 if (windowData.exists()) {
1609 pop_up_window(read_counts(fileName));
1610 return true;
1611 }
1612 IMessageBox messageBox(controlPanel);
1613 messageBoxShowing++;
1614 messageBox.show("Not a valid coverage file",
1615 IMessageBox::okButton);
1616 messageBoxShowing--;
1617 }
1618 return true;
1619 }
1620 case IDM_STATISTICS: {
1621 LOGSECTION("IDM_STATISTICS");
1622 if (AgFrame::windowRegistry.action("Statistical Summary")) {
1623 return true;
1624 }
1625 AgFrame *window = new StatisticsWindow();
1626 window->setAutoDeleteObject();
1627 window->positionFrame();
1628 window->show().setFocus();
1629 return true;
1630 }
1631 case IDM_SYNTAX_FILE: {
1632 LOGSECTION("IDM_SYNTAX_FILE");
1633 if (AgFrame::windowRegistry.action(syntaxFileId)) {
1634 return true;
1635 }
1636 LOGS("Not in registry");
1637 syntaxFileId = nextChildId();
1638 FileWindow *fileWindow = new FileWindow(syntaxFileId, inputFile,
1639 syntaxFileRect);
1640 fileWindow->enableCursorBar();
1641 fileWindow->setAutoDeleteObject();
1642 fileWindow->syntaxDependent = 1;
1643 //IPoint where = (IPair) place(IWindow::desktopWindow()->size(),
1644 // fileWindow->size(), 22);
1645 if (syntaxFileRect.area() <= 0) {
1646 AgQuadrant quad = findQuadrant(controlPanel);
1647 if (quad == lowerRight) {
1648 quad = upperRight;
1649 }
1650 else {
1651 quad = lowerRight;
1652 }
1653 AgRectangle bestRect(
1654 AgRectangle::desktop().position(quad),
1655 fileWindow->size(),
1656 opposite(quad)
1657 );
1658 IPoint where = (IPair) bestRect.position();
1659 fileWindow->moveTo(where);
1660 }
1661 //cascadeOffset -= cascadeIncrement;
1662 fileWindow->show().setFocus();
1663 LOGS("file created");
1664 return true;
1665 }
1666 case IDM_CASCADE: {
1667 LOGSECTION("IDM_CASCADE");
1668 int n = AgFrame::windowRegistry.size();
1669 AgFrame::windowRegistry.cascadeFlag++;
1670 LOGV(n);
1671 if (n == 0) {
1672 return true;
1673 }
1674 cascadeOffset = cascadeOrigin;
1675 for (int i = 0; i < n; i++) {
1676 WindowRecord &windowRecord = AgFrame::windowRegistry[i];
1677 LOGV(windowRecord.title.pointer());
1678 LOGV(cascadeOffset.asString());
1679 windowRecord.window->positionFrame();
1680 windowRecord.window->show().mySetFocus();
1681 windowRecord.isActive = 0;
1682 }
1683 if (n) {
1684 AgFrame::windowRegistry[n-1].isActive = 1;
1685 }
1686 AgFrame::windowRegistry.cascadeFlag--;
1687 return true;
1688 }
1689 case IDM_CLOSE_WINDOWS: {
1690 closeWindows();
1691 return true;
1692 }
1693 case IDM_HIDE_WINDOWS: {
1694 hideWindows();
1695 return true;
1696 }
1697 case IDM_RESTORE_WINDOWS: {
1698 restoreWindows();
1699 return true;
1700 }
1701 default: {
1702 LOGSECTION("defaultCommand");
1703 LOGV(cmdEvent.commandId());
1704 LOGV(IDM_RECENT_FILES);
1705 unsigned fileIndex = cmdEvent.commandId() - IDM_RECENT_FILES;
1706 LOGV(fileIndex);
1707 LOGV(recentFiles.size());
1708 if (fileIndex < recentFiles.size()) {
1709 LOGSECTION("RecentFile");
1710 AgString fileName = recentFiles[fileIndex];
1711 FILE *f = fopen(fileName.pointer(), "r");
1712 if (f == 0) {
1713 char msg[MAX_PATH+100];
1714 sprintf(msg, "Cannot open %s", fileName.pointer());
1715 IMessageBox messageBox(controlPanel);
1716 messageBoxShowing++;
1717 messageBox.show(msg, IMessageBox::information);
1718 messageBoxShowing--;
1719 return true;
1720 }
1721 fclose(f);
1722 LOGS("Starting fileread and analysis");
1723 activeCursor = waitCursor;
1724 resetCursor();
1725 closeSyntaxWindows();
1726 idSyntaxFile(fileName);
1727 monitor(analyzeThread);
1728 loadSyntaxFile();
1729 buildErrorMsg[0] = 0;
1730 LOGV((int) &analyzeThread);
1731 LOGV((int) &IThread::current());
1732 rememberFile(fileName);
1733 if (autobuildFlag) {
1734 IReference<IThreadFn> fn = new BuildParserFn(this);
1735 analyzeThread.start(fn);
1736 }
1737 else {
1738 IReference<IThreadFn> fn = new AnalyzeGrammarFn(this);
1739 analyzeThread.start(fn);
1740 }
1741 return true;
1742 }
1743 if (AgFrame::windowRegistry.action(cmdEvent.commandId())) {
1744 return true;
1745 }
1746 }
1747 } /* end switch */
1748 return false;
1749 }
1750
1751
1752 Boolean ControlPanel::menuSelected(IMenuEvent &event) {
1753 LOGSECTION_OFF("ControlPanel::menuSelected");
1754 IMenuItem menuItem = event.menuItem();
1755 selectedMenuText = removeTilde(menuItem.text());
1756 LOGV(selectedMenuText.pointer());
1757 selectedMenuText = selectedMenuText.lastCut(':').leftX();
1758 char *menuName[] = {"Action", "Browse", "Options", "Windows", "Help"};
1759 for (int i = 0; i < 5; i++) {
1760 if (selectedMenuText == menuName[i]) {
1761 break;
1762 }
1763 }
1764 if (i < 5) {
1765 selectedMenuText = selectedMenuText.concat(" Menu");
1766 }
1767 LOGV(selectedMenuText.pointer());
1768 return false;
1769 }
1770
1771 AgString ControlPanel::selectedMenuText;
1772
1773 Boolean ControlPanel::menuShowing(IMenuEvent &event, ISubmenu &submenu) {
1774 LOGSECTION_OFF("ControlPanel::menuShowing");
1775 LOGV(event.menuItemId());
1776 AgFrame::menuShowingFlag = 1;
1777 LOGV(AgFrame::menuShowingFlag);
1778 switch (event.menuItemId()) {
1779 case IDM_OPTIONS: {
1780 submenu.checkItem(IDM_AUTOBUILD, autobuildFlag);
1781 submenu.checkItem(IDM_SHOW_SYNTAX, showSyntaxFlag);
1782 submenu.checkItem(IDM_SHOW_STATS, showStatsFlag);
1783 submenu.checkItem(IDM_STAY_ON_TOP, stayOnTopFlag);
1784 return true;
1785 }
1786 }
1787 if (helpCursorSet) {
1788 return true;
1789 }
1790 switch (event.menuItemId()) {
1791 case IDM_FILE: {
1792 LOGSECTION_OFF("File Menu Showing");
1793 LOGV(syntax_state);
1794 if (simple_file_name.exists()) {
1795 IMenuItem item = submenu.menuItem(IDM_BUILD);
1796 AgString text = AgString::format("Bui%cld %s", TILDE,
1797 simple_file_name.pointer());
1798 item.setText(text.pointer());
1799 submenu.setItem(item);
1800 LOGV(text.pointer());
1801 LOGV((char *) item.text());
1802 }
1803 if (syntax_state == syntax_analyzed ||
1804 (syntax_state > syntax_reset && syntax_state < syntax_analyzed &&
1805 getFileTimestamp(openFileName.pointer()) > openFileTimestamp)) {
1806 LOGV("syntax analyzed");
1807 }
1808 else {
1809 submenu.disableItem(IDM_BUILD);
1810 }
1811 if (simple_file_name.exists()) {
1812 IMenuItem item = submenu.menuItem(IDM_REBUILD);
1813 AgString text = AgString::format("Rebuil%cd %s", TILDE,
1814 simple_file_name.pointer());
1815 item.setText(text.pointer());
1816 submenu.setItem(item);
1817 LOGV(text.pointer());
1818 LOGV((char *) item.text());
1819 }
1820 if (syntax_state == engine_built) {
1821 if (getFileTimestamp(openFileName.pointer()) <= openFileTimestamp) {
1822 submenu.disableItem(IDM_REBUILD);
1823 }
1824 }
1825 else {
1826 submenu.disableItem(IDM_REBUILD);
1827 }
1828 if (simple_file_name.exists()) {
1829 AgString text = AgString::format("%cReanalyze %s", TILDE,
1830 simple_file_name.pointer());
1831 IMenuItem item = submenu.menuItem(IDM_REANALYZE);
1832 item.setText(text.pointer());
1833 submenu.setItem(item);
1834 LOGV(text.pointer());
1835 LOGV((char *) item.text());
1836 }
1837 if (syntax_state > syntax_reset) {
1838 if (getFileTimestamp(openFileName.pointer()) <= openFileTimestamp) {
1839 submenu.disableItem(IDM_REANALYZE);
1840 }
1841 }
1842 else {
1843 submenu.disableItem(IDM_REANALYZE);
1844 }
1845
1846 if (!error_trace || syntax_state < syntax_analyzed) {
1847 submenu.disableItem(IDM_ERROR_TRACE);
1848 }
1849 if (syntax_state < syntax_analyzed) {
1850 submenu.disableItem(IDM_GRAMMAR_TRACE);
1851 }
1852 LOGV(char_set_dict->nsx);
1853 if (syntax_state < syntax_analyzed
1854 || char_set_dict->nsx <= 1
1855 || badRecursionFlag) {
1856 submenu.disableItem(IDM_FILE_TRACE);
1857 }
1858
1859 if (recentFiles.size() == 0) {
1860 return true;
1861 }
1862 LOGV(recentFiles.size());
1863 submenu.addSeparator(1000);
1864 int i;
1865 int nFiles = recentFiles.size();
1866 int n = nFiles;
1867 for (i = 1; i <= n; i++) {
1868 AgString fileName = recentFiles[nFiles-i];
1869 int length = fileName.size();
1870 char text[_MAX_PATH + 10];
1871 if (length > 35) {
1872 char head[30];
1873 strncpy(head, fileName.pointer(), 15);
1874 head[15] = 0;
1875 sprintf(text, "%c%d. %s ... %s", TILDE, i, head,
1876 fileName.pointer() + length - 15);
1877 }
1878 else {
1879 sprintf(text, "%c%d. %s", TILDE, i, fileName.pointer());
1880 }
1881 submenu.addText(IDM_RECENT_FILES + nFiles-i, text);
1882 }
1883 return true;
1884 }
1885 case IDM_BROWSE: {
1886 LOGSECTION_OFF("IDM_BROWSE");
1887 if (syntax_state < syntax_analyzed) {
1888 submenu.disableItem(IDM_RES_CON);
1889 submenu.disableItem(IDM_UNRES_CON);
1890 submenu.disableItem(IDM_STATE_TABLE);
1891 submenu.disableItem(IDM_ANOMALY_TABLE);
1892 }
1893 else {
1894 if (key_mess->nt == 0) {
1895 submenu.disableItem(IDM_ANOMALY_TABLE);
1896 }
1897 if (unres_con->nt == 0) {
1898 submenu.disableItem(IDM_UNRES_CON);
1899 }
1900 if (prr->nt == 0) {
1901 submenu.disableItem(IDM_RES_CON);
1902 }
1903 }
1904 if (syntax_state < syntax_parsed) {
1905 submenu.disableItem(IDM_CHAR_MAP);
1906 submenu.disableItem(IDM_CHAR_SETS);
1907 submenu.disableItem(IDM_RULE_TABLE);
1908 submenu.disableItem(IDM_PROC_TABLE);
1909 submenu.disableItem(IDM_RULE_COUNTS);
1910 submenu.disableItem(IDM_TOKEN_TABLE);
1911 submenu.disableItem(IDM_SYMBOL_TABLE);
1912 submenu.disableItem(IDM_TRACE_COUNTS);
1913 submenu.disableItem(IDM_KEYWORD_TABLE);
1914 submenu.disableItem(IDM_PARTITION_SETS);
1915 submenu.disableItem(IDM_STATISTICS);
1916 }
1917 else {
1918 if (n_chars == 0) {
1919 submenu.disableItem(IDM_CHAR_MAP);
1920 }
1921 if (char_set_dict->nsx <= 1) {
1922 submenu.disableItem(IDM_CHAR_SETS);
1923 }
1924 if (Keyword::count() <= 1) {
1925 submenu.disableItem(IDM_KEYWORD_TABLE);
1926 }
1927 if (part_dict->nsx <= 1) {
1928 submenu.disableItem(IDM_PARTITION_SETS);
1929 }
1930 if (Procedure::count() <= 1) {
1931 submenu.disableItem(IDM_PROC_TABLE);
1932 }
1933 if (!rule_coverage) {
1934 submenu.disableItem(IDM_RULE_COUNTS);
1935 }
1936 if (!traceCounts.exists()) {
1937 submenu.disableItem(IDM_TRACE_COUNTS);
1938 }
1939 }
1940
1941 int disableFlag = true;
1942 LOGS("disable syntax file selection");
1943 LOGV(disableFlag);
1944 if (simple_file_name.exists()) {
1945 AgString text = AgString::format("Syntax %cFile - %s", TILDE,
1946 simple_file_name.pointer());
1947 IMenuItem item = submenu.menuItem(IDM_SYNTAX_FILE);
1948 item.setText(text.pointer());
1949 submenu.setItem(item);
1950 LOGV(text.pointer());
1951 disableFlag = 0;
1952 }
1953 LOGV(disableFlag);
1954 if (disableFlag) {
1955 submenu.disableItem(IDM_SYNTAX_FILE);
1956 }
1957 LOGS("disableFlag set");
1958
1959 if (errorList.size() == 0) {
1960 submenu.disableItem(IDM_ERROR_TABLE);
1961 }
1962 return true;
1963 }
1964 case IDM_WINDOWS: {
1965 LOGSECTION_OFF("IDM_WINDOWS");
1966 int ln;
1967 int n = AgFrame::windowRegistry.size();
1968 LOGV(n);
1969 if (n == 0) {
1970 submenu.disableItem(IDM_CASCADE);
1971 submenu.disableItem(IDM_CLOSE_WINDOWS);
1972 submenu.disableItem(IDM_HIDE_WINDOWS);
1973 submenu.disableItem(IDM_RESTORE_WINDOWS);
1974 submenu.disableItem(IDM_COPY);
1975 return true;
1976 }
1977 else {
1978 int i, k;
1979 for (i = k = 0; i < n; i++) {
1980 if (!AgFrame::windowRegistry[i].window->isVisible()) {
1981 k++;
1982 }
1983 }
1984 if (k == 0) {
1985 submenu.disableItem(IDM_RESTORE_WINDOWS);
1986 }
1987
1988 for (i = k = 0; i < n; i++) {
1989 if (AgFrame::windowRegistry[i].window->isVisible()) {
1990 k++;
1991 }
1992 }
1993 if (k == 0) {
1994 submenu.disableItem(IDM_HIDE_WINDOWS);
1995 }
1996 }
1997
1998 AgFrame *activeWindow = 0;
1999 while (n--) {
2000 if (AgFrame::windowRegistry[n].isActive) {
2001 activeWindow = AgFrame::windowRegistry[n].window;
2002 break;
2003 }
2004 }
2005 LOGV((int) activeWindow);
2006 if (activeWindow) {
2007 LOGV(activeWindow->copyTitle());
2008 }
2009 int disableFlag =
2010 (activeWindow == 0) || !activeWindow->copyTitle().exists();
2011 if (disableFlag) {
2012 submenu.disableItem(IDM_COPY);
2013 }
2014 else {
2015 char buf[200];
2016 sprintf(buf, "Co%cpy %s", TILDE, activeWindow->copyTitle().pointer());
2017 IMenuItem item = submenu.menuItem(IDM_COPY);
2018 item.setDisabled(disableFlag);
2019 item.setText(buf);
2020 submenu.setItem(item);
2021 }
2022 submenu.addSeparator(10000);
2023 int itemHeight = submenu.itemRect(IDM_COPY).size().height();
2024 LOGV(submenu.itemRect(IDM_COPY).asString()) LCV(itemHeight);
2025 if (itemHeight == 0) {
2026 itemHeight = submenu.font().maxCharHeight();
2027 LOGV(itemHeight);
2028 }
2029 int magicNumber = IWindow::desktopWindow()->size().height()/itemHeight;
2030 LOGV(magicNumber);
2031
2032 n = AgFrame::windowRegistry.size();
2033 for (ln = 0; ln < n; ln++) {
2034 WindowRecord &windowRecord = AgFrame::windowRegistry[ln];
2035 int view = windowRecord.window->windowTitle.viewNumber();
2036 AgString title = windowRecord.title;
2037 if (view) {
2038 char buf[10];
2039 sprintf(buf, ":%d", view);
2040 title = windowRecord.title.concat(buf);
2041 }
2042 submenu.addText(windowRecord.id, title.pointer());
2043 //submenu.checkItem(windowRecord.id, windowRecord.isActive);
2044
2045 IMenuItem item(windowRecord.id);
2046 item.setText(title.pointer());
2047 item.setChecked(windowRecord.isActive);
2048 if ((ln + 7) % magicNumber == 0) {
2049 item.setLayout(IMenuItem::splitWithSeparatorLayout);
2050 }
2051 submenu.setItem(item);
2052 LOGV(windowRecord.title.pointer());
2053 }
2054 return true;
2055 }
2056 }
2057 return false;
2058 }
2059
2060 Boolean ControlPanel::menuEnded(IMenuEvent &event) {
2061 LOGSECTION("ControlPanel::menuEnded");
2062 LOGV(selectedMenuText);
2063 AgFrame::menuShowingFlag = 0;
2064 LOGV(AgFrame::menuShowingFlag);
2065 if (helpRequested) {
2066 AgHelpWindow::showHelp(selectedMenuText);
2067 helpRequested = 0;
2068 }
2069 if (!helpCursorSet) {
2070 selectedMenuText.discardData();
2071 }
2072 return false;
2073 }
2074
2075 void ControlPanel::closeWindows() {
2076 LOGSECTION("ControlPanel::closeWindows");
2077 int n = AgFrame::windowRegistry.size();
2078 LOGV(n);
2079 AgStack<AgFrame*> windowStack;
2080 for (int i = 0; i< n; i++) {
2081 AgFrame *window = AgFrame::windowRegistry[i].window;
2082 windowStack.push(window);
2083 LOGV(AgFrame::windowRegistry[i].title.pointer());
2084 window->closeModalDialog();
2085 window->closeAction.performDeferred();
2086 }
2087 while(windowStack.size()) {
2088 AgFrame *window = windowStack.pop();
2089 AgFrame::windowRegistry.remove(window->id());
2090 }
2091 cascadeOffset = cascadeOrigin;
2092 }
2093
2094 void ControlPanel::hideWindows() {
2095 LOGSECTION("ControlPanel::hideWindows");
2096 int n = AgFrame::windowRegistry.size();
2097 for (int i = 0; i< n; i++) {
2098 AgFrame *window = AgFrame::windowRegistry[i].window;
2099 LOGV(AgFrame::windowRegistry[i].title.pointer());
2100 AgFrame::windowRegistry[i].isShowing = window->isVisible();
2101 window->hide();
2102 AgFrame::windowRegistry[i].isActive = 0;
2103 }
2104 }
2105
2106 void ControlPanel::restoreWindows() {
2107 LOGSECTION("ControlPanel::restoreWindows");
2108 int n = AgFrame::windowRegistry.size();
2109 int i;
2110 int active = AgFrame::windowRegistry.size();
2111 for (i = 0; i< n; i++) {
2112 LOGV(AgFrame::windowRegistry[i].isShowing);
2113 LOGV(AgFrame::windowRegistry[i].title.pointer());
2114 AgFrame::windowRegistry[i].window->IWindow::show();
2115 AgFrame::windowRegistry[i].isShowing = 0;
2116 if (AgFrame::windowRegistry[i].isActive) {
2117 active = i;
2118 }
2119 }
2120 n = AgFrame::windowRegistry.size();
2121 if (active && active < n) {
2122 AgFrame::windowRegistry[active].window->mySetFocus();
2123 }
2124 }
2125
2126 void ControlPanel::closeSyntaxWindows() {
2127 LOGSECTION("ControlPanel::closeSyntaxWindows");
2128 int n = AgFrame::windowRegistry.size();
2129 AgStack<AgFrame*> windowStack;
2130 for (int i = 0; i < n; i++) {
2131 AgFrame *window = AgFrame::windowRegistry[i].window;
2132 if (!window->syntaxDependent) {
2133 continue;
2134 }
2135 window->closeModalDialog();
2136 window->closeAction.performDeferred();
2137 windowStack.push(window);
2138 }
2139 while(windowStack.size()) {
2140 AgFrame *window = windowStack.pop();
2141 AgFrame::windowRegistry.remove(window->id());
2142 }
2143
2144 if (AgFrame::windowRegistry.size() == 0) {
2145 cascadeOffset = cascadeOrigin;
2146 }
2147 }