PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/Rusty/Core/Gui/Gui.cs

http://github.com/polyethene/IronAHK
C# | 2007 lines | 1634 code | 327 blank | 46 comment | 442 complexity | ec3dc8a92590f112873d2ae330b6e0d8 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.IO;
  5. using System.Windows.Forms;
  6. namespace IronAHK.Rusty
  7. {
  8. partial class Core
  9. {
  10. // TODO: organise Gui.cs
  11. /// <summary>
  12. /// Creates and manages windows and controls.
  13. /// </summary>
  14. /// <param name="Command">
  15. /// <list type="bullet">
  16. /// <item><term>Add</term>: <description>creates controls.</description></item>
  17. /// <item><term>Show</term>: <description>display or move the window.</description></item>
  18. /// <item><term>Submit</term>: <description>saves user input.</description></item>
  19. /// <item><term>Hide</term>: <description>hides the window.</description></item>
  20. /// <item><term>Destroy</term>: <description>deletes the window.</description></item>
  21. /// <item><term>Font</term>: <description>sets the default font style for subsequently created controls.</description></item>
  22. /// <item><term>Color</term>: <description>sets the color for the window or controls.</description></item>
  23. /// <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>
  24. /// <item><term>Options</term>: <description>sets various options for the appearance and behaviour of the window.</description></item>
  25. /// <item><term>Menu</term>: <description>associates a menu bar with the window.</description></item>
  26. /// <item><term>Minimize/Maximize/Restore</term>: <description>performs the indicated operation on the window.</description></item>
  27. /// <item><term>Flash</term>: <description>blinks the window in the task bar.</description></item>
  28. /// <item><term>Default</term>: <description>changes the default window on the current thread.</description></item>
  29. /// </list>
  30. /// </param>
  31. /// <param name="Param2"></param>
  32. /// <param name="Param3"></param>
  33. /// <param name="Param4"></param>
  34. public static void Gui(string Command, string Param2, string Param3, string Param4)
  35. {
  36. if (guis == null)
  37. guis = new Dictionary<string, Form>();
  38. string id = GuiId(ref Command);
  39. if (!guis.ContainsKey(id))
  40. guis.Add(id, GuiCreateWindow(id));
  41. switch (Command.ToLowerInvariant())
  42. {
  43. #region Add
  44. case Keyword_Add:
  45. {
  46. Control control = null;
  47. GuiControlEdit(ref control, guis[id], Param2, Param3, Param4);
  48. GuiAssociatedInfo(control).LastControl = control;
  49. }
  50. break;
  51. #endregion
  52. #region Show
  53. case Keyword_Show:
  54. {
  55. bool center = false, cX = false, cY = false, auto = false, min = false, max = false, restore = false, hide = false;
  56. int?[] pos = { null, null, null, null };
  57. foreach (var option in ParseOptions(Param2))
  58. {
  59. string mode = option.ToLowerInvariant();
  60. int select = -1;
  61. switch (mode[0])
  62. {
  63. case 'w': select = 0; break;
  64. case 'h': select = 1; break;
  65. case 'x': select = 2; break;
  66. case 'y': select = 3; break;
  67. }
  68. if (select == -1)
  69. {
  70. switch (mode)
  71. {
  72. case Keyword_Center: center = true; break;
  73. case Keyword_AutoSize: auto = true; break;
  74. case Keyword_Maximize: max = true; break;
  75. case Keyword_Minimize: min = true; break;
  76. case Keyword_Restore: restore = true; break;
  77. case Keyword_NoActivate: break;
  78. case Keyword_NA: break;
  79. case Keyword_Hide: hide = true; break;
  80. }
  81. }
  82. else
  83. {
  84. mode = mode.Substring(1);
  85. int n;
  86. if (mode.Equals(Keyword_Center, StringComparison.OrdinalIgnoreCase))
  87. {
  88. if (select == 2)
  89. cX = true;
  90. else
  91. cY = true;
  92. }
  93. else if (mode.Length != 0 && int.TryParse(mode, out n))
  94. pos[select] = n;
  95. }
  96. }
  97. if (auto || pos[0] == null && pos[1] == null)
  98. {
  99. guis[id].Size = guis[id].PreferredSize;
  100. var status = GuiAssociatedInfo(guis[id]).StatusBar;
  101. int d = status == null ? 0 : status.Height;
  102. if (d > 0)
  103. guis[id].ClientSize = new Size(guis[id].ClientSize.Width, guis[id].ClientSize.Height + d);
  104. }
  105. else
  106. {
  107. var size = guis[id].PreferredSize;
  108. if (pos[0] != null)
  109. size.Width = (int)pos[0];
  110. if (pos[1] != null)
  111. size.Height = (int)pos[1];
  112. guis[id].ClientSize = size;
  113. }
  114. var location = new Point();
  115. if (pos[2] != null)
  116. location.X = (int)pos[2];
  117. if (pos[3] != null)
  118. location.Y = (int)pos[3];
  119. var screen = Screen.PrimaryScreen.Bounds;
  120. if (location == null)
  121. center = true;
  122. if (center)
  123. cX = cY = true;
  124. if (cX)
  125. location.X = (screen.Width - guis[id].Size.Width) / 2 + screen.X;
  126. if (cY)
  127. location.Y = (screen.Height - guis[id].Size.Height) / 2 + screen.Y;
  128. guis[id].StartPosition = FormStartPosition.Manual;
  129. guis[id].Location = location;
  130. guis[id].Text = Param3;
  131. if (hide)
  132. guis[id].Hide();
  133. else
  134. guis[id].Show();
  135. guis[id].ResumeLayout(true);
  136. if (min)
  137. guis[id].WindowState = FormWindowState.Minimized;
  138. else if (max)
  139. guis[id].WindowState = FormWindowState.Maximized;
  140. else if (restore)
  141. guis[id].WindowState = FormWindowState.Normal;
  142. }
  143. break;
  144. #endregion
  145. #region Misc.
  146. case Keyword_Submit:
  147. {
  148. if (!Keyword_NoHide.Equals(Param2, StringComparison.OrdinalIgnoreCase))
  149. guis[id].Hide();
  150. // TODO: way to return multipart variable (A_LastResult?) for Gui,Submit and GuiControlGet,,Pos
  151. }
  152. break;
  153. case Keyword_Cancel:
  154. case Keyword_Hide:
  155. guis[id].Hide();
  156. break;
  157. case Keyword_Destroy:
  158. guis[id].Hide();
  159. guis[id].Dispose();
  160. guis.Remove(id);
  161. break;
  162. case Keyword_Font:
  163. GuiAssociatedInfo(guis[id]).Font = string.IsNullOrEmpty(Param2) && string.IsNullOrEmpty(Param3) ?
  164. guis[id].Font : ParseFont(GuiAssociatedInfo(guis[id]).Font, Param2, Param3);
  165. break;
  166. case Keyword_Color:
  167. Color c;
  168. if(Keyword_Default.Equals(Param2, StringComparison.OrdinalIgnoreCase))
  169. c = Color.LightGray; //TODO: Use correctly Control color, BUT NOT Transparent.
  170. else
  171. c = ParseColor(Param2);
  172. if(c.A == 0xFF)
  173. guis[id].BackColor = c;
  174. break;
  175. case Keyword_Margin:
  176. {
  177. int d, x = guis[id].Margin.Left, y = guis[id].Margin.Top;
  178. if (int.TryParse(Param2, out d))
  179. x = d;
  180. if (int.TryParse(Param3, out d))
  181. y = d;
  182. guis[id].Margin = new Padding(x, y, x, y);
  183. }
  184. break;
  185. case Keyword_Menu:
  186. break;
  187. case Keyword_Minimize:
  188. guis[id].WindowState = FormWindowState.Minimized;
  189. break;
  190. case Keyword_Maximize:
  191. guis[id].WindowState = FormWindowState.Maximized;
  192. break;
  193. case Keyword_Restore:
  194. guis[id].WindowState = FormWindowState.Normal;
  195. break;
  196. case Keyword_Flash:
  197. if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  198. WindowsAPI.FlashWindow(guis[id].Handle, OnOff(Param2) ?? true);
  199. break;
  200. case Keyword_Default:
  201. DefaultGuiId = id;
  202. break;
  203. case Keyword_TreeView:
  204. {
  205. var tree = GuiFindControl(Param2, guis[id]);
  206. if (tree == null || !typeof(TreeView).IsAssignableFrom(tree.GetType()))
  207. DefaultTreeView = null;
  208. else
  209. DefaultTreeView = (TreeView)tree;
  210. }
  211. break;
  212. case Keyword_ListView:
  213. {
  214. var list = GuiFindControl(Param2, guis[id]);
  215. if (list == null || !typeof(ListView).IsAssignableFrom(list.GetType()))
  216. DefaultListView = null;
  217. else
  218. DefaultListView = (ListView)list;
  219. }
  220. break;
  221. #endregion
  222. #region Options
  223. default:
  224. {
  225. foreach (var option in ParseOptions(Command))
  226. {
  227. bool on = option[0] != '-';
  228. string mode = option;
  229. if (mode[0] == '+' || mode[0] == '-')
  230. mode = mode.Substring(1);
  231. if (mode.Length == 0)
  232. continue;
  233. mode = mode.ToLowerInvariant();
  234. switch (mode)
  235. {
  236. case Keyword_AlwaysOnTop: guis[id].TopMost = on; break;
  237. case Keyword_Border: break;
  238. case Keyword_Caption: break;
  239. case Keyword_Disabled: guis[id].Enabled = !on; break;
  240. case Keyword_LastFound: lastFoundForm = guis[id].Handle.ToInt64(); break;
  241. case Keyword_LastFoundExist: lastFoundForm = guis[id].Handle.ToInt64(); break;
  242. case Keyword_MaximizeBox: guis[id].MaximizeBox = on; break;
  243. case Keyword_MinimizeBox: guis[id].MinimizeBox = on; break;
  244. case Keyword_OwnDialogs: dialogOwner = guis[id]; break;
  245. case Keyword_Owner: break;
  246. case Keyword_Resize: break;
  247. case Keyword_SysMenu: guis[id].ControlBox = on; break;
  248. case Keyword_Theme: Application.EnableVisualStyles(); break;
  249. case Keyword_ToolWindow: break;
  250. case Keyword_Redraw: guis[id].Refresh(); break;
  251. case Keyword_Cursor:
  252. {
  253. switch (Param2.ToLowerInvariant())
  254. {
  255. case "cross": guis[id].Cursor = Cursors.Cross; break;
  256. case "hand": guis[id].Cursor = Cursors.Hand; break;
  257. case "help": guis[id].Cursor = Cursors.Help; break;
  258. case "beam": guis[id].Cursor = Cursors.IBeam; break;
  259. case "no": guis[id].Cursor = Cursors.No; break;
  260. case "wait": guis[id].Cursor = Cursors.WaitCursor; break;
  261. case "nomove": guis[id].Cursor = Cursors.NoMove2D; break;
  262. case "size": guis[id].Cursor = Cursors.SizeAll; break;
  263. case "split":
  264. {
  265. if (Param3.ToLowerInvariant() == Keyword_Vertical)
  266. guis[id].Cursor = Cursors.VSplit;
  267. else
  268. guis[id].Cursor = Cursors.HSplit;
  269. break;
  270. }
  271. case "pan":
  272. {
  273. switch (Param3.ToLowerInvariant())
  274. {
  275. case "east":
  276. case "e": guis[id].Cursor = Cursors.PanEast; break;
  277. case "south":
  278. case "s": guis[id].Cursor = Cursors.PanSouth; break;
  279. case "west":
  280. case "w": guis[id].Cursor = Cursors.PanWest; break;
  281. default:
  282. case "north":
  283. case "n": guis[id].Cursor = Cursors.PanNorth; break;
  284. }
  285. break;
  286. }
  287. case "arrow":
  288. default: guis[id].Cursor = Cursors.Arrow; break;
  289. }
  290. break;
  291. }
  292. case Keyword_Icon:
  293. {
  294. if (Param2 != string.Empty)
  295. {
  296. if (File.Exists(Param2))
  297. if (Path.GetExtension(Param2.ToLowerInvariant())==".ico")
  298. guis[id].Icon = new Icon(Param2);
  299. }
  300. guis[id].ShowIcon = on;
  301. break;
  302. }
  303. case Keyword_TaskBar:
  304. {
  305. guis[id].ShowInTaskbar = on;
  306. break;
  307. }
  308. case Keyword_BackGroundImage:
  309. {
  310. if (on)
  311. {
  312. if (File.Exists(Param2))
  313. {
  314. guis[id].BackgroundImage = new Bitmap(Param2);
  315. switch (Param3.ToLowerInvariant())
  316. {
  317. case Keyword_None: guis[id].BackgroundImageLayout = ImageLayout.None; break;
  318. case Keyword_Tile: guis[id].BackgroundImageLayout = ImageLayout.Tile; break;
  319. case Keyword_Center: guis[id].BackgroundImageLayout = ImageLayout.Center; break;
  320. case Keyword_Zoom: guis[id].BackgroundImageLayout = ImageLayout.Zoom; break;
  321. case Keyword_Stretch:
  322. default: guis[id].BackgroundImageLayout = ImageLayout.Stretch; break;
  323. }
  324. }
  325. }
  326. else
  327. {
  328. guis[id].BackgroundImage = null;
  329. }
  330. break;
  331. }
  332. default:
  333. string arg;
  334. string[] parts;
  335. int n;
  336. Size size;
  337. if (mode.StartsWith(Keyword_Delimiter))
  338. {
  339. arg = mode.Substring(Keyword_Delimiter.Length);
  340. if (arg.Length > 0)
  341. GuiAssociatedInfo(guis[id]).Delimiter = arg[0];
  342. }
  343. else if (mode.StartsWith(Keyword_Label))
  344. {
  345. arg = mode.Substring(Keyword_Label.Length);
  346. if (arg.Length > 0)
  347. guis[id].Name = arg;
  348. }
  349. else if (mode.StartsWith(Keyword_MinSize))
  350. {
  351. arg = mode.Substring(Keyword_MinSize.Length);
  352. parts = arg.Split(new[] { "x", "X", "*" }, 2, StringSplitOptions.None);
  353. size = guis[id].MinimumSize;
  354. if (parts.Length > 0 && int.TryParse(parts[0], out n))
  355. size.Width = n;
  356. if (parts.Length > 1 && int.TryParse(parts[1], out n))
  357. size.Height = n;
  358. guis[id].MinimumSize = size;
  359. }
  360. else if (mode.StartsWith(Keyword_MaxSize))
  361. {
  362. arg = mode.Substring(Keyword_MaxSize.Length);
  363. parts = arg.Split(new[] { "x", "X", "*" }, 2, StringSplitOptions.None);
  364. size = guis[id].MaximumSize;
  365. if (parts.Length > 0 && int.TryParse(parts[0], out n))
  366. size.Width = n;
  367. if (parts.Length > 1 && int.TryParse(parts[1], out n))
  368. size.Height = n;
  369. guis[id].MaximumSize = size;
  370. }
  371. break;
  372. }
  373. }
  374. }
  375. break;
  376. #endregion
  377. }
  378. }
  379. #region Helpers
  380. static void GuiControlEdit(ref Control control, Form parent, string type, string options, string content)
  381. {
  382. string opts = null;
  383. switch (type.ToLowerInvariant())
  384. {
  385. #region Text
  386. case Keyword_Text:
  387. {
  388. var text = (Label)(control ?? new Label());
  389. parent.Controls.Add(text);
  390. control = text;
  391. text.Text = content;
  392. }
  393. break;
  394. #endregion
  395. #region Edit
  396. case Keyword_Edit:
  397. {
  398. var edit = (TextBox)(control ?? new TextBox());
  399. parent.Controls.Add(edit);
  400. control = edit;
  401. edit.Text = NormaliseEol(content);
  402. edit.Tag = options;
  403. opts = GuiApplyStyles(edit, options);
  404. foreach (var opt in ParseOptions(opts))
  405. {
  406. bool on = opt[0] != '-';
  407. string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
  408. switch (mode)
  409. {
  410. case Keyword_Limit:
  411. if (!on)
  412. edit.MaxLength = int.MaxValue;
  413. break;
  414. case Keyword_Lowercase: edit.CharacterCasing = on ? CharacterCasing.Lower : CharacterCasing.Normal; break;
  415. case Keyword_Multi: edit.Multiline = on; break;
  416. case Keyword_Number:
  417. {
  418. if (on)
  419. edit.KeyPress += OnEditKeyPress;
  420. else
  421. edit.KeyPress -= OnEditKeyPress;
  422. break;
  423. }
  424. case Keyword_Password: edit.PasswordChar = '●'; break;
  425. case Keyword_Readonly: edit.ReadOnly = on; break;
  426. case Keyword_Uppercase: edit.CharacterCasing = on ? CharacterCasing.Upper : CharacterCasing.Normal; break;
  427. case Keyword_WantCtrlA: break; //I dont see that the normal ctrl+A works! perhaps new implementation?
  428. case Keyword_WantReturn: edit.AcceptsReturn = on; break;
  429. case Keyword_WantTab: edit.AcceptsTab = on; break;
  430. case Keyword_Wrap: edit.WordWrap = on; break;
  431. default:
  432. int n;
  433. if (mode.StartsWith(Keyword_Limit) && int.TryParse(mode.Substring(Keyword_Limit.Length), out n))
  434. edit.MaxLength = n;
  435. break;
  436. }
  437. }
  438. }
  439. break;
  440. #endregion
  441. #region UpDown
  442. case Keyword_UpDown:
  443. {
  444. var updown = (NumericUpDown)(control ?? new NumericUpDown());
  445. var last = GuiAssociatedInfo(parent).LastControl;
  446. if (last != null && last is TextBox)
  447. {
  448. updown.Location = last.Location;
  449. updown.Size = last.Size;
  450. updown.Font = last.Font;
  451. updown.ForeColor = last.ForeColor;
  452. last.Parent.Controls.Remove(last);
  453. GuiAssociatedInfo(parent).Controls.Pop();
  454. options = string.Concat(last.Tag as string ?? string.Empty, " ", options);
  455. }
  456. parent.Controls.Add(updown);
  457. control = updown;
  458. updown.Value = decimal.Parse(content);
  459. opts = GuiApplyStyles(updown, options);
  460. foreach (var opt in ParseOptions(opts))
  461. {
  462. bool on = opt[0] != '-';
  463. string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
  464. switch (mode)
  465. {
  466. case Keyword_Horz: break;
  467. case Keyword_Left: break;
  468. case Keyword_Wrap: break;
  469. case "16": break;
  470. case "0x80": break;
  471. default:
  472. if (mode.StartsWith(Keyword_Range))
  473. {
  474. string[] range = mode.Substring(Keyword_Range.Length).Split(new[] { "-" }, 2, StringSplitOptions.None);
  475. decimal n;
  476. if (decimal.TryParse(range[0], out n))
  477. updown.Minimum = n;
  478. if (range.Length > 1 && decimal.TryParse(range[1], out n))
  479. updown.Maximum = n;
  480. }
  481. break;
  482. }
  483. }
  484. }
  485. break;
  486. #endregion
  487. #region Picture
  488. case Keyword_Picture:
  489. case Keyword_Pic:
  490. {
  491. var pic = (PictureBox)(control ?? new PictureBox());
  492. parent.Controls.Add(pic);
  493. control = pic;
  494. bool exists = File.Exists(content);
  495. if (exists)
  496. {
  497. pic.ImageLocation = content;
  498. try
  499. {
  500. var image = Image.FromFile(pic.ImageLocation);
  501. pic.Size = image.Size;
  502. }
  503. catch (Exception) { }
  504. }
  505. GuiApplyStyles(pic, options);
  506. }
  507. break;
  508. #endregion
  509. #region Button
  510. case Keyword_Button:
  511. {
  512. var button = (Button)(control ?? new Button());
  513. parent.Controls.Add(button);
  514. control = button;
  515. button.Text = content;
  516. }
  517. break;
  518. #endregion
  519. #region CheckBox
  520. case Keyword_CheckBox:
  521. {
  522. var check = (CheckBox)(control ?? new CheckBox());
  523. parent.Controls.Add(check);
  524. control = check;
  525. check.Text = content;
  526. opts = GuiApplyStyles(check, options);
  527. foreach (var opt in ParseOptions(opts))
  528. {
  529. switch (opt.ToLowerInvariant())
  530. {
  531. case Keyword_Check3:
  532. case Keyword_CheckedGray:
  533. check.CheckState = CheckState.Indeterminate;
  534. break;
  535. case Keyword_Checked:
  536. check.CheckState = CheckState.Checked;
  537. break;
  538. default:
  539. if (opt.StartsWith(Keyword_Checked, StringComparison.OrdinalIgnoreCase))
  540. {
  541. string arg = opt.Substring(Keyword_Checked.Length).Trim();
  542. int n;
  543. if (int.TryParse(arg, out n))
  544. check.CheckState = n == -1 ? CheckState.Indeterminate : n == 1 ? CheckState.Checked : CheckState.Unchecked;
  545. }
  546. break;
  547. }
  548. }
  549. }
  550. break;
  551. #endregion
  552. #region Radio
  553. case Keyword_Radio:
  554. {
  555. var radio = (RadioButton)(control ?? new RadioButton());
  556. parent.Controls.Add(radio);
  557. control = radio;
  558. radio.Text = content;
  559. radio.Checked = false;
  560. opts = GuiApplyStyles(radio, options);
  561. foreach (var opt in ParseOptions(opts))
  562. {
  563. switch (opt.ToLowerInvariant())
  564. {
  565. case Keyword_Checked:
  566. radio.Checked = true;
  567. break;
  568. default:
  569. if (opt.StartsWith(Keyword_Checked, StringComparison.OrdinalIgnoreCase))
  570. {
  571. string arg = opt.Substring(Keyword_Checked.Length).Trim();
  572. int n;
  573. if (int.TryParse(arg, out n))
  574. radio.Checked = n == 1;
  575. }
  576. break;
  577. }
  578. }
  579. }
  580. break;
  581. #endregion
  582. #region DropDownList
  583. case Keyword_DropDownList:
  584. case Keyword_DDL:
  585. {
  586. var ddl = (ComboBox)(control ?? new ComboBox());
  587. parent.Controls.Add(ddl);
  588. control = ddl;
  589. ddl.Text = content;
  590. ddl.DropDownStyle = ComboBoxStyle.DropDownList;
  591. opts = GuiApplyStyles(ddl, options);
  592. int select;
  593. bool clear;
  594. ddl.Items.AddRange(GuiParseList(ddl, out select, out clear));
  595. if (select > -1 && select < ddl.Items.Count)
  596. ddl.SelectedIndex = select;
  597. foreach (var opt in ParseOptions(opts))
  598. {
  599. bool on = opt[0] != '-';
  600. string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
  601. switch (mode)
  602. {
  603. case Keyword_Sort: ddl.Sorted = on; break;
  604. case Keyword_Uppercase: ddl.Text = ddl.Text.ToUpperInvariant(); break;
  605. case Keyword_Lowercase: ddl.Text = ddl.Text.ToLowerInvariant(); break;
  606. default:
  607. if (mode.StartsWith(Keyword_Choose, StringComparison.OrdinalIgnoreCase))
  608. {
  609. mode = mode.Substring(Keyword_Choose.Length);
  610. int n;
  611. if (int.TryParse(mode, out n) && n > -1 && n < ddl.Items.Count)
  612. ddl.SelectedIndex = n;
  613. }
  614. break;
  615. }
  616. }
  617. }
  618. break;
  619. #endregion
  620. #region ComboBox
  621. case Keyword_ComboBox:
  622. {
  623. var combo = (ComboBox)(control ?? new ComboBox());
  624. parent.Controls.Add(combo);
  625. control = combo;
  626. combo.Text = content;
  627. opts = GuiApplyStyles(combo, options);
  628. int select;
  629. bool clear;
  630. combo.Items.AddRange(GuiParseList(combo, out select, out clear));
  631. if (select > -1 && select < combo.Items.Count)
  632. combo.SelectedIndex = select;
  633. foreach (var opt in ParseOptions(opts))
  634. {
  635. bool on = opt[0] != '-';
  636. string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
  637. switch (mode)
  638. {
  639. case Keyword_Limit: break;
  640. case Keyword_Simple: break;
  641. }
  642. }
  643. }
  644. break;
  645. #endregion
  646. #region ListBox
  647. case Keyword_ListBox:
  648. {
  649. var listbox = new ListBox();
  650. parent.Controls.Add(listbox);
  651. control = listbox;
  652. listbox.Text = content;
  653. opts = GuiApplyStyles(listbox, options);
  654. int select;
  655. bool clear;
  656. listbox.Items.AddRange(GuiParseList(listbox, out select, out clear));
  657. if (select > -1 && select < listbox.Items.Count)
  658. listbox.SelectedIndex = select;
  659. bool multi = false, read = false;
  660. foreach (var opt in ParseOptions(opts))
  661. {
  662. bool on = opt[0] != '-';
  663. string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
  664. switch (mode)
  665. {
  666. case Keyword_Multi:
  667. case "8":
  668. multi = on;
  669. break;
  670. case Keyword_Readonly: read = on; break;
  671. case Keyword_Sort: listbox.Sorted = on; break;
  672. default:
  673. if (mode.StartsWith(Keyword_Choose, StringComparison.OrdinalIgnoreCase))
  674. {
  675. mode = mode.Substring(Keyword_Choose.Length);
  676. int n;
  677. if (int.TryParse(mode, out n) && n > -1 && n < listbox.Items.Count)
  678. listbox.SelectedIndex = n;
  679. }
  680. break;
  681. }
  682. }
  683. listbox.SelectionMode = multi ? SelectionMode.MultiExtended : read ? SelectionMode.None : SelectionMode.One;
  684. }
  685. break;
  686. #endregion
  687. #region ListView
  688. case Keyword_ListView:
  689. {
  690. var lv = (ListView)(control ?? new ListView());
  691. parent.Controls.Add(lv);
  692. control = lv;
  693. lv.Text = content;
  694. opts = GuiApplyStyles(lv, options);
  695. lv.View = View.Details;
  696. int select;
  697. bool clear;
  698. foreach (var item in GuiParseList(lv, out select, out clear))
  699. lv.Columns.Add(new ColumnHeader { Text = item });
  700. foreach (var opt in ParseOptions(opts))
  701. {
  702. bool on = opt[0] != '-';
  703. string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
  704. switch (mode)
  705. {
  706. case Keyword_Checked: lv.CheckBoxes = on; break;
  707. case Keyword_Grid: lv.GridLines = on; break;
  708. case Keyword_Hdr: break;
  709. case "lv0x10": break;
  710. case "lv0x20": break;
  711. case Keyword_Multi: lv.MultiSelect = on; break;
  712. case Keyword_NoSortHdr: break;
  713. case Keyword_Readonly: break;
  714. case Keyword_Sort: lv.Sorting = on ? SortOrder.Ascending : SortOrder.None; break;
  715. case Keyword_SortDesc: lv.Sorting = on ? SortOrder.Descending : SortOrder.None; break;
  716. case Keyword_WantF2: break;
  717. }
  718. }
  719. }
  720. break;
  721. #endregion
  722. #region TreeView
  723. case Keyword_TreeView:
  724. {
  725. var tree = (TreeView)(control ?? new TreeView());
  726. parent.Controls.Add(tree);
  727. control = tree;
  728. opts = GuiApplyStyles(tree, options);
  729. foreach (var opt in ParseOptions(opts))
  730. {
  731. bool on = opt[0] != '-';
  732. string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
  733. switch (mode)
  734. {
  735. case Keyword_Buttons: break;
  736. case Keyword_HScroll: break;
  737. case Keyword_Lines: break;
  738. case Keyword_Readonly: break;
  739. case Keyword_WantF2: break;
  740. default:
  741. if (mode.StartsWith(Keyword_ImageList))
  742. {
  743. mode = mode.Substring(Keyword_ImageList.Length);
  744. // UNDONE: TreeView control ImageList
  745. }
  746. break;
  747. }
  748. }
  749. }
  750. break;
  751. #endregion
  752. #region Hotkey
  753. case Keyword_Hotkey:
  754. {
  755. var hotkey = (HotkeyBox)(control ?? new HotkeyBox());
  756. parent.Controls.Add(hotkey);
  757. control = hotkey;
  758. opts = GuiApplyStyles(hotkey, options);
  759. foreach (var opt in ParseOptions(opts))
  760. {
  761. bool on = opt[0] != '-';
  762. string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
  763. switch (mode)
  764. {
  765. case Keyword_Limit:
  766. if (!on)
  767. hotkey.Limit = HotkeyBox.Limits.None;
  768. else
  769. {
  770. int n;
  771. if (int.TryParse(mode, out n))
  772. hotkey.Limit = (HotkeyBox.Limits)n;
  773. }
  774. break;
  775. }
  776. }
  777. }
  778. break;
  779. #endregion
  780. #region DateTime
  781. case Keyword_DateTime:
  782. {
  783. var date = (DateTimePicker)(control ?? new DateTimePicker());
  784. parent.Controls.Add(date);
  785. control = date;
  786. opts = GuiApplyStyles(date, options);
  787. if (content == string.Empty)
  788. date.Value = DateTime.Now;
  789. else
  790. date.Value = ToDateTime(content);
  791. date.Format = DateTimePickerFormat.Short;
  792. foreach (var opt in ParseOptions(opts))
  793. {
  794. bool on = opt[0] != '-';
  795. string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
  796. switch (mode)
  797. {
  798. case "1": date.ShowUpDown = on; break;
  799. case "2": date.ShowCheckBox = on; break;
  800. case Keyword_Right: date.DropDownAlign = LeftRightAlignment.Right; break; //***Bug*** - case dont match!
  801. case Keyword_LongDate: date.Format = DateTimePickerFormat.Long; date.Value = DateTime.Now; break;
  802. case Keyword_Time: date.Format = DateTimePickerFormat.Time; date.Value = DateTime.Now; break;
  803. default:
  804. if (mode.StartsWith(Keyword_Range))
  805. {
  806. string[] range = mode.Substring(Keyword_Range.Length).Split(new[] { "-" }, 2, StringSplitOptions.None);
  807. if (range[0].Length != 0)
  808. date.MinDate = ToDateTime(range[0]);
  809. if (range.Length > 0 && range[1].Length != 0)
  810. date.MaxDate = ToDateTime(range[1]);
  811. }
  812. else if (mode.StartsWith(Keyword_Choose))
  813. {
  814. mode = mode.Substring(Keyword_Choose.Length);
  815. if (mode.Length != 0)
  816. date.Value = ToDateTime(mode);
  817. }
  818. break;
  819. }
  820. }
  821. }
  822. break;
  823. #endregion
  824. #region MonthCal
  825. case Keyword_MonthCal:
  826. {
  827. var cal = (MonthCalendar)(control ?? new MonthCalendar());
  828. parent.Controls.Add(cal);
  829. control = cal;
  830. opts = GuiApplyStyles(cal, options);
  831. if (!string.IsNullOrEmpty(content))
  832. cal.SetDate(ToDateTime(content));
  833. foreach (var opt in ParseOptions(opts))
  834. {
  835. bool on = opt[0] != '-';
  836. string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
  837. switch (mode)
  838. {
  839. case "4": cal.ShowWeekNumbers = on; break;
  840. case "8": cal.ShowTodayCircle = on; break;
  841. case "16": cal.ShowToday = on; break;
  842. case Keyword_Multi: cal.MaxSelectionCount = int.MaxValue; break;
  843. default:
  844. if (mode.StartsWith(Keyword_Range, StringComparison.OrdinalIgnoreCase))
  845. {
  846. string[] range = mode.Substring(Keyword_Range.Length).Split(new[] { "-" }, 2, StringSplitOptions.None);
  847. if (!string.IsNullOrEmpty(range[0]))
  848. cal.MinDate = ToDateTime(range[0]);
  849. if (range.Length > 1 && !string.IsNullOrEmpty(range[1]))
  850. cal.MaxDate = ToDateTime(range[1]);
  851. }
  852. break;
  853. }
  854. }
  855. }
  856. break;
  857. #endregion
  858. #region Slider
  859. case Keyword_Slider:
  860. {
  861. var slider = (TrackBar)(control ?? new TrackBar());
  862. parent.Controls.Add(slider);
  863. control = slider;
  864. opts = GuiApplyStyles(slider, options);
  865. int n;
  866. foreach (var opt in ParseOptions(opts))
  867. {
  868. bool on = opt[0] != '-';
  869. string mode = opt.Substring(!on || opt[0] == '+' ? 1 : 0).ToLowerInvariant();
  870. switch (mode)
  871. {
  872. // UNDONE: misc slider properties
  873. case Keyword_Center: break;
  874. case Keyword_Invert: break;
  875. case Keyword_Left: break;
  876. case Keyword_NoTicks: slider.TickStyle = TickStyle.None; break;
  877. case Keyword_Thick: break;
  878. case Keyword_Vertical: slider.Orientation = Orientation.Vertical; break;
  879. default:
  880. if (mode.StartsWith(Keyword_Line))
  881. {
  882. mode = mode.Substring(Keyword_Line.Length);
  883. // UNDONE: slider line property
  884. }
  885. else if (mode.StartsWith(Keyword_Page))
  886. {
  887. mode = mode.Substring(Keyword_Page.Length);
  888. // UNDONE: slider page property
  889. }
  890. else if (mode.StartsWith(Keyword_Range))
  891. {
  892. mode = mode.Substring(Keyword_Range.Length);
  893. string[] parts = mode.Split(new[] { "-" }, 2, StringSplitOptions.None);
  894. if (parts[0].Length != 0 && int.TryParse(parts[0], out n))
  895. slider.Minimum = n;
  896. if (parts.Length > 0 && parts[1].Length != 0 && int.TryParse(parts[1], out n))
  897. slider.Maximum = n;
  898. }
  899. else if (mode.StartsWith(Keyword_TickInterval))
  900. {
  901. mode = mode.Substring(Keyword_TickInterval.Length);
  902. if (mode.Length != 0 && int.TryParse(mode, out n))
  903. slider.TickFrequency = n;
  904. }
  905. else if (mode.StartsWith(Keyword_ToolTip))
  906. {
  907. mode = mode.Substring(Keyword_ToolTip.Length);
  908. switch (mode) // …

Large files files are truncated, but you can click here to view the full file