[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / System.Web / System.Web.UI.WebControls / DataGridColumn.cs
blob761173c248c1de8c848691752cc8225d93107b17
1 //
2 // System.Web.UI.WebControls.DataGridColumn.cs
3 //
4 // Author:
5 // Dick Porter <dick@ximian.com>
6 //
7 // Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
8 //
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:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
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;
30 using System.Drawing;
31 using System.Security.Permissions;
33 namespace System.Web.UI.WebControls
35 // CAS
36 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
37 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38 // attributes
39 [TypeConverter (typeof (System.ComponentModel.ExpandableObjectConverter))]
40 public abstract class DataGridColumn : IStateManager
42 DataGrid owner;
43 StateBag viewstate;
44 bool tracking_viewstate;
45 bool design;
47 TableItemStyle footer_style;
48 TableItemStyle header_style;
49 TableItemStyle item_style;
51 protected DataGridColumn ()
53 viewstate = new StateBag ();
56 [DefaultValue (null)]
57 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
58 [PersistenceMode (PersistenceMode.InnerProperty)]
59 [WebSysDescription ("")]
60 [WebCategory ("Misc")]
61 public virtual TableItemStyle FooterStyle {
62 get {
63 if (footer_style == null) {
64 footer_style = new TableItemStyle ();
66 if (tracking_viewstate)
67 footer_style.TrackViewState ();
70 return (footer_style);
74 [DefaultValue ("")]
75 [WebSysDescription ("")]
76 [WebCategory ("Misc")]
77 public virtual string FooterText {
78 get { return (viewstate.GetString ("FooterText", String.Empty)); }
79 set { viewstate["FooterText"] = value; }
82 [DefaultValue ("")]
83 [WebSysDescription ("")]
84 [WebCategory ("Misc")]
85 [UrlProperty]
86 public virtual string HeaderImageUrl {
87 get { return (viewstate.GetString ("HeaderImageUrl", String.Empty)); }
88 set { viewstate["HeaderImageUrl"] = value; }
91 [DefaultValue (null)]
92 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
93 [PersistenceMode (PersistenceMode.InnerProperty)]
94 [WebSysDescription ("")]
95 [WebCategory ("Misc")]
96 public virtual TableItemStyle HeaderStyle {
97 get {
98 if (header_style == null) {
99 header_style = new TableItemStyle ();
101 if (tracking_viewstate)
102 header_style.TrackViewState ();
105 return (header_style);
109 [DefaultValue ("")]
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 {
123 get {
124 if (item_style == null) {
125 item_style = new TableItemStyle ();
127 if (tracking_viewstate)
128 item_style.TrackViewState ();
131 return (item_style);
135 [DefaultValue ("")]
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)
161 if (control == null)
162 return Color.Empty;
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)
170 return color;
172 return GetForeColor ((WebControl) control.Parent);
175 protected internal override void Render (HtmlTextWriter writer)
177 Color color = GetForeColor (this);
178 if (color != Color.Empty)
179 ForeColor = color;
180 base.Render (writer);
184 public virtual void InitializeCell (TableCell cell, int columnIndex, ListItemType itemType)
186 switch (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 &nbsp;
200 bool sort = false;
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) {
208 if (sort) {
209 ImageButton butt = new ImageButton ();
211 /* Don't need to
212 * resolve this, Image
213 * does that when it
214 * renders
216 butt.ImageUrl = image_url;
217 butt.CommandName = "Sort";
218 butt.CommandArgument = sort_ex;
220 cell.Controls.Add (butt);
221 } else {
222 Image image = new Image ();
224 image.ImageUrl = image_url;
226 cell.Controls.Add (image);
228 } else {
229 if (sort) {
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);
240 } else {
241 string text = HeaderText;
242 if (text.Length > 0)
243 cell.Text = text;
244 else
245 cell.Text = "&nbsp;";
249 break;
251 case ListItemType.Footer:
253 /* Display FooterText or &nbsp; */
254 string text = FooterText;
256 if (text.Length > 0)
257 cell.Text = text;
258 else
259 cell.Text = "&nbsp;";
261 break;
263 default:
264 break;
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)
284 return header_style;
286 if (type == ListItemType.Footer)
287 return footer_style;
289 return item_style;
292 internal void Set_Owner (DataGrid value)
294 owner = 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 ()
320 TrackViewState ();
323 bool IStateManager.IsTrackingViewState {
324 get { return (IsTrackingViewState); }
327 protected virtual void LoadViewState (object savedState)
329 object[] pieces = savedState as object[];
331 if (pieces == null)
332 return;
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 ();
362 return (res);
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); }