System.Drawing: added email to icon and test file headers
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / DataGridViewBand.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 using System.ComponentModel;
28
29 namespace System.Windows.Forms {
30
31         public class DataGridViewBand : DataGridViewElement, ICloneable, IDisposable {
32
33                 private ContextMenuStrip contextMenuStrip = null;
34                 private DataGridViewCellStyle defaultCellStyle;
35                 private Type defaultHeaderCellType;
36                 private bool displayed;
37                 private bool frozen = false;
38                 private int index = -1;
39                 private bool readOnly = false;
40                 private DataGridViewTriState resizable = DataGridViewTriState.NotSet;
41                 private bool selected = false;
42                 private object tag = null;
43                 private bool visible = true;
44                 private DataGridViewHeaderCell headerCellCore;
45                 private bool isRow;
46                 private DataGridViewCellStyle inheritedStyle = null;
47
48                 internal DataGridViewBand ()
49                 {
50                         defaultHeaderCellType = typeof (DataGridViewHeaderCell);
51                         isRow = this is DataGridViewRow;
52                 }
53
54                 ~DataGridViewBand ()
55                 {
56                         Dispose();
57                 }
58
59                 [DefaultValue (null)]
60                 public virtual ContextMenuStrip ContextMenuStrip {
61                         get { return contextMenuStrip; }
62                         set { contextMenuStrip = value; }
63                 }
64
65                 [Browsable (false)]
66                 public virtual DataGridViewCellStyle DefaultCellStyle {
67                         get {
68                                 if (defaultCellStyle == null) {
69                                         defaultCellStyle = new DataGridViewCellStyle();
70                                 }
71                                 return defaultCellStyle;
72                         }
73                         set { defaultCellStyle = value; }
74                 }
75
76                 [Browsable (false)]
77                 public Type DefaultHeaderCellType {
78                         get { return defaultHeaderCellType; }
79                         set {
80                                 if (!value.IsSubclassOf(typeof(DataGridViewHeaderCell))) {
81                                         throw new ArgumentException("Type is not DataGridViewHeaderCell or a derived type.");
82                                 }
83                                 defaultHeaderCellType = value;
84                         }
85                 }
86
87                 [Browsable (false)]
88                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
89                 public virtual bool Displayed {
90                         get { return displayed; }
91                 }
92
93                 [DefaultValue (false)]
94                 public virtual bool Frozen {
95                         get { return frozen; }
96                         set {
97                                 if (frozen != value) {
98                                         frozen = value;
99                                         if (frozen)
100                                                 SetState (State | DataGridViewElementStates.Frozen);
101                                         else
102                                                 SetState (State & ~DataGridViewElementStates.Frozen);
103                                 }
104                         }
105                 }
106
107                 [Browsable (false)]
108                 public bool HasDefaultCellStyle {
109                         get { return (defaultCellStyle != null); }
110                 }
111
112                 [Browsable (false)]
113                 public int Index {
114                         get { return index; }
115                 }
116
117                 [Browsable (false)]
118                 public virtual DataGridViewCellStyle InheritedStyle {
119                         get { return inheritedStyle; }
120                 }
121
122                 [DefaultValue (false)]
123                 public virtual bool ReadOnly {
124                         get { return readOnly; }
125                         set {
126                                 if (readOnly != value) {
127                                         readOnly = value;
128                                         if (readOnly)
129                                                 SetState (State | DataGridViewElementStates.ReadOnly);
130                                         else
131                                                 SetState (State & ~DataGridViewElementStates.ReadOnly);
132                                 }
133                         }
134                 }
135
136                 [Browsable (true)]
137                 public virtual DataGridViewTriState Resizable {
138                         get { 
139                                 if (resizable == DataGridViewTriState.NotSet && DataGridView != null) {
140                                         return DataGridView.AllowUserToResizeColumns ? DataGridViewTriState.True : DataGridViewTriState.False;
141                                 }
142                                 return resizable; }
143                         set {
144                                 if (value != resizable) {
145                                         resizable = value;
146                                         if (resizable == DataGridViewTriState.True)
147                                                 SetState (State | DataGridViewElementStates.Resizable);
148                                         else
149                                                 SetState (State & ~DataGridViewElementStates.Resizable);
150                                 }
151                         }
152                 }
153
154                 [Browsable (false)]
155                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
156                 public virtual bool Selected {
157                         get { return selected; }
158                         set {
159                                 if (DataGridView == null) {
160                                         throw new InvalidOperationException("Cant select a row non associated with a DataGridView.");
161                                 }
162                                 if (isRow) {
163                                         DataGridView.SetSelectedRowCoreInternal (Index, value);
164                                 } else {
165                                         DataGridView.SetSelectedColumnCoreInternal (Index, value);
166                                 }
167                         }
168                 }
169                 
170                 internal bool SelectedInternal {
171                         get {
172                                 return selected;
173                         }
174                         set {
175                                 if (selected != value) {
176                                         selected = value;
177
178                                         if (selected)
179                                                 SetState (State | DataGridViewElementStates.Selected);
180                                         else
181                                                 SetState (State & ~DataGridViewElementStates.Selected);
182                                 }
183                         }
184                 }
185
186                 internal bool DisplayedInternal {
187                         get { return displayed; }
188                         set {
189                                 if (value != displayed) {
190                                         displayed = value;
191                                         if (displayed)
192                                                 SetState (State | DataGridViewElementStates.Displayed);
193                                         else
194                                                 SetState (State & ~DataGridViewElementStates.Displayed);
195                                 }
196                         }
197                 }
198                 
199                 [Browsable (false)]
200                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
201                 public object Tag {
202                         get { return tag; }
203                         set { tag = value; }
204                 }
205
206                 [DefaultValue (true)]
207                 public virtual bool Visible {
208                         get { return visible; }
209                         set {
210                                 if (visible != value) {
211                                         visible = value;
212                                         if (visible)
213                                                 SetState (State | DataGridViewElementStates.Visible);
214                                         else
215                                                 SetState (State & ~DataGridViewElementStates.Visible);
216                                 }
217                         }
218                 }
219
220                 public virtual object Clone ()
221                 {
222                         DataGridViewBand result = new DataGridViewBand();
223                         //////////////////////////////
224                         return result;
225                 }
226
227                 //public sealed void Dispose () {
228                 public void Dispose ()
229                 {
230                 }
231
232                 public override string ToString ()
233                 {
234                         return this.GetType().Name + ": " + index.ToString() + ".";
235                 }
236
237                 [Browsable (false)]
238                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
239                 protected DataGridViewHeaderCell HeaderCellCore {
240                         get { return headerCellCore; }
241                         set { headerCellCore = value; }
242                 }
243
244                 protected bool IsRow {
245                         get { return isRow; }
246                 }
247
248                 protected virtual void Dispose (bool disposing)
249                 {
250                 }
251
252                 protected override void OnDataGridViewChanged ()
253                 {
254                 }
255
256                 internal virtual void SetIndex (int index)
257                 {
258                         this.index = index;
259                 }
260
261         }
262
263 }
264