* XplatUIX11.cs: Removed unused hwnd var in SetBorderStyle.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / PropertyGridTextBox.cs
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:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
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.
19 //
20 // Copyright (c) 2004-2005 Novell, Inc.
21 //
22 // Authors:
23 //      Jonathan Chambers (jonathan.chambers@ansys.com)
24 //
25
26 // COMPLETE
27
28 using System;
29 using System.Drawing;
30
31 namespace System.Windows.Forms.PropertyGridInternal {
32         internal class PropertyGridTextBox : System.Windows.Forms.UserControl {
33                 #region Private Members
34
35                 private TextBox textbox;
36                 private Button dialog_button;
37                 private Button dropdown_button;
38
39                 #endregion Private Members
40
41                 #region Contructors
42                 public PropertyGridTextBox() {
43                         dialog_button = new Button();
44                         dropdown_button = new Button();
45                         textbox = new TextBox();
46
47                         SuspendLayout();
48
49                         dialog_button.Dock = DockStyle.Right;
50                         dialog_button.Size = new Size(16, 16);
51                         dialog_button.TabIndex = 1;
52                         dialog_button.Visible = false;
53                         dialog_button.Click += new System.EventHandler(dialog_button_Click);
54
55                         dropdown_button.Dock = DockStyle.Right;
56                         dropdown_button.Size = new Size(16, 16);
57                         dropdown_button.TabIndex = 2;
58                         dropdown_button.Visible = false;
59                         dropdown_button.Click += new System.EventHandler(dropdown_button_Click);
60
61                         textbox.AutoSize = false;
62                         // this is to explicitly set bgcolor to avoid
63                         // default ReadOnly color (which makes grid item
64                         // bgcolor inconsistent).
65                         textbox.BackColor = textbox.BackColor;
66                         textbox.BorderStyle = BorderStyle.None;
67                         textbox.Dock = DockStyle.Fill;
68                         textbox.TabIndex = 3;
69
70                         Controls.Add(textbox);
71                         Controls.Add(dropdown_button);
72                         Controls.Add(dialog_button);
73
74                         ResumeLayout(false);
75
76                         dropdown_button.Paint+=new PaintEventHandler(dropdown_button_Paint);
77                         dialog_button.Paint+=new PaintEventHandler(dialog_button_Paint);
78                         textbox.DoubleClick+=new EventHandler(textbox_DoubleClick);
79                 }
80
81                 
82                 #endregion Contructors
83
84                 #region Public Instance Properties
85
86                 public bool DialogButtonVisible {
87                         get{
88                                 return dialog_button.Visible;
89                         }
90                         set {
91                                 dialog_button.Visible = value;
92                         }
93                 }
94                 public bool DropDownButtonVisible {
95                         get{
96                                 return dropdown_button.Visible;
97                         }
98                         set {
99                                 dropdown_button.Visible = value;
100                         }
101                 }
102
103                 public bool ReadOnly {
104                         get {
105                                 return textbox.ReadOnly;
106                         }
107                         set {
108                                 textbox.ReadOnly = value;
109                         }
110                 }
111
112                 public new string Text {
113                         get {
114                                 return textbox.Text;
115                         }
116                         set {
117                                 textbox.Text = value;
118                         }
119                 }
120
121                 #endregion Public Instance Properties
122                 
123                 #region Events
124                 static object DropDownButtonClickedEvent = new object ();
125                 static object DialogButtonClickedEvent = new object ();
126                 static object ToggleValueEvent = new object ();
127
128                 public event EventHandler DropDownButtonClicked {
129                         add { Events.AddHandler (DropDownButtonClickedEvent, value); }
130                         remove { Events.RemoveHandler (DropDownButtonClickedEvent, value); }
131                 }
132
133                 public event EventHandler DialogButtonClicked {
134                         add { Events.AddHandler (DialogButtonClickedEvent, value); }
135                         remove { Events.RemoveHandler (DialogButtonClickedEvent, value); }
136                 }
137
138                 public event EventHandler ToggleValue {
139                         add { Events.AddHandler (ToggleValueEvent, value); }
140                         remove { Events.RemoveHandler (ToggleValueEvent, value); }
141                 }
142                 
143                 #endregion Events
144                 
145                 #region Private Helper Methods
146
147                 private void dropdown_button_Paint(object sender, PaintEventArgs e)
148                 {
149                         ThemeEngine.Current.CPDrawComboButton(e.Graphics, dropdown_button.ClientRectangle, dropdown_button.ButtonState);
150                 }
151
152                 private void dialog_button_Paint(object sender, PaintEventArgs e) {
153                         // best way to draw the ellipse?
154                         e.Graphics.DrawString("...", new Font(Font,FontStyle.Bold), Brushes.Black, 0,0);
155                 }
156
157                 private void dropdown_button_Click(object sender, EventArgs e) {
158                         EventHandler eh = (EventHandler)(Events [DropDownButtonClickedEvent]);
159                         if (eh != null)
160                                 eh (this, e);
161                 }
162
163                 private void dialog_button_Click(object sender, EventArgs e) {
164                         EventHandler eh = (EventHandler)(Events [DialogButtonClickedEvent]);
165                         if (eh != null)
166                                 eh (this, e);
167                 }
168
169                 #endregion Private Helper Methods
170
171                 private void textbox_DoubleClick(object sender, EventArgs e) {
172                         EventHandler eh = (EventHandler)(Events [ToggleValueEvent]);
173                         if (eh != null)
174                                 eh (this, e);
175                 }
176         }
177 }