2
0

Command.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //
  2. // Permission is hereby granted, free of charge, to any person obtaining
  3. // a copy of this software and associated documentation files (the
  4. // "Software"), to deal in the Software without restriction, including
  5. // without limitation the rights to use, copy, modify, merge, publish,
  6. // distribute, sublicense, and/or sell copies of the Software, and to
  7. // permit persons to whom the Software is furnished to do so, subject to
  8. // the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be
  11. // included in all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  17. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  18. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  19. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. //
  21. /**
  22. * Project : Mono
  23. * Namespace : System.Web.UI.MobileControls
  24. * Class : Command
  25. * Author : Gaurav Vaish
  26. *
  27. * Copyright : 2003 with Gaurav Vaish, and with
  28. * Ximian Inc
  29. */
  30. using System.Collections.Specialized;
  31. using System.Web.UI;
  32. using System.Web.UI.WebControls;
  33. namespace System.Web.UI.MobileControls
  34. {
  35. public class Command : TextControl, IPostBackEventHandler,
  36. IPostBackDataHandler
  37. {
  38. private static readonly object ClickEvent = new object();
  39. private static readonly object ItemCommandEvent = new object();
  40. public Command()
  41. {
  42. }
  43. public event EventHandler Click
  44. {
  45. add
  46. {
  47. Events.AddHandler(ClickEvent, value);
  48. }
  49. remove
  50. {
  51. Events.RemoveHandler(ClickEvent, value);
  52. }
  53. }
  54. public event ObjectListCommandEventHandler ItemCommand
  55. {
  56. add
  57. {
  58. Events.AddHandler(ItemCommandEvent, value);
  59. }
  60. remove
  61. {
  62. Events.RemoveHandler(ItemCommandEvent, value);
  63. }
  64. }
  65. bool IPostBackDataHandler.LoadPostData(string key,
  66. NameValueCollection data)
  67. {
  68. bool dataChanged;
  69. bool stateChanged = Adapter.LoadPostData(key, data, null, out dataChanged);
  70. if(stateChanged)
  71. {
  72. if(dataChanged)
  73. Page.RegisterRequiresRaiseEvent(this);
  74. } else
  75. {
  76. if(data[key] != null)
  77. Page.RegisterRequiresRaiseEvent(this);
  78. }
  79. return false;
  80. }
  81. void IPostBackDataHandler.RaisePostDataChangedEvent()
  82. {
  83. }
  84. void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
  85. {
  86. if(CausesValidation)
  87. MobilePage.Validate();
  88. Form.CurrentPage = 1;
  89. OnClick(EventArgs.Empty);
  90. OnItemCommand(new CommandEventArgs(CommandName, CommandArgument));
  91. }
  92. public bool CausesValidation
  93. {
  94. get
  95. {
  96. object o = ViewState["CausesValidation"];
  97. if(o != null)
  98. return (bool)o;
  99. return true;
  100. }
  101. set
  102. {
  103. ViewState["CausesValidation"] = value;
  104. }
  105. }
  106. public string CommandArgument
  107. {
  108. get
  109. {
  110. object o = ViewState["CommandArgument"];
  111. if(o != null)
  112. return (string)o;
  113. return String.Empty;
  114. }
  115. set
  116. {
  117. ViewState["CommandArgument"] = value;
  118. }
  119. }
  120. public string CommandName
  121. {
  122. get
  123. {
  124. object o = ViewState["CommandName"];
  125. if(o != null)
  126. return (string)o;
  127. return String.Empty;
  128. }
  129. set
  130. {
  131. ViewState["CommandName"] = value;
  132. }
  133. }
  134. public CommandFormat Format
  135. {
  136. get
  137. {
  138. object o = ViewState["Format"];
  139. if(o != null)
  140. return (CommandFormat)o;
  141. return CommandFormat.Button;
  142. }
  143. set
  144. {
  145. //if(!System.Enum.IsDefined(typeof(CommandFormat), value)
  146. // throw new ArgumentException("Illegal value");
  147. ViewState["Format"] = value;
  148. }
  149. }
  150. public string ImageUrl
  151. {
  152. get
  153. {
  154. object o = ViewState["ImageUrl"];
  155. if(o != null)
  156. return (string)o;
  157. return String.Empty;
  158. }
  159. set
  160. {
  161. ViewState["ImageUrl"] = value;
  162. }
  163. }
  164. public string SoftKeyLabel
  165. {
  166. get
  167. {
  168. object o = ViewState["SoftKeyLabel"];
  169. if(o != null)
  170. return (string)o;
  171. return String.Empty;
  172. }
  173. set
  174. {
  175. ViewState["SoftKeyLabel"] = value;
  176. }
  177. }
  178. protected virtual void OnClick(EventArgs e)
  179. {
  180. EventHandler eh = (EventHandler)(Events[ClickEvent]);
  181. if(eh != null)
  182. eh(this, e);
  183. }
  184. protected virtual void OnItemCommand(CommandEventArgs e)
  185. {
  186. CommandEventHandler ceh = (CommandEventHandler)(Events[ItemCommandEvent]);
  187. if(ceh != null)
  188. ceh(this, e);
  189. }
  190. protected virtual bool IsFormSubmitControl()
  191. {
  192. return true;
  193. }
  194. }
  195. }