2 // System.Web.UI.WebControls.BulletedList.cs
5 // Ben Maurer (bmaurer@users.sourceforge.net)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
32 using System.Collections;
33 using System.Globalization;
36 using System.ComponentModel;
37 using System.ComponentModel.Design;
38 using System.Security.Permissions;
40 namespace System.Web.UI.WebControls {
43 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
44 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
46 [DesignerAttribute ("System.Web.UI.Design.WebControls.BulletedListDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
47 [DefaultEventAttribute ("Click")]
48 [DefaultPropertyAttribute ("BulletStyle")]
49 [SupportsEventValidation]
50 public class BulletedList : ListControl, IPostBackEventHandler {
52 PostBackOptions postBackOptions;
54 [MonoTODO ("we are missing a new style enum, we should be using it")]
55 protected override void AddAttributesToRender (HtmlTextWriter writer)
57 const string ListStyleType = "list-style-type";
58 const string ListStyleImage = "list-style-image";
60 bool isNumeric = false;
63 case BulletStyle.NotSet:
66 case BulletStyle.Numbered:
67 writer.AddStyleAttribute (ListStyleType, "decimal");
71 case BulletStyle.LowerAlpha:
72 writer.AddStyleAttribute (ListStyleType, "lower-alpha");
76 case BulletStyle.UpperAlpha:
77 writer.AddStyleAttribute (ListStyleType, "upper-alpha");
81 case BulletStyle.LowerRoman:
82 writer.AddStyleAttribute (ListStyleType, "lower-roman");
86 case BulletStyle.UpperRoman:
87 writer.AddStyleAttribute (ListStyleType, "upper-roman");
91 case BulletStyle.Disc:
92 writer.AddStyleAttribute (ListStyleType, "disc");
95 case BulletStyle.Circle:
96 writer.AddStyleAttribute (ListStyleType, "circle");
99 case BulletStyle.Square:
100 writer.AddStyleAttribute (ListStyleType, "square");
103 case BulletStyle.CustomImage:
104 writer.AddStyleAttribute (ListStyleImage, "url(" + BulletImageUrl+ ")");
108 if (isNumeric && FirstBulletNumber != 1)
109 writer.AddAttribute ("start", FirstBulletNumber.ToString ());
111 base.AddAttributesToRender (writer);
114 protected virtual void RenderBulletText (ListItem item, int index, HtmlTextWriter writer)
116 switch (DisplayMode) {
117 case BulletedListDisplayMode.Text:
119 writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled");
120 writer.RenderBeginTag (HtmlTextWriterTag.Span);
123 writer.Write (item.Text);
126 writer.RenderEndTag ();
130 case BulletedListDisplayMode.HyperLink:
131 if (Enabled && item.Enabled) {
132 writer.AddAttribute (HtmlTextWriterAttribute.Href, item.Value);
134 writer.AddAttribute(HtmlTextWriterAttribute.Target, this.Target);
138 writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled");
140 writer.RenderBeginTag (HtmlTextWriterTag.A);
141 writer.Write (item.Text);
142 writer.RenderEndTag ();
145 case BulletedListDisplayMode.LinkButton:
146 if (Enabled && item.Enabled)
147 writer.AddAttribute (HtmlTextWriterAttribute.Href, Page.ClientScript.GetPostBackEventReference (GetPostBackOptions (index.ToString (CultureInfo.InvariantCulture))));
149 writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled");
150 writer.RenderBeginTag (HtmlTextWriterTag.A);
151 writer.Write (item.Text);
152 writer.RenderEndTag ();
157 PostBackOptions GetPostBackOptions (string argument) {
158 if (postBackOptions == null) {
159 postBackOptions = new PostBackOptions (this);
160 postBackOptions.ActionUrl = null;
161 postBackOptions.ValidationGroup = null;
162 postBackOptions.RequiresJavaScriptProtocol = true;
163 postBackOptions.ClientSubmit = true;
164 postBackOptions.PerformValidation = CausesValidation && Page != null && Page.AreValidatorsUplevel (ValidationGroup);
165 if (postBackOptions.PerformValidation)
166 postBackOptions.ValidationGroup = ValidationGroup;
168 postBackOptions.Argument = argument;
169 return postBackOptions;
172 protected internal override void RenderContents (HtmlTextWriter writer)
176 bool havePage = Page != null;
178 foreach (ListItem i in Items) {
181 Page.ClientScript.RegisterForEventValidation (this.UniqueID, i.Value.ToString ());
184 i.Attributes.AddAttributes (writer);
186 writer.RenderBeginTag (HtmlTextWriterTag.Li);
187 this.RenderBulletText (i, idx ++, writer);
188 writer.RenderEndTag ();
192 protected internal override void Render (HtmlTextWriter writer)
194 base.Render (writer);
197 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
199 RaisePostBackEvent (eventArgument);
202 protected virtual void RaisePostBackEvent (string eventArgument)
204 if (CausesValidation)
205 Page.Validate (ValidationGroup);
207 this.OnClick (new BulletedListEventArgs (int.Parse (eventArgument, CultureInfo.InvariantCulture)));
210 [BrowsableAttribute (false)]
211 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
212 public override bool AutoPostBack {
213 get { return base.AutoPostBack; }
214 set { throw new NotSupportedException (String.Format ("This property is not supported in {0}", GetType ())); }
218 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
219 public override int SelectedIndex {
221 set { throw new NotSupportedException (String.Format ("This property is not supported in {0}", GetType ())); }
224 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
225 public override ListItem SelectedItem {
229 [EditorBrowsable (EditorBrowsableState.Never)]
231 public override string SelectedValue
233 get { return string.Empty; }
234 set { throw new NotSupportedException (); }
237 [DefaultValueAttribute ("")]
238 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
239 [UrlPropertyAttribute]
240 public virtual string BulletImageUrl {
241 get { return ViewState.GetString ("BulletImageUrl", ""); }
242 set { ViewState ["BulletImageUrl"] = value; }
245 [DefaultValueAttribute (BulletStyle.NotSet)]
246 public virtual BulletStyle BulletStyle {
247 get { return (BulletStyle) ViewState.GetInt ("BulletStyle", (int) BulletStyle.NotSet); }
249 if ((int) value < 0 || (int) value > 9)
250 throw new ArgumentOutOfRangeException ("value");
252 ViewState ["BulletStyle"] = value;
256 public override ControlCollection Controls { get { return new EmptyControlCollection (this); } }
258 [DefaultValueAttribute (BulletedListDisplayMode.Text)]
259 public virtual BulletedListDisplayMode DisplayMode {
260 get { return (BulletedListDisplayMode) ViewState.GetInt ("DisplayMode", (int)BulletedListDisplayMode.Text); }
262 if ((int) value < 0 || (int) value > 2)
263 throw new ArgumentOutOfRangeException ("value");
265 ViewState ["DisplayMode"] = value;
269 [DefaultValueAttribute (1)]
270 public virtual int FirstBulletNumber {
271 get { return ViewState.GetInt ("FirstBulletNumber", 1); }
272 set { ViewState ["FirstBulletNumber"] = value; }
276 protected override HtmlTextWriterTag TagKey {
278 switch (BulletStyle) {
279 case BulletStyle.Numbered:
280 case BulletStyle.LowerAlpha:
281 case BulletStyle.UpperAlpha:
282 case BulletStyle.LowerRoman:
283 case BulletStyle.UpperRoman:
284 return HtmlTextWriterTag.Ol;
286 case BulletStyle.NotSet:
287 case BulletStyle.Disc:
288 case BulletStyle.Circle:
289 case BulletStyle.Square:
290 case BulletStyle.CustomImage:
292 return HtmlTextWriterTag.Ul;
297 [DefaultValueAttribute ("")]
298 [TypeConverter (typeof (TargetConverter))]
299 public virtual string Target {
300 get { return ViewState.GetString ("Target", ""); }
301 set { ViewState ["Target"] = value; }
304 [EditorBrowsable (EditorBrowsableState.Never)]
305 public override string Text
307 get { return string.Empty; }
308 set { throw new NotSupportedException (); }
312 static readonly object ClickEvent = new object ();
313 public event BulletedListEventHandler Click
316 Events.AddHandler (ClickEvent, value);
319 Events.RemoveHandler (ClickEvent, value);
323 protected virtual void OnClick (BulletedListEventArgs e)
325 if (Events != null) {
326 BulletedListEventHandler eh = (BulletedListEventHandler) (Events [ClickEvent]);