-
Notifications
You must be signed in to change notification settings - Fork 1
/
Editors.cs
299 lines (258 loc) · 8.58 KB
/
Editors.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
/*
* Creato da SharpDevelop.
* Utente: michele
* Data: 29/01/2009
* Ora: 8.41
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
using wx;
namespace mkdb
{
// Stupid thing
public class wxFont : wx.Font
{
public override string ToString()
{
return this.FaceName + "; " + this.PointSize + "pt";
}
}
public class wxColor : wx.Colour
{
public override string ToString()
{
return this.Red + "; " + this.Green + "; " + this.Blue;
}
}
public class wxFlags : Hashtable
{
public override string ToString()
{
string str = "";
foreach (DictionaryEntry d in this)
{
str += " ;" + d.Key;
}
return str;
}
}
/// <summary>
/// Description of wxFontEditors.
/// </summary>
public class wxColorEditors : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
// We will use a window for property editing.
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
System.Drawing.Color winColor;
if (context == null || context.Instance == null || provider == null)
return value;
wxColor color = (wxColor)value;
System.Windows.Forms.ColorDialog colDialog = new System.Windows.Forms.ColorDialog();
colDialog.Color = new System.Drawing.Color();
colDialog.Color = System.Drawing.Color.FromArgb(255, color.Red, color.Green, color.Blue);
if (colDialog.ShowDialog() != DialogResult.Cancel)
{
winColor = colDialog.Color;
color.Set(winColor.R, winColor.G, winColor.B);
}
return color;
}
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return true;
}
public override void PaintValue(PaintValueEventArgs e)
{
if (e.Value != null)
{
if (e.Value is wxColor)
{
System.Drawing.Color col = new System.Drawing.Color();
col = System.Drawing.Color.FromArgb(255, ((wxColor)e.Value).Red,
((wxColor)e.Value).Green,
((wxColor)e.Value).Blue);
System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(col);
e.Graphics.FillRectangle(brush, e.Bounds);
}
}
base.PaintValue(e);
}
}
/// <summary>
/// Description of wxFontEditors.
/// </summary>
public class wxFontEditors : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
// We will use a window for property editing.
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
System.Drawing.Font winFont = null;
if (context == null || context.Instance == null || provider == null)
return value;
wxFont wfnt = (wxFont)value;
System.Windows.Forms.FontDialog fontDialog = new System.Windows.Forms.FontDialog();
fontDialog.Font = new System.Drawing.Font(wfnt.FaceName, wfnt.PointSize);
if (fontDialog.ShowDialog() != DialogResult.Cancel)
{
winFont = fontDialog.Font;
wfnt.FaceName = winFont.Name;
if (winFont.Bold) wfnt.Family &= FontFamily.wxBOLD;
if (winFont.Italic) wfnt.Family &= FontFamily.wxITALIC;
if (winFont.Underline) wfnt.Underlined = true; else wfnt.Underlined = false;
wfnt.PointSize = (int)winFont.SizeInPoints;
}
return wfnt;
}
}
/*
/// <summary>
/// Implements a custom type editor for selecting a <see cref="SemiNavigationPage"/> in a list
/// </summary>
public class wxFlagsEditor : UITypeEditor
{
private IWindowsFormsEditorService edSvc = null;
private CheckedListBox clb;
private ToolTip tooltipControl;
/// <summary>
/// Internal class used for storing custom data in listviewitems
/// </summary>
internal class clbItem
{
private string _name;
private int _val;
public clbItem(string name, int val)
{
_name = name;
_val = val;
}
public string Name
{
get { return _name; }
}
public int Value
{
get { return _val; }
}
}
/// <summary>
/// Overrides the method used to provide basic behaviour for selecting editor.
/// Shows our custom control for editing the value.
/// </summary>
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (context != null || context.Instance != null || provider != null)
return value;
edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc != null)
{
// Create a CheckedListBox and populate it with all the enum values
clb = new CheckedListBox();
clb.BorderStyle = BorderStyle.FixedSingle;
clb.CheckOnClick = true;
clb.MouseDown += new MouseEventHandler(this.OnMouseDown);
clb.MouseMove += new MouseEventHandler(this.OnMouseMoved);
Hashtable ht = (Hashtable)value;
foreach (DictionaryEntry d in ht)
{
clbItem = new clbItem(d.Key, d.Value);
clb.Items.Add(clbItem, true);
}
foreach(string name in Enum.GetNames(context.PropertyDescriptor.PropertyType))
{
// Get the enum value
object enumVal = Enum.Parse(context.PropertyDescriptor.PropertyType, name);
// Get the int value
int intVal = (int) Convert.ChangeType(enumVal, typeof(int));
// Get the description attribute for this field
System.Reflection.FieldInfo fi = context.PropertyDescriptor.PropertyType.GetField(name);
DescriptionAttribute[] attrs = (DescriptionAttribute[]) fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
// Store the the description
string tooltip = attrs.Length > 0 ? attrs[0].Description : string.Empty;
// Get the int value of the current enum value (the one being edited)
int intEdited = (int) Convert.ChangeType(value, typeof(int));
// Creates a clbItem that stores the name, the int value and the tooltip
clbItem item = new clbItem(enumVal.ToString(), intVal, tooltip);
// Get the checkstate from the value being edited
bool checkedItem = (intEdited & intVal) > 0;
// Add the item with the right check state
clb.Items.Add(item, checkedItem);
}
// Show our CheckedListbox as a DropDownControl.
// This methods returns only when the dropdowncontrol is closed
edSvc.DropDownControl(clb);
// Get the sum of all checked flags
int result = 0;
foreach(clbItem obj in clb.CheckedItems)
{
result += obj.Value;
}
// return the right enum value corresponding to the result
return Enum.ToObject(context.PropertyDescriptor.PropertyType, result);
}
}
return value;
}
/// <summary>
/// Shows a dropdown icon in the property editor
/// </summary>
/// <param name="context">The context of the editing control</param>
/// <returns>Returns <c>UITypeEditorEditStyle.DropDown</c></returns>
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
private bool handleLostfocus = false;
/// <summary>
/// When got the focus, handle the lost focus event.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnMouseDown(object sender, MouseEventArgs e)
{
if(!handleLostfocus && clb.ClientRectangle.Contains(clb.PointToClient(new Point(e.X, e.Y))))
{
clb.LostFocus += new EventHandler(this.ValueChanged);
handleLostfocus = true;
}
}
/// <summary>
/// Occurs when the mouse is moved over the checkedlistbox.
/// Sets the tooltip of the item under the pointer
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnMouseMoved(object sender, MouseEventArgs e)
{
int index = clb.IndexFromPoint(e.X, e.Y);
if(index >= 0)
tooltipControl.SetToolTip(clb, ((clbItem) clb.Items[index]).Tooltip);
}
/// <summary>
/// Close the dropdowncontrol when the user has selected a value
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ValueChanged(object sender, EventArgs e)
{
if (edSvc != null)
{
edSvc.CloseDropDown();
}
}
}
*/
}