2 // System.Web.UI.WebControls.DataGridColumn.cs
5 // Dick Porter <dick@ximian.com>
7 // Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System
.ComponentModel
;
31 using System
.Security
.Permissions
;
33 namespace System
.Web
.UI
.WebControls
36 [AspNetHostingPermissionAttribute (SecurityAction
.LinkDemand
, Level
= AspNetHostingPermissionLevel
.Minimal
)]
37 [AspNetHostingPermissionAttribute (SecurityAction
.InheritanceDemand
, Level
= AspNetHostingPermissionLevel
.Minimal
)]
39 [TypeConverter (typeof (System
.ComponentModel
.ExpandableObjectConverter
))]
40 public abstract class DataGridColumn
: IStateManager
44 bool tracking_viewstate
;
47 TableItemStyle footer_style
;
48 TableItemStyle header_style
;
49 TableItemStyle item_style
;
51 protected DataGridColumn ()
53 viewstate
= new StateBag ();
57 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Content
)]
58 [PersistenceMode (PersistenceMode
.InnerProperty
)]
59 [WebSysDescription ("")]
60 [WebCategory ("Misc")]
61 public virtual TableItemStyle FooterStyle
{
63 if (footer_style
== null) {
64 footer_style
= new TableItemStyle ();
66 if (tracking_viewstate
)
67 footer_style
.TrackViewState ();
70 return (footer_style
);
75 [WebSysDescription ("")]
76 [WebCategory ("Misc")]
77 public virtual string FooterText
{
78 get { return (viewstate.GetString ("FooterText", String.Empty)); }
79 set { viewstate["FooterText"] = value; }
83 [WebSysDescription ("")]
84 [WebCategory ("Misc")]
86 public virtual string HeaderImageUrl
{
87 get { return (viewstate.GetString ("HeaderImageUrl", String.Empty)); }
88 set { viewstate["HeaderImageUrl"] = value; }
92 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Content
)]
93 [PersistenceMode (PersistenceMode
.InnerProperty
)]
94 [WebSysDescription ("")]
95 [WebCategory ("Misc")]
96 public virtual TableItemStyle HeaderStyle
{
98 if (header_style
== null) {
99 header_style
= new TableItemStyle ();
101 if (tracking_viewstate
)
102 header_style
.TrackViewState ();
105 return (header_style
);
110 [WebSysDescription ("")]
111 [WebCategory ("Misc")]
112 public virtual string HeaderText
{
113 get { return (viewstate.GetString ("HeaderText", String.Empty)); }
114 set { viewstate["HeaderText"] = value; }
117 [DefaultValue (null)]
118 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Content
)]
119 [PersistenceMode (PersistenceMode
.InnerProperty
)]
120 [WebSysDescription ("")]
121 [WebCategory ("Misc")]
122 public virtual TableItemStyle ItemStyle
{
124 if (item_style
== null) {
125 item_style
= new TableItemStyle ();
127 if (tracking_viewstate
)
128 item_style
.TrackViewState ();
136 [WebSysDescription ("")]
137 [WebCategory ("Misc")]
138 public virtual string SortExpression
{
139 get { return (viewstate.GetString ("SortExpression", String.Empty)); }
140 set { viewstate["SortExpression"] = value; }
143 [DefaultValue (true)]
144 [WebSysDescription ("")]
145 [WebCategory ("Misc")]
146 public bool Visible
{
147 get { return (viewstate.GetBool ("Visible", true)); }
148 set { viewstate["Visible"] = value; }
151 public virtual void Initialize ()
153 if (owner
!= null && owner
.Site
!= null)
154 design
= owner
.Site
.DesignMode
;
157 internal class ForeColorLinkButton
: LinkButton
159 Color
GetForeColor (WebControl control
)
164 // don't go beyond the container table.
165 if (control
is Table
)
166 return control
.ControlStyle
.ForeColor
;
168 Color color
= control
.ControlStyle
.ForeColor
;
169 if (color
!= Color
.Empty
)
172 return GetForeColor ((WebControl
) control
.Parent
);
175 protected internal override void Render (HtmlTextWriter writer
)
177 Color color
= GetForeColor (this);
178 if (color
!= Color
.Empty
)
180 base.Render (writer
);
184 public virtual void InitializeCell (TableCell cell
, int columnIndex
, ListItemType itemType
)
187 case ListItemType
.Header
:
189 /* If sorting is enabled, add a
190 * LinkButton or an ImageButton
191 * (depending on HeaderImageUrl).
193 * If sorting is disabled, the
194 * HeaderText or an Image is displayed
195 * (depending on HeaderImageUrl).
197 * If neither HeaderText nor
198 * HeaderImageUrl is set, use
201 string sort_ex
= SortExpression
;
203 if (owner
!= null && sort_ex
.Length
> 0)
204 sort
= owner
.AllowSorting
;
206 string image_url
= HeaderImageUrl
;
207 if (image_url
.Length
> 0) {
209 ImageButton butt
= new ImageButton ();
212 * resolve this, Image
216 butt
.ImageUrl
= image_url
;
217 butt
.CommandName
= "Sort";
218 butt
.CommandArgument
= sort_ex
;
220 cell
.Controls
.Add (butt
);
222 Image image
= new Image ();
224 image
.ImageUrl
= image_url
;
226 cell
.Controls
.Add (image
);
230 // This one always gets the forecolor of the header_style
231 // from one of the parents, but we can't look it up at this
232 // point, as it can change afterwards.
233 LinkButton link
= new ForeColorLinkButton ();
235 link
.Text
= HeaderText
;
236 link
.CommandName
= "Sort";
237 link
.CommandArgument
= sort_ex
;
239 cell
.Controls
.Add (link
);
241 string text
= HeaderText
;
245 cell
.Text
= " ";
251 case ListItemType
.Footer
:
253 /* Display FooterText or */
254 string text
= FooterText
;
259 cell
.Text
= " ";
268 public override string ToString ()
270 return (String
.Empty
);
273 protected bool DesignMode
{
274 get {return (design); }
277 protected DataGrid Owner
{
278 get { return (owner); }
281 internal TableItemStyle
GetStyle (ListItemType type
)
283 if (type
== ListItemType
.Header
)
286 if (type
== ListItemType
.Footer
)
292 internal void Set_Owner (DataGrid
value)
297 protected StateBag ViewState
{
298 get { return (viewstate); }
301 /* There are no events defined for DataGridColumn, so no
302 * idea what this method is supposed to do
304 protected virtual void OnColumnChanged ()
308 void IStateManager
.LoadViewState (object savedState
)
310 LoadViewState (savedState
);
313 object IStateManager
.SaveViewState ()
315 return (SaveViewState ());
318 void IStateManager
.TrackViewState ()
323 bool IStateManager
.IsTrackingViewState
{
324 get { return (IsTrackingViewState); }
327 protected virtual void LoadViewState (object savedState
)
329 object[] pieces
= savedState
as object[];
334 if (pieces
[0] != null)
335 viewstate
.LoadViewState (pieces
[0]);
337 if (pieces
[1] != null)
338 FooterStyle
.LoadViewState (pieces
[1]);
340 if (pieces
[2] != null)
341 HeaderStyle
.LoadViewState (pieces
[2]);
343 if (pieces
[3] != null)
344 ItemStyle
.LoadViewState (pieces
[3]);
347 protected virtual object SaveViewState ()
349 object[] res
= new object[4];
351 res
[0] = viewstate
.SaveViewState ();
353 if (footer_style
!= null)
354 res
[1] = footer_style
.SaveViewState ();
356 if (header_style
!= null)
357 res
[2] = header_style
.SaveViewState ();
359 if (item_style
!= null)
360 res
[3] = item_style
.SaveViewState ();
365 protected virtual void TrackViewState ()
367 tracking_viewstate
= true;
369 viewstate
.TrackViewState ();
370 if (footer_style
!= null)
371 footer_style
.TrackViewState ();
373 if (header_style
!= null)
374 header_style
.TrackViewState ();
376 if (item_style
!= null)
377 item_style
.TrackViewState ();
380 protected bool IsTrackingViewState
{
381 get { return (tracking_viewstate); }