2
0

BulletedList.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. //
  2. // System.Web.UI.WebControls.BulletedList.cs
  3. //
  4. // Authors:
  5. // Ben Maurer ([email protected])
  6. //
  7. // (C) 2003 Ben Maurer
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System.IO;
  31. using System.Collections;
  32. using System.Globalization;
  33. using System.Text;
  34. using System.Drawing;
  35. using System.ComponentModel;
  36. using System.ComponentModel.Design;
  37. using System.Security.Permissions;
  38. namespace System.Web.UI.WebControls {
  39. // CAS
  40. [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  41. [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  42. // attributes
  43. [DesignerAttribute ("System.Web.UI.Design.WebControls.BulletedListDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  44. [DefaultEventAttribute ("Click")]
  45. [DefaultPropertyAttribute ("BulletStyle")]
  46. [SupportsEventValidation]
  47. public class BulletedList : ListControl, IPostBackEventHandler {
  48. [MonoTODO ("we are missing a new style enum, we should be using it")]
  49. protected override void AddAttributesToRender (HtmlTextWriter writer)
  50. {
  51. const string ListStyleType = "list-style-type";
  52. const string ListStyleImage = "list-style-image";
  53. bool isNumeric = false;
  54. switch (BulletStyle)
  55. {
  56. case BulletStyle.NotSet:
  57. break;
  58. case BulletStyle.Numbered:
  59. writer.AddStyleAttribute (ListStyleType, "decimal");
  60. isNumeric = true;
  61. break;
  62. case BulletStyle.LowerAlpha:
  63. writer.AddStyleAttribute (ListStyleType, "lower-alpha");
  64. isNumeric = true;
  65. break;
  66. case BulletStyle.UpperAlpha:
  67. writer.AddStyleAttribute (ListStyleType, "upper-alpha");
  68. isNumeric = true;
  69. break;
  70. case BulletStyle.LowerRoman:
  71. writer.AddStyleAttribute (ListStyleType, "lower-roman");
  72. isNumeric = true;
  73. break;
  74. case BulletStyle.UpperRoman:
  75. writer.AddStyleAttribute (ListStyleType, "lower-roman");
  76. isNumeric = true;
  77. break;
  78. case BulletStyle.Disc:
  79. writer.AddStyleAttribute (ListStyleType, "disc");
  80. break;
  81. case BulletStyle.Circle:
  82. writer.AddStyleAttribute (ListStyleType, "circle");
  83. break;
  84. case BulletStyle.Square:
  85. writer.AddStyleAttribute (ListStyleType, "square");
  86. break;
  87. case BulletStyle.CustomImage:
  88. writer.AddStyleAttribute (ListStyleImage, "url(" + BulletImageUrl+ ")");
  89. break;
  90. }
  91. if (isNumeric && FirstBulletNumber != 1)
  92. writer.AddAttribute ("start", FirstBulletNumber.ToString ());
  93. base.AddAttributesToRender (writer);
  94. }
  95. [MonoTODO ("new bool prop on ListItem: Enabled")]
  96. protected virtual void RenderBulletText (ListItem item, int index, HtmlTextWriter writer)
  97. {
  98. boo
  99. switch (DisplayMode) {
  100. case BulletedListDisplayMode.Text:
  101. //if (!item.Enabled) {
  102. // writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled");
  103. // writer.RenderBeginTag (HtmlTextWriterTag.Span);
  104. //}
  105. writer.Write (item.Text);
  106. //if (!item.Enabled)
  107. // writer.RenderEndTag ();
  108. break;
  109. case BulletedListDisplayMode.HyperLink:
  110. //if (Enabled && item.Enabled) {
  111. // writer.AddAttribute (HtmlTextWriterAttribute.Href, item.Value);
  112. // if (Target != "")
  113. // writer.AddAttribute(HtmlTextWriterAttribute.Target, this.Target);
  114. //
  115. //}
  116. //else
  117. writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled");
  118. writer.RenderBeginTag (HtmlTextWriterTag.A);
  119. writer.Write (item.Text);
  120. writer.RenderEndTag ();
  121. break;
  122. case BulletedListDisplayMode.LinkButton:
  123. //if (Enabled && item.Enabled)
  124. writer.AddAttribute (HtmlTextWriterAttribute.Href, Page.ClientScript.GetPostBackClientHyperlink (this, (index.ToString (CultureInfo.InvariantCulture))));
  125. //else
  126. // writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled");
  127. writer.RenderBeginTag (HtmlTextWriterTag.A);
  128. writer.Write (item.Text);
  129. writer.RenderEndTag ();
  130. break;
  131. }
  132. }
  133. protected internal override void RenderContents (HtmlTextWriter writer)
  134. {
  135. int idx = 0;
  136. foreach (ListItem i in Items) {
  137. writer.RenderBeginTag (HtmlTextWriterTag.Li);
  138. this.RenderBulletText (i, idx ++, writer);
  139. writer.RenderEndTag ();
  140. }
  141. }
  142. [MonoTODO]
  143. protected internal override void Render (HtmlTextWriter w)
  144. {
  145. throw new NotImplementedException ();
  146. }
  147. void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
  148. {
  149. RaisePostBackEvent (eventArgument);
  150. }
  151. [MonoTODO ("ListControl has a CausesValidation prop in v1.2, we need to use it")]
  152. protected virtual void RaisePostBackEvent (string eventArgument)
  153. {
  154. //if (CausesValidation)
  155. // Page.Validate ();
  156. this.OnClick (new BulletedListEventArgs (int.Parse (eventArgument, CultureInfo.InvariantCulture)));
  157. }
  158. [BrowsableAttribute (false)]
  159. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  160. public override bool AutoPostBack {
  161. get { return base.AutoPostBack; }
  162. set { throw new NotSupportedException (String.Format ("This property is not supported in {0}", GetType ())); }
  163. }
  164. [Bindable (false)]
  165. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  166. public override int SelectedIndex {
  167. get { return base.SelectedIndex; }
  168. set { throw new NotSupportedException (String.Format ("This property is not supported in {0}", GetType ())); }
  169. }
  170. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  171. public override ListItem SelectedItem {
  172. get { return base.SelectedItem; }
  173. }
  174. [EditorBrowsable (EditorBrowsableState.Never)]
  175. [Bindable (false)]
  176. [MonoTODO]
  177. public override string SelectedValue
  178. {
  179. get {
  180. throw new NotImplementedException ();
  181. }
  182. set {
  183. throw new NotImplementedException ();
  184. }
  185. }
  186. [DefaultValueAttribute ("")]
  187. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  188. [UrlPropertyAttribute]
  189. public virtual string BulletImageUrl {
  190. get {
  191. object ret = ViewState ["BulletImageUrl"];
  192. if (ret != null)
  193. return (string) ret;
  194. return "";
  195. }
  196. set {
  197. ViewState ["BulletImageUrl"] = value;
  198. }
  199. }
  200. [DefaultValueAttribute (BulletStyle.NotSet)]
  201. public virtual BulletStyle BulletStyle {
  202. get {
  203. object ret = ViewState ["BulletStyle"];
  204. if (ret != null)
  205. return (BulletStyle) ret;
  206. return BulletStyle.NotSet;
  207. }
  208. set {
  209. if ((int) value < 0 || (int) value > 9)
  210. throw new ArgumentOutOfRangeException ("value");
  211. ViewState ["BulletStyle"] = value;
  212. }
  213. }
  214. public override ControlCollection Controls { get { return new EmptyControlCollection (this); } }
  215. [DefaultValueAttribute (BulletedListDisplayMode.Text)]
  216. public virtual BulletedListDisplayMode DisplayMode {
  217. get {
  218. object ret = ViewState ["DisplayMode"];
  219. if (ret != null)
  220. return (BulletedListDisplayMode) ret;
  221. return BulletedListDisplayMode.Text;
  222. }
  223. set {
  224. if ((int) value < 0 || (int) value > 2)
  225. throw new ArgumentOutOfRangeException ("value");
  226. ViewState ["DisplayMode"] = value;
  227. }
  228. }
  229. [DefaultValueAttribute (1)]
  230. public virtual int FirstBulletNumber {
  231. get {
  232. object ret = ViewState ["FirstBulletNumber"];
  233. if (ret != null)
  234. return (int) ret;
  235. return 1;
  236. }
  237. set {
  238. ViewState ["FirstBulletNumber"] = value;
  239. }
  240. }
  241. protected override HtmlTextWriterTag TagKey {
  242. get {
  243. switch (BulletStyle) {
  244. case BulletStyle.Numbered:
  245. case BulletStyle.LowerAlpha:
  246. case BulletStyle.UpperAlpha:
  247. case BulletStyle.LowerRoman:
  248. case BulletStyle.UpperRoman:
  249. return HtmlTextWriterTag.Ol;
  250. case BulletStyle.NotSet:
  251. case BulletStyle.Disc:
  252. case BulletStyle.Circle:
  253. case BulletStyle.Square:
  254. case BulletStyle.CustomImage:
  255. default:
  256. return HtmlTextWriterTag.Ul;
  257. }
  258. }
  259. }
  260. [DefaultValueAttribute ("")]
  261. [TypeConverter (typeof (TargetConverter))]
  262. public virtual string Target {
  263. get {
  264. object ret = ViewState ["Target"];
  265. if (ret != null)
  266. return (string) ret;
  267. return "";
  268. }
  269. set {
  270. ViewState ["Target"] = value;
  271. }
  272. }
  273. [EditorBrowsable (EditorBrowsableState.Never)]
  274. [MonoTODO]
  275. public override string Text
  276. {
  277. get {
  278. throw new NotImplementedException ();
  279. }
  280. set {
  281. throw new NotImplementedException ();
  282. }
  283. }
  284. static readonly object ClickEvent = new object ();
  285. public event BulletedListEventHandler Click
  286. {
  287. add {
  288. Events.AddHandler (ClickEvent, value);
  289. }
  290. remove {
  291. Events.RemoveHandler (ClickEvent, value);
  292. }
  293. }
  294. protected virtual void OnClick (BulletedListEventArgs e)
  295. {
  296. if (Events != null) {
  297. BulletedListEventHandler eh = (BulletedListEventHandler) (Events [ClickEvent]);
  298. if (eh != null)
  299. eh (this, e);
  300. }
  301. }
  302. }
  303. }
  304. #endif