* TabControl.cs: Show the tooltip depending on the value
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridViewHeaderCell.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 //      Pedro Martínez Juliá <pedromj@gmail.com>
24 //
25
26
27 #if NET_2_0
28
29 using System.ComponentModel;
30 using System.Drawing;
31
32 namespace System.Windows.Forms {
33         public class DataGridViewHeaderCell : DataGridViewCell {
34
35                 private ButtonState buttonState;
36
37                 public DataGridViewHeaderCell ()
38                 {
39                         buttonState = ButtonState.Normal;
40                 }
41
42                 [Browsable (false)]
43                 public override bool Displayed {
44                         get { return base.Displayed; }
45                 }
46
47                 public override Type FormattedValueType {
48                         get { return typeof(string); } //base.FormattedValueType; }
49                 }
50
51                 [Browsable (false)]
52                 public override bool Frozen {
53                         get { return base.Frozen; }
54                 }
55
56                 [Browsable (false)]
57                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
58                 public override bool ReadOnly {
59                         get { return base.ReadOnly; }
60                         set { base.ReadOnly = value; }
61                 }
62
63                 [Browsable (false)]
64                 public override bool Resizable {
65                         get { return base.Resizable; }
66                 }
67
68                 [Browsable (false)]
69                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
70                 public override bool Selected {
71                         get { return base.Selected; }
72                         set { base.Selected = value; }
73                 }
74
75                 public override Type ValueType {
76                         get { return base.ValueType; }
77                         set { base.ValueType = value; }
78                 }
79
80                 [Browsable (false)]
81                 public override bool Visible {
82                         get { return base.Visible; }
83                 }
84
85                 public override object Clone ()
86                 {
87                         DataGridViewHeaderCell result = new DataGridViewHeaderCell();
88                         return result;
89                 }
90
91                 protected override void Dispose (bool disposing)
92                 {
93                 }
94
95                 public override ContextMenuStrip GetInheritedContextMenuStrip (int rowIndex)
96                 {
97                         if (DataGridView == null)
98                                 return null;
99
100                         if (ContextMenuStrip != null)
101                                 return ContextMenuStrip;
102                         if (DataGridView.ContextMenuStrip != null)
103                                 return DataGridView.ContextMenuStrip;
104
105                         return null;
106                 }
107
108                 public override DataGridViewElementStates GetInheritedState (int rowIndex)
109                 {
110                         DataGridViewElementStates result;
111
112                         result = DataGridViewElementStates.ResizableSet | State;
113
114                         return result;
115                 }
116
117                 public override string ToString ()
118                 {
119                         return string.Format ("DataGridViewHeaderCell {{ ColumnIndex={0}, RowIndex={1} }}", ColumnIndex, RowIndex);
120                 }
121
122                 protected override Size GetSize (int rowIndex)
123                 {
124                         if (DataGridView == null && rowIndex != -1)
125                                 throw new ArgumentOutOfRangeException ("rowIndex");
126                         if (OwningColumn != null && rowIndex != -1)
127                                 throw new ArgumentOutOfRangeException ("rowIndex");
128                         if (OwningRow != null && (rowIndex < 0 || rowIndex >= DataGridView.Rows.Count))
129                                 throw new ArgumentOutOfRangeException ("rowIndex");
130                         if (OwningColumn == null && OwningRow == null && rowIndex != -1)
131                                 throw new ArgumentOutOfRangeException ("rowIndex");
132                         if (OwningRow != null && OwningRow.Index != rowIndex)
133                                 throw new ArgumentException ("rowIndex");
134                                 
135                         if (DataGridView == null)
136                                 return new Size (-1, -1);
137
138                         if (this is DataGridViewTopLeftHeaderCell)
139                                 return new Size (DataGridView.RowHeadersWidth, DataGridView.ColumnHeadersHeight);
140                         if (this is DataGridViewColumnHeaderCell)
141                                 return new Size (100, DataGridView.ColumnHeadersHeight);
142                         if (this is DataGridViewRowHeaderCell)
143                                 return new Size (DataGridView.RowHeadersWidth, 22);
144                         
145                         return Size.Empty;
146                 }
147
148                 protected override object GetValue (int rowIndex)
149                 {
150                         return base.GetValue (rowIndex);
151                 }
152
153                 protected override bool MouseDownUnsharesRow (DataGridViewCellMouseEventArgs e)
154                 {
155                         if (DataGridView == null)
156                                 return false;
157                                 
158                         if (e.Button == MouseButtons.Left && Application.RenderWithVisualStyles && DataGridView.EnableHeadersVisualStyles)
159                                 return true;
160                                 
161                         return false;
162                 }
163
164                 protected override bool MouseEnterUnsharesRow (int rowIndex)
165                 {
166                         if (DataGridView == null)
167                                 return false;
168
169                         if (Application.RenderWithVisualStyles && DataGridView.EnableHeadersVisualStyles)
170                                 return true;
171
172                         return false;
173                 }
174
175                 protected override bool MouseLeaveUnsharesRow (int rowIndex)
176                 {
177                         if (DataGridView == null)
178                                 return false;
179
180                         if (ButtonState != ButtonState.Normal && Application.RenderWithVisualStyles && DataGridView.EnableHeadersVisualStyles)
181                                 return true;
182
183                         return false;
184                 }
185
186                 protected override bool MouseUpUnsharesRow (DataGridViewCellMouseEventArgs e)
187                 {
188                         if (DataGridView == null)
189                                 return false;
190
191                         if (e.Button == MouseButtons.Left && Application.RenderWithVisualStyles && DataGridView.EnableHeadersVisualStyles)
192                                 return true;
193
194                         return false;
195                 }
196
197                 protected override void OnMouseDown (DataGridViewCellMouseEventArgs e)
198                 {
199                         base.OnMouseDown (e);
200                 }
201
202                 protected override void OnMouseEnter (int rowIndex)
203                 {
204                         base.OnMouseEnter (rowIndex);
205                 }
206
207                 protected override void OnMouseLeave (int rowIndex)
208                 {
209                         base.OnMouseLeave (rowIndex);
210                 }
211
212                 protected override void OnMouseUp (DataGridViewCellMouseEventArgs e)
213                 {
214                         base.OnMouseUp (e);
215                 }
216
217                 protected override void Paint (Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
218                 {
219                         base.Paint (graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
220                 }
221                 
222                 protected ButtonState ButtonState {
223                         get { return buttonState; }
224                 }
225
226         }
227
228 }
229
230 #endif