(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Web / System.Web.UI.WebControls / RadioButtonList.cs
blob19078dfe5212a415ac297fbaf13be956e8e11c44
1 //
2 // System.Web.UI.WebControls.RadioButtonList.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.Collections.Specialized;
35 using System.ComponentModel;
36 using System.Globalization;
37 using System.Web;
38 using System.Web.UI;
40 namespace System.Web.UI.WebControls
42 [ValidationProperty("SelectedItem")]
43 public class RadioButtonList : ListControl, IRepeatInfoUser, INamingContainer, IPostBackDataHandler
45 private bool selectionIndexChanged;
46 private short tabIndex;
48 public RadioButtonList(): base()
50 selectionIndexChanged = false;
53 [DefaultValue (-1), Bindable (true), WebCategory ("Layout")]
54 [WebSysDescription ("The border left within a RadioButton.")]
55 public virtual int CellPadding
57 get
59 if(ControlStyleCreated)
61 return (int)(((TableStyle)ControlStyle).CellPadding);
63 return -1;
65 set {
66 if (value < -1)
67 throw new ArgumentOutOfRangeException ("value", "CellPadding value has to be -1 for 'not set' or > -1.");
68 ((TableStyle)ControlStyle).CellPadding = value;
72 [DefaultValue (-1), Bindable (true), WebCategory ("Layout")]
73 [WebSysDescription ("The border left between RadioButtons.")]
74 public virtual int CellSpacing
76 get
78 if(ControlStyleCreated)
80 return (int)(((TableStyle)ControlStyle).CellSpacing);
82 return -1;
84 set {
85 if (value < -1)
86 throw new ArgumentOutOfRangeException ("value", "CellSpacing value has to be -1 for 'not set' or > -1.");
87 ((TableStyle)ControlStyle).CellSpacing = value;
91 [DefaultValue (0), Bindable (true), WebCategory ("Layout")]
92 [WebSysDescription ("The number of columns that should be used to display the RadioButtons.")]
93 public virtual int RepeatColumns
95 get
97 object o = ViewState["RepeatColumns"];
98 if(o != null)
99 return (int)o;
100 return 0;
102 set {
103 if (value < 0)
104 throw new ArgumentOutOfRangeException ("value", "RepeatColumns value has to be 0 for 'not set' or > 0.");
105 ViewState["RepeatColumns"] = value;
109 [DefaultValue (typeof (RepeatDirection), "Vertical"), Bindable (true), WebCategory ("Layout")]
110 [WebSysDescription ("The direction that is followed when doing the layout.")]
111 public virtual RepeatDirection RepeatDirection
115 object o = ViewState["RepeatDirection"];
116 if(o != null)
117 return (RepeatDirection)o;
118 return RepeatDirection.Vertical;
122 if(!Enum.IsDefined(typeof(RepeatDirection), value))
123 throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
124 ViewState["RepeatDirection"] = value;
128 [DefaultValue (typeof (RepeatLayout), "Table"), Bindable (true), WebCategory ("Layout")]
129 [WebSysDescription ("The method used to create the layout.")]
130 public virtual RepeatLayout RepeatLayout
134 object o = ViewState["RepeatLayout"];
135 if(o != null)
136 return (RepeatLayout)o;
137 return RepeatLayout.Table;
141 if(!Enum.IsDefined(typeof(RepeatLayout), value))
142 throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
143 ViewState["RepeatLayout"] = value;
147 [DefaultValue (typeof (TextAlign), "Right"), Bindable (true), WebCategory ("Appearance")]
148 [WebSysDescription ("The alignment of the RadioButton text.")]
149 public virtual TextAlign TextAlign
153 object o = ViewState["TextAlign"];
154 if(o != null)
155 return (TextAlign)o;
156 return TextAlign.Right;
160 if(!Enum.IsDefined(typeof(TextAlign), value))
161 throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
162 ViewState["TextAlign"] = value;
166 protected override Style CreateControlStyle()
168 return new TableStyle(ViewState);
171 protected override void Render(HtmlTextWriter writer)
173 RepeatInfo info = new RepeatInfo();
174 Style cStyle = (ControlStyleCreated ? ControlStyle : null);
175 bool dirty = false;
176 tabIndex = TabIndex;
177 if(tabIndex != 0)
179 dirty = !ViewState.IsItemDirty("TabIndex");
180 TabIndex = 0;
182 info.RepeatColumns = RepeatColumns;
183 info.RepeatDirection = RepeatDirection;
184 info.RepeatLayout = RepeatLayout;
185 info.RenderRepeater(writer, this, cStyle, this);
186 if(tabIndex != 0)
188 TabIndex = tabIndex;
190 if(dirty)
192 ViewState.SetItemDirty("TabIndex", false);
196 bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
198 string value = postCollection [postDataKey];
199 int c = Items.Count;
200 for (int i = 0; i < c; i++) {
201 if (Items [i].Value != value)
202 continue;
204 if (i != SelectedIndex) {
205 SelectedIndex = i;
206 selectionIndexChanged = true;
209 return true;
212 return false;
215 void IPostBackDataHandler.RaisePostDataChangedEvent()
217 if(selectionIndexChanged)
218 OnSelectedIndexChanged(EventArgs.Empty);
221 Style IRepeatInfoUser.GetItemStyle(System.Web.UI.WebControls.ListItemType itemType, int repeatIndex)
223 return null;
226 void IRepeatInfoUser.RenderItem (System.Web.UI.WebControls.ListItemType itemType,
227 int repeatIndex,
228 RepeatInfo repeatInfo,
229 HtmlTextWriter writer)
231 /* Create a new RadioButton as if it was defined in the page and render it */
232 RadioButton button = new RadioButton ();
233 button.Page = Page;
234 button.GroupName = UniqueID;
235 button.TextAlign = TextAlign;
236 button.AutoPostBack = AutoPostBack;
237 button.ID = ClientID + "_" + repeatIndex.ToString (NumberFormatInfo.InvariantInfo);;
238 button.TabIndex = tabIndex;
239 ListItem current = Items [repeatIndex];
240 button.Text = current.Text;
241 button.Attributes ["value"] = current.Value;
242 button.Checked = current.Selected;
243 button.Enabled = Enabled;
244 button.RenderControl (writer);
247 bool IRepeatInfoUser.HasFooter
251 return false;
255 bool IRepeatInfoUser.HasHeader
259 return false;
263 bool IRepeatInfoUser.HasSeparators
267 return false;
271 int IRepeatInfoUser.RepeatedItemCount
275 return Items.Count;