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 [MonoTODO ("we are missing a new style enum, we should be using it")]
53 protected override void AddAttributesToRender (HtmlTextWriter writer)
55 const string ListStyleType = "list-style-type";
56 const string ListStyleImage = "list-style-image";
58 bool isNumeric = false;
61 case BulletStyle.NotSet:
64 case BulletStyle.Numbered:
65 writer.AddStyleAttribute (ListStyleType, "decimal");
69 case BulletStyle.LowerAlpha:
70 writer.AddStyleAttribute (ListStyleType, "lower-alpha");
74 case BulletStyle.UpperAlpha:
75 writer.AddStyleAttribute (ListStyleType, "upper-alpha");
79 case BulletStyle.LowerRoman:
80 writer.AddStyleAttribute (ListStyleType, "lower-roman");
84 case BulletStyle.UpperRoman:
85 writer.AddStyleAttribute (ListStyleType, "upper-roman");
89 case BulletStyle.Disc:
90 writer.AddStyleAttribute (ListStyleType, "disc");
93 case BulletStyle.Circle:
94 writer.AddStyleAttribute (ListStyleType, "circle");
97 case BulletStyle.Square:
98 writer.AddStyleAttribute (ListStyleType, "square");
101 case BulletStyle.CustomImage:
102 writer.AddStyleAttribute (ListStyleImage, "url(" + BulletImageUrl+ ")");
106 if (isNumeric && FirstBulletNumber != 1)
107 writer.AddAttribute ("start", FirstBulletNumber.ToString ());
109 base.AddAttributesToRender (writer);
112 protected virtual void RenderBulletText (ListItem item, int index, HtmlTextWriter writer)
114 switch (DisplayMode) {
115 case BulletedListDisplayMode.Text:
117 writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled");
118 writer.RenderBeginTag (HtmlTextWriterTag.Span);
121 writer.Write (item.Text);
124 writer.RenderEndTag ();
128 case BulletedListDisplayMode.HyperLink:
129 if (Enabled && item.Enabled) {
130 writer.AddAttribute (HtmlTextWriterAttribute.Href, item.Value);
132 writer.AddAttribute(HtmlTextWriterAttribute.Target, this.Target);
136 writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled");
138 writer.RenderBeginTag (HtmlTextWriterTag.A);
139 writer.Write (item.Text);
140 writer.RenderEndTag ();
143 case BulletedListDisplayMode.LinkButton:
144 if (Enabled && item.Enabled)
145 writer.AddAttribute (HtmlTextWriterAttribute.Href, Page.ClientScript.GetPostBackClientHyperlink (this, (index.ToString (CultureInfo.InvariantCulture))));
147 writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled");
148 writer.RenderBeginTag (HtmlTextWriterTag.A);
149 writer.Write (item.Text);
150 writer.RenderEndTag ();
155 protected internal override void RenderContents (HtmlTextWriter writer)
158 foreach (ListItem i in Items) {
159 writer.RenderBeginTag (HtmlTextWriterTag.Li);
160 this.RenderBulletText (i, idx ++, writer);
161 writer.RenderEndTag ();
165 protected internal override void Render (HtmlTextWriter writer)
167 base.Render (writer);
170 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
172 RaisePostBackEvent (eventArgument);
175 [MonoTODO ("ListControl has a CausesValidation prop in v1.2, we need to use it")]
176 protected virtual void RaisePostBackEvent (string eventArgument)
178 //if (CausesValidation)
181 this.OnClick (new BulletedListEventArgs (int.Parse (eventArgument, CultureInfo.InvariantCulture)));
184 [BrowsableAttribute (false)]
185 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
186 public override bool AutoPostBack {
187 get { return base.AutoPostBack; }
188 set { throw new NotSupportedException (String.Format ("This property is not supported in {0}", GetType ())); }
192 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
193 public override int SelectedIndex {
195 set { throw new NotSupportedException (String.Format ("This property is not supported in {0}", GetType ())); }
198 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
199 public override ListItem SelectedItem {
203 [EditorBrowsable (EditorBrowsableState.Never)]
205 public override string SelectedValue
207 get { return string.Empty; }
208 set { throw new NotSupportedException (); }
211 [DefaultValueAttribute ("")]
212 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
213 [UrlPropertyAttribute]
214 public virtual string BulletImageUrl {
215 get { return ViewState.GetString ("BulletImageUrl", ""); }
216 set { ViewState ["BulletImageUrl"] = value; }
219 [DefaultValueAttribute (BulletStyle.NotSet)]
220 public virtual BulletStyle BulletStyle {
221 get { return (BulletStyle) ViewState.GetInt ("BulletStyle", (int) BulletStyle.NotSet); }
223 if ((int) value < 0 || (int) value > 9)
224 throw new ArgumentOutOfRangeException ("value");
226 ViewState ["BulletStyle"] = value;
230 public override ControlCollection Controls { get { return new EmptyControlCollection (this); } }
232 [DefaultValueAttribute (BulletedListDisplayMode.Text)]
233 public virtual BulletedListDisplayMode DisplayMode {
234 get { return (BulletedListDisplayMode) ViewState.GetInt ("DisplayMode", (int)BulletedListDisplayMode.Text); }
236 if ((int) value < 0 || (int) value > 2)
237 throw new ArgumentOutOfRangeException ("value");
239 ViewState ["DisplayMode"] = value;
243 [DefaultValueAttribute (1)]
244 public virtual int FirstBulletNumber {
245 get { return ViewState.GetInt ("FirstBulletNumber", 1); }
246 set { ViewState ["FirstBulletNumber"] = value; }
250 protected override HtmlTextWriterTag TagKey {
252 switch (BulletStyle) {
253 case BulletStyle.Numbered:
254 case BulletStyle.LowerAlpha:
255 case BulletStyle.UpperAlpha:
256 case BulletStyle.LowerRoman:
257 case BulletStyle.UpperRoman:
258 return HtmlTextWriterTag.Ol;
260 case BulletStyle.NotSet:
261 case BulletStyle.Disc:
262 case BulletStyle.Circle:
263 case BulletStyle.Square:
264 case BulletStyle.CustomImage:
266 return HtmlTextWriterTag.Ul;
271 [DefaultValueAttribute ("")]
272 [TypeConverter (typeof (TargetConverter))]
273 public virtual string Target {
274 get { return ViewState.GetString ("Target", ""); }
275 set { ViewState ["Target"] = value; }
278 [EditorBrowsable (EditorBrowsableState.Never)]
279 public override string Text
281 get { return string.Empty; }
282 set { throw new NotSupportedException (); }
286 static readonly object ClickEvent = new object ();
287 public event BulletedListEventHandler Click
290 Events.AddHandler (ClickEvent, value);
293 Events.RemoveHandler (ClickEvent, value);
297 protected virtual void OnClick (BulletedListEventArgs e)
299 if (Events != null) {
300 BulletedListEventHandler eh = (BulletedListEventHandler) (Events [ClickEvent]);