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;
39 namespace System.Web.UI.WebControls {
41 [DesignerAttribute ("System.Web.UI.Design.WebControls.BulletedListDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
42 [DefaultEventAttribute ("Click")]
43 [DefaultPropertyAttribute ("BulletStyle")]
44 public class BulletedList : ListControl, IPostBackEventHandler {
46 [MonoTODO ("we are missing a new style enum, we should be using it")]
47 protected override void AddAttributesToRender (HtmlTextWriter writer)
49 const string ListStyleType = "list-style-type";
50 const string ListStyleImage = "list-style-image";
52 bool isNumeric = false;
55 case BulletStyle.NotSet:
58 case BulletStyle.Numbered:
59 writer.AddStyleAttribute (ListStyleType, "decimal");
63 case BulletStyle.LowerAlpha:
64 writer.AddStyleAttribute (ListStyleType, "lower-alpha");
68 case BulletStyle.UpperAlpha:
69 writer.AddStyleAttribute (ListStyleType, "upper-alpha");
73 case BulletStyle.LowerRoman:
74 writer.AddStyleAttribute (ListStyleType, "lower-roman");
78 case BulletStyle.UpperRoman:
79 writer.AddStyleAttribute (ListStyleType, "lower-roman");
83 case BulletStyle.Disc:
84 writer.AddStyleAttribute (ListStyleType, "disc");
87 case BulletStyle.Circle:
88 writer.AddStyleAttribute (ListStyleType, "circle");
91 case BulletStyle.Square:
92 writer.AddStyleAttribute (ListStyleType, "square");
95 case BulletStyle.CustomImage:
96 writer.AddStyleAttribute (ListStyleImage, "url(" + BulletImageUrl+ ")");
100 if (isNumeric && FirstBulletNumber != 1)
101 writer.AddAttribute ("start", FirstBulletNumber.ToString ());
103 base.AddAttributesToRender (writer);
107 [MonoTODO ("new bool prop on ListItem: Enabled")]
108 protected virtual void RenderBulletText (ListItem item, int index, HtmlTextWriter writer)
110 switch (DisplayMode) {
111 case BulletedListDisplayMode.Text:
112 //if (!item.Enabled) {
113 // writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled");
114 // writer.RenderBeginTag (HtmlTextWriterTag.Span);
116 writer.Write (item.Text);
118 // writer.RenderEndTag ();
121 case BulletedListDisplayMode.HyperLink:
122 //if (cacheIsEnabled && item.Enabled) {
123 // writer.AddAttribute (HtmlTextWriterAttribute.Href, item.Value);
125 // writer.AddAttribute(HtmlTextWriterAttribute.Target, this.Target);
129 writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled");
131 writer.RenderBeginTag (HtmlTextWriterTag.A);
132 writer.Write (item.Text);
133 writer.RenderEndTag ();
136 case BulletedListDisplayMode.LinkButton:
137 //if (cacheIsEnabled && item.Enabled)
138 writer.AddAttribute (HtmlTextWriterAttribute.Href, Page.ClientScript.GetPostBackClientHyperlink (this, (index.ToString (CultureInfo.InvariantCulture))));
140 // writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled");
141 writer.RenderBeginTag (HtmlTextWriterTag.A);
142 writer.Write (item.Text);
143 writer.RenderEndTag ();
148 protected internal override void RenderContents (HtmlTextWriter writer)
150 cacheIsEnabled = this.Enabled;
152 foreach (ListItem i in Items) {
153 writer.RenderBeginTag (HtmlTextWriterTag.Li);
154 this.RenderBulletText (i, idx ++, writer);
155 writer.RenderEndTag ();
160 protected internal override void Render (HtmlTextWriter w)
162 throw new NotImplementedException ();
165 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
167 RaisePostBackEvent (eventArgument);
170 [MonoTODO ("ListControl has a CausesValidation prop in v1.2, we need to use it")]
171 protected virtual void RaisePostBackEvent (string eventArgument)
173 //if (CausesValidation)
176 this.OnClick (new BulletedListEventArgs (int.Parse (eventArgument, CultureInfo.InvariantCulture)));
179 [BrowsableAttribute (false)]
180 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
181 public override bool AutoPostBack {
182 get { return base.AutoPostBack; }
183 set { throw new NotSupportedException (String.Format ("This property is not supported in {0}", GetType ())); }
187 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
188 public override int SelectedIndex {
189 get { return base.SelectedIndex; }
190 set { throw new NotSupportedException (String.Format ("This property is not supported in {0}", GetType ())); }
193 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
194 public override ListItem SelectedItem {
195 get { return base.SelectedItem; }
198 [EditorBrowsable (EditorBrowsableState.Never)]
201 public override string SelectedValue
204 throw new NotImplementedException ();
207 throw new NotImplementedException ();
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 {
216 object ret = ViewState ["BulletImageUrl"];
223 ViewState ["BulletImageUrl"] = value;
227 [DefaultValueAttribute (BulletStyle.NotSet)]
228 public virtual BulletStyle BulletStyle {
230 object ret = ViewState ["BulletStyle"];
232 return (BulletStyle) ret;
234 return BulletStyle.NotSet;
237 if ((int) value < 0 || (int) value > 9)
238 throw new ArgumentOutOfRangeException ("value");
240 ViewState ["BulletStyle"] = value;
244 public override ControlCollection Controls { get { return new EmptyControlCollection (this); } }
246 [DefaultValueAttribute (BulletedListDisplayMode.Text)]
247 public virtual BulletedListDisplayMode DisplayMode {
249 object ret = ViewState ["DisplayMode"];
251 return (BulletedListDisplayMode) ret;
253 return BulletedListDisplayMode.Text;
256 if ((int) value < 0 || (int) value > 2)
257 throw new ArgumentOutOfRangeException ("value");
259 ViewState ["DisplayMode"] = value;
263 [DefaultValueAttribute (1)]
264 public virtual int FirstBulletNumber {
266 object ret = ViewState ["FirstBulletNumber"];
273 ViewState ["FirstBulletNumber"] = value;
278 protected override HtmlTextWriterTag TagKey {
280 switch (BulletStyle) {
281 case BulletStyle.Numbered:
282 case BulletStyle.LowerAlpha:
283 case BulletStyle.UpperAlpha:
284 case BulletStyle.LowerRoman:
285 case BulletStyle.UpperRoman:
286 return HtmlTextWriterTag.Ol;
288 case BulletStyle.NotSet:
289 case BulletStyle.Disc:
290 case BulletStyle.Circle:
291 case BulletStyle.Square:
292 case BulletStyle.CustomImage:
294 return HtmlTextWriterTag.Ul;
299 [DefaultValueAttribute ("")]
300 [TypeConverter (typeof (TargetConverter))]
301 public virtual string Target {
303 object ret = ViewState ["Target"];
310 ViewState ["Target"] = value;
314 [EditorBrowsable (EditorBrowsableState.Never)]
316 public override string Text
319 throw new NotImplementedException ();
322 throw new NotImplementedException ();
327 static readonly object ClickEvent = new object ();
328 public event BulletedListEventHandler Click
331 Events.AddHandler (ClickEvent, value);
334 Events.RemoveHandler (ClickEvent, value);
338 protected virtual void OnClick (BulletedListEventArgs e)
340 if (Events != null) {
341 BulletedListEventHandler eh = (BulletedListEventHandler) (Events [ClickEvent]);