Calendar.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 : Calendar
  25. * Author : Gaurav Vaish
  26. *
  27. * Copyright : 2003 with Gaurav Vaish, and with
  28. * Ximian Inc
  29. */
  30. using System.Web.UI;
  31. using System.Web.Mobile;
  32. using System.Web.UI.WebControls;
  33. namespace System.Web.UI.MobileControls
  34. {
  35. public class Calendar : MobileControl, IPostBackEventHandler
  36. {
  37. private System.Web.UI.WebControls.Calendar webCal;
  38. private static readonly object SelectionChangedEvent = new object();
  39. public Calendar()
  40. {
  41. webCal = CreateWebCalendar();
  42. webCal.Visible = false;
  43. webCal.Controls.Add(webCal);
  44. webCal.SelectionChanged += new EventHandler(WebSelectionChanged);
  45. }
  46. protected virtual System.Web.UI.WebControls.Calendar CreateWebCalendar()
  47. {
  48. return new System.Web.UI.WebControls.Calendar();
  49. }
  50. void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
  51. {
  52. if(MobilePage.ActiveForm != Form)
  53. MobilePage.ActiveForm = Form;
  54. Adapter.HandlePostBackEvent(eventArgument);
  55. }
  56. public event EventHandler SelectionChanged
  57. {
  58. add
  59. {
  60. Events.AddHandler(SelectionChangedEvent, value);
  61. }
  62. remove
  63. {
  64. Events.RemoveHandler(SelectionChangedEvent, value);
  65. }
  66. }
  67. public string CalendarEntryText
  68. {
  69. get
  70. {
  71. object o = ViewState["CalendarEntryText"];
  72. if(o != null)
  73. return (string)o;
  74. return String.Empty;
  75. }
  76. set
  77. {
  78. ViewState["CalendarEntryText"] = value;
  79. }
  80. }
  81. public FirstDayOfWeek FirstDayOfWeek
  82. {
  83. get
  84. {
  85. return webCal.FirstDayOfWeek;
  86. }
  87. set
  88. {
  89. webCal.FirstDayOfWeek = value;
  90. }
  91. }
  92. public DateTime SelectedDate
  93. {
  94. get
  95. {
  96. return webCal.SelectedDate;
  97. }
  98. set
  99. {
  100. webCal.SelectedDate = value;
  101. }
  102. }
  103. public SelectedDatesCollection SelectedDates
  104. {
  105. get
  106. {
  107. return webCal.SelectedDates;
  108. }
  109. }
  110. public CalendarSelectionMode SelectionMode
  111. {
  112. get
  113. {
  114. return webCal.SelectionMode;
  115. }
  116. set
  117. {
  118. webCal.SelectionMode = value;
  119. }
  120. }
  121. public bool ShowDayHeader
  122. {
  123. get
  124. {
  125. return webCal.ShowDayHeader;
  126. }
  127. set
  128. {
  129. webCal.ShowDayHeader = value;
  130. }
  131. }
  132. public DateTime VisibleDate
  133. {
  134. get
  135. {
  136. return webCal.VisibleDate;
  137. }
  138. set
  139. {
  140. webCal.VisibleDate = value;
  141. }
  142. }
  143. public System.Web.UI.WebControls.Calendar WebCalendar
  144. {
  145. get
  146. {
  147. return webCal;
  148. }
  149. }
  150. private void WebSelectionChanged(object sender, EventArgs e)
  151. {
  152. OnSelectionChanged();
  153. }
  154. protected virtual void OnSelectionChanged()
  155. {
  156. EventHandler eh = (EventHandler)(Events[SelectionChangedEvent]);
  157. if(eh != null)
  158. {
  159. eh(this, new EventArgs());
  160. }
  161. }
  162. public void RaiseSelectionChangedEvent()
  163. {
  164. WebSelectionChanged(this, new EventArgs());
  165. }
  166. }
  167. }