* ListView.cs: When doing layout calculations don't use a ref
[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.NotSet;
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                         defaultHeaderCellType = typeof (DataGridViewHeaderCell);
53                         isRow = this is DataGridViewRow;
54                 }
55
56                 ~DataGridViewBand ()
57                 {
58                         Dispose();
59                 }
60
61                 [DefaultValue (null)]
62                 public virtual ContextMenuStrip ContextMenuStrip {
63                         get { return contextMenuStrip; }
64                         set { contextMenuStrip = value; }
65                 }
66
67                 [Browsable (false)]
68                 public virtual DataGridViewCellStyle DefaultCellStyle {
69                         get {
70                                 if (defaultCellStyle == null) {
71                                         defaultCellStyle = new DataGridViewCellStyle();
72                                 }
73                                 return defaultCellStyle;
74                         }
75                         set { defaultCellStyle = value; }
76                 }
77
78                 [Browsable (false)]
79                 public Type DefaultHeaderCellType {
80                         get { return defaultHeaderCellType; }
81                         set {
82                                 if (value.IsSubclassOf(typeof(DataGridViewHeaderCell))) {
83                                         throw new ArgumentException("Type is not DataGridViewHeaderCell or a derived type.");
84                                 }
85                                 defaultHeaderCellType = value;
86                         }
87                 }
88
89                 [Browsable (false)]
90                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
91                 public virtual bool Displayed {
92                         get { return displayed; }
93                 }
94
95                 [DefaultValue (false)]
96                 public virtual bool Frozen {
97                         get { return frozen; }
98                         set { frozen = value; }
99                 }
100
101                 [Browsable (false)]
102                 public bool HasDefaultCellStyle {
103                         get { return (defaultCellStyle != null); }
104                 }
105
106                 [Browsable (false)]
107                 public int Index {
108                         get { return index; }
109                 }
110
111                 [Browsable (false)]
112                 public virtual DataGridViewCellStyle InheritedStyle {
113                         get { return inheritedStyle; }
114                 }
115
116                 [DefaultValue (false)]
117                 public virtual bool ReadOnly {
118                         get { return readOnly; }
119                         set { readOnly = value; }
120                 }
121
122                 [Browsable (true)]
123                 public virtual DataGridViewTriState Resizable {
124                         get { 
125                                 if (resizable == DataGridViewTriState.NotSet && DataGridView != null) {
126                                         return DataGridView.AllowUserToResizeColumns ? DataGridViewTriState.True : DataGridViewTriState.False;
127                                 }
128                                 return resizable; }
129                         set { resizable = value; }
130                 }
131
132                 [Browsable (false)]
133                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
134                 public virtual bool Selected {
135                         get { return selected; }
136                         set {
137                                 if (DataGridView == null) {
138                                         throw new InvalidOperationException("Cant select a row non associated with a DataGridView.");
139                                 }
140                                 if (isRow) {
141                                         DataGridView.SetSelectedRowCoreInternal (Index, value);
142                                 } else {
143                                         DataGridView.SetSelectedColumnCoreInternal (Index, value);
144                                 }
145                         }
146                 }
147                 
148                 internal bool SelectedInternal {
149                         get {
150                                 return selected;
151                         }
152                         set {
153                                 selected = value;
154                         }
155                 }
156
157                 [Browsable (false)]
158                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
159                 public object Tag {
160                         get { return tag; }
161                         set { tag = value; }
162                 }
163
164                 [DefaultValue (true)]
165                 public virtual bool Visible {
166                         get { return visible; }
167                         set { visible = value; }
168                 }
169
170                 public virtual object Clone ()
171                 {
172                         DataGridViewBand result = new DataGridViewBand();
173                         //////////////////////////////
174                         return result;
175                 }
176
177                 //public sealed void Dispose () {
178                 public void Dispose ()
179                 {
180                 }
181
182                 public override string ToString ()
183                 {
184                         return this.GetType().Name + ": " + index.ToString() + ".";
185                 }
186
187                 [Browsable (false)]
188                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
189                 protected DataGridViewHeaderCell HeaderCellCore {
190                         get { return headerCellCore; }
191                         set { headerCellCore = value; }
192                 }
193
194                 protected bool IsRow {
195                         get { return isRow; }
196                 }
197
198                 protected virtual void Dispose (bool disposing)
199                 {
200                 }
201
202                 protected override void OnDataGridViewChanged ()
203                 {
204                 }
205
206                 internal virtual void SetIndex (int index)
207                 {
208                         this.index = index;
209                 }
210
211         }
212
213 }
214
215 #endif