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
|
//-----------------------------------------------------------------------------
// Copyright 2007 Jonathan Westhues
//
// This file is part of LDmicro.
//
// LDmicro 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.
//
// LDmicro 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 LDmicro. If not, see <http://www.gnu.org/licenses/>.
//------
//
// Common controls in the main window. The main window consists of the drawing
// area, where the ladder diagram is displayed, plus various controls for
// scrolling, I/O list, menus.
// Jonathan Westhues, Nov 2004
//-----------------------------------------------------------------------------
#include "linuxUI.h"
#include <typeinfo>
//#include <commctrl.h>
//#include <commdlg.h>
#include <stdio.h>
#include <stdlib.h>
#include "ldmicro.h"
// Menu IDs
HMENU NewMenu;
HMENU OpenMenu;
HMENU SaveMenu;
HMENU SaveAsMenu;
HMENU ExportMenu;
HMENU ExitMenu;
HMENU UndoMenu;
HMENU RedoMenu;
HMENU PushRungUpMenu;
HMENU PushRungDownMenu;
HMENU InsertRungBeforeMenu;
HMENU InsertRungAfterMenu;
HMENU DeleteElementMenu;
HMENU DeleteRungMenu;
HMENU InsertCommentMenu;
HMENU InsertContactsMenu;
HMENU InsertCoilMenu;
HMENU InsertTonMenu;
HMENU InsertTofMenu;
HMENU InsertRtoMenu;
HMENU InsertResMenu;
HMENU InsertOsrMenu;
HMENU InsertOsfMenu;
HMENU InsertCtuMenu;
HMENU InsertCtdMenu;
HMENU InsertCtcMenu;
HMENU InsertAddMenu;
HMENU InsertSubMenu;
HMENU InsertMulMenu;
HMENU InsertDivMenu;
HMENU InsertMovMenu;
HMENU InsertReadAdcMenu;
HMENU InsertSetPwmMenu;
HMENU InsertUartSendMenu;
HMENU InsertUartRecvMenu;
HMENU InsertEquMenu;
HMENU InsertNeqMenu;
HMENU InsertGrtMenu;
HMENU InsertGeqMenu;
HMENU InsertLesMenu;
HMENU InsertLeqMenu;
HMENU InsertOpenMenu;
HMENU InsertShortMenu;
HMENU InsertMasterRlyMenu;
HMENU InsertShiftRegMenu;
HMENU InsertLutMenu;
HMENU InsertFmtdStrMenu;
HMENU InsertPersistMenu;
HMENU MakeNormalMenu;
HMENU NegateMenu;
HMENU MakeSetOnlyMenu;
HMENU MakeResetOnlyMenu;
HMENU InsertPwlMenu;
HMENU McuSettingsMenu;
HMENU ProcessorMenuItems[NUM_SUPPORTED_MCUS+1];
HMENU MicroControllerMenu; // Item for Microcontroller
HMENU SimulationModeMenu;
HMENU StartSimulationMenu;
HMENU StopSimulationMenu;
HMENU SingleCycleMenu;
HMENU CompileMenu;
HMENU CompileAsMenu;
HMENU ManualMenu;
HMENU AboutMenu;
// scrollbars for the ladder logic area
// static HWND HorizScrollBar;
// static HWND VertScrollBar;
int ScrollWidth;
int ScrollHeight;
BOOL NeedHoriz;
// status bar at the bottom of the screen, to display settings
static HMENU StatusBar[3];
// have to get back to the menus to gray/ungray, check/uncheck things
static HMENU FileMenu;
static HMENU EditMenu;
static HMENU InstructionMenu;
static HMENU ProcessorMenu;
static HMENU SimulateMenu;
static HMENU TopMenu; // Menu Bar
static HMENU Settings;
static HMENU Compile;
static HMENU Help;
HMENU ScrollWindow;
// listview used to maintain the list of I/O pins with symbolic names, plus
// the internal relay too
HLIST IoList;
static int IoListSelectionPoint;
static BOOL IoListOutOfSync;
int IoListHeight;
int IoListTop;
// whether the simulation is running in real time
static BOOL RealTimeSimulationRunning;
// Displaying keyboard shortcuts for each menu item
void AddMenuAccelerators (void){
// Declaring the accelerator group for keyboard shortcuts
AccelGroup = gtk_accel_group_new ();
// Creating keyboard shortcuts for File menu
gtk_widget_add_accelerator (NewMenu, "activate", AccelGroup, GDK_KEY_N,
GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (OpenMenu, "activate", AccelGroup, GDK_KEY_O,
GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (SaveMenu, "activate", AccelGroup, GDK_KEY_S,
GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (ExportMenu, "activate", AccelGroup, GDK_KEY_E,
GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
// Creating keyboard shortcuts for Edit menu
gtk_widget_add_accelerator (UndoMenu, "activate", AccelGroup, GDK_KEY_Z,
GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (RedoMenu, "activate", AccelGroup, GDK_KEY_Y,
GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertRungBeforeMenu, "activate", AccelGroup, GDK_KEY_F6,
GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertRungAfterMenu, "activate", AccelGroup, GDK_KEY_V,
GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (PushRungUpMenu, "activate", AccelGroup, GDK_KEY_uparrow,
GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (PushRungDownMenu, "activate", AccelGroup, GDK_KEY_downarrow,
GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (DeleteElementMenu, "activate", AccelGroup, GDK_KEY_Delete,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (DeleteRungMenu, "activate", AccelGroup, GDK_KEY_Delete,
GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE);
// Creating keyboard shortcuts for Instructions menu
gtk_widget_add_accelerator (InsertCommentMenu, "activate", AccelGroup, GDK_KEY_semicolon,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertContactsMenu, "activate", AccelGroup, GDK_KEY_C,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertOsrMenu, "activate", AccelGroup, GDK_KEY_backslash,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertOsfMenu, "activate", AccelGroup, GDK_KEY_slash,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertTonMenu, "activate", AccelGroup, GDK_KEY_O,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertTofMenu, "activate", AccelGroup, GDK_KEY_F,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertRtoMenu, "activate", AccelGroup, GDK_KEY_T,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertCtuMenu, "activate", AccelGroup, GDK_KEY_U,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertCtdMenu, "activate", AccelGroup, GDK_KEY_I,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertCtcMenu, "activate", AccelGroup, GDK_KEY_J,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertEquMenu, "activate", AccelGroup, GDK_KEY_equal,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertGrtMenu, "activate", AccelGroup, GDK_KEY_greater,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertGeqMenu, "activate", AccelGroup, GDK_KEY_Stop,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertLesMenu, "activate", AccelGroup, GDK_KEY_less,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertLeqMenu, "activate", AccelGroup, GDK_KEY_comma,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertCoilMenu, "activate", AccelGroup, GDK_KEY_L,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertResMenu, "activate", AccelGroup, GDK_KEY_E,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertMovMenu, "activate", AccelGroup, GDK_KEY_M,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertAddMenu, "activate", AccelGroup, GDK_KEY_plus,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertSubMenu, "activate", AccelGroup, GDK_KEY_minus,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertMulMenu, "activate", AccelGroup, GDK_KEY_multiply,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertDivMenu, "activate", AccelGroup, GDK_KEY_D,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (InsertReadAdcMenu, "activate", AccelGroup, GDK_KEY_P,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (MakeNormalMenu, "activate", AccelGroup, GDK_KEY_A,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (NegateMenu, "activate", AccelGroup, GDK_KEY_N,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (MakeSetOnlyMenu, "activate", AccelGroup, GDK_KEY_S,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (MakeResetOnlyMenu, "activate", AccelGroup, GDK_KEY_R,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
// Creating keyboard shortcuts for Simulation menu
gtk_widget_add_accelerator (SimulationModeMenu, "activate", AccelGroup, GDK_KEY_M,
GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (StartSimulationMenu, "activate", AccelGroup, GDK_KEY_R,
GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (StopSimulationMenu, "activate", AccelGroup, GDK_KEY_H,
GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
gtk_widget_add_accelerator (SingleCycleMenu, "activate", AccelGroup, GDK_KEY_space,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
// Creating keyboard shortcuts for Compile menu
gtk_widget_add_accelerator (CompileMenu, "activate", AccelGroup, GDK_KEY_F5,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
// Creating keyboard shortcuts for Help menu
gtk_widget_add_accelerator (ManualMenu, "activate", AccelGroup, GDK_KEY_F1,
(GdkModifierType)0, GTK_ACCEL_VISIBLE);
gtk_window_add_accel_group (GTK_WINDOW (MainWindow), AccelGroup);
}
//-----------------------------------------------------------------------------
// Create the top-level menu bar for the main window. Mostly static, but we
// create the "select processor" menu from the list in mcutable.h dynamically.
//-----------------------------------------------------------------------------
HMENU MakeMainWindowMenus(void)
{
HMENU MenuBox; // Box for packing and alignment
// HMENU TopMenu; // Menu Bar
HWID FileLabel; // File menu label
HWID EditLabel; // Edit menu label
HWID InstructionLabel; // Instruction menu label
HWID SettingsLabel; // Settings menu label
HWID CompileLabel; // Compile menu label
HWID HelpLabel; // Help menu label
HWID SimulateLabel; // Simulate menu label
HMENU FileMenuSeparator; // File menu separator
HMENU EditMenuSeparator; // Edit menu separator
HMENU InstructionMenuSeparator; // Instruction menu separator
HMENU SimulateMenuSeparator; // Simulate menu separator
int i;
// Creating a box for desired orientation
MenuBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
// Create new menu bar to hold menu and add it to window
TopMenu = gtk_menu_bar_new();
// Creating various menus
FileMenu = gtk_menu_new();
EditMenu = gtk_menu_new();
Settings = gtk_menu_new();
ProcessorMenu = gtk_menu_new();
InstructionMenu = gtk_menu_new();
SimulateMenu = gtk_menu_new();
Compile = gtk_menu_new();
Help = gtk_menu_new();
// Creating labels for each menu
FileLabel = gtk_menu_item_new_with_mnemonic("_File");
EditLabel = gtk_menu_item_new_with_mnemonic("_Edit");
SettingsLabel = gtk_menu_item_new_with_mnemonic("_Settings");
InstructionLabel = gtk_menu_item_new_with_mnemonic("_Instructions");
SimulateLabel = gtk_menu_item_new_with_mnemonic("_Simulate");
CompileLabel = gtk_menu_item_new_with_mnemonic("_Compile");
HelpLabel = gtk_menu_item_new_with_mnemonic("_Help");
// Creating labels for File Menu
NewMenu = gtk_menu_item_new_with_mnemonic("_New");
OpenMenu = gtk_menu_item_new_with_mnemonic("_Open");
SaveMenu = gtk_menu_item_new_with_mnemonic("_Save");
SaveAsMenu = gtk_menu_item_new_with_mnemonic("_Save As");
ExportMenu = gtk_menu_item_new_with_mnemonic("_Export As Text");
ExitMenu = gtk_menu_item_new_with_mnemonic("_Exit");
// Appending menu items (labels) to File menu and adding separators
gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), NewMenu); // Appending menu items
gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), OpenMenu);
gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), SaveMenu);
gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), SaveAsMenu);
FileMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), FileMenuSeparator);
gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), ExportMenu);
FileMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), FileMenuSeparator);
gtk_menu_shell_append(GTK_MENU_SHELL (FileMenu), ExitMenu);
// Creating labels for Edit Menu
UndoMenu = gtk_menu_item_new_with_mnemonic("_Undo");
RedoMenu = gtk_menu_item_new_with_mnemonic("_Redo");
InsertRungBeforeMenu = gtk_menu_item_new_with_mnemonic("_Insert rung Before");
InsertRungAfterMenu = gtk_menu_item_new_with_mnemonic("_Insert Rung After");
PushRungUpMenu = gtk_menu_item_new_with_mnemonic("_Move Selected Rung Up");
PushRungDownMenu = gtk_menu_item_new_with_mnemonic("_Move Selected Rung Down");
DeleteElementMenu = gtk_menu_item_new_with_mnemonic("_Delete Selected Element");
DeleteRungMenu = gtk_menu_item_new_with_mnemonic("_Delete Rung");
// Appending menu items to Edit menu and adding separators
gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), UndoMenu);
gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), RedoMenu);
EditMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(EditMenu), EditMenuSeparator);
gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), InsertRungBeforeMenu);
gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), InsertRungAfterMenu);
gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), PushRungUpMenu);
gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), PushRungDownMenu);
EditMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(EditMenu), EditMenuSeparator);
gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), DeleteElementMenu);
gtk_menu_shell_append(GTK_MENU_SHELL (EditMenu), DeleteRungMenu);
// Creating labels for Settings Menu
McuSettingsMenu = gtk_menu_item_new_with_mnemonic ("_MCU Parameters...");
MicroControllerMenu = gtk_menu_item_new_with_mnemonic ("_Microcontroller");
// Appending menu items to Settings menu
gtk_menu_shell_append (GTK_MENU_SHELL (Settings), McuSettingsMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (Settings), MicroControllerMenu);
// Appending the microcontroller names to "Microcontroller" item
GSList* mcuList = NULL;
for (i = 0; i < NUM_SUPPORTED_MCUS; i++){
ProcessorMenuItems[i] = gtk_radio_menu_item_new_with_label (mcuList, SupportedMcus[i].mcuName);
mcuList = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (ProcessorMenuItems[i]));
gtk_menu_shell_append (GTK_MENU_SHELL (ProcessorMenu), ProcessorMenuItems[i]);
}
ProcessorMenuItems[NUM_SUPPORTED_MCUS] = gtk_radio_menu_item_new_with_label (mcuList, "(no microcontroller)");
mcuList = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (ProcessorMenuItems[NUM_SUPPORTED_MCUS]));
gtk_menu_shell_append (GTK_MENU_SHELL (ProcessorMenu), ProcessorMenuItems[NUM_SUPPORTED_MCUS]);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(MicroControllerMenu), ProcessorMenu);
// Creating labels for Instruction Menu and adding separators
InsertCommentMenu = gtk_menu_item_new_with_mnemonic("_Insert Comment");
InsertContactsMenu = gtk_menu_item_new_with_mnemonic("_Insert Contacts");
InsertOsrMenu = gtk_menu_item_new_with_mnemonic("_Insert OSR (One Shot Rising)");
InsertOsfMenu = gtk_menu_item_new_with_mnemonic("_Insert OSF (One Shot Falling)");
InsertTonMenu = gtk_menu_item_new_with_mnemonic("_Insert TON (Delayed Turn On)");
InsertTofMenu = gtk_menu_item_new_with_mnemonic("_Insert TOF (Delayed Turn Off)");
InsertRtoMenu = gtk_menu_item_new_with_mnemonic("_Insert RTO (Retentive Delayed Turn On)");
InsertCtuMenu = gtk_menu_item_new_with_mnemonic("_Insert CTU (Count Up)");
InsertCtdMenu = gtk_menu_item_new_with_mnemonic("_Insert CTD (Count Down)");
InsertCtcMenu = gtk_menu_item_new_with_mnemonic("_Insert CTC (Count Circular)");
InsertEquMenu = gtk_menu_item_new_with_mnemonic("_Insert EQU (Compare for Equals)");
InsertNeqMenu = gtk_menu_item_new_with_mnemonic("_Insert NEQ (Compare for Not Equals)");
InsertGrtMenu = gtk_menu_item_new_with_mnemonic("_Insert GRT (Compare for Greater Than)");
InsertGeqMenu = gtk_menu_item_new_with_mnemonic("_Insert GEQ (Compare for Greater Than or Equal)");
InsertLesMenu = gtk_menu_item_new_with_mnemonic("_Insert LES (Compare for Less Than)");
InsertLeqMenu = gtk_menu_item_new_with_mnemonic("_Insert LEQ (Compare for Less Than or Equal)");
InsertOpenMenu = gtk_menu_item_new_with_mnemonic("_Insert Open Circuit");
InsertShortMenu = gtk_menu_item_new_with_mnemonic("_Insert Short Circuit");
InsertMasterRlyMenu = gtk_menu_item_new_with_mnemonic("_Insert Master Control Relay");
InsertCoilMenu = gtk_menu_item_new_with_mnemonic("_Insert Coil");
InsertResMenu = gtk_menu_item_new_with_mnemonic("_Insert RES (Counter/RTO Reset)");
InsertMovMenu = gtk_menu_item_new_with_mnemonic("_Insert MOV (Move)");
InsertAddMenu = gtk_menu_item_new_with_mnemonic("_Insert ADD (16-bit Integer Ad)");
InsertSubMenu = gtk_menu_item_new_with_mnemonic("_Insert SUB (16-bit Integer Subtract)");
InsertMulMenu = gtk_menu_item_new_with_mnemonic("_Insert MUL (16-bit Integer Multiply)");
InsertDivMenu = gtk_menu_item_new_with_mnemonic("_Insert DIV (16-bit Integer Division)");
InsertShiftRegMenu = gtk_menu_item_new_with_mnemonic("_Insert Shift Register");
InsertLutMenu = gtk_menu_item_new_with_mnemonic("_Insert Look-Up Table");
InsertPwlMenu = gtk_menu_item_new_with_mnemonic("_Insert Piecewise Linear");
InsertFmtdStrMenu = gtk_menu_item_new_with_mnemonic("_Insert Formatted String Over UART");
InsertUartSendMenu = gtk_menu_item_new_with_mnemonic("_Insert UART Send");
InsertUartRecvMenu = gtk_menu_item_new_with_mnemonic("_Insert UART Receive");
InsertSetPwmMenu = gtk_menu_item_new_with_mnemonic("_Insert Set PWM Output");
InsertReadAdcMenu = gtk_menu_item_new_with_mnemonic("_Insert A/D Converter Read");
InsertPersistMenu = gtk_menu_item_new_with_mnemonic("_Insert Make Persistent");
MakeNormalMenu = gtk_menu_item_new_with_mnemonic("_Make Normal");
NegateMenu = gtk_menu_item_new_with_mnemonic("_Make Negated");
MakeSetOnlyMenu = gtk_menu_item_new_with_mnemonic("_Make Set-Only");
MakeResetOnlyMenu = gtk_menu_item_new_with_mnemonic("_Make Reset-Only");
// Appending menu items to Instruction menu and adding separators
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertCommentMenu);
InstructionMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertContactsMenu);
InstructionMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertOsrMenu);
InstructionMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertOsfMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertTonMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertTofMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertRtoMenu);
InstructionMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertCtuMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertCtdMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertCtcMenu);
InstructionMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertEquMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertNeqMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertGrtMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertGeqMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertLesMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertLeqMenu);
InstructionMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertOpenMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertShortMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertMasterRlyMenu);
InstructionMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertCoilMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertResMenu);
InstructionMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertMovMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertAddMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertSubMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertMulMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertDivMenu);
InstructionMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append (GTK_MENU_SHELL(InstructionMenu), InstructionMenuSeparator);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertShiftRegMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertLutMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertPwlMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertFmtdStrMenu);
InstructionMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InstructionMenuSeparator);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertUartSendMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertUartRecvMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertSetPwmMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertReadAdcMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InsertPersistMenu);
InstructionMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), InstructionMenuSeparator);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MakeNormalMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), NegateMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MakeSetOnlyMenu);
gtk_menu_shell_append (GTK_MENU_SHELL (InstructionMenu), MakeResetOnlyMenu);
// Creating labels for Compile Menu
CompileMenu = gtk_menu_item_new_with_mnemonic("_Compile");
CompileAsMenu = gtk_menu_item_new_with_mnemonic("_Compile As...");
// Appending menu items to Compile menu
gtk_menu_shell_append(GTK_MENU_SHELL (Compile), CompileMenu);
gtk_menu_shell_append(GTK_MENU_SHELL (Compile), CompileAsMenu);
// Creating labels for Help Menu
ManualMenu = gtk_menu_item_new_with_mnemonic("_Manual...");
AboutMenu = gtk_menu_item_new_with_mnemonic("_About...");
// Appending menu items to Help menu
gtk_menu_shell_append(GTK_MENU_SHELL (Help), ManualMenu);
gtk_menu_shell_append(GTK_MENU_SHELL (Help), AboutMenu);
// Creating labels for Simulation Menu
SimulationModeMenu = gtk_check_menu_item_new_with_mnemonic("_Simulation Mode");
StartSimulationMenu = gtk_menu_item_new_with_mnemonic("_Start Real-Time Simulation");
StopSimulationMenu = gtk_menu_item_new_with_mnemonic("_Halt Simulation");
SingleCycleMenu = gtk_menu_item_new_with_mnemonic("_Single Cycle");
// Appending menu items to Simulate menu and adding separators
gtk_menu_shell_append(GTK_MENU_SHELL (SimulateMenu), SimulationModeMenu);
gtk_menu_shell_append(GTK_MENU_SHELL (SimulateMenu), StartSimulationMenu);
gtk_menu_shell_append(GTK_MENU_SHELL (SimulateMenu), StopSimulationMenu);
gtk_menu_shell_append(GTK_MENU_SHELL (SimulateMenu), SingleCycleMenu);
SimulateMenuSeparator = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(SimulateMenu), SimulateMenuSeparator);
// Creating submenus for each menu
gtk_menu_item_set_submenu(GTK_MENU_ITEM(FileLabel), FileMenu);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(EditLabel), EditMenu);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(SettingsLabel), Settings);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(InstructionLabel), InstructionMenu);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(SimulateLabel), SimulateMenu);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(CompileLabel), Compile);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(HelpLabel), Help);
// Appending the menu item to the menu bar
gtk_menu_shell_append(GTK_MENU_SHELL(TopMenu), FileLabel);
gtk_menu_shell_append(GTK_MENU_SHELL(TopMenu), EditLabel);
gtk_menu_shell_append(GTK_MENU_SHELL(TopMenu), SettingsLabel);
gtk_menu_shell_append(GTK_MENU_SHELL(TopMenu), InstructionLabel);
gtk_menu_shell_append(GTK_MENU_SHELL(TopMenu), SimulateLabel);
gtk_menu_shell_append(GTK_MENU_SHELL(TopMenu), CompileLabel);
gtk_menu_shell_append(GTK_MENU_SHELL(TopMenu), HelpLabel);
// Packing the menu bar into the box for alignment
gtk_box_pack_start(GTK_BOX(MenuBox), TopMenu, FALSE, FALSE, 0);
AddMenuAccelerators ();
return MenuBox;
}
//-----------------------------------------------------------------------------
// Create the standard Windows controls used in the main window: a Listview
// for the I/O list, and a status bar for settings.
//-----------------------------------------------------------------------------
void MakeMainWindowControls(void)
{
HWID PackBoxMenu = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
HWID grid = gtk_grid_new();
/// Pane to separate Scrolled Window and other widgets
HWID pane = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
IoList = (GtkTreeModel*)gtk_list_store_new (5,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING);
int typeWidth = 85;
int pinWidth = 100;
int portWidth = 90;
/// Creating a list
view = gtk_tree_view_new_with_model (GTK_TREE_MODEL(IoList));
gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (IoList));
gtk_tree_view_set_enable_search (GTK_TREE_VIEW (view), FALSE);
column = gtk_tree_view_column_new_with_attributes("Name",
gtk_cell_renderer_text_new(),
"text", LV_IO_NAME,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
gtk_tree_view_column_set_min_width (column, 250);
column = gtk_tree_view_column_new_with_attributes("Type",
gtk_cell_renderer_spin_new(),
"text", LV_IO_TYPE,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
gtk_tree_view_column_set_min_width (column, typeWidth);
column = gtk_tree_view_column_new_with_attributes("State",
gtk_cell_renderer_text_new(),
"text", LV_IO_STATE,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
gtk_tree_view_column_set_min_width (column, 100);
column = gtk_tree_view_column_new_with_attributes("Pin on Processor",
gtk_cell_renderer_text_new(),
"text", LV_IO_PIN,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
gtk_tree_view_column_set_min_width (column, pinWidth);
column = gtk_tree_view_column_new_with_attributes("MCU Port",
gtk_cell_renderer_text_new(),
"text", LV_IO_PORT,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
gtk_tree_view_column_set_min_width (column, portWidth);
/// Appending Menus to grid
gtk_grid_attach (GTK_GRID (grid), MakeMainWindowMenus(), 0, 0, 1, 1);
/// Creating Scrolled Window
ScrollWindow = gtk_scrolled_window_new (NULL, NULL);
HWID ViewPortMenu = gtk_viewport_new (NULL,NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (ScrollWindow),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_ALWAYS);
gtk_widget_set_hexpand(GTK_WIDGET(ScrollWindow), TRUE);
gtk_widget_set_vexpand(GTK_WIDGET(ScrollWindow), TRUE);
/// Adding DrawWindow to pane
gtk_container_add (GTK_CONTAINER(ViewPortMenu), DrawWindow);
gtk_container_add (GTK_CONTAINER(ScrollWindow), ViewPortMenu);
gtk_paned_pack1 (GTK_PANED (pane), ScrollWindow, TRUE, TRUE);
gtk_paned_set_position (GTK_PANED (pane), 0);
/// Appending tree view to scrolled window
HWID ViewScroll = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (ViewScroll),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_ALWAYS);
gtk_widget_set_hexpand(GTK_WIDGET(ViewScroll), TRUE);
gtk_widget_set_vexpand(GTK_WIDGET(ViewScroll), TRUE);
gtk_container_add (GTK_CONTAINER(ViewScroll), view);
/// Appending tree view to pane and pane to grid
gtk_paned_pack2 (GTK_PANED(pane), ViewScroll, FALSE, FALSE);
gtk_paned_set_position (GTK_PANED (pane), 400);
gtk_grid_attach (GTK_GRID (grid), pane, 0, 0, 1, 1);
gtk_box_pack_start(GTK_BOX(PackBoxMenu), grid, FALSE, TRUE, 0);
/// Grid for status bars
HWID StatusGrid = gtk_grid_new();
gtk_widget_override_background_color(GTK_WIDGET(StatusGrid),
GTK_STATE_FLAG_NORMAL, ((HBRUSH)GetStockObject(DKGRAY_BRUSH)));
/// Creating Status Bar 1 and attaching to grid
StatusBar[0] = gtk_statusbar_new();
gtk_statusbar_push (GTK_STATUSBAR (StatusBar[0]),
gtk_statusbar_get_context_id (GTK_STATUSBAR (StatusBar[0]),
"Introduction"), "LDMicro Started");
/// Appneding Status Bar 1 to the status grid
gtk_grid_attach (GTK_GRID (StatusGrid), StatusBar[0], 0, 0, 1, 1);
/// Creating Status Bar 2 and attaching to grid
StatusBar[1] = gtk_statusbar_new();
gtk_statusbar_push (GTK_STATUSBAR (StatusBar[1]),
gtk_statusbar_get_context_id (GTK_STATUSBAR (StatusBar[1]),
"Introduction"), "LDMicro Started");
/// Appneding Status Bar 2 to the status box
gtk_grid_attach (GTK_GRID (StatusGrid), StatusBar[1], 1, 0, 1, 1);
/// Creating Status Bar 3 and attaching to grid
StatusBar[2] = gtk_statusbar_new();
gtk_statusbar_push (GTK_STATUSBAR (StatusBar[2]),
gtk_statusbar_get_context_id (GTK_STATUSBAR (StatusBar[2]),
"Introduction"), "LDMicro Started");
/// Appneding Status Bar 3 to the status box
gtk_grid_attach (GTK_GRID (StatusGrid), StatusBar[2], 2, 0, 1, 1);
/// Attach status grid to box
gtk_box_pack_start(GTK_BOX(PackBoxMenu), StatusGrid, FALSE, FALSE, 0);
/// Adding box to Main Window
gtk_container_add(GTK_CONTAINER(MainWindow), PackBoxMenu);
}
//-----------------------------------------------------------------------------
// Adjust the size and visibility of the scrollbars as necessary, either due
// to a change in the size of the program or a change in the size of the
// window.
//-----------------------------------------------------------------------------
void RefreshScrollbars(void)
{
SCROLLINFO vert, horiz;
SetUpScrollbars(&NeedHoriz, &horiz, &vert);
// SetScrollInfo(HorizScrollBar, SB_CTL, &horiz, TRUE);
// SetScrollInfo(VertScrollBar, SB_CTL, &vert, TRUE);
// RECT main;
// GetClientRect(MainWindow, &main);
// if(NeedHoriz) {
// MoveWindow(HorizScrollBar, 0, IoListTop - ScrollHeight - 2,
// main.right - ScrollWidth - 2, ScrollHeight, TRUE);
// ShowWindow(HorizScrollBar, SW_SHOW);
// EnableWindow(HorizScrollBar, TRUE);
// } else {
// ShowWindow(HorizScrollBar, SW_HIDE);
// }
// MoveWindow(VertScrollBar, main.right - ScrollWidth - 2, 1, ScrollWidth,
// NeedHoriz ? (IoListTop - ScrollHeight - 4) : (IoListTop - 3), TRUE);
// MoveWindow(VertScrollBar, main.right - ScrollWidth - 2, 1, ScrollWidth,
// NeedHoriz ? (IoListTop - ScrollHeight - 4) : (IoListTop - 3), TRUE);
InvalidateRect(DrawWindow, NULL, FALSE);
}
//-----------------------------------------------------------------------------
// Respond to a WM_VSCROLL sent to the main window, presumably by the one and
// only vertical scrollbar that it has as a child.
//-----------------------------------------------------------------------------
void VscrollProc(int wParam)
{
int prevY = ScrollYOffset;
switch(wParam) {
case SB_LINEUP:
case SB_PAGEUP:
if(ScrollYOffset > 0) {
ScrollYOffset--;
}
break;
case SB_LINEDOWN:
case SB_PAGEDOWN:
if(ScrollYOffset < ScrollYOffsetMax) {
ScrollYOffset++;
}
break;
case SB_TOP:
ScrollYOffset = 0;
break;
case SB_BOTTOM:
ScrollYOffset = ScrollYOffsetMax;
break;
// case SB_THUMBTRACK:
// case SB_THUMBPOSITION:
// ScrollYOffset = HIWORD(wParam);
// break;
}
// if(prevY != ScrollYOffset) {
// SCROLLINFO si;
// si.cbSize = sizeof(si);
// si.fMask = SIF_POS;
// si.nPos = ScrollYOffset;
// SetScrollInfo(VertScrollBar, SB_CTL, &si, TRUE);
// InvalidateRect(MainWindow, NULL, FALSE);
// }
}
//-----------------------------------------------------------------------------
// Respond to a WM_HSCROLL sent to the main window, presumably by the one and
// only horizontal scrollbar that it has as a child.
//-----------------------------------------------------------------------------
void HscrollProc(int wParam)
{
int prevX = ScrollXOffset;
switch(wParam) {
case SB_LINEUP:
ScrollXOffset -= FONT_WIDTH;
break;
case SB_PAGEUP:
ScrollXOffset -= POS_WIDTH*FONT_WIDTH;
break;
case SB_LINEDOWN:
ScrollXOffset += FONT_WIDTH;
break;
case SB_PAGEDOWN:
ScrollXOffset += POS_WIDTH*FONT_WIDTH;
break;
case SB_TOP:
ScrollXOffset = 0;
break;
case SB_BOTTOM:
ScrollXOffset = ScrollXOffsetMax;
break;
// case SB_THUMBTRACK:
// case SB_THUMBPOSITION:
// ScrollXOffset = HIWORD(wParam);
// break;
}
if(ScrollXOffset > ScrollXOffsetMax) ScrollXOffset = ScrollXOffsetMax;
if(ScrollXOffset < 0) ScrollXOffset = 0;
// if(prevX != ScrollXOffset) {
// SCROLLINFO si;
// si.cbSize = sizeof(si);
// si.fMask = SIF_POS;
// si.nPos = ScrollXOffset;
// SetScrollInfo(HorizScrollBar, SB_CTL, &si, TRUE);
// InvalidateRect(MainWindow, NULL, FALSE);
// }
}
//-----------------------------------------------------------------------------
// Set up the title bar text for the main window; indicate whether we are in
// simulation or editing mode, and indicate the filename.
//-----------------------------------------------------------------------------
void UpdateMainWindowTitleBar(void)
{
char line[PATH_MAX+100];
if(InSimulationMode) {
if(RealTimeSimulationRunning) {
strcpy(line, "LDmicro - Simulation (Running)");
} else {
strcpy(line, "LDmicro - Simulation (Stopped)");
}
} else {
strcpy(line, "LDmicro - Program Editor");
}
if(strlen(CurrentSaveFile) > 0) {
sprintf(line+strlen(line), " - %s", CurrentSaveFile);
} else {
strcat(line, " - (not yet saved)");
}
gtk_window_set_title (GTK_WINDOW (MainWindow), line);
}
//-----------------------------------------------------------------------------
// Set the enabled state of the logic menu items to reflect where we are on
// the schematic (e.g. can't insert two coils in series).
//-----------------------------------------------------------------------------
void SetMenusEnabled(BOOL canNegate, BOOL canNormal, BOOL canResetOnly,
BOOL canSetOnly, BOOL canDelete, BOOL canInsertEnd, BOOL canInsertOther,
BOOL canPushDown, BOOL canPushUp, BOOL canInsertComment)
{
EnableMenuItem(EditMenu, PushRungUpMenu,
canPushUp ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(EditMenu, PushRungDownMenu,
canPushDown ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(EditMenu, DeleteRungMenu,
(Prog.numRungs > 1) ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(InstructionMenu, NegateMenu,
canNegate ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(InstructionMenu, MakeNormalMenu,
canNormal ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(InstructionMenu, MakeResetOnlyMenu,
canResetOnly ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(InstructionMenu, MakeSetOnlyMenu,
canSetOnly ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(InstructionMenu, InsertCommentMenu,
canInsertComment ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(EditMenu, DeleteElementMenu,
canDelete ? MF_ENABLED : MF_GRAYED);
int t;
t = canInsertEnd ? MF_ENABLED : MF_GRAYED;
EnableMenuItem(InstructionMenu, InsertCoilMenu, t);
EnableMenuItem(InstructionMenu, InsertResMenu, t);
EnableMenuItem(InstructionMenu, InsertMovMenu, t);
EnableMenuItem(InstructionMenu, InsertAddMenu, t);
EnableMenuItem(InstructionMenu, InsertSubMenu, t);
EnableMenuItem(InstructionMenu, InsertMulMenu, t);
EnableMenuItem(InstructionMenu, InsertDivMenu, t);
EnableMenuItem(InstructionMenu, InsertCtcMenu, t);
EnableMenuItem(InstructionMenu, InsertPersistMenu, t);
EnableMenuItem(InstructionMenu, InsertReadAdcMenu, t);
EnableMenuItem(InstructionMenu, InsertSetPwmMenu, t);
EnableMenuItem(InstructionMenu, InsertMasterRlyMenu, t);
EnableMenuItem(InstructionMenu, InsertShiftRegMenu, t);
EnableMenuItem(InstructionMenu, InsertLutMenu, t);
EnableMenuItem(InstructionMenu, InsertPwlMenu, t);
t = canInsertOther ? MF_ENABLED : MF_GRAYED;
EnableMenuItem(InstructionMenu, InsertTonMenu, t);
EnableMenuItem(InstructionMenu, InsertTofMenu, t);
EnableMenuItem(InstructionMenu, InsertOsrMenu, t);
EnableMenuItem(InstructionMenu, InsertOsfMenu, t);
EnableMenuItem(InstructionMenu, InsertRtoMenu, t);
EnableMenuItem(InstructionMenu, InsertContactsMenu, t);
EnableMenuItem(InstructionMenu, InsertCtuMenu, t);
EnableMenuItem(InstructionMenu, InsertCtdMenu, t);
EnableMenuItem(InstructionMenu, InsertEquMenu, t);
EnableMenuItem(InstructionMenu, InsertNeqMenu, t);
EnableMenuItem(InstructionMenu, InsertGrtMenu, t);
EnableMenuItem(InstructionMenu, InsertGeqMenu, t);
EnableMenuItem(InstructionMenu, InsertLesMenu, t);
EnableMenuItem(InstructionMenu, InsertLeqMenu, t);
EnableMenuItem(InstructionMenu, InsertShortMenu, t);
EnableMenuItem(InstructionMenu, InsertOpenMenu, t);
EnableMenuItem(InstructionMenu, InsertUartSendMenu, t);
EnableMenuItem(InstructionMenu, InsertUartRecvMenu, t);
EnableMenuItem(InstructionMenu, InsertFmtdStrMenu, t);
}
//-----------------------------------------------------------------------------
// Set the enabled state of the undo/redo menus.
//-----------------------------------------------------------------------------
void SetUndoEnabled(BOOL undoEnabled, BOOL redoEnabled)
{
EnableMenuItem(EditMenu, UndoMenu, undoEnabled ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(EditMenu, RedoMenu, redoEnabled ? MF_ENABLED : MF_GRAYED);
}
//-----------------------------------------------------------------------------
// Toggle whether we are in simulation mode. A lot of options are only
// available in one mode or the other.
//-----------------------------------------------------------------------------
void ToggleSimulationMode(void)
{
InSimulationMode = !InSimulationMode;
if(InSimulationMode) {
EnableMenuItem(SimulateMenu, StartSimulationMenu, MF_ENABLED);
EnableMenuItem(SimulateMenu, SingleCycleMenu, MF_ENABLED);
EnableMenuItem(FileMenu, OpenMenu, MF_GRAYED);
EnableMenuItem(FileMenu, SaveMenu, MF_GRAYED);
EnableMenuItem(FileMenu, SaveAsMenu, MF_GRAYED);
EnableMenuItem(FileMenu, NewMenu, MF_GRAYED);
EnableMenuItem(FileMenu, ExportMenu, MF_GRAYED);
EnableMenuItem(TopMenu, EditMenu, MF_GRAYED);
EnableMenuItem(TopMenu, Settings, MF_GRAYED);
EnableMenuItem(TopMenu, InstructionMenu, MF_GRAYED);
EnableMenuItem(TopMenu, Compile, MF_GRAYED);
CheckMenuItem(SimulateMenu, SimulationModeMenu, MF_CHECKED);
ClearSimulationData(); // simulation.cpp, ldmicro.h
// Recheck InSimulationMode, because there could have been a Compile
// error, which would have kicked us out of simulation mode.
if(UartFunctionUsed() && InSimulationMode) {
ShowUartSimulationWindow(); // simulate.cpp
}
}
else {
RealTimeSimulationRunning = FALSE;
KillTimer(MainWindow, TIMER_SIMULATE);
EnableMenuItem(SimulateMenu, StartSimulationMenu, MF_GRAYED);
EnableMenuItem(SimulateMenu, StopSimulationMenu, MF_GRAYED);
EnableMenuItem(SimulateMenu, SingleCycleMenu, MF_GRAYED);
EnableMenuItem(FileMenu, OpenMenu, MF_ENABLED);
EnableMenuItem(FileMenu, SaveMenu, MF_ENABLED);
EnableMenuItem(FileMenu, SaveAsMenu, MF_ENABLED);
EnableMenuItem(FileMenu, NewMenu, MF_ENABLED);
EnableMenuItem(FileMenu, ExportMenu, MF_ENABLED);
EnableMenuItem(TopMenu, EditMenu, MF_ENABLED);
EnableMenuItem(TopMenu, Settings, MF_ENABLED);
EnableMenuItem(TopMenu, InstructionMenu, MF_ENABLED);
EnableMenuItem(TopMenu, Compile, MF_ENABLED);
CheckMenuItem(SimulateMenu, SimulationModeMenu, MF_UNCHECKED);
if(UartFunctionUsed()) {
DestroyUartSimulationWindow();
}
}
UpdateMainWindowTitleBar();
RefreshControlsToSettings();
}
//-----------------------------------------------------------------------------
// Cause the status bar and the list view to be in sync with the actual data
// structures describing the settings and the I/O configuration. Listview
// does callbacks to get the strings it displays, so it just needs to know
// how many elements to populate.
//-----------------------------------------------------------------------------
void RefreshControlsToSettings(void)
{
GtkTreeIter iter;
BOOL path_not_empty = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(IoList), &iter);
// g_print("path e = %i\n", path_not_empty);
int * ip;
int i = 0;
if(!IoListOutOfSync) {
IoListSelectionPoint = -1;
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
GtkTreeModel *IoModelPtr;
if(gtk_tree_selection_get_selected (selection, &IoModelPtr, &iter))
{
GtkTreePath *path = gtk_tree_model_get_path ( IoModelPtr, &iter ) ;
ip = gtk_tree_path_get_indices ( path ) ;
i = ip[0];
IoListSelectionPoint = i;
}
}
gtk_list_store_clear (GTK_LIST_STORE(IoList));
/// Fill IO List
NMHDR h;
h.code = LVN_GETDISPINFO;
h.hlistFrom = IoList;
gtk_tree_model_get_iter_first (GTK_TREE_MODEL(IoList), &iter);
for(i = 0; i < Prog.io.count; i++) {
gtk_list_store_append (GTK_LIST_STORE(IoList), &iter);
h.item.iItem = i;
h.hlistIter = &iter;
IoListProc(&h);
}
if(IoListSelectionPoint >= 0) {
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
gtk_tree_selection_unselect_all (selection);
GtkTreePath *path = gtk_tree_path_new_from_indices ( IoListSelectionPoint, -1);
gtk_tree_selection_select_path (selection, path);
// ListView_EnsureVisible(IoList, IoListSelectionPoint, FALSE);
}
IoListOutOfSync = FALSE;
if(Prog.mcu) {
gtk_statusbar_push (GTK_STATUSBAR (StatusBar[0]),
gtk_statusbar_get_context_id (GTK_STATUSBAR (StatusBar[0]), "MCU Name"),
(gchar*)Prog.mcu->mcuName);
}
else {
gtk_statusbar_push (GTK_STATUSBAR (StatusBar[0]),
gtk_statusbar_get_context_id (GTK_STATUSBAR (StatusBar[0]), "MCU Name"),
"no MCU selected");
}
char buf[256];
sprintf(buf, _("cycle time %.2f ms"), (double)Prog.cycleTime/1000.0);
gtk_statusbar_push (GTK_STATUSBAR (StatusBar[1]),
gtk_statusbar_get_context_id (GTK_STATUSBAR (StatusBar[1]), "Cycle time"),
buf);
if(Prog.mcu && (Prog.mcu->whichIsa == ISA_ANSIC ||
Prog.mcu->whichIsa == ISA_INTERPRETED))
{
strcpy(buf, "");
} else {
sprintf(buf, _("processor clock %.4f MHz"),
(double)Prog.mcuClock/1000000.0);
}
gtk_statusbar_push (GTK_STATUSBAR (StatusBar[2]),
gtk_statusbar_get_context_id (GTK_STATUSBAR (StatusBar[2]), "Processor time"),
buf);
for(i = 0; i < NUM_SUPPORTED_MCUS; i++) {
if(&SupportedMcus[i] == Prog.mcu) {
CheckMenuItem(ProcessorMenu, ProcessorMenuItems[i], MF_CHECKED);
}
else {
CheckMenuItem(ProcessorMenu, ProcessorMenuItems[i], MF_UNCHECKED);
}
}
// `(no microcontroller)' setting
if (!Prog.mcu){
CheckMenuItem(ProcessorMenu, ProcessorMenuItems[NUM_SUPPORTED_MCUS], MF_CHECKED);
}
else {
CheckMenuItem(ProcessorMenu, ProcessorMenuItems[NUM_SUPPORTED_MCUS], MF_UNCHECKED);
}
}
//-----------------------------------------------------------------------------
// Regenerate the I/O list, keeping the selection in the same place if
// possible.
//-----------------------------------------------------------------------------
void GenerateIoListDontLoseSelection(void)
{
GtkTreeIter iter;
BOOL path_not_empty = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(IoList), &iter);
// g_print("path e = %i\n", path_not_empty);
int * i ;
IoListSelectionPoint = -1;
// GtkTreeSelection * tsel = gtk_tree_view_get_selection (tv);
// GtkTreeModel * tm ;
GtkTreePath * path ;
GtkTreeModel *IoModelPtr;
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
if(gtk_tree_selection_get_selected (selection, &IoModelPtr, &iter))
{
path = gtk_tree_model_get_path ( IoModelPtr , &iter ) ;
i = gtk_tree_path_get_indices ( path ) ;
IoListSelectionPoint = i[0];
}
// gtk_tree_model_iter_next (GTK_TREE_MODEL(IoList), iter);
// BOOL iter_v = gtk_list_store_iter_is_valid(GTK_LIST_STORE(IoList), iter);
// g_print("iter = %i\n", iter_v);
// if ( gtk_tree_selection_get_selected ( tsel , &tm , &iter ) )
// {
// return i [ 0 ] ;
// }
IoListSelectionPoint = GenerateIoList(IoListSelectionPoint);
// can't just update the listview index; if I/O has been added then the
// new selection point might be out of range till we refill it
IoListOutOfSync = TRUE;
RefreshControlsToSettings();
}
//-----------------------------------------------------------------------------
// Called when the main window has been resized. Adjust the size of the
// status bar and the listview to reflect the new window size.
//-----------------------------------------------------------------------------
void MainWindowResized(void)
{
RECT main;
GetClientRect(DrawWindow, &main);
RECT status;
// GetWindowRect(StatusBar, &status);
// int statusHeight = status.bottom - status.top;
// MoveWindow(StatusBar, 0, main.bottom - statusHeight, main.right,
// statusHeight, TRUE);
// Make sure that the I/O list can't disappear entirely.
if(IoListHeight < 30) {
IoListHeight = 30;
}
IoListTop = main.bottom ;//- IoListHeight - statusHeight;
// Make sure that we can't drag the top of the I/O list above the
// bottom of the menu bar, because it then becomes inaccessible.
if(IoListTop < 5) {
IoListHeight = main.bottom - 5;//- statusHeight - 5;
IoListTop = main.bottom - IoListHeight;// - statusHeight;
}
// MoveWindow(IoList, 0, IoListTop, main.right, IoListHeight, TRUE);
RefreshScrollbars();
InvalidateRect(DrawWindow, NULL, FALSE);
}
//-----------------------------------------------------------------------------
// Start real-time simulation. Have to update the controls grayed status
// to reflect this.
//-----------------------------------------------------------------------------
void StartSimulation(void)
{
RealTimeSimulationRunning = TRUE;
EnableMenuItem(SimulateMenu, StartSimulationMenu, MF_GRAYED);
EnableMenuItem(SimulateMenu, StopSimulationMenu, MF_ENABLED);
StartSimulationTimer();
UpdateMainWindowTitleBar();
}
//-----------------------------------------------------------------------------
// Stop real-time simulation. Have to update the controls grayed status
// to reflect this.
//-----------------------------------------------------------------------------
void StopSimulation(void)
{
RealTimeSimulationRunning = FALSE;
EnableMenuItem(SimulateMenu, StartSimulationMenu, MF_ENABLED);
EnableMenuItem(SimulateMenu, StopSimulationMenu, MF_GRAYED);
KillTimer(MainWindow, TIMER_SIMULATE);
UpdateMainWindowTitleBar();
}
|