Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/vaclgui/ftview.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 * ftview.cpp | |
7 */ | |
8 | |
9 //#include <imsgbox.hpp> | |
10 //#include <itbarcnr.hpp> | |
11 | |
12 #include "agstring.h" | |
13 #include "agview.hpp" | |
14 #include "arrays.h" | |
15 #include "ctrlpanel.hpp" | |
16 #include "data.h" | |
17 #include "dc.h" | |
18 #include "dvplug.hpp" | |
19 #include "ftpar.h" | |
20 #include "ftview.hpp" | |
21 #include "helpview.hpp" | |
22 #include "myalloc.h" | |
23 #include "p.h" | |
24 #include "rule.h" | |
25 #include "vaclgui.hpp" | |
26 | |
27 //#define INCLUDE_LOGGING | |
28 #include "log.h" | |
29 | |
30 | |
31 #define PARSE_FILE "&Parse File" | |
32 #define SINGLE_STEP "&Single step" | |
33 #define RELOAD "Re&load" | |
34 #define RESET "&Reset" | |
35 #define HELP "&Help" | |
36 #define SYNCH_PARSE "&Synch Parse" | |
37 | |
38 //void logChildren(IWindow *window) { | |
39 // LOGSECTION("logChildren"); | |
40 // LOGV(window->id()); | |
41 // IWindow::ChildCursor cursor(*window); | |
42 // for (cursor.setToFirst(); cursor.isValid(); cursor.setToNext()) { | |
43 // IWindow child(window->childAt(cursor)); | |
44 // LOGS(" ") LV(child.id()); | |
45 // } | |
46 //} | |
47 | |
48 FileTraceView::FileTraceView(FileTraceWindow *frame_, | |
49 text_file text_, | |
50 AgString fileName_) | |
51 : ICanvas(nextChildId(), frame_, frame_, IRectangle(), | |
52 ICanvas::classDefaultStyle | |
53 | IWindow::clipChildren) | |
54 , mainSplitter(nextChildId(), this, this, IRectangle(), | |
55 ISplitCanvas::horizontal | |
56 | IWindow::visible) | |
57 , tracePanels(nextChildId(), &mainSplitter, &mainSplitter, IRectangle(), | |
58 ISplitCanvas::classDefaultStyle) | |
59 , leftPanel(nextChildId(), &tracePanels, &tracePanels, IRectangle(), | |
60 visible) | |
61 , rightPanel(nextChildId(), &tracePanels, &tracePanels, IRectangle(), | |
62 visible) | |
63 , stackView(&leftPanel) | |
64 , fileView(&rightPanel, text_, fileName_) | |
65 , fileTitle(nextChildId(), &rightPanel, &rightPanel) | |
66 , fileName(fileName_) | |
67 , textFile(text_) | |
68 , bottomPanel(nextChildId(), &mainSplitter, &mainSplitter, IRectangle(), | |
69 ISplitCanvas::vertical | |
70 | visible) | |
71 , reductionChoiceView(&bottomPanel) | |
72 , ruleView(&bottomPanel) | |
73 , frame(frame_) | |
74 , dataColorChange(this, onColorChange) | |
75 , fontChange(this, onFontChange) | |
76 , focusControl(FileTraceWindow::fileTab) | |
77 , activePanel(FileTraceWindow::fileTab) | |
78 , fileViewHelp(&rightPanel, "Test File") | |
79 { | |
80 LOGSECTION("FileTraceView::FileTraceView"); | |
81 | |
82 LOGV((int) &mainSplitter); | |
83 LOGV((int) &tracePanels); | |
84 LOGV((int) &leftPanel); | |
85 LOGV((int) &rightPanel); | |
86 LOGV((int) &bottomPanel); | |
87 LOGV((int) &stackView); | |
88 LOGV((int) &fileView); | |
89 LOGV((int) &reductionChoiceView); | |
90 LOGV((int) &ruleView); | |
91 LOGV((int) &this); | |
92 | |
93 LOGV(id()) LCV(handle().asDebugInfo()); | |
94 LOGV(leftPanel.id()) LCV((int) &leftPanel) | |
95 LCV(leftPanel.handle().asDebugInfo()); | |
96 LOGV(rightPanel.id()) LCV((int) &rightPanel) | |
97 LCV(rightPanel.handle().asDebugInfo()); | |
98 LOGV(stackView.id()) LCV((int) &stackView) | |
99 LCV(stackView.handle().asDebugInfo()); | |
100 LOGV(fileView.id()) LCV((int) &fileView) | |
101 LCV(fileView.handle().asDebugInfo()); | |
102 LOGV(fileTitle.id()) LCV((int) &fileTitle) | |
103 LCV(fileTitle.handle().asDebugInfo()); | |
104 | |
105 setFont(stackView.dataArea.font()); | |
106 | |
107 ruleView.setEnterAction(AgAction()); | |
108 ruleView.copyTitle = "File Trace: Rule Stack"; | |
109 reductionChoiceView.copyTitle = "File Trace: Reduction Choices"; | |
110 stackView.copyTitle = "File Trace: Parser Stack"; | |
111 | |
112 dataColorChange.attach(&ColorSpec::inactiveTitle); | |
113 dataColorChange.attach(&ColorSpec::activeTitle); | |
114 fontChange.attach(&FontSpec::columnHead); | |
115 | |
116 reductionMenu = new FtParserReductionDc(fileView.parser); | |
117 AgDataViewPlug *connector = new AgDataViewPlug(reductionMenu); | |
118 reductionMenu->windowConnector = connector; | |
119 reductionChoiceView.init(connector); | |
120 | |
121 bottomPanel.setSplitWindowPercentage(&reductionChoiceView, 0); | |
122 bottomPanel.setSplitWindowPercentage(&ruleView, 100); | |
123 | |
124 fileTitle | |
125 . setText(fileName.pointer()) | |
126 . setAlignment(IStaticText::centerCenter) | |
127 . setBackgroundColor(ColorSpec::inactiveTitle.bg()) | |
128 . setForegroundColor(ColorSpec::inactiveTitle.fg()) | |
129 ; | |
130 LOGS("titles set up"); | |
131 //dc_ref stackWindow = new FtParserDc(fileView.parser); | |
132 parserDc = new FtParserDc(fileView.parser); | |
133 | |
134 //fileView.parser.displayControl = stackWindow; | |
135 //stackConnector = new AgDataViewPlug(stackWindow); | |
136 stackConnector = new AgDataViewPlug(parserDc); | |
137 //stackWindow->windowConnector = stackConnector; | |
138 parserDc->windowConnector = stackConnector; | |
139 stackView.init(stackConnector); | |
140 | |
141 itemStack = fileView.parser.x1x_new(); | |
142 //dc_ref ruleWindow = new rule_stack_dc(itemStack,0,stackWindow->head_title); | |
143 //ruleControl = new rule_stack_dc(itemStack,0, stackWindow->head_title); | |
144 ruleControl = new rule_stack_dc(itemStack, 0, parserDc->head_title); | |
145 //fileView.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 int width = stackView.tableWidth; | |
153 int height = font().externalLeading() + font().maxSize().height(); | |
154 ISize minSize(width, 5*height); | |
155 | |
156 LOGV(minSize.asString()); | |
157 leftPanel | |
158 . addToCell(&stackView, 1,1) | |
159 . setColumnWidth(1,width,true) | |
160 . setRowHeight(1,0,true) | |
161 . setMinimumSize(minSize) | |
162 ; | |
163 width = fileTitle.minimumSize().width(); | |
164 int maxWidth = IWindow::desktopWindow()->size().width()/3; | |
165 IFont titleFont = fileTitle.font(); | |
166 int lineHeight = titleFont.maxCharHeight() + titleFont.externalLeading() | |
167 + titleFont.maxDescender(); | |
168 if (width > maxWidth) { | |
169 width = maxWidth; | |
170 } | |
171 minSize.setWidth(maxWidth); | |
172 minSize.setHeight(lineHeight); | |
173 fileTitle.setMinimumSize(minSize); | |
174 minSize = ISize(width, 5*height); | |
175 LOGV(minSize.asString()); | |
176 rightPanel | |
177 . addToCell(&fileTitle, 1, 1) | |
178 . addToCell(&fileView, 1, 2) | |
179 . setColumnWidth(1, width, true) | |
180 . setRowHeight(2, 0, true) | |
181 . setMinimumSize(minSize) | |
182 ; | |
183 mainSplitter.setSplitWindowPercentage(&tracePanels, 60); | |
184 mainSplitter.setSplitWindowPercentage(&bottomPanel, 40); | |
185 tracePanels.setSplitWindowPercentage(&leftPanel, 25); | |
186 tracePanels.setSplitWindowPercentage(&rightPanel, 75); | |
187 LOGS("splitters set"); | |
188 AgFocusHandler::handleEventsFor(&stackView.dataArea); | |
189 AgFocusHandler::handleEventsFor(&fileTitle); | |
190 AgFocusHandler::handleEventsFor(&fileView.dataArea); | |
191 AgFocusHandler::handleEventsFor(&reductionChoiceView.dataArea); | |
192 AgFocusHandler::handleEventsFor(&ruleView.dataArea); | |
193 LOGS("Focus handler set"); | |
194 IMouseHandler::handleEventsFor(&fileTitle); | |
195 IPaintHandler::handleEventsFor(this); | |
196 LOGS("Mouse handler set"); | |
197 focusControl = FileTraceWindow::fileTab; | |
198 LOGS("all done"); | |
199 } | |
200 | |
201 FileTraceView::~FileTraceView() { | |
202 AgFocusHandler::stopHandlingEventsFor(&stackView.dataArea); | |
203 AgFocusHandler::stopHandlingEventsFor(&fileTitle); | |
204 AgFocusHandler::stopHandlingEventsFor(&fileView.dataArea); | |
205 AgFocusHandler::stopHandlingEventsFor(&reductionChoiceView.dataArea); | |
206 AgFocusHandler::stopHandlingEventsFor(&ruleView.dataArea); | |
207 IMouseHandler::stopHandlingEventsFor(&fileTitle); | |
208 IPaintHandler::stopHandlingEventsFor(this); | |
209 } | |
210 | |
211 Boolean FileTraceView::paintWindow(IPaintEvent &event) { | |
212 LOGSECTION("FileTraceView::paintWindow"); | |
213 LOGV(event.rect().asString()); | |
214 event.clearBackground(IGUIColor::dialogBgnd); | |
215 return false; | |
216 } | |
217 | |
218 FileTraceView &FileTraceView::refreshRules(int rule) { | |
219 LOGSECTION("FileTraceView::refreshRules"); | |
220 LOGV(rule); | |
221 FtParser &parser = fileView.parser; | |
222 delete_tsd(itemStack); | |
223 itemStack = parser.x1x_new(); | |
224 //parser.ruleControl->parser_stack = parser.itemStack; | |
225 ruleControl->parser_stack = itemStack; | |
226 int k = itemStack->nt; | |
227 int ln = parser.stateStack.size(); | |
228 //parser.ruleControl->des->d_size.y = k; | |
229 ruleControl->des->d_size.y = k; | |
230 //LOGV(k); | |
231 while (k--) { | |
232 int sx, sn, fn, fx; | |
233 xtxf(itemStack, k, &sx, &sn, &fn, &fx); | |
234 int length = Rule(fn)->length(); | |
235 //LOGV(length); | |
236 if (sx == ln && rule == 0) { | |
237 break; | |
238 } | |
239 if (rule && fn == rule && fx == 0 && sx+length >= ln) { | |
240 break; | |
241 } | |
242 } | |
243 k = itemStack->nt - 1 - k; | |
244 //LOGV(k); | |
245 | |
246 ruleView | |
247 . reset() | |
248 . setCursorLine(itemStack->nt-1) | |
249 . setCursorLine(k) | |
250 . synchCursor(k); | |
251 //. refresh(); | |
252 return *this; | |
253 } | |
254 | |
255 Boolean FileTraceView::mouseClicked(IMouseClickEvent &event) { | |
256 LOGSECTION("FileTraceView::mouseClicked"); | |
257 LOGV(event.mouseButton()) LCV(event.mouseAction()); | |
258 if (event.mouseAction() != IMouseClickEvent::down) { | |
259 return false; | |
260 } | |
261 IWindow *controlWindow = event.controlWindow(); | |
262 if (controlWindow == &fileTitle) { | |
263 fileView.dataArea.setFocus(); | |
264 focusControl = FileTraceWindow::fileTab; | |
265 return false; | |
266 } | |
267 return false; | |
268 } | |
269 | |
270 Boolean FileTraceView::gotFocus(IEvent &event) { | |
271 LOGSECTION("FileTraceView::gotFocus"); | |
272 LOGV(focusControl); | |
273 IWindowHandle handle = (void *) event.parameter1(); | |
274 //IWindow *lastWindow = IWindow::windowWithHandle(handle); | |
275 //LOGV(handle.asUnsigned()) LCV((int) lastWindow); | |
276 LOGV((int) event.controlWindow()) LCV((int) event.dispatchingWindow()); | |
277 if (event.controlWindow() == &fileView.dataArea) { | |
278 ColorSpec *color = &ColorSpec::activeTitle; | |
279 fileTitle.setBackgroundColor(color->bg()); | |
280 fileTitle.setForegroundColor(color->fg()); | |
281 focusControl = activePanel = FileTraceWindow::fileTab; | |
282 | |
283 fileTitle.refresh(); | |
284 } | |
285 else if (event.controlWindow() == &stackView.dataArea) { | |
286 focusControl = activePanel = FileTraceWindow::stackTab; | |
287 } | |
288 else if (event.controlWindow() == &reductionChoiceView.dataArea) { | |
289 focusControl = activePanel = FileTraceWindow::choiceTab; | |
290 } | |
291 else if (event.controlWindow() == &ruleView.dataArea) { | |
292 focusControl = activePanel = FileTraceWindow::ruleTab; | |
293 } | |
294 frame->parseButton.disableDefault(); | |
295 frame->resetButton.disableDefault(); | |
296 frame->reloadButton.disableDefault(); | |
297 frame->helpButton.disableDefault(); | |
298 frame->stepButton.enableDefault(); | |
299 | |
300 LOGV(focusControl); | |
301 return false; | |
302 } | |
303 | |
304 Boolean FileTraceView::lostFocus(IEvent &event) { | |
305 LOGSECTION("FileTraceView::lostFocus"); | |
306 LOGV(focusControl); | |
307 IWindowHandle handle = (void *) event.parameter1(); | |
308 //IWindow *nextWindow = IWindow::windowWithHandle(handle); | |
309 //LOGV(handle.asUnsigned()) LCV((int) nextWindow); | |
310 if (event.controlWindow() == &fileView.dataArea) { | |
311 ColorSpec *color = &ColorSpec::inactiveTitle; | |
312 fileTitle.setBackgroundColor(color->bg()); | |
313 fileTitle.setForegroundColor(color->fg()); | |
314 fileTitle.refresh(); | |
315 } | |
316 return false; | |
317 } | |
318 | |
319 Boolean FileTraceWindow::characterKeyPress(IKeyboardEvent &event) { | |
320 LOGSECTION("FileTraceWindow::characterKeyPress"); | |
321 ok_ptr(this); | |
322 char character = event.character(); | |
323 LOGV(character) LCV(event.isCtrlDown()); | |
324 if (event.isCtrlDown()) { | |
325 return true; | |
326 } | |
327 if (canvas.focusControl < stepTab) { | |
328 canvas.activePanel = canvas.focusControl; | |
329 } | |
330 switch (character) { | |
331 case 'p': | |
332 case 'P': | |
333 parseFile(); | |
334 return true; | |
335 case 's': | |
336 case 'S': | |
337 doStep(); | |
338 return true; | |
339 case 'r': | |
340 case 'R': | |
341 resetParser(); | |
342 return true; | |
343 case 'l': | |
344 case 'L': | |
345 reload(); | |
346 return true; | |
347 case 'h': | |
348 case 'H': | |
349 AgHelpWindow::showHelp("File Trace"); | |
350 helpButton.disableDefault(); | |
351 helpButton.unhighlight(); | |
352 stepButton.enableDefault(); | |
353 canvas.focusControl = fileTab; | |
354 return true; | |
355 } | |
356 return false; | |
357 } | |
358 | |
359 Boolean FileTraceWindow::virtualKeyPress(IKeyboardEvent &event) { | |
360 LOGSECTION("FileTraceWindow::virtualKeyPress"); | |
361 ok_ptr(this); | |
362 int increment = 0; | |
363 int &focusControl = canvas.focusControl; | |
364 int &activePanel = canvas.activePanel; | |
365 LOGV(focusControl); | |
366 LOGV((int) event.controlWindow()) LCV((int) event.dispatchingWindow()); | |
367 LOGV(event.virtualKey()); | |
368 switch (event.virtualKey()) { | |
369 case IKeyboardEvent::enter: | |
370 case IKeyboardEvent::newLine: { | |
371 //activePanel = focusControl; | |
372 if (focusControl >= stepTab) { | |
373 tabControl[focusControl].action.performDeferred(); | |
374 IPushButton *button = (IPushButton *)tabControl[focusControl].window; | |
375 button->disableDefault(); | |
376 button->unhighlight(); | |
377 } | |
378 else { | |
379 activePanel = focusControl; | |
380 doStep(); | |
381 } | |
382 return true; | |
383 } | |
384 case IKeyboardEvent::right: | |
385 case IKeyboardEvent::down: | |
386 if (focusControl < stepTab) { | |
387 return AgFrame::virtualKeyPress(event); | |
388 } | |
389 if (focusControl + 1 == nTabs) { | |
390 increment = stepTab - focusControl; | |
391 } | |
392 else { | |
393 increment = 1; | |
394 } | |
395 break; | |
396 case IKeyboardEvent::tab: | |
397 increment = 1; | |
398 break; | |
399 case IKeyboardEvent::left: | |
400 case IKeyboardEvent::up: | |
401 if (focusControl < stepTab) { | |
402 return AgFrame::virtualKeyPress(event); | |
403 } | |
404 if (focusControl == stepTab) { | |
405 increment = nTabs - 1 - stepTab; | |
406 } | |
407 else { | |
408 increment = nTabs - 1; | |
409 } | |
410 break; | |
411 case IKeyboardEvent::backTab: | |
412 increment = nTabs - 1; | |
413 break; | |
414 default: | |
415 return AgFrame::virtualKeyPress(event); | |
416 } | |
417 if (event.controlWindow() != event.dispatchingWindow()) { | |
418 return true; | |
419 } | |
420 IPushButton *button; | |
421 if (focusControl >= stepTab) { | |
422 button = (IPushButton *) tabControl[focusControl].window; | |
423 button->unhighlight(); | |
424 button->disableDefault(); | |
425 } | |
426 do { | |
427 focusControl = (focusControl + increment) % nTabs; | |
428 } while (!tabControl[focusControl].enabled); | |
429 LOGV(focusControl) LCV(increment); | |
430 if (focusControl >= stepTab) { | |
431 button = (IPushButton *) tabControl[focusControl].window; | |
432 } | |
433 else { | |
434 button = &stepButton; | |
435 } | |
436 button->enableDefault(); | |
437 setFocus(); | |
438 return true; | |
439 } | |
440 | |
441 Boolean FileTraceWindow::mouseClicked(IMouseClickEvent &event) { | |
442 LOGSECTION("FileTraceWindow::mouseClicked"); | |
443 ok_ptr(this); | |
444 LOGV(event.mouseButton()) LCV(event.mouseAction()); | |
445 if (event.mouseButton() != 0) { | |
446 return false; | |
447 } | |
448 int &focusControl = canvas.focusControl; | |
449 int &activePanel = canvas.activePanel; | |
450 IWindow *controlWindow = event.controlWindow(); | |
451 LOGV((int)controlWindow) LCV((int)event.dispatchingWindow()); | |
452 | |
453 if (event.mouseAction() == IMouseClickEvent::click) { | |
454 return false; | |
455 } | |
456 if (event.mouseAction() == IMouseClickEvent::doubleClick) { | |
457 return false; | |
458 } | |
459 | |
460 int tab; | |
461 for (tab = 0; tab < nTabs; tab++) { | |
462 LOGV(tab) LCV((int) tabControl[tab].window); | |
463 if (controlWindow == tabControl[tab].window) { | |
464 break; | |
465 } | |
466 } | |
467 if (tab == nTabs) { | |
468 return False; | |
469 } | |
470 | |
471 if (ControlPanel::helpCursorSet) { | |
472 if (event.mouseAction() == IMouseClickEvent::up) { | |
473 ControlPanel::helpCursorSet = 0; | |
474 LOGV(tabControl[tab].helpTopic); | |
475 AgHelpWindow::showHelp(tabControl[tab].helpTopic); | |
476 ControlPanel::resetCursor(); | |
477 } | |
478 return true; | |
479 } | |
480 LOGV(focusControl) LCV(activePanel); | |
481 if (tab < stepTab) { | |
482 return false; | |
483 } | |
484 if (focusControl >= stepTab) { | |
485 IPushButton *button = (IPushButton *) tabControl[focusControl].window; | |
486 button->unhighlight(); | |
487 button->disableDefault(); | |
488 } | |
489 IPushButton *button = (IPushButton *) tabControl[tab].window; | |
490 if (event.mouseAction() == IMouseClickEvent::down) { | |
491 if (focusControl < stepTab) { | |
492 activePanel = focusControl; | |
493 } | |
494 button->highlight(); | |
495 button->setFocus(); | |
496 focusControl = tab; | |
497 button->capturePointer(); | |
498 return true; | |
499 } | |
500 if (event.mouseAction() == IMouseClickEvent::up) { | |
501 button->unhighlight(); | |
502 button->releasePointer(); | |
503 AgAction &action = tabControl[tab].action; | |
504 IWindowHandle h = tabControl[tab].window->handle(); | |
505 if (h == event.windowUnderPointer()) { | |
506 action.performDeferred(); | |
507 } | |
508 else if (activePanel < stepTab) { | |
509 button->disableDefault(); | |
510 parseButton.enableDefault(); | |
511 focusControl = activePanel; | |
512 setFocus(); | |
513 } | |
514 else { | |
515 button->disableDefault(); | |
516 stepButton.enableDefault(); | |
517 focusControl = stepTab; | |
518 setFocus(); | |
519 } | |
520 return true; | |
521 } | |
522 return false; | |
523 } | |
524 | |
525 | |
526 FileTraceWindow &FileTraceWindow::setFocus() { | |
527 LOGSECTION("FileTraceWindow::setFocus"); | |
528 ok_ptr(this); | |
529 int &focusControl = canvas.focusControl; | |
530 if (focusControl < stepTab) { | |
531 canvas.activePanel = focusControl; | |
532 } | |
533 LOGV(focusControl) LCV((int) tabControl[focusControl].window); | |
534 tabControl[focusControl].window->setFocus(); | |
535 IPushButton *button; | |
536 for (int i = stepTab; i < nTabs; i++) { | |
537 button = (IPushButton *)tabControl[i].window; | |
538 button->disableDefault(); | |
539 button->unhighlight(); | |
540 } | |
541 button = &stepButton; | |
542 if (focusControl > stepTab) { | |
543 button = (IPushButton *)tabControl[focusControl].window; | |
544 } | |
545 button->enableDefault(); | |
546 return *this; | |
547 } | |
548 | |
549 | |
550 FileTraceWindow::FileTraceWindow(AgString fileName_, | |
551 int flags) | |
552 : AgFrame( IFrameWindow::dialogBackground | |
553 | IFrameWindow::systemMenu | |
554 | IFrameWindow::maximizeButton | |
555 | IFrameWindow::sizingBorder) | |
556 , canvas(this, text_file(fileName_, flags), fileName_) | |
557 , fileName(fileName_) | |
558 , toolBar(this, ISetCanvas::packTight | ISetCanvas::centerVerticalAlign) | |
559 , locationField(nextChildId(), &toolBar, &toolBar, IRectangle(), | |
560 IStaticText::defaultStyle() | |
561 | IStaticText::center | |
562 | IStaticText::vertCenter | |
563 | IStaticText::border3D) | |
564 , locationFieldHelp(&locationField, "Parse Location") | |
565 , statusField(nextChildId(), &toolBar, &toolBar, IRectangle(), | |
566 IStaticText::defaultStyle() | |
567 | IStaticText::center | |
568 | IStaticText::vertCenter | |
569 | IStaticText::border3D) | |
570 , statusFieldHelp(&statusField, "Parse Status") | |
571 , buttonGroup(&toolBar, ISetCanvas::packExpanded) | |
572 , stepButton(IDTB_STEP, &buttonGroup, SINGLE_STEP) | |
573 , parseButton(IDTB_PARSE_FILE, &buttonGroup, PARSE_FILE) | |
574 , resetButton(IDTB_RESET, &buttonGroup, RESET) | |
575 , reloadButton(IDTB_RELOAD, &buttonGroup, RELOAD) | |
576 , helpButton(IDTB_HELP, &buttonGroup, HELP) | |
577 { | |
578 LOGSECTION("FileTraceWindow::FileTraceWindow"); | |
579 ok_ptr(this); | |
580 | |
581 tabControl[stackTab] = TabControl(&canvas.stackView.dataArea, | |
582 "Parser Stack Pane"); | |
583 tabControl[fileTab] = TabControl(&canvas.fileView.dataArea, | |
584 "Test File Pane"); | |
585 tabControl[choiceTab] = TabControl(&canvas.reductionChoiceView.dataArea, | |
586 "Reduction Choices Pane"); | |
587 tabControl[choiceTab].enabled = 0; | |
588 tabControl[ruleTab] = TabControl(&canvas.ruleView.dataArea, | |
589 "Rule Stack Pane"); | |
590 tabControl[stepTab] | |
591 = TabControl(&stepButton, "Single Step", actionObject(this, doStep)); | |
592 tabControl[parseTab] | |
593 = TabControl(&parseButton, "Parse File", actionObject(this, parseFile)); | |
594 tabControl[resetTab] | |
595 = TabControl(&resetButton, "Reset", actionObject(this, resetParser)); | |
596 tabControl[reloadTab] | |
597 = TabControl(&reloadButton, "Reload", actionObject(this, reload)); | |
598 tabControl[helpTab] | |
599 = TabControl(&helpButton, "File Trace", actionObject(this, showHelp)); | |
600 | |
601 #ifdef INCLUDE_LOGGING | |
602 { | |
603 for (int tab = 0; tab < nTabs; tab++) { | |
604 LOGV(tab) LCV((int) tabControl[tab].window); | |
605 } | |
606 } | |
607 #endif | |
608 setFont(canvas.stackView.dataArea.font()); | |
609 | |
610 ISize buttonSize= stepButton.minimumSize(); | |
611 IFont buttonFont = stepButton.font(); | |
612 int buttonWidth = buttonFont.textWidth(" Synch Parse "); | |
613 LOGV(buttonWidth); | |
614 buttonSize.setWidth(buttonWidth); | |
615 stepButton.setMinimumSize(buttonSize); | |
616 parseButton.setMinimumSize(buttonSize); | |
617 int buttonHeight = buttonSize.height(); | |
618 | |
619 syntaxDependent = 1; | |
620 IColor buttonTextColor = stepButton.foregroundColor(); | |
621 | |
622 ISize minimum(buttonWidth, buttonHeight); | |
623 LOGV(minimum.asString()); | |
624 | |
625 locationField.setFont(buttonFont); | |
626 | |
627 locationField.setMinimumSize( | |
628 ISize(locationField.font().textWidth("9999:999"), | |
629 minimum.height()) | |
630 ); | |
631 locationField.setBackgroundColor(IGUIColor::dialogBgnd); | |
632 locationField.setForegroundColor(buttonTextColor); | |
633 LOGV(locationField.minimumSize().asString()); | |
634 | |
635 statusField.setFont(buttonFont); | |
636 LOGV(statusField.minimumSize().asString()); | |
637 statusField.setMinimumSize( | |
638 ISize(statusField.font().textWidth("MSelect reduction tokenM"), | |
639 minimum.height()) | |
640 ); | |
641 LOGV(statusField.minimumSize().asString()); | |
642 statusField.setBackgroundColor(IGUIColor::dialogBgnd); | |
643 statusField.setForegroundColor(buttonTextColor); | |
644 | |
645 ISize margin = toolBar.margin(); | |
646 margin.setHeight(0); | |
647 toolBar.setMargin(margin); | |
648 margin = buttonGroup.margin(); | |
649 margin.setWidth(0); | |
650 margin.setHeight(margin.height()/2); | |
651 buttonGroup.setMargin(margin); | |
652 ISize pad = buttonGroup.pad(); | |
653 pad.setWidth(0); | |
654 buttonGroup.setPad(pad); | |
655 | |
656 stepButton.enableDefault(); | |
657 | |
658 LOGV(stepButton.minimumSize().asString()); | |
659 LOGV(parseButton.minimumSize().asString()); | |
660 LOGV(resetButton.minimumSize().asString()); | |
661 LOGV(reloadButton.minimumSize().asString()); | |
662 LOGV(helpButton.minimumSize().asString()); | |
663 | |
664 LOGV((int) this); | |
665 setClient(&canvas); | |
666 AgString objectTitle = AgString::format("AnaGram : %s", | |
667 simple_file_name.pointer()); | |
668 windowTitle.setObjectText(objectTitle.pointer()); | |
669 | |
670 addExtension(&toolBar, IFrameWindow::belowClient, IFrameWindow::thickLine); | |
671 canvas.fileView.desynchAction = actionObject(this, onDesynch); | |
672 canvas.fileView.resynchAction = actionObject(this, onResynch); | |
673 | |
674 windowTitle.setViewText("File Trace"); | |
675 registerTitle("File Trace"); | |
676 | |
677 canvas.stackView.setColumnTitles("\tState\tToken\tToken Name"); | |
678 ISize sizeLeft = canvas.stackView.suggestSize(); | |
679 ISize sizeRight = canvas.fileView.suggestSize(); | |
680 LOGV(sizeLeft.asString()); | |
681 LOGV(sizeRight.asString()); | |
682 int thickness = | |
683 2*canvas.tracePanels.splitBarThickness(ISplitCanvas::splitBarEdge); | |
684 thickness += | |
685 canvas.tracePanels.splitBarThickness(ISplitCanvas::splitBarMiddle); | |
686 int width = sizeLeft.width() + sizeRight.width() + thickness; | |
687 int height = max(2*sizeLeft.height(), sizeRight.height()); | |
688 height += height/2; | |
689 | |
690 LOGV(width) LCV(height); | |
691 int maxWidth = 2*IWindow::desktopWindow()->size().width()/3; | |
692 LOGV(maxWidth); | |
693 int toolWidth = toolBar.minimumSize().width(); | |
694 if (maxWidth < toolWidth) { | |
695 maxWidth = toolWidth; | |
696 } | |
697 if (width > maxWidth) { | |
698 width = maxWidth; | |
699 } | |
700 if (width < toolWidth) { | |
701 width = toolWidth; | |
702 } | |
703 | |
704 int left = canvas.stackView.columnHeadWidth; | |
705 left += 2*font().avgCharWidth(); | |
706 int maxRight = maxWidth - left; | |
707 int right = sizeRight.width(); | |
708 LOGV(right); | |
709 LOGV(maxRight); | |
710 if (right > maxRight) right = maxRight; | |
711 int sum = left+right; | |
712 LOGV(left) LCV(right) LCV(sum); | |
713 canvas.tracePanels.setSplitWindowPercentage( | |
714 &canvas.leftPanel, (100*left)/sum); | |
715 canvas.tracePanels.setSplitWindowPercentage( | |
716 &canvas.rightPanel, (100*right)/sum); | |
717 LOGS("percentages set") LCV((100*left)/sum) LCV((100*right)/sum); | |
718 ISize clientSize(width, height); | |
719 LOGV(clientSize.asString()); | |
720 IRectangle frameRect(frameRectFor(clientSize)); | |
721 LOGV(frameRect.asString()); | |
722 sizeTo(frameRect.size()); | |
723 LOGV(frameRect.size().asString()); | |
724 | |
725 positionFrame(); | |
726 canvas.stackView | |
727 . setFrame(this) | |
728 . setEnterAction(AgAction()) | |
729 . setSelectAction(actionObject(this, stackSelect)) | |
730 ; | |
731 | |
732 canvas.fileView | |
733 . setFrame(this) | |
734 . setEnterAction(actionObject(this, fileEnter)) | |
735 ; | |
736 | |
737 canvas.ruleView | |
738 . setEnterAction(AgAction()) | |
739 . setSelectAction(actionObject(this, ruleSelect)) | |
740 . setFrame(this) | |
741 ; | |
742 | |
743 canvas.reductionChoiceView | |
744 . setEnterAction(actionObject(this, reductionChoiceEnter)) | |
745 . setSelectAction(actionObject(this, tokenSelect)) | |
746 ; | |
747 | |
748 FtParser &parser = canvas.fileView.parser; | |
749 setLocationField(canvas.fileView.parser.displayLocation()); | |
750 statusField.setText(FtParser::processStateText[parser.processState]); | |
751 | |
752 for (int i = 0; i < nTabs; i++) { | |
753 IKeyboardHandler::handleEventsFor(tabControl[i].window); | |
754 IMouseHandler::handleEventsFor(tabControl[i].window); | |
755 } | |
756 frameHandler->setActivateAction(actionObject(this, onActivate)); | |
757 AgFocusHandler::handleEventsFor(this); | |
758 LOGS("Handlers set"); | |
759 canvas.focusControl = canvas.activePanel = fileTab; | |
760 canvas.fileView.dataArea.setFocus(); | |
761 //setFocus(); | |
762 show(); | |
763 LOGS("all done"); | |
764 } | |
765 | |
766 void FileTraceWindow::onDesynch() { | |
767 LOGSECTION("FileTrace"); | |
768 ok_ptr(this); | |
769 stepButton.setText(SYNCH_PARSE); | |
770 } | |
771 | |
772 void FileTraceWindow::onResynch() { | |
773 LOGSECTION("FileTrace"); | |
774 ok_ptr(this); | |
775 stepButton.setText(SINGLE_STEP); | |
776 } | |
777 | |
778 void FileTraceWindow::onActivate() { | |
779 LOGSECTION("FileTraceWindow::onActivate"); | |
780 ok_ptr(this); | |
781 //canvas.setFocus(); | |
782 } | |
783 | |
784 FileTraceWindow::~FileTraceWindow() { | |
785 AgFocusHandler::stopHandlingEventsFor(this); | |
786 for (int i = 0; i < nTabs; i++) { | |
787 IKeyboardHandler::stopHandlingEventsFor(tabControl[i].window); | |
788 IMouseHandler::stopHandlingEventsFor(tabControl[i].window); | |
789 } | |
790 } | |
791 | |
792 Boolean FileTraceWindow::gotFocus(IEvent &event) { | |
793 LOGSECTION("FileTraceWindow::gotFocus"); | |
794 ok_ptr(this); | |
795 //int &focusControl = canvas.focusControl; | |
796 //LOGV(focusControl); | |
797 IWindowHandle handle = (void *) event.parameter1(); | |
798 //IWindow *lastWindow = IWindow::windowWithHandle(handle); | |
799 //LOGV((int) lastWindow); | |
800 LOGV((int) &canvas.stackView.dataArea); | |
801 LOGV((int) &canvas.ruleView.dataArea); | |
802 return false; | |
803 } | |
804 | |
805 AgString FileTraceWindow::copyTitle() { | |
806 ok_ptr(this); | |
807 | |
808 switch (canvas.focusControl) { | |
809 case 0: return canvas.stackView.copyTitle;; | |
810 case 2: return canvas.reductionChoiceView.copyTitle;; | |
811 case 3: return canvas.ruleView.copyTitle;; | |
812 } | |
813 return AgString(); | |
814 } | |
815 | |
816 FileTraceWindow &FileTraceWindow::copyTo(IClipboard &c) { | |
817 ok_ptr(this); | |
818 | |
819 switch (canvas.focusControl) { | |
820 case 0: canvas.stackView.copyTo(c); break; | |
821 case 2: canvas.reductionChoiceView.copyTo(c); break; | |
822 case 3: canvas.ruleView.copyTo(c); break; | |
823 } | |
824 return *this; | |
825 } | |
826 | |
827 | |
828 Boolean FileTraceWindow::windowResize(IResizeEvent &event){ | |
829 LOGSECTION("FileTraceWindow::windowResize"); | |
830 ok_ptr(this); | |
831 | |
832 if (event.controlWindow() != this) { | |
833 return false; | |
834 } | |
835 canvas.mainSplitter.sizeTo( | |
836 clientRectFor(IRectangle(IPoint(), event.newSize())).size() | |
837 ); | |
838 LOGV(id()); | |
839 return false; | |
840 } | |
841 | |
842 FileTraceWindow &FileTraceWindow::setLocationField(cint loc) { | |
843 ok_ptr(this); | |
844 char buffer[100]; | |
845 sprintf(buffer, "%d:%d", loc.y+1, loc.x+1); | |
846 locationField.setText(buffer); | |
847 return *this; | |
848 } | |
849 | |
850 FileTraceWindow &FileTraceWindow::setStatusField(const char *msg) { | |
851 ok_ptr(this); | |
852 statusField.setText(msg); | |
853 statusField.refresh(IWindow::immediate); | |
854 return *this; | |
855 } | |
856 | |
857 FileTraceWindow &FileTraceWindow::showReductionSelection() { | |
858 LOGSECTION("FileTraceWindow::showReductionSelection"); | |
859 ok_ptr(this); | |
860 FtParser &parser = canvas.fileView.parser; | |
861 canvas.reductionMenu = new FtParserReductionDc(parser); | |
862 AgDataViewPlug *connector = new AgDataViewPlug(canvas.reductionMenu); | |
863 canvas.reductionMenu->windowConnector = connector; | |
864 | |
865 canvas.reductionChoiceView.init(connector); | |
866 | |
867 LOGV(canvas.reductionMenu->columnHeadTitle.pointer()); | |
868 LOGV(connector->columnHeadTitle().pointer()); | |
869 | |
870 ISize tableSize = canvas.reductionChoiceView.suggestSize(); | |
871 | |
872 int width = 40*font().avgCharWidth(); | |
873 int testWidth = tableSize.width(); | |
874 if (testWidth < width/2) { | |
875 width = width/2; | |
876 } | |
877 else if (testWidth > 2*width) { | |
878 width = 2*width; | |
879 } | |
880 else { | |
881 width = testWidth; | |
882 } | |
883 | |
884 int rightWidth = canvas.bottomPanel.size().width(); | |
885 | |
886 int thickness = | |
887 2*canvas.tracePanels.splitBarThickness(ISplitCanvas::splitBarEdge); | |
888 thickness += | |
889 canvas.tracePanels.splitBarThickness(ISplitCanvas::splitBarMiddle); | |
890 canvas.bottomPanel.setSplitWindowPercentage(&canvas.reductionChoiceView, | |
891 width); | |
892 canvas.bottomPanel.setSplitWindowPercentage(&canvas.ruleView, | |
893 rightWidth - width - thickness); | |
894 | |
895 canvas.bottomPanel.refresh(); | |
896 LOGV(canvas.size().asString()); | |
897 int ln = parser.reductionSelection; | |
898 canvas.reductionChoiceView | |
899 . setCursorLine(ln) | |
900 . show() | |
901 ; | |
902 parser.reductionState.token = ibnfs[ibnfb[parser.ruleToReduce]+ln]; | |
903 canvas.stackView.repaintLine(parser.stateStack.size()); | |
904 canvas.reductionChoiceView.dataArea.setFocus(); | |
905 return *this; | |
906 } | |
907 | |
908 FileTraceView &FileTraceView::completeReduction() { | |
909 LOGSECTION("FileTraceView::completeReduction"); | |
910 reductionMenu->des->d_size.y = 0; | |
911 bottomPanel.setSplitWindowPercentage(&reductionChoiceView, 0); | |
912 bottomPanel.setSplitWindowPercentage(&ruleView, 100); | |
913 bottomPanel.refresh(); | |
914 FtParser &parser = fileView.parser; | |
915 int lineNumber = reductionChoiceView.getCursorLine(); | |
916 LOGV(lineNumber); | |
917 int token = ibnfs[ibnfb[parser.ruleToReduce]+lineNumber]; | |
918 LOGV(token); | |
919 parser.completeReduction(token); | |
920 int fileIndex = (char *) parser.state.pointer - parser.text.pointer(); | |
921 fileView.reductionTable[fileIndex] = token; | |
922 LOGV(fileIndex) LCV(token) LCV(fileView.reductionTable[fileIndex]); | |
923 return *this; | |
924 } | |
925 | |
926 void FileTraceWindow::reductionChoiceEnter() { | |
927 LOGSECTION("FileTraceWindow::reductionChoiceEnter"); | |
928 ok_ptr(this); | |
929 canvas.completeReduction(); | |
930 fileEnter(); | |
931 } | |
932 | |
933 void FileTraceWindow::synchRules(unsigned stackIndex, unsigned token) { | |
934 LOGSECTION("FileTraceWindow::synchRules"); | |
935 ok_ptr(this); | |
936 FtParser &parser = canvas.fileView.parser; | |
937 unsigned stackLocation = canvas.itemStack->nt; | |
938 int sx, sn, snx; | |
939 if (stackIndex >= parser.stateStack.size()) { | |
940 sn = parser.state.number; | |
941 } | |
942 else { | |
943 sn = parser.stateStack[stackIndex].number; | |
944 } | |
945 state_number_map *sp = &map_state_number[sn]; | |
946 LOGV(stackLocation); | |
947 while (stackLocation--) { | |
948 int fn, fx; | |
949 xtxf(canvas.itemStack,stackLocation, &sx, &snx, &fn, &fx); | |
950 if (sx == stackIndex) { | |
951 break; | |
952 } | |
953 } | |
954 int k = stackLocation; | |
955 LOGV(sn); | |
956 LOGV(token); | |
957 if (stackIndex >= parser.stateStack.size()) { | |
958 int ruleViewLine = canvas.itemStack->nt - stackLocation - 1; | |
959 do { | |
960 int fn, fx; | |
961 xtxf(canvas.itemStack, k, &sx, &snx, &fn, &fx); | |
962 if (fx < Rule(fn)->length() | |
963 && token == Rule(fn).token(fx)) | |
964 //&& token == lstptr(map_form_number[fn],tokens)[fx]) | |
965 { | |
966 k = canvas.itemStack->nt - k - 1; | |
967 canvas.ruleView.setCursorLine(k).synchCursor(k); | |
968 ruleViewLine = k; | |
969 return; | |
970 } | |
971 unsigned *p = lstptr(*sp,reductions); | |
972 unsigned n = sp->n_reductions; | |
973 while (n--) { | |
974 unsigned tn = *p++; | |
975 unsigned rule = *p++; | |
976 if (rule == fn && tn == token) { | |
977 k = canvas.itemStack->nt - k - 1; | |
978 canvas.ruleView.setCursorLine(k).synchCursor(k); | |
979 ruleViewLine = k; | |
980 return; | |
981 } | |
982 } | |
983 k--; | |
984 } while (k >= 0 && sx == stackIndex); | |
985 canvas.ruleView.setCursorLine(ruleViewLine).synchCursor(ruleViewLine); | |
986 return; | |
987 } | |
988 int nextState; | |
989 if (stackIndex + 1 >= parser.stateStack.size()) { | |
990 nextState = parser.state.number; | |
991 } | |
992 else { | |
993 nextState = parser.stateStack[stackIndex+1].number; | |
994 } | |
995 int charToken = map_state_number[nextState].char_token; | |
996 LOGV(nextState) LCV(charToken); | |
997 do { | |
998 int fn,fx; | |
999 xtxf(canvas.itemStack, k, &sx, &snx, &fn, &fx); | |
1000 int length = Rule(fn)->length(); | |
1001 LOGV(k) LCV(snx); | |
1002 LOGV(fn) LCV(fx) LCV(length); | |
1003 if (fx < length | |
1004 && charToken == Rule(fn).token(fx)) { | |
1005 //&& charToken == lstptr(map_form_number[fn],tokens)[fx]) { | |
1006 k = canvas.itemStack->nt - k - 1; | |
1007 canvas.ruleView.setCursorLine(k).synchCursor(k); | |
1008 return; | |
1009 } | |
1010 k--; | |
1011 LOGV(k); | |
1012 LOGV(sn) LCV(snx); | |
1013 } while (k >= 0 && sx == stackIndex); | |
1014 } | |
1015 | |
1016 void FileTraceWindow::ruleSelect() { | |
1017 LOGSECTION("FileTraceWindow::ruleSelect"); | |
1018 ok_ptr(this); | |
1019 FtParser &parser = canvas.fileView.parser; | |
1020 int ruleLine = canvas.ruleView.getCursorLine(); | |
1021 | |
1022 int k = canvas.itemStack->nt - ruleLine - 1; | |
1023 LOGV(k); | |
1024 int sx, sn, fn, fx; | |
1025 xtxf(canvas.itemStack, k, &sx, &sn, &fn, &fx); | |
1026 int length = Rule(fn)->length(); | |
1027 LOGV(fn); | |
1028 LOGV(fx); | |
1029 LOGV(length); | |
1030 int stackDepth = parser.stateStack.size(); | |
1031 int stackLevel = sx; | |
1032 LOGV(stackLevel) LCV(stackDepth); | |
1033 if (stackLevel == stackDepth && | |
1034 parser.processState == FtParser::selectionRequired) { | |
1035 if (fx >= length) { | |
1036 return; | |
1037 } | |
1038 //int tn = lstptr(map_form_number[fn],tokens)[fx]; | |
1039 int tn = Rule(fn).token(fx); | |
1040 LOGV(tn); | |
1041 int n = ibnfn[parser.ruleToReduce]; | |
1042 while (n--) { | |
1043 LOGV(n); | |
1044 LOGV(ibnfs[ibnfb[parser.ruleToReduce]+n]); | |
1045 if (ibnfs[ibnfb[parser.ruleToReduce]+n] == tn) { | |
1046 break; | |
1047 } | |
1048 } | |
1049 LOGV(fn) LCV(n) LCV(tn); | |
1050 canvas.reductionChoiceView.setCursorLine(n); | |
1051 parser.reductionState.token = tn; | |
1052 canvas.stackView.repaintLine(stackDepth); | |
1053 return; | |
1054 } | |
1055 canvas.stackView.setCursorLine(stackLevel); | |
1056 //canvas.fileView.turnHighlightOn(stackLevel); | |
1057 if (parser.processState != FtParser::finished) { | |
1058 canvas.fileView.turnHighlightOn(stackLevel); | |
1059 } | |
1060 } | |
1061 | |
1062 void FileTraceWindow::stackSelect() { | |
1063 LOGSECTION("FileTraceWindow::stackSelect"); | |
1064 ok_ptr(this); | |
1065 int ln = canvas.stackView.getCursorLine(); | |
1066 LOGV(ln); | |
1067 FtParser &parser = canvas.fileView.parser; | |
1068 if (parser.processState != FtParser::finished) { | |
1069 canvas.fileView.turnHighlightOn(ln); | |
1070 } | |
1071 //int sn = parser.state.number; | |
1072 int tn = parser.state.token; | |
1073 if (ln < parser.stateStack.size()) { | |
1074 tn = parser.stateStack[ln].token; | |
1075 } | |
1076 synchRules(ln, tn); | |
1077 } | |
1078 | |
1079 void FileTraceWindow::tokenSelect() { | |
1080 LOGSECTION("FileTraceWindow::tokenSelect"); | |
1081 ok_ptr(this); | |
1082 int ln = canvas.reductionChoiceView.getCursorLine(); | |
1083 LOGV(ln); | |
1084 FtParser &parser = canvas.fileView.parser; | |
1085 parser.reductionSelection = ln; | |
1086 int flag = parser.validSelection(ln, parser.reductionState.number); | |
1087 parser.processState = | |
1088 flag ? FtParser::selectionRequired : FtParser::selectionError; | |
1089 statusField.setText(FtParser::processStateText[parser.processState]); | |
1090 parser.reductionState.token = ibnfs[ibnfb[parser.ruleToReduce]+ln]; | |
1091 canvas.stackView.repaintLine(parser.stateStack.size()); | |
1092 } | |
1093 | |
1094 void FileTraceWindow::fileEnter() { | |
1095 LOGSECTION("FileTraceWindow::fileEnter"); | |
1096 ok_ptr(this); | |
1097 LOGV(canvas.focusControl) LCV(canvas.fileView.dataArea.hasFocus()); | |
1098 LOGV(canvas.fileView.cursorHideCount); | |
1099 if (stepButton.text() != SINGLE_STEP) { | |
1100 stepButton.setText(SINGLE_STEP); | |
1101 } | |
1102 FtParser &parser = canvas.fileView.parser; | |
1103 LOGV(parser.location()); | |
1104 unsigned stackDepth = parser.stateStack.size(); | |
1105 //parser.displayControl->des->d_size.y = stackDepth+1; | |
1106 canvas.parserDc->des->d_size.y = stackDepth+1; | |
1107 LOGV(stackDepth); | |
1108 LOGV(parser.processState); | |
1109 | |
1110 if (parser.processState > FtParser::running) { | |
1111 messageBeep(); | |
1112 } | |
1113 | |
1114 int stackCursor = stackDepth; | |
1115 canvas.focusControl = canvas.activePanel = fileTab; | |
1116 if (parser.processState == FtParser::selectionRequired) { | |
1117 canvas.fileView.turnHighlightOn(stackCursor); | |
1118 | |
1119 int k = parser.stateStack.size() - parser.reductionIndex; | |
1120 LOGV(k); | |
1121 assert((unsigned) k <= (unsigned) parser.stateStack.size()); | |
1122 parser.stateStack.discardData(k); | |
1123 unsigned stackDepth = parser.stateStack.size(); | |
1124 //parser.displayControl->des->d_size.y = stackDepth+1; | |
1125 canvas.parserDc->des->d_size.y = stackDepth+1; | |
1126 | |
1127 showReductionSelection(); | |
1128 stackCursor = parser.reductionIndex; | |
1129 canvas.reductionChoiceView.dataArea.setFocus(); | |
1130 canvas.focusControl = canvas.activePanel = choiceTab; | |
1131 tabControl[choiceTab].enabled = 1; | |
1132 } | |
1133 else if (parser.ruleToReduce) { | |
1134 parser.ruleToReduce = 0; | |
1135 canvas.reductionMenu->des->d_size.y = 0; | |
1136 canvas.bottomPanel.setSplitWindowPercentage(&canvas.reductionChoiceView,0); | |
1137 canvas.bottomPanel.setSplitWindowPercentage(&canvas.ruleView, 100); | |
1138 canvas.bottomPanel.refresh(); | |
1139 statusField.setText(FtParser::processStateText[parser.processState]); | |
1140 canvas.fileView.turnHighlightOff(); | |
1141 canvas.fileView.dataArea.setFocus(); | |
1142 tabControl[choiceTab].enabled = 0; | |
1143 } | |
1144 | |
1145 LOGV(canvas.focusControl) LCV(canvas.fileView.dataArea.hasFocus()); | |
1146 canvas.stackView.reset(); | |
1147 LOGV(canvas.focusControl) LCV(canvas.fileView.dataArea.hasFocus()); | |
1148 LOGV(canvas.fileView.cursorHideCount); | |
1149 canvas.stackView.setCursorLine(stackCursor); | |
1150 LOGV(canvas.focusControl) LCV(canvas.fileView.dataArea.hasFocus()); | |
1151 LOGV(canvas.fileView.cursorHideCount); | |
1152 canvas.stackView. refresh(); | |
1153 LOGV(canvas.focusControl) LCV(canvas.fileView.dataArea.hasFocus()); | |
1154 LOGV(canvas.fileView.cursorHideCount); | |
1155 | |
1156 LOGV(parser.location()); | |
1157 canvas.refreshRules(parser.ruleToReduce); | |
1158 LOGV(canvas.focusControl) LCV(canvas.fileView.dataArea.hasFocus()); | |
1159 LOGV(canvas.fileView.cursorHideCount); | |
1160 LOGV(parser.location()); | |
1161 | |
1162 setLocationField(canvas.fileView.parser.displayLocation()); | |
1163 LOGV(canvas.focusControl) LCV(canvas.fileView.dataArea.hasFocus()); | |
1164 LOGV(canvas.fileView.cursorHideCount); | |
1165 setStatusField(FtParser::processStateText[parser.processState]); | |
1166 LOGV(canvas.focusControl) LCV(canvas.fileView.dataArea.hasFocus()); | |
1167 LOGV(canvas.fileView.cursorHideCount); | |
1168 //canvas.fileView.dataArea.setFocus(); | |
1169 //canvas.focusControl = 1; | |
1170 setFocus(); | |
1171 LOGV(canvas.focusControl) LCV(canvas.fileView.dataArea.hasFocus()); | |
1172 LOGV(canvas.fileView.cursorHideCount); | |
1173 | |
1174 AgFrame::windowRegistry.refresh("Trace Coverage"); | |
1175 stepButton.enableDefault(); | |
1176 setMousePointer(IPointerHandle()); | |
1177 } | |
1178 | |
1179 void FileTraceWindow::reload() { | |
1180 ok_ptr(this); | |
1181 canvas.fileView.reductionTable.reset(); | |
1182 canvas.fileView.reload(); | |
1183 canvas.fileView.refresh(); | |
1184 resetParser(); | |
1185 } | |
1186 | |
1187 void FileTraceWindow::showHelp() { | |
1188 ok_ptr(this); | |
1189 AgHelpWindow::showHelp("File Trace"); | |
1190 helpButton.disableDefault(); | |
1191 helpButton.unhighlight(); | |
1192 stepButton.enableDefault(); | |
1193 canvas.focusControl = FileTraceWindow::fileTab; | |
1194 } | |
1195 | |
1196 | |
1197 | |
1198 void FileTraceWindow::resetParser() { | |
1199 ok_ptr(this); | |
1200 FtParser &parser = canvas.fileView.parser; | |
1201 if (parser.ruleToReduce) { | |
1202 parser.ruleToReduce = 0; | |
1203 canvas.reductionMenu->des->d_size.y = 0; | |
1204 canvas.bottomPanel.setSplitWindowPercentage(&canvas.reductionChoiceView,0); | |
1205 canvas.bottomPanel.setSplitWindowPercentage(&canvas.ruleView, 100); | |
1206 canvas.bottomPanel.refresh(); | |
1207 } | |
1208 parser.reset(); | |
1209 onResynch(); | |
1210 setLocationField(canvas.fileView.parser.displayLocation()); | |
1211 LOGV(parser.state.number) LCV(parser.state.token); | |
1212 //parser.displayControl->des->d_size.y = parser.stateStack.size() + 1; | |
1213 canvas.parserDc->des->d_size.y = parser.stateStack.size() + 1; | |
1214 canvas.refreshRules(0); | |
1215 synchRules(parser.stateStack.size(), parser.state.token); | |
1216 statusField.setText(FtParser::processStateText[parser.processState]); | |
1217 canvas.stackView.reset().setCursorLine(0).refresh(); | |
1218 canvas.fileView.turnHighlightOff(); | |
1219 canvas.fileView.setCursorLocation(cint(0,0)); | |
1220 canvas.fileView.refresh(); | |
1221 canvas.fileView.dataArea.setFocus(); | |
1222 canvas.focusControl = canvas.activePanel = fileTab; | |
1223 tabControl[choiceTab].enabled = 0; | |
1224 stepButton.unhighlight(); | |
1225 stepButton.enableDefault(); | |
1226 } | |
1227 | |
1228 Boolean FileTraceWindow::findNext(AgString s) { | |
1229 LOGSECTION("FileTraceWindow::findNext"); | |
1230 ok_ptr(this); | |
1231 LOGV(canvas.focusControl); | |
1232 int flag = 0; | |
1233 | |
1234 switch (canvas.focusControl) { | |
1235 case 0: { | |
1236 flag = canvas.stackView.findNext(s); | |
1237 if (flag) { | |
1238 stackSelect(); | |
1239 } | |
1240 return flag; | |
1241 } | |
1242 case 1: { | |
1243 flag = canvas.fileView.findNext(s); | |
1244 return flag; | |
1245 } | |
1246 case 2: { | |
1247 flag = canvas.reductionChoiceView.findNext(s); | |
1248 if (flag) { | |
1249 tokenSelect(); | |
1250 } | |
1251 return flag; | |
1252 } | |
1253 case 3: { | |
1254 flag = canvas.ruleView.findNext(s); | |
1255 if (flag) { | |
1256 ruleSelect(); | |
1257 } | |
1258 return flag; | |
1259 } | |
1260 } | |
1261 | |
1262 return flag; | |
1263 } | |
1264 | |
1265 Boolean FileTraceWindow::findPrev(AgString s) { | |
1266 LOGSECTION("FileTraceWindow::findPrev"); | |
1267 ok_ptr(this); | |
1268 LOGV(canvas.focusControl); | |
1269 int flag = 0; | |
1270 | |
1271 switch (canvas.focusControl) { | |
1272 case 0: { | |
1273 flag = canvas.stackView.findPrev(s); | |
1274 if (flag) { | |
1275 stackSelect(); | |
1276 } | |
1277 return flag; | |
1278 } | |
1279 case 1: | |
1280 return canvas.fileView.findPrev(s); | |
1281 case 2: { | |
1282 flag = canvas.reductionChoiceView.findPrev(s); | |
1283 if (flag) { | |
1284 tokenSelect(); | |
1285 } | |
1286 return flag; | |
1287 } | |
1288 case 3: { | |
1289 flag = canvas.ruleView.findPrev(s); | |
1290 if (flag) { | |
1291 ruleSelect(); | |
1292 } | |
1293 return flag; | |
1294 } | |
1295 } | |
1296 return flag; | |
1297 } | |
1298 | |
1299 | |
1300 void FileTraceWindow::doStep() { | |
1301 LOGSECTION("FileTraceWindow::doStep"); | |
1302 ok_ptr(this); | |
1303 FtParser &parser = canvas.fileView.parser; | |
1304 LOGV(parser.processState); | |
1305 canvas.focusControl = canvas.activePanel = fileTab; | |
1306 if (parser.processState == FtParser::selectionRequired && | |
1307 parser.location() == canvas.fileView.cursorLocation) { | |
1308 reductionChoiceEnter(); | |
1309 } | |
1310 else { | |
1311 canvas.fileView.step(); | |
1312 } | |
1313 setLocationField(parser.displayLocation()); | |
1314 statusField.setText(FtParser::processStateText[parser.processState]); | |
1315 stepButton.unhighlight(); | |
1316 stepButton.enableDefault(); | |
1317 setFocus(); | |
1318 LOGV(parser.processState); | |
1319 } | |
1320 | |
1321 void FileTraceWindow::parseFile() { | |
1322 LOGSECTION("FileTraceWindow::parseFile"); | |
1323 ok_ptr(this); | |
1324 FtParser &parser = canvas.fileView.parser; | |
1325 LOGV(parser.processState); | |
1326 if (parser.processState == FtParser::selectionRequired) { | |
1327 reductionChoiceEnter(); | |
1328 } | |
1329 if (parser.processState > FtParser::running) { | |
1330 messageBeep(); | |
1331 canvas.focusControl = canvas.activePanel = fileTab; | |
1332 parseButton.disableDefault(); | |
1333 parseButton.unhighlight(); | |
1334 setFocus(); | |
1335 return; | |
1336 } | |
1337 while (parser.processState <= FtParser::running) { | |
1338 canvas.fileView.parse(); | |
1339 if (parser.processState != FtParser::selectionRequired) { | |
1340 continue; | |
1341 } | |
1342 int fileIndex = (char *) parser.state.pointer - parser.text.pointer(); | |
1343 int tn = canvas.fileView.reductionTable[fileIndex]; | |
1344 LOGV(fileIndex) LCV(tn); | |
1345 if (tn == 0) { | |
1346 continue; | |
1347 } | |
1348 parser.completeReduction(tn); | |
1349 } | |
1350 setLocationField(parser.displayLocation()); | |
1351 statusField.setText(FtParser::processStateText[parser.processState]); | |
1352 LOGV(parser.processState); | |
1353 parseButton.unhighlight(); | |
1354 parseButton.disableDefault(); | |
1355 } |