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
|
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2004-2005 Novell, Inc.
//
// Authors:
// Jonathan Chambers ([email protected])
//
// COMPLETE
using System;
using System.Drawing;
using System.ComponentModel;
namespace ShiftUI.PropertyGridInternal
{
internal class PGTextBox : TextBox
{
private bool _focusing = false;
public void FocusAt (Point location)
{
_focusing = true;
Point pnt = PointToClient (location);
XplatUI.SendMessage (Handle, Msg.WM_LBUTTONDOWN, new IntPtr ((int)MsgButtons.MK_LBUTTON), Widget.MakeParam (pnt.X, pnt.Y));
}
protected override bool IsInputKey (Keys keyData)
{
// To be handled by the PropertyGridView
if ((keyData & Keys.Alt) != 0 &&
(keyData & Keys.KeyCode) == Keys.Down)
return true;
return base.IsInputKey (keyData);
}
protected override void WndProc (ref Message m)
{
// Swallow the first MOUSEMOVE after the focusing WM_LBUTTONDOWN
if (_focusing && m.Msg == (int)Msg.WM_MOUSEMOVE) {
_focusing = false;
return;
}
base.WndProc (ref m);
}
}
internal class PropertyGridTextBox : ShiftUI.UserWidget, IMessageFilter
{
#region Private Members
private PGTextBox textbox;
private Button dialog_button;
private Button dropdown_button;
private bool validating = false;
private bool filtering = false;
#endregion Private Members
#region Contructors
public PropertyGridTextBox() {
dialog_button = new Button();
dropdown_button = new Button();
textbox = new PGTextBox ();
SuspendLayout();
dialog_button.Dock = DockStyle.Right;
dialog_button.BackColor = SystemColors.Control;
dialog_button.Size = new Size(16, 16);
dialog_button.TabIndex = 1;
dialog_button.Visible = false;
dialog_button.Click += new System.EventHandler(dialog_button_Click);
dropdown_button.Dock = DockStyle.Right;
dropdown_button.BackColor = SystemColors.Control;
dropdown_button.Size = new Size(16, 16);
dropdown_button.TabIndex = 2;
dropdown_button.Visible = false;
dropdown_button.Click += new System.EventHandler(dropdown_button_Click);
textbox.AutoSize = false;
textbox.BorderStyle = BorderStyle.None;
textbox.Dock = DockStyle.Fill;
textbox.TabIndex = 3;
Widgets.Add(textbox);
Widgets.Add(dropdown_button);
Widgets.Add(dialog_button);
SetStyle (Widgetstyles.Selectable, true);
ResumeLayout(false);
dropdown_button.Paint+=new PaintEventHandler(dropdown_button_Paint);
dialog_button.Paint+=new PaintEventHandler(dialog_button_Paint);
textbox.DoubleClick+=new EventHandler(textbox_DoubleClick);
textbox.KeyDown+=new KeyEventHandler(textbox_KeyDown);
textbox.GotFocus+=new EventHandler(textbox_GotFocus);
}
#endregion Contructors
#region Protected Instance Properties
protected override void OnGotFocus (EventArgs args)
{
base.OnGotFocus (args);
// force-disable selection
textbox.has_been_focused = true;
textbox.Focus ();
textbox.SelectionLength = 0;
}
#endregion
#region Public Instance Properties
public bool DialogButtonVisible {
get{
return dialog_button.Visible;
}
set {
dialog_button.Visible = value;
}
}
public bool DropDownButtonVisible {
get{
return dropdown_button.Visible;
}
set {
dropdown_button.Visible = value;
}
}
public new Color ForeColor {
get {
return base.ForeColor;
}
set {
textbox.ForeColor = value;
dropdown_button.ForeColor = value;
dialog_button.ForeColor = value;
base.ForeColor = value;
}
}
public new Color BackColor {
get {
return base.BackColor;
}
set {
textbox.BackColor = value;
base.BackColor = value;
}
}
public bool ReadOnly {
get {
return textbox.ReadOnly;
}
set {
textbox.ReadOnly = value;
}
}
public new string Text {
get {
return textbox.Text;
}
set {
textbox.Text = value;
}
}
public char PasswordChar {
set { textbox.PasswordChar = value; }
}
#endregion Public Instance Properties
#region Events
static object DropDownButtonClickedEvent = new object ();
static object DialogButtonClickedEvent = new object ();
static object ToggleValueEvent = new object ();
static object KeyDownEvent = new object ();
static object ValidateEvent = new object ();
public event EventHandler DropDownButtonClicked {
add { Events.AddHandler (DropDownButtonClickedEvent, value); }
remove { Events.RemoveHandler (DropDownButtonClickedEvent, value); }
}
public event EventHandler DialogButtonClicked {
add { Events.AddHandler (DialogButtonClickedEvent, value); }
remove { Events.RemoveHandler (DialogButtonClickedEvent, value); }
}
public event EventHandler ToggleValue {
add { Events.AddHandler (ToggleValueEvent, value); }
remove { Events.RemoveHandler (ToggleValueEvent, value); }
}
public new event KeyEventHandler KeyDown {
add { Events.AddHandler (KeyDownEvent, value); }
remove { Events.RemoveHandler (KeyDownEvent, value); }
}
public new event CancelEventHandler Validate {
add { Events.AddHandler (ValidateEvent, value); }
remove { Events.RemoveHandler (ValidateEvent, value); }
}
#endregion Events
#region Private Helper Methods
private void dropdown_button_Paint(object sender, PaintEventArgs e)
{
ThemeEngine.Current.CPDrawComboButton(e.Graphics, dropdown_button.ClientRectangle, dropdown_button.ButtonState);
}
private void dialog_button_Paint(object sender, PaintEventArgs e) {
// best way to draw the ellipse?
e.Graphics.DrawString("...", new Font(Font,FontStyle.Bold), Brushes.Black, 0,0);
}
private void dropdown_button_Click(object sender, EventArgs e) {
EventHandler eh = (EventHandler)(Events [DropDownButtonClickedEvent]);
if (eh != null)
eh (this, e);
}
private void dialog_button_Click(object sender, EventArgs e) {
EventHandler eh = (EventHandler)(Events [DialogButtonClickedEvent]);
if (eh != null)
eh (this, e);
}
#endregion Private Helper Methods
internal void SendMouseDown (Point screenLocation)
{
Point clientLocation = PointToClient (screenLocation);
XplatUI.SendMessage (Handle, Msg.WM_LBUTTONDOWN, new IntPtr ((int) MsgButtons.MK_LBUTTON), Widget.MakeParam (clientLocation.X, clientLocation.Y));
textbox.FocusAt (screenLocation);
}
private void textbox_DoubleClick(object sender, EventArgs e) {
EventHandler eh = (EventHandler)(Events [ToggleValueEvent]);
if (eh != null)
eh (this, e);
}
private void textbox_KeyDown(object sender, KeyEventArgs e) {
KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]);
if (eh != null)
eh (this, e);
}
private void textbox_GotFocus(object sender, EventArgs e) {
if (!filtering) {
filtering = true;
Application.AddMessageFilter ((IMessageFilter)this);
}
}
protected override void DestroyHandle ()
{
Application.RemoveMessageFilter ((IMessageFilter)this);
filtering = false;
base.DestroyHandle ();
}
bool IMessageFilter.PreFilterMessage(ref Message m)
{
// validating check is to allow whatever UI code to execute
// without filtering messages (i.e. error dialogs, etc)
//
if (!validating && m.HWnd != textbox.Handle && textbox.Focused &&
(m.Msg == (int)Msg.WM_LBUTTONDOWN ||
m.Msg == (int)Msg.WM_MBUTTONDOWN ||
m.Msg == (int)Msg.WM_RBUTTONDOWN ||
m.Msg == (int)Msg.WM_NCLBUTTONDOWN ||
m.Msg == (int)Msg.WM_NCMBUTTONDOWN ||
m.Msg == (int)Msg.WM_NCRBUTTONDOWN)) {
CancelEventHandler validateHandler = (CancelEventHandler)(Events [ValidateEvent]);
if (validateHandler != null) {
CancelEventArgs args = new CancelEventArgs ();
validating = true;
validateHandler (this, args);
validating = false;
if (!args.Cancel) {
Application.RemoveMessageFilter ((IMessageFilter)this);
filtering = false;
}
return args.Cancel;
}
}
return false;
}
}
}
|