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.Size = new Size(16, 16);
74 dialog_button.TabIndex = 1;
75 dialog_button.Visible = false;
76 dialog_button.Click += new System.EventHandler(dialog_button_Click);
78 dropdown_button.Dock = DockStyle.Right;
79 dropdown_button.Size = new Size(16, 16);
80 dropdown_button.TabIndex = 2;
81 dropdown_button.Visible = false;
82 dropdown_button.Click += new System.EventHandler(dropdown_button_Click);
84 textbox.AutoSize = false;
85 // this is to explicitly set bgcolor to avoid
86 // default ReadOnly color (which makes grid item
87 // bgcolor inconsistent).
88 textbox.BackColor = textbox.BackColor;
89 textbox.BorderStyle = BorderStyle.None;
90 textbox.Dock = DockStyle.Fill;
93 Controls.Add(textbox);
94 Controls.Add(dropdown_button);
95 Controls.Add(dialog_button);
97 SetStyle (ControlStyles.Selectable, true);
101 dropdown_button.Paint+=new PaintEventHandler(dropdown_button_Paint);
102 dialog_button.Paint+=new PaintEventHandler(dialog_button_Paint);
103 textbox.DoubleClick+=new EventHandler(textbox_DoubleClick);
107 #endregion Contructors
109 #region Protected Instance Properties
111 protected override void OnGotFocus (EventArgs args)
113 base.OnGotFocus (args);
114 // force-disable selection
115 textbox.has_been_focused = true;
117 textbox.SelectionLength = 0;
122 #region Public Instance Properties
124 public bool DialogButtonVisible {
126 return dialog_button.Visible;
129 dialog_button.Visible = value;
132 public bool DropDownButtonVisible {
134 return dropdown_button.Visible;
137 dropdown_button.Visible = value;
141 public new Color ForeColor {
143 return base.ForeColor;
146 textbox.ForeColor = value;
147 dropdown_button.ForeColor = value;
148 dialog_button.ForeColor = value;
149 base.ForeColor = value;
153 public new Color BackColor {
155 return base.BackColor;
158 textbox.BackColor = value;
159 dropdown_button.BackColor = value;
160 dialog_button.BackColor = value;
161 base.BackColor = value;
164 public bool ReadOnly {
166 return textbox.ReadOnly;
169 textbox.ReadOnly = value;
173 public new string Text {
178 textbox.Text = value;
182 public char PasswordChar {
183 set { textbox.PasswordChar = value; }
186 #endregion Public Instance Properties
189 static object DropDownButtonClickedEvent = new object ();
190 static object DialogButtonClickedEvent = new object ();
191 static object ToggleValueEvent = new object ();
193 public event EventHandler DropDownButtonClicked {
194 add { Events.AddHandler (DropDownButtonClickedEvent, value); }
195 remove { Events.RemoveHandler (DropDownButtonClickedEvent, value); }
198 public event EventHandler DialogButtonClicked {
199 add { Events.AddHandler (DialogButtonClickedEvent, value); }
200 remove { Events.RemoveHandler (DialogButtonClickedEvent, value); }
203 public event EventHandler ToggleValue {
204 add { Events.AddHandler (ToggleValueEvent, value); }
205 remove { Events.RemoveHandler (ToggleValueEvent, value); }
210 #region Private Helper Methods
212 private void dropdown_button_Paint(object sender, PaintEventArgs e)
214 ThemeEngine.Current.CPDrawComboButton(e.Graphics, dropdown_button.ClientRectangle, dropdown_button.ButtonState);
217 private void dialog_button_Paint(object sender, PaintEventArgs e) {
218 // best way to draw the ellipse?
219 e.Graphics.DrawString("...", new Font(Font,FontStyle.Bold), Brushes.Black, 0,0);
222 private void dropdown_button_Click(object sender, EventArgs e) {
223 EventHandler eh = (EventHandler)(Events [DropDownButtonClickedEvent]);
228 private void dialog_button_Click(object sender, EventArgs e) {
229 EventHandler eh = (EventHandler)(Events [DialogButtonClickedEvent]);
234 #endregion Private Helper Methods
236 internal void SendMouseDown (Point screenLocation)
238 Point clientLocation = PointToClient (screenLocation);
239 XplatUI.SendMessage (Handle, Msg.WM_LBUTTONDOWN, new IntPtr ((int) MsgButtons.MK_LBUTTON), Control.MakeParam (clientLocation.X, clientLocation.Y));
240 textbox.FocusAt (screenLocation);
243 private void textbox_DoubleClick(object sender, EventArgs e) {
244 EventHandler eh = (EventHandler)(Events [ToggleValueEvent]);