summaryrefslogtreecommitdiff
path: root/fluid/nodes/factory.cxx
blob: 8388e02028be1083549b6bc813e3089663e4cb60 (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
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
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
//
// Node Factory code for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2025 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file.  If this
// file is missing or damaged, see the license at:
//
//     https://www.fltk.org/COPYING.php
//
// Please see the following page on how to report bugs and issues:
//
//     https://www.fltk.org/bugs.php
//

/**

 
 \todo Verify the text

 Type classes for most of the fltk widgets.  Most of the work
 is done by code in Widget_Node.cxx.  Also a factory instance
 of each of these type classes.

 This file also contains the "new" menu, which has a pointer
 to a factory instance for every class (both the ones defined
 here and ones in other files)


 Type classes for most of the fltk widgets.  Most of the work
 is done by code in Widget_Node.C.  Also a factory instance
 of each of these type classes.

 This file also contains the "new" menu, which has a pointer
 to a factory instance for every class (both the ones defined
 here and ones in other files)

 */
#include "nodes/factory.h"

#include "app/Snap_Action.h"
#include "Fluid.h"
#include "proj/undo.h"
#include "nodes/Button_Node.h"
#include "nodes/Function_Node.h"
#include "nodes/Grid_Node.h"
#include "nodes/Group_Node.h"
#include "nodes/Menu_Node.h"
#include "nodes/Widget_Node.h"
#include "nodes/Window_Node.h"
#include "rsrcs/pixmaps.h"

#include <FL/Fl.H>
#include <FL/Fl_Adjuster.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Browser.H>
#include <FL/Fl_Check_Browser.H>
#include <FL/Fl_Clock.H>
#include <FL/Fl_Counter.H>
#include <FL/Fl_Dial.H>
#include <FL/Fl_File_Browser.H>
#include <FL/Fl_File_Input.H>
#include <FL/Fl_Help_View.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Menu_Item.H>
#include <FL/Fl_Output.H>
#include <FL/Fl_Progress.H>
#include <FL/Fl_Roller.H>
#include <FL/Fl_Scrollbar.H>
#include <FL/Fl_Terminal.H>
#include <FL/Fl_Spinner.H>
#include <FL/Fl_Text_Display.H>
#include <FL/Fl_Text_Editor.H>
#include <FL/Fl_Tree.H>
#include <FL/Fl_Value_Slider.H>
#include <FL/Fl_Value_Input.H>
#include <FL/Fl_Value_Output.H>
#include <FL/Fl_Window.H>
#include "../src/flstring.h"

#include <stdio.h>
#include <stdlib.h>


// ---- Browser Types -------------------------------------------------- MARK: -


// ---- Browser_Base ----

static Fl_Menu_Item browser_base_type_menu[] = {
  {"No Select", 0, nullptr, (void*)nullptr},
  {"Select", 0, nullptr, (void*)FL_SELECT_BROWSER},
  {"Hold", 0, nullptr, (void*)FL_HOLD_BROWSER},
  {"Multi", 0, nullptr, (void*)FL_MULTI_BROWSER},
  {nullptr}
};

/**
 \brief This is the base class for some browsers types.
 This class will not be instantiated.
 */
class Browser_Base_Node : public Widget_Node
{
public:
  typedef Widget_Node super;
  static Browser_Base_Node prototype;
private:
  Fl_Menu_Item *subtypes() override { return browser_base_type_menu; }
  int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) override {
    Fl_Browser_ *myo = (Fl_Browser_*)(w==4 ? ((Widget_Node*)factory)->o : o);
    switch (w) {
      case 4:
      case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
      case 1: myo->textfont(f); break;
      case 2: myo->textsize(s); break;
      case 3: myo->textcolor(c); break;
    }
    return 1;
  }
public:
  void ideal_size(int &w, int &h) override {
    w = 120;
    h = 160;
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_Browser_"; }
  const char *alt_type_name() override { return "fltk::Browser_"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    Fl_Browser* b = new Fl_Browser(x, y, w, h);
    return b;
  }
  Widget_Node *_make() override { return new Browser_Base_Node(); }
  Type type() const override { return Type::Browser_; }
  bool is_a(Type inType) const override { return (inType==Type::Browser_) ? true : super::is_a(inType); }
};

Browser_Base_Node Browser_Base_Node::prototype;


// ---- Browser ----

/**
 \brief Handle a plain browser widget.
 Most of the work is already done in Browser_Base_Node.
 */
class Browser_Node : public Browser_Base_Node
{
public:
  typedef Browser_Base_Node super;
  static Browser_Node prototype;
public:
  const char *type_name() override { return "Fl_Browser"; }
  const char *alt_type_name() override { return "fltk::Browser"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    Fl_Browser* b = new Fl_Browser(x, y, w, h);
    // Fl_Browser::add calls fl_height(), which requires the X display open.
    // Avoid this when compiling so it works w/o a display:
    if (!Fluid.batch_mode) {
      char buffer[20];
      for (int i = 1; i <= 20; i++) {
        sprintf(buffer,"Browser Line %d",i);
        b->add(buffer);
      }
    }
    return b;
  }
  Widget_Node *_make() override { return new Browser_Node(); }
  Type type() const override { return Type::Browser; }
  bool is_a(Type inType) const override { return (inType==Type::Browser) ? true : super::is_a(inType); }
};

Browser_Node Browser_Node::prototype;


// ---- Check Browser ----

/**
 \brief Manage the Check Browser.
 The Fl_Check_Browser is derived form Fl_Browser_ (underline!), not Fl_Browser.
 */
class Check_Browser_Node : public Browser_Base_Node
{
public:
  typedef Browser_Base_Node super;
  static Check_Browser_Node prototype;
public:
  const char *type_name() override { return "Fl_Check_Browser"; }
  const char *alt_type_name() override { return "fltk::CheckBrowser"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    Fl_Check_Browser* b = new Fl_Check_Browser(x, y, w, h);
    // Fl_Check_Browser::add calls fl_height(), which requires the X display open.
    // Avoid this when compiling so it works w/o a display:
    if (!Fluid.batch_mode) {
      char buffer[20];
      for (int i = 1; i <= 20; i++) {
        sprintf(buffer,"Browser Line %d",i);
        b->add(buffer);
      }
    }
    return b;
  }
  Widget_Node *_make() override { return new Check_Browser_Node(); }
  Type type() const override { return Type::Check_Browser; }
  bool is_a(Type inType) const override { return (inType==Type::Check_Browser) ? true : super::is_a(inType); }
};

Check_Browser_Node Check_Browser_Node::prototype;


// ---- File Browser ----

/**
 \brief Manage the File Browser, not to be confused with the file dialog.
 As oppoesed to the Hold, Multi, and Select Browser, this is not a subclass, but
 its own implementation, based on Fl_Browser.
 */
class File_Browser_Node : public Browser_Node
{
public:
  typedef Browser_Node super;
  static File_Browser_Node prototype;
public:
  const char *type_name() override { return "Fl_File_Browser"; }
  const char *alt_type_name() override { return "fltk::FileBrowser"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    Fl_File_Browser* b = new Fl_File_Browser(x, y, w, h);
    if (!Fluid.batch_mode) b->load(".");
    return b;
  }
  Widget_Node *_make() override { return new File_Browser_Node(); }
  Type type() const override { return Type::File_Browser; }
  bool is_a(Type inType) const override { return (inType==Type::File_Browser) ? true : super::is_a(inType); }
};

File_Browser_Node File_Browser_Node::prototype;


// ---- Tree Type ------------------------------------------------------ MARK: -

/**
 \brief Handle the Tree widget.
 Fl_Tree is derived from Fl_Group, but FLUID does not support extended Fl_Tree
 functionality, so we derive the Type from Widget_Node.
 \note Updating item_labelfont etc. does not refresh any of the existing
    items in the tree, so I decided against implementig those via
    the labelfont UI.
 */
class Tree_Node : public Widget_Node
{
public:
  typedef Widget_Node super;
  static Tree_Node prototype;
public:
  void ideal_size(int &w, int &h) override {
    w = 120;
    h = 160;
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_Tree"; }
  const char *alt_type_name() override { return "fltk::TreeBrowser"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    Fl_Tree* b = new Fl_Tree(x, y, w, h);
    if (!Fluid.batch_mode) {
      b->add("/A1/B1/C1");
      b->add("/A1/B1/C2");
      b->add("/A1/B2/C1");
      b->add("/A1/B2/C2");
      b->add("/A2/B1/C1");
      b->add("/A2/B1/C2");
      b->add("/A2/B2/C1");
      b->add("/A2/B2/C2");
    }
    return b;
  }
  Widget_Node *_make() override { return new Tree_Node(); }
  Type type() const override { return Type::Tree; }
  bool is_a(Type inType) const override { return (inType==Type::Tree) ? true : super::is_a(inType); }
};

Tree_Node Tree_Node::prototype;



// ---- Help Viewer ---------------------------------------------------- MARK: -

/**
 \brief Handle the Help View widget.
 Fl_Help_View is derived from Fl_Group, but supporting children is not useful,
 so we derive from Widget_Node.
 */
class Help_View_Node : public Widget_Node
{
public:
  typedef Widget_Node super;
  static Help_View_Node prototype;
private:
  int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) override {
    Fl_Help_View *myo = (Fl_Help_View*)(w==4 ? ((Widget_Node*)factory)->o : o);
    switch (w) {
      case 4:
      case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
      case 1: myo->textfont(f); break;
      case 2: myo->textsize(s); break;
      case 3: myo->textcolor(c); break;
    }
    return 1;
  }
public:
  void ideal_size(int &w, int &h) override {
    w = 160;
    h = 120;
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_Help_View"; }
  const char *alt_type_name() override { return "fltk::HelpView"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    Fl_Help_View *myo = new Fl_Help_View(x, y, w, h);
    if (!Fluid.batch_mode) {
      myo->value("<HTML><BODY><H1>Fl_Help_View Widget</H1>"
                 "<P>This is a Fl_Help_View widget.</P></BODY></HTML>");
    }
    return myo;
  }
  Widget_Node *_make() override { return new Help_View_Node(); }
  Type type() const override { return Type::Help_View; }
  bool is_a(Type inType) const override { return (inType==Type::Help_View) ? true : super::is_a(inType); }
};

Help_View_Node Help_View_Node::prototype;



// ---- Valuators ------------------------------------------------------ MARK: -


// ---- Valuator Base ----

/**
 \brief Just a base class for all valuators.
 */
class Valuator_Node : public Widget_Node
{
public:
  typedef Widget_Node super;
  static Valuator_Node prototype;
public:
  const char *type_name() override { return "Fl_Valuator"; }
  const char *alt_type_name() override { return "fltk::Valuator"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    return new Fl_Slider(x, y, w, h, "Valuator");
  }
  Widget_Node *_make() override { return new Valuator_Node(); }
  Type type() const override { return Type::Valuator_; }
  bool is_a(Type inType) const override { return (inType==Type::Valuator_) ? true : super::is_a(inType); }
};

Valuator_Node Valuator_Node::prototype;


// ---- Counter ----

static Fl_Menu_Item counter_type_menu[] = {
  { "Normal", 0, nullptr, (void*)nullptr },
  { "Simple", 0, nullptr, (void*)FL_SIMPLE_COUNTER },
  { nullptr }
};

/**
 \brief Manage the Counter widget.
 Strictly speaking, the ideal size should derive from the textsize not the labelsize.
 */
class Counter_Node : public Valuator_Node
{
public:
  typedef Valuator_Node super;
  static Counter_Node prototype;
private:
  Fl_Menu_Item *subtypes() override { return counter_type_menu; }
  int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) override {
    Fl_Counter *myo = (Fl_Counter*)(w==4 ? ((Widget_Node*)factory)->o : o);
    switch (w) {
      case 4:
      case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
      case 1: myo->textfont(f); break;
      case 2: myo->textsize(s); break;
      case 3: myo->textcolor(c); break;
    }
    return 1;
  }
public:
  void ideal_size(int &w, int &h) override {
    auto layout = Fluid.proj.layout;
    h = layout->textsize_not_null() + 8;
    w = layout->textsize_not_null() * 4 + 4 * h; // make room for the arrows
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_Counter"; }
  const char *alt_type_name() override { return "fltk::Counter"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    return new Fl_Counter(x, y, w, h, "counter:");
  }
  Widget_Node *_make() override { return new Counter_Node(); }
  Type type() const override { return Type::Counter; }
  bool is_a(Type inType) const override { return (inType==Type::Counter) ? true : super::is_a(inType); }
};

Counter_Node Counter_Node::prototype;


// ---- Adjuster ----

/**
 \brief Handle Adjuster widgets which are derived from valuators.
 */
class Adjuster_Node : public Valuator_Node
{
public:
  typedef Valuator_Node super;
  static Adjuster_Node prototype;
public:
  void ideal_size(int &w, int &h) override {
    auto layout = Fluid.proj.layout;
    h = layout->labelsize + 8;
    w = 3 * h;
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_Adjuster"; }
  const char *alt_type_name() override { return "fltk::Adjuster"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    return new Fl_Adjuster(x, y, w, h);
  }
  Widget_Node *_make() override { return new Adjuster_Node(); }
  Type type() const override { return Type::Adjuster; }
  bool is_a(Type inType) const override { return (inType==Type::Adjuster) ? true : super::is_a(inType); }
};

Adjuster_Node Adjuster_Node::prototype;


// ---- Dial ----

static Fl_Menu_Item dial_type_menu[] = {
  { "Dot", 0, nullptr, (void*)nullptr },
  { "Line", 0, nullptr, (void*)FL_LINE_DIAL },
  { "Fill", 0, nullptr, (void*)FL_FILL_DIAL },
  { nullptr }
};

/**
 \brief Manage dials.
 */
class Dial_Node : public Valuator_Node
{
public:
  typedef Valuator_Node super;
  static Dial_Node prototype;
private:
  Fl_Menu_Item *subtypes() override { return dial_type_menu; }
public:
  void ideal_size(int &w, int &h) override {
    w = 60; h = 60;
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_Dial"; }
  const char *alt_type_name() override { return "fltk::Dial"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    return new Fl_Dial(x, y, w, h);
  }
  Widget_Node *_make() override { return new Dial_Node(); }
  Type type() const override { return Type::Dial; }
  bool is_a(Type inType) const override { return (inType==Type::Dial) ? true : super::is_a(inType); }
};

Dial_Node Dial_Node::prototype;


// ---- Roller ----

static Fl_Menu_Item roller_type_menu[] = {
  { "Vertical", 0, nullptr, (void*)nullptr },
  { "Horizontal", 0, nullptr, (void*)FL_HORIZONTAL },
  { nullptr }
};

/**
 \brief Manage Roller widgets. They are vertical by default.
 */
class Roller_Node : public Valuator_Node
{
public:
  typedef Valuator_Node super;
  static Roller_Node prototype;
private:
  Fl_Menu_Item *subtypes() override { return roller_type_menu; }
public:
  void ideal_size(int &w, int &h) override {
    auto layout = Fluid.proj.layout;
    w = layout->labelsize + 8;
    h = 4 * w;
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_Roller"; }
  const char *alt_type_name() override { return "fltk::Roller"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    return new Fl_Roller(x, y, w, h);
  }
  Widget_Node *_make() override { return new Roller_Node(); }
  Type type() const override { return Type::Roller; }
  bool is_a(Type inType) const override { return (inType==Type::Roller) ? true : super::is_a(inType); }
};

Roller_Node Roller_Node::prototype;


// ---- Slider ----

static Fl_Menu_Item slider_type_menu[] = {
  { "Vertical", 0, nullptr, (void*)nullptr },
  { "Horizontal", 0, nullptr, (void*)FL_HOR_SLIDER },
  { "Vert Fill", 0, nullptr, (void*)FL_VERT_FILL_SLIDER },
  { "Horz Fill", 0, nullptr, (void*)FL_HOR_FILL_SLIDER },
  { "Vert Knob", 0, nullptr, (void*)FL_VERT_NICE_SLIDER },
  { "Horz Knob", 0, nullptr, (void*)FL_HOR_NICE_SLIDER },
  { nullptr }
};

/**
 \brief Manage Slider widgets.
 They are vertical by default.
 Fl_Value_Slider has its own type.
 */
class Slider_Node : public Valuator_Node
{
public:
  typedef Valuator_Node super;
  static Slider_Node prototype;
private:
  Fl_Menu_Item *subtypes() override { return slider_type_menu; }
public:
  void ideal_size(int &w, int &h) override {
    auto layout = Fluid.proj.layout;
    w = layout->labelsize + 8;
    h = 4 * w;
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_Slider"; }
  const char *alt_type_name() override { return "fltk::Slider"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    return new Fl_Slider(x, y, w, h, "slider:");
  }
  Widget_Node *_make() override { return new Slider_Node(); }
  Type type() const override { return Type::Slider; }
  bool is_a(Type inType) const override { return (inType==Type::Slider) ? true : super::is_a(inType); }
};

Slider_Node Slider_Node::prototype;


// ---- Scrollbar ----

static Fl_Menu_Item scrollbar_type_menu[] = {
  { "Vertical", 0, nullptr, (void*)nullptr },
  { "Horizontal", 0, nullptr, (void*)FL_HOR_SLIDER },
  { nullptr }
};

/**
 \brief Manage Scrollbars which are derived from Sliders.
 */
class Scrollbar_Node : public Slider_Node
{
public:
  typedef Slider_Node super;
  static Scrollbar_Node prototype;
private:
  Fl_Menu_Item *subtypes() override { return scrollbar_type_menu; }
public:
  const char *type_name() override { return "Fl_Scrollbar"; }
  const char *alt_type_name() override { return "fltk::Scrollbar"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    return new Fl_Scrollbar(x, y, w, h);
  }
  Widget_Node *_make() override { return new Scrollbar_Node(); }
  Type type() const override { return Type::Scrollbar; }
  bool is_a(Type inType) const override { return (inType==Type::Scrollbar) ? true : super::is_a(inType); }
};

Scrollbar_Node Scrollbar_Node::prototype;


// ---- Value Slider ----

/**
 \brief Manage Value Sliders and their text settings.
 */
class Value_Slider_Node : public Slider_Node
{
public:
  typedef Slider_Node super;
  static Value_Slider_Node prototype;
private:
  int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) override {
    Fl_Value_Slider *myo = (Fl_Value_Slider*)(w==4 ? ((Widget_Node*)factory)->o : o);
    switch (w) {
      case 4:
      case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
      case 1: myo->textfont(f); break;
      case 2: myo->textsize(s); break;
      case 3: myo->textcolor(c); break;
    }
    return 1;
  }
public:
  const char *type_name() override { return "Fl_Value_Slider"; }
  const char *alt_type_name() override { return "fltk::ValueSlider"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    return new Fl_Value_Slider(x, y, w, h, "slider:");
  }
  Widget_Node *_make() override { return new Value_Slider_Node(); }
  Type type() const override { return Type::Value_Slider; }
  bool is_a(Type inType) const override { return (inType==Type::Value_Slider) ? true : super::is_a(inType); }
};

Value_Slider_Node Value_Slider_Node::prototype;


// ---- Value Input ----

/**
 \brief Manage Value Inputs and their text settings.
 */
class Value_Input_Node : public Valuator_Node
{
public:
  typedef Valuator_Node super;
  static Value_Input_Node prototype;
private:
  int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) override {
    Fl_Value_Input *myo = (Fl_Value_Input*)(w==4 ? ((Widget_Node*)factory)->o : o);
    switch (w) {
      case 4:
      case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
      case 1: myo->textfont(f); break;
      case 2: myo->textsize(s); break;
      case 3: myo->textcolor(c); break;
    }
    return 1;
  }
public:
  void ideal_size(int &w, int &h) override {
    auto layout = Fluid.proj.layout;
    h = layout->textsize_not_null() + 8;
    w = layout->textsize_not_null() * 4 + 8;
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_Value_Input"; }
  const char *alt_type_name() override { return "fltk::ValueInput"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    Fl_Value_Input *myo = new Fl_Value_Input(x, y, w, h, "value:");
    return myo;
  }
  Widget_Node *_make() override { return new Value_Input_Node(); }
  Type type() const override { return Type::Value_Input; }
  bool is_a(Type inType) const override { return (inType==Type::Value_Input) ? true : super::is_a(inType); }
};

Value_Input_Node Value_Input_Node::prototype;


// ---- Value Output ----

/**
 \brief Handle Value Output widgets, no shortcut with Value Input unfortunately.
 */
class Value_Output_Node : public Valuator_Node
{
public:
  typedef Valuator_Node super;
  static Value_Output_Node prototype;
private:
  int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) override {
    Fl_Value_Output *myo = (Fl_Value_Output*)(w==4 ? ((Widget_Node*)factory)->o : o);
    switch (w) {
      case 4:
      case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
      case 1: myo->textfont(f); break;
      case 2: myo->textsize(s); break;
      case 3: myo->textcolor(c); break;
    }
    return 1;
  }
public:
  void ideal_size(int &w, int &h) override {
    auto layout = Fluid.proj.layout;
    h = layout->textsize_not_null() + 8;
    w = layout->textsize_not_null() * 4 + 8;
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_Value_Output"; }
  const char *alt_type_name() override { return "fltk::ValueOutput"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    Fl_Value_Output *myo = new Fl_Value_Output(x, y, w, h, "value:");
    return myo;
  }
  Widget_Node *_make() override { return new Value_Output_Node(); }
  Type type() const override { return Type::Value_Output; }
  bool is_a(Type inType) const override { return (inType==Type::Value_Output) ? true : super::is_a(inType); }
};

Value_Output_Node Value_Output_Node::prototype;



// ---- Input ---------------------------------------------------------- MARK: -


// ---- Input ----

static Fl_Menu_Item input_type_menu[] = {
  { "Normal", 0, nullptr, (void*)nullptr },
  { "Multiline", 0, nullptr, (void*)FL_MULTILINE_INPUT },
  { "Secret", 0, nullptr, (void*)FL_SECRET_INPUT },
  { "Int", 0, nullptr, (void*)FL_INT_INPUT },
  { "Float", 0, nullptr, (void*)FL_FLOAT_INPUT },
  {nullptr}
};

/**
 \brief Manage simple text input widgets.
 The managed class is derived from Fl_Input_, but for simplicity, deriving from
 Widget_Node seems sufficient here.
 */
class Input_Node : public Widget_Node
{
public:
  typedef Widget_Node super;
  static Input_Node prototype;
private:
  Fl_Menu_Item *subtypes() override { return input_type_menu; }
  int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) override {
    Fl_Input_ *myo = (Fl_Input_*)(w==4 ? ((Widget_Node*)factory)->o : o);
    switch (w) {
      case 4:
      case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
      case 1: myo->textfont(f); break;
      case 2: myo->textsize(s); break;
      case 3: myo->textcolor(c); break;
    }
    return 1;
  }
public:
  void ideal_size(int &w, int &h) override {
    auto layout = Fluid.proj.layout;
    h = layout->textsize_not_null() + 8;
    w = layout->textsize_not_null() * 6 + 8;
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_Input"; }
  const char *alt_type_name() override { return "fltk::Input"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    Fl_Input *myo = new Fl_Input(x, y, w, h, "input:");
    myo->value("Text Input");
    return myo;
  }
  Widget_Node *_make() override { return new Input_Node(); }
  Type type() const override { return Type::Input; }
  bool is_a(Type inType) const override { return (inType==Type::Input) ? true : super::is_a(inType); }
  void copy_properties() override {
    Widget_Node::copy_properties();
    Fl_Input_ *d = (Fl_Input_*)live_widget, *s = (Fl_Input_*)o;
    d->textfont(s->textfont());
    d->textsize(s->textsize());
    d->textcolor(s->textcolor());
    d->shortcut(s->shortcut());
  }
};

Input_Node Input_Node::prototype;


// ---- File Input ----

/**
 \brief Manage file name input widgets.
 */
class File_Input_Node : public Input_Node
{
public:
  typedef Input_Node super;
  static File_Input_Node prototype;
private:
  Fl_Menu_Item *subtypes() override { return nullptr; } // Don't inherit.
public:
  void ideal_size(int &w, int &h) override {
    auto layout = Fluid.proj.layout;
    h = layout->textsize_not_null() + 8 + 10; // Directoy bar is additional 10 pixels high
    w = layout->textsize_not_null() * 10 + 8;
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_File_Input"; }
  const char *alt_type_name() override { return "fltk::FileInput"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    Fl_File_Input *myo = new Fl_File_Input(x, y, w, h, "file:");
    myo->value("/usr/include/FL/Fl.H");
    return myo;
  }
  Widget_Node *_make() override { return new File_Input_Node(); }
  Type type() const override { return Type::File_Input; }
  bool is_a(Type inType) const override { return (inType==Type::File_Input) ? true : super::is_a(inType); }
};

File_Input_Node File_Input_Node::prototype;


// ---- Output ----

static Fl_Menu_Item output_type_menu[] = {
  { "Normal", 0, nullptr, (void*)FL_NORMAL_OUTPUT },
  { "Multiline", 0, nullptr, (void*)FL_MULTILINE_OUTPUT },
  { nullptr }
};

/**
 \brief Manage Output widgets, derived from Input.
 */
class Output_Node : public Input_Node
{
public:
  typedef Input_Node super;
  static Output_Node prototype;
private:
  Fl_Menu_Item *subtypes() override { return output_type_menu; }
public:
  const char *type_name() override { return "Fl_Output"; }
  const char *alt_type_name() override { return "fltk::Output"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    Fl_Output *myo = new Fl_Output(x, y, w, h, "output:");
    myo->value("Text Output");
    return myo;
  }
  Widget_Node *_make() override { return new Output_Node(); }
  Type type() const override { return Type::Output; }
  bool is_a(Type inType) const override { return (inType==Type::Output) ? true : super::is_a(inType); }
};

Output_Node Output_Node::prototype;



// ---- Text Editor ---------------------------------------------------- MARK: -


// ---- Text Display ----

/**
 \brief Manage the Text Display as a base class.
 Fl_Text_Display is actually derived from Fl_Group, but for FLUID, deriving
 the type from Widget is better.
 */
class Text_Display_Node : public Widget_Node
{
public:
  typedef Widget_Node super;
  static Text_Display_Node prototype;
private:
  int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) override {
    Fl_Text_Display *myo = (Fl_Text_Display*)(w==4 ? ((Widget_Node*)factory)->o : o);
    switch (w) {
      case 4:
      case 0: f = myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
      case 1: myo->textfont(f); break;
      case 2: myo->textsize(s); break;
      case 3: myo->textcolor(c); break;
    }
    return 1;
  }
public:
  void ideal_size(int &w, int &h) override {
    auto layout = Fluid.proj.layout;
    h = layout->textsize_not_null() * 4 + 8;
    w = layout->textsize_not_null() * 10 + 8;
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_Text_Display"; }
  const char *alt_type_name() override { return "fltk::TextDisplay"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    Fl_Text_Display *myo = new Fl_Text_Display(x, y, w, h);
    if (!Fluid.batch_mode) {
      Fl_Text_Buffer *b = new Fl_Text_Buffer();
      b->text("Lorem ipsum dolor\nsit amet, consetetur\nsadipscing elitr");
      myo->buffer(b);
    }
    return myo;
  }
  Widget_Node *_make() override { return new Text_Display_Node(); }
  Type type() const override { return Type::Text_Display; }
  bool is_a(Type inType) const override { return (inType==Type::Text_Display) ? true : super::is_a(inType); }
};

Text_Display_Node Text_Display_Node::prototype;


// ---- Text Editor ----

/**
 \brief Manage Text Editors based on Text Display.
 */
class Text_Editor_Node : public Text_Display_Node
{
public:
  typedef Text_Display_Node super;
  static Text_Editor_Node prototype;
public:
  const char *type_name() override {return "Fl_Text_Editor";}
  const char *alt_type_name() override {return "fltk::TextEditor";}
  Fl_Widget *widget(int x, int y, int w, int h) override {
    Fl_Text_Editor *myo = new Fl_Text_Editor(x, y, w, h);
    if (!Fluid.batch_mode) {
      Fl_Text_Buffer *b = new Fl_Text_Buffer();
      b->text("Lorem ipsum dolor\nsit amet, consetetur\nsadipscing elitr");
      myo->buffer(b);
    }
    return myo;
  }
  Widget_Node *_make() override { return new Text_Editor_Node(); }
  Type type() const override { return Type::Text_Editor; }
  bool is_a(Type inType) const override { return (inType==Type::Text_Editor) ? true : super::is_a(inType); }
};

Text_Editor_Node Text_Editor_Node::prototype;


// ---- Terminal ----

/** Use this terminal instead of Fl_Terminal to capture resize actions. */
class Fl_Terminal_Proxy : public Fl_Terminal {
public:
  Fl_Terminal_Proxy(int x, int y, int w, int h, const char *l=nullptr)
  : Fl_Terminal(x, y, w, h, l) { }
  void print_sample_text() {
    clear_screen_home(false);
    append("> ls -als");
  }
  void resize(int x, int y, int w, int h) override {
    Fl_Terminal::resize(x, y, w, h);
    // After a resize, the top text vanishes, so make sure we redraw it.
    print_sample_text();
  }
};

/** Use this terminal in batch mode to avoid opening a DISPLAY connection. */
class Fl_Batchmode_Terminal : public Fl_Group {
public:
  Fl_Font tfont_;
  int tsize_;
  Fl_Color tcolor_;
  Fl_Batchmode_Terminal(int x, int y, int w, int h, const char *l=nullptr)
  : Fl_Group(x, y, w, h, l)
  { // set the defaults that Fl_Terminal would set
    box(FL_DOWN_BOX);
    color(FL_FOREGROUND_COLOR);
    selection_color(FL_BACKGROUND_COLOR);
    labeltype(FL_NORMAL_LABEL);
    labelfont(0);
    labelsize(14);
    labelcolor(FL_FOREGROUND_COLOR);
    tfont_ = 4;
    tcolor_ = 0xd0d0d000;
    tsize_ = 14;
    align(Fl_Align(FL_ALIGN_TOP));
    when(FL_WHEN_RELEASE);
    end();
  }
};

/**
 \brief Manage a terminal widget.
 */
class Terminal_Node : public Widget_Node
{
public:
  typedef Widget_Node super;
  static Terminal_Node prototype;
public:
  const char *type_name() override { return "Fl_Terminal"; }
  // Older .fl files with Fl_Simple_Terminal will create a Fl_Terminal instead.
  const char *alt_type_name() override { return "Fl_Simple_Terminal"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    Fl_Widget *ret = nullptr;
    if (Fluid.batch_mode) {
      ret = new Fl_Batchmode_Terminal(x, y, w, h);
    } else {
      Fl_Terminal_Proxy *term = new Fl_Terminal_Proxy(x, y, w+100, h);
      ret = term;
    }
    return ret;
  }
  int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) override {
    if (Fluid.batch_mode) {
      Fl_Batchmode_Terminal *myo = (Fl_Batchmode_Terminal*)(w==4 ? ((Widget_Node*)factory)->o : o);
      switch (w) {
        case 4:
        case 0: f = (Fl_Font)myo->tfont_; s = myo->tsize_; c = myo->tcolor_; break;
        case 1: myo->tfont_ = f; break;
        case 2: myo->tsize_ = s; break;
        case 3: myo->tcolor_ = c; break;
      }
    } else {
      Fl_Terminal_Proxy *myo = (Fl_Terminal_Proxy*)(w==4 ? ((Widget_Node*)factory)->o : o);
      switch (w) {
        case 4:
        case 0: f = (Fl_Font)myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
        case 1: myo->textfont(f); myo->print_sample_text(); break;
        case 2: myo->textsize(s); myo->print_sample_text(); break;
        case 3: myo->textcolor(c); myo->print_sample_text(); break;
      }
    }
    return 1;
  }
  Widget_Node *_make() override {return new Terminal_Node();}
  Type type() const override { return Type::Terminal; }
  bool is_a(Type inType) const override { return (inType==Type::Terminal) ? true : super::is_a(inType); }
};

Terminal_Node Terminal_Node::prototype;


// ---- Other ---------------------------------------------------------- MARK: -


// ---- Box ----

/**
 \brief Manage box widgets.
 Ideal size is set to 100x100, snapped to layout.
 */
class Box_Node : public Widget_Node
{
public:
  typedef Widget_Node super;
  static Box_Node prototype;
public:
  void ideal_size(int &w, int &h) override {
    w = 100; h = 100;
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_Box"; }
  const char *alt_type_name() override { return "fltk::Widget"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    return new Fl_Box(x, y, w, h, "label");
  }
  Widget_Node *_make() override { return new Box_Node(); }
  Type type() const override { return Type::Box; }
  bool is_a(Type inType) const override { return (inType==Type::Box) ? true : super::is_a(inType); }
};

Box_Node Box_Node::prototype;


// ---- Clock ----

/**
 \brief Manage Clock widgets.
 Ideal size is set to 80x80 snapped to layout.
 */
class Clock_Node : public Widget_Node
{
public:
  typedef Widget_Node super;
  static Clock_Node prototype;
public:
  void ideal_size(int &w, int &h) override {
    w = 80; h = 80;
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_Clock"; }
  const char *alt_type_name() override { return "fltk::Clock"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    return new Fl_Clock(x, y, w, h);
  }
  Widget_Node *_make() override { return new Clock_Node(); }
  Type type() const override { return Type::Clock; }
  bool is_a(Type inType) const override { return (inType==Type::Clock) ? true : super::is_a(inType); }
};

Clock_Node Clock_Node::prototype;


// ---- Progress ----

/**
 \brief Manage a Progress widget.
 Ideal size is set to match the label font and label text width times 3.
 \note minimum, maximum, and value must be set via extra code fields.
 */
class Progress_Node : public Widget_Node
{
public:
  typedef Widget_Node super;
  static Progress_Node prototype;
public:
  void ideal_size(int &w, int &h) override {
    auto layout = Fluid.proj.layout;
    h = layout->labelsize + 8;
    w = layout->labelsize * 12;
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_Progress"; }
  const char *alt_type_name() override { return "fltk::ProgressBar"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    Fl_Progress *myo = new Fl_Progress(x, y, w, h, "label");
    myo->value(50);
    return myo;
  }
  Widget_Node *_make() override { return new Progress_Node(); }
  Type type() const override { return Type::Progress; }
  bool is_a(Type inType) const override { return (inType==Type::Progress) ? true : super::is_a(inType); }
};

Progress_Node Progress_Node::prototype;

// ---- Spinner ----

static Fl_Menu_Item spinner_type_menu[] = {
  { "Integer", 0, nullptr, (void*)FL_INT_INPUT },
  { "Float",  0, nullptr, (void*)FL_FLOAT_INPUT },
  { nullptr }
};

/**
 \brief Manage Spinner widgets.
 \note Fl_Spinner is derived from Fl_Group, *not* Fl_Valuator as one may expect.
    For FLUID, this means some special handling and no Group support.
 */
class Spinner_Node : public Widget_Node
{
public:
  typedef Widget_Node super;
  static Spinner_Node prototype;
private:
  Fl_Menu_Item *subtypes() override { return spinner_type_menu; }
  int textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) override {
    Fl_Spinner *myo = (Fl_Spinner*)(w==4 ? ((Widget_Node*)factory)->o : o);
    switch (w) {
      case 4:
      case 0: f = (Fl_Font)myo->textfont(); s = myo->textsize(); c = myo->textcolor(); break;
      case 1: myo->textfont(f); break;
      case 2: myo->textsize(s); break;
      case 3: myo->textcolor(c); break;
    }
    return 1;
  }
public:
  void ideal_size(int &w, int &h) override {
    auto layout = Fluid.proj.layout;
    h = layout->textsize_not_null() + 8;
    w = layout->textsize_not_null() * 4 + 8;
    fld::app::Snap_Action::better_size(w, h);
  }
  const char *type_name() override { return "Fl_Spinner"; }
  const char *alt_type_name() override { return "fltk::Spinner"; }
  Fl_Widget *widget(int x, int y, int w, int h) override {
    return new Fl_Spinner(x, y, w, h, "spinner:");
  }
  Widget_Node *_make() override { return new Spinner_Node(); }
  Type type() const override { return Type::Spinner; }
  bool is_a(Type inType) const override { return (inType==Type::Spinner) ? true : super::is_a(inType); }
};

Spinner_Node Spinner_Node::prototype;



// ---- Type Factory --------------------------------------------------- MARK: -

extern void select(Node *,int);
extern void select_only(Node *);

/**
 List all known types.
 This is used to convert a type name into a pointer to the prototype.
 This list may contain types that are supported in .fl files, but not
 available in the *New* menu.

 \note Make sure that this array stays synchronized to `Fl_Menu_Item New_Menu[]`
    further down in this file.
 */
static Node *known_types[] = {
  // functions
  (Node*)&Function_Node::prototype,
  (Node*)&Code_Node::prototype,
  (Node*)&CodeBlock_Node::prototype,
  (Node*)&Decl_Node::prototype,
  (Node*)&DeclBlock_Node::prototype,
  (Node*)&Class_Node::prototype,
  (Node*)&Widget_Class_Node::prototype,
  (Node*)&Comment_Node::prototype,
  (Node*)&Data_Node::prototype,
  // groups
  (Node*)&Window_Node::prototype,
  (Node*)&Group_Node::prototype,
  (Node*)&Pack_Node::prototype,
  (Node*)&Flex_Node::prototype,
  (Node*)&Tabs_Node::prototype,
  (Node*)&Scroll_Node::prototype,
  (Node*)&Tile_Node::prototype,
  (Node*)&Wizard_Node::prototype,
  (Node*)&Grid_Node::prototype,
  // buttons
  (Node*)&Button_Node::prototype,
  (Node*)&Return_Button_Node::prototype,
  (Node*)&Light_Button_Node::prototype,
  (Node*)&Check_Button_Node::prototype,
  (Node*)&Repeat_Button_Node::prototype,
  (Node*)&Round_Button_Node::prototype,
  // valuators
  (Node*)&Slider_Node::prototype,
  (Node*)&Scrollbar_Node::prototype,
  (Node*)&Value_Slider_Node::prototype,
  (Node*)&Adjuster_Node::prototype,
  (Node*)&Counter_Node::prototype,
  (Node*)&Spinner_Node::prototype,
  (Node*)&Dial_Node::prototype,
  (Node*)&Roller_Node::prototype,
  (Node*)&Value_Input_Node::prototype,
  (Node*)&Value_Output_Node::prototype,
  // text
  (Node*)&Input_Node::prototype,
  (Node*)&Output_Node::prototype,
  (Node*)&Text_Editor_Node::prototype,
  (Node*)&Text_Display_Node::prototype,
  (Node*)&File_Input_Node::prototype,
  (Node*)&Terminal_Node::prototype,
  // menus
  (Node*)&Menu_Bar_Node::prototype,
  (Node*)&Menu_Button_Node::prototype,
  (Node*)&Choice_Node::prototype,
  (Node*)&Input_Choice_Node::prototype,
  (Node*)&Submenu_Node::prototype,
  (Node*)&Menu_Item_Node::prototype,
  (Node*)&Checkbox_Menu_Item_Node::prototype,
  (Node*)&Radio_Menu_Item_Node::prototype,
  // browsers
  (Node*)&Browser_Node::prototype,
  (Node*)&Check_Browser_Node::prototype,
  (Node*)&File_Browser_Node::prototype,
  (Node*)&Tree_Node::prototype,
  (Node*)&Help_View_Node::prototype,
  (Node*)&Table_Node::prototype,
  // misc
  (Node*)&Box_Node::prototype,
  (Node*)&Clock_Node::prototype,
  (Node*)&Progress_Node::prototype,
};

/**
 Create and add a new widget to the widget tree.

 Fluid will try to set a default position for widgets to the user's expectation.
 Using the context menu will put new widgets at the position of the mouse click.
 Pulldown menu and bin actions will generate widgets no too far from previously
 added widgets in the same group.

 Widgets can be added by dragging them from the widget bin to the
 desired location.

 By setting the strategy, widgets are added as the last child of a group (this
 is done when reading them from a file), or close to the current widget, which
 the user would expect in interactive mode.

 \param[in] inPrototype pointer to one of the FL_..._type prototype; note the
    lower case 't' in type.
 \param[in] strategy add after current or as last child
 \param[in] and_open if set to true, call open() on the widget after creating it
 \return the newly created type or nullptr

 \see add_new_widget_from_file(const char*, int)
 add_new_widget_from_user(Node*, int)
 add_new_widget_from_user(const char*, int)
 */
Node *add_new_widget_from_user(Node *inPrototype, Strategy strategy, bool and_open) {
  Fluid.proj.undo.checkpoint();
  Fluid.proj.undo.suspend();
  auto layout = Fluid.proj.layout;
  Node *t = ((Node*)inPrototype)->make(strategy);
  if (t) {
    if (t->is_widget() && !t->is_a(Type::Window)) {
      auto layout = Fluid.proj.layout;
      Widget_Node *wt = (Widget_Node *)t;
      bool changed = false;

      // Set font sizes...
      changed |= (wt->o->labelsize() != layout->labelsize);
      wt->o->labelsize(layout->labelsize);
      if (layout->labelfont >= 0) {
        changed |= (wt->o->labelfont() != layout->labelfont);
        wt->o->labelfont(layout->labelfont);
      }

      Fl_Font fc, f = layout->textfont;
      int sc, s = layout->textsize;
      Fl_Color cc, c;
      wt->textstuff(0, fc, sc, cc);

      if ((f >= 0) && (fc != f)) {
        changed = true;
        wt->textstuff(1, f, s, c);
      }
      if ((s > 0) && (sc != s)) {
        changed = true;
        wt->textstuff(2, f, s, c);
      }

      if (changed && t->is_a(Type::Menu_Item)) {
        Node * tt = t->parent;
        while (tt && !tt->is_a(Type::Menu_Manager_)) tt = tt->parent;
        if (tt)
          ((Menu_Manager_Node*)tt)->build_menu();
      }
    }
    if (t->is_true_widget() && !t->is_a(Type::Window)) {
      // Resize and/or reposition new widget...
      Widget_Node *wt = (Widget_Node *)t;

      // The parent field is already set at this point, so we can use that
      // inside ideal_size().
      int w = 0, h = 0;
      wt->ideal_size(w, h);

      if ((t->parent && t->parent->is_a(Type::Flex))) {
        if (Window_Node::popupx != 0x7FFFFFFF)
          ((Flex_Node*)t->parent)->insert_child_at(((Widget_Node*)t)->o, Window_Node::popupx, Window_Node::popupy);
        t->parent->layout_widget();
      } else if (   wt->is_a(Type::Group)
                 && wt->parent
                 && wt->parent->is_a(Type::Tabs)
                 //&& (Window_Node::popupx == 0x7FFFFFFF)
                 && (layout->top_tabs_margin > 0)) {
        // If the widget is a group and the parent is tabs and the top tabs
        // margin is set (and the user is not requesting a specific position)
        // then prefit the group correctly to the Tabs container.
        Fl_Widget *po = ((Tabs_Node*)wt->parent)->o;
        wt->o->resize(po->x(), po->y() + layout->top_tabs_margin,
                      po->w(), po->h() - layout->top_tabs_margin);
      } else if (   wt->is_a(Type::Menu_Bar)
                 && wt->parent
                 && wt->parent->is_a(Type::Window)
                 && (wt->prev == wt->parent)) {
        // If this is the first child of a window, make the menu bar as wide as
        // the window and drop it at 0, 0. Otherwise just use the suggested size.
        w = wt->o->window()->w();
        wt->o->resize(0, 0, w, h);
      } else {
        if (Window_Node::popupx != 0x7FFFFFFF) {
          // If this callback was called from the RMB popup menu in a window,
          // popupx and popupy will contain the mouse coordinates at RMB event.
          wt->o->resize(Window_Node::popupx, Window_Node::popupy, w, h);
        } else {
          // If popupx is invalid, use the default position and find a good
          // size for the widget.
          wt->o->size(w, h);
        }
      }
      if (t->parent && t->parent->is_a(Type::Grid)) {
        if (Window_Node::popupx != 0x7FFFFFFF) {
          ((Grid_Node*)t->parent)->insert_child_at(((Widget_Node*)t)->o, Window_Node::popupx, Window_Node::popupy);
        } else {
          ((Grid_Node*)t->parent)->insert_child_at_next_free_cell(((Widget_Node*)t)->o);
        }
      }
    }
    if (t->is_a(Type::Window)) {
      int x = 0, y = 0, w = 480, h = 320;
      Window_Node *wt = (Window_Node *)t;
      wt->ideal_size(w, h);
      if (Fluid.main_window) {
        int sx, sy, sw, sh;
        Fl_Window *win = Fluid.main_window;
        int screen = Fl::screen_num(win->x(), win->y());
        Fl::screen_work_area(sx, sy, sw, sh, screen);
        x = sx + sw/2 - w/2;
        y = sy + sh/2 - h/2;
      }
      wt->o->resize(x, y, w, h);
    }
    // make the new widget visible
    select_only(t);
    Fluid.proj.set_modflag(1);
    if (and_open)
      t->open();
  } else {
    Fluid.proj.undo.current_ --;
    Fluid.proj.undo.last_ --;
  }
  Fluid.proj.undo.resume();
  return t;
}

/**
 Create and add a new widget to the widget tree.

 \param[in] inName find the right prototype by this name
 \param[in] strategy where to add the node
 \param[in] and_open if set to true, call open() on the widget after creating it
 \return the newly created type or nullptr

 \see add_new_widget_from_file(const char*, int)
 add_new_widget_from_user(Node*, int)
 add_new_widget_from_user(const char*, int)
 */
Node *add_new_widget_from_user(const char *inName, Strategy strategy, bool and_open) {
  Node *prototype = typename_to_prototype(inName);
  if (prototype)
    return add_new_widget_from_user(prototype, strategy, and_open);
  else
    return nullptr;
}

/**
 Callback for all non-widget menu items.
 */
static void cbf(Fl_Widget *, void *v) {
  Node *t = nullptr;
  if (Fluid.proj.tree.current && Fluid.proj.tree.current->can_have_children())
    t = ((Node*)v)->make(Strategy::AS_LAST_CHILD);
  else
    t = ((Node*)v)->make(Strategy::AFTER_CURRENT);
  select_only(t);
}

/**
 Callback for all widget menu items.

 \param[in] v cast to Node to get the prototype of the type that the user
    wants to create.
 */
static void cb(Fl_Widget *, void *v) {
  Node *t = nullptr;
  if (Fluid.proj.tree.current && Fluid.proj.tree.current->can_have_children())
    t = add_new_widget_from_user((Node*)v, Strategy::AS_LAST_CHILD);
  else
    t = add_new_widget_from_user((Node*)v, Strategy::AFTER_CURRENT);
  select_only(t);
}

/**
 \note Make sure that this menu stays synchronized to `Node *known_types[]`
    defined further up in this file.
 */
Fl_Menu_Item New_Menu[] = {
  {"Code",0,nullptr,nullptr,FL_SUBMENU},
  {"Function/Method",0,cbf,(void*)&Function_Node::prototype},
  {"Code",0,cbf,(void*)&Code_Node::prototype},
  {"Code Block",0,cbf,(void*)&CodeBlock_Node::prototype},
  {"Declaration",0,cbf,(void*)&Decl_Node::prototype},
  {"Declaration Block",0,cbf,(void*)&DeclBlock_Node::prototype},
  {"Class",0,cbf,(void*)&Class_Node::prototype},
  {"Widget Class",0,cb,(void*)&Widget_Class_Node::prototype},
  {"Comment",0,cbf,(void*)&Comment_Node::prototype},
  {"Inlined Data",0,cbf,(void*)&Data_Node::prototype},
  {nullptr},
  {"Group",0,nullptr,nullptr,FL_SUBMENU},
  {nullptr,0,cb,(void*)&Window_Node::prototype},
  {nullptr,0,cb,(void*)&Group_Node::prototype},
  {nullptr,0,cb,(void*)&Pack_Node::prototype},
  {nullptr,0,cb,(void*)&Flex_Node::prototype},
  {nullptr,0,cb,(void*)&Tabs_Node::prototype},
  {nullptr,0,cb,(void*)&Scroll_Node::prototype},
  {nullptr,0,cb,(void*)&Tile_Node::prototype},
  {nullptr,0,cb,(void*)&Wizard_Node::prototype},
  {nullptr,0,cb,(void*)&Grid_Node::prototype},
  {nullptr},
  {"Buttons",0,nullptr,nullptr,FL_SUBMENU},
  {nullptr,0,cb,(void*)&Button_Node::prototype},
  {nullptr,0,cb,(void*)&Return_Button_Node::prototype},
  {nullptr,0,cb,(void*)&Light_Button_Node::prototype},
  {nullptr,0,cb,(void*)&Check_Button_Node::prototype},
  {nullptr,0,cb,(void*)&Repeat_Button_Node::prototype},
  {nullptr,0,cb,(void*)&Round_Button_Node::prototype},
  {nullptr},
  {"Valuators",0,nullptr,nullptr,FL_SUBMENU},
  {nullptr,0,cb,(void*)&Slider_Node::prototype},
  {nullptr,0,cb,(void*)&Scrollbar_Node::prototype},
  {nullptr,0,cb,(void*)&Value_Slider_Node::prototype},
  {nullptr,0,cb,(void*)&Adjuster_Node::prototype},
  {nullptr,0,cb,(void*)&Counter_Node::prototype},
  {nullptr,0,cb,(void*)&Spinner_Node::prototype},
  {nullptr,0,cb,(void*)&Dial_Node::prototype},
  {nullptr,0,cb,(void*)&Roller_Node::prototype},
  {nullptr,0,cb,(void*)&Value_Input_Node::prototype},
  {nullptr,0,cb,(void*)&Value_Output_Node::prototype},
  {nullptr},
  {"Text",0,nullptr,nullptr,FL_SUBMENU},
  {nullptr,0,cb,(void*)&Input_Node::prototype},
  {nullptr,0,cb,(void*)&Output_Node::prototype},
  {nullptr,0,cb,(void*)&Text_Editor_Node::prototype},
  {nullptr,0,cb,(void*)&Text_Display_Node::prototype},
  {nullptr,0,cb,(void*)&File_Input_Node::prototype},
  {nullptr,0,cb,(void*)&Terminal_Node::prototype},
  {nullptr},
  {"Menus",0,nullptr,nullptr,FL_SUBMENU},
  {nullptr,0,cb,(void*)&Menu_Bar_Node::prototype},
  {nullptr,0,cb,(void*)&Menu_Button_Node::prototype},
  {nullptr,0,cb,(void*)&Choice_Node::prototype},
  {nullptr,0,cb,(void*)&Input_Choice_Node::prototype},
  {nullptr,0,cb, (void*)&Submenu_Node::prototype},
  {nullptr,0,cb, (void*)&Menu_Item_Node::prototype},
  {"Checkbox Menu Item",0,cb, (void*)&Checkbox_Menu_Item_Node::prototype},
  {"Radio Menu Item",0,cb, (void*)&Radio_Menu_Item_Node::prototype},
  {nullptr},
  {"Browsers",0,nullptr,nullptr,FL_SUBMENU},
  {nullptr,0,cb,(void*)&Browser_Node::prototype},
  {nullptr,0,cb,(void*)&Check_Browser_Node::prototype},
  {nullptr,0,cb,(void*)&File_Browser_Node::prototype},
  {nullptr,0,cb,(void*)&Tree_Node::prototype},
  {nullptr,0,cb,(void*)&Help_View_Node::prototype},
  {nullptr,0,cb,(void*)&Table_Node::prototype},
  {nullptr},
  {"Other",0,nullptr,nullptr,FL_SUBMENU},
  {nullptr,0,cb,(void*)&Box_Node::prototype},
  {nullptr,0,cb,(void*)&Clock_Node::prototype},
  {nullptr,0,cb,(void*)&Progress_Node::prototype},
  {nullptr},
  {nullptr}};

#include <FL/Fl_Multi_Label.H>

/**
 Modify a menuitem to display an icon in front of the label.
 This is implemented using Fl_Multi_Label as the labeltype (FL_MULTI_LABEL).
 The icon may be null. If ic is null only the text is assigned
 to the label and Fl_Multi_Label is not used.
 \param[in] mi pointer to tme menu item that will be modified
 \param[in] ic icon for the menu, may be nullptr
 \param[in] txt new label text, may *not* be nullptr, will not be copied
 */
static void make_iconlabel(Fl_Menu_Item *mi, Fl_Image *ic, const char *txt)
{
  if (ic) {
    char *t1 = new char[strlen(txt)+6];
    strcpy(t1, " ");
    strcat(t1, txt);
    strcat(t1, "...");
    Fl_Multi_Label *ml = new Fl_Multi_Label;
    ml->labela = (char*)ic;
    ml->labelb = t1;
    ml->typea = FL_IMAGE_LABEL;
    ml->typeb = FL_NORMAL_LABEL;
    ml->label(mi);
  } else {
    if (txt != mi->text)
      mi->label(txt);
  }
}

/**
 Create the labels and icons for the `New_Menu` array.

 Names and icons are taken from the referenced prototypes.
 */
void fill_in_New_Menu() {
  for (unsigned i = 0; i < sizeof(New_Menu)/sizeof(*New_Menu); i++) {
    Fl_Menu_Item *m = New_Menu+i;
    if (m->user_data()) {
      Node *t = (Node*)m->user_data();
      if (m->text) {
        make_iconlabel( m, pixmap[(int)t->type()], m->label() );
      } else {
        const char *n = t->type_name();
        if (!strncmp(n,"Fl_",3)) n += 3;
        if (!strncmp(n,"fltk::",6)) n += 6;
        make_iconlabel( m, pixmap[(int)t->type()], n );
      }
    }
  }
}

/**
 Find the correct prototype for a given type name.
 \param[in] inName a C string that must match type_name() or alt_type_name() of
    one of the known Node classes.
 \return the matching prototype or nullptr
 */
Node *typename_to_prototype(const char *inName)
{
  if (inName==nullptr || *inName==0)
    return nullptr;
  for (unsigned i = 0; i < sizeof(known_types)/sizeof(*known_types); i++) {
    Node *prototype = known_types[i];
    if (fl_ascii_strcasecmp(inName, prototype->type_name())==0)
      return prototype;
    if (fl_ascii_strcasecmp(inName, prototype->alt_type_name())==0)
      return prototype;
  }
  return nullptr;
}

/**
 Create and add a new type node to the widget tree.

 This is used by the .fl file reader. New types are always created as
 the last child of the first compatible parent. New widgets have a default
 setup. Their position, size and label will be read next in the file.

 \param[in] inName a C string that described the type we want
 \param[in] strategy add after current or as last child
 \return the type node that was created or nullptr
 \see add_new_widget_from_file(const char*, int)
 add_new_widget_from_user(Node*, int)
 add_new_widget_from_user(const char*, int)
*/
Node *add_new_widget_from_file(const char *inName, Strategy strategy) {
  Node *prototype = typename_to_prototype(inName);
  if (!prototype)
    return nullptr;
  Node *new_node = prototype->make(strategy);
  return new_node;
}

////////////////////////////////////////////////////////////////

// Since I have included all the .H files, do this table here:
// This table is only used to read fdesign files:

struct symbol {const char *name; int value;};

/**
 Table with all symbols known by the "fdesign" format reader.
 This table does not need to be sorted alphabetically.
 */
static symbol table[] = {
  {"BLACK",                     FL_BLACK},
  {"RED",                       FL_RED},
  {"GREEN",                     FL_GREEN},
  {"YELLOW",                    FL_YELLOW},
  {"BLUE",                      FL_BLUE},
  {"MAGENTA",                   FL_MAGENTA},
  {"CYAN",                      FL_CYAN},
  {"WHITE",                     FL_WHITE},

  {"LCOL",                      FL_BLACK},
  {"COL1",                      FL_GRAY},
  {"MCOL",                      FL_LIGHT1},
  {"LEFT_BCOL",                 FL_LIGHT3},
  {"TOP_BCOL",                  FL_LIGHT2},
  {"BOTTOM_BCOL",               FL_DARK2},
  {"RIGHT_BCOL",                FL_DARK3},
  {"INACTIVE",                  FL_INACTIVE_COLOR},
  {"INACTIVE_COL",              FL_INACTIVE_COLOR},
  {"FREE_COL1",                 FL_FREE_COLOR},
  {"FREE_COL2",                 FL_FREE_COLOR+1},
  {"FREE_COL3",                 FL_FREE_COLOR+2},
  {"FREE_COL4",                 FL_FREE_COLOR+3},
  {"FREE_COL5",                 FL_FREE_COLOR+4},
  {"FREE_COL6",                 FL_FREE_COLOR+5},
  {"FREE_COL7",                 FL_FREE_COLOR+6},
  {"FREE_COL8",                 FL_FREE_COLOR+7},
  {"FREE_COL9",                 FL_FREE_COLOR+8},
  {"FREE_COL10",                FL_FREE_COLOR+9},
  {"FREE_COL11",                FL_FREE_COLOR+10},
  {"FREE_COL12",                FL_FREE_COLOR+11},
  {"FREE_COL13",                FL_FREE_COLOR+12},
  {"FREE_COL14",                FL_FREE_COLOR+13},
  {"FREE_COL15",                FL_FREE_COLOR+14},
  {"FREE_COL16",                FL_FREE_COLOR+15},
  {"TOMATO",                    131},
  {"INDIANRED",                 164},
  {"SLATEBLUE",                 195},
  {"DARKGOLD",                  84},
  {"PALEGREEN",                 157},
  {"ORCHID",                    203},
  {"DARKCYAN",                  189},
  {"DARKTOMATO",                113},
  {"WHEAT",                     174},
  {"ALIGN_CENTER",              FL_ALIGN_CENTER},
  {"ALIGN_TOP",                 FL_ALIGN_TOP},
  {"ALIGN_BOTTOM",              FL_ALIGN_BOTTOM},
  {"ALIGN_LEFT",                FL_ALIGN_LEFT},
  {"ALIGN_RIGHT",               FL_ALIGN_RIGHT},
  {"ALIGN_INSIDE",              FL_ALIGN_INSIDE},
  {"ALIGN_TOP_LEFT",            FL_ALIGN_TOP | FL_ALIGN_LEFT},
  {"ALIGN_TOP_RIGHT",           FL_ALIGN_TOP | FL_ALIGN_RIGHT},
  {"ALIGN_BOTTOM_LEFT",         FL_ALIGN_BOTTOM | FL_ALIGN_LEFT},
  {"ALIGN_BOTTOM_RIGHT",        FL_ALIGN_BOTTOM | FL_ALIGN_RIGHT},
  {"ALIGN_CENTER|FL_ALIGN_INSIDE",      FL_ALIGN_CENTER|FL_ALIGN_INSIDE},
  {"ALIGN_TOP|FL_ALIGN_INSIDE",         FL_ALIGN_TOP|FL_ALIGN_INSIDE},
  {"ALIGN_BOTTOM|FL_ALIGN_INSIDE",      FL_ALIGN_BOTTOM|FL_ALIGN_INSIDE},
  {"ALIGN_LEFT|FL_ALIGN_INSIDE",        FL_ALIGN_LEFT|FL_ALIGN_INSIDE},
  {"ALIGN_RIGHT|FL_ALIGN_INSIDE",       FL_ALIGN_RIGHT|FL_ALIGN_INSIDE},
  {"ALIGN_INSIDE|FL_ALIGN_INSIDE",      FL_ALIGN_INSIDE|FL_ALIGN_INSIDE},
  {"ALIGN_TOP_LEFT|FL_ALIGN_INSIDE",    FL_ALIGN_TOP|FL_ALIGN_LEFT|FL_ALIGN_INSIDE},
  {"ALIGN_TOP_RIGHT|FL_ALIGN_INSIDE",   FL_ALIGN_TOP|FL_ALIGN_RIGHT|FL_ALIGN_INSIDE},
  {"ALIGN_BOTTOM_LEFT|FL_ALIGN_INSIDE", FL_ALIGN_BOTTOM|FL_ALIGN_LEFT|FL_ALIGN_INSIDE},
  {"ALIGN_BOTTOM_RIGHT|FL_ALIGN_INSIDE",FL_ALIGN_BOTTOM|FL_ALIGN_RIGHT|FL_ALIGN_INSIDE},

  {"ALIGN_LEFT_TOP",            FL_ALIGN_TOP | FL_ALIGN_LEFT},
  {"ALIGN_RIGHT_TOP",           FL_ALIGN_TOP | FL_ALIGN_RIGHT},
  {"ALIGN_LEFT_BOTTOM",         FL_ALIGN_BOTTOM | FL_ALIGN_LEFT},
  {"ALIGN_RIGHT_BOTTOM",        FL_ALIGN_BOTTOM | FL_ALIGN_RIGHT},
  {"INVALID_STYLE",             255},
  {"NORMAL_STYLE",              FL_HELVETICA},
  {"BOLD_STYLE",                FL_HELVETICA|FL_BOLD},
  {"ITALIC_STYLE",              FL_HELVETICA|FL_ITALIC},
  {"BOLDITALIC_STYLE",          FL_HELVETICA|FL_BOLD|FL_ITALIC},
  {"FIXED_STYLE",               FL_COURIER},
  {"FIXEDBOLD_STYLE",           FL_COURIER|FL_BOLD},
  {"FIXEDITALIC_STYLE",         FL_COURIER|FL_ITALIC},
  {"FIXEDBOLDITALIC_STYLE",     FL_COURIER|FL_BOLD|FL_ITALIC},
  {"TIMES_STYLE",               FL_TIMES},
  {"TIMESBOLD_STYLE",           FL_TIMES|FL_BOLD},
  {"TIMESITALIC_STYLE",         FL_TIMES|FL_ITALIC},
  {"TIMESBOLDITALIC_STYLE",     FL_TIMES|FL_BOLD|FL_ITALIC},
  {"SHADOW_STYLE",              (_FL_SHADOW_LABEL<<8)},
  {"ENGRAVED_STYLE",            (_FL_ENGRAVED_LABEL<<8)},
  {"EMBOSSED_STYLE",            (_FL_EMBOSSED_LABEL<<0)},
  {"TINY_SIZE",                 8},
  {"SMALL_SIZE",                11},
  {"NORMAL_SIZE",               FL_NORMAL_SIZE},
  {"MEDIUM_SIZE",               18},
  {"LARGE_SIZE",                24},
  {"HUGE_SIZE",                 32},
  {"DEFAULT_SIZE",              FL_NORMAL_SIZE},
  {"TINY_FONT",                 8},
  {"SMALL_FONT",                11},
  {"NORMAL_FONT",               FL_NORMAL_SIZE},
  {"MEDIUM_FONT",               18},
  {"LARGE_FONT",                24},
  {"HUGE_FONT",                 32},
  {"NORMAL_FONT1",              11},
  {"NORMAL_FONT2",              FL_NORMAL_SIZE},
  {"DEFAULT_FONT",              11},
  {"RETURN_END_CHANGED",        0},
  {"RETURN_CHANGED",            1},
  {"RETURN_END",                2},
  {"RETURN_ALWAYS",             3},
  {"PUSH_BUTTON",               FL_TOGGLE_BUTTON},
  {"RADIO_BUTTON",              FL_RADIO_BUTTON},
  {"HIDDEN_BUTTON",             FL_HIDDEN_BUTTON},
  {"SELECT_BROWSER",            FL_SELECT_BROWSER},
  {"HOLD_BROWSER",              FL_HOLD_BROWSER},
  {"MULTI_BROWSER",             FL_MULTI_BROWSER},
  {"SIMPLE_COUNTER",            FL_SIMPLE_COUNTER},
  {"LINE_DIAL",                 FL_LINE_DIAL},
  {"FILL_DIAL",                 FL_FILL_DIAL},
  {"VERT_SLIDER",               FL_VERT_SLIDER},
  {"HOR_SLIDER",                FL_HOR_SLIDER},
  {"VERT_FILL_SLIDER",          FL_VERT_FILL_SLIDER},
  {"HOR_FILL_SLIDER",           FL_HOR_FILL_SLIDER},
  {"VERT_NICE_SLIDER",          FL_VERT_NICE_SLIDER},
  {"HOR_NICE_SLIDER",           FL_HOR_NICE_SLIDER},
};

/**
 \brief Find a symbol in an array of name/value pairs and return the value.

 If numberok is 0, and the symbol was not found, v remains unchanged and the
 function returns 0.

 If numberok is set and no label matched, the symbol is interpreted as a
 string containing an integer. If the string is not an integer, v is set to 0
 and the function returns 0.

 If the symbol is found, or the integer could be read, v is set to the
 value, and the function returns 1.

 \param[in] name find a symbol by this name, a leading "FL_" is ignored
 \param[out] v value associated to the symbol, or the integer value
 \param[in] numberok if set, the symbol can also be a text representing an
    integer number
 \return 0 if the symbol was not found and the integer was not valid
 \return 1 otherwise and set v
 */
int lookup_symbol(const char *name, int &v, int numberok) {
  if ((name[0]=='F') && (name[1]=='L') && (name[2]=='_'))
    name += 3;
  for (int i=0; i < int(sizeof(table)/sizeof(*table)); i++) {
    if (!fl_ascii_strcasecmp(name,table[i].name)) {
      v = table[i].value;
      return 1;
    }
  }
  if (numberok && ((v = atoi(name)) || !strcmp(name,"0")))
    return 1;
  return 0;
}