summaryrefslogtreecommitdiff
path: root/test/tree.fl
blob: a5070891ae2e44b46799ce3b9fa7ecec6f0d1404 (plain)
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
# data file for the Fltk User Interface Designer (fluid)
version 1.0300 
header_name {.h} 
code_name {.cxx}
decl {\#include <stdio.h>} {public global
} 

decl {\#include <FL/Fl.H>} {public global
} 

decl {\#include <FL/Fl_Pixmap.H>} {public global
} 

decl {\#include <FL/Fl_Group.H>} {public global
} 

decl {\#include <FL/Fl_Tree.H>} {public global
} 

decl {\#include <FL/fl_ask.H>} {public global
} 

Function {Button_CB(Fl_Widget*w, void*data)} {open return_type void
} {
  code {fprintf(stderr, "'%s' button pushed\\n", w->label());} {}
} 

Function {RebuildTree()} {open
} {
  code {// REBUILD THE TREE TO MAKE CURRENT "DEFAULT" PREFS TAKE EFFECT
tree->clear();
tree->add("Aaa");
tree->add("Bbb");
tree->add("Ccc");
tree->add("Ddd");
tree->add("Bbb/child-01");
tree->add("Bbb/child-01/111");
tree->add("Bbb/child-01/222");
tree->add("Bbb/child-01/333");
tree->add("Bbb/child-02");
tree->add("Bbb/child-03");
tree->add("Bbb/child-04");

{
    static Fl_Button *but = 0;
    // Assign an FLTK widget to one of the items
    Fl_Tree_Item *i;
    if ( ( i = tree->find_item("Bbb/child-03") ) != NULL ) {
        if ( !but ) {		// only do this once at program startup
            tree->begin();
            but = new Fl_Button(1,1,140,1,"ccc button");     // we control w() only
            but->labelsize(10);
	    but->callback(Button_CB);
        }
        i->widget(but);
        tree->end();
    }
}
{
    // Assign an FLTK group to one of the items with widgets
    Fl_Tree_Item *i;
    if ( ( i = tree->find_item("Bbb/child-04") ) != NULL ) {
        static Fl_Group *grp = 0;
        if ( !grp ) {		// only do this once at program startup
            tree->begin();
              grp = new Fl_Group(100,100,140,18); // build group.. tree handles position
              grp->color(FL_WHITE);
              grp->begin();
                Fl_Button *abut = new Fl_Button(grp->x()+0 ,grp->y()+2,65,15,"D1");
                abut->labelsize(10);
		abut->callback(Button_CB);
                Fl_Button *bbut = new Fl_Button(grp->x()+75,grp->y()+2,65,15,"D2");
                bbut->labelsize(10);
		bbut->callback(Button_CB);
              grp->end();
              grp->resizable(grp);
            tree->end();
        }
        i->widget(grp);
    }
}

// Add an 'Ascending' node, and create it sorted
tree->sortorder(FL_TREE_SORT_NONE);
tree->add("Ascending")->close();
tree->sortorder(FL_TREE_SORT_ASCENDING);
tree->add("Ascending/Zzz");
tree->add("Ascending/Xxx");
tree->add("Ascending/Aaa");
tree->add("Ascending/Bbb");
tree->add("Ascending/Yyy");
tree->add("Ascending/Ccc");

// Add a 'Descending' node, and create it sorted
tree->sortorder(FL_TREE_SORT_NONE);
tree->add("Descending")->close();
tree->sortorder(FL_TREE_SORT_DESCENDING);
tree->add("Descending/Zzz");
tree->add("Descending/Xxx");
tree->add("Descending/Aaa");
tree->add("Descending/Bbb");
tree->add("Descending/Yyy");
tree->add("Descending/Ccc");

tree->redraw();} {}
} 

Function {} {open
} {
  Fl_Window window {
    label tree open
    xywh {1105 30 580 695} type Double visible
  } {
    Fl_Group tree {
      user_data 1234
      callback {Fl_Tree_Item *item = tree->item_clicked();
if ( item ) {
  fprintf(stderr, "TREE CALLBACK: label='%s' userdata=%ld\\n",
          item->label(),
          (long)tree->user_data());
} else {
  fprintf(stderr, "TREE CALLBACK: no item (probably multiple items were changed at once)\\n");
}} open
      xywh {15 15 550 390} box DOWN_BOX color 55
      class Fl_Tree
    } {}
    Fl_Value_Slider margintop_slider {
      label {margintop()}
      user_data tree
      callback {int val = (int)margintop_slider->value();
tree->margintop(val);
tree->redraw();}
      tooltip {Changes the top margin for the tree widget} xywh {190 414 240 16} type Horizontal labelsize 12 align 4 step 0.01 textsize 12
      code0 {o->value(tree->margintop());}
      code1 {o->range(0.0, 100.0);}
      code2 {o->step(1.0);}
      code3 {o->color(46); o->selection_color(FL_RED);}
    }
    Fl_Value_Slider marginleft_slider {
      label {marginleft()}
      user_data tree
      callback {int val = (int)marginleft_slider->value();
tree->marginleft(val);
tree->redraw();}
      tooltip {Changes the left margin for the tree widget} xywh {190 434 240 16} type Horizontal labelsize 12 align 4 step 0.01 textsize 12
      code0 {o->value(tree->marginleft());}
      code1 {o->range(0.0, 100.0);}
      code2 {o->step(1.0);}
      code3 {o->color(46); o->selection_color(FL_RED);}
    }
    Fl_Value_Slider openchild_marginbottom_slider {
      label {openchild_marginbottom()}
      user_data tree
      callback {int val = (int)openchild_marginbottom_slider->value();
tree->openchild_marginbottom(val);
tree->redraw();}
      tooltip {Changes the vertical space below an open child tree} xywh {190 454 240 16} type Horizontal labelsize 12 align 4 step 0.01 textsize 12
      code0 {o->value(tree->openchild_marginbottom());}
      code1 {o->range(0.0, 100.0);}
      code2 {o->step(1.0);}
      code3 {o->color(46); o->selection_color(FL_RED);}
    }
    Fl_Value_Slider labelsize_slider {
      label {Text size}
      user_data tree
      callback {int size = (int)labelsize_slider->value();

// DO SELECTED ITEMS
int count = 0;
for ( Fl_Tree_Item *item=tree->first(); item; item = item->next() ) {
    if ( item->is_selected() ) {
        item->labelsize(size);
        count++;
    }
}

// NO ITEMS SELECTED? DO ALL
if ( ! count ) {
    for ( Fl_Tree_Item *item=tree->first(); item; item = item->next() ) {
        item->labelsize(size);
    }
}

tree->redraw();}
      tooltip {Changes the font size of the selected items
If none selected, all are changed} xywh {190 474 240 16} type Horizontal labelsize 12 align 4 step 0.01 textsize 12
      code0 {o->value(tree->labelsize());}
      code1 {o->range(5.0, 200.0);}
      code2 {o->step(1.0);}
      code3 {o->color(46); o->selection_color(FL_RED);}
    }
    Fl_Value_Slider connectorwidth_slider {
      label {Connector width}
      user_data tree
      callback {tree->connectorwidth((int)connectorwidth_slider->value());}
      tooltip {Tests Fl_Tree::connectorwidth()} xywh {190 494 240 16} type Horizontal labelsize 12 align 4 step 0.01 textsize 12
      code0 {o->value(tree->connectorwidth());}
      code1 {o->range(10.0, 100.0);}
      code2 {o->step(1.0);}
      code3 {o->color(46); o->selection_color(FL_RED);}
    }
    Fl_Check_Button usericon_radio {
      label {Enable user icons?}
      user_data tree
      callback {static const char *L_folder_xpm[] = {
    "11 11 3 1",
    ".  c None",
    "x  c \#d8d833",
    "@  c \#808011",
    "...........",
    ".....@@@@..",
    "....@xxxx@.",
    "@@@@@xxxx@@",
    "@xxxxxxxxx@",
    "@xxxxxxxxx@",
    "@xxxxxxxxx@",
    "@xxxxxxxxx@",
    "@xxxxxxxxx@",
    "@xxxxxxxxx@",
    "@@@@@@@@@@@"};
static Fl_Pixmap L_folderpixmap(L_folder_xpm);

static const char *L_document_xpm[] = {
    "11 11 3 1",
    ".  c None",
    "x  c \#d8d8f8",
    "@  c \#202060",
    ".@@@@@@@@@.",
    ".@xxxxxxx@.",
    ".@xxxxxxx@.",
    ".@xxxxxxx@.",
    ".@xxxxxxx@.",
    ".@xxxxxxx@.",
    ".@xxxxxxx@.",
    ".@xxxxxxx@.",
    ".@xxxxxxx@.",
    ".@xxxxxxx@.",
    ".@@@@@@@@@."};
static Fl_Pixmap L_documentpixmap(L_document_xpm);

Fl_Tree_Item *i = 0;
if ( usericon_radio->value() ) {
    tree->usericon(&L_folderpixmap);
    if ( ( i = tree->find_item("Bbb/bgb/111") ) != NULL ) i->usericon(&L_documentpixmap);
    if ( ( i = tree->find_item("Bbb/bgb/222") ) != NULL ) i->usericon(&L_documentpixmap);
    if ( ( i = tree->find_item("Bbb/bgb/333") ) != NULL ) i->usericon(&L_documentpixmap);
} else {
    tree->usericon(0);
    if ( ( i = tree->find_item("Bbb/bgb/111") ) != NULL ) i->usericon(0);
    if ( ( i = tree->find_item("Bbb/bgb/222") ) != NULL ) i->usericon(0);
    if ( ( i = tree->find_item("Bbb/bgb/333") ) != NULL ) i->usericon(0);
}}
      tooltip {Tests Fl_Tree_Item::usericon()} xywh {145 520 130 16} down_box DOWN_BOX labelsize 11
    }
    Fl_Check_Button showroot_radio {
      label {Show root?}
      user_data tree
      callback {int onoff = showroot_radio->value();
tree->showroot(onoff);}
      tooltip {Tests Fl_Tree_Item::usericon()} xywh {145 539 130 16} down_box DOWN_BOX labelsize 11
      code0 {int onoff = tree->showroot(); showroot_radio->value(onoff);}
    }
    Fl_Choice collapseicons_chooser {
      label {Collapse icons}
      callback {static const char *L_open_xpm[] = {
    "11 11 2 1",
    ".  c None",
    "@  c \#000000",
    "...@.......",
    "...@@......",
    "...@@@.....",
    "...@@@@....",
    "...@@@@@...",
    "...@@@@@@..",
    "...@@@@@...",
    "...@@@@....",
    "...@@@.....",
    "...@@......",
    "...@......."};
static Fl_Pixmap L_openpixmap(L_open_xpm);

static const char *L_close_xpm[] = {
    "11 11 2 1",
    ".  c None",
    "@  c \#000000",
    "...........",
    "...........",
    "...........",
    "...........",
    "...........",
    "@@@@@@@@@@@",
    ".@@@@@@@@@.",
    "..@@@@@@@..",
    "...@@@@@...",
    "....@@@....",
    ".....@....."};
static Fl_Pixmap L_closepixmap(L_close_xpm);

switch ( collapseicons_chooser->value() ) {
    case 0:
        tree->showcollapse(1);
        tree->openicon(0);
        tree->closeicon(0);
        break;
    case 1:
        tree->showcollapse(1);
        tree->openicon(&L_openpixmap);
        tree->closeicon(&L_closepixmap);
        break;
    case 2:
        tree->showcollapse(0);
        break;
}} open
      tooltip {Tests Fl_Tree::openicon() and Fl_Tree::closeicon()} xywh {145 564 110 16} down_box BORDER_BOX labelsize 11 textsize 11
    } {
      MenuItem {} {
        label Normal
        xywh {0 0 36 21} labelsize 11
      }
      MenuItem {} {
        label Arrow
        xywh {10 10 36 21} labelsize 11
      }
      MenuItem {} {
        label Off
        xywh {20 20 36 21} labelsize 11
      }
    }
    Fl_Choice connectorstyle_chooser {
      label {Line style}
      callback {// CHANGE COLLAPSESTYLE
switch ( connectorstyle_chooser->value() ) {
    case 0: tree->connectorstyle(FL_TREE_CONNECTOR_NONE);     break;
    case 1: tree->connectorstyle(FL_TREE_CONNECTOR_DOTTED);   break;
    case 2: tree->connectorstyle(FL_TREE_CONNECTOR_SOLID);    break;
}} open
      tooltip {Tests connectorstyle() bit flags} xywh {145 584 110 16} down_box BORDER_BOX labelsize 11 textsize 11
      code0 {connectorstyle_chooser->value(1);   // tree's default is 'dotted'}
    } {
      MenuItem {} {
        label None
        xywh {30 30 36 21} labelsize 11
      }
      MenuItem {} {
        label Dotted
        xywh {10 10 36 21} labelsize 11
      }
      MenuItem {} {
        label Solid
        xywh {20 20 36 21} labelsize 11
      }
    }
    Fl_Choice labelcolor_chooser {
      label {Item Text Color}
      callback {// Set color..
Fl_Color c = Fl_Color(0x00000000);
switch ( labelcolor_chooser->value() ) {
    case 0:  c = Fl_Color(0x00000000); break;	// black
    case 1:  c = Fl_Color(0xd0000000); break;	// red
    case 2:  c = Fl_Color(0x00a00000); break;	// green
    case 3:  c = Fl_Color(0x0000a000); break;	// blue
    default: c = Fl_Color(0x00000000); break;	// black
}

// DO SELECTED ITEMS
int count = 0;
for ( Fl_Tree_Item *item=tree->first(); item; item = item->next() ) {
    if ( item->is_selected() ) {
        item->labelcolor(c);
        count++;
    }
}

// NO ITEMS SELECTED? DO ALL
if ( ! count ) {
    for ( Fl_Tree_Item *item=tree->first(); item; item = item->next() ) {
        item->labelcolor(c);
    }
}

tree->redraw();} open
      tooltip {Changes the label color for the selected items
If no items selected, all are changed} xywh {145 604 110 16} down_box BORDER_BOX labelsize 11 textsize 11
    } {
      MenuItem {} {
        label Black
        xywh {20 20 36 21} labelsize 11
      }
      MenuItem {} {
        label Red
        xywh {30 30 36 21} labelsize 11
      }
      MenuItem {} {
        label Green
        xywh {40 40 36 21} labelsize 11
      }
      MenuItem {} {
        label Blue
        xywh {50 50 36 21} labelsize 11
      }
    }
    Fl_Choice selectmode_chooser {
      label {Selection Mode}
      callback {// Set selection mode
switch ( selectmode_chooser->value() ) {
    case 0:  tree->selectmode(FL_TREE_SELECT_NONE);   break;	// None
    case 1:  tree->selectmode(FL_TREE_SELECT_SINGLE); break;	// Single
    case 2:  tree->selectmode(FL_TREE_SELECT_MULTI);  break; 	// Multi
    default: tree->selectmode(FL_TREE_SELECT_SINGLE); break;	// Single
}}
      tooltip {Sets how Fl_Tree handles mouse selection of tree items} xywh {145 624 110 16} down_box BORDER_BOX labelsize 11 textsize 11
      code0 {selectmode_chooser->value(1);}
      code1 {cb_selectmode_chooser(selectmode_chooser, (void*)0);}
    } {
      MenuItem {} {
        label None
        xywh {30 30 36 21} labelsize 11
      }
      MenuItem {} {
        label Single
        xywh {40 40 36 21} labelsize 11
      }
      MenuItem {} {
        label Multi
        xywh {50 50 36 21} labelsize 11
      }
    }
    Fl_Choice whenmode_chooser {
      label When
      callback {// Set when mode
switch ( whenmode_chooser->value() ) {
  case 0:  tree->when(FL_WHEN_RELEASE);   break;
  case 1:  tree->when(FL_WHEN_CHANGED);   break;
  case 2:  tree->when(FL_WHEN_NEVER);     break;
  default: tree->when(FL_WHEN_RELEASE);   break;
}}
      tooltip {Sets when() the tree's callback is invoked} xywh {145 644 110 16} down_box BORDER_BOX labelsize 11 textsize 11
      code0 {whenmode_chooser->value(1);}
      code1 {cb_whenmode_chooser(whenmode_chooser, (void*)0);}
    } {
      MenuItem {} {
        label Changed
        xywh {40 40 36 21} labelsize 11
      }
      MenuItem {} {
        label Released
        xywh {50 50 36 21} labelsize 11
      }
      MenuItem {} {
        label Never
        xywh {60 60 36 21} labelsize 11
      }
    }
    Fl_Box docallback_box {
      xywh {280 521 285 81} box GTK_DOWN_BOX color 47
    }
    Fl_Check_Button docallback_radio {
      label {Invoke callback on select changes?} user_data_type {void*}
      tooltip {Invokes the callback when one or more item's state changes.} xywh {310 529 230 16} down_box DOWN_BOX labelsize 11
    }
    Fl_Button selectall_button {
      label {Select All}
      callback {int docallbacks = docallback_radio->value() ? 1 : 0;
tree->select_all(0,docallbacks);
tree->redraw();}
      tooltip {Selects all items in the tree} xywh {305 551 105 16} labelsize 11
    }
    Fl_Button deselectall_button {
      label {Deselect All}
      callback {int docallbacks = docallback_radio->value() ? 1 : 0;
tree->deselect_all(0,docallbacks);
tree->redraw();}
      tooltip {Deselects all items in the tree} xywh {305 571 105 16} labelsize 11
    }
    Fl_Light_Button bbbselect_toggle {
      label { Select Bbb}
      callback {// Toggle select of just the Bbb item and its immediate children
int docallback = docallback_radio->value() ? 1 : 0;
Fl_Tree_Item *bbb = tree->find_item("/Bbb");
if ( !bbb) {
  fl_alert("FAIL: Couldn't find item '/Bbb'???");
  return;
}
int onoff = bbbselect_toggle->value();
if ( onoff ) tree->select_all(bbb, docallback);		// select /Bbb and its children
else         tree->deselect_all(bbb, docallback);	// deselect /Bbb and its children

tree->redraw();

// Toggle select of just the Bbb item and its immediate children
//int docallback = docallback_radio->value() ? 1 : 0;
//int onoff = bbbselect_toggle->value();
//
//if ( onoff ) tree->select("/Bbb", docallback);
//else         tree->deselect("/Bbb", docallback);
//
//tree->redraw();}
      tooltip {Toggle selection of the /Bbb item and its children} xywh {430 552 115 15} labelsize 11
    }
    Fl_Light_Button bbbchild02select_toggle {
      label { Toggle child-02}
      callback {// Toggle select of just the /Bbb/child-02 item
int docallback = docallback_radio->value() ? 1 : 0;
int onoff = bbbchild02select_toggle->value();
if ( onoff ) tree->select("/Bbb/child-02", docallback);
else         tree->deselect("/Bbb/child-02", docallback);
tree->redraw();}
      tooltip {Toggle the single item /Bbb/child-02} xywh {430 571 115 16} labelsize 11
    }
    Fl_Light_Button deactivate_toggle {
      label { Deactivate}
      callback {int onoff = deactivate_toggle->value() ? 0 : 1;

int count = 0;
for (Fl_Tree_Item *item=tree->first(); item; item = item->next()) {
    if ( item->is_selected() ) {
        item->activate(onoff);
        ++count;
    }
}

if ( count == 0 ) {
    for (Fl_Tree_Item *item=tree->first(); item; item = item->next()) {
        item->activate(onoff);
    }
}

tree->redraw();}
      tooltip {Toggle the deactivation state of the selected items.
If none are selected, all are set.} xywh {280 625 90 16} labelsize 11
    }
    Fl_Light_Button bold_toggle {
      label { Bold Font}
      callback {int face = bold_toggle->value() ? FL_HELVETICA_BOLD : FL_HELVETICA;

// DO SELECTED ITEMS
int count = 0;
for ( Fl_Tree_Item *item=tree->first(); item; item = item->next() ) {
    if ( item->is_selected() ) {
        item->labelfont(face);
        count++;
    }
}

// NO ITEMS SELECTED? DO ALL
if ( ! count ) {
    for ( Fl_Tree_Item *item=tree->first(); item; item = item->next() ) {
        item->labelfont(face);
    }
}

tree->redraw();}
      tooltip {Toggles bold font for selected items
If nothing selected, all are changed} xywh {280 644 90 16} labelsize 11
    }
    Fl_Button insertabove_button {
      label {Insert Above}
      callback {Fl_Tree_Item *item=tree->first();
while (item) {
    if ( item->is_selected() ) {
        tree->insert_above(item, "AaaAaa");
        tree->insert_above(item, "BbbBbb");
        tree->insert_above(item, "CccCcc");
    }
    item = item->next();
}

tree->redraw();}
      tooltip {Inserts three items above the selected items} xywh {380 624 90 16} labelsize 11
    }
    Fl_Button rebuildtree_button {
      label {Rebuild Tree}
      callback {RebuildTree();}
      tooltip {Rebuilds the tree with defaults} xywh {380 644 90 16} labelsize 11
    }
    Fl_Button clearselected_button {
      label {Clear Selected}
      callback {Fl_Tree_Item *item=tree->first();
while (item) {
    if ( item->is_selected() ) {
    	if ( tree->remove(item) == -1 ) break;
    	item = tree->first();
    } else {
        item = item->next();
    }
}

tree->redraw();}
      tooltip {Clears the selected items} xywh {475 624 90 16} labelsize 11
    }
    Fl_Button clearall_button {
      label {Clear All}
      callback {tree->clear();
tree->redraw();} selected
      tooltip {Clears all items
Tests Fl_Tree::clear()} xywh {475 644 90 16} labelsize 11
    }
  }
  code {// Initialize Tree
tree->root_label("ROOT");
docallback_radio->value(1);	// enable docallbacks radio button
RebuildTree();
tree->show_self();} {}
  code {// FLTK stuff
Fl::scheme("gtk+");
window->resizable(window);
window->size_range(window->w(), window->h(), 0, 0);} {}
}