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)
31 namespace System.Windows.Forms.PropertyGridInternal
33 internal class PGTextBox : TextBox
35 private bool _focusing = false;
37 public void FocusAt (Point location)
40 Point pnt = PointToClient (location);
41 XplatUI.SendMessage (Handle, Msg.WM_LBUTTONDOWN, new IntPtr ((int)MsgButtons.MK_LBUTTON), Control.MakeParam (pnt.X, pnt.Y));
44 protected override void WndProc (ref Message m)
46 // Swallow the first MOUSEMOVE after the focusing WM_LBUTTONDOWN
47 if (_focusing && m.Msg == (int)Msg.WM_MOUSEMOVE) {
55 internal class PropertyGridTextBox : System.Windows.Forms.UserControl {
56 #region Private Members
58 private PGTextBox textbox;
59 private Button dialog_button;
60 private Button dropdown_button;
62 #endregion Private Members
65 public PropertyGridTextBox() {
66 dialog_button = new Button();
67 dropdown_button = new Button();
68 textbox = new PGTextBox ();
72 dialog_button.Dock = DockStyle.Right;
73 dialog_button.BackColor = SystemColors.Control;
74 dialog_button.Size = new Size(16, 16);
75 dialog_button.TabIndex = 1;
76 dialog_button.Visible = false;
77 dialog_button.Click += new System.EventHandler(dialog_button_Click);
79 dropdown_button.Dock = DockStyle.Right;
80 dropdown_button.BackColor = SystemColors.Control;
81 dropdown_button.Size = new Size(16, 16);
82 dropdown_button.TabIndex = 2;
83 dropdown_button.Visible = false;
84 dropdown_button.Click += new System.EventHandler(dropdown_button_Click);
86 textbox.AutoSize = false;
87 textbox.BorderStyle = BorderStyle.None;
88 textbox.Dock = DockStyle.Fill;
91 Controls.Add(textbox);
92 Controls.Add(dropdown_button);
93 Controls.Add(dialog_button);
95 SetStyle (ControlStyles.Selectable, true);
99 dropdown_button.Paint+=new PaintEventHandler(dropdown_button_Paint);
100 dialog_button.Paint+=new PaintEventHandler(dialog_button_Paint);
101 textbox.DoubleClick+=new EventHandler(textbox_DoubleClick);
105 #endregion Contructors
107 #region Protected Instance Properties
109 protected override void OnGotFocus (EventArgs args)
111 base.OnGotFocus (args);
112 // force-disable selection
113 textbox.has_been_focused = true;
115 textbox.SelectionLength = 0;
120 #region Public Instance Properties
122 public bool DialogButtonVisible {
124 return dialog_button.Visible;
127 dialog_button.Visible = value;
130 public bool DropDownButtonVisible {
132 return dropdown_button.Visible;
135 dropdown_button.Visible = value;
139 public new Color ForeColor {
141 return base.ForeColor;
144 textbox.ForeColor = value;
145 dropdown_button.ForeColor = value;
146 dialog_button.ForeColor = value;
147 base.ForeColor = value;
151 public new Color BackColor {
153 return base.BackColor;
156 textbox.BackColor = value;
157 base.BackColor = value;
160 public bool ReadOnly {
162 return textbox.ReadOnly;
165 textbox.ReadOnly = value;
169 public new string Text {
174 textbox.Text = value;
178 public char PasswordChar {
179 set { textbox.PasswordChar = value; }
182 #endregion Public Instance Properties
185 static object DropDownButtonClickedEvent = new object ();
186 static object DialogButtonClickedEvent = new object ();
187 static object ToggleValueEvent = new object ();
189 public event EventHandler DropDownButtonClicked {
190 add { Events.AddHandler (DropDownButtonClickedEvent, value); }
191 remove { Events.RemoveHandler (DropDownButtonClickedEvent, value); }
194 public event EventHandler DialogButtonClicked {
195 add { Events.AddHandler (DialogButtonClickedEvent, value); }
196 remove { Events.RemoveHandler (DialogButtonClickedEvent, value); }
199 public event EventHandler ToggleValue {
200 add { Events.AddHandler (ToggleValueEvent, value); }
201 remove { Events.RemoveHandler (ToggleValueEvent, value); }
206 #region Private Helper Methods
208 private void dropdown_button_Paint(object sender, PaintEventArgs e)
210 ThemeEngine.Current.CPDrawComboButton(e.Graphics, dropdown_button.ClientRectangle, dropdown_button.ButtonState);
213 private void dialog_button_Paint(object sender, PaintEventArgs e) {
214 // best way to draw the ellipse?
215 e.Graphics.DrawString("...", new Font(Font,FontStyle.Bold), Brushes.Black, 0,0);
218 private void dropdown_button_Click(object sender, EventArgs e) {
219 EventHandler eh = (EventHandler)(Events [DropDownButtonClickedEvent]);
224 private void dialog_button_Click(object sender, EventArgs e) {
225 EventHandler eh = (EventHandler)(Events [DialogButtonClickedEvent]);
230 #endregion Private Helper Methods
232 internal void SendMouseDown (Point screenLocation)
234 Point clientLocation = PointToClient (screenLocation);
235 XplatUI.SendMessage (Handle, Msg.WM_LBUTTONDOWN, new IntPtr ((int) MsgButtons.MK_LBUTTON), Control.MakeParam (clientLocation.X, clientLocation.Y));
236 textbox.FocusAt (screenLocation);
239 private void textbox_DoubleClick(object sender, EventArgs e) {
240 EventHandler eh = (EventHandler)(Events [ToggleValueEvent]);