1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
|
/*
* RTFL
*
* Copyright 2013-2015 Sebastian Geerken <sgeerken@dillo.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version; with the following exception:
*
* The copyright holders of RTFL give you permission to link this file
* statically or dynamically against all versions of the graphviz
* library, which are published by AT&T Corp. under one of the following
* licenses:
*
* - Common Public License version 1.0 as published by International
* Business Machines Corporation (IBM), or
* - Eclipse Public License version 1.0 as published by the Eclipse
* Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "objview_graph.hh" // Because ObjViewGraph is needed here.
using namespace lout::object;
using namespace lout::container::typed;
using namespace lout::misc;
using namespace dw::core;
using namespace dw::core::style;
using namespace rtfl::dw;
namespace rtfl {
namespace objects {
static void scrollToLabel (Label *label)
{
Widget *parent = label->getParent (), *child = label;
while (parent != NULL && !parent->instanceOf (ObjViewGraph::CLASS_ID)) {
if (parent->instanceOf (Toggle::CLASS_ID)) {
Toggle *toggle = (Toggle*)parent;
if (toggle->isLargeShown () && child == toggle->getSmall ())
toggle->toggle (false);
else if (!toggle->isLargeShown () && child == toggle->getLarge ())
toggle->toggle (true);
}
child = parent;
parent = parent->getParent ();
}
label->scrollTo (HPOS_INTO_VIEW, VPOS_INTO_VIEW);
}
// ----------------------------------------------------------------------
bool OVGCommonCommand::CommandLinkReceiver::click (Widget *widget, int link,
int img, int x, int y,
EventButton *event)
{
// "link" is "navigableCommandsIndex".
graph->setCommand (link);
return true;
}
// ----------------------------------------------------------------------
OVGCommonCommand::OVGCommonCommand (ObjViewGraph *graph, const char *id,
ObjViewFunction *function)
{
this->id = strdup (id);
this->graph = graph;
this->function = function;
relatedCommand = NULL;
executed = false;
visible = true;
}
OVGCommonCommand::~OVGCommonCommand ()
{
free (id);
}
const char *OVGCommonCommand::getFileName ()
{
// Not needed for non-navigable command.
assertNotReached ();
return NULL;
}
int OVGCommonCommand::getLineNo ()
{
// Not needed for non-navigable command.
assertNotReached ();
return 0;
}
int OVGCommonCommand::getProcessId ()
{
// Not yet clear what to do with this one.
assertNotReached ();
return 0;
}
void OVGCommonCommand::exec (ObjViewGraph *graph)
{
assert (!executed);
assert (graph == this->graph);
doExec ();
executed = true;
}
void OVGCommonCommand::show (ObjViewGraph *graph)
{
assert (executed);
assert (graph == this->graph);
visible = true;
doShow ();
}
void OVGCommonCommand::hide (ObjViewGraph *graph)
{
assert (executed);
assert (graph == this->graph);
visible = false;
doHide ();
}
void OVGCommonCommand::scrollTo (ObjViewGraph *graph)
{
assert (executed);
assert (graph == this->graph);
doScrollTo ();
}
void OVGCommonCommand::select (ObjViewGraph *graph)
{
assert (executed);
assert (graph == this->graph);
doSelect ();
}
void OVGCommonCommand::unselect (ObjViewGraph *graph)
{
assert (executed);
assert (graph == this->graph);
doUnselect ();
}
// Most commands do not have to impelemt these:
void OVGCommonCommand::doShow ()
{
assertNotReached ();
}
void OVGCommonCommand::doHide ()
{
assertNotReached ();
}
void OVGCommonCommand::doScrollTo ()
{
assertNotReached ();
}
void OVGCommonCommand::doSelect ()
{
assertNotReached ();
}
void OVGCommonCommand::doUnselect ()
{
assertNotReached ();
}
bool OVGCommonCommand::isVisible (ObjViewGraph *graph)
{
return visible;
}
bool OVGCommonCommand::calcVisibility (ObjViewGraph *graph)
{
return true;
}
int OVGCommonCommand::getNavigableCommandsIndex (ObjViewGraph *graph)
{
assertNotReached ();
return -1;
}
void OVGCommonCommand::setNavigableCommandsIndex (ObjViewGraph *graph,
int navigableCommandsIndex)
{
assertNotReached ();
}
void OVGCommonCommand::setVisibleIndex (ObjViewGraph *graph,
int visibleIndex)
{
assertNotReached ();
}
// ----------------------------------------------------------------------
OVGNavigableCommand::OVGNavigableCommand (const char *fileName, int lineNo,
ObjViewGraph *graph, const char *id,
ObjViewFunction *function) :
OVGCommonCommand (graph, id, function)
{
this->fileName = strdup (fileName);
this->lineNo = lineNo;
navigableCommandsIndex = -1;
label1 = label2 = NULL;
hbox = NULL;
}
OVGNavigableCommand::~OVGNavigableCommand ()
{
free (fileName);
}
const char *OVGNavigableCommand::getFileName ()
{
return fileName;
}
int OVGNavigableCommand::getLineNo ()
{
return lineNo;
}
void OVGNavigableCommand::initWidgets ()
{
label1->setLink (navigableCommandsIndex);
label1->connectLink (&linkReceiver);
label2->setLink (navigableCommandsIndex);
label2->connectLink (&linkReceiver);
}
void OVGNavigableCommand::removeWidgets ()
{
delete hbox;
label1 = label2 = NULL;
hbox = NULL;
}
int OVGNavigableCommand::getNavigableCommandsIndex (ObjViewGraph *graph)
{
return navigableCommandsIndex;
}
void OVGNavigableCommand::setNavigableCommandsIndex (ObjViewGraph *graph,
int navigableCommandsIndex)
{
this->navigableCommandsIndex = navigableCommandsIndex;
if (label1)
label1->setLink (navigableCommandsIndex);
if (label2)
label2->setLink (navigableCommandsIndex);
}
void OVGNavigableCommand::setVisibleIndex (ObjViewGraph *graph,
int visibleIndex)
{
assert (label1 != NULL);
// Assume 5 digits (99999) at max.
char buf[15];
snprintf (buf, 15, "<i>%d:</i> ", visibleIndex);
label1->setText (buf);
}
void OVGNavigableCommand::doShow ()
{
label1->show ();
label2->show ();
}
void OVGNavigableCommand::doHide ()
{
label1->hide ();
label2->hide ();
}
void OVGNavigableCommand::doScrollTo ()
{
scrollToLabel (label2);
}
void OVGNavigableCommand::doSelect ()
{
label1->select ();
label2->select ();
}
void OVGNavigableCommand::doUnselect ()
{
label1->unselect ();
label2->unselect ();
}
// ----------------------------------------------------------------------
OVGIncIndentCommand::OVGIncIndentCommand (const char *fileName, int lineNo,
ObjViewGraph *graph, const char *id,
ObjViewFunction *function) :
OVGNavigableCommand (fileName, lineNo, graph, id, function)
{
linkReceiver.setData (graph, this);
}
OVGIncIndentCommand::~OVGIncIndentCommand ()
{
}
bool OVGIncIndentCommand::calcVisibility (ObjViewGraph *graph)
{
return graph->filterTool->isTypeSelected (OVG_COMMAND_INDENT);
}
void OVGIncIndentCommand::doExec ()
{
graph->addMessage (id, "<i>start</i>", &hbox, &label1, &label2);
initWidgets ();
success = graph->incIndent (id);
}
// ----------------------------------------------------------------------
OVGDecIndentCommand::OVGDecIndentCommand (const char *fileName, int lineNo,
ObjViewGraph *graph, const char *id,
OVGIncIndentCommand *startCommand,
ObjViewFunction *function) :
OVGNavigableCommand (fileName, lineNo, graph, id, function)
{
linkReceiver.setData (graph, this);
setRelatedCommand (startCommand);
startCommand->setRelatedCommand (this);
}
OVGDecIndentCommand::~OVGDecIndentCommand ()
{
}
bool OVGDecIndentCommand::calcVisibility (ObjViewGraph *graph)
{
return graph->filterTool->isTypeSelected (OVG_COMMAND_INDENT);
}
void OVGDecIndentCommand::doExec ()
{
success = graph->decIndent (id);
graph->addMessage (id, "<i>end</i>", &hbox, &label1, &label2);
initWidgets ();
}
// ----------------------------------------------------------------------
OVGEnterCommand::OVGEnterCommand (const char *fileName, int lineNo,
ObjViewGraph *graph, const char *id,
const char *aspect, int prio,
const char *funname, const char *args,
ObjViewFunction *function) :
OVGNavigableCommand (fileName, lineNo, graph, id, function)
{
linkReceiver.setData (graph, this);
graph->filterTool->addAspect (aspect);
graph->filterTool->addPriority (prio);
this->aspect = strdup (aspect);
this->prio = prio;
this->funname = strdup (funname);
this->args = strdup (args);
}
OVGEnterCommand::~OVGEnterCommand ()
{
free (aspect);
free (funname);
free (args);
}
bool OVGEnterCommand::calcVisibility (ObjViewGraph *graph)
{
return graph->filterTool->isTypeSelected (OVG_COMMAND_FUNCTION) &&
graph->filterTool->isAspectSelected (aspect) &&
graph->filterTool->isPrioritySelected (prio);
}
void OVGEnterCommand::doExec ()
{
char *message = createMessage ("<i>enter</i>: <b>", "</b> (", ")", "");
graph->addMessage (id, message, &hbox, &label1, &label2);
freeMessage (message);
initWidgets ();
success = graph->incIndent (id);
}
char *OVGEnterCommand::createMessage (const char *c1, const char *c2,
const char *c3a, const char *c3b)
{
size_t l = strlen (c1) + strlen (funname) + strlen (c2) + strlen (args) +
strlen (c3a) + strlen (c3b) + 1;
char *message = new char[l];
snprintf (message, l, "%s%s%s%s%s%s", c1, funname, c2, args, c3a, c3b);
return message;
}
void OVGEnterCommand::freeMessage (char *message)
{
delete[] message;
}
char *OVGEnterCommand::createName ()
{
size_t l =
1 + strlen (id) + 2 + strlen (funname) + 2 + strlen (args) + 1 + 1;
char *message = new char[l];
snprintf (message, l, "[%s] %s (%s)", id, funname, args);
return message;
}
void OVGEnterCommand::freeName (char *name)
{
delete[] name;
}
int OVGEnterCommand::getColor ()
{
return graph->getObjectColor (id);
}
ObjViewFunction *OVGEnterCommand::getParent ()
{
return getFunction ();
}
bool OVGEnterCommand::isSelectable ()
{
return isVisible (graph);
}
void OVGEnterCommand::select ()
{
graph->clearSelection ();
graph->navigableCommandsPos = navigableCommandsIndex;
graph->unclearSelection ();
}
// ----------------------------------------------------------------------
OVGLeaveCommand::OVGLeaveCommand (const char *fileName, int lineNo,
ObjViewGraph *graph, const char *id,
const char *vals,
OVGEnterCommand *enterCommand) :
OVGNavigableCommand (fileName, lineNo, graph, id, enterCommand)
{
linkReceiver.setData (graph, this);
this->enterCommand = enterCommand;
this->vals = vals ? strdup (vals) : NULL;
setRelatedCommand (enterCommand);
enterCommand->setRelatedCommand (this);
}
OVGLeaveCommand::~OVGLeaveCommand ()
{
if (vals)
free (vals);
}
bool OVGLeaveCommand::calcVisibility (ObjViewGraph *graph)
{
return enterCommand->calcVisibility (graph);
}
void OVGLeaveCommand::doExec ()
{
success = graph->decIndent (id);
char *message = vals ?
enterCommand->createMessage ("<i>leave: ", "</i> (", ") ⇒ ", vals) :
enterCommand->createMessage ("<i>leave: ", "</i> (", ")", "");
graph->addMessage (id, message, &hbox, &label1, &label2);
enterCommand->freeMessage (message);
initWidgets ();
}
// ----------------------------------------------------------------------
OVGAddMessageCommand::OVGAddMessageCommand (const char *fileName, int lineNo,
ObjViewGraph *graph,
const char *id, const char *aspect,
int prio, const char *message,
ObjViewFunction *function) :
OVGNavigableCommand (fileName, lineNo, graph, id, function)
{
linkReceiver.setData (graph, this);
graph->filterTool->addAspect (aspect);
graph->filterTool->addPriority (prio);
this->aspect = strdup (aspect);
this->prio = prio;
this->message = strdup (message);
}
OVGAddMessageCommand::~OVGAddMessageCommand ()
{
free (aspect);
free (message);
}
bool OVGAddMessageCommand::calcVisibility (ObjViewGraph *graph)
{
return graph->filterTool->isTypeSelected (OVG_COMMAND_MESSAGE) &&
graph->filterTool->isAspectSelected (aspect) &&
graph->filterTool->isPrioritySelected (prio);
}
void OVGAddMessageCommand::doExec ()
{
graph->addMessage (id, message, &hbox, &label1, &label2);
initWidgets ();
}
// ----------------------------------------------------------------------
OVGAddMarkCommand::OVGAddMarkCommand (const char *fileName, int lineNo,
ObjViewGraph *graph,
const char *id, const char *aspect,
int prio, const char *mark,
ObjViewFunction *function) :
OVGNavigableCommand (fileName, lineNo, graph, id, function)
{
linkReceiver.setData (graph, this);
graph->filterTool->addAspect (aspect);
graph->filterTool->addPriority (prio);
this->aspect = strdup (aspect);
this->prio = prio;
this->mark = strdup (mark);
}
OVGAddMarkCommand::~OVGAddMarkCommand ()
{
free (aspect);
free (mark);
}
bool OVGAddMarkCommand::calcVisibility (ObjViewGraph *graph)
{
return graph->filterTool->isTypeSelected (OVG_COMMAND_MARK) &&
graph->filterTool->isAspectSelected (aspect) &&
graph->filterTool->isPrioritySelected (prio);
}
void OVGAddMarkCommand::doExec ()
{
size_t l = 13 + strlen (mark) + 1;
char *message = new char[l];
snprintf (message, l, "<i>mark:</i> %s", mark);
graph->addMessage (id, message, &hbox, &label1, &label2);
initWidgets ();
delete[] message;
}
bool OVGAddMarkCommand::isSelectable ()
{
return isVisible (graph);
}
void OVGAddMarkCommand::select ()
{
graph->clearSelection ();
graph->navigableCommandsPos = navigableCommandsIndex;
graph->unclearSelection ();
}
// ----------------------------------------------------------------------
OVGCreateCommand::OVGCreateCommand (const char *fileName, int lineNo,
ObjViewGraph *graph, const char *id,
const char *className,
ObjViewFunction *function):
OVGNavigableCommand (fileName, lineNo, graph, id, function)
{
this->className = strdup (className);
linkReceiver.setData (graph, this);
}
OVGCreateCommand::~OVGCreateCommand ()
{
free (className);
}
bool OVGCreateCommand::calcVisibility (ObjViewGraph *graph)
{
return graph->filterTool->isTypeSelected (OVG_COMMAND_CREATE);
}
void OVGCreateCommand::doExec ()
{
size_t l = 15 + strlen (className) + 1;
char *message = new char[l];
snprintf (message, l, "<i>create:</i> %s", className);
graph->addMessage (id, message, &hbox, &label1, &label2);
initWidgets ();
delete[] message;
graph->setClassName (id, className);
}
// ----------------------------------------------------------------------
OVGAddAssocCommand::OVGAddAssocCommand (const char *fileName, int lineNo,
ObjViewGraph *graph,
const char *id1, const char *id2,
ObjViewFunction *function) :
OVGNavigableCommand (fileName, lineNo, graph, id1, function)
{
linkReceiver.setData (graph, this);
this->id2 = strdup (id2);
}
OVGAddAssocCommand::~OVGAddAssocCommand ()
{
free (id2);
}
bool OVGAddAssocCommand::calcVisibility (ObjViewGraph *graph)
{
return graph->filterTool->isTypeSelected (OVG_COMMAND_ASSOC);
}
void OVGAddAssocCommand::doExec ()
{
size_t l = 14 + strlen (id2) + 5 + 1;
char *message = new char[l];
snprintf (message, l, "<i>assoc → %s</i>", id2);
graph->addMessage (id, message, &hbox, &label1, &label2);
initWidgets ();
delete[] message;
graph->addAssoc (id, id2);
}
// ----------------------------------------------------------------------
OVGAddAttrCommand::OVGAddAttrCommand (const char *fileName, int lineNo,
ObjViewGraph *graph, const char *id,
const char *name,const char *value,
ObjViewFunction *function) :
OVGNavigableCommand (fileName, lineNo, graph, id, function)
{
linkReceiver.setData (graph, this);
this->name = strdup (name);
this->value = strdup (value);
smallLabel = NULL;
attribute = NULL;
childNo = -1;
}
OVGAddAttrCommand::~OVGAddAttrCommand ()
{
free (name);
free (value);
}
bool OVGAddAttrCommand::calcVisibility (ObjViewGraph *graph)
{
return graph->filterTool->isTypeSelected (OVG_COMMAND_ADD_ATTR);
}
void OVGAddAttrCommand::doExec ()
{
attribute = graph->addAttribute (id, name, value, &smallLabel, NULL, &label1,
&label2);
childNo = attribute->registerChild ();
initWidgets ();
}
void OVGAddAttrCommand::doShow ()
{
OVGNavigableCommand::doShow ();
// Set the appropriate current value (seen when the history is
// hidden). It can be assumed that doShow() is called in the order
// of the creation, so the last visible command will stay; this
// does indeed represent the current value.
assert (smallLabel != NULL);
smallLabel->setText (value);
// ...
assert (attribute != NULL);
assert (childNo != -1);
attribute->childShown (childNo);
}
void OVGAddAttrCommand::doHide ()
{
OVGNavigableCommand::doHide ();
// ...
assert (attribute != NULL);
assert (childNo != -1);
attribute->childHidden (childNo);
}
// ----------------------------------------------------------------------
OVGDeleteCommand::OVGDeleteCommand (const char *fileName, int lineNo,
ObjViewGraph *graph, const char *id,
ObjViewFunction *function) :
OVGNavigableCommand (fileName, lineNo, graph, id, function)
{
linkReceiver.setData (graph, this);
}
OVGDeleteCommand::~OVGDeleteCommand ()
{
}
bool OVGDeleteCommand::calcVisibility (ObjViewGraph *graph)
{
return graph->filterTool->isTypeSelected (OVG_COMMAND_DELETE);
}
void OVGDeleteCommand::doExec ()
{
graph->addMessage (id, "<i>delete</i>", &hbox, &label1, &label2);
initWidgets ();
// Change appearance of window (simple experiment).
//Widget *node = graph->ensureObject(id)->node;
//StyleAttrs attrs = *(node->getStyle());
//attrs.setBorderStyle (BORDER_DOTTED);
//node->setStyle (Style::create (&attrs));
// Furthermore, this message is added often several times, since this command
// is printed in all destructors in the class hierarchie. Should be limited
// to once.
}
} // namespace objects
} // namespace rtfl
|