Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/vaclgui/gtview.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 * gtview.cpp | |
7 */ | |
8 | |
9 //#include <commctrl.h> | |
10 //#include <imsgbox.hpp> | |
11 #include <windows.h> | |
12 | |
13 #include "agstring.h" | |
14 #include "arrays.h" | |
15 #include "ctrlpanel.hpp" | |
16 #include "data.h" | |
17 #include "dc.h" | |
18 #include "dspar.hpp" | |
19 #include "dvplug.hpp" | |
20 #include "gtview.hpp" | |
21 #include "helpview.hpp" | |
22 #include "minmax.h" | |
23 #include "myalloc.h" | |
24 #include "p.h" | |
25 #include "rule.h" | |
26 #include "tracedc.h" | |
27 #include "vaclgui-res.h" | |
28 #include "vaclgui.hpp" | |
29 | |
30 //#define INCLUDE_LOGGING | |
31 #include "log.h" | |
32 | |
33 | |
34 #define RESET "&Reset" | |
35 #define HELP "&Help" | |
36 #define PROCEED "&Proceed" | |
37 #define SINGLE_STEP "&Single step" | |
38 | |
39 //static char *buttonLabel[] = { | |
40 // RESET, HELP, PROCEED, SINGLE_STEP | |
41 //}; | |
42 | |
43 GTView::GTView(GTWindow *owner_, DcRef<FtParserDc> parserDc_) | |
44 : ICanvas(nextChildId(), owner_, owner_, IRectangle(), | |
45 ICanvas::classDefaultStyle | IWindow::clipChildren) | |
46 , parserDc(parserDc_) | |
47 , parser(parserDc->parser) | |
48 , stackViewData(new AgDataViewPlug(parserDc)) | |
49 , mainSplitter(nextChildId(), this, this, | |
50 IRectangle(), ISplitCanvas::horizontal | IWindow::visible) | |
51 , tracePanels(nextChildId(), &mainSplitter, &mainSplitter) | |
52 , leftPanel(nextChildId(), &tracePanels, &tracePanels) | |
53 , stackView(&leftPanel) | |
54 , stackTitle(nextChildId(), &leftPanel, &leftPanel) | |
55 , rightPanel(nextChildId(), &tracePanels, &tracePanels) | |
56 , tokenListView(&rightPanel) | |
57 , tokenListTitle(nextChildId(), &rightPanel, &rightPanel) | |
58 , bottomPanel(nextChildId(), &mainSplitter, &mainSplitter, | |
59 IRectangle(), ISplitCanvas::vertical | visible) | |
60 , reductionChoiceView(&bottomPanel) | |
61 , ruleView(&bottomPanel) | |
62 , focusControl(GTWindow::tokenTab) | |
63 , activePanel(GTWindow::tokenTab) | |
64 , frame(owner_) | |
65 , dataColorChange(this, onColorChange) | |
66 , fontChange(this, onFontChange) | |
67 , leftButtonState(buttonIdle) | |
68 , itemStack(parser.x1x_new()) | |
69 { | |
70 LOGSECTION("GTView::GTView"); | |
71 LOGV(id()); | |
72 | |
73 LOGV((int) &stackView); | |
74 LOGV((int) &stackView.dataArea); | |
75 LOGV((int) &tokenListView); | |
76 LOGV((int) &tokenListView.dataArea); | |
77 | |
78 setFont(tokenListView.dataArea.font()); | |
79 | |
80 dataColorChange.attach(&ColorSpec::inactiveCursor); | |
81 dataColorChange.attach(&ColorSpec::activeCursor); | |
82 fontChange.attach(&FontSpec::columnHead); | |
83 | |
84 ruleView.setEnterAction(AgAction()); | |
85 stackView.helpTopic = "Token Stack"; | |
86 tokenListView.helpTopic = "Allowable Input"; | |
87 tokenListView.copyTitle = "Grammar Trace: Allowable Input"; | |
88 ruleView.copyTitle = "Grammar Trace: Rule Stack"; | |
89 reductionChoiceView.copyTitle = "Grammar Trace: Reduction Choices"; | |
90 stackView.copyTitle = "Grammar Trace: Parser Stack"; | |
91 | |
92 stackView.init(stackViewData); | |
93 parserDc->windowConnector = stackViewData; | |
94 | |
95 reductionMenu = new FtParserReductionDc(parser); | |
96 AgDataViewPlug *connector = new AgDataViewPlug(reductionMenu); | |
97 reductionMenu->windowConnector = connector; | |
98 reductionChoiceView.init(connector); | |
99 | |
100 bottomPanel.setSplitWindowPercentage(&reductionChoiceView, 0); | |
101 bottomPanel.setSplitWindowPercentage(&ruleView, 100); | |
102 | |
103 stackTitle | |
104 . setText("Parser Stack") | |
105 . setAlignment(IStaticText::centerCenter) | |
106 . setBackgroundColor(ColorSpec::inactiveTitle.bg()) | |
107 . setForegroundColor(ColorSpec::inactiveTitle.fg()) | |
108 ; | |
109 AgString tokenTitle = | |
110 AgString::format("Allowable input - State %d", parser.state.number); | |
111 tokenListTitle | |
112 . setText(tokenTitle.pointer()) | |
113 . setAlignment(IStaticText::centerCenter) | |
114 . setBackgroundColor(ColorSpec::inactiveTitle.bg()) | |
115 . setForegroundColor(ColorSpec::inactiveTitle.fg()) | |
116 ; | |
117 LOGS("titles set up"); | |
118 int width = stackTitle.minimumSize().width(); | |
119 int height = font().externalLeading() + font().maxSize().height(); | |
120 ISize minSize(width, 5*height); | |
121 | |
122 leftPanel | |
123 . addToCell(&stackView, 1,1) | |
124 . addToCell(&stackTitle, 1,2) | |
125 . setColumnWidth(1,width,true) | |
126 . setRowHeight(1,0,true) | |
127 . setMinimumSize(minSize) | |
128 ; | |
129 width = tokenListTitle.minimumSize().width(); | |
130 minSize= ISize(width, 5*height); | |
131 rightPanel | |
132 . addToCell(&tokenListView, 1,1) | |
133 . addToCell(&tokenListTitle,1,2) | |
134 . setColumnWidth(1,width,true) | |
135 . setRowHeight(1,0,true) | |
136 . setMinimumSize(minSize) | |
137 ; | |
138 | |
139 //dc_ref ruleWindow = parserDc->rule_stack(parser.stateStack.size()); | |
140 itemStack = parser.x1x_new(); | |
141 //dc_ref ruleWindow = new rule_stack_dc(itemStack, parser.stateStack.size(), | |
142 // parserDc->head_title); | |
143 ruleControl = new rule_stack_dc(itemStack,parser.stateStack.size(), | |
144 parserDc->head_title); | |
145 //parser.ruleControl = ruleWindow; | |
146 //ruleConnector = new AgDataViewPlug(ruleWindow); | |
147 ruleConnector = new AgDataViewPlug(ruleControl); | |
148 //ruleWindow->windowConnector = ruleConnector; | |
149 ruleControl->windowConnector = ruleConnector; | |
150 ruleView.init(ruleConnector); | |
151 | |
152 mainSplitter.setSplitWindowPercentage(&tracePanels, 55); | |
153 mainSplitter.setSplitWindowPercentage(&bottomPanel, 45); | |
154 tracePanels.setSplitWindowPercentage(&leftPanel, 25); | |
155 tracePanels.setSplitWindowPercentage(&rightPanel, 75); | |
156 | |
157 AgFocusHandler::handleEventsFor(&stackView.dataArea); | |
158 IMouseHandler::handleEventsFor(&stackTitle); | |
159 AgFocusHandler::handleEventsFor(&tokenListView.dataArea); | |
160 IMouseHandler::handleEventsFor(&tokenListTitle); | |
161 AgFocusHandler::handleEventsFor(&reductionChoiceView.dataArea); | |
162 AgFocusHandler::handleEventsFor(&ruleView.dataArea); | |
163 //AgFocusHandler::handleEventsFor(&frame->comboBox); | |
164 //AgFocusHandler::handleEventsFor(&frame->containerBar); | |
165 IFocusHandler::handleEventsFor(&frame->comboBox); | |
166 //IFocusHandler::handleEventsFor(&frame->containerBar); | |
167 IPaintHandler::handleEventsFor(this); | |
168 LOGS("all done"); | |
169 } | |
170 | |
171 GTView::~GTView() { | |
172 AgFocusHandler::stopHandlingEventsFor(&stackView.dataArea); | |
173 IMouseHandler::stopHandlingEventsFor(&stackTitle); | |
174 AgFocusHandler::stopHandlingEventsFor(&tokenListView.dataArea); | |
175 IMouseHandler::stopHandlingEventsFor(&tokenListTitle); | |
176 AgFocusHandler::stopHandlingEventsFor(&reductionChoiceView.dataArea); | |
177 AgFocusHandler::stopHandlingEventsFor(&ruleView.dataArea); | |
178 //AgFocusHandler::stopHandlingEventsFor(&frame->comboBox); | |
179 //AgFocusHandler::stopHandlingEventsFor(&frame->containerBar); | |
180 IFocusHandler::stopHandlingEventsFor(&frame->comboBox); | |
181 //IFocusHandler::stopHandlingEventsFor(&frame->containerBar); | |
182 IPaintHandler::stopHandlingEventsFor(this); | |
183 } | |
184 | |
185 | |
186 Boolean GTView::paintWindow(IPaintEvent &event) { | |
187 LOGSECTION("GTView::paintWindow"); | |
188 LOGV(event.rect().asString()); | |
189 event.clearBackground(IGUIColor::dialogBgnd); | |
190 return false; | |
191 } | |
192 | |
193 GTView >View::refreshRules(int rule) { | |
194 LOGSECTION("GTView::refreshRules"); | |
195 LOGV(rule); | |
196 delete_tsd(itemStack); | |
197 itemStack = parser.x1x_new(); | |
198 //parser.ruleControl->parser_stack = parser.itemStack; | |
199 ruleControl->parser_stack = itemStack; | |
200 int k = itemStack->nt; | |
201 int ln = parser.stateStack.size(); | |
202 LOGV(itemStack->nt); | |
203 LOGV(parser.stateStack.size()); | |
204 //parser.ruleControl->des->d_size.y = k; | |
205 ruleControl->des->d_size.y = k; | |
206 //ruleWindow->des->d_size.y = k; | |
207 ruleControl->des->d_size.y = k; | |
208 LOGV(k); | |
209 while (k--) { | |
210 int sx, sn, fn, fx; | |
211 xtxf(itemStack, k, &sx, &sn, &fn, &fx); | |
212 int length = Rule(fn)->length(); | |
213 LOGV(length); | |
214 if (sx == ln && rule == 0) { | |
215 break; | |
216 } | |
217 if (rule && fn == rule && fx == 0 && sx+length >= ln) { | |
218 break; | |
219 } | |
220 } | |
221 k = itemStack->nt - 1 - k; | |
222 LOGV(k); | |
223 | |
224 ruleView | |
225 . reset() | |
226 . setCursorLine(itemStack->nt-1) | |
227 . setCursorLine(k).synchCursor(k) | |
228 . refresh(); | |
229 frame->ruleViewLine = k; | |
230 return *this; | |
231 } | |
232 | |
233 Boolean GTView::mouseClicked(IMouseClickEvent &event) { | |
234 LOGSECTION("GTView::mouseClicked"); | |
235 if (event.mouseAction() != IMouseClickEvent::down) { | |
236 return false; | |
237 } | |
238 if (event.controlWindow() == &tokenListTitle) { | |
239 LOGS("tokenList should get focus"); | |
240 if (!tokenListView.dataArea.hasFocus()) { | |
241 tokenListView.dataArea.setFocus(); | |
242 } | |
243 return false; | |
244 } | |
245 else if (event.controlWindow() == &stackTitle) { | |
246 LOGS("stackView should get focus"); | |
247 if (!stackView.dataArea.hasFocus()) { | |
248 stackView.dataArea.setFocus(); | |
249 } | |
250 return false; | |
251 } | |
252 return false; | |
253 } | |
254 | |
255 | |
256 Boolean GTView::gotFocus(IControlEvent &event) { | |
257 LOGSECTION("GTView::gotFocus(c)"); | |
258 return gotFocus((IEvent &)event); | |
259 } | |
260 | |
261 Boolean GTView::gotFocus(IEvent &event) { | |
262 LOGSECTION("GTView::gotFocus"); | |
263 LOGV(ruleView.windowId); | |
264 if (event.controlWindow() == 0) { | |
265 return false; | |
266 } | |
267 #ifdef INCLUDE_LOGGING | |
268 IWindowHandle handle = (void *) event.parameter1(); | |
269 IWindow *lastWindow; | |
270 do { | |
271 lastWindow = IWindow::windowWithHandle(handle); | |
272 LOGV((int) lastWindow); | |
273 handle = GetParent(handle); | |
274 } while (lastWindow == 0 && handle != 0); | |
275 LOGV((int) event.controlWindow()) LCV((int)event.dispatchingWindow()); | |
276 #endif | |
277 if (event.controlWindow() == &stackView.dataArea) { | |
278 stackTitle.setBackgroundColor(ColorSpec::activeTitle.bg()); | |
279 stackTitle.setForegroundColor(ColorSpec::activeTitle.fg()); | |
280 stackTitle.refresh(); | |
281 focusControl = activePanel = GTWindow::stackTab; | |
282 } | |
283 else if (event.controlWindow() == &tokenListView.dataArea) { | |
284 tokenListTitle.setBackgroundColor(ColorSpec::activeTitle.bg()); | |
285 tokenListTitle.setForegroundColor(ColorSpec::activeTitle.fg()); | |
286 tokenListTitle.refresh(); | |
287 focusControl = GTWindow::tokenTab; | |
288 } | |
289 else if (event.controlWindow() == &reductionChoiceView.dataArea) { | |
290 focusControl = activePanel = GTWindow::choiceTab; | |
291 } | |
292 else if (event.controlWindow() == &ruleView.dataArea) { | |
293 focusControl = activePanel = GTWindow::ruleTab; | |
294 } | |
295 else if (event.controlWindow() == &frame->comboBox) { | |
296 focusControl = activePanel = GTWindow::comboTab; | |
297 } | |
298 else if (event.controlWindow() == &frame->containerBar) { | |
299 focusControl = activePanel = GTWindow::comboTab; | |
300 } | |
301 else if (event.dispatchingWindow() == &frame->comboBox) { | |
302 focusControl = activePanel = GTWindow::comboTab; | |
303 } | |
304 else if (event.dispatchingWindow() == &frame->containerBar) { | |
305 focusControl = activePanel = GTWindow::comboTab; | |
306 } | |
307 else { | |
308 return false; | |
309 } | |
310 | |
311 // Can't field mouse clicks reliably on combobox, so we show | |
312 // help using gotFocus(). | |
313 LOGV(leftButtonState); | |
314 if (focusControl == GTWindow::comboTab | |
315 && leftButtonState == buttonIdle | |
316 && ControlPanel::helpCursorSet) { | |
317 //ControlPanel::helpCursorSet = 0; | |
318 //AgHelpWindow::showHelp("Text Entry"); | |
319 //ControlPanel::resetCursor(); | |
320 followUpPending = 1; | |
321 defer(this, followUpFocusMsg); | |
322 return true; | |
323 } | |
324 | |
325 | |
326 frame->stepButton.disableDefault(); | |
327 frame->resetButton.disableDefault(); | |
328 frame->helpButton.disableDefault(); | |
329 frame->proceedButton.enableDefault(); | |
330 LOGV(ruleView.windowId); | |
331 LOGV(focusControl); | |
332 return false; | |
333 } | |
334 | |
335 void GTView::followUpFocusMsg() { | |
336 if (!followUpPending) { | |
337 return; | |
338 } | |
339 ControlPanel::helpCursorSet = 0; | |
340 AgHelpWindow::showHelp("Text Entry"); | |
341 ControlPanel::resetCursor(); | |
342 followUpPending = 0; | |
343 } | |
344 | |
345 Boolean GTView::lostFocus(IControlEvent &event) { | |
346 LOGSECTION("GTView::lostFocus(c)"); | |
347 return lostFocus((IEvent &) event); | |
348 } | |
349 | |
350 Boolean GTView::lostFocus(IEvent &event) { | |
351 LOGSECTION("GTView::lostFocus"); | |
352 LOGV(focusControl); | |
353 #ifdef INCLUDE_LOGGING | |
354 IWindowHandle handle = (void *) event.parameter1(); | |
355 IWindow *nextWindow; | |
356 do { | |
357 nextWindow = IWindow::windowWithHandle(handle); | |
358 LOGV((int) nextWindow); | |
359 handle = GetParent(handle); | |
360 } while (nextWindow == 0 && handle != 0); | |
361 | |
362 LOGV((int) nextWindow); | |
363 LOGV((int) event.controlWindow()) LCV((int)event.dispatchingWindow()); | |
364 #endif | |
365 if (event.controlWindow() == &stackView.dataArea) { | |
366 stackTitle.setBackgroundColor(ColorSpec::inactiveTitle.bg()); | |
367 stackTitle.setForegroundColor(ColorSpec::inactiveTitle.fg()); | |
368 stackTitle.refresh(); | |
369 } | |
370 if (event.controlWindow() == &tokenListView.dataArea) { | |
371 tokenListTitle.setBackgroundColor(ColorSpec::inactiveTitle.bg()); | |
372 tokenListTitle.setForegroundColor(ColorSpec::inactiveTitle.fg()); | |
373 tokenListTitle.refresh(); | |
374 } | |
375 LOGV(focusControl); | |
376 return false; | |
377 } | |
378 | |
379 | |
380 Boolean GTWindow::virtualKeyPress(IKeyboardEvent &event) { | |
381 LOGSECTION("GTWindow::virtualKeyPress"); | |
382 ok_ptr(this); | |
383 int increment = 0; | |
384 int &focusControl = canvas.focusControl; | |
385 int &activePanel = canvas.activePanel; | |
386 LOGV(focusControl); | |
387 LOGV((int) event.controlWindow()) LCV((int) event.dispatchingWindow()); | |
388 LOGV(event.virtualKey()); | |
389 switch (event.virtualKey()) { | |
390 case IKeyboardEvent::enter: | |
391 case IKeyboardEvent::newLine: { | |
392 //activePanel = focusControl; | |
393 if (focusControl >= proceedTab) { | |
394 tabControl[focusControl].action.performDeferred(); | |
395 IPushButton *button = (IPushButton *)tabControl[focusControl].window; | |
396 button->disableDefault(); | |
397 button->unhighlight(); | |
398 } | |
399 else { | |
400 activePanel = focusControl; | |
401 proceed(); | |
402 } | |
403 return true; | |
404 } | |
405 case IKeyboardEvent::right: | |
406 case IKeyboardEvent::down: | |
407 if (focusControl < proceedTab) { | |
408 return AgFrame::virtualKeyPress(event); | |
409 } | |
410 if (focusControl + 1 == nTabs) { | |
411 increment = proceedTab - focusControl; | |
412 } | |
413 else { | |
414 increment = 1; | |
415 } | |
416 break; | |
417 case IKeyboardEvent::tab: | |
418 increment = 1; | |
419 break; | |
420 case IKeyboardEvent::left: | |
421 case IKeyboardEvent::up: | |
422 if (focusControl < proceedTab) { | |
423 return AgFrame::virtualKeyPress(event); | |
424 } | |
425 if (focusControl == proceedTab) { | |
426 increment = nTabs - 1 - proceedTab; | |
427 } | |
428 else { | |
429 increment = nTabs - 1; | |
430 } | |
431 break; | |
432 case IKeyboardEvent::backTab: | |
433 increment = nTabs - 1; | |
434 break; | |
435 default: | |
436 return AgFrame::virtualKeyPress(event); | |
437 } | |
438 if (event.controlWindow() != event.dispatchingWindow()) { | |
439 return true; | |
440 } | |
441 IPushButton *button; | |
442 if (focusControl >= proceedTab) { | |
443 button = (IPushButton *) tabControl[focusControl].window; | |
444 button->unhighlight(); | |
445 button->disableDefault(); | |
446 } | |
447 do { | |
448 focusControl = (focusControl + increment) % nTabs; | |
449 } while (!tabControl[focusControl].enabled); | |
450 LOGV(focusControl) LCV(increment); | |
451 if (focusControl >= proceedTab) { | |
452 button = (IPushButton *) tabControl[focusControl].window; | |
453 } | |
454 else { | |
455 button = &proceedButton; | |
456 } | |
457 button->enableDefault(); | |
458 setFocus(); | |
459 return true; | |
460 } | |
461 | |
462 Boolean GTWindow::mouseClicked(IMouseClickEvent &event) { | |
463 LOGSECTION("GTWindow::mouseClicked"); | |
464 GTView::ButtonState &lbs = canvas.leftButtonState; | |
465 ok_ptr(this); | |
466 LOGV(event.mouseButton()) LCV(event.mouseAction()); | |
467 if (event.mouseButton() != 0) { | |
468 return false; | |
469 } | |
470 LOGV(lbs); | |
471 if (event.mouseAction() == IMouseClickEvent::down) { | |
472 lbs = GTView::buttonDown; | |
473 } | |
474 else if (event.mouseAction() == IMouseClickEvent::up) { | |
475 lbs = GTView::waitingForClick; | |
476 } | |
477 else if (event.mouseAction() == IMouseClickEvent::click) { | |
478 lbs = GTView::buttonIdle; | |
479 } | |
480 LOGV(lbs); | |
481 int &focusControl = canvas.focusControl; | |
482 int &activePanel = canvas.activePanel; | |
483 LOGV(focusControl) LCV(activePanel); | |
484 IWindow *controlWindow = event.controlWindow(); | |
485 LOGV((int)controlWindow) LCV((int)event.dispatchingWindow()); | |
486 if (event.controlWindow() == &statusField) { | |
487 return false; | |
488 } | |
489 | |
490 int tab; | |
491 for (tab = 0; tab < nTabs; tab++) { | |
492 LOGV(tab) LCV((int) tabControl[tab].window); | |
493 if (controlWindow == tabControl[tab].window) { | |
494 break; | |
495 } | |
496 } | |
497 if (tab == nTabs) { | |
498 return False; | |
499 } | |
500 | |
501 LOGV(ControlPanel::helpCursorSet); | |
502 if (ControlPanel::helpCursorSet) { | |
503 if (event.mouseAction() == IMouseClickEvent::up) { | |
504 ControlPanel::helpCursorSet = 0; | |
505 canvas.followUpPending = 0; | |
506 LOGV(tabControl[tab].helpTopic); | |
507 AgHelpWindow::showHelp(tabControl[tab].helpTopic); | |
508 ControlPanel::resetCursor(); | |
509 } | |
510 return true; | |
511 } | |
512 LOGV(focusControl) LCV(activePanel); | |
513 if (tab < proceedTab) { | |
514 return false; | |
515 } | |
516 if (focusControl >= proceedTab) { | |
517 IPushButton *button = (IPushButton *) tabControl[focusControl].window; | |
518 button->unhighlight(); | |
519 button->disableDefault(); | |
520 } | |
521 IPushButton *button = (IPushButton *) tabControl[tab].window; | |
522 if (event.mouseAction() == IMouseClickEvent::down) { | |
523 if (focusControl < proceedTab) activePanel = focusControl; | |
524 button->highlight(); | |
525 button->setFocus(); | |
526 focusControl = tab; | |
527 button->capturePointer(); | |
528 return true; | |
529 } | |
530 if (event.mouseAction() == IMouseClickEvent::up) { | |
531 button->unhighlight(); | |
532 button->releasePointer(); | |
533 AgAction &action = tabControl[tab].action; | |
534 IWindowHandle h = tabControl[tab].window->handle(); | |
535 if (h == event.windowUnderPointer()) { | |
536 action.performDeferred(); | |
537 } | |
538 else if (activePanel < proceedTab) { | |
539 button->disableDefault(); | |
540 proceedButton.enableDefault(); | |
541 focusControl = activePanel; | |
542 setFocus(); | |
543 } | |
544 else { | |
545 button->disableDefault(); | |
546 proceedButton.enableDefault(); | |
547 focusControl = proceedTab; | |
548 setFocus(); | |
549 } | |
550 } | |
551 return true; | |
552 } | |
553 | |
554 Boolean GTWindow::characterKeyPress(IKeyboardEvent &event) { | |
555 LOGSECTION("GTWindow::characterKeyPress"); | |
556 ok_ptr(this); | |
557 if (event.isCtrlDown()) { | |
558 return true; | |
559 } | |
560 if (canvas.focusControl < proceedTab) { | |
561 canvas.activePanel = canvas.focusControl; | |
562 } | |
563 char character = event.character(); | |
564 switch (character) { | |
565 case 'p': | |
566 case 'P': | |
567 proceed(); | |
568 return true; | |
569 case 's': | |
570 case 'S': | |
571 doStep(); | |
572 return true; | |
573 case 'r': | |
574 case 'R': | |
575 resetParser(); | |
576 return true; | |
577 case 'h': | |
578 case 'H': | |
579 AgHelpWindow::showHelp("Grammar Trace"); | |
580 helpButton.disableDefault(); | |
581 helpButton.unhighlight(); | |
582 stepButton.enableDefault(); | |
583 //canvas.focusControl = tokenTab; | |
584 if (comboBox.text().length()) { | |
585 canvas.focusControl = comboTab; | |
586 } | |
587 else { | |
588 canvas.focusControl = tokenTab; | |
589 } | |
590 return true; | |
591 } | |
592 return false; | |
593 } | |
594 | |
595 GTWindow >Window::setFocus() { | |
596 LOGSECTION("GTWindow::setFocus"); | |
597 //int protectHelp = ControlPanel::helpCursorSet; | |
598 //ControlPanel::helpCursorSet = 0; | |
599 ok_ptr(this); | |
600 int &focusControl = canvas.focusControl; | |
601 if (focusControl < proceedTab) { | |
602 canvas.activePanel = focusControl; | |
603 } | |
604 LOGV(focusControl); | |
605 LOGV(canvas.ruleView.windowId); | |
606 assert(focusControl >= 0 && focusControl < nTabs); | |
607 LOGV(canvas.ruleView.windowId); | |
608 tabControl[focusControl].window->setFocus(); | |
609 LOGV(canvas.ruleView.windowId); | |
610 IPushButton *button; | |
611 for (int i = proceedTab; i < nTabs; i++) { | |
612 button = (IPushButton *)tabControl[i].window; | |
613 LOGV((int) button); | |
614 button->disableDefault(); | |
615 button->unhighlight(); | |
616 } | |
617 LOGV(canvas.ruleView.windowId); | |
618 if (focusControl >= proceedTab) { | |
619 button = (IPushButton *)tabControl[focusControl].window; | |
620 } | |
621 else { | |
622 button = &proceedButton; | |
623 } | |
624 LOGV(canvas.ruleView.windowId); | |
625 LOGV((int) button); | |
626 button->enableDefault(); | |
627 LOGV(canvas.ruleView.windowId); | |
628 //ControlPanel::helpCursorSet = protectHelp; | |
629 LOGS("all done"); | |
630 return *this; | |
631 } | |
632 | |
633 void GTWindow::init() { | |
634 LOGSECTION("GTWindow::init"); | |
635 ok_ptr(this); | |
636 tabControl[stackTab] = TabControl(&canvas.stackView.dataArea, | |
637 "Parser Stack Pane"); | |
638 tabControl[tokenTab] = TabControl(&canvas.tokenListView.dataArea, | |
639 "Allowable Input Pane"); | |
640 tabControl[choiceTab] = TabControl(&canvas.reductionChoiceView.dataArea, | |
641 "Reduction Choices Pane"); | |
642 tabControl[choiceTab].enabled = 0; | |
643 tabControl[ruleTab] = TabControl(&canvas.ruleView.dataArea, | |
644 "Rule Stack Pane"); | |
645 tabControl[comboTab] | |
646 = TabControl(&comboBox, "Text Entry Field", | |
647 actionObject(this, comboBoxEnter)); | |
648 tabControl[proceedTab] | |
649 = TabControl(&proceedButton, "Proceed", actionObject(this, proceed)); | |
650 tabControl[stepTab] | |
651 = TabControl(&stepButton, "Single Step", actionObject(this, doStep)); | |
652 tabControl[resetTab] | |
653 = TabControl(&resetButton, "Reset", actionObject(this, resetParser)); | |
654 tabControl[helpTab] | |
655 = TabControl(&helpButton, "Grammar Trace", actionObject(this, showHelp)); | |
656 /* | |
657 LOGV((int) &comboBox) LCV((int) &containerBar); | |
658 new ControlHelpDemon(&containerBar, "Container Bar"); | |
659 new ControlHelpDemon(&toolBar, "Tool Bar"); | |
660 */ | |
661 //parser.displayControl = parserDc; | |
662 setClient(&canvas); | |
663 addExtension(&toolBar, IFrameWindow::belowClient, IFrameWindow::thickLine); | |
664 | |
665 IFont buttonFont = stepButton.font(); | |
666 int buttonWidth = buttonFont.textWidth(" Synch Parse "); | |
667 LOGV(buttonWidth); | |
668 IColor buttonTextColor = resetButton.foregroundColor(); | |
669 | |
670 ISize minimum = stepButton.minimumSize(); | |
671 minimum.setWidth(buttonWidth); | |
672 stepButton.setMinimumSize(minimum); | |
673 statusField.setFont(buttonFont); | |
674 LOGV(statusField.font().name()); | |
675 int statusFieldWidth = buttonFont.textWidth("MSelect reduction tokenM"); | |
676 statusField.setMinimumSize(ISize(statusFieldWidth,minimum.height())); | |
677 LOGV(statusField.minimumSize().asString()); | |
678 statusField.setBackgroundColor(IGUIColor::dialogBgnd); | |
679 statusField.setForegroundColor(buttonTextColor); | |
680 | |
681 ISize margin = toolBar.margin(); | |
682 margin.setHeight(0); | |
683 toolBar.setMargin(margin); | |
684 containerBar.setMargin(ISize()); | |
685 margin = buttonGroup.margin(); | |
686 margin.setWidth(0); | |
687 margin.setHeight(margin.height()/2); | |
688 buttonGroup.setMargin(margin); | |
689 ISize pad = buttonGroup.pad(); | |
690 pad.setWidth(0); | |
691 buttonGroup.setPad(pad); | |
692 | |
693 proceedButton.enableDefault(); | |
694 | |
695 LOGV(proceedButton.minimumSize().asString()); | |
696 LOGV(stepButton.minimumSize().asString()); | |
697 LOGV(resetButton.minimumSize().asString()); | |
698 LOGV(helpButton.minimumSize().asString()); | |
699 | |
700 int minWidth = toolBar.minimumSize().width(); | |
701 LOGV(parser.stateStack.size()); | |
702 tokenList = parserDc->tokenMenu(parser.stateStack.size()); | |
703 LOGV((int) (dc *)tokenList); | |
704 tokenList->windowConnector = new AgDataViewPlug(tokenList); | |
705 LOGV((int)tokenList->windowConnector); | |
706 | |
707 canvas.tokenListView | |
708 . init(tokenList->windowConnector->windowData()) | |
709 . adjustMaxWidth("Token0\tAction\tToken Name") | |
710 . setColumnTitles("Token\tAction\tToken Name") | |
711 ; | |
712 canvas.stackView | |
713 . adjustMaxWidth(" 1\tState:\tToken0\tToken Name") | |
714 . setColumnTitles("\tState\tToken\tToken Name") | |
715 ; | |
716 int loopControl = 2; | |
717 ISize sizeLeft; | |
718 ISize sizeRight; | |
719 while (loopControl--) { | |
720 int desktopWidth = IWindow::desktopWindow()->size().width(); | |
721 sizeLeft = canvas.stackView.suggestSize(); | |
722 if (sizeLeft.width() > desktopWidth/6) { | |
723 sizeLeft.setWidth(desktopWidth/3); | |
724 } | |
725 sizeRight = canvas.tokenListView.suggestSize(); | |
726 if (sizeRight.width() > desktopWidth/2) { | |
727 sizeRight.setWidth(desktopWidth/2); | |
728 } | |
729 int thickness = | |
730 2*canvas.tracePanels.splitBarThickness(ISplitCanvas::splitBarEdge); | |
731 LOGV(canvas.tracePanels.splitBarThickness(ISplitCanvas::splitBarEdge)); | |
732 LOGV(canvas.tracePanels.splitBarThickness(ISplitCanvas::splitBarMiddle)); | |
733 LOGV(borderWidth()); | |
734 thickness += | |
735 canvas.tracePanels.splitBarThickness(ISplitCanvas::splitBarMiddle); | |
736 thickness += 2*borderWidth(); | |
737 int width = sizeLeft.width() + sizeRight.width() + thickness; | |
738 int height = max(6*sizeLeft.height(), sizeRight.height()); | |
739 LOGV(height); | |
740 height = | |
741 min(height, | |
742 3*AgDataView::defaultWindowHeight*canvas.stackView.lineHeight()/2); | |
743 height += 2*canvas.stackView.columnHeadTitle.size().height(); | |
744 height += canvas.stackTitle.minimumSize().height(); | |
745 LOGV(height); | |
746 if (width < minWidth) { | |
747 width = minWidth; | |
748 } | |
749 if (width > (2*desktopWidth)/3) { | |
750 width = (2*desktopWidth)/3; | |
751 } | |
752 int toolbarWidth = toolBar.minimumSize().width(); | |
753 if (width < toolbarWidth) { | |
754 width = toolbarWidth; | |
755 } | |
756 ISize clientSize(width, height); | |
757 LOGV(clientSize.asString()); | |
758 IRectangle frameRect(frameRectFor(clientSize)); | |
759 ISize frameSize = frameRect.size(); | |
760 LOGV(frameSize.asString()); | |
761 ISize resultant = clientRectFor(frameRect).size(); | |
762 LOGV(resultant.asString()); | |
763 sizeTo(frameRect.size()); | |
764 LOGV(sizeLeft.asString()); | |
765 LOGV(sizeRight.asString()); | |
766 setStatusField(); | |
767 } | |
768 | |
769 int left = canvas.stackView.tableWidth; | |
770 int right = canvas.tokenListView.tableWidth; | |
771 if (left > sizeLeft.width()) { | |
772 left = sizeLeft.width(); | |
773 } | |
774 if (right > sizeRight.width()) { | |
775 right = sizeRight.width(); | |
776 } | |
777 | |
778 LOGV(left); | |
779 LOGV(right); | |
780 | |
781 canvas.tracePanels.setSplitWindowPercentage(&canvas.leftPanel, left); | |
782 canvas.tracePanels.setSplitWindowPercentage(&canvas.rightPanel, right); | |
783 positionFrame(); | |
784 | |
785 stackViewLine = parser.stateStack.size(); | |
786 canvas.stackView | |
787 . setEnterAction(AgAction()) | |
788 . setSelectAction(actionObject(this, stackSelect)) | |
789 . setCursorLine(stackViewLine) | |
790 ; | |
791 canvas.ruleView | |
792 . setSelectAction(actionObject(this, ruleSelect)) | |
793 . setEnterAction(AgAction()) | |
794 ; | |
795 canvas.tokenListView | |
796 //. setEnterAction(AgAction()) | |
797 . setEnterAction(actionObject(this, tokenEnter)) | |
798 . setSelectAction(actionObject(this, tokenSelect)) | |
799 ; | |
800 canvas.reductionChoiceView | |
801 . setEnterAction(actionObject(this, reductionChoiceEnter)) | |
802 . setSelectAction(actionObject(this, reductionChoiceSelect)) | |
803 ; | |
804 | |
805 listViewLine = canvas.tokenListView.getCursorLine(); | |
806 | |
807 LOGV(listViewLine); | |
808 stackViewLine = parser.stateStack.size(); | |
809 ruleViewLine = canvas.ruleView.getCursorLine(); | |
810 LOGV(canvas.ruleView.windowId); | |
811 | |
812 syntaxDependent = 1; | |
813 LOGV(parser.stateStack.size()); | |
814 IShowListHandler::handleEventsFor(&comboBox); | |
815 listViewLine = | |
816 tokenList->positionCursor(parser.state.number,parser.state.token); | |
817 LOGV(canvas.ruleView.windowId); | |
818 canvas.tokenListView.setCursorLine(listViewLine); | |
819 LOGV(canvas.ruleView.windowId); | |
820 synchRules(parser.stateStack.size(), parser.state.token); | |
821 LOGV(canvas.ruleView.windowId); | |
822 frameHandler->setDeactivateAction(actionObject(this, onDeactivate)); | |
823 LOGV(canvas.ruleView.windowId); | |
824 AgFocusHandler::handleEventsFor(this); | |
825 for (int i = 0; i < nTabs; i++) { | |
826 IKeyboardHandler::handleEventsFor(tabControl[i].window); | |
827 if (i == comboTab) { | |
828 continue; | |
829 } | |
830 IMouseHandler::handleEventsFor(tabControl[i].window); | |
831 } | |
832 IMouseHandler::handleEventsFor(&statusField); | |
833 IKeyboardHandler::handleEventsFor(&containerBar); | |
834 LOGV(canvas.ruleView.windowId); | |
835 show(); | |
836 LOGV(canvas.ruleView.windowId); | |
837 //setFocus(); | |
838 //LOGS("Returned from setFocus"); | |
839 LOGV(canvas.ruleView.windowId); | |
840 canvas.ruleView.setCursorLine(canvas.itemStack->nt - 1); | |
841 refresh(); | |
842 LOGS("refresh call returned"); | |
843 canvas.ruleView.setCursorLine(ruleViewLine); | |
844 canvas.tokenListView.dataArea.setFocus(); | |
845 LOGS("all done"); | |
846 } | |
847 | |
848 GTWindow::GTWindow(trace_window_dc* gtControl) | |
849 : AgFrame( IFrameWindow::dialogBackground | |
850 | IFrameWindow::systemMenu | |
851 | IFrameWindow::maximizeButton | |
852 | IFrameWindow::sizingBorder) | |
853 , parser((gtControl == 0 ? 0 : gtControl->parser_stack)) | |
854 , parserDc(new FtParserDc(parser)) | |
855 , canvas(this, parserDc) | |
856 , toolBar(this, ISetCanvas::packTight | ISetCanvas::centerVerticalAlign) | |
857 , containerBar(&toolBar, ISetCanvas::packTight) | |
858 , statusField(nextChildId(), &containerBar, &containerBar, IRectangle(), | |
859 IStaticText::defaultStyle() | |
860 | IStaticText::center | |
861 | IStaticText::vertCenter | |
862 | IStaticText::border3D) | |
863 , statusFieldHelp(&statusField, "Parse Status") | |
864 , comboBox(&containerBar, "Now is the time for ") | |
865 //, comboBoxHelp(&comboBox, "Grammar Trace Text Entry") | |
866 , buttonGroup(&toolBar, ISetCanvas::packExpanded) | |
867 , proceedButton(IDTB_PROCEED, &buttonGroup, PROCEED) | |
868 , stepButton(IDTB_STEP, &buttonGroup, SINGLE_STEP) | |
869 , resetButton(IDTB_RESET, &buttonGroup, RESET) | |
870 , helpButton(IDTB_HELP, &buttonGroup, HELP) | |
871 , comboBoxActive(0) | |
872 , comboBoxListShowing(0) | |
873 , ruleSelectActive(0) | |
874 , selectedToken(0) | |
875 { | |
876 LOGSECTION("GTWindow::GTWindow"); | |
877 ok_ptr(this); | |
878 AgString title; | |
879 if (gtControl == 0) { | |
880 title = "Grammar Trace"; | |
881 } | |
882 else { | |
883 if (gtControl->foot_title.exists()) { | |
884 title = AgString::format("%s (%s)", | |
885 gtControl->head_title.pointer(), | |
886 gtControl->foot_title.pointer()); | |
887 } | |
888 else { | |
889 title = gtControl->head_title; | |
890 } | |
891 } | |
892 LOGV(title.pointer()); | |
893 AgString objectName = AgString::format("AnaGram : %s", | |
894 simple_file_name.pointer()); | |
895 LOGV(objectName.pointer()); | |
896 windowTitle.setObjectText(objectName.pointer()); | |
897 windowTitle.setViewText(title.pointer()); | |
898 registerTitle(title.pointer()); | |
899 init(); | |
900 } | |
901 | |
902 GTWindow::GTWindow(tsd *initialStates, AgString headTitle, AgString footTitle) | |
903 : AgFrame( IFrameWindow::dialogBackground | |
904 | IFrameWindow::systemMenu | |
905 | IFrameWindow::maximizeButton | |
906 | IFrameWindow::sizingBorder) | |
907 , parser(initialStates) | |
908 , parserDc(new FtParserDc(parser)) | |
909 , canvas(this, parserDc) | |
910 , toolBar(this, ISetCanvas::packTight | ISetCanvas::centerVerticalAlign) | |
911 , containerBar(&toolBar, ISetCanvas::packTight) | |
912 , statusField(nextChildId(), &containerBar, &containerBar, IRectangle(), | |
913 IStaticText::defaultStyle() | |
914 | IStaticText::center | |
915 | IStaticText::vertCenter | |
916 | IStaticText::border3D) | |
917 , statusFieldHelp(&statusField, "Parse Status") | |
918 , comboBox(&containerBar, "Now is the time for ") | |
919 //, comboBoxHelp(&comboBox, "Grammar Trace Text Entry") | |
920 , buttonGroup(&toolBar, ISetCanvas::packExpanded) | |
921 , proceedButton(IDTB_PROCEED, &buttonGroup, PROCEED) | |
922 , stepButton(IDTB_STEP, &buttonGroup, SINGLE_STEP) | |
923 , resetButton(IDTB_RESET, &buttonGroup, RESET) | |
924 , helpButton(IDTB_HELP, &buttonGroup, HELP) | |
925 , comboBoxActive(0) | |
926 , comboBoxListShowing(0) | |
927 , ruleSelectActive(0) | |
928 , selectedToken(0) | |
929 { | |
930 LOGSECTION("GTWindow::GTWindow"); | |
931 ok_ptr(this); | |
932 | |
933 AgString objectName = AgString::format("AnaGram : %s", | |
934 simple_file_name.pointer()); | |
935 LOGV(objectName.pointer()); | |
936 AgString title; | |
937 if (footTitle.exists()) { | |
938 title = AgString::format("%s (%s)", | |
939 headTitle.pointer(), | |
940 footTitle.pointer()); | |
941 } | |
942 else { | |
943 title = headTitle; | |
944 } | |
945 | |
946 windowTitle.setObjectText(objectName.pointer()); | |
947 windowTitle.setViewText(title.pointer()); | |
948 registerTitle(title.pointer()); | |
949 init(); | |
950 comboBox.setEnterAction(actionObject(this, comboBoxEnter)); | |
951 } | |
952 | |
953 void GTWindow::setRuleViewCursor() { | |
954 LOGSECTION("GTWindow::setRuleViewCursor"); | |
955 ok_ptr(this); | |
956 LOGV(canvas.ruleView.cursorLine); | |
957 canvas.ruleView.setCursorLine(canvas.itemStack->nt - 1); | |
958 LOGV(canvas.ruleView.cursorLine); | |
959 canvas.ruleView.setCursorLine(ruleViewLine); | |
960 LOGV(canvas.ruleView.cursorLine); | |
961 } | |
962 | |
963 void GTWindow::onDeactivate() { | |
964 LOGSECTION("GTWindow::onDeactivate"); | |
965 ok_ptr(this); | |
966 //if (comboBox.hasFocus()) canvas.focusControl = comboTab; | |
967 } | |
968 | |
969 | |
970 GTWindow::~GTWindow() { | |
971 IShowListHandler::stopHandlingEventsFor(&comboBox); | |
972 AgFocusHandler::stopHandlingEventsFor(this); | |
973 for (int i = 0; i < nTabs; i++) { | |
974 IKeyboardHandler::stopHandlingEventsFor(tabControl[i].window); | |
975 if (i == comboTab) { | |
976 continue; | |
977 } | |
978 IMouseHandler::stopHandlingEventsFor(tabControl[i].window); | |
979 } | |
980 IMouseHandler::stopHandlingEventsFor(&statusField); | |
981 IKeyboardHandler::stopHandlingEventsFor(&containerBar); | |
982 } | |
983 | |
984 AgString GTWindow::copyTitle() { | |
985 ok_ptr(this); | |
986 switch (canvas.focusControl) { | |
987 case stackTab: return canvas.stackView.copyTitle;; | |
988 case tokenTab: return canvas.tokenListView.copyTitle;; | |
989 case choiceTab: return canvas.reductionChoiceView.copyTitle;; | |
990 case ruleTab: return canvas.ruleView.copyTitle;; | |
991 } | |
992 return AgString(); | |
993 } | |
994 | |
995 GTWindow >Window::copyTo(IClipboard &c) { | |
996 ok_ptr(this); | |
997 switch (canvas.focusControl) { | |
998 case stackTab: canvas.stackView.copyTo(c); break; | |
999 case tokenTab: canvas.tokenListView.copyTo(c); break; | |
1000 case choiceTab: canvas.reductionChoiceView.copyTo(c); break; | |
1001 case ruleTab: canvas.ruleView.copyTo(c); break; | |
1002 } | |
1003 return *this; | |
1004 } | |
1005 | |
1006 /* | |
1007 GTView >View::completeReduction() { | |
1008 LOGSECTION("GTView::completeReduction"); | |
1009 reductionMenu->des->d_size.y = 0; | |
1010 bottomPanel.setSplitWindowPercentage(&reductionChoiceView, 0); | |
1011 bottomPanel.setSplitWindowPercentage(&ruleView, 100); | |
1012 bottomPanel.refresh(); | |
1013 tabControl[comboTab].enabled = 0; | |
1014 frame->reductionChoiceLine = reductionChoiceView.getCursorLine(); | |
1015 int token = ibnfs[ibnfb[parser.ruleToReduce]+frame->reductionChoiceLine]; | |
1016 LOGV(token); | |
1017 parser.completeReduction(token); | |
1018 return *this; | |
1019 } | |
1020 */ | |
1021 | |
1022 void GTWindow::reductionChoiceSelect() { | |
1023 LOGSECTION("GTWindow::reductionChoiceSelect"); | |
1024 ok_ptr(this); | |
1025 int sn = parser.reductionState.number; | |
1026 reductionChoiceLine = canvas.reductionChoiceView.getCursorLine(); | |
1027 int tn = canvas.reductionMenu->token(reductionChoiceLine); | |
1028 parser.reductionState.token= tn; | |
1029 LOGV(sn) LCV(tn); | |
1030 listViewLine = tokenList->positionCursor(sn,tn); | |
1031 canvas.tokenListView.setCursorLine(listViewLine); | |
1032 canvas.stackView.repaintLine(parser.stateStack.size()); | |
1033 } | |
1034 | |
1035 void GTWindow::ruleSelect() { | |
1036 LOGSECTION("GTWindow::ruleSelect"); | |
1037 ok_ptr(this); | |
1038 LOGV(listViewLine); | |
1039 LOGV(stackViewLine); | |
1040 LOGV(ruleViewLine); | |
1041 int tn = 0; | |
1042 int k = canvas.ruleView.getCursorLine(); | |
1043 if (k == ruleViewLine) { | |
1044 return; | |
1045 } | |
1046 ruleViewLine = k; | |
1047 LOGV(k); | |
1048 k = canvas.itemStack->nt - k - 1; | |
1049 LOGV(k); | |
1050 int sx, sn, fn, fx; | |
1051 xtxf(canvas.itemStack, k, &sx, &sn, &fn, &fx); | |
1052 int length = Rule(fn)->length(); | |
1053 LOGV(fn); | |
1054 LOGV(fx); | |
1055 LOGV(length); | |
1056 if (fx < length) { | |
1057 //tn = lstptr(map_form_number[fn],tokens)[fx]; | |
1058 tn = Rule(fn).token(fx); | |
1059 } | |
1060 int stackDepth = parser.stateStack.size(); | |
1061 int stackLevel = sx; | |
1062 LOGV(stackLevel) LCV(stackDepth); | |
1063 if (stackLevel == stackDepth && | |
1064 parser.processState == FtParser::selectionRequired) { | |
1065 if (fx >= length) { | |
1066 return; | |
1067 } | |
1068 //int tn = lstptr(map_form_number[fn],tokens)[fx]; | |
1069 int tn = Rule(fn).token(fx); | |
1070 LOGV(tn); | |
1071 int n = ibnfn[parser.ruleToReduce]; | |
1072 while (n--) { | |
1073 LOGV(n); | |
1074 LOGV(ibnfs[ibnfb[parser.ruleToReduce]+n]); | |
1075 if (ibnfs[ibnfb[parser.ruleToReduce]+n] == tn) { | |
1076 break; | |
1077 } | |
1078 } | |
1079 LOGV(fn) LCV(n) LCV(tn); | |
1080 if (n < 0) { | |
1081 return; | |
1082 } | |
1083 canvas.reductionChoiceView.setCursorLine(n); | |
1084 parser.reductionState.token = tn; | |
1085 synchTokenList(sn, tn); | |
1086 canvas.stackView.repaintLine(stackDepth); | |
1087 return; | |
1088 } | |
1089 canvas.stackView.setCursorLine(stackLevel); | |
1090 stackViewLine = stackLevel; | |
1091 synchTokenList(sn, tn); | |
1092 } | |
1093 | |
1094 void GTWindow::setLookaheadToken(unsigned token) { | |
1095 LOGSECTION("GTWindow::setLookaheadToken"); | |
1096 ok_ptr(this); | |
1097 LOGV(parser.stateStack.size()); | |
1098 LOGV(canvas.stackView.cursorLine); | |
1099 parser.state.token = token; | |
1100 LOGV(token); | |
1101 int line = parser.stateStack.size(); | |
1102 canvas.stackView.setCursorLine(line); | |
1103 } | |
1104 | |
1105 | |
1106 void GTWindow::synchRules(unsigned stackIndex, unsigned token) { | |
1107 LOGSECTION("GTWindow::synchRules"); | |
1108 ok_ptr(this); | |
1109 LOGV(stackIndex) LCV(token); | |
1110 unsigned stackLocation = canvas.itemStack->nt; | |
1111 LOGV(stackLocation); | |
1112 int snx, sn, sx; | |
1113 if (stackIndex >= parser.stateStack.size()) { | |
1114 sn = parser.state.number; | |
1115 } | |
1116 else { | |
1117 sn = parser.stateStack[stackIndex].number; | |
1118 } | |
1119 state_number_map *sp = &map_state_number[sn]; | |
1120 LOGV(stackLocation); | |
1121 while (stackLocation--) { | |
1122 int fn, fx; | |
1123 xtxf(canvas.itemStack,stackLocation, &sx, &snx, &fn, &fx); | |
1124 if (sx == stackIndex) { | |
1125 break; | |
1126 } | |
1127 } | |
1128 assert(sx == stackIndex); | |
1129 int k = stackLocation; | |
1130 LOGV(sn); | |
1131 LOGV(token); | |
1132 if (stackIndex >= parser.stateStack.size()) { | |
1133 ruleViewLine = canvas.itemStack->nt - stackLocation - 1; | |
1134 do { | |
1135 int fn, fx; | |
1136 xtxf(canvas.itemStack, k, &sx, &snx, &fn, &fx); | |
1137 if (fx < Rule(fn)->length() | |
1138 && token == Rule(fn).token(fx)) | |
1139 //&& token == lstptr(map_form_number[fn],tokens)[fx]) | |
1140 { | |
1141 k = canvas.itemStack->nt - k - 1; | |
1142 canvas.ruleView.setCursorLine(k).synchCursor(k); | |
1143 ruleViewLine = k; | |
1144 return; | |
1145 } | |
1146 unsigned *p = lstptr(*sp,reductions); | |
1147 unsigned n = sp->n_reductions; | |
1148 while (n--) { | |
1149 unsigned tn = *p++; | |
1150 unsigned rule = *p++; | |
1151 if (rule == fn && tn == token) { | |
1152 k = canvas.itemStack->nt - k - 1; | |
1153 canvas.ruleView.setCursorLine(k).synchCursor(k); | |
1154 ruleViewLine = k; | |
1155 return; | |
1156 } | |
1157 } | |
1158 k--; | |
1159 } while (k >= 0 && sx == stackIndex); | |
1160 canvas.ruleView.setCursorLine(ruleViewLine).synchCursor(ruleViewLine); | |
1161 return; | |
1162 } | |
1163 int nextState; | |
1164 if (stackIndex + 1 >= parser.stateStack.size()) { | |
1165 nextState = parser.state.number; | |
1166 } | |
1167 else { | |
1168 nextState = parser.stateStack[stackIndex+1].number; | |
1169 } | |
1170 int charToken = map_state_number[nextState].char_token; | |
1171 LOGV(nextState) LCV(charToken); | |
1172 do { | |
1173 int fn, fx; | |
1174 xtxf(canvas.itemStack, k, &sx, &snx, &fn, &fx); | |
1175 int length = Rule(fn)->length(); | |
1176 LOGV(k) LCV(snx); | |
1177 LOGV(fn) LCV(fx) LCV(length); | |
1178 //if (sx == stackIndex && fx < length | |
1179 // && token == lstptr(map_form_number[fn],tokens)[fx]) { | |
1180 if (fx < length | |
1181 && charToken == Rule(fn).token(fx)) { | |
1182 //&& charToken == lstptr(map_form_number[fn],tokens)[fx]) { | |
1183 k = canvas.itemStack->nt - k - 1; | |
1184 canvas.ruleView.setCursorLine(k).synchCursor(k); | |
1185 ruleViewLine = k; | |
1186 return; | |
1187 } | |
1188 k--; | |
1189 LOGV(k); | |
1190 LOGV(sn) LCV(snx); | |
1191 } while (k >= 0 && sx == stackIndex); | |
1192 } | |
1193 | |
1194 void GTWindow::setUpViews() { | |
1195 LOGSECTION("GTWindow::setUpViews"); | |
1196 ok_ptr(this); | |
1197 unsigned stackDepth = parser.stateStack.size(); | |
1198 int stackCursor = stackDepth; | |
1199 LOGV(tokenList->state_number); | |
1200 canvas.activePanel = canvas.focusControl; | |
1201 if (parser.processState == FtParser::selectionRequired) { | |
1202 LOGV(statusField.font().name()); | |
1203 showReductionSelection(); | |
1204 LOGV(statusField.font().name()); | |
1205 stackCursor = parser.reductionIndex; | |
1206 canvas.focusControl = canvas.activePanel = choiceTab; | |
1207 tabControl[choiceTab].enabled = 1; | |
1208 } | |
1209 else if (parser.ruleToReduce) { | |
1210 parser.ruleToReduce = 0; | |
1211 canvas.reductionMenu->des->d_size.y = 0; | |
1212 canvas.bottomPanel.setSplitWindowPercentage(&canvas.reductionChoiceView,0); | |
1213 canvas.bottomPanel.setSplitWindowPercentage(&canvas.ruleView, 100); | |
1214 canvas.bottomPanel.refresh(); | |
1215 tabControl[choiceTab].enabled = 0; | |
1216 } | |
1217 LOGV(tokenList->state_number); | |
1218 canvas.refreshRules(parser.ruleToReduce); | |
1219 LOGV(tokenList->state_number); | |
1220 IString text = comboBox.text(); | |
1221 LOGV(parser.state.token); | |
1222 int sn = parser.state.number; | |
1223 int tn = 0; | |
1224 if (parser.processState != FtParser::ready) { | |
1225 tn = parser.state.token; | |
1226 } | |
1227 if (parser.processState == FtParser::selectionRequired) { | |
1228 LOGS("selection required"); | |
1229 sn = parser.reductionState.number; | |
1230 tn = | |
1231 canvas.reductionMenu->token(canvas.reductionChoiceView.getCursorLine()); | |
1232 LOGV(sn) LCV(tn); | |
1233 } | |
1234 else if (parser.processState <= FtParser::running) { | |
1235 tn = parser.state.token; | |
1236 parser.processState = FtParser::ready; | |
1237 } | |
1238 else if (canvas.focusControl == comboTab) { | |
1239 LOGS("Text in the combobox"); | |
1240 LOGV(text); | |
1241 if (text.length()) { | |
1242 parser.prime((const char*) text); | |
1243 tn = parser.state.token; | |
1244 LOGV(tn); | |
1245 state_number_map *sp = &map_state_number[sn]; | |
1246 unsigned *tokenPointer = lstptr(*sp,t_actions); | |
1247 int k; | |
1248 for (k = 0; tokenPointer[k]; k++) { | |
1249 if (tokenPointer[k] == tn) { | |
1250 break; | |
1251 } | |
1252 } | |
1253 LOGV(tn) LCV(k) LCV(tokenPointer[k]); | |
1254 tn = tokenPointer[k]; | |
1255 int snx; | |
1256 k = canvas.ruleView.getCursorLine(); | |
1257 LOGV(k) LCV(canvas.itemStack->nt); | |
1258 k = canvas.itemStack->nt - k - 1; | |
1259 LOGV(k) LCV(sn); | |
1260 if (tn) { | |
1261 do { | |
1262 int sx, fn, fx; | |
1263 xtxf(canvas.itemStack, k, &sx, &snx, &fn, &fx); | |
1264 LOGV(k) LCV(sx) LCV(snx) LCV(fn) LCV(fx);; | |
1265 int length = Rule(fn)->length(); | |
1266 LOGV(length); | |
1267 if (sn == snx && fx < length) { | |
1268 if (tn == Rule(fn).token(fx)) { | |
1269 break; | |
1270 } | |
1271 //if (tn == lstptr(map_form_number[fn],tokens)[fx]) break; | |
1272 } | |
1273 if (k == 0) { | |
1274 break; | |
1275 } | |
1276 k--; | |
1277 } while (sn == snx); | |
1278 } | |
1279 LOGV(sn) LCV(snx); | |
1280 if (tn && sn == snx) { | |
1281 k = canvas.itemStack->nt - k - 1; | |
1282 canvas.ruleView.setCursorLine(k).synchCursor(k); | |
1283 ruleViewLine = k; | |
1284 } | |
1285 else { | |
1286 tn == 0; | |
1287 } | |
1288 } | |
1289 } | |
1290 LOGV(tokenList->state_number); | |
1291 LOGV(parser.state.token); | |
1292 if (parser.processState == FtParser::running) { | |
1293 parser.processState = FtParser::ready; | |
1294 } | |
1295 LOGV(sn); | |
1296 LOGV(tn); | |
1297 | |
1298 canvas.stackView | |
1299 . reset() | |
1300 . setLayoutDistorted(IWindow::layoutChanged | IWindow::immediateUpdate, 0) | |
1301 . setCursorLine(stackCursor) | |
1302 . refresh() | |
1303 ; | |
1304 LOGV(tokenList->state_number); | |
1305 LOGV(parser.state.token); | |
1306 stackViewLine = stackCursor; | |
1307 LOGS("stackView set up"); | |
1308 | |
1309 LOGS("new token menu created"); | |
1310 LOGV(parser.state.number); | |
1311 tokenList->reset(parser.state.number); | |
1312 | |
1313 LOGV(parser.state.token); | |
1314 LOGV(tokenList->state_number); | |
1315 LOGS("new tokenList created"); | |
1316 char buf[100]; | |
1317 sprintf(buf, "Allowable input - State %d", parser.state.number); | |
1318 //AgString tokenTitle = AgString::format("Allowable input - State %d", | |
1319 // parser.state.number); | |
1320 //LOGV(tokenTitle.pointer()); | |
1321 canvas.tokenListTitle | |
1322 //. setText(tokenTitle.pointer()) | |
1323 . setText(buf) | |
1324 . refresh() | |
1325 ; | |
1326 LOGS("tokenListTitle set up"); | |
1327 LOGV(tokenList->state_number); | |
1328 listViewLine = tokenList->positionCursor(sn, tn); | |
1329 canvas.tokenListView | |
1330 . reset() | |
1331 . setCursorLine(listViewLine) | |
1332 . setLayoutDistorted(IWindow::layoutChanged | IWindow::immediateUpdate, 0) | |
1333 . refresh() | |
1334 ; | |
1335 LOGV(parser.state.token); | |
1336 LOGS("tokenListView set up"); | |
1337 LOGV(tokenList->state_number); | |
1338 LOGV(listViewLine); | |
1339 LOGV(stackViewLine); | |
1340 LOGV(ruleViewLine); | |
1341 LOGV(parser.location()); | |
1342 setStatusField(); | |
1343 LOGV(tokenList->state_number); | |
1344 setFocus(); | |
1345 LOGV(tokenList->state_number); | |
1346 } | |
1347 | |
1348 void GTWindow::reductionChoiceEnter() { | |
1349 LOGSECTION("GTWindow::reductionChoiceEnter"); | |
1350 ok_ptr(this); | |
1351 tabControl[choiceTab].enabled = 0; | |
1352 reductionChoiceLine = canvas.reductionChoiceView.getCursorLine(); | |
1353 int tn = canvas.reductionMenu->token(reductionChoiceLine); | |
1354 parser.reductionState.token = tn; | |
1355 unsigned sn = parser.reductionState.number; | |
1356 LOGV(sn) LCV(tn); | |
1357 listViewLine = tokenList->positionCursor(sn,tn); | |
1358 canvas.tokenListView.setCursorLine(listViewLine); | |
1359 if (comboBox.text().length()) canvas.focusControl = comboTab; | |
1360 else canvas.focusControl = tokenTab; | |
1361 acceptToken(); | |
1362 setFocus(); | |
1363 } | |
1364 | |
1365 Boolean GTWindow::windowResize(IResizeEvent &event){ | |
1366 LOGSECTION("GTWindow::windowResize"); | |
1367 ok_ptr(this); | |
1368 if (event.controlWindow() != this) { | |
1369 return false; | |
1370 } | |
1371 LOGV(id()); | |
1372 canvas.mainSplitter.sizeTo( | |
1373 clientRectFor(IRectangle(IPoint(), event.newSize())).size() | |
1374 ); | |
1375 return false; | |
1376 } | |
1377 | |
1378 void GTWindow::synchTokenList(unsigned sn, unsigned tn) { | |
1379 LOGSECTION("GTWindow::synchTokenList"); | |
1380 ok_ptr(this); | |
1381 AgString tokenTitle = AgString::format("Allowable input - State %d", sn); | |
1382 canvas.tokenListTitle.setText(tokenTitle.pointer()); | |
1383 | |
1384 LOGV(sn); | |
1385 | |
1386 tokenList->reset(sn); | |
1387 | |
1388 listViewLine = tokenList->positionCursor(sn,tn); | |
1389 canvas.tokenListView | |
1390 . reset() | |
1391 . setCursorLine(listViewLine) | |
1392 . setLayoutDistorted(IWindow::layoutChanged | IWindow::immediateUpdate, 0) | |
1393 . refresh() | |
1394 ; | |
1395 } | |
1396 | |
1397 void GTWindow::stackSelect() { | |
1398 LOGSECTION("GTWindow::stackSelect"); | |
1399 ok_ptr(this); | |
1400 int ln = canvas.stackView.getCursorLine(); | |
1401 LOGV(listViewLine); | |
1402 LOGV(stackViewLine); | |
1403 LOGV(ruleViewLine); | |
1404 FtParser::State state = | |
1405 (ln >= parser.stateStack.size()) ? parser.state : parser.stateStack[ln]; | |
1406 int sn = state.number, tn = state.token; | |
1407 synchTokenList(sn, tn); | |
1408 synchRules(ln, tn); | |
1409 } | |
1410 | |
1411 GTWindow >Window::showReductionSelection() { | |
1412 LOGSECTION("GTWindow::showReductionSelection"); | |
1413 ok_ptr(this); | |
1414 | |
1415 LOGV(statusField.font().name()); | |
1416 | |
1417 canvas.reductionMenu = new FtParserReductionDc(parser); | |
1418 AgDataViewPlug *connector = new AgDataViewPlug(canvas.reductionMenu); | |
1419 canvas.reductionMenu->windowConnector = connector; | |
1420 | |
1421 canvas.reductionChoiceView.init(connector); | |
1422 | |
1423 LOGV(canvas.reductionMenu->columnHeadTitle.pointer()); | |
1424 LOGV(connector->columnHeadTitle().pointer()); | |
1425 | |
1426 canvas.reductionChoiceView.setEnterAction(actionObject(this, | |
1427 reductionChoiceEnter)); | |
1428 | |
1429 ISize tableSize = canvas.reductionChoiceView.suggestSize(); | |
1430 | |
1431 int width = 40*font().avgCharWidth(); | |
1432 int testWidth = tableSize.width(); | |
1433 if (testWidth < width/2) { | |
1434 width = width/2; | |
1435 } | |
1436 else if (testWidth > 2*width) { | |
1437 width = 2*width; | |
1438 } | |
1439 else { | |
1440 width = testWidth; | |
1441 } | |
1442 | |
1443 int rightWidth = canvas.bottomPanel.size().width(); | |
1444 | |
1445 int thickness = | |
1446 2*canvas.tracePanels.splitBarThickness(ISplitCanvas::splitBarEdge); | |
1447 thickness += | |
1448 canvas.tracePanels.splitBarThickness(ISplitCanvas::splitBarMiddle); | |
1449 canvas.bottomPanel.setSplitWindowPercentage(&canvas.reductionChoiceView, | |
1450 width); | |
1451 canvas.bottomPanel.setSplitWindowPercentage(&canvas.ruleView, | |
1452 rightWidth - width - thickness); | |
1453 | |
1454 canvas.bottomPanel.refresh(); | |
1455 LOGV(canvas.size().asString()); | |
1456 reductionChoiceLine = parser.reductionSelection; | |
1457 canvas.reductionChoiceView | |
1458 . setCursorLine(reductionChoiceLine) | |
1459 . synchCursor(reductionChoiceLine) | |
1460 ; | |
1461 canvas.focusControl = choiceTab; | |
1462 setFocus(); | |
1463 | |
1464 int sn = parser.reductionState.number; | |
1465 int tn = canvas.reductionMenu->token(0); | |
1466 listViewLine = tokenList->positionCursor(sn, tn); | |
1467 canvas.tokenListView.setCursorLine(listViewLine); | |
1468 | |
1469 return *this; | |
1470 } | |
1471 | |
1472 void GTWindow::comboBoxSelect() { | |
1473 LOGSECTION("GTWindow::comboBoxSelect"); | |
1474 ok_ptr(this); | |
1475 IString text = comboBox.itemText(comboBox.selection()); | |
1476 LOGV((char *) text); | |
1477 comboBox.setText(text); | |
1478 } | |
1479 | |
1480 void GTWindow::comboBoxEnter() { | |
1481 LOGSECTION("GTWindow::comboBoxEnter"); | |
1482 ok_ptr(this); | |
1483 canvas.focusControl = comboTab; | |
1484 int selection = comboBox.selection(); | |
1485 LOGV(selection); | |
1486 LOGV(IComboBox::notFound); | |
1487 LOGV(comboBox.isListShowing()); | |
1488 LOGV(comboBox.hasChanged()); | |
1489 if (comboBoxListShowing) { | |
1490 comboBoxListShowing = 0; | |
1491 LOGV(selection); | |
1492 if (selection == IComboBox::notFound) { | |
1493 return; | |
1494 } | |
1495 IString text = comboBox.itemText(selection); | |
1496 LOGV((char *) text); | |
1497 comboBox.setText(text); | |
1498 LOGV(comboBox.selection()); | |
1499 return; | |
1500 } | |
1501 comboBoxProceed(); | |
1502 proceedButton.unhighlight(); | |
1503 } | |
1504 | |
1505 Boolean GTWindow::listShown(IControlEvent &) { | |
1506 LOGSECTION("GTWindow::listShown"); | |
1507 ok_ptr(this); | |
1508 comboBoxListShowing = 1; | |
1509 return false; | |
1510 } | |
1511 | |
1512 void GTWindow::ComboBox::saveText() { | |
1513 LOGSECTION("GTWindow::comboBox::saveText()"); | |
1514 IString contents = text(); | |
1515 if (contents.length() == 0) { | |
1516 return; | |
1517 } | |
1518 int n = count(); | |
1519 while (n--) { | |
1520 if (itemText(n) == contents) { | |
1521 remove(n); | |
1522 break; | |
1523 } | |
1524 } | |
1525 addAsFirst(contents); | |
1526 IEntryField::removeAll(); | |
1527 n = count(); | |
1528 LOGV(count()); | |
1529 if (n < 8 && n > minimumRows()) { | |
1530 setMinimumRows(8); | |
1531 } | |
1532 LOGV(minimumRows()); | |
1533 } | |
1534 | |
1535 void GTWindow::proceed() { | |
1536 LOGSECTION("GTWindow::proceed"); | |
1537 ok_ptr(this); | |
1538 IString text = comboBox.text(); | |
1539 LOGV(text); | |
1540 LOGV(canvas.focusControl); | |
1541 //if (comboBox.hasFocus()) { | |
1542 // canvas.focusControl = canvas.activePanel = comboTab; | |
1543 //} | |
1544 LOGV(canvas.focusControl) LCV(canvas.activePanel); | |
1545 //switch(canvas.focusControl) { | |
1546 switch(canvas.activePanel) { | |
1547 case stackTab: | |
1548 case ruleTab: { | |
1549 messageBeep(); | |
1550 setFocus(); | |
1551 return; | |
1552 } | |
1553 case tokenTab: { | |
1554 tokenProceed(); | |
1555 break; | |
1556 } | |
1557 case choiceTab: { | |
1558 reductionChoiceEnter(); | |
1559 break; | |
1560 } | |
1561 case comboTab: { | |
1562 comboBoxProceed(); | |
1563 break; | |
1564 } | |
1565 case proceedTab: { // proceed button has focus | |
1566 if (parser.processState == FtParser::selectionRequired) { | |
1567 reductionChoiceEnter(); | |
1568 } | |
1569 else if (text.length() > 0) { | |
1570 comboBoxProceed(); | |
1571 } | |
1572 else tokenProceed(); | |
1573 break; | |
1574 } | |
1575 default: | |
1576 assert(0); | |
1577 } | |
1578 | |
1579 proceedButton.unhighlight(); | |
1580 proceedButton.enableDefault(); | |
1581 setFocus(); | |
1582 } | |
1583 | |
1584 void GTWindow::doStep() { | |
1585 LOGSECTION("GTWindow::doStep"); | |
1586 ok_ptr(this); | |
1587 IString text = comboBox.text(); | |
1588 LOGV(text); | |
1589 | |
1590 LOGV(canvas.focusControl); | |
1591 //if (comboBox.hasFocus()) { | |
1592 // canvas.focusControl = canvas.activePanel = comboTab; | |
1593 //} | |
1594 LOGV(canvas.focusControl) LCV(canvas.activePanel); | |
1595 //switch(canvas.focusControl) { | |
1596 switch(canvas.activePanel) { | |
1597 case stackTab: | |
1598 case ruleTab: { | |
1599 messageBeep(); | |
1600 setFocus(); | |
1601 return; | |
1602 } | |
1603 case tokenTab: { | |
1604 canvas.focusControl = tokenTab; | |
1605 acceptToken(); | |
1606 break; | |
1607 } | |
1608 case choiceTab: { | |
1609 reductionChoiceEnter(); | |
1610 break; | |
1611 } | |
1612 case comboTab: { | |
1613 comboBoxStep(); | |
1614 break; | |
1615 } | |
1616 case stepTab: { // step button has focus | |
1617 if (parser.processState == FtParser::selectionRequired) { | |
1618 reductionChoiceEnter(); | |
1619 } | |
1620 else if (text.length() > 0) { | |
1621 comboBoxStep(); | |
1622 } | |
1623 else { | |
1624 canvas.focusControl = tokenTab; | |
1625 acceptToken(); | |
1626 } | |
1627 break; | |
1628 } | |
1629 default: | |
1630 assert(0); | |
1631 } | |
1632 | |
1633 proceedButton.enableDefault(); | |
1634 stepButton.unhighlight(); | |
1635 stepButton.disableDefault(); | |
1636 setFocus(); | |
1637 } | |
1638 | |
1639 | |
1640 void GTWindow::comboBoxProceed() { | |
1641 LOGSECTION("GTWindow::comboBoxProceed"); | |
1642 ok_ptr(this); | |
1643 canvas.focusControl = comboTab; | |
1644 if (parser.processState == FtParser::finished) { | |
1645 messageBeep(); | |
1646 setFocus(); | |
1647 return; | |
1648 } | |
1649 LOGV(comboBox.selectedTextLength()); | |
1650 LOGV(comboBox.hasSelectedText()); | |
1651 IString text = comboBox.text(); | |
1652 LOGV((char *) text); | |
1653 if (text.length() == 0) { | |
1654 messageBeep(); | |
1655 setFocus(); | |
1656 return; | |
1657 } | |
1658 | |
1659 if (parser.processState == FtParser::selectionRequired) { | |
1660 parser.ruleToReduce = 0; | |
1661 canvas.reductionMenu->des->d_size.y = 0; | |
1662 canvas.bottomPanel.setSplitWindowPercentage(&canvas.reductionChoiceView,0); | |
1663 canvas.bottomPanel.setSplitWindowPercentage(&canvas.ruleView, 100); | |
1664 tabControl[choiceTab].enabled = 0; | |
1665 canvas.bottomPanel.refresh(); | |
1666 parser.processState = FtParser::running; | |
1667 } | |
1668 | |
1669 unsigned stackLevel = canvas.stackView.getCursorLine(); | |
1670 unsigned stackDepth = parser.stateStack.size(); | |
1671 if (stackLevel != stackDepth) { | |
1672 LOGV(stackDepth); | |
1673 while (stackDepth > stackLevel) { | |
1674 parser.stateStack.pop(parser.state); | |
1675 stackDepth--; | |
1676 } | |
1677 parserDc->des->d_size.y = stackLevel+1; | |
1678 } | |
1679 | |
1680 parser.parse(text); | |
1681 if (parser.processState > FtParser::running) { | |
1682 messageBeep(); | |
1683 } | |
1684 LOGV(comboBox.selectedTextLength()); | |
1685 LOGV(comboBox.hasSelectedText()); | |
1686 | |
1687 int k = (char *) text + strlen(text) - (char *) parser.state.pointer; | |
1688 comboBox.saveText(); | |
1689 comboBox.setText((char *) parser.state.pointer); | |
1690 if (k > 0) { | |
1691 comboBox.setText((char *) parser.state.pointer); | |
1692 } | |
1693 | |
1694 if (parser.processState == FtParser::selectionRequired) { | |
1695 int k = parser.stateStack.size() - parser.reductionIndex; | |
1696 assert((unsigned) k <= (unsigned) parser.stateStack.size()); | |
1697 LOGV(k); | |
1698 parser.stateStack.discardData(k); | |
1699 parser.state = parser.reductionState; | |
1700 } | |
1701 LOGV(parser.state.number); | |
1702 LOGV(parser.state.token); | |
1703 tokenList->reset(parser.state.number); | |
1704 stackDepth = parser.stateStack.size(); | |
1705 //parser.displayControl->des->d_size.y = stackDepth+1; | |
1706 parserDc->des->d_size.y = stackDepth+1; | |
1707 LOGV(stackDepth); | |
1708 LOGV(parser.processState); | |
1709 LOGV(tokenList->state_number); | |
1710 | |
1711 setUpViews(); | |
1712 } | |
1713 | |
1714 void GTWindow::comboBoxStep() { | |
1715 LOGSECTION("GTWindow::comboBoxStep"); | |
1716 ok_ptr(this); | |
1717 LOGV(comboBox.selectedTextLength()); | |
1718 LOGV(comboBox.hasSelectedText()); | |
1719 IString text = comboBox.text(); | |
1720 LOGV((char *) text); | |
1721 if (text.length() == 0 || parser.processState == FtParser::finished) { | |
1722 messageBeep(); | |
1723 return; | |
1724 } | |
1725 | |
1726 if (parser.processState == FtParser::selectionRequired) { | |
1727 parser.ruleToReduce = 0; | |
1728 tabControl[choiceTab].enabled = 0; | |
1729 canvas.reductionMenu->des->d_size.y = 0; | |
1730 canvas.bottomPanel.setSplitWindowPercentage(&canvas.reductionChoiceView,0); | |
1731 canvas.bottomPanel.setSplitWindowPercentage(&canvas.ruleView, 100); | |
1732 canvas.bottomPanel.refresh(); | |
1733 parser.processState = FtParser::running; | |
1734 } | |
1735 | |
1736 canvas.focusControl = comboTab; | |
1737 unsigned stackLevel = canvas.stackView.getCursorLine(); | |
1738 unsigned stackDepth = parser.stateStack.size(); | |
1739 if (stackLevel != stackDepth) { | |
1740 LOGV(stackDepth); | |
1741 while (stackDepth > stackLevel) { | |
1742 parser.stateStack.pop(parser.state); | |
1743 stackDepth--; | |
1744 } | |
1745 parserDc->des->d_size.y = stackLevel+1; | |
1746 } | |
1747 | |
1748 LOGV((int)(char *) text); | |
1749 LOGV(parser.state.pointer); | |
1750 | |
1751 parser.processState = FtParser::running; | |
1752 parser.step(text); | |
1753 if (parser.processState > FtParser::running) { | |
1754 messageBeep(); | |
1755 } | |
1756 | |
1757 LOGV(comboBox.selectedTextLength()); | |
1758 LOGV(comboBox.hasSelectedText()); | |
1759 int k = (char *) text + strlen(text) - (char *) parser.state.pointer; | |
1760 LOGV(k); | |
1761 comboBox.saveText(); | |
1762 if (k > 0) { | |
1763 comboBox.setText((char *) parser.state.pointer); | |
1764 } | |
1765 | |
1766 if (parser.processState == FtParser::selectionRequired) { | |
1767 int k = parser.stateStack.size() - parser.reductionIndex; | |
1768 assert((unsigned) k <= (unsigned) parser.stateStack.size()); | |
1769 LOGV(k); | |
1770 parser.stateStack.discardData(k); | |
1771 parser.state = parser.reductionState; | |
1772 } | |
1773 LOGV(parser.state.number); | |
1774 LOGV(parser.state.token); | |
1775 tokenList->reset(parser.state.number); | |
1776 stackDepth = parser.stateStack.size(); | |
1777 //parser.displayControl->des->d_size.y = stackDepth+1; | |
1778 parserDc->des->d_size.y = stackDepth+1; | |
1779 LOGV(stackDepth); | |
1780 LOGV(parser.processState); | |
1781 LOGV(tokenList->state_number); | |
1782 | |
1783 setUpViews(); | |
1784 } | |
1785 | |
1786 void GTWindow::tokenSelect() { | |
1787 LOGSECTION("GTWindow::tokenSelect"); | |
1788 ok_ptr(this); | |
1789 LOGV(canvas.tokenListView.getCursorLine()); | |
1790 | |
1791 int line = canvas.tokenListView.getCursorLine(); | |
1792 LOGV(line); | |
1793 LOGV(listViewLine); | |
1794 LOGV(stackViewLine); | |
1795 LOGV(ruleViewLine); | |
1796 | |
1797 int stackLine = canvas.stackView.getCursorLine(); | |
1798 LOGV(stackLine); | |
1799 if (stackLine == stackViewLine && line == listViewLine) { | |
1800 return; | |
1801 } | |
1802 listViewLine = line; | |
1803 int stackDepth = parser.stateStack.size(); | |
1804 LOGV(stackDepth); | |
1805 int sn; | |
1806 if (stackLine >= stackDepth) { | |
1807 sn = parser.state.number; | |
1808 } | |
1809 else { | |
1810 sn = parser.stateStack[stackLine].number; | |
1811 } | |
1812 LOGV(sn); | |
1813 state_number_map *sp = &map_state_number[sn]; | |
1814 | |
1815 unsigned token = lstptr(*sp,t_actions)[line]; | |
1816 LOGV(token); | |
1817 if (parser.processState == FtParser::selectionRequired) { | |
1818 int n = ibnfn[parser.ruleToReduce]; | |
1819 while (n--) { | |
1820 if (token == ibnfs[ibnfb[parser.ruleToReduce]+n]) { | |
1821 canvas.reductionChoiceView.setCursorLine(n); | |
1822 reductionChoiceLine = n; | |
1823 break; | |
1824 } | |
1825 } | |
1826 } | |
1827 } | |
1828 | |
1829 void GTWindow::acceptToken() { | |
1830 LOGSECTION("GTWindow::acceptToken"); | |
1831 ok_ptr(this); | |
1832 LOGV(canvas.tokenListView.getCursorLine()); | |
1833 LOGV(listViewLine); | |
1834 LOGV(stackViewLine); | |
1835 LOGV(ruleViewLine); | |
1836 | |
1837 canvas.focusControl = tokenTab; | |
1838 if (parser.processState == FtParser::finished) { | |
1839 messageBeep(); | |
1840 setFocus(); | |
1841 return; | |
1842 } | |
1843 int line = canvas.tokenListView.getCursorLine(); | |
1844 LOGV(tokenList->state_number); | |
1845 | |
1846 | |
1847 int stackLevel = canvas.stackView.getCursorLine(); | |
1848 int stackDepth = parser.stateStack.size(); | |
1849 if (stackLevel != stackDepth) { | |
1850 LOGV(stackDepth); | |
1851 while (stackDepth > stackLevel) { | |
1852 parser.stateStack.pop(parser.state); | |
1853 stackDepth--; | |
1854 } | |
1855 parserDc->des->d_size.y = stackLevel+1; | |
1856 } | |
1857 | |
1858 LOGV(parser.state.token); | |
1859 | |
1860 if (parser.processState == FtParser::selectionRequired) { | |
1861 parser.ruleToReduce = 0; | |
1862 tabControl[choiceTab].enabled = 0; | |
1863 canvas.reductionMenu->des->d_size.y = 0; | |
1864 canvas.bottomPanel.setSplitWindowPercentage(&canvas.reductionChoiceView,0); | |
1865 canvas.bottomPanel.setSplitWindowPercentage(&canvas.ruleView, 100); | |
1866 canvas.bottomPanel.refresh(); | |
1867 parser.processState = FtParser::running; | |
1868 } | |
1869 | |
1870 state_number_map *sp = &map_state_number[parser.state.number]; | |
1871 unsigned token = lstptr(*sp, t_actions)[line]; | |
1872 | |
1873 LOGV(canvas.tokenListView.cursorLine); | |
1874 AgString lineText = canvas.tokenListView.windowData-> | |
1875 getLine(canvas.tokenListView.cursorLine); | |
1876 LOGV(lineText.pointer()); | |
1877 if (lineText == "No Default") { | |
1878 messageBeep(); | |
1879 setFocus(); | |
1880 return; | |
1881 } | |
1882 | |
1883 LOGV(parser.state.token); | |
1884 parser.stepToken(token); | |
1885 | |
1886 if (parser.processState > FtParser::running) { | |
1887 messageBeep(); | |
1888 } | |
1889 | |
1890 if (parser.processState == FtParser::selectionRequired) { | |
1891 int k = parser.stateStack.size() - parser.reductionIndex; | |
1892 assert((unsigned) k <= (unsigned) parser.stateStack.size()); | |
1893 LOGV(k); | |
1894 parser.stateStack.discardData(k); | |
1895 parser.state = parser.reductionState; | |
1896 unsigned stackDepth = parser.stateStack.size(); | |
1897 //parser.displayControl->des->d_size.y = stackDepth+1; | |
1898 parserDc->des->d_size.y = stackDepth+1; | |
1899 } | |
1900 LOGV(parser.state.number); | |
1901 LOGV(parser.state.token); | |
1902 tokenList->reset(parser.state.number); | |
1903 stackDepth = parser.stateStack.size(); | |
1904 //parser.displayControl->des->d_size.y = stackDepth+1; | |
1905 parserDc->des->d_size.y = stackDepth+1; | |
1906 | |
1907 LOGV(stackDepth); | |
1908 LOGV(parser.processState); | |
1909 LOGV(tokenList->state_number); | |
1910 setUpViews(); | |
1911 LOGV(tokenList->state_number); | |
1912 AgFrame::windowRegistry.refresh("Trace Coverage"); | |
1913 } | |
1914 | |
1915 void GTWindow::tokenEnter() { | |
1916 LOGSECTION("GTWindow::tokenEnter"); | |
1917 ok_ptr(this); | |
1918 //acceptToken(); | |
1919 //comboBox.saveText(); | |
1920 tokenProceed(); | |
1921 } | |
1922 | |
1923 | |
1924 void GTWindow::tokenProceed() { | |
1925 LOGSECTION("GTWindow::tokenProceed"); | |
1926 ok_ptr(this); | |
1927 LOGV(canvas.tokenListView.getCursorLine()); | |
1928 LOGV(listViewLine); | |
1929 LOGV(stackViewLine); | |
1930 LOGV(ruleViewLine); | |
1931 canvas.focusControl = tokenTab; | |
1932 if (parser.processState == FtParser::finished) { | |
1933 messageBeep(); | |
1934 setFocus(); | |
1935 return; | |
1936 } | |
1937 int line = canvas.tokenListView.getCursorLine(); | |
1938 LOGV(tokenList->state_number); | |
1939 | |
1940 | |
1941 int stackLevel = canvas.stackView.getCursorLine(); | |
1942 int stackDepth = parser.stateStack.size(); | |
1943 if (stackLevel != stackDepth) { | |
1944 LOGV(stackDepth); | |
1945 while (stackDepth > stackLevel) { | |
1946 parser.stateStack.pop(parser.state); | |
1947 stackDepth--; | |
1948 } | |
1949 parserDc->des->d_size.y = stackLevel+1; | |
1950 } | |
1951 | |
1952 LOGV(parser.state.token); | |
1953 | |
1954 if (parser.processState == FtParser::selectionRequired) { | |
1955 parser.ruleToReduce = 0; | |
1956 tabControl[choiceTab].enabled = 0; | |
1957 canvas.reductionMenu->des->d_size.y = 0; | |
1958 canvas.bottomPanel.setSplitWindowPercentage(&canvas.reductionChoiceView,0); | |
1959 canvas.bottomPanel.setSplitWindowPercentage(&canvas.ruleView, 100); | |
1960 canvas.bottomPanel.refresh(); | |
1961 parser.processState = FtParser::running; | |
1962 } | |
1963 | |
1964 state_number_map *sp = &map_state_number[parser.state.number]; | |
1965 unsigned token = lstptr(*sp,t_actions)[line]; | |
1966 | |
1967 LOGV(canvas.tokenListView.cursorLine); | |
1968 AgString lineText = canvas.tokenListView.windowData-> | |
1969 getLine(canvas.tokenListView.cursorLine); | |
1970 LOGV(lineText.pointer()); | |
1971 if (lineText == "No Default") { | |
1972 messageBeep(); | |
1973 setFocus(); | |
1974 return; | |
1975 } | |
1976 | |
1977 LOGV(parser.state.token); | |
1978 if (token) { | |
1979 parser.parseToken(token); | |
1980 } | |
1981 else { | |
1982 parser.stepToken(token); | |
1983 } | |
1984 | |
1985 if (parser.processState > FtParser::running) { | |
1986 messageBeep(); | |
1987 } | |
1988 | |
1989 if (parser.processState == FtParser::selectionRequired) { | |
1990 int k = parser.stateStack.size() - parser.reductionIndex; | |
1991 assert((unsigned) k <= (unsigned) parser.stateStack.size()); | |
1992 LOGV(k); | |
1993 parser.stateStack.discardData(k); | |
1994 parser.state = parser.reductionState; | |
1995 unsigned stackDepth = parser.stateStack.size(); | |
1996 //parser.displayControl->des->d_size.y = stackDepth+1; | |
1997 parserDc->des->d_size.y = stackDepth+1; | |
1998 } | |
1999 LOGV(parser.state.number); | |
2000 LOGV(parser.state.token); | |
2001 tokenList->reset(parser.state.number); | |
2002 stackDepth = parser.stateStack.size(); | |
2003 //parser.displayControl->des->d_size.y = stackDepth+1; | |
2004 parserDc->des->d_size.y = stackDepth+1; | |
2005 | |
2006 //comboBox.saveText(); | |
2007 | |
2008 LOGV(stackDepth); | |
2009 LOGV(parser.processState); | |
2010 LOGV(tokenList->state_number); | |
2011 setUpViews(); | |
2012 LOGV(tokenList->state_number); | |
2013 AgFrame::windowRegistry.refresh("Trace Coverage"); | |
2014 } | |
2015 | |
2016 Boolean GTWindow::findNext(AgString s) { | |
2017 LOGSECTION("GTWindow::findNext"); | |
2018 ok_ptr(this); | |
2019 LOGV(canvas.focusControl); | |
2020 int flag; | |
2021 switch (canvas.focusControl) { | |
2022 case stackTab: { | |
2023 flag = canvas.stackView.findNext(s); | |
2024 if (flag) { | |
2025 stackSelect(); | |
2026 } | |
2027 return flag; | |
2028 } | |
2029 case tokenTab: { | |
2030 flag = canvas.tokenListView.findNext(s); | |
2031 if (flag) { | |
2032 tokenSelect(); | |
2033 } | |
2034 return flag; | |
2035 } | |
2036 case choiceTab: { | |
2037 flag = canvas.reductionChoiceView.findNext(s); | |
2038 if (flag) { | |
2039 reductionChoiceSelect(); | |
2040 } | |
2041 return flag; | |
2042 } | |
2043 case ruleTab: { | |
2044 flag = canvas.ruleView.findNext(s); | |
2045 if (flag) { | |
2046 ruleSelect(); | |
2047 } | |
2048 return flag; | |
2049 } | |
2050 default: | |
2051 messageBeep(); | |
2052 return false; | |
2053 } | |
2054 } | |
2055 | |
2056 Boolean GTWindow::findPrev(AgString s) { | |
2057 LOGSECTION("GTWindow::findPrev"); | |
2058 ok_ptr(this); | |
2059 LOGV(canvas.focusControl); | |
2060 int flag; | |
2061 switch (canvas.focusControl) { | |
2062 case stackTab: { | |
2063 flag = canvas.stackView.findPrev(s); | |
2064 if (flag) { | |
2065 stackSelect(); | |
2066 } | |
2067 return flag; | |
2068 } | |
2069 case tokenTab: { | |
2070 flag = canvas.tokenListView.findPrev(s); | |
2071 if (flag) { | |
2072 tokenSelect(); | |
2073 } | |
2074 return flag; | |
2075 } | |
2076 case choiceTab: { | |
2077 flag = canvas.reductionChoiceView.findPrev(s); | |
2078 if (flag) { | |
2079 reductionChoiceSelect(); | |
2080 } | |
2081 return flag; | |
2082 } | |
2083 case ruleTab: { | |
2084 flag = canvas.ruleView.findPrev(s); | |
2085 if (flag) { | |
2086 ruleSelect(); | |
2087 } | |
2088 return flag; | |
2089 } | |
2090 default: | |
2091 messageBeep(); | |
2092 return false; | |
2093 } | |
2094 } | |
2095 | |
2096 | |
2097 char *GTWindow::processStateText[] = { | |
2098 "Ready", | |
2099 "Running", //running, | |
2100 "Parse Complete", //finished, | |
2101 "Syntax Error", //syntaxError, | |
2102 "Unexpected End of File", //unexpectedEndOfFile, | |
2103 "Select Reduction Token", //selectionRequired | |
2104 "Selection Error" | |
2105 }; | |
2106 | |
2107 GTWindow >Window::setStatusField() { | |
2108 ok_ptr(this); | |
2109 char *msg = processStateText[parser.processState]; | |
2110 statusField.setText(msg); | |
2111 statusField.refresh(); | |
2112 AgString tokenTitle = AgString::format("Allowable input - State %d", | |
2113 parser.state.number); | |
2114 canvas.tokenListTitle.setText(tokenTitle.pointer()); | |
2115 return *this; | |
2116 } | |
2117 | |
2118 void GTWindow::resetParser() { | |
2119 LOGSECTION("GTWindow::resetParser"); | |
2120 ok_ptr(this); | |
2121 if (parser.ruleToReduce) { | |
2122 parser.ruleToReduce = 0; | |
2123 canvas.reductionMenu->des->d_size.y = 0; | |
2124 canvas.bottomPanel.setSplitWindowPercentage(&canvas.reductionChoiceView,0); | |
2125 canvas.bottomPanel.setSplitWindowPercentage(&canvas.ruleView, 100); | |
2126 canvas.bottomPanel.refresh(); | |
2127 } | |
2128 tabControl[choiceTab].enabled = 0; | |
2129 comboBox.saveText(); | |
2130 parser.reset(); | |
2131 LOGV(parser.state.token); | |
2132 LOGV(parser.processState); | |
2133 int stackDepth = parser.stateStack.size(); | |
2134 parserDc->des->d_size.y = stackDepth + 1; | |
2135 canvas.stackView.setCursorLine(stackDepth); | |
2136 tokenList->reset(parser.state.number); | |
2137 LOGV(parser.state.token); | |
2138 canvas.tokenListView.reset(); | |
2139 LOGV(parser.state.token); | |
2140 LOGV(parser.state.token); | |
2141 LOGV(parser.processState); | |
2142 listViewLine | |
2143 = tokenList->positionCursor(parser.state.number, parser.state.token); | |
2144 canvas.tokenListView.setCursorLine(listViewLine); | |
2145 LOGV(parser.state.token); | |
2146 canvas.refreshRules(0); | |
2147 synchRules(parser.stateStack.size(), parser.state.token); | |
2148 LOGV(parser.processState); | |
2149 | |
2150 // if (comboBox.text().length()) canvas.focusControl = comboTab; | |
2151 // else canvas.focusControl = tokenTab; | |
2152 canvas.focusControl = tokenTab; | |
2153 setFocus(); | |
2154 canvas.stackView.refresh(); | |
2155 canvas.tokenListView.refresh(); | |
2156 LOGV(parser.processState); | |
2157 setStatusField(); | |
2158 resetButton.unhighlight(); | |
2159 resetButton.disableDefault(); | |
2160 proceedButton.enableDefault(); | |
2161 } | |
2162 | |
2163 void GTWindow::showHelp() { | |
2164 ok_ptr(this); | |
2165 AgHelpWindow::showHelp("Grammar Trace"); | |
2166 helpButton.unhighlight(); | |
2167 helpButton.disableDefault(); | |
2168 proceedButton.enableDefault(); | |
2169 if (comboBox.text().length()) { | |
2170 canvas.focusControl = comboTab; | |
2171 } | |
2172 else { | |
2173 canvas.focusControl = tokenTab; | |
2174 } | |
2175 } | |
2176 |