KeywordEditor.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. //
  5. // Purpose: A keyword editor form. Allows the end user to insert
  6. // new and edit exsisting keywords in the string.
  7. //
  8. #if DESIGNER
  9. using System.Collections;
  10. using System.Globalization;
  11. using FastReport.DataVisualization.Charting;
  12. using FastReport.DataVisualization.Charting.Utilities;
  13. namespace FastReport.Design.DataVisualization.Charting
  14. {
  15. /// <summary>
  16. /// Summary description for KeywordEditor.
  17. /// </summary>
  18. internal class KeywordEditor : System.Windows.Forms.Form
  19. {
  20. #region Fields
  21. /// <summary>
  22. /// List of keywords that are applicable to the edited property
  23. /// </summary>
  24. private ArrayList _applicableKeywords = null;
  25. /// <summary>
  26. /// Keyword beign edited or empty if inserting a new one.
  27. /// </summary>
  28. internal string Keyword = string.Empty;
  29. /// <summary>
  30. /// Maximum number of supported Y values.
  31. /// </summary>
  32. private int _maxYValueIndex = 9;
  33. // Form fields
  34. private System.Windows.Forms.GroupBox _groupBoxKeywords;
  35. private System.Windows.Forms.ListBox _listBoxKeywords;
  36. private System.Windows.Forms.GroupBox _groupBoxDescription;
  37. private System.Windows.Forms.Label _labelDescription;
  38. private System.Windows.Forms.Button _buttonCancel;
  39. private System.Windows.Forms.Button _buttonOk;
  40. private System.Windows.Forms.GroupBox _groupBoxFormat;
  41. private System.Windows.Forms.Label _labelFormat;
  42. private System.Windows.Forms.NumericUpDown _numericUpDownYValue;
  43. private System.Windows.Forms.Label _labelYValue;
  44. private System.Windows.Forms.ComboBox _comboBoxFormat;
  45. private System.Windows.Forms.Label _labelPrecision;
  46. private System.Windows.Forms.TextBox _textBoxCustomFormat;
  47. private System.Windows.Forms.Label _labelCustomFormat;
  48. private System.Windows.Forms.Label _labelSample;
  49. private System.Windows.Forms.TextBox _textBoxSample;
  50. private System.Windows.Forms.TextBox _textBoxPrecision;
  51. private System.Windows.Forms.ToolTip _toolTip;
  52. private System.ComponentModel.IContainer _components;
  53. // resolved VSTS by extending the dialog by 36x28 pixels.
  54. // 5767 FRA: ChartAPI: String "Format Sample:" is truncated on the "Keywords Editor'
  55. // 4383 DEU: VC/VB/VCS/VWD: ChartAPI: The string "If a chart type supports..." is truncated on the 'Keyword Editor' dialog.
  56. // 3524 DEU: VC/VB/VCS/VWD: ChartAPI: The string "If a chart type supports..." is truncated on the 'Keyword Editor' dialog.
  57. private static int widthDialogExtend = 80;
  58. private static int heightDialogExtend = 38;
  59. #endregion // Fields
  60. #region Constructors
  61. /// <summary>
  62. /// Default public constructor.
  63. /// </summary>
  64. public KeywordEditor()
  65. {
  66. //
  67. // Required for Windows Form Designer support
  68. //
  69. InitializeComponent();
  70. PrepareControlsLayout();
  71. }
  72. /// <summary>
  73. /// Form constructor.
  74. /// </summary>
  75. /// <param name="applicableKeywords">List of keywords that can be inserted.</param>
  76. /// <param name="keyword">Keyword that should be edited.</param>
  77. /// <param name="maxYValueIndex">Maximum number of Y Values supported.</param>
  78. public KeywordEditor(ArrayList applicableKeywords, string keyword, int maxYValueIndex) : this()
  79. {
  80. // Save input data
  81. this._applicableKeywords = applicableKeywords;
  82. this.Keyword = keyword;
  83. this._maxYValueIndex = maxYValueIndex;
  84. }
  85. /// <summary>
  86. /// Clean up any resources being used.
  87. /// </summary>
  88. protected override void Dispose( bool disposing )
  89. {
  90. if( disposing )
  91. {
  92. if(_components != null)
  93. {
  94. _components.Dispose();
  95. }
  96. }
  97. base.Dispose( disposing );
  98. }
  99. #endregion // Constructors
  100. #region Windows Form Designer generated code
  101. /// <summary>
  102. /// Required method for Designer support - do not modify
  103. /// the contents of this method with the code editor.
  104. /// </summary>
  105. private void InitializeComponent()
  106. {
  107. this._components = new System.ComponentModel.Container();
  108. this._groupBoxKeywords = new System.Windows.Forms.GroupBox();
  109. this._listBoxKeywords = new System.Windows.Forms.ListBox();
  110. this._groupBoxDescription = new System.Windows.Forms.GroupBox();
  111. this._labelDescription = new System.Windows.Forms.Label();
  112. this._buttonCancel = new System.Windows.Forms.Button();
  113. this._buttonOk = new System.Windows.Forms.Button();
  114. this._groupBoxFormat = new System.Windows.Forms.GroupBox();
  115. this._textBoxPrecision = new System.Windows.Forms.TextBox();
  116. this._labelSample = new System.Windows.Forms.Label();
  117. this._textBoxSample = new System.Windows.Forms.TextBox();
  118. this._numericUpDownYValue = new System.Windows.Forms.NumericUpDown();
  119. this._labelYValue = new System.Windows.Forms.Label();
  120. this._comboBoxFormat = new System.Windows.Forms.ComboBox();
  121. this._labelPrecision = new System.Windows.Forms.Label();
  122. this._labelFormat = new System.Windows.Forms.Label();
  123. this._labelCustomFormat = new System.Windows.Forms.Label();
  124. this._textBoxCustomFormat = new System.Windows.Forms.TextBox();
  125. this._toolTip = new System.Windows.Forms.ToolTip(this._components);
  126. this._groupBoxKeywords.SuspendLayout();
  127. this._groupBoxDescription.SuspendLayout();
  128. this._groupBoxFormat.SuspendLayout();
  129. ((System.ComponentModel.ISupportInitialize)(this._numericUpDownYValue)).BeginInit();
  130. this.SuspendLayout();
  131. //
  132. // groupBoxKeywords
  133. //
  134. this._groupBoxKeywords.Controls.AddRange(new System.Windows.Forms.Control[] {
  135. this._listBoxKeywords});
  136. this._groupBoxKeywords.Location = new System.Drawing.Point(8, 16);
  137. this._groupBoxKeywords.Name = "groupBoxKeywords";
  138. this._groupBoxKeywords.Size = new System.Drawing.Size(216, 232);
  139. this._groupBoxKeywords.TabIndex = 0;
  140. this._groupBoxKeywords.TabStop = false;
  141. this._groupBoxKeywords.Text = SR.LabelKeyKeywords;
  142. //
  143. // listBoxKeywords
  144. //
  145. this._listBoxKeywords.Location = new System.Drawing.Point(8, 24);
  146. this._listBoxKeywords.Name = "listBoxKeywords";
  147. this._listBoxKeywords.Size = new System.Drawing.Size(200, 199);
  148. this._listBoxKeywords.TabIndex = 0;
  149. this._listBoxKeywords.DoubleClick += new System.EventHandler(this.listBoxKeywords_DoubleClick);
  150. this._listBoxKeywords.SelectedIndexChanged += new System.EventHandler(this.listBoxKeywords_SelectedIndexChanged);
  151. //
  152. // groupBoxDescription
  153. //
  154. this._groupBoxDescription.Controls.AddRange(new System.Windows.Forms.Control[] {
  155. this._labelDescription});
  156. this._groupBoxDescription.Location = new System.Drawing.Point(240, 16);
  157. this._groupBoxDescription.Name = "groupBoxDescription";
  158. this._groupBoxDescription.Size = new System.Drawing.Size(328, 88);
  159. this._groupBoxDescription.TabIndex = 1;
  160. this._groupBoxDescription.TabStop = false;
  161. this._groupBoxDescription.Text = SR.LabelDescription;
  162. //
  163. // labelDescription
  164. //
  165. this._labelDescription.Location = new System.Drawing.Point(16, 24);
  166. this._labelDescription.Name = "labelDescription";
  167. this._labelDescription.Size = new System.Drawing.Size(304, 56);
  168. this._labelDescription.TabIndex = 0;
  169. this._labelDescription.Text = "<replaced at runtime>";
  170. //
  171. // buttonCancel
  172. //
  173. this._buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  174. this._buttonCancel.Location = new System.Drawing.Point(479, 256);
  175. this._buttonCancel.Name = "buttonCancel";
  176. this._buttonCancel.Size = new System.Drawing.Size(90, 27);
  177. this._buttonCancel.TabIndex = 4;
  178. this._buttonCancel.Text = SR.LabelButtonCancel;
  179. //
  180. // buttonOk
  181. //
  182. this._buttonOk.DialogResult = System.Windows.Forms.DialogResult.OK;
  183. this._buttonOk.Location = new System.Drawing.Point(367, 256);
  184. this._buttonOk.Name = "buttonOk";
  185. this._buttonOk.Size = new System.Drawing.Size(90, 27);
  186. this._buttonOk.TabIndex = 3;
  187. this._buttonOk.Text = SR.LabelButtonOk;
  188. this._buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
  189. //
  190. // groupBoxFormat
  191. //
  192. this._groupBoxFormat.Controls.AddRange(new System.Windows.Forms.Control[] {
  193. this._textBoxPrecision,
  194. this._labelSample,
  195. this._textBoxSample,
  196. this._numericUpDownYValue,
  197. this._labelYValue,
  198. this._comboBoxFormat,
  199. this._labelPrecision,
  200. this._labelFormat,
  201. this._labelCustomFormat,
  202. this._textBoxCustomFormat});
  203. this._groupBoxFormat.Location = new System.Drawing.Point(240, 112);
  204. this._groupBoxFormat.Name = "groupBoxFormat";
  205. this._groupBoxFormat.Size = new System.Drawing.Size(328, 136);
  206. this._groupBoxFormat.TabIndex = 2;
  207. this._groupBoxFormat.TabStop = false;
  208. this._groupBoxFormat.Text = SR.LabelValueFormatting;
  209. //
  210. // textBoxPrecision
  211. //
  212. this._textBoxPrecision.Location = new System.Drawing.Point(112, 48);
  213. this._textBoxPrecision.Name = "textBoxPrecision";
  214. this._textBoxPrecision.Size = new System.Drawing.Size(64, 20);
  215. this._textBoxPrecision.TabIndex = 3;
  216. this._textBoxPrecision.Text = "";
  217. this._textBoxPrecision.TextChanged += new System.EventHandler(this.textBoxPrecision_TextChanged);
  218. //
  219. // labelSample
  220. //
  221. this._labelSample.Location = new System.Drawing.Point(8, 72);
  222. this._labelSample.Name = "labelSample";
  223. this._labelSample.Size = new System.Drawing.Size(96, 23);
  224. this._labelSample.TabIndex = 7;
  225. this._labelSample.Text = SR.LabelFormatKeySample;
  226. this._labelSample.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  227. //
  228. // textBoxSample
  229. //
  230. this._textBoxSample.Location = new System.Drawing.Point(112, 72);
  231. this._textBoxSample.Name = "textBoxSample";
  232. this._textBoxSample.ReadOnly = true;
  233. this._textBoxSample.Size = new System.Drawing.Size(192, 20);
  234. this._textBoxSample.TabIndex = 8;
  235. this._textBoxSample.Text = "";
  236. //
  237. // numericUpDownYValue
  238. //
  239. this._numericUpDownYValue.CausesValidation = false;
  240. this._numericUpDownYValue.Location = new System.Drawing.Point(112, 104);
  241. this._numericUpDownYValue.Maximum = new System.Decimal(new int[] {
  242. 9,
  243. 0,
  244. 0,
  245. 0});
  246. this._numericUpDownYValue.Name = "numericUpDownYValue";
  247. this._numericUpDownYValue.Size = new System.Drawing.Size(64, 20);
  248. this._numericUpDownYValue.TabIndex = 10;
  249. this._numericUpDownYValue.ValueChanged += new System.EventHandler(this.numericUpDownYValue_ValueChanged);
  250. //
  251. // labelYValue
  252. //
  253. this._labelYValue.Location = new System.Drawing.Point(8, 104);
  254. this._labelYValue.Name = "labelYValue";
  255. this._labelYValue.Size = new System.Drawing.Size(96, 23);
  256. this._labelYValue.TabIndex = 9;
  257. this._labelYValue.Text = SR.LabelKeyYValueIndex;
  258. this._labelYValue.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  259. //
  260. // comboBoxFormat
  261. //
  262. this._comboBoxFormat.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  263. this._comboBoxFormat.Items.AddRange(new object[] {
  264. SR.DescriptionTypeNone,
  265. SR.DescriptionNumberFormatTypeCurrency,
  266. SR.DescriptionNumberFormatTypeDecimal,
  267. SR.DescriptionNumberFormatTypeScientific,
  268. SR.DescriptionNumberFormatTypeFixedPoint,
  269. SR.DescriptionNumberFormatTypeGeneral,
  270. SR.DescriptionNumberFormatTypeNumber,
  271. SR.DescriptionNumberFormatTypePercent,
  272. SR.DescriptionTypeCustom});
  273. this._comboBoxFormat.Location = new System.Drawing.Point(112, 24);
  274. this._comboBoxFormat.MaxDropDownItems = 10;
  275. this._comboBoxFormat.Name = "comboBoxFormat";
  276. this._comboBoxFormat.Size = new System.Drawing.Size(192, 21);
  277. this._comboBoxFormat.TabIndex = 1;
  278. this._comboBoxFormat.SelectedIndexChanged += new System.EventHandler(this.comboBoxFormat_SelectedIndexChanged);
  279. //
  280. // labelPrecision
  281. //
  282. this._labelPrecision.Location = new System.Drawing.Point(8, 48);
  283. this._labelPrecision.Name = "labelPrecision";
  284. this._labelPrecision.Size = new System.Drawing.Size(96, 23);
  285. this._labelPrecision.TabIndex = 2;
  286. this._labelPrecision.Text = SR.LabelKeyPrecision;
  287. this._labelPrecision.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  288. //
  289. // labelFormat
  290. //
  291. this._labelFormat.Location = new System.Drawing.Point(8, 24);
  292. this._labelFormat.Name = "labelFormat";
  293. this._labelFormat.Size = new System.Drawing.Size(96, 23);
  294. this._labelFormat.TabIndex = 0;
  295. this._labelFormat.Text = SR.LabelKeyFormat;
  296. this._labelFormat.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  297. //
  298. // labelCustomFormat
  299. //
  300. this._labelCustomFormat.Location = new System.Drawing.Point(8, 48);
  301. this._labelCustomFormat.Name = "labelCustomFormat";
  302. this._labelCustomFormat.Size = new System.Drawing.Size(96, 23);
  303. this._labelCustomFormat.TabIndex = 4;
  304. this._labelCustomFormat.Text = SR.LabelKeyCustomFormat;
  305. this._labelCustomFormat.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  306. this._labelCustomFormat.Visible = false;
  307. //
  308. // textBoxCustomFormat
  309. //
  310. this._textBoxCustomFormat.Location = new System.Drawing.Point(112, 48);
  311. this._textBoxCustomFormat.Name = "textBoxCustomFormat";
  312. this._textBoxCustomFormat.Size = new System.Drawing.Size(192, 20);
  313. this._textBoxCustomFormat.TabIndex = 5;
  314. this._textBoxCustomFormat.Text = "";
  315. this._textBoxCustomFormat.Visible = false;
  316. this._textBoxCustomFormat.TextChanged += new System.EventHandler(this.textBoxCustomFormat_TextChanged);
  317. //
  318. // KeywordEditor
  319. //
  320. this.AcceptButton = this._buttonOk;
  321. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  322. this.CancelButton = this._buttonCancel;
  323. this.ClientSize = new System.Drawing.Size(578, 295);
  324. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  325. this._groupBoxFormat,
  326. this._buttonCancel,
  327. this._buttonOk,
  328. this._groupBoxDescription,
  329. this._groupBoxKeywords});
  330. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  331. this.MaximizeBox = false;
  332. this.MinimizeBox = false;
  333. this.Name = "KeywordEditor";
  334. this.ShowInTaskbar = false;
  335. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  336. this.Text = SR.LabelKeywordEditor;
  337. this.Load += new System.EventHandler(this.KeywordEditor_Load);
  338. this._groupBoxKeywords.ResumeLayout(false);
  339. this._groupBoxDescription.ResumeLayout(false);
  340. this._groupBoxFormat.ResumeLayout(false);
  341. ((System.ComponentModel.ISupportInitialize)(this._numericUpDownYValue)).EndInit();
  342. this.ResumeLayout(false);
  343. }
  344. #endregion
  345. #region Event Handlers
  346. /// <summary>
  347. /// Form loaded event handler.
  348. /// </summary>
  349. /// <param name="sender">Event sender.</param>
  350. /// <param name="e">Event arguments.</param>
  351. private void KeywordEditor_Load(object sender, System.EventArgs e)
  352. {
  353. // Set restriction on the Y Value index editor
  354. if(this._maxYValueIndex >= 0 && this._maxYValueIndex < 10)
  355. {
  356. this._numericUpDownYValue.Maximum = this._maxYValueIndex;
  357. }
  358. this._numericUpDownYValue.Enabled = this._maxYValueIndex > 0;
  359. this._labelYValue.Enabled = this._maxYValueIndex > 0;
  360. // Set tooltip for custom format
  361. this._toolTip.SetToolTip(this._textBoxCustomFormat, SR.DescriptionToolTipCustomFormatCharacters);
  362. // Select format None
  363. this._comboBoxFormat.SelectedIndex = 0;
  364. // Fill list of applicable keywords
  365. if(this._applicableKeywords != null)
  366. {
  367. foreach(KeywordInfo keywordInfo in this._applicableKeywords)
  368. {
  369. this._listBoxKeywords.Items.Add(keywordInfo);
  370. }
  371. }
  372. // Check if keyword for editing was specified
  373. if(this.Keyword.Length == 0)
  374. {
  375. this._listBoxKeywords.SelectedIndex = 0;
  376. this._comboBoxFormat.SelectedIndex = 0;
  377. }
  378. else
  379. {
  380. // Iterate through all keywords and find a match
  381. bool itemFound = false;
  382. foreach(KeywordInfo keywordInfo in this._applicableKeywords)
  383. {
  384. // Iterate through all possible keyword names
  385. string[] keywordNames = keywordInfo.GetKeywords();
  386. foreach(string keywordName in keywordNames)
  387. {
  388. if(this.Keyword.StartsWith(keywordName, StringComparison.Ordinal))
  389. {
  390. // Select keyword in the list
  391. this._listBoxKeywords.SelectedItem = keywordInfo;
  392. int keywordLength = keywordName.Length;
  393. // Check if keyword support multiple Y values
  394. if(keywordInfo.SupportsValueIndex)
  395. {
  396. if(this.Keyword.Length > keywordLength &&
  397. this.Keyword[keywordLength] == 'Y')
  398. {
  399. ++keywordLength;
  400. if(this.Keyword.Length > (keywordLength) &&
  401. char.IsDigit(this.Keyword[keywordLength]))
  402. {
  403. int yValueIndex = int.Parse(this.Keyword.Substring(keywordLength, 1), CultureInfo.InvariantCulture);
  404. if(yValueIndex < 0 || yValueIndex > this._maxYValueIndex)
  405. {
  406. yValueIndex = 0;
  407. }
  408. _numericUpDownYValue.Value = yValueIndex;
  409. ++keywordLength;
  410. }
  411. }
  412. }
  413. // Check if keyword support format string
  414. if(keywordInfo.SupportsFormatting)
  415. {
  416. if(this.Keyword.Length > keywordLength &&
  417. this.Keyword[keywordLength] == '{' &&
  418. this.Keyword.EndsWith("}", StringComparison.Ordinal))
  419. {
  420. // Get format string
  421. string format = this.Keyword.Substring(keywordLength + 1, this.Keyword.Length - keywordLength - 2);
  422. if(format.Length == 0)
  423. {
  424. // Select format None
  425. this._comboBoxFormat.SelectedIndex = 0;
  426. }
  427. else
  428. {
  429. // Check if format string is custom
  430. if(format.Length == 1 ||
  431. (format.Length == 2 && char.IsDigit(format[1])) ||
  432. (format.Length == 3 && char.IsDigit(format[2])) )
  433. {
  434. if(format[0] == 'C')
  435. {
  436. this._comboBoxFormat.SelectedIndex = 1;
  437. }
  438. else if(format[0] == 'D')
  439. {
  440. this._comboBoxFormat.SelectedIndex = 2;
  441. }
  442. else if(format[0] == 'E')
  443. {
  444. this._comboBoxFormat.SelectedIndex = 3;
  445. }
  446. else if(format[0] == 'F')
  447. {
  448. this._comboBoxFormat.SelectedIndex = 4;
  449. }
  450. else if(format[0] == 'G')
  451. {
  452. this._comboBoxFormat.SelectedIndex = 5;
  453. }
  454. else if(format[0] == 'N')
  455. {
  456. this._comboBoxFormat.SelectedIndex = 6;
  457. }
  458. else if(format[0] == 'P')
  459. {
  460. this._comboBoxFormat.SelectedIndex = 7;
  461. }
  462. else
  463. {
  464. // Custom format
  465. this._comboBoxFormat.SelectedIndex = 8;
  466. this._textBoxCustomFormat.Text = format;
  467. }
  468. // Get precision
  469. if(this._comboBoxFormat.SelectedIndex != 8 && format.Length > 0)
  470. {
  471. this._textBoxPrecision.Text = format.Substring(1);
  472. }
  473. }
  474. else
  475. {
  476. // Custom format
  477. this._comboBoxFormat.SelectedIndex = 8;
  478. this._textBoxCustomFormat.Text = format;
  479. }
  480. }
  481. }
  482. }
  483. // Stop iteration
  484. itemFound = true;
  485. break;
  486. }
  487. }
  488. // Break from the keywords loop
  489. if(itemFound)
  490. {
  491. break;
  492. }
  493. }
  494. }
  495. }
  496. /// <summary>
  497. /// Selected format changed event handler.
  498. /// </summary>
  499. /// <param name="sender">Event sender.</param>
  500. /// <param name="e">Event arguments.</param>
  501. private void comboBoxFormat_SelectedIndexChanged(object sender, System.EventArgs e)
  502. {
  503. // Format disabled
  504. _labelCustomFormat.Enabled = (this._comboBoxFormat.SelectedIndex > 0);
  505. _textBoxCustomFormat.Enabled = (this._comboBoxFormat.SelectedIndex > 0);
  506. _labelPrecision.Enabled = (this._comboBoxFormat.SelectedIndex > 0);
  507. _textBoxPrecision.Enabled = (this._comboBoxFormat.SelectedIndex > 0);
  508. _labelSample.Enabled = (this._comboBoxFormat.SelectedIndex > 0);
  509. _textBoxSample.Enabled = (this._comboBoxFormat.SelectedIndex > 0);
  510. // Hide show form control depending on the format selection
  511. bool customFormat = ((string)_comboBoxFormat.SelectedItem == "Custom");
  512. _labelCustomFormat.Visible = customFormat;
  513. _textBoxCustomFormat.Visible = customFormat;
  514. _labelPrecision.Visible = !customFormat;
  515. _textBoxPrecision.Visible = !customFormat;
  516. // Update format sample
  517. this.UpdateNumericSample();
  518. }
  519. /// <summary>
  520. /// Selected keyword changed event handler.
  521. /// </summary>
  522. /// <param name="sender">Event sender.</param>
  523. /// <param name="e">Event arguments.</param>
  524. private void listBoxKeywords_SelectedIndexChanged(object sender, System.EventArgs e)
  525. {
  526. // Get selected keyword
  527. KeywordInfo keywordInfo = _listBoxKeywords.SelectedItem as KeywordInfo;
  528. if(keywordInfo != null)
  529. {
  530. // Show description of the selected keyword
  531. this._labelDescription.Text = keywordInfo.Description.Replace("\\n", "\n");
  532. // Check if keyword support value formatting
  533. _groupBoxFormat.Enabled = keywordInfo.SupportsFormatting;
  534. // Check if keyword support Y value index
  535. _labelYValue.Enabled = keywordInfo.SupportsValueIndex;
  536. _numericUpDownYValue.Enabled = keywordInfo.SupportsValueIndex && this._maxYValueIndex > 0;
  537. this._labelYValue.Enabled = keywordInfo.SupportsValueIndex && this._maxYValueIndex > 0;
  538. }
  539. }
  540. /// <summary>
  541. /// Keyword double click event handler.
  542. /// </summary>
  543. /// <param name="sender">Event sender.</param>
  544. /// <param name="e">Event arguments.</param>
  545. private void listBoxKeywords_DoubleClick(object sender, System.EventArgs e)
  546. {
  547. // Simulate accept button click when user double clicks in the list
  548. this.AcceptButton.PerformClick();
  549. }
  550. /// <summary>
  551. /// Precision text changed event handler.
  552. /// </summary>
  553. /// <param name="sender">Event sender.</param>
  554. /// <param name="e">Event arguments.</param>
  555. private void textBoxPrecision_TextChanged(object sender, System.EventArgs e)
  556. {
  557. MessageBoxOptions messageBoxOptions = 0;
  558. if (RightToLeft == System.Windows.Forms.RightToLeft.Yes)
  559. {
  560. messageBoxOptions = MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading;
  561. }
  562. if(this._textBoxPrecision.Text.Length >= 1 && !char.IsDigit(this._textBoxPrecision.Text[0]))
  563. {
  564. MessageBox.Show(this, SR.MessagePrecisionInvalid, SR.MessageChartTitle, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, messageBoxOptions);
  565. this._textBoxPrecision.Text = "";
  566. }
  567. else if(this._textBoxPrecision.Text.Length >= 2 && (!char.IsDigit(this._textBoxPrecision.Text[0]) || !char.IsDigit(this._textBoxPrecision.Text[1])))
  568. {
  569. MessageBox.Show(this, SR.MessagePrecisionInvalid, SR.MessageChartTitle, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, messageBoxOptions);
  570. this._textBoxPrecision.Text = "";
  571. }
  572. this.UpdateNumericSample();
  573. }
  574. /// <summary>
  575. /// Custom format text changed event handler.
  576. /// </summary>
  577. /// <param name="sender">Event sender.</param>
  578. /// <param name="e">Event arguments.</param>
  579. private void textBoxCustomFormat_TextChanged(object sender, System.EventArgs e)
  580. {
  581. this.UpdateNumericSample();
  582. }
  583. /// <summary>
  584. /// Ok button click event handler.
  585. /// </summary>
  586. /// <param name="sender">Event sender.</param>
  587. /// <param name="e">Event arguments.</param>
  588. private void buttonOk_Click(object sender, System.EventArgs e)
  589. {
  590. // Generate new keyword
  591. this.Keyword = string.Empty;
  592. // Get selected keyword
  593. KeywordInfo keywordInfo = this._listBoxKeywords.SelectedItem as KeywordInfo;
  594. if(keywordInfo != null)
  595. {
  596. this.Keyword = keywordInfo.Keyword;
  597. if(keywordInfo.SupportsValueIndex &&
  598. (int)_numericUpDownYValue.Value > 0)
  599. {
  600. this.Keyword += "Y" + ((int)_numericUpDownYValue.Value).ToString(CultureInfo.InvariantCulture);
  601. }
  602. if(keywordInfo.SupportsFormatting &&
  603. _comboBoxFormat.SelectedIndex > 0 &&
  604. this.GetFormatString().Length > 0)
  605. {
  606. this.Keyword += "{" + this.GetFormatString() + "}";
  607. }
  608. }
  609. }
  610. /// <summary>
  611. /// Y Value index changed event handler.
  612. /// </summary>
  613. /// <param name="sender">Event sender.</param>
  614. /// <param name="e">Event arguments.</param>
  615. private void numericUpDownYValue_ValueChanged(object sender, System.EventArgs e)
  616. {
  617. if(_numericUpDownYValue.Value > this._maxYValueIndex && _numericUpDownYValue.Value < 0)
  618. {
  619. MessageBoxOptions messageBoxOptions = 0;
  620. if (RightToLeft == System.Windows.Forms.RightToLeft.Yes)
  621. {
  622. messageBoxOptions = MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading;
  623. }
  624. MessageBox.Show(this, SR.MessageYValueIndexInvalid(this._maxYValueIndex.ToString(CultureInfo.CurrentCulture)), SR.MessageChartTitle,
  625. MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, messageBoxOptions);
  626. _numericUpDownYValue.Value = 0;
  627. }
  628. }
  629. #endregion // Event Handlers
  630. #region Helper Methods
  631. /// <summary>
  632. /// Gets current format string
  633. /// </summary>
  634. /// <returns></returns>
  635. private string GetFormatString()
  636. {
  637. string formatString = string.Empty;
  638. if(this._comboBoxFormat.Enabled &&
  639. this._comboBoxFormat.SelectedIndex == 1)
  640. {
  641. formatString = "C" + _textBoxPrecision.Text;
  642. }
  643. else if(this._comboBoxFormat.SelectedIndex == 2)
  644. {
  645. formatString = "D" + _textBoxPrecision.Text;
  646. }
  647. else if(this._comboBoxFormat.SelectedIndex == 3)
  648. {
  649. formatString = "E" + _textBoxPrecision.Text;
  650. }
  651. else if(this._comboBoxFormat.SelectedIndex == 4)
  652. {
  653. formatString = "G" + _textBoxPrecision.Text;
  654. }
  655. else if(this._comboBoxFormat.SelectedIndex == 5)
  656. {
  657. formatString = "G" + _textBoxPrecision.Text;
  658. }
  659. else if(this._comboBoxFormat.SelectedIndex == 6)
  660. {
  661. formatString = "N" + _textBoxPrecision.Text;
  662. }
  663. else if(this._comboBoxFormat.SelectedIndex == 7)
  664. {
  665. formatString = "P" + _textBoxPrecision.Text;
  666. }
  667. else if(this._comboBoxFormat.SelectedIndex == 8)
  668. {
  669. formatString = this._textBoxCustomFormat.Text;
  670. }
  671. return formatString;
  672. }
  673. /// <summary>
  674. /// Updates numeric sample on the form.
  675. /// </summary>
  676. private void UpdateNumericSample()
  677. {
  678. string formatString = this.GetFormatString();
  679. if(this._comboBoxFormat.SelectedIndex == 0)
  680. {
  681. // No format
  682. _textBoxSample.Text = string.Empty;
  683. }
  684. else if(this._comboBoxFormat.SelectedIndex == 1)
  685. {
  686. _textBoxSample.Text = String.Format(CultureInfo.CurrentCulture, "{0:" + formatString + "}", 12345.6789);
  687. }
  688. else if(this._comboBoxFormat.SelectedIndex == 2)
  689. {
  690. _textBoxSample.Text = String.Format(CultureInfo.CurrentCulture, "{0:" + formatString + "}", 12345);
  691. }
  692. else if(this._comboBoxFormat.SelectedIndex == 3)
  693. {
  694. _textBoxSample.Text = String.Format(CultureInfo.CurrentCulture, "{0:" + formatString + "}", 12345.6789);
  695. }
  696. else if(this._comboBoxFormat.SelectedIndex == 4)
  697. {
  698. _textBoxSample.Text = String.Format(CultureInfo.CurrentCulture, "{0:" + formatString + "}", 12345.6789);
  699. }
  700. else if(this._comboBoxFormat.SelectedIndex == 5)
  701. {
  702. _textBoxSample.Text = String.Format(CultureInfo.CurrentCulture, "{0:" + formatString + "}", 12345.6789);
  703. }
  704. else if(this._comboBoxFormat.SelectedIndex == 6)
  705. {
  706. _textBoxSample.Text = String.Format(CultureInfo.CurrentCulture, "{0:" + formatString + "}", 12345.6789);
  707. }
  708. else if(this._comboBoxFormat.SelectedIndex == 7)
  709. {
  710. _textBoxSample.Text = String.Format(CultureInfo.CurrentCulture, "{0:" + formatString + "}", 0.126);
  711. }
  712. else if(this._comboBoxFormat.SelectedIndex == 8)
  713. {
  714. // Custom format
  715. bool success = false;
  716. try
  717. {
  718. this._textBoxSample.Text = String.Format(CultureInfo.CurrentCulture, "{0:" + formatString + "}", 12345.67890);
  719. success = true;
  720. }
  721. catch(FormatException)
  722. {
  723. }
  724. if(!success)
  725. {
  726. try
  727. {
  728. this._textBoxSample.Text = String.Format(CultureInfo.CurrentCulture, "{0:" + formatString + "}", 12345);
  729. success = true;
  730. }
  731. catch(FormatException)
  732. {
  733. }
  734. }
  735. if(!success)
  736. {
  737. this._textBoxSample.Text = SR.DesciptionCustomLabelFormatInvalid;
  738. }
  739. }
  740. }
  741. /// <summary>
  742. /// VSTS: 787936, 787937 - Expand the dialog with widthDialogExtend, heightDialogExtend to make room for localization.
  743. /// </summary>
  744. private void PrepareControlsLayout()
  745. {
  746. this.Width += widthDialogExtend;
  747. this._buttonOk.Left += widthDialogExtend;
  748. this._buttonCancel.Left += widthDialogExtend;
  749. this._groupBoxDescription.Width += widthDialogExtend;
  750. this._groupBoxFormat.Width += widthDialogExtend;
  751. this._labelDescription.Width += widthDialogExtend;
  752. foreach (System.Windows.Forms.Control ctrl in this._groupBoxFormat.Controls)
  753. {
  754. if (ctrl is Label)
  755. ctrl.Width += widthDialogExtend;
  756. else
  757. ctrl.Left += widthDialogExtend;
  758. }
  759. this.Height += heightDialogExtend;
  760. this._buttonOk.Top += heightDialogExtend;
  761. this._buttonCancel.Top += heightDialogExtend;
  762. this._groupBoxKeywords.Height += heightDialogExtend;
  763. this._listBoxKeywords.IntegralHeight = false;
  764. this._listBoxKeywords.Height += heightDialogExtend;
  765. this._groupBoxDescription.Height += heightDialogExtend;
  766. this._labelDescription.Height += heightDialogExtend;
  767. this._groupBoxFormat.Top += heightDialogExtend;
  768. }
  769. #endregion // Helper Methods
  770. }
  771. }
  772. #endif