2007-06-13 Jonathan Pobst <monkey@jpobst.com>
[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 #if NET_2_0
28
29 using System.ComponentModel;
30
31 namespace System.Windows.Forms {
32
33         public class DataGridViewBand : DataGridViewElement, ICloneable, IDisposable {
34
35                 private ContextMenuStrip contextMenuStrip = null;
36                 private DataGridViewCellStyle defaultCellStyle;
37                 private Type defaultHeaderCellType;
38                 private bool displayed;
39                 private bool frozen = false;
40                 private int index = -1;
41                 private bool readOnly = false;
42                 private DataGridViewTriState resizable = DataGridViewTriState.True;
43                 private bool selected = false;
44                 private object tag = null;
45                 private bool visible = true;
46                 private DataGridViewHeaderCell headerCellCore;
47                 private bool isRow;
48                 private DataGridViewCellStyle inheritedStyle = null;
49
50                 internal DataGridViewBand ()
51                 {
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 { frozen = value; }
97                 }
98
99                 [Browsable (false)]
100                 public bool HasDefaultCellStyle {
101                         get { return (defaultCellStyle != null); }
102                 }
103
104                 [Browsable (false)]
105                 public int Index {
106                         get { return index; }
107                 }
108
109                 [Browsable (false)]
110                 public virtual DataGridViewCellStyle InheritedStyle {
111                         get { return inheritedStyle; }
112                 }
113
114                 [DefaultValue (false)]
115                 public virtual bool ReadOnly {
116                         get { return readOnly; }
117                         set { readOnly = value; }
118                 }
119
120                 [Browsable (true)]
121                 public virtual DataGridViewTriState Resizable {
122                         get { return resizable; }
123                         set { resizable = value; }
124                 }
125
126                 [Browsable (false)]
127                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
128                 public virtual bool Selected {
129                         get { return selected; }
130                         set {
131                                 if (DataGridView == null) {
132                                         throw new InvalidOperationException("Cant select a row non associated with a DataGridView.");
133                                 }
134                                 selected = value;
135                         }
136                 }
137
138                 [Browsable (false)]
139                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
140                 public object Tag {
141                         get { return tag; }
142                         set { tag = value; }
143                 }
144
145                 [DefaultValue (true)]
146                 public virtual bool Visible {
147                         get { return visible; }
148                         set { visible = value; }
149                 }
150
151                 public virtual object Clone ()
152                 {
153                         DataGridViewBand result = new DataGridViewBand();
154                         //////////////////////////////
155                         return result;
156                 }
157
158                 //public sealed void Dispose () {
159                 public void Dispose ()
160                 {
161                 }
162
163                 public override string ToString ()
164                 {
165                         return this.GetType().Name + ": " + index.ToString() + ".";
166                 }
167
168                 [Browsable (false)]
169                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
170                 protected DataGridViewHeaderCell HeaderCellCore {
171                         get { return headerCellCore; }
172                         set { headerCellCore = value; }
173                 }
174
175                 protected bool IsRow {
176                         get { return isRow; }
177                 }
178
179                 protected virtual void Dispose (bool disposing)
180                 {
181                 }
182
183                 protected override void OnDataGridViewChanged ()
184                 {
185                 }
186
187                 internal virtual void SetIndex (int index)
188                 {
189                         this.index = index;
190                 }
191
192         }
193
194 }
195
196 #endif