forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommon.cs
More file actions
500 lines (450 loc) · 19.7 KB
/
Common.cs
File metadata and controls
500 lines (450 loc) · 19.7 KB
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
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel.Design;
using System.Windows.Forms;
using System.Reflection;
using PluginCore.Helpers;
using PluginCore.Managers;
using PluginCore;
namespace System.Windows.Forms
{
public class ToolStripSpringComboBox : ToolStripComboBoxEx
{
public ToolStripSpringComboBox()
{
this.Control.PreviewKeyDown += new PreviewKeyDownEventHandler(this.OnPreviewKeyDown);
}
/// <summary>
/// Fixes the Control+Alt (AltGr) key combination handling
/// </summary>
private void OnPreviewKeyDown(Object sender, PreviewKeyDownEventArgs e)
{
Keys ctrlAlt = Keys.Control | Keys.Alt;
if ((e.KeyData & ctrlAlt) == ctrlAlt) e.IsInputKey = true;
}
/// <summary>
/// Makes the control spring automaticly
/// </summary>
public override Size GetPreferredSize(Size constrainingSize)
{
// Use the default size if the text box is on the overflow menu
// or is on a vertical ToolStrip.
if (IsOnOverflow || Owner.Orientation == Orientation.Vertical)
{
return DefaultSize;
}
// Declare a variable to store the total available width as
// it is calculated, starting with the display width of the
// owning ToolStrip.
Int32 width = Owner.DisplayRectangle.Width;
// Subtract the width of the overflow button if it is displayed.
if (Owner.OverflowButton.Visible)
{
width = width - Owner.OverflowButton.Width - Owner.OverflowButton.Margin.Horizontal;
}
// Declare a variable to maintain a count of ToolStripSpringComboBox
// items currently displayed in the owning ToolStrip.
Int32 springBoxCount = 0;
foreach (ToolStripItem item in Owner.Items)
{
// Ignore items on the overflow menu.
if (item.IsOnOverflow) continue;
if (item is ToolStripSpringComboBox)
{
// For ToolStripSpringComboBox items, increment the count and
// subtract the margin width from the total available width.
springBoxCount++;
width -= item.Margin.Horizontal;
}
else
{
// For all other items, subtract the full width from the total
// available width.
width = width - item.Width - item.Margin.Horizontal;
}
}
// If there are multiple ToolStripSpringComboBox items in the owning
// ToolStrip, divide the total available width between them.
if (springBoxCount > 1) width /= springBoxCount;
// If the available width is less than the default width, use the
// default width, forcing one or more items onto the overflow menu.
if (width < DefaultSize.Width) width = DefaultSize.Width;
// Retrieve the preferred size from the base class, but change the
// width to the calculated width.
Size size = base.GetPreferredSize(constrainingSize);
size.Width = width;
return size;
}
}
public class ToolStripSpringTextBox : ToolStripTextBox
{
public ToolStripSpringTextBox()
{
this.Control.PreviewKeyDown += new PreviewKeyDownEventHandler(this.OnPreviewKeyDown);
}
/// <summary>
/// Fixes the Control+Alt (AltGr) key combination handling
/// </summary>
private void OnPreviewKeyDown(Object sender, PreviewKeyDownEventArgs e)
{
Keys ctrlAlt = Keys.Control | Keys.Alt;
if ((e.KeyData & ctrlAlt) == ctrlAlt) e.IsInputKey = true;
}
/// <summary>
/// Makes the control spring automaticly
/// </summary>
public override Size GetPreferredSize(Size constrainingSize)
{
// Use the default size if the text box is on the overflow menu
// or is on a vertical ToolStrip.
if (IsOnOverflow || Owner.Orientation == Orientation.Vertical)
{
return DefaultSize;
}
// Declare a variable to store the total available width as
// it is calculated, starting with the display width of the
// owning ToolStrip.
Int32 width = Owner.DisplayRectangle.Width;
// Subtract the width of the overflow button if it is displayed.
if (Owner.OverflowButton.Visible)
{
width = width - Owner.OverflowButton.Width - Owner.OverflowButton.Margin.Horizontal;
}
// Declare a variable to maintain a count of ToolStripSpringTextBox
// items currently displayed in the owning ToolStrip.
Int32 springBoxCount = 0;
foreach (ToolStripItem item in Owner.Items)
{
// Ignore items on the overflow menu.
if (item.IsOnOverflow) continue;
if (item is ToolStripSpringTextBox)
{
// For ToolStripSpringTextBox items, increment the count and
// subtract the margin width from the total available width.
springBoxCount++;
width -= item.Margin.Horizontal;
}
else
{
// For all other items, subtract the full width from the total
// available width.
width = width - item.Width - item.Margin.Horizontal;
}
}
// If there are multiple ToolStripSpringTextBox items in the owning
// ToolStrip, divide the total available width between them.
if (springBoxCount > 1) width /= springBoxCount;
// If the available width is less than the default width, use the
// default width, forcing one or more items onto the overflow menu.
if (width < DefaultSize.Width) width = DefaultSize.Width;
// Retrieve the preferred size from the base class, but change the
// width to the calculated width.
Size size = base.GetPreferredSize(constrainingSize);
size.Width = width;
return size;
}
}
public class DataGridViewEx : DataGridView, IEventHandler
{
public DataGridViewEx()
{
this.CellPainting += this.OnDataGridViewCellPainting;
EventManager.AddEventHandler(this, EventType.ApplyTheme);
}
protected override void Dispose(bool disposing)
{
EventManager.RemoveEventHandler(this);
base.Dispose(disposing);
}
public void HandleEvent(object sender, NotifyEvent e, HandlingPriority priority)
{
if (e.Type == EventType.ApplyTheme)
{
RefreshColors();
}
}
private void RefreshColors()
{
Color fore = PluginBase.MainForm.GetThemeColor("DataGridView.ForeColor");
Color back = PluginBase.MainForm.GetThemeColor("DataGridView.BackColor");
Color border = PluginBase.MainForm.GetThemeColor("ColumnHeader.BorderColor");
DefaultCellStyle.ForeColor = (fore != Color.Empty) ? fore : SystemColors.WindowText;
DefaultCellStyle.BackColor = (back != Color.Empty) ? back : SystemColors.Window;
GridColor = (border != Color.Empty) ? border : SystemColors.ControlDark;
}
private void OnDataGridViewCellPainting(Object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex == -1)
{
Color back = PluginBase.MainForm.GetThemeColor("ColumnHeader.BackColor");
Color text = PluginBase.MainForm.GetThemeColor("ColumnHeader.TextColor");
Color border = PluginBase.MainForm.GetThemeColor("ColumnHeader.BorderColor");
if (back != Color.Empty && border != Color.Empty && text != Color.Empty)
{
this.EnableHeadersVisualStyles = false;
this.ColumnHeadersDefaultCellStyle.ForeColor = text;
e.Graphics.FillRectangle(new SolidBrush(back), e.CellBounds);
e.Graphics.DrawLine(new Pen(border), e.CellBounds.X, e.CellBounds.Height - 1, e.CellBounds.X + e.CellBounds.Width, e.CellBounds.Height - 1);
e.Graphics.DrawLine(new Pen(border), e.CellBounds.X + e.CellBounds.Width - 1, 3, e.CellBounds.X + e.CellBounds.Width - 1, e.CellBounds.Height - 6);
e.PaintContent(e.ClipBounds);
e.Handled = true;
}
else this.EnableHeadersVisualStyles = true;
}
}
}
public class ListViewEx : ListView
{
private Timer expandDelay;
public Boolean UseTheme = true;
public ListViewEx()
{
this.OwnerDraw = true;
this.DrawColumnHeader += this.OnDrawColumnHeader;
this.DrawSubItem += this.OnDrawSubItem;
this.DrawItem += this.OnDrawItem;
this.expandDelay = new Timer();
this.expandDelay.Interval = 50;
this.expandDelay.Tick += this.ExpandDelayTick;
this.expandDelay.Enabled = true;
this.expandDelay.Start();
}
private void OnDrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
e.DrawDefault = true;
}
private void OnDrawItem(object sender, DrawListViewItemEventArgs e)
{
e.DrawDefault = true;
}
private void OnDrawColumnHeader(Object sender, DrawListViewColumnHeaderEventArgs e)
{
Color back = PluginBase.MainForm.GetThemeColor("ColumnHeader.BackColor");
Color text = PluginBase.MainForm.GetThemeColor("ColumnHeader.TextColor");
Color border = PluginBase.MainForm.GetThemeColor("ColumnHeader.BorderColor");
if (UseTheme && back != Color.Empty && border != Color.Empty && text != Color.Empty)
{
e.Graphics.FillRectangle(new SolidBrush(back), e.Bounds.X, 0, e.Bounds.Width, e.Bounds.Height);
e.Graphics.DrawLine(new Pen(border), e.Bounds.X, e.Bounds.Height - 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Height - 1);
e.Graphics.DrawLine(new Pen(border), e.Bounds.X + e.Bounds.Width - 1, 3, e.Bounds.X + e.Bounds.Width - 1, e.Bounds.Height - 6);
Int32 textHeight = TextRenderer.MeasureText("HeightTest", e.Font).Height + 1;
Rectangle textRect = new Rectangle(e.Bounds.X + 3, e.Bounds.Y + (e.Bounds.Height / 2) - (textHeight / 2), e.Bounds.Width, e.Bounds.Height);
TextRenderer.DrawText(e.Graphics, e.Header.Text, e.Font, textRect.Location, text);
}
else e.DrawDefault = true;
}
private void ExpandDelayTick(object sender, EventArgs e)
{
this.expandDelay.Enabled = false;
if (this.View == View.Details && this.Columns.Count > 0)
{
this.Columns[this.Columns.Count - 1].Width = -2;
}
}
protected override void WndProc(ref Message message)
{
switch (message.Msg)
{
case 0xf: // WM_PAINT
// Delay column expand...
this.expandDelay.Enabled = true;
break;
}
base.WndProc(ref message);
}
}
public class ToolStripComboBoxEx : ToolStripControlHost
{
public ToolStripComboBoxEx() : base(new FlatCombo())
{
Font font = PluginBase.Settings.DefaultFont;
this.FlatCombo.Font = font;
}
protected override Size DefaultSize
{
get { return new Size(100, 22); }
}
public ComboBoxStyle DropDownStyle
{
set { this.FlatCombo.DropDownStyle = value; }
get { return this.FlatCombo.DropDownStyle; }
}
public FlatStyle FlatStyle
{
set { this.FlatCombo.FlatStyle = value; }
get { return this.FlatCombo.FlatStyle; }
}
public Int32 SelectedIndex
{
set { this.FlatCombo.SelectedIndex = value; }
get { return this.FlatCombo.SelectedIndex; }
}
public Object SelectedItem
{
set { this.FlatCombo.SelectedItem = value; }
get { return this.FlatCombo.SelectedItem; }
}
public FlatCombo.ObjectCollection Items
{
get { return this.FlatCombo.Items; }
}
public FlatCombo FlatCombo
{
get { return this.Control as FlatCombo; }
}
}
public class FlatCombo : ComboBox, IEventHandler
{
private Boolean useTheme = true;
private Pen BorderPen = new Pen(SystemColors.ControlDark);
private SolidBrush BackBrush = new SolidBrush(SystemColors.Window);
private SolidBrush ArrowBrush = new SolidBrush(SystemColors.ControlText);
private ComboBoxStyle prevStyle = ComboBoxStyle.DropDown;
private Boolean updatingStyle = false;
public FlatCombo()
{
this.UseTheme = true;
EventManager.AddEventHandler(this, EventType.ApplyTheme);
}
protected override void Dispose(bool disposing)
{
EventManager.RemoveEventHandler(this);
base.Dispose(disposing);
}
public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority)
{
if (e.Type == EventType.ApplyTheme)
{
this.FlatStyle = PluginBase.Settings.ComboBoxFlatStyle;
this.UseTheme = (this.FlatStyle == FlatStyle.Popup);
}
}
public Boolean UseTheme
{
get { return this.useTheme; }
set
{
this.useTheme = value;
this.RefreshColors();
}
}
private void RefreshColors()
{
Color fore = PluginBase.MainForm.GetThemeColor("ToolStripComboBoxControl.ForeColor");
Color back = PluginBase.MainForm.GetThemeColor("ToolStripComboBoxControl.BackColor");
Color border = PluginBase.MainForm.GetThemeColor("ToolStripComboBoxControl.BorderColor");
if (fore == Color.Empty && back == Color.Empty && border == Color.Empty) this.useTheme = false;
this.BorderPen.Color = useTheme && border != Color.Empty ? border : SystemColors.ControlDark;
this.ArrowBrush.Color = useTheme && fore != Color.Empty ? fore : SystemColors.ControlText;
this.BackBrush.Color = useTheme && back != Color.Empty ? back : SystemColors.Window;
this.ForeColor = useTheme && fore != Color.Empty ? fore : SystemColors.ControlText;
this.BackColor = useTheme && back != Color.Empty ? back : SystemColors.Window;
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (!this.useTheme) return;
switch (m.Msg)
{
case 0x85: // WM_NCPAINT
case 0x14: // WM_ERASEBKGND
case 0xf: // WM_PAINT
Int32 pad = ScaleHelper.Scale(2);
Int32 width = ScaleHelper.Scale(18);
Graphics g = this.CreateGraphics();
Rectangle backRect = new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width - 1, this.ClientRectangle.Height - 1);
Rectangle dropRect = new Rectangle(this.ClientRectangle.Right - width, this.ClientRectangle.Y, width, this.ClientRectangle.Height);
if (this.Enabled) g.FillRectangle(BackBrush, dropRect);
g.DrawRectangle(BorderPen, backRect);
Point middle = new Point(dropRect.Left + (dropRect.Width / 2), dropRect.Top + (dropRect.Height / 2));
Point[] arrow = new Point[]
{
new Point(middle.X - pad, middle.Y - 1),
new Point(middle.X + pad + 1, middle.Y - 1),
new Point(middle.X, middle.Y + pad)
};
if (this.Enabled) g.FillPolygon(ArrowBrush, arrow);
else g.FillPolygon(SystemBrushes.ControlDark, arrow);
break;
default:
break;
}
}
protected override void OnEnabledChanged(EventArgs e)
{
base.OnEnabledChanged(e);
this.updatingStyle = true;
if (this.Enabled) this.DropDownStyle = this.prevStyle;
else
{
this.prevStyle = this.DropDownStyle;
this.DropDownStyle = ComboBoxStyle.DropDownList;
}
this.updatingStyle = false;
}
protected override void OnDropDownStyleChanged(EventArgs e)
{
base.OnDropDownStyleChanged(e);
if (!this.updatingStyle) this.prevStyle = this.DropDownStyle;
}
protected override void OnMouseEnter(System.EventArgs e)
{
base.OnMouseEnter(e);
Color border = PluginBase.MainForm.GetThemeColor("ToolStripComboBoxControl.ActiveBorderColor");
BorderPen.Color = border != Color.Empty ? border : SystemColors.Highlight;
this.Invalidate();
}
protected override void OnMouseLeave(System.EventArgs e)
{
base.OnMouseLeave(e);
if (this.Focused) return;
Color border = PluginBase.MainForm.GetThemeColor("ToolStripComboBoxControl.BorderColor");
BorderPen.Color = border != Color.Empty ? border : SystemColors.ControlDark;
this.Invalidate();
}
protected override void OnLostFocus(System.EventArgs e)
{
base.OnLostFocus(e);
Color border = PluginBase.MainForm.GetThemeColor("ToolStripComboBoxControl.BorderColor");
BorderPen.Color = border != Color.Empty ? border : SystemColors.ControlDark;
this.Invalidate();
}
protected override void OnGotFocus(System.EventArgs e)
{
base.OnGotFocus(e);
Color border = PluginBase.MainForm.GetThemeColor("ToolStripComboBoxControl.ActiveBorderColor");
BorderPen.Color = border != Color.Empty ? border : SystemColors.Highlight;
this.Invalidate();
}
protected override void OnMouseHover(System.EventArgs e)
{
base.OnMouseHover(e);
Color border = PluginBase.MainForm.GetThemeColor("ToolStripComboBoxControl.ActiveBorderColor");
BorderPen.Color = border != Color.Empty ? border : SystemColors.Highlight;
this.Invalidate();
}
}
public class DescriptiveCollectionEditor : CollectionEditor
{
public DescriptiveCollectionEditor(Type type) : base(type) {}
protected override CollectionForm CreateCollectionForm()
{
CollectionForm form = base.CreateCollectionForm();
form.Shown += delegate
{
ShowDescription(form);
};
return form;
}
private static void ShowDescription(Control control)
{
PropertyGrid grid = control as PropertyGrid;
if (grid != null) grid.HelpVisible = true;
foreach (Control child in control.Controls)
{
ShowDescription(child);
}
}
}
}