2
0

ImageButton.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. //
  2. // System.Web.UI.WebControls.ImageButton.cs
  3. //
  4. // Authors:
  5. // Jordi Mas i Hernandez ([email protected])
  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. using System.Collections.Specialized;
  31. using System.ComponentModel;
  32. namespace System.Web.UI.WebControls {
  33. [DefaultEvent("Click")]
  34. #if NET_2_0
  35. [Designer ("System.Web.UI.Design.WebControls.PreviewControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  36. #endif
  37. public class ImageButton : Image, IPostBackDataHandler, IPostBackEventHandler
  38. #if NET_2_0
  39. , IButtonControl
  40. #endif
  41. {
  42. private static readonly object ClickEvent = new object ();
  43. private static readonly object CommandEvent = new object ();
  44. private int pos_x, pos_y;
  45. public ImageButton ()
  46. {
  47. }
  48. #if ONLY_1_1
  49. [Bindable(false)]
  50. #endif
  51. [DefaultValue(true)]
  52. [WebSysDescription ("")]
  53. [WebCategory ("Behavior")]
  54. #if NET_2_0
  55. [Themeable (false)]
  56. public virtual
  57. #else
  58. public
  59. #endif
  60. bool CausesValidation {
  61. get {
  62. return ViewState.GetBool ("CausesValidation", true);
  63. }
  64. set {
  65. ViewState ["CausesValidation"] = value;
  66. }
  67. }
  68. [Bindable(true)]
  69. [DefaultValue("")]
  70. [WebSysDescription ("")]
  71. [WebCategory ("Behavior")]
  72. #if NET_2_0
  73. [Themeable (false)]
  74. public virtual
  75. #else
  76. public
  77. #endif
  78. string CommandArgument {
  79. get {
  80. return ViewState.GetString ("CommandArgument", "");
  81. }
  82. set {
  83. ViewState ["CommandArgument"] = value;
  84. }
  85. }
  86. [DefaultValue("")]
  87. [WebSysDescription ("")]
  88. [WebCategory ("Behavior")]
  89. #if NET_2_0
  90. [Themeable (false)]
  91. public virtual
  92. #else
  93. public
  94. #endif
  95. string CommandName {
  96. get {
  97. return ViewState.GetString ("CommandName", "");
  98. }
  99. set {
  100. ViewState ["CommandName"] = value;
  101. }
  102. }
  103. #if NET_2_0
  104. [EditorBrowsable (EditorBrowsableState.Always)]
  105. [Browsable (true)]
  106. [DefaultValue (true)]
  107. [Bindable (true)]
  108. [MonoTODO]
  109. public virtual new bool Enabled
  110. {
  111. get {
  112. throw new NotImplementedException ();
  113. }
  114. set {
  115. throw new NotImplementedException ();
  116. }
  117. }
  118. [Browsable (false)]
  119. [EditorBrowsable (EditorBrowsableState.Never)]
  120. [Themeable (false)]
  121. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  122. [MonoTODO]
  123. public virtual new bool GenerateEmptyAlternateText
  124. {
  125. get {
  126. throw new NotImplementedException ();
  127. }
  128. set {
  129. throw new NotImplementedException ();
  130. }
  131. }
  132. [DefaultValue ("")]
  133. [Themeable (false)]
  134. [MonoTODO]
  135. public virtual string OnClientClick
  136. {
  137. get {
  138. throw new NotImplementedException ();
  139. }
  140. set {
  141. throw new NotImplementedException ();
  142. }
  143. }
  144. [Themeable (false)]
  145. [UrlProperty]
  146. [DefaultValue ("")]
  147. [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  148. [MonoTODO]
  149. public virtual string PostBackUrl
  150. {
  151. get {
  152. throw new NotImplementedException ();
  153. }
  154. set {
  155. throw new NotImplementedException ();
  156. }
  157. }
  158. [Themeable (false)]
  159. [DefaultValue ("")]
  160. [WebSysDescription ("")]
  161. [WebCategory ("Behavior")]
  162. public virtual string ValidationGroup
  163. {
  164. get {
  165. return ViewState.GetString ("ValidationGroup", "");
  166. }
  167. set {
  168. ViewState ["ValidationGroup"] = value;
  169. }
  170. }
  171. #endif
  172. [Browsable(false)]
  173. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  174. #if NET_2_0 && HAVE_CONTROL_ADAPTERS
  175. protected virtual new
  176. #else
  177. protected override
  178. #endif
  179. HtmlTextWriterTag TagKey {
  180. get { return HtmlTextWriterTag.Input; }
  181. }
  182. #if NET_2_0
  183. [MonoTODO]
  184. protected virtual string Text
  185. {
  186. get {
  187. throw new NotImplementedException ();
  188. }
  189. set {
  190. throw new NotImplementedException ();
  191. }
  192. }
  193. #endif
  194. protected override void AddAttributesToRender (HtmlTextWriter writer)
  195. {
  196. if (Page != null)
  197. Page.VerifyRenderingInServerForm (this);
  198. writer.AddAttribute (HtmlTextWriterAttribute.Type, "image");
  199. if (CausesValidation && Page != null && Page.AreValidatorsUplevel ()) {
  200. ClientScriptManager csm = new ClientScriptManager (Page);
  201. writer.AddAttribute (HtmlTextWriterAttribute.Onclick, csm.GetClientValidationEvent ());
  202. writer.AddAttribute ("language", "javascript");
  203. }
  204. base.AddAttributesToRender (writer);
  205. }
  206. #if NET_2_0
  207. [MonoTODO]
  208. protected virtual PostBackOptions GetPostBackOptions ()
  209. {
  210. throw new NotImplementedException ();
  211. }
  212. #endif
  213. #if NET_2_0
  214. [MonoTODO]
  215. protected virtual bool LoadPostData (string postDataKey, NameValueCollection psotCollection)
  216. {
  217. throw new NotImplementedException ();
  218. }
  219. [MonoTODO]
  220. protected virtual void RaisePostDataChangedEvent ()
  221. {
  222. throw new NotImplementedException ();
  223. }
  224. [MonoTODO]
  225. protected virtual void RaisePostBackEvent (string eventArgument)
  226. {
  227. throw new NotImplementedException ();
  228. }
  229. #endif
  230. bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
  231. {
  232. string x, y;
  233. x = postCollection [UniqueID + ".x"];
  234. y = postCollection [UniqueID + ".y"];
  235. if (x != null && y != null) {
  236. pos_x = Int32.Parse(x);
  237. pos_y = Int32.Parse(y);
  238. Page.RegisterRequiresRaiseEvent (this);
  239. }
  240. return true;
  241. }
  242. void IPostBackDataHandler.RaisePostDataChangedEvent ()
  243. {
  244. }
  245. void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
  246. {
  247. if (CausesValidation)
  248. #if NET_2_0
  249. Page.Validate (ValidationGroup);
  250. #else
  251. Page.Validate ();
  252. #endif
  253. OnClick (new ImageClickEventArgs (pos_x, pos_y));
  254. OnCommand (new CommandEventArgs (CommandName, CommandArgument));
  255. }
  256. protected virtual void OnClick (ImageClickEventArgs e)
  257. {
  258. if (Events != null) {
  259. EventHandler eh = (EventHandler) (Events [ClickEvent]);
  260. if (eh != null)
  261. eh (this, e);
  262. }
  263. }
  264. protected virtual void OnCommand (CommandEventArgs e)
  265. {
  266. if (Events != null) {
  267. CommandEventHandler eh = (CommandEventHandler) (Events [CommandEvent]);
  268. if (eh != null)
  269. eh (this, e);
  270. }
  271. RaiseBubbleEvent (this, e);
  272. }
  273. #if NET_2_0
  274. protected internal
  275. #else
  276. protected
  277. #endif
  278. override void OnPreRender (EventArgs e)
  279. {
  280. if (Page != null)
  281. Page.RegisterRequiresPostBack (this);
  282. }
  283. [WebSysDescription ("")]
  284. [WebCategory ("Action")]
  285. public event ImageClickEventHandler Click
  286. {
  287. add {
  288. Events.AddHandler (ClickEvent, value);
  289. }
  290. remove {
  291. Events.RemoveHandler (ClickEvent, value);
  292. }
  293. }
  294. [WebSysDescription ("")]
  295. [WebCategory ("Action")]
  296. public event CommandEventHandler Command
  297. {
  298. add {
  299. Events.AddHandler (CommandEvent, value);
  300. }
  301. remove {
  302. Events.RemoveHandler (CommandEvent, value);
  303. }
  304. }
  305. #if NET_2_0
  306. [MonoTODO]
  307. string IButtonControl.Text
  308. {
  309. get {
  310. throw new NotImplementedException ();
  311. }
  312. set {
  313. throw new NotImplementedException ();
  314. }
  315. }
  316. [MonoTODO]
  317. event EventHandler IButtonControl.Click
  318. {
  319. add {
  320. throw new NotImplementedException ();
  321. }
  322. remove {
  323. throw new NotImplementedException ();
  324. }
  325. }
  326. #endif
  327. }
  328. }