2005-09-09 Chris Toshok <toshok@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / RadioButtonList.cs
1 //
2 // System.Web.UI.WebControls.RadioButtonList.cs
3 //
4 // Authors:
5 //    Jordi Mas i Hernandez (jordi@ximian.com)
6 //
7 // (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9 //
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //
31
32 using System.Collections;
33 using System.ComponentModel;
34 using System.Collections.Specialized;
35
36 namespace System.Web.UI.WebControls {
37
38         [ValidationProperty ("SelectedItem")]
39         public class RadioButtonList : ListControl, IRepeatInfoUser,
40                 INamingContainer, IPostBackDataHandler {
41
42                 public RadioButtonList ()
43                 {
44
45                 }
46
47 #if ONLY_1_1
48                 [Bindable (true)]
49 #endif          
50                 [DefaultValue (-1)]
51                 [WebSysDescription ("")]
52                 [WebCategory ("Layout")]
53                 public virtual int CellPadding {
54                         get {
55                                 if (ControlStyleCreated == false)
56                                         return -1; // default value
57
58                                 return ((TableStyle) ControlStyle).CellPadding;
59                         }
60
61                         set {
62                                 ((TableStyle) ControlStyle).CellPadding = value;
63                         }
64                 }
65
66 #if ONLY_1_1
67                 [Bindable (true)]
68 #endif          
69                 [DefaultValue (-1)]
70                 [WebSysDescription ("")]
71                 [WebCategory ("Layout")]
72                 public virtual int CellSpacing {
73                         get {
74                                 if (ControlStyleCreated == false)
75                                         return -1; // default value
76
77                                 return ((TableStyle) ControlStyle).CellSpacing;
78                         }
79
80                         set {
81                                 ((TableStyle) ControlStyle).CellSpacing = value;
82                         }
83                 }
84
85 #if ONLY_1_1
86                 [Bindable (true)]
87 #endif          
88                 [DefaultValue (0)]
89                 [WebSysDescription ("")]
90                 [WebCategory ("Layout")]
91                 public virtual int RepeatColumns  {
92                         get {
93                                 return ViewState.GetInt ("RepeatColumns", 0);
94                         }
95
96                         set {
97                                 if (value < 0)
98                                         throw new ArgumentOutOfRangeException ("The number of columns is set to a negative value.");
99
100                                 ViewState ["RepeatColumns"] = value;
101                         }
102                 }
103
104 #if ONLY_1_1
105                 [Bindable (true)]
106 #endif          
107                 [DefaultValue (RepeatDirection.Vertical)]
108                 [WebSysDescription ("")]
109                 [WebCategory ("Layout")]
110                 public virtual RepeatDirection RepeatDirection {
111                         get {
112                                 return (RepeatDirection) ViewState.GetInt ("RepeatDirection", (int) RepeatDirection.Vertical);
113                         }
114
115                         set {
116                                 if (value != RepeatDirection.Horizontal && value != RepeatDirection.Vertical)
117                                         throw new ArgumentOutOfRangeException ("he display direction of the list is not one of the RepeatDirection values.");
118
119                                 ViewState ["RepeatDirection"] = value;
120                         }
121                 }
122
123 #if ONLY_1_1
124                 [Bindable (true)]
125 #endif          
126                 [DefaultValue (RepeatLayout.Table)]
127                 [WebSysDescription ("")]
128                 [WebCategory ("Layout")]
129                 public virtual RepeatLayout RepeatLayout {
130                         get {
131                                 return (RepeatLayout) ViewState.GetInt ("RepeatLayout", (int) RepeatLayout.Table);
132                         }
133
134                         set {
135                                 if (value != RepeatLayout.Flow && value != RepeatLayout.Table)
136                                         throw new ArgumentOutOfRangeException ("The radio buttons layout is not one of the RepeatLayout values.");
137
138                                 ViewState ["RepeatLayout"] = value;
139                         }
140                 }
141
142 #if ONLY_1_1
143                 [Bindable (true)]
144 #endif          
145                 [DefaultValue (TextAlign.Right)]
146                 [WebSysDescription ("")]
147                 [WebCategory ("Appearance")]
148                 public virtual TextAlign TextAlign {
149                         get {
150                                 return (TextAlign )ViewState.GetInt ("TextAlign", (int) TextAlign.Right);
151                         }
152
153                         set {
154                                 if (value != TextAlign.Left && value != TextAlign.Right)
155                                         throw new ArgumentOutOfRangeException ("The label text alignment associated with the radio buttons is not one of the TextAlign values.");
156
157                                 ViewState ["TextAlign"] = value;
158                         }
159                 }
160
161                 // Interface properties
162
163 #if NET_2_0
164                 [MonoTODO]
165                 protected virtual bool HasFooter
166                 {
167                         get {
168                                 throw new NotImplementedException ();
169                         }
170                 }
171
172                 [MonoTODO]
173                 protected virtual bool HasHeader 
174                 {
175                         get {
176                                 throw new NotImplementedException ();
177                         }
178                 }
179
180                 [MonoTODO]
181                 protected virtual bool HasSeparators
182                 {
183                         get {
184                                 throw new NotImplementedException ();
185                         }
186                 }
187                 
188                 [MonoTODO]
189                 protected virtual int RepeatedItemCount
190                 {
191                         get {
192                                 throw new NotImplementedException ();
193                         }
194                 }
195 #endif
196                 
197                 bool IRepeatInfoUser.HasFooter {
198                         get { return false; }
199                 }
200
201                 bool IRepeatInfoUser.HasHeader {
202                         get { return false; }
203                 }
204
205                 bool IRepeatInfoUser.HasSeparators {
206                         get { return false; }
207                 }
208
209                 int IRepeatInfoUser.RepeatedItemCount {
210                         get { return Items.Count; }
211                 }
212
213                 protected override Style CreateControlStyle ()
214                 {
215                         return new TableStyle (ViewState);
216                 }
217
218 #if NET_2_0
219                 [MonoTODO]
220                 protected override Control FindControl (string id, int pathOffset)
221                 {
222                         throw new NotImplementedException ();
223                 }
224 #endif
225
226 #if NET_2_0
227                 protected virtual
228 #endif
229                 Style GetItemStyle (ListItemType itemType, int repeatIndex)
230                 {
231                         return null;
232                 }
233
234 #if NET_2_0
235                 protected virtual
236 #endif
237                 void RenderItem (ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
238                 {
239                         RadioButton radio = new RadioButton ();
240                         radio.Text = Items [repeatIndex].Text;
241                         radio.ID = ClientID + "_"  + repeatIndex;
242                         radio.TextAlign = TextAlign;
243                         radio.GroupName = UniqueID;
244                         radio.Page = Page;
245                         radio.Checked = Items [repeatIndex].Selected;
246                         radio.Attributes["Value"] = Items [repeatIndex].Value;
247                         radio.RenderControl (writer);
248                 }
249
250                 [MonoTODO]
251 #if NET_2_0
252                 protected virtual
253 #endif
254                 bool LoadPostData (string postDataKey, NameValueCollection postCollection)
255                 {
256                         return true;
257                 }
258
259                 [MonoTODO]
260 #if NET_2_0
261                 protected virtual
262 #endif
263                 void RaisePostDataChangedEvent ()
264                 {
265                 }
266
267
268                 bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
269                 {
270                         return LoadPostData (postDataKey, postCollection);
271                 }
272                 
273                 void IPostBackDataHandler.RaisePostDataChangedEvent ()
274                 {
275                         RaisePostDataChangedEvent ();
276                 }
277
278                 Style IRepeatInfoUser.GetItemStyle (ListItemType itemType,  int repeatIndex)
279                 {
280                         return GetItemStyle (itemType, repeatIndex);
281                 }
282
283                 void IRepeatInfoUser.RenderItem (ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
284                 {
285                         RenderItem (itemType, repeatIndex, repeatInfo, writer);
286                 }
287
288 #if NET_2_0
289                 protected internal
290 #else           
291                 protected
292 #endif          
293                 override void Render (HtmlTextWriter writer)
294                 {
295                         RepeatInfo repeat = new RepeatInfo ();
296                         repeat.RepeatColumns = RepeatColumns;
297                         repeat.RepeatDirection = RepeatDirection;
298                         repeat.RepeatLayout = RepeatLayout;
299                         repeat.RenderRepeater (writer, this, ControlStyle, this);
300                 }
301         }
302
303 }
304