* TreeView.cs: Don't draw the selected node when we lose
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridTextBox.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) 2005 Novell, Inc. (http://www.novell.com)
21 //
22 // Author:
23 //      Jordi Mas i Hernandez <jordi@ximian.com>
24 //
25 //
26
27 // NOT COMPLETE
28
29 using System.ComponentModel;
30 using System.Drawing;
31 using System.Runtime.InteropServices;
32 using System.Diagnostics;
33
34 namespace System.Windows.Forms
35 {
36         [DefaultProperty("GridEditName")]
37         [DesignTimeVisible(false)]
38         [ToolboxItem(false)]
39         public class DataGridTextBox : TextBox
40         {
41
42                 #region Local Variables
43                 private bool isedit;
44                 private DataGrid grid;
45                 #endregion      // Local Variables
46
47                 #region Constructors
48                 public DataGridTextBox ()
49                 {
50                         isedit = true;
51                         grid = null;
52
53                         SetStyle (ControlStyles.UserPaint | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, false);
54                         SetStyle (ControlStyles.FixedHeight, true);
55                 }
56                 #endregion
57
58                 #region Public Instance Properties
59                 public bool IsInEditOrNavigateMode {
60                         get {
61                                 return isedit;
62                         }
63                         set {
64                                 if (value != isedit) {
65                                         isedit = value;
66                                 }
67                         }
68                 }
69
70                 #endregion      // Public Instance Properties
71
72                 #region Public Instance Methods
73                 protected override void OnKeyPress (KeyPressEventArgs e)
74                 {                       
75                         grid.is_changing = true;
76                         grid.InvalidateCurrentRowHeader ();
77                         base.OnKeyPress (e);
78                 }
79
80                 protected override void OnMouseWheel (MouseEventArgs e)
81                 {
82                         base.OnMouseWheel (e);
83                 }
84
85                 protected internal override bool ProcessKeyMessage (ref Message m)
86                 {
87                         Keys key = (Keys) m.WParam.ToInt32 ();
88                         
89                         switch (key) {
90                         case Keys.Return:
91                                 grid.EndEdit (false);
92                                 return true;
93                         
94                         case Keys.Escape:
95                                 grid.EndEdit (true);
96                                 return true;
97                                 
98                         case Keys.Right:
99                         case Keys.Tab:
100                         case Keys.Up:
101                         case Keys.Down:
102                         case Keys.PageUp:
103                         case Keys.PageDown:
104                         case Keys.Home:
105                         case Keys.End:
106                                 grid.EndEdit (false);
107                                 break;
108                         
109                         default:
110                                 break;
111                         }                       
112                         
113                         isedit = false;
114                         return base.ProcessKeyMessage (ref m);
115                 }
116
117                 public void SetDataGrid (DataGrid parentGrid)
118                 {
119                         grid = parentGrid;
120                 }
121
122                 protected override void WndProc (ref Message m)
123                 {
124                         base.WndProc (ref m);
125                 }
126
127                 #endregion      // Public Instance Methods
128
129         }
130 }