**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Web / System.Web.UI.WebControls / DataGridColumn.cs
blob2a5a28efb485951ba9290ff455a2cef16df140be
1 //
2 // System.Web.UI.WebControls.DataGridColumn.cs
3 //
4 // Authors:
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //
8 // (C) Gaurav Vaish (2002)
9 // (C) 2003 Andreas Nahr
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System;
34 using System.Web;
35 using System.Web.UI;
36 using System.ComponentModel;
38 namespace System.Web.UI.WebControls
40 [TypeConverter(typeof(ExpandableObjectConverter))]
41 public abstract class DataGridColumn : IStateManager
43 private StateBag viewState;
44 private bool marked;
45 private TableItemStyle footerStyle;
46 private TableItemStyle headerStyle;
47 private TableItemStyle itemStyle;
49 private DataGrid owner;
50 private bool designMode;
52 public DataGridColumn()
54 viewState = new StateBag();
57 internal TableItemStyle FooterStyleInternal
59 get
61 return footerStyle;
65 internal TableItemStyle HeaderStyleInternal
67 get
69 return headerStyle;
73 internal TableItemStyle ItemStyleInternal
75 get
77 return itemStyle;
81 [DefaultValue (null), WebCategory ("Misc")]
82 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
83 [PersistenceMode (PersistenceMode.InnerProperty)]
84 [WebSysDescription ("The style applied to the footer of this column.")]
85 public virtual TableItemStyle FooterStyle
87 get
89 if(footerStyle == null)
91 footerStyle = new TableItemStyle();
92 if(IsTrackingViewState)
94 footerStyle.TrackViewState();
97 return footerStyle;
101 [DefaultValue (null), WebCategory ("Misc")]
102 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
103 [PersistenceMode (PersistenceMode.InnerProperty)]
104 [WebSysDescription ("The style applied to the header of this column.")]
105 public virtual TableItemStyle HeaderStyle
109 if(headerStyle == null)
111 headerStyle= new TableItemStyle();
112 if(IsTrackingViewState)
114 headerStyle.TrackViewState();
117 return headerStyle;
121 [DefaultValue (null), WebCategory ("Misc")]
122 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
123 [PersistenceMode (PersistenceMode.InnerProperty)]
124 [WebSysDescription ("The style applied to the rows of this column.")]
125 public virtual TableItemStyle ItemStyle
129 if(itemStyle == null)
131 itemStyle = new TableItemStyle();
132 if(IsTrackingViewState)
134 itemStyle.TrackViewState();
137 return itemStyle;
141 [DefaultValue (""), WebCategory ("Misc")]
142 [WebSysDescription ("The text within the footer of this column.")]
143 public virtual string FooterText
147 object o = ViewState["FooterText"];
148 if(o != null)
150 return (string)o;
152 return String.Empty;
156 ViewState["FooterText"] = value;
157 OnColumnChanged();
161 [DefaultValue (""), WebCategory ("Misc")]
162 [WebSysDescription ("The URL to an image that is displayed in the header of this column.")]
163 public virtual string HeaderImageUrl
167 object o = ViewState["HeaderImageUrl"];
168 if(o != null)
170 return (string)o;
172 return String.Empty;
176 ViewState["HeaderImageUrl"] = value;
177 OnColumnChanged();
181 [DefaultValue (""), WebCategory ("Misc")]
182 [WebSysDescription ("The text within the header of this column.")]
183 public virtual string HeaderText
187 object o = ViewState["HeaderText"];
188 if(o != null)
190 return (string)o;
192 return String.Empty;
196 ViewState["HeaderText"] = value;
197 OnColumnChanged();
201 [DefaultValue (""), WebCategory ("Misc")]
202 [WebSysDescription ("An expression that determines how the colum should be sorted.")]
203 public virtual string SortExpression
207 object o = ViewState["SortExpression"];
208 if(o != null)
210 return (string)o;
212 return String.Empty;
216 ViewState["SortExpression"] = value;
217 OnColumnChanged();
221 [DefaultValue (true), WebCategory ("Misc")]
222 [WebSysDescription ("The visibility of this column.")]
223 public bool Visible
227 object o = ViewState["Visible"];
228 if(o != null)
230 return (bool)o;
232 return true;
236 ViewState["Visible"] = value;
237 OnColumnChanged();
241 public virtual void Initialize()
243 if(owner != null && owner.Site != null)
245 designMode = owner.Site.DesignMode;
249 public virtual void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType)
251 switch(itemType)
253 case ListItemType.Header : InitializeCellHeader(cell, columnIndex);
254 break;
255 case ListItemType.Footer : InitializeCellFooter(cell, columnIndex);
256 break;
257 default : if (ItemStyleInternal != null)
258 cell.ApplyStyle (ItemStyleInternal);
259 return;
263 private void InitializeCellHeader(TableCell cell, int columnIndex)
265 WebControl ctrl = null;
266 bool sort = true;
267 string sortExpr = "";
268 ImageButton headButton;
269 Image headImage;
270 LinkButtonInternal link;
272 if(owner != null)
274 sort = owner.AllowSorting;
276 if(sort)
278 sortExpr = SortExpression;
279 if(sortExpr.Length == 0)
281 sort = false;
284 if(HeaderImageUrl.Length > 0)
286 if(sort)
288 headButton = new ImageButton();
289 headButton.ImageUrl = HeaderImageUrl;
290 headButton.CommandName = "Sort";
291 headButton.CommandArgument = sortExpr;
292 headButton.CausesValidation = false;
293 ctrl = headButton;
294 } else
296 headImage = new Image();
297 headImage.ImageUrl = HeaderImageUrl;
298 ctrl = headImage;
300 } else
302 if(sort)
304 link = new LinkButtonInternal();
305 link.Text = HeaderText;
306 link.CommandName = "Sort";
307 link.CommandArgument = sortExpr;
308 link.CausesValidation = false;
309 ctrl = link;
310 } else
312 if(HeaderText.Length > 0)
314 cell.Text = HeaderText;
315 } else
317 cell.Text = " ";
321 if(ctrl != null)
323 cell.Controls.Add(ctrl);
325 if (HeaderStyleInternal != null)
326 cell.ApplyStyle (HeaderStyleInternal);
329 private void InitializeCellFooter(TableCell cell, int columnIndex)
331 cell.Text = (FooterText.Length > 0 ? FooterText : " ");
332 if (FooterStyleInternal != null)
333 cell.ApplyStyle (FooterStyleInternal);
336 public override string ToString()
338 return String.Empty;
341 protected bool DesignMode
345 return designMode;
349 protected DataGrid Owner
353 return owner;
357 protected StateBag ViewState
361 return viewState;
365 /// <summary>
366 /// Undocumented
367 /// </summary>
368 protected virtual void OnColumnChanged()
370 if(owner != null)
372 owner.OnColumnsChanged();
376 internal void SetOwner (DataGrid datagrid)
378 owner = datagrid;
381 protected virtual object SaveViewState()
383 object[] states = new object[4];
384 states[0] = ViewState.SaveViewState();
385 states[1] = (footerStyle == null ? null : footerStyle.SaveViewState());
386 states[2] = (headerStyle == null ? null : headerStyle.SaveViewState());
387 states[3] = (itemStyle == null ? null : itemStyle.SaveViewState());
389 for (int i = 0; i < states.Length; i++) {
390 if (states [i] != null)
391 return states;
393 return null;
396 protected virtual void LoadViewState(object savedState)
398 if (savedState == null)
399 return;
401 object[] states = (object[]) savedState;
402 ViewState.LoadViewState (states [0]);
403 FooterStyle.LoadViewState (states [1]);
404 HeaderStyle.LoadViewState (states [2]);
405 ItemStyle.LoadViewState (states [3]);
408 protected virtual void TrackViewState()
410 marked = true;
411 ViewState.TrackViewState();
412 if(footerStyle != null)
414 footerStyle.TrackViewState();
416 if(headerStyle != null)
418 headerStyle.TrackViewState();
420 if(itemStyle != null)
422 itemStyle.TrackViewState();
426 protected bool IsTrackingViewState
430 return marked;
434 void IStateManager.LoadViewState(object savedState)
436 LoadViewState(savedState);
439 object IStateManager.SaveViewState()
441 return SaveViewState();
444 void IStateManager.TrackViewState()
446 TrackViewState();
449 bool IStateManager.IsTrackingViewState
453 return IsTrackingViewState;