1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2005 Novell, Inc.
23 // Jonathan Chambers (jonathan.chambers@ansys.com)
30 using System.ComponentModel;
32 namespace System.Windows.Forms.PropertyGridInternal
34 internal class PGTextBox : TextBox
36 private bool _focusing = false;
38 public void FocusAt (Point location)
41 Point pnt = PointToClient (location);
42 XplatUI.SendMessage (Handle, Msg.WM_LBUTTONDOWN, new IntPtr ((int)MsgButtons.MK_LBUTTON), Control.MakeParam (pnt.X, pnt.Y));
45 protected override bool IsInputKey (Keys keyData)
47 // To be handled by the PropertyGridView
48 if ((keyData & Keys.Alt) != 0 &&
49 (keyData & Keys.KeyCode) == Keys.Down)
51 return base.IsInputKey (keyData);
54 protected override void WndProc (ref Message m)
56 // Swallow the first MOUSEMOVE after the focusing WM_LBUTTONDOWN
57 if (_focusing && m.Msg == (int)Msg.WM_MOUSEMOVE) {
65 internal class PropertyGridTextBox : System.Windows.Forms.UserControl, IMessageFilter
67 #region Private Members
69 private PGTextBox textbox;
70 private Button dialog_button;
71 private Button dropdown_button;
72 private bool validating = false;
73 private bool filtering = false;
75 #endregion Private Members
78 public PropertyGridTextBox() {
79 dialog_button = new Button();
80 dropdown_button = new Button();
81 textbox = new PGTextBox ();
85 dialog_button.Dock = DockStyle.Right;
86 dialog_button.BackColor = SystemColors.Control;
87 dialog_button.Size = new Size(16, 16);
88 dialog_button.TabIndex = 1;
89 dialog_button.Visible = false;
90 dialog_button.Click += new System.EventHandler(dialog_button_Click);
92 dropdown_button.Dock = DockStyle.Right;
93 dropdown_button.BackColor = SystemColors.Control;
94 dropdown_button.Size = new Size(16, 16);
95 dropdown_button.TabIndex = 2;
96 dropdown_button.Visible = false;
97 dropdown_button.Click += new System.EventHandler(dropdown_button_Click);
99 textbox.AutoSize = false;
100 textbox.BorderStyle = BorderStyle.None;
101 textbox.Dock = DockStyle.Fill;
102 textbox.TabIndex = 3;
104 Controls.Add(textbox);
105 Controls.Add(dropdown_button);
106 Controls.Add(dialog_button);
108 SetStyle (ControlStyles.Selectable, true);
112 dropdown_button.Paint+=new PaintEventHandler(dropdown_button_Paint);
113 dialog_button.Paint+=new PaintEventHandler(dialog_button_Paint);
114 textbox.DoubleClick+=new EventHandler(textbox_DoubleClick);
115 textbox.KeyDown+=new KeyEventHandler(textbox_KeyDown);
116 textbox.GotFocus+=new EventHandler(textbox_GotFocus);
120 #endregion Contructors
122 #region Protected Instance Properties
124 protected override void OnGotFocus (EventArgs args)
126 base.OnGotFocus (args);
127 // force-disable selection
128 textbox.has_been_focused = true;
130 textbox.SelectionLength = 0;
135 #region Public Instance Properties
137 public bool DialogButtonVisible {
139 return dialog_button.Visible;
142 dialog_button.Visible = value;
145 public bool DropDownButtonVisible {
147 return dropdown_button.Visible;
150 dropdown_button.Visible = value;
154 public new Color ForeColor {
156 return base.ForeColor;
159 textbox.ForeColor = value;
160 dropdown_button.ForeColor = value;
161 dialog_button.ForeColor = value;
162 base.ForeColor = value;
166 public new Color BackColor {
168 return base.BackColor;
171 textbox.BackColor = value;
172 base.BackColor = value;
175 public bool ReadOnly {
177 return textbox.ReadOnly;
180 textbox.ReadOnly = value;
184 public new string Text {
189 textbox.Text = value;
193 public char PasswordChar {
194 set { textbox.PasswordChar = value; }
197 #endregion Public Instance Properties
200 static object DropDownButtonClickedEvent = new object ();
201 static object DialogButtonClickedEvent = new object ();
202 static object ToggleValueEvent = new object ();
203 static object KeyDownEvent = new object ();
204 static object ValidateEvent = new object ();
206 public event EventHandler DropDownButtonClicked {
207 add { Events.AddHandler (DropDownButtonClickedEvent, value); }
208 remove { Events.RemoveHandler (DropDownButtonClickedEvent, value); }
211 public event EventHandler DialogButtonClicked {
212 add { Events.AddHandler (DialogButtonClickedEvent, value); }
213 remove { Events.RemoveHandler (DialogButtonClickedEvent, value); }
216 public event EventHandler ToggleValue {
217 add { Events.AddHandler (ToggleValueEvent, value); }
218 remove { Events.RemoveHandler (ToggleValueEvent, value); }
221 public new event KeyEventHandler KeyDown {
222 add { Events.AddHandler (KeyDownEvent, value); }
223 remove { Events.RemoveHandler (KeyDownEvent, value); }
226 public new event CancelEventHandler Validate {
227 add { Events.AddHandler (ValidateEvent, value); }
228 remove { Events.RemoveHandler (ValidateEvent, value); }
232 #region Private Helper Methods
234 private void dropdown_button_Paint(object sender, PaintEventArgs e)
236 ThemeEngine.Current.CPDrawComboButton(e.Graphics, dropdown_button.ClientRectangle, dropdown_button.ButtonState);
239 private void dialog_button_Paint(object sender, PaintEventArgs e) {
240 // best way to draw the ellipse?
241 e.Graphics.DrawString("...", new Font(Font,FontStyle.Bold), Brushes.Black, 0,0);
244 private void dropdown_button_Click(object sender, EventArgs e) {
245 EventHandler eh = (EventHandler)(Events [DropDownButtonClickedEvent]);
250 private void dialog_button_Click(object sender, EventArgs e) {
251 EventHandler eh = (EventHandler)(Events [DialogButtonClickedEvent]);
256 #endregion Private Helper Methods
258 internal void SendMouseDown (Point screenLocation)
260 Point clientLocation = PointToClient (screenLocation);
261 XplatUI.SendMessage (Handle, Msg.WM_LBUTTONDOWN, new IntPtr ((int) MsgButtons.MK_LBUTTON), Control.MakeParam (clientLocation.X, clientLocation.Y));
262 textbox.FocusAt (screenLocation);
265 private void textbox_DoubleClick(object sender, EventArgs e) {
266 EventHandler eh = (EventHandler)(Events [ToggleValueEvent]);
271 private void textbox_KeyDown(object sender, KeyEventArgs e) {
272 KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]);
277 private void textbox_GotFocus(object sender, EventArgs e) {
280 Application.AddMessageFilter ((IMessageFilter)this);
284 bool IMessageFilter.PreFilterMessage(ref Message m)
286 // validating check is to allow whatever UI code to execute
287 // without filtering messages (i.e. error dialogs, etc)
289 if (!validating && m.HWnd != textbox.Handle &&
290 m.Msg == (int)Msg.WM_LBUTTONDOWN ||
291 m.Msg == (int)Msg.WM_MBUTTONDOWN ||
292 m.Msg == (int)Msg.WM_RBUTTONDOWN ||
293 m.Msg == (int)Msg.WM_NCLBUTTONDOWN ||
294 m.Msg == (int)Msg.WM_NCMBUTTONDOWN ||
295 m.Msg == (int)Msg.WM_NCRBUTTONDOWN) {
296 CancelEventHandler validateHandler = (CancelEventHandler)(Events [ValidateEvent]);
297 if (validateHandler != null) {
298 CancelEventArgs args = new CancelEventArgs ();
300 validateHandler (this, args);
303 Application.RemoveMessageFilter ((IMessageFilter)this);