forked from Paris/IronAHK
/
Gui.cs
2011 lines (1691 loc) · 83.2 KB
/
Gui.cs
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace IronAHK.Rusty
{
partial class Core
{
// TODO: organise Gui.cs
/// <summary>
/// Creates and manages windows and controls.
/// </summary>
/// <param name="Command">
/// <list type="bullet">
/// <item><term>Add</term>: <description>creates controls.</description></item>
/// <item><term>Show</term>: <description>display or move the window.</description></item>
/// <item><term>Submit</term>: <description>saves user input.</description></item>
/// <item><term>Hide</term>: <description>hides the window.</description></item>
/// <item><term>Destroy</term>: <description>deletes the window.</description></item>
/// <item><term>Font</term>: <description>sets the default font style for subsequently created controls.</description></item>
/// <item><term>Color</term>: <description>sets the color for the window or controls.</description></item>
/// <item><term>Margin</term>: <description>sets the spacing used between the edges of the window and controls when an absolute position is unspecified.</description></item>
/// <item><term>Options</term>: <description>sets various options for the appearance and behaviour of the window.</description></item>
/// <item><term>Menu</term>: <description>associates a menu bar with the window.</description></item>
/// <item><term>Minimize/Maximize/Restore</term>: <description>performs the indicated operation on the window.</description></item>
/// <item><term>Flash</term>: <description>blinks the window in the task bar.</description></item>
/// <item><term>Default</term>: <description>changes the default window on the current thread.</description></item>
/// </list>
/// </param>
/// <param name="Param2"></param>
/// <param name="Param3"></param>
/// <param name="Param4"></param>
public static void Gui(string Command, string Param2, string Param3, string Param4)
{
if (guis == null)
guis = new Dictionary<string, Form>();
string id = GuiId(ref Command);
if (!guis.ContainsKey(id))
guis.Add(id, GuiCreateWindow(id));
switch (Command.ToLowerInvariant())
{
#region Add
case Keyword_Add:
{
Control control = null;
GuiControlEdit(ref control, guis[id], Param2, Param3, Param4);
GuiAssociatedInfo(control).LastControl = control;
}
break;
#endregion
#region Show
case Keyword_Show:
{
bool center = false, cX = false, cY = false, auto = false, min = false, max = false, restore = false, hide = false;
int?[] pos = { null, null, null, null };
foreach (var option in ParseOptions(Param2))
{
string mode = option.ToLowerInvariant();
int select = -1;
switch (mode[0])
{
case 'w': select = 0; break;
case 'h': select = 1; break;
case 'x': select = 2; break;
case 'y': select = 3; break;
}
if (select == -1)
{
switch (mode)
{
case Keyword_Center: center = true; break;
case Keyword_AutoSize: auto = true; break;
case Keyword_Maximize: max = true; break;
case Keyword_Minimize: min = true; break;
case Keyword_Restore: restore = true; break;
case Keyword_NoActivate: break;
case Keyword_NA: break;
case Keyword_Hide: hide = true; break;
}
}
else
{
mode = mode.Substring(1);
int n;
if (mode.Equals(Keyword_Center, StringComparison.OrdinalIgnoreCase))
{
if (select == 2)
cX = true;
else
cY = true;
}
else if (mode.Length != 0 && int.TryParse(mode, out n))
pos[select] = n;
}
}
if (auto || pos[0] == null && pos[1] == null)
{
guis[id].Size = guis[id].PreferredSize;
var status = GuiAssociatedInfo(guis[id]).StatusBar;
int d = status == null ? 0 : status.Height;
if (d > 0)
guis[id].ClientSize = new Size(guis[id].ClientSize.Width, guis[id].ClientSize.Height + d);
}
else
{
var size = guis[id].PreferredSize;
if (pos[0] != null)
size.Width = (int)pos[0];
if (pos[1] != null)
size.Height = (int)pos[1];
guis[id].ClientSize = size;
}
var location = new Point();
if (pos[2] != null)
location.X = (int)pos[2];
if (pos[3] != null)
location.Y = (int)pos[3];
var screen = Screen.PrimaryScreen.Bounds;
if (location == null)
center = true;
if (center)
cX = cY = true;
if (cX)
location.X = (screen.Width - guis[id].Size.Width) / 2 + screen.X;
if (cY)
location.Y = (screen.Height - guis[id].Size.Height) / 2 + screen.Y;
guis[id].StartPosition = FormStartPosition.Manual;
guis[id].Location = location;
guis[id].Text = Param3;
if (min)
guis[id].WindowState = FormWindowState.Minimized;
else if (max)
guis[id].WindowState = FormWindowState.Maximized;
else if (restore)
guis[id].WindowState = FormWindowState.Normal;
else if (hide)
guis[id].Hide();
else
guis[id].Show();
guis[id].ResumeLayout(true);
}
break;
#endregion
#region Misc.
case Keyword_Submit:
{
if (!Keyword_NoHide.Equals(Param2, StringComparison.OrdinalIgnoreCase))
guis[id].Hide();
// TODO: way to return multipart variable (A_LastResult?) for Gui,Submit and GuiControlGet,,Pos
}
break;
case Keyword_Cancel:
case Keyword_Hide:
guis[id].Hide();
break;
case Keyword_Destroy:
guis[id].Hide();
guis[id].Dispose();
guis.Remove(id);
break;
case Keyword_Font:
GuiAssociatedInfo(guis[id]).Font = string.IsNullOrEmpty(Param2) && string.IsNullOrEmpty(Param3) ?
guis[id].Font : ParseFont(GuiAssociatedInfo(guis[id]).Font, Param2, Param3);
break;
case Keyword_Color:
guis[id].BackColor = Keyword_Default.Equals(Param2, StringComparison.OrdinalIgnoreCase) ? Color.Transparent : ParseColor(Param2);
break;
case Keyword_Margin:
{
int d, x = guis[id].Margin.Left, y = guis[id].Margin.Top;
if (int.TryParse(Param2, out d))
x = d;
if (int.TryParse(Param3, out d))
y = d;
guis[id].Margin = new Padding(x, y, x, y);
}
break;
case Keyword_Menu:
break;
case Keyword_Minimize:
guis[id].WindowState = FormWindowState.Minimized;
break;
case Keyword_Maximize:
guis[id].WindowState = FormWindowState.Maximized;
break;
case Keyword_Restore:
guis[id].WindowState = FormWindowState.Normal;
break;
case Keyword_Flash:
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
WindowsAPI.FlashWindow(guis[id].Handle, OnOff(Param2) ?? true);
break;
case Keyword_Default:
DefaultGuiId = id;
break;
case Keyword_TreeView:
{
var tree = GuiFindControl(Param2, guis[id]);
if (tree == null || !typeof(TreeView).IsAssignableFrom(tree.GetType()))
DefaultTreeView = null;
else
DefaultTreeView = (TreeView)tree;
}
break;
case Keyword_ListView:
{
var list = GuiFindControl(Param2, guis[id]);
if (list == null || !typeof(ListView).IsAssignableFrom(list.GetType()))
DefaultListView = null;
else
DefaultListView = (ListView)list;
}
break;
#endregion
#region Options
default:
{
foreach (var option in ParseOptions(Command))
{
bool on = option[0] != '-';
string mode = option;
if (mode[0] == '+' || mode[0] == '-')
mode = mode.Substring(1);
if (mode.Length == 0)
continue;
mode = mode.ToLowerInvariant();
switch (mode)
{
case Keyword_AlwaysOnTop: guis[id].TopMost = on; break;
case Keyword_Border: break;
case Keyword_Caption: break;
case Keyword_Disabled: guis[id].Enabled = !on; break;
case Keyword_LastFound: lastFoundForm = guis[id].Handle.ToInt64(); break;
case Keyword_LastFoundExist: lastFoundForm = guis[id].Handle.ToInt64(); break;
case Keyword_MaximizeBox: guis[id].MaximizeBox = on; break;
case Keyword_MinimizeBox: guis[id].MinimizeBox = on; break;
case Keyword_OwnDialogs: dialogOwner = guis[id]; break;
case Keyword_Owner: break;
case Keyword_Resize: break;
case Keyword_SysMenu: guis[id].ControlBox = on; break;
case Keyword_Theme: Application.EnableVisualStyles(); break;
case Keyword_ToolWindow: break;
case Keyword_Redraw: guis[id].Refresh(); break;
case Keyword_Cursor:
{
switch (Param2.ToLowerInvariant())
{
case "cross": guis[id].Cursor = Cursors.Cross; break;
case "hand": guis[id].Cursor = Cursors.Hand; break;
case "help": guis[id].Cursor = Cursors.Help; break;
case "beam": guis[id].Cursor = Cursors.IBeam; break;
case "no": guis[id].Cursor = Cursors.No; break;
case "wait": guis[id].Cursor = Cursors.WaitCursor; break;
case "nomove": guis[id].Cursor = Cursors.NoMove2D; break;
case "size": guis[id].Cursor = Cursors.SizeAll; break;
case "split":
{
if (Param3.ToLowerInvariant() == Keyword_Vertical)
guis[id].Cursor = Cursors.VSplit;
else
guis[id].Cursor = Cursors.HSplit;
break;
}
case "pan":
{
switch (Param3.ToLowerInvariant())
{
case "east":
case "e": guis[id].Cursor = Cursors.PanEast; break;
case "south":
case "s": guis[id].Cursor = Cursors.PanSouth; break;
case "west":
case "w": guis[id].Cursor = Cursors.PanWest; break;
default:
case "north":
case "n": guis[id].Cursor = Cursors.PanNorth; break;
}
break;
}
case "arrow":
default: guis[id].Cursor = Cursors.Arrow; break;
}
break;
}
case Keyword_Icon:
{
if (Param2 != string.Empty)
{
if (File.Exists(Param2))
if (Path.GetExtension(Param2.ToLowerInvariant())==".ico")
guis[id].Icon = new Icon(Param2);
}
guis[id].ShowIcon = on;
break;
}
case Keyword_TaskBar:
{
guis[id].ShowInTaskbar = on;
break;
}
case Keyword_BackGroundImage:
{
if (on)
{
if (File.Exists(Param2))
{
guis[id].BackgroundImage = new Bitmap(Param2);
switch (Param3.ToLowerInvariant())
{
case Keyword_None: guis[id].BackgroundImageLayout = ImageLayout.None; break;
case Keyword_Tile: guis[id].BackgroundImageLayout = ImageLayout.Tile; break;
case Keyword_Center: guis[id].BackgroundImageLayout = ImageLayout.Center; break;
case Keyword_Zoom: guis[id].BackgroundImageLayout = ImageLayout.Zoom; break;
case Keyword_Stretch:
default: guis[id].BackgroundImageLayout = ImageLayout.Stretch; break;
}
}
}
else
{
guis[id].BackgroundImage = null;
}
break;
}
default:
string arg;
string[] parts;
int n;
Size size;
if (mode.StartsWith(Keyword_Delimiter))
{
arg = mode.Substring(Keyword_Delimiter.Length);
if (arg.Length > 0)
GuiAssociatedInfo(guis[id]).Delimiter = arg[0];
}
else if (mode.StartsWith(Keyword_Label))
{
arg = mode.Substring(Keyword_Label.Length);
if (arg.Length > 0)
guis[id].Name = arg;
}
else if (mode.StartsWith(Keyword_MinSize))
{
arg = mode.Substring(Keyword_MinSize.Length);
parts = arg.Split(new[] { 'x', 'X', '*' }, 2);
size = guis[id].MinimumSize;
if (parts.Length > 0 && int.TryParse(parts[0], out n))
size.Width = n;
if (parts.Length > 1 && int.TryParse(parts[1], out n))
size.Height = n;
guis[id].MinimumSize = size;
}
else if (mode.StartsWith(Keyword_MaxSize))
{
arg = mode.Substring(Keyword_MaxSize.Length);
parts = arg.Split(new[] { 'x', 'X', '*' }, 2);
size = guis[id].MaximumSize;
if (parts.Length > 0 && int.TryParse(parts[0], out n))
size.Width = n;
if (parts.Length > 1 && int.TryParse(parts[1], out n))
size.Height = n;
guis[id].MaximumSize = size;
}
break;
}
}
}
break;
#endregion
}
}
#region Helpers
static void GuiControlEdit(ref Control control, Form parent, string type, string options, string content)
{
string opts = null;
switch (type.ToLowerInvariant())
{
#region Text
case Keyword_Text:
{
var text = (Label)(control ?? new Label());
parent.Controls.Add(text);
control = text;
text.Text = content;
}
break;
#endregion
#region Edit
case Keyword_Edit:
{
var edit = (TextBox)(control ?? new TextBox());
parent.Controls.Add(edit);
control = edit;
edit.Text = NormaliseEol(content);
edit.Tag = options;
opts = GuiApplyStyles(edit, options);
foreach (var opt in ParseOptions(opts))
{
bool on = opt[0] != '-';
string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
switch (mode)
{
case Keyword_Limit:
if (!on)
edit.MaxLength = int.MaxValue;
break;
case Keyword_Lowercase: edit.CharacterCasing = on ? CharacterCasing.Lower : CharacterCasing.Normal; break;
case Keyword_Multi: edit.Multiline = on; break;
case Keyword_Number:
{
if (on)
edit.KeyPress += new System.Windows.Forms.KeyPressEventHandler(Edit_Number);
else
edit.KeyPress -= new System.Windows.Forms.KeyPressEventHandler(Edit_Number);
break;
}
case Keyword_Password: edit.PasswordChar = '●'; break;
case Keyword_Readonly: edit.ReadOnly = on; break;
case Keyword_Uppercase: edit.CharacterCasing = on ? CharacterCasing.Upper : CharacterCasing.Normal; break;
case Keyword_WantCtrlA: break; //I dont see that the normal ctrl+A works! perhaps new implementation?
case Keyword_WantReturn: edit.AcceptsReturn = on; break;
case Keyword_WantTab: edit.AcceptsTab = on; break;
case Keyword_Wrap: edit.WordWrap = on; break;
default:
int n;
if (mode.StartsWith(Keyword_Limit) && int.TryParse(mode.Substring(Keyword_Limit.Length), out n))
edit.MaxLength = n;
break;
}
}
}
break;
#endregion
#region UpDown
case Keyword_UpDown:
{
var updown = (NumericUpDown)(control ?? new NumericUpDown());
var last = GuiAssociatedInfo(parent).LastControl;
if (last != null && last is TextBox)
{
updown.Location = last.Location;
updown.Size = last.Size;
updown.Font = last.Font;
updown.ForeColor = last.ForeColor;
last.Parent.Controls.Remove(last);
GuiAssociatedInfo(parent).Controls.Pop();
options = string.Concat(last.Tag as string ?? string.Empty, " ", options);
}
parent.Controls.Add(updown);
control = updown;
updown.Value = decimal.Parse(content);
opts = GuiApplyStyles(updown, options);
foreach (var opt in ParseOptions(opts))
{
bool on = opt[0] != '-';
string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
switch (mode)
{
case Keyword_Horz: break;
case Keyword_Left: break;
case Keyword_Wrap: break;
case "16": break;
case "0x80": break;
default:
if (mode.StartsWith(Keyword_Range))
{
string[] range = mode.Substring(Keyword_Range.Length).Split(new[] { '-' }, 2);
decimal n;
if (decimal.TryParse(range[0], out n))
updown.Minimum = n;
if (range.Length > 1 && decimal.TryParse(range[1], out n))
updown.Maximum = n;
}
break;
}
}
}
break;
#endregion
#region Picture
case Keyword_Picture:
case Keyword_Pic:
{
var pic = (PictureBox)(control ?? new PictureBox());
parent.Controls.Add(pic);
control = pic;
bool exists = File.Exists(content);
if (exists)
{
pic.ImageLocation = content;
try
{
var image = Image.FromFile(pic.ImageLocation);
pic.Size = image.Size;
}
catch (Exception) { }
}
GuiApplyStyles(pic, options);
}
break;
#endregion
#region Button
case Keyword_Button:
{
var button = (Button)(control ?? new Button());
parent.Controls.Add(button);
control = button;
button.Text = content;
}
break;
#endregion
#region CheckBox
case Keyword_CheckBox:
{
var check = (CheckBox)(control ?? new CheckBox());
parent.Controls.Add(check);
control = check;
check.Text = content;
opts = GuiApplyStyles(check, options);
foreach (var opt in ParseOptions(opts))
{
switch (opt.ToLowerInvariant())
{
case Keyword_Check3:
case Keyword_CheckedGray:
check.CheckState = CheckState.Indeterminate;
break;
case Keyword_Checked:
check.CheckState = CheckState.Checked;
break;
default:
if (opt.StartsWith(Keyword_Checked, StringComparison.OrdinalIgnoreCase))
{
string arg = opt.Substring(Keyword_Checked.Length).Trim();
int n;
if (int.TryParse(arg, out n))
check.CheckState = n == -1 ? CheckState.Indeterminate : n == 1 ? CheckState.Checked : CheckState.Unchecked;
}
break;
}
}
}
break;
#endregion
#region Radio
case Keyword_Radio:
{
var radio = (RadioButton)(control ?? new RadioButton());
parent.Controls.Add(radio);
control = radio;
radio.Text = content;
radio.Checked = false;
opts = GuiApplyStyles(radio, options);
foreach (var opt in ParseOptions(opts))
{
switch (opt.ToLowerInvariant())
{
case Keyword_Checked:
radio.Checked = true;
break;
default:
if (opt.StartsWith(Keyword_Checked, StringComparison.OrdinalIgnoreCase))
{
string arg = opt.Substring(Keyword_Checked.Length).Trim();
int n;
if (int.TryParse(arg, out n))
radio.Checked = n == 1;
}
break;
}
}
}
break;
#endregion
#region DropDownList
case Keyword_DropDownList:
case Keyword_DDL:
{
var ddl = (ComboBox)(control ?? new ComboBox());
parent.Controls.Add(ddl);
control = ddl;
ddl.Text = content;
ddl.DropDownStyle = ComboBoxStyle.DropDownList;
opts = GuiApplyStyles(ddl, options);
int select;
bool clear;
ddl.Items.AddRange(GuiParseList(ddl, out select, out clear));
if (select > -1 && select < ddl.Items.Count)
ddl.SelectedIndex = select;
foreach (var opt in ParseOptions(opts))
{
bool on = opt[0] != '-';
string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
switch (mode)
{
case Keyword_Sort: ddl.Sorted = on; break;
case Keyword_Uppercase: ddl.Text = ddl.Text.ToUpperInvariant(); break;
case Keyword_Lowercase: ddl.Text = ddl.Text.ToLowerInvariant(); break;
default:
if (mode.StartsWith(Keyword_Choose, StringComparison.OrdinalIgnoreCase))
{
mode = mode.Substring(Keyword_Choose.Length);
int n;
if (int.TryParse(mode, out n) && n > -1 && n < ddl.Items.Count)
ddl.SelectedIndex = n;
}
break;
}
}
}
break;
#endregion
#region ComboBox
case Keyword_ComboBox:
{
var combo = (ComboBox)(control ?? new ComboBox());
parent.Controls.Add(combo);
control = combo;
combo.Text = content;
opts = GuiApplyStyles(combo, options);
int select;
bool clear;
combo.Items.AddRange(GuiParseList(combo, out select, out clear));
if (select > -1 && select < combo.Items.Count)
combo.SelectedIndex = select;
foreach (var opt in ParseOptions(opts))
{
bool on = opt[0] != '-';
string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
switch (mode)
{
case Keyword_Limit: break;
case Keyword_Simple: break;
}
}
}
break;
#endregion
#region ListBox
case Keyword_ListBox:
{
var listbox = new ListBox();
parent.Controls.Add(listbox);
control = listbox;
listbox.Text = content;
opts = GuiApplyStyles(listbox, options);
int select;
bool clear;
listbox.Items.AddRange(GuiParseList(listbox, out select, out clear));
if (select > -1 && select < listbox.Items.Count)
listbox.SelectedIndex = select;
bool multi = false, read = false;
foreach (var opt in ParseOptions(opts))
{
bool on = opt[0] != '-';
string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
switch (mode)
{
case Keyword_Multi:
case "8":
multi = on;
break;
case Keyword_Readonly: read = on; break;
case Keyword_Sort: listbox.Sorted = on; break;
default:
if (mode.StartsWith(Keyword_Choose, StringComparison.OrdinalIgnoreCase))
{
mode = mode.Substring(Keyword_Choose.Length);
int n;
if (int.TryParse(mode, out n) && n > -1 && n < listbox.Items.Count)
listbox.SelectedIndex = n;
}
break;
}
}
listbox.SelectionMode = multi ? SelectionMode.MultiExtended : read ? SelectionMode.None : SelectionMode.One;
}
break;
#endregion
#region ListView
case Keyword_ListView:
{
var lv = (ListView)(control ?? new ListView());
parent.Controls.Add(lv);
control = lv;
lv.Text = content;
opts = GuiApplyStyles(lv, options);
lv.View = View.Details;
int select;
bool clear;
foreach (var item in GuiParseList(lv, out select, out clear))
lv.Columns.Add(new ColumnHeader { Text = item });
foreach (var opt in ParseOptions(opts))
{
bool on = opt[0] != '-';
string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
switch (mode)
{
case Keyword_Checked: lv.CheckBoxes = on; break;
case Keyword_Grid: lv.GridLines = on; break;
case Keyword_Hdr: break;
case "lv0x10": break;
case "lv0x20": break;
case Keyword_Multi: lv.MultiSelect = on; break;
case Keyword_NoSortHdr: break;
case Keyword_Readonly: break;
case Keyword_Sort: lv.Sorting = on ? SortOrder.Ascending : SortOrder.None; break;
case Keyword_SortDesc: lv.Sorting = on ? SortOrder.Descending : SortOrder.None; break;
case Keyword_WantF2: break;
}
}
}
break;
#endregion
#region TreeView
case Keyword_TreeView:
{
var tree = (TreeView)(control ?? new TreeView());
parent.Controls.Add(tree);
control = tree;
opts = GuiApplyStyles(tree, options);
foreach (var opt in ParseOptions(opts))
{
bool on = opt[0] != '-';
string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
switch (mode)
{
case Keyword_Buttons: break;
case Keyword_HScroll: break;
case Keyword_Lines: break;
case Keyword_Readonly: break;
case Keyword_WantF2: break;
default:
if (mode.StartsWith(Keyword_ImageList))
{
mode = mode.Substring(Keyword_ImageList.Length);
// UNDONE: TreeView control ImageList
}
break;
}
}
}
break;
#endregion
#region Hotkey
case Keyword_Hotkey:
{
var hotkey = (HotkeyBox)(control ?? new HotkeyBox());
parent.Controls.Add(hotkey);
control = hotkey;
opts = GuiApplyStyles(hotkey, options);
foreach (var opt in ParseOptions(opts))
{
bool on = opt[0] != '-';
string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
switch (mode)
{
case Keyword_Limit:
if (!on)
hotkey.Limit = HotkeyBox.Limits.None;
else
{
int n;
if (int.TryParse(mode, out n))
hotkey.Limit = (HotkeyBox.Limits)n;
}
break;
}
}
}
break;
#endregion
#region DateTime
case Keyword_DateTime:
{
var date = (DateTimePicker)(control ?? new DateTimePicker());
parent.Controls.Add(date);
control = date;
opts = GuiApplyStyles(date, options);
if (content == string.Empty)
date.Value = DateTime.Now;
else
date.Value = ToDateTime(content);
date.Format = DateTimePickerFormat.Short;
foreach (var opt in ParseOptions(opts))
{
bool on = opt[0] != '-';
string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
switch (mode)
{
case "1": date.ShowUpDown = on; break;
case "2": date.ShowCheckBox = on; break;
case Keyword_Right: date.DropDownAlign = LeftRightAlignment.Right; break; //***Bug*** - case dont match!
case Keyword_LongDate: date.Format = DateTimePickerFormat.Long; date.Value = DateTime.Now; break;
case Keyword_Time: date.Format = DateTimePickerFormat.Time; date.Value = DateTime.Now; break;
default:
if (mode.StartsWith(Keyword_Range))
{
string[] range = mode.Substring(Keyword_Range.Length).Split(new[] { '-' }, 2);
if (range[0].Length != 0)
date.MinDate = ToDateTime(range[0]);
if (range.Length > 0 && range[1].Length != 0)
date.MaxDate = ToDateTime(range[1]);
}
else if (mode.StartsWith(Keyword_Choose))
{
mode = mode.Substring(Keyword_Choose.Length);
if (mode.Length != 0)
date.Value = ToDateTime(mode);
}
break;
}
}
}
break;
#endregion
#region MonthCal
case Keyword_MonthCal:
{
var cal = (MonthCalendar)(control ?? new MonthCalendar());
parent.Controls.Add(cal);
control = cal;
opts = GuiApplyStyles(cal, options);
if (!string.IsNullOrEmpty(content))
cal.SetDate(ToDateTime(content));
foreach (var opt in ParseOptions(opts))
{
bool on = opt[0] != '-';
string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
switch (mode)
{
case "4": cal.ShowWeekNumbers = on; break;
case "8": cal.ShowTodayCircle = on; break;
case "16": cal.ShowToday = on; break;
case Keyword_Multi: cal.MaxSelectionCount = int.MaxValue; break;
default:
if (mode.StartsWith(Keyword_Range, StringComparison.OrdinalIgnoreCase))
{
string[] range = mode.Substring(Keyword_Range.Length).Split(new[] { '-' }, 2);
if (!string.IsNullOrEmpty(range[0]))
cal.MinDate = ToDateTime(range[0]);
if (range.Length > 1 && !string.IsNullOrEmpty(range[1]))
cal.MaxDate = ToDateTime(range[1]);
}
break;
}
}
}
break;
#endregion
#region Slider
case Keyword_Slider:
{