/
Form1.cs
435 lines (403 loc) · 22.2 KB
/
Form1.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
using DevExpress.XtraTab;
using DevExpress.XtraEditors;
using DevExpress.XtraRichEdit;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Columns;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using System.Drawing;
using DevExpress.Office.Utils;
using DevExpress.XtraSpreadsheet;
using DevExpress.Spreadsheet;
namespace SpreadsheetControl_API_Part03
{
public partial class Form1 : Form
{
SplitContainerControl horizontalSplitContainerControl1;
SplitContainerControl verticalSplitContainerControl1;
#region Controls
private TreeList treeList1;
private XtraTabControl xtraTabControl1;
private XtraTabPage xtraTabPage1;
private RichEditControl richEditControlCS;
private XtraTabPage xtraTabPage2;
private DisplayResultControl displayResultControl1;
private RichEditControl richEditControlVB;
#endregion
#region InitializeComponent
private void InitializeComponent()
{
this.horizontalSplitContainerControl1 = new DevExpress.XtraEditors.SplitContainerControl();
this.xtraTabControl1 = new DevExpress.XtraTab.XtraTabControl();
this.xtraTabPage1 = new DevExpress.XtraTab.XtraTabPage();
this.richEditControlCS = new DevExpress.XtraRichEdit.RichEditControl();
this.xtraTabPage2 = new DevExpress.XtraTab.XtraTabPage();
this.richEditControlVB = new DevExpress.XtraRichEdit.RichEditControl();
this.xtraTabPage3 = new DevExpress.XtraTab.XtraTabPage();
this.richEditControlCSClass = new DevExpress.XtraRichEdit.RichEditControl();
this.xtraTabPage4 = new DevExpress.XtraTab.XtraTabPage();
this.richEditControlVBClass = new DevExpress.XtraRichEdit.RichEditControl();
this.codeExampleNameLbl = new DevExpress.XtraEditors.LabelControl();
this.displayResultControl1 = new SpreadsheetControl_API_Part03.DisplayResultControl();
this.verticalSplitContainerControl1 = new DevExpress.XtraEditors.SplitContainerControl();
this.treeList1 = new DevExpress.XtraTreeList.TreeList();
((System.ComponentModel.ISupportInitialize)(this.horizontalSplitContainerControl1)).BeginInit();
this.horizontalSplitContainerControl1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.xtraTabControl1)).BeginInit();
this.xtraTabControl1.SuspendLayout();
this.xtraTabPage1.SuspendLayout();
this.xtraTabPage2.SuspendLayout();
this.xtraTabPage3.SuspendLayout();
this.xtraTabPage4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.verticalSplitContainerControl1)).BeginInit();
this.verticalSplitContainerControl1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.treeList1)).BeginInit();
this.SuspendLayout();
//
// horizontalSplitContainerControl1
//
this.horizontalSplitContainerControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.horizontalSplitContainerControl1.FixedPanel = DevExpress.XtraEditors.SplitFixedPanel.Panel2;
this.horizontalSplitContainerControl1.Horizontal = false;
this.horizontalSplitContainerControl1.Location = new System.Drawing.Point(0, 0);
this.horizontalSplitContainerControl1.Name = "horizontalSplitContainerControl1";
this.horizontalSplitContainerControl1.Panel1.Controls.Add(this.xtraTabControl1);
this.horizontalSplitContainerControl1.Panel1.Controls.Add(this.codeExampleNameLbl);
this.horizontalSplitContainerControl1.Panel1.Text = "Panel1";
this.horizontalSplitContainerControl1.Panel2.Controls.Add(this.displayResultControl1);
this.horizontalSplitContainerControl1.Panel2.Text = "Panel2";
this.horizontalSplitContainerControl1.Size = new System.Drawing.Size(989, 655);
this.horizontalSplitContainerControl1.SplitterPosition = 340;
this.horizontalSplitContainerControl1.TabIndex = 2;
this.horizontalSplitContainerControl1.Text = "splitContainerControl1";
//
// xtraTabControl1
//
this.xtraTabControl1.AppearancePage.PageClient.BackColor = System.Drawing.Color.Transparent;
this.xtraTabControl1.AppearancePage.PageClient.BackColor2 = System.Drawing.Color.Transparent;
this.xtraTabControl1.AppearancePage.PageClient.BorderColor = System.Drawing.Color.Transparent;
this.xtraTabControl1.AppearancePage.PageClient.Options.UseBackColor = true;
this.xtraTabControl1.AppearancePage.PageClient.Options.UseBorderColor = true;
this.xtraTabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.xtraTabControl1.HeaderAutoFill = DevExpress.Utils.DefaultBoolean.True;
this.xtraTabControl1.Location = new System.Drawing.Point(0, 44);
this.xtraTabControl1.Name = "xtraTabControl1";
this.xtraTabControl1.SelectedTabPage = this.xtraTabPage1;
this.xtraTabControl1.Size = new System.Drawing.Size(989, 266);
this.xtraTabControl1.TabIndex = 11;
this.xtraTabControl1.TabPages.AddRange(new DevExpress.XtraTab.XtraTabPage[] {
this.xtraTabPage1,
this.xtraTabPage2,
this.xtraTabPage3,
this.xtraTabPage4});
//
// xtraTabPage1
//
this.xtraTabPage1.Appearance.HeaderActive.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
this.xtraTabPage1.Appearance.HeaderActive.Options.UseFont = true;
this.xtraTabPage1.Controls.Add(this.richEditControlCS);
this.xtraTabPage1.Name = "xtraTabPage1";
this.xtraTabPage1.Size = new System.Drawing.Size(983, 238);
this.xtraTabPage1.Tag = "CS";
this.xtraTabPage1.Text = "CS";
//
// richEditControlCS
//
this.richEditControlCS.ActiveViewType = DevExpress.XtraRichEdit.RichEditViewType.Draft;
this.richEditControlCS.Dock = System.Windows.Forms.DockStyle.Fill;
this.richEditControlCS.EnableToolTips = true;
this.richEditControlCS.Location = new System.Drawing.Point(0, 0);
this.richEditControlCS.Name = "richEditControlCS";
this.richEditControlCS.Options.Export.PlainText.ExportFinalParagraphMark = DevExpress.XtraRichEdit.Export.PlainText.ExportFinalParagraphMark.Never;
this.richEditControlCS.Options.HorizontalRuler.Visibility = DevExpress.XtraRichEdit.RichEditRulerVisibility.Hidden;
this.richEditControlCS.Size = new System.Drawing.Size(983, 238);
this.richEditControlCS.TabIndex = 14;
//
// xtraTabPage2
//
this.xtraTabPage2.Appearance.HeaderActive.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
this.xtraTabPage2.Appearance.HeaderActive.Options.UseFont = true;
this.xtraTabPage2.Controls.Add(this.richEditControlVB);
this.xtraTabPage2.Name = "xtraTabPage2";
this.xtraTabPage2.Size = new System.Drawing.Size(983, 238);
this.xtraTabPage2.Tag = "VB";
this.xtraTabPage2.Text = "VB";
//
// richEditControlVB
//
this.richEditControlVB.ActiveViewType = DevExpress.XtraRichEdit.RichEditViewType.Draft;
this.richEditControlVB.Dock = System.Windows.Forms.DockStyle.Fill;
this.richEditControlVB.EnableToolTips = true;
this.richEditControlVB.Location = new System.Drawing.Point(0, 0);
this.richEditControlVB.Name = "richEditControlVB";
this.richEditControlVB.Options.Export.PlainText.ExportFinalParagraphMark = DevExpress.XtraRichEdit.Export.PlainText.ExportFinalParagraphMark.Never;
this.richEditControlVB.Options.HorizontalRuler.Visibility = DevExpress.XtraRichEdit.RichEditRulerVisibility.Hidden;
this.richEditControlVB.Size = new System.Drawing.Size(983, 238);
this.richEditControlVB.TabIndex = 15;
//
// xtraTabPage3
//
this.xtraTabPage3.Controls.Add(this.richEditControlCSClass);
this.xtraTabPage3.Name = "xtraTabPage3";
this.xtraTabPage3.Size = new System.Drawing.Size(983, 238);
this.xtraTabPage3.Tag = "CS";
this.xtraTabPage3.Text = "СS Helper";
//
// richEditControlCSClass
//
this.richEditControlCSClass.ActiveViewType = DevExpress.XtraRichEdit.RichEditViewType.Draft;
this.richEditControlCSClass.Dock = System.Windows.Forms.DockStyle.Fill;
this.richEditControlCSClass.EnableToolTips = true;
this.richEditControlCSClass.Location = new System.Drawing.Point(0, 0);
this.richEditControlCSClass.Name = "richEditControlCSClass";
this.richEditControlCSClass.Options.Export.PlainText.ExportFinalParagraphMark = DevExpress.XtraRichEdit.Export.PlainText.ExportFinalParagraphMark.Never;
this.richEditControlCSClass.Options.HorizontalRuler.Visibility = DevExpress.XtraRichEdit.RichEditRulerVisibility.Hidden;
this.richEditControlCSClass.Size = new System.Drawing.Size(983, 238);
this.richEditControlCSClass.TabIndex = 0;
//
// xtraTabPage4
//
this.xtraTabPage4.Controls.Add(this.richEditControlVBClass);
this.xtraTabPage4.Name = "xtraTabPage4";
this.xtraTabPage4.Size = new System.Drawing.Size(983, 238);
this.xtraTabPage4.Tag = "VB";
this.xtraTabPage4.Text = "VB Helper";
//
// richEditControlVBClass
//
this.richEditControlVBClass.ActiveViewType = DevExpress.XtraRichEdit.RichEditViewType.Draft;
this.richEditControlVBClass.Dock = System.Windows.Forms.DockStyle.Fill;
this.richEditControlVBClass.EnableToolTips = true;
this.richEditControlVBClass.Location = new System.Drawing.Point(0, 0);
this.richEditControlVBClass.Name = "richEditControlVBClass";
this.richEditControlVBClass.Options.Export.PlainText.ExportFinalParagraphMark = DevExpress.XtraRichEdit.Export.PlainText.ExportFinalParagraphMark.Never;
this.richEditControlVBClass.Options.HorizontalRuler.Visibility = DevExpress.XtraRichEdit.RichEditRulerVisibility.Hidden;
this.richEditControlVBClass.Size = new System.Drawing.Size(983, 238);
this.richEditControlVBClass.TabIndex = 1;
//
// codeExampleNameLbl
//
this.codeExampleNameLbl.Appearance.Font = new System.Drawing.Font("Arial", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.codeExampleNameLbl.Dock = System.Windows.Forms.DockStyle.Top;
this.codeExampleNameLbl.Location = new System.Drawing.Point(0, 0);
this.codeExampleNameLbl.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5);
this.codeExampleNameLbl.Name = "codeExampleNameLbl";
this.codeExampleNameLbl.Padding = new System.Windows.Forms.Padding(0, 0, 0, 12);
this.codeExampleNameLbl.Size = new System.Drawing.Size(72, 44);
this.codeExampleNameLbl.TabIndex = 10;
this.codeExampleNameLbl.Text = "label1";
//
// displayResultControl1
//
this.displayResultControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.displayResultControl1.Location = new System.Drawing.Point(0, 0);
this.displayResultControl1.Name = "displayResultControl1";
this.displayResultControl1.Size = new System.Drawing.Size(989, 340);
this.displayResultControl1.TabIndex = 0;
//
// verticalSplitContainerControl1
//
this.verticalSplitContainerControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.verticalSplitContainerControl1.FixedPanel = DevExpress.XtraEditors.SplitFixedPanel.Panel2;
this.verticalSplitContainerControl1.Location = new System.Drawing.Point(0, 0);
this.verticalSplitContainerControl1.Name = "verticalSplitContainerControl1";
this.verticalSplitContainerControl1.Panel1.Controls.Add(this.horizontalSplitContainerControl1);
this.verticalSplitContainerControl1.Panel1.Text = "Panel1";
this.verticalSplitContainerControl1.Panel2.Controls.Add(this.treeList1);
this.verticalSplitContainerControl1.Panel2.Text = "Panel2";
this.verticalSplitContainerControl1.Size = new System.Drawing.Size(1212, 655);
this.verticalSplitContainerControl1.SplitterPosition = 218;
this.verticalSplitContainerControl1.TabIndex = 0;
this.verticalSplitContainerControl1.Text = "verticalSplitContainerControl1";
//
// treeList1
//
this.treeList1.Appearance.FocusedCell.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Underline);
this.treeList1.Appearance.FocusedCell.Options.UseFont = true;
this.treeList1.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeList1.Location = new System.Drawing.Point(0, 0);
this.treeList1.Name = "treeList1";
this.treeList1.Size = new System.Drawing.Size(218, 655);
this.treeList1.TabIndex = 11;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1212, 655);
this.Controls.Add(this.verticalSplitContainerControl1);
this.Name = "Form1";
((System.ComponentModel.ISupportInitialize)(this.horizontalSplitContainerControl1)).EndInit();
this.horizontalSplitContainerControl1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.xtraTabControl1)).EndInit();
this.xtraTabControl1.ResumeLayout(false);
this.xtraTabPage1.ResumeLayout(false);
this.xtraTabPage2.ResumeLayout(false);
this.xtraTabPage3.ResumeLayout(false);
this.xtraTabPage4.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.verticalSplitContainerControl1)).EndInit();
this.verticalSplitContainerControl1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.treeList1)).EndInit();
this.ResumeLayout(false);
}
#endregion
LabelControl codeExampleNameLbl;
ExampleCodeEditor codeEditor;
ExampleEvaluatorByTimer evaluator;
List<CodeExampleGroup> examples;
private XtraTabPage xtraTabPage3;
private RichEditControl richEditControlCSClass;
private XtraTabPage xtraTabPage4;
private RichEditControl richEditControlVBClass;
bool treeListRootNodeLoading = true;
private SpreadsheetControl spreadsheetControl;
public Form1()
{
InitializeComponent();
InitializeRichEditControl();
string examplePath = CodeExampleDemoUtils.GetExamplePath("CodeExamples");
Dictionary<string, FileInfo> examplesCS = CodeExampleDemoUtils.GatherExamplesFromProject(examplePath, ExampleLanguage.Csharp);
Dictionary<string, FileInfo> examplesVB = CodeExampleDemoUtils.GatherExamplesFromProject(examplePath, ExampleLanguage.VB);
DisableTabs(examplesCS.Count, examplesVB.Count);
this.examples = CodeExampleDemoUtils.FindExamples(examplePath, examplesCS, examplesVB);
ShowExamplesInTreeList(treeList1, examples);
this.codeEditor = new ExampleCodeEditor(richEditControlCS, richEditControlVB, richEditControlCSClass, richEditControlVBClass);
CurrentExampleLanguage = CodeExampleDemoUtils.DetectExampleLanguage("SpreadsheetControl_API_Part03");
this.evaluator = new RichEditExampleEvaluatorByTimer();
this.evaluator.QueryEvaluate += OnExampleEvaluatorQueryEvaluate;
this.evaluator.OnBeforeCompile += evaluator_OnBeforeCompile;
this.evaluator.OnAfterCompile += evaluator_OnAfterCompile;
this.xtraTabControl1.SelectedPageChanged += xtraTabControl1_SelectedPageChanged;
ShowFirstExample("Data Validation Actions");
}
private void InitializeRichEditControl()
{
this.spreadsheetControl = this.displayResultControl1.Speadsheet;
}
public ExampleLanguage CurrentExampleLanguage
{
get
{
if (xtraTabControl1.SelectedTabPage.Tag.ToString() == "CS") return ExampleLanguage.Csharp;
else return ExampleLanguage.VB;
}
set
{
this.codeEditor.CurrentExampleLanguage = value;
//xtraTabControl1.SelectedTabPageIndex = (value == ExampleLanguage.Csharp) ? 0 : 1;
}
}
void ShowExamplesInTreeList(TreeList treeList, List<CodeExampleGroup> examples)
{
#region InitializeTreeList
treeList.OptionsPrint.UsePrintStyles = true;
treeList.FocusedNodeChanged += new DevExpress.XtraTreeList.FocusedNodeChangedEventHandler(this.OnNewExampleSelected);
treeList.OptionsView.ShowColumns = false;
treeList.OptionsView.ShowIndicator = false;
treeList.VirtualTreeGetChildNodes += treeList_VirtualTreeGetChildNodes;
treeList.VirtualTreeGetCellValue += treeList_VirtualTreeGetCellValue;
#endregion
TreeListColumn col1 = new TreeListColumn();
col1.VisibleIndex = 0;
col1.OptionsColumn.AllowEdit = false;
col1.OptionsColumn.AllowMove = false;
col1.OptionsColumn.ReadOnly = true;
treeList.Columns.AddRange(new TreeListColumn[] { col1 });
treeList.DataSource = new Object();
treeList.ExpandAll();
}
void treeList_VirtualTreeGetCellValue(object sender, VirtualTreeGetCellValueInfo args)
{
CodeExampleGroup group = args.Node as CodeExampleGroup;
if (group != null)
args.CellData = group.Name;
CodeExample example = args.Node as CodeExample;
if (example != null)
args.CellData = example.RegionName;
}
void treeList_VirtualTreeGetChildNodes(object sender, VirtualTreeGetChildNodesInfo args)
{
if (treeListRootNodeLoading)
{
args.Children = examples;
treeListRootNodeLoading = false;
}
else
{
if (args.Node == null)
return;
CodeExampleGroup group = args.Node as CodeExampleGroup;
if (group != null)
args.Children = group.Examples;
}
}
void ShowFirstExample(string firstGroupName)
{
treeList1.ExpandAll();
if (treeList1.Nodes.Count > 0)
treeList1.FocusedNode = treeList1.FindNodeByFieldValue("", firstGroupName).NextVisibleNode;
}
void evaluator_OnAfterCompile(object sender, OnAfterCompileEventArgs args)
{
codeEditor.AfterCompile(args.Result);
}
void evaluator_OnBeforeCompile(object sender, EventArgs e)
{
IWorkbook document = spreadsheetControl.Document;
document.BeginUpdate();
codeEditor.BeforeCompile();
spreadsheetControl.CreateNewDocument();
document.Unit = DevExpress.Office.DocumentUnit.Document;
document.EndUpdate();
}
void OnNewExampleSelected(object sender, FocusedNodeChangedEventArgs e)
{
CodeExample newExample = (sender as TreeList).GetDataRecordByNode(e.Node) as CodeExample;
CodeExample oldExample = (sender as TreeList).GetDataRecordByNode(e.OldNode) as CodeExample;
if (newExample == null)
return;
string exampleCode = codeEditor.ShowExample(oldExample, newExample);
codeExampleNameLbl.Text = CodeExampleDemoUtils.ConvertStringToMoreHumanReadableForm(newExample.RegionName) + " example";
CodeEvaluationEventArgs args = new CodeEvaluationEventArgs();
InitializeCodeEvaluationEventArgs(args);
evaluator.ForceCompile(args);
}
void InitializeCodeEvaluationEventArgs(CodeEvaluationEventArgs e)
{
e.Result = true;
e.Code = codeEditor.CurrentCodeEditor.Text;
e.CodeClasses = codeEditor.CurrentCodeClassEditor.Text;
e.Language = CurrentExampleLanguage;
e.EvaluationParameter = spreadsheetControl.Document;
}
void OnExampleEvaluatorQueryEvaluate(object sender, CodeEvaluationEventArgs e)
{
e.Result = false;
if (codeEditor.RichEditTextChanged)
{// && compileComplete) {
TimeSpan span = DateTime.Now - codeEditor.LastExampleCodeModifiedTime;
if (span < TimeSpan.FromMilliseconds(1000))
{//CompileTimeIntervalInMilliseconds 1900
codeEditor.ResetLastExampleModifiedTime();
return;
}
//e.Result = true;
InitializeCodeEvaluationEventArgs(e);
}
}
void DisableTabs(int examplesCSCount, int examplesVBCount)
{
if (examplesCSCount == 0)
foreach (XtraTabPage t in xtraTabControl1.TabPages) if (t.Tag.ToString() == "CS") t.PageEnabled = false;
if (examplesVBCount == 0)
foreach (XtraTabPage t in xtraTabControl1.TabPages) if (t.Tag.ToString() == "VB") t.PageEnabled = false;
}
void xtraTabControl1_SelectedPageChanged(object sender, TabPageChangedEventArgs e)
{
CurrentExampleLanguage = (e.Page.Tag.ToString() == "CS") ? ExampleLanguage.Csharp : ExampleLanguage.VB;
}
}
}