Calendar.cs 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  1. //
  2. // System.Web.UI.WebControls.Calendar.cs
  3. //
  4. // Authors:
  5. // Gaurav Vaish ([email protected])
  6. // Gonzalo Paniagua Javier ([email protected])
  7. // Andreas Nahr ([email protected])
  8. //
  9. // (c) Copyright 2002 Ximian, Inc. (http://www.ximian.com)
  10. // (C) Gaurav Vaish (2002)
  11. // (C) 2003 Andreas Nahr
  12. //
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining
  15. // a copy of this software and associated documentation files (the
  16. // "Software"), to deal in the Software without restriction, including
  17. // without limitation the rights to use, copy, modify, merge, publish,
  18. // distribute, sublicense, and/or sell copies of the Software, and to
  19. // permit persons to whom the Software is furnished to do so, subject to
  20. // the following conditions:
  21. //
  22. // The above copyright notice and this permission notice shall be
  23. // included in all copies or substantial portions of the Software.
  24. //
  25. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  29. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  30. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  31. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  32. //
  33. using System;
  34. using System.IO;
  35. using System.Collections;
  36. using System.Globalization;
  37. using System.Text;
  38. using System.Web;
  39. using System.Web.UI;
  40. using System.Drawing;
  41. using System.ComponentModel;
  42. using System.ComponentModel.Design;
  43. namespace System.Web.UI.WebControls
  44. {
  45. [DefaultEvent("SelectionChanged")]
  46. [DefaultProperty("SelectedDate")]
  47. [Designer("System.Web.UI.Design.WebControls.CalendarDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
  48. [DataBindingHandler("System.Web.UI.Design.WebControls.CalendarDataBindingHandler, " + Consts.AssemblySystem_Design)]
  49. public class Calendar : WebControl, IPostBackEventHandler
  50. {
  51. //
  52. private TableItemStyle dayHeaderStyle;
  53. private TableItemStyle dayStyle;
  54. private TableItemStyle nextPrevStyle;
  55. private TableItemStyle otherMonthDayStyle;
  56. private SelectedDatesCollection selectedDates;
  57. private ArrayList selectedDatesList;
  58. private TableItemStyle selectedDayStyle;
  59. private TableItemStyle selectorStyle;
  60. private TableItemStyle titleStyle;
  61. private TableItemStyle todayDayStyle;
  62. private TableItemStyle weekendDayStyle;
  63. private static readonly object DayRenderEvent = new object();
  64. private static readonly object SelectionChangedEvent = new object();
  65. private static readonly object VisibleMonthChangedEvent = new object();
  66. private Color defaultTextColor;
  67. private System.Globalization.Calendar globCal;
  68. private DateTimeFormatInfo infoCal = DateTimeFormatInfo.CurrentInfo;
  69. private static readonly DateTime begin_date = new DateTime (2000,01,01,0,0,0,0);
  70. private static int MASK_WEEKEND = (0x01 << 0);
  71. private static int MASK_OMONTH = (0x01 << 1);
  72. private static int MASK_TODAY = (0x01 << 2);
  73. private static int MASK_SELECTED = (0x01 << 3);
  74. private static int MASK_DAY = (0x01 << 4);
  75. private static int MASK_UNIQUE = MASK_WEEKEND | MASK_OMONTH | MASK_TODAY | MASK_SELECTED;
  76. public Calendar(): base()
  77. {
  78. }
  79. [DefaultValue (2), Bindable (true), WebCategory ("Layout")]
  80. [WebSysDescription ("The border left within the calendar days.")]
  81. public int CellPadding
  82. {
  83. get
  84. {
  85. object o = ViewState["CellPadding"];
  86. if(o!=null)
  87. return (int)o;
  88. return 2;
  89. }
  90. set
  91. {
  92. if (value < -1)
  93. throw new ArgumentOutOfRangeException ("value", "CellPadding value has to be -1 for 'not set' or > -1.");
  94. ViewState["CellPadding"] = value;
  95. }
  96. }
  97. [DefaultValue (0), Bindable (true), WebCategory ("Layout")]
  98. [WebSysDescription ("The border left between calendar days.")]
  99. public int CellSpacing
  100. {
  101. get
  102. {
  103. object o = ViewState["CellSpacing"];
  104. if(o!=null)
  105. return (int)o;
  106. return 0;
  107. }
  108. set
  109. {
  110. if (value < -1)
  111. throw new ArgumentOutOfRangeException ("value", "CellSpacing value has to be -1 for 'not set' or > -1.");
  112. ViewState["CellSpacing"] = value;
  113. }
  114. }
  115. [NotifyParentProperty (true), WebCategory ("Style")]
  116. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  117. [PersistenceMode (PersistenceMode.InnerProperty)]
  118. [WebSysDescription ("The style applied to the day header.")]
  119. public TableItemStyle DayHeaderStyle
  120. {
  121. get
  122. {
  123. if(dayHeaderStyle==null)
  124. dayHeaderStyle = new TableItemStyle();
  125. if(IsTrackingViewState)
  126. dayHeaderStyle.TrackViewState();
  127. return dayHeaderStyle;
  128. }
  129. }
  130. [DefaultValue (typeof (DayNameFormat), "Short"), Bindable (true), WebCategory ("Appearance")]
  131. [WebSysDescription ("The format for the day name display.")]
  132. public DayNameFormat DayNameFormat
  133. {
  134. get
  135. {
  136. object o = ViewState["DayNameFormat"];
  137. if(o!=null)
  138. return (DayNameFormat)o;
  139. return DayNameFormat.Short;
  140. }
  141. set
  142. {
  143. if(!System.Enum.IsDefined(typeof(DayNameFormat),value))
  144. throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
  145. ViewState["DayNameFormat"] = value;
  146. }
  147. }
  148. [DefaultValue (null)]
  149. [NotifyParentProperty (true), WebCategory ("Style")]
  150. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  151. [PersistenceMode (PersistenceMode.InnerProperty)]
  152. [WebSysDescription ("The style applied to the day entry.")]
  153. public TableItemStyle DayStyle
  154. {
  155. get
  156. {
  157. if(dayStyle==null)
  158. dayStyle = new TableItemStyle();
  159. if(IsTrackingViewState)
  160. dayStyle.TrackViewState();
  161. return dayStyle;
  162. }
  163. }
  164. [DefaultValue (typeof (FirstDayOfWeek), "Default"), Bindable (true), WebCategory ("Appearance")]
  165. [WebSysDescription ("The day that a week begins with.")]
  166. public FirstDayOfWeek FirstDayOfWeek
  167. {
  168. get
  169. {
  170. object o = ViewState["FirstDayOfWeek"];
  171. if(o!=null)
  172. return (FirstDayOfWeek)o;
  173. return FirstDayOfWeek.Default;
  174. }
  175. set
  176. {
  177. if(!System.Enum.IsDefined(typeof(FirstDayOfWeek), value))
  178. throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
  179. ViewState["FirstDayOfWeek"] = value;
  180. }
  181. }
  182. [DefaultValue (">"), Bindable (true), WebCategory ("Appearance")]
  183. [WebSysDescription ("The text for selecting the next month.")]
  184. public string NextMonthText
  185. {
  186. get
  187. {
  188. object o = ViewState["NextMonthText"];
  189. if(o!=null)
  190. return (string)o;
  191. return "&gt;";
  192. }
  193. set
  194. {
  195. ViewState["NextMonthText"] = value;
  196. }
  197. }
  198. [DefaultValue (typeof (NextPrevFormat), "CustomText"), Bindable (true), WebCategory ("Appearance")]
  199. [WebSysDescription ("The format for the month navigation.")]
  200. public NextPrevFormat NextPrevFormat
  201. {
  202. get
  203. {
  204. object o = ViewState["NextPrevFormat"];
  205. if(o!=null)
  206. return (NextPrevFormat)o;
  207. return NextPrevFormat.CustomText;
  208. }
  209. set
  210. {
  211. if(!System.Enum.IsDefined(typeof(NextPrevFormat), value))
  212. throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
  213. ViewState["NextPrevFormat"] = value;
  214. }
  215. }
  216. [NotifyParentProperty (true), WebCategory ("Style")]
  217. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  218. [PersistenceMode (PersistenceMode.InnerProperty)]
  219. [WebSysDescription ("The style applied to the month navigation.")]
  220. public TableItemStyle NextPrevStyle
  221. {
  222. get
  223. {
  224. if(nextPrevStyle == null)
  225. nextPrevStyle = new TableItemStyle();
  226. if(IsTrackingViewState)
  227. nextPrevStyle.TrackViewState();
  228. return nextPrevStyle;
  229. }
  230. }
  231. [DefaultValue (null)]
  232. [NotifyParentProperty (true), WebCategory ("Style")]
  233. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  234. [PersistenceMode (PersistenceMode.InnerProperty)]
  235. [WebSysDescription ("The style applied to day entries belonging to another month.")]
  236. public TableItemStyle OtherMonthDayStyle
  237. {
  238. get
  239. {
  240. if(otherMonthDayStyle == null)
  241. otherMonthDayStyle = new TableItemStyle();
  242. if(IsTrackingViewState)
  243. otherMonthDayStyle.TrackViewState();
  244. return otherMonthDayStyle;
  245. }
  246. }
  247. [DefaultValue ("<"), Bindable (true), WebCategory ("Appearance")]
  248. [WebSysDescription ("The text for selecting the previous month.")]
  249. public string PrevMonthText
  250. {
  251. get
  252. {
  253. object o = ViewState["PrevMonthText"];
  254. if(o!=null)
  255. return (string)o;
  256. return "&lt;";
  257. }
  258. set
  259. {
  260. ViewState["PrevMonthText"] = value;
  261. }
  262. }
  263. [DefaultValue (null), Bindable (true)]
  264. [WebSysDescription ("The currently selected date.")]
  265. public DateTime SelectedDate
  266. {
  267. get
  268. {
  269. if(SelectedDates.Count > 0)
  270. {
  271. return SelectedDates[0];
  272. }
  273. return DateTime.MinValue;
  274. }
  275. set
  276. {
  277. if(value == DateTime.MinValue)
  278. {
  279. SelectedDates.Clear();
  280. } else
  281. {
  282. SelectedDates.SelectRange(value, value);
  283. }
  284. }
  285. }
  286. [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  287. [WebSysDescription ("All currently selected dates.")]
  288. public SelectedDatesCollection SelectedDates
  289. {
  290. get
  291. {
  292. if(selectedDates==null)
  293. {
  294. if(selectedDatesList == null)
  295. selectedDatesList = new ArrayList();
  296. selectedDates = new SelectedDatesCollection(selectedDatesList);
  297. }
  298. return selectedDates;
  299. }
  300. }
  301. [DefaultValue (null)]
  302. [NotifyParentProperty (true), WebCategory ("Style")]
  303. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  304. [PersistenceMode (PersistenceMode.InnerProperty)]
  305. [WebSysDescription ("The style applied to the selected day.")]
  306. public TableItemStyle SelectedDayStyle
  307. {
  308. get
  309. {
  310. if(selectedDayStyle==null)
  311. selectedDayStyle = new TableItemStyle();
  312. if(IsTrackingViewState)
  313. selectedDayStyle.TrackViewState();
  314. return selectedDayStyle;
  315. }
  316. }
  317. [DefaultValue (typeof (CalendarSelectionMode), "Day"), Bindable (true), WebCategory ("Behavior")]
  318. [WebSysDescription ("The mode in which days or other entries are selected.")]
  319. public CalendarSelectionMode SelectionMode
  320. {
  321. get
  322. {
  323. object o = ViewState["SelectionMode"];
  324. if(o!=null)
  325. return (CalendarSelectionMode)o;
  326. return CalendarSelectionMode.Day;
  327. }
  328. set
  329. {
  330. if(!System.Enum.IsDefined(typeof(CalendarSelectionMode), value))
  331. throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
  332. ViewState["SelectionMode"] = value;
  333. }
  334. }
  335. [DefaultValue (">>"), Bindable (true), WebCategory ("Appearance")]
  336. [WebSysDescription ("The text that is used for selection of months.")]
  337. public string SelectMonthText
  338. {
  339. get
  340. {
  341. object o = ViewState["SelectMonthText"];
  342. if(o!=null)
  343. return (string)o;
  344. return "&gt;&gt;";
  345. }
  346. set
  347. {
  348. ViewState["SelectMonthText"] = value;
  349. }
  350. }
  351. [NotifyParentProperty (true), WebCategory ("Style")]
  352. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  353. [PersistenceMode (PersistenceMode.InnerProperty)]
  354. [WebSysDescription ("The style applied to the selector.")]
  355. public TableItemStyle SelectorStyle
  356. {
  357. get
  358. {
  359. if(selectorStyle==null)
  360. selectorStyle = new TableItemStyle();
  361. return selectorStyle;
  362. }
  363. }
  364. [DefaultValue (">"), Bindable (true), WebCategory ("Appearance")]
  365. [WebSysDescription ("The text that is used for selection of weeks.")]
  366. public string SelectWeekText
  367. {
  368. get
  369. {
  370. object o = ViewState["SelectWeekText"];
  371. if(o!=null)
  372. return (string)o;
  373. return "&gt;";
  374. }
  375. set
  376. {
  377. ViewState["SelectWeekText"] = value;
  378. }
  379. }
  380. [DefaultValue (true), Bindable (true), WebCategory ("Appearance")]
  381. [WebSysDescription ("Determines if the header for days is shown.")]
  382. public bool ShowDayHeader
  383. {
  384. get
  385. {
  386. object o = ViewState["ShowDayHeader"];
  387. if(o!=null)
  388. return (bool)o;
  389. return true;
  390. }
  391. set
  392. {
  393. ViewState["ShowDayHeader"] = value;
  394. }
  395. }
  396. [DefaultValue (false), Bindable (true), WebCategory ("Appearance")]
  397. [WebSysDescription ("Determines if gridlines are shown.")]
  398. public bool ShowGridLines
  399. {
  400. get
  401. {
  402. object o = ViewState["ShowGridLines"];
  403. if(o!=null)
  404. return (bool)o;
  405. return false;
  406. }
  407. set
  408. {
  409. ViewState["ShowGridLines"] = value;
  410. }
  411. }
  412. [DefaultValue (true), Bindable (true), WebCategory ("Appearance")]
  413. [WebSysDescription ("Determines if month navigation is shown.")]
  414. public bool ShowNextPrevMonth
  415. {
  416. get
  417. {
  418. object o = ViewState["ShowNextPrevMonth"];
  419. if(o!=null)
  420. return (bool)o;
  421. return true;
  422. }
  423. set
  424. {
  425. ViewState["ShowNextPrevMonth"] = value;
  426. }
  427. }
  428. [DefaultValue (true), Bindable (true), WebCategory ("Appearance")]
  429. [WebSysDescription ("Determines if the title is shown.")]
  430. public bool ShowTitle
  431. {
  432. get
  433. {
  434. object o = ViewState["ShowTitle"];
  435. if(o!=null)
  436. return (bool)o;
  437. return true;
  438. }
  439. set
  440. {
  441. ViewState["ShowTitle"] = value;
  442. }
  443. }
  444. [DefaultValue (typeof (TitleFormat), "MonthYear"), Bindable (true), WebCategory ("Appearance")]
  445. [WebSysDescription ("The format in which the title is rendered.")]
  446. public TitleFormat TitleFormat
  447. {
  448. get
  449. {
  450. object o = ViewState["TitleFormat"];
  451. if(o!=null)
  452. return (TitleFormat)o;
  453. return TitleFormat.MonthYear;
  454. }
  455. set
  456. {
  457. if(!System.Enum.IsDefined(typeof(TitleFormat), value))
  458. throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
  459. ViewState["TitleFormat"] = value;
  460. }
  461. }
  462. [NotifyParentProperty (true), WebCategory ("Style")]
  463. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  464. [PersistenceMode (PersistenceMode.InnerProperty)]
  465. [WebSysDescription ("The style applied to the title.")]
  466. public TableItemStyle TitleStyle
  467. {
  468. get
  469. {
  470. if(titleStyle==null)
  471. titleStyle = new TableItemStyle();
  472. if(IsTrackingViewState)
  473. titleStyle.TrackViewState();
  474. return titleStyle;
  475. }
  476. }
  477. [DefaultValue (null)]
  478. [NotifyParentProperty (true), WebCategory ("Style")]
  479. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  480. [PersistenceMode (PersistenceMode.InnerProperty)]
  481. [WebSysDescription ("The style applied to the today's date display.")]
  482. public TableItemStyle TodayDayStyle
  483. {
  484. get
  485. {
  486. if(todayDayStyle==null)
  487. todayDayStyle = new TableItemStyle();
  488. if(IsTrackingViewState)
  489. todayDayStyle.TrackViewState();
  490. return todayDayStyle;
  491. }
  492. }
  493. [Bindable (true), Browsable (false)]
  494. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  495. [WebSysDescription ("The current date.")]
  496. public DateTime TodaysDate
  497. {
  498. get
  499. {
  500. object o = ViewState["TodaysDate"];
  501. if(o!=null)
  502. return (DateTime)o;
  503. return DateTime.Today;
  504. }
  505. set
  506. {
  507. ViewState["TodaysDate"] = value.Date;
  508. }
  509. }
  510. [DefaultValue (null), Bindable (true)]
  511. [WebSysDescription ("The month that is displayed.")]
  512. public DateTime VisibleDate
  513. {
  514. get
  515. {
  516. object o = ViewState["VisibleDate"];
  517. if(o!=null)
  518. return (DateTime)o;
  519. return DateTime.MinValue;
  520. }
  521. set
  522. {
  523. ViewState["VisibleDate"] = value.Date;
  524. }
  525. }
  526. [NotifyParentProperty (true), WebCategory ("Style")]
  527. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  528. [PersistenceMode (PersistenceMode.InnerProperty)]
  529. [WebSysDescription ("The style applied to weekend days.")]
  530. public TableItemStyle WeekendDayStyle
  531. {
  532. get
  533. {
  534. if(weekendDayStyle == null)
  535. weekendDayStyle = new TableItemStyle();
  536. if(IsTrackingViewState)
  537. {
  538. weekendDayStyle.TrackViewState();
  539. }
  540. return weekendDayStyle;
  541. }
  542. }
  543. [WebCategory ("Action")]
  544. [WebSysDescription ("Raised when a day entry is rendered.")]
  545. public event DayRenderEventHandler DayRender
  546. {
  547. add
  548. {
  549. Events.AddHandler(DayRenderEvent, value);
  550. }
  551. remove
  552. {
  553. Events.RemoveHandler(DayRenderEvent, value);
  554. }
  555. }
  556. [WebCategory ("Action")]
  557. [WebSysDescription ("Raised when another entry is selected.")]
  558. public event EventHandler SelectionChanged
  559. {
  560. add
  561. {
  562. Events.AddHandler(SelectionChangedEvent, value);
  563. }
  564. remove
  565. {
  566. Events.RemoveHandler(SelectionChangedEvent, value);
  567. }
  568. }
  569. [WebCategory ("Action")]
  570. [WebSysDescription ("Raised when a the currently visible month has changed.")]
  571. public event MonthChangedEventHandler VisibleMonthChanged
  572. {
  573. add
  574. {
  575. Events.AddHandler(VisibleMonthChangedEvent, value);
  576. }
  577. remove
  578. {
  579. Events.RemoveHandler(VisibleMonthChangedEvent, value);
  580. }
  581. }
  582. protected virtual void OnDayRender(TableCell cell, CalendarDay day)
  583. {
  584. if(Events!=null)
  585. {
  586. DayRenderEventHandler dreh = (DayRenderEventHandler)(Events[DayRenderEvent]);
  587. if(dreh!=null)
  588. dreh(this, new DayRenderEventArgs(cell, day));
  589. }
  590. }
  591. protected virtual void OnSelectionChanged()
  592. {
  593. if(Events!=null)
  594. {
  595. EventHandler eh = (EventHandler)(Events[SelectionChangedEvent]);
  596. if(eh!=null)
  597. eh(this, new EventArgs());
  598. }
  599. }
  600. protected virtual void OnVisibleMonthChanged(DateTime newDate, DateTime prevDate)
  601. {
  602. if(Events!=null)
  603. {
  604. MonthChangedEventHandler mceh = (MonthChangedEventHandler)(Events[VisibleMonthChangedEvent]);
  605. if(mceh!=null)
  606. mceh(this, new MonthChangedEventArgs(newDate, prevDate));
  607. }
  608. }
  609. /// <remarks>
  610. /// See test6.aspx in Tests directory for verification
  611. /// </remarks>
  612. void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
  613. {
  614. // initialize the calendar...TODO: find out why this isn't done in the constructor
  615. // if the culture is changed between rendering and postback this will be broken
  616. globCal = DateTimeFormatInfo.CurrentInfo.Calendar;
  617. // TODO: Find out what kind of exceptions to throw when we get bad data
  618. if (eventArgument.StartsWith ("V")) {
  619. TimeSpan mod = new TimeSpan (Int32.Parse (eventArgument.Substring (1)), 0, 0, 0);
  620. DateTime new_date = begin_date + mod;
  621. VisibleDate = new_date;
  622. OnVisibleMonthChanged (VisibleDate, new_date);
  623. } else if (eventArgument.StartsWith ("R")) {
  624. TimeSpan mod = new TimeSpan (Int32.Parse (eventArgument.Substring (1,
  625. eventArgument.Length - 3)), 0, 0, 0);
  626. DateTime range_begin = begin_date + mod;
  627. int sel_days = Int32.Parse (eventArgument.Substring (eventArgument.Length - 2));
  628. SelectRangeInternal (range_begin, range_begin.AddDays (sel_days - 1), GetEffectiveVisibleDate ());
  629. } else {
  630. TimeSpan mod = new TimeSpan (Int32.Parse (eventArgument), 0, 0, 0);
  631. DateTime day = begin_date + mod;
  632. SelectRangeInternal (day, day, GetEffectiveVisibleDate ());
  633. }
  634. }
  635. protected override void OnPreRender (EventArgs e)
  636. {
  637. base.OnPreRender (e);
  638. }
  639. protected override void Render(HtmlTextWriter writer)
  640. {
  641. globCal = DateTimeFormatInfo.CurrentInfo.Calendar;
  642. DateTime visDate = GetEffectiveVisibleDate();
  643. DateTime firstDate = GetFirstCalendarDay(visDate);
  644. bool isEnabled;
  645. bool isHtmlTextWriter;
  646. //FIXME: when Control.Site works, reactivate this
  647. //if (Page == null || Site == null) {
  648. // isEnabled = false;
  649. // isHtmlTextWriter = false;
  650. //} else {
  651. isEnabled = Enabled;
  652. isHtmlTextWriter = (writer.GetType() != typeof(HtmlTextWriter));
  653. //}
  654. defaultTextColor = ForeColor;
  655. if(defaultTextColor == Color.Empty)
  656. defaultTextColor = Color.Black;
  657. Table calTable = new Table ();
  658. calTable.ID = ID;
  659. calTable.CopyBaseAttributes(this);
  660. if(ControlStyleCreated)
  661. calTable.ApplyStyle(ControlStyle);
  662. calTable.Width = Width;
  663. calTable.Height = Height;
  664. calTable.CellSpacing = CellSpacing;
  665. calTable.CellPadding = CellPadding;
  666. if (ControlStyleCreated &&
  667. ControlStyle.IsSet (WebControls.Style.BORDERWIDTH) &&
  668. BorderWidth != Unit.Empty)
  669. calTable.BorderWidth = BorderWidth;
  670. else
  671. calTable.BorderWidth = Unit.Pixel(1);
  672. if (ShowGridLines)
  673. calTable.GridLines = GridLines.Both;
  674. else
  675. calTable.GridLines = GridLines.None;
  676. calTable.RenderBeginTag (writer);
  677. if (ShowTitle)
  678. RenderTitle (writer, visDate, SelectionMode, isEnabled);
  679. if (ShowDayHeader)
  680. RenderHeader (writer, firstDate, SelectionMode, isEnabled, isHtmlTextWriter);
  681. RenderAllDays (writer, firstDate, visDate, SelectionMode, isEnabled, isHtmlTextWriter);
  682. calTable.RenderEndTag(writer);
  683. }
  684. protected override ControlCollection CreateControlCollection()
  685. {
  686. return new EmptyControlCollection(this);
  687. }
  688. protected override void LoadViewState(object savedState)
  689. {
  690. if (savedState!=null) {
  691. object[] states = (object[]) savedState;
  692. if(states[0] != null)
  693. base.LoadViewState(states[0]);
  694. if(states[1] != null)
  695. DayHeaderStyle.LoadViewState(states[1]);
  696. if(states[2] != null)
  697. DayStyle.LoadViewState(states[2]);
  698. if(states[3] != null)
  699. NextPrevStyle.LoadViewState(states[3]);
  700. if(states[4] != null)
  701. OtherMonthDayStyle.LoadViewState(states[4]);
  702. if(states[5] != null)
  703. SelectedDayStyle.LoadViewState(states[5]);
  704. if(states[6] != null)
  705. SelectorStyle.LoadViewState(states[6]);
  706. if(states[7] != null)
  707. TitleStyle.LoadViewState(states[7]);
  708. if(states[8] != null)
  709. TodayDayStyle.LoadViewState(states[8]);
  710. if(states[9] != null)
  711. WeekendDayStyle.LoadViewState(states[9]);
  712. ArrayList dateList = ViewState ["_CalendarSelectedDates"] as ArrayList;
  713. if (dateList != null)
  714. selectedDates = new SelectedDatesCollection (dateList);
  715. }
  716. }
  717. protected override object SaveViewState()
  718. {
  719. if (SelectedDates.Count > 0)
  720. ViewState["_CalendarSelectedDates"] = selectedDates.GetDateList ();
  721. object[] states = new object [10];
  722. states[0] = base.SaveViewState();
  723. states[1] = (dayHeaderStyle == null ? null : dayHeaderStyle.SaveViewState());
  724. states[2] = (dayStyle == null ? null : dayStyle.SaveViewState());
  725. states[3] = (nextPrevStyle == null ? null : nextPrevStyle.SaveViewState());
  726. states[4] = (otherMonthDayStyle == null ? null : otherMonthDayStyle.SaveViewState());
  727. states[5] = (selectedDayStyle == null ? null : selectedDayStyle.SaveViewState());
  728. states[6] = (selectorStyle == null ? null : selectorStyle.SaveViewState());
  729. states[7] = (titleStyle == null ? null : titleStyle.SaveViewState());
  730. states[8] = (todayDayStyle == null ? null : todayDayStyle.SaveViewState());
  731. states[9] = (weekendDayStyle == null ? null : weekendDayStyle.SaveViewState());
  732. for(int i=0; i < states.Length; i++)
  733. {
  734. if(states[i]!=null)
  735. return states;
  736. }
  737. return null;
  738. }
  739. protected override void TrackViewState()
  740. {
  741. base.TrackViewState();
  742. if(titleStyle!=null)
  743. {
  744. titleStyle.TrackViewState();
  745. }
  746. if(nextPrevStyle!=null)
  747. {
  748. nextPrevStyle.TrackViewState();
  749. }
  750. if(dayStyle!=null)
  751. {
  752. dayStyle.TrackViewState();
  753. }
  754. if(dayHeaderStyle!=null)
  755. {
  756. dayHeaderStyle.TrackViewState();
  757. }
  758. if(todayDayStyle!=null)
  759. {
  760. todayDayStyle.TrackViewState();
  761. }
  762. if(weekendDayStyle!=null)
  763. {
  764. weekendDayStyle.TrackViewState();
  765. }
  766. if(otherMonthDayStyle!=null)
  767. {
  768. otherMonthDayStyle.TrackViewState();
  769. }
  770. if(selectedDayStyle!=null)
  771. {
  772. selectedDayStyle.TrackViewState();
  773. }
  774. if(selectorStyle!=null)
  775. {
  776. selectorStyle.TrackViewState();
  777. }
  778. }
  779. private void RenderAllDays (HtmlTextWriter writer,
  780. DateTime firstDay,
  781. DateTime activeDate,
  782. CalendarSelectionMode mode,
  783. bool isActive,
  784. bool isDownLevel)
  785. {
  786. TableItemStyle weeksStyle = null;
  787. TableCell weeksCell = new TableCell ();
  788. TableItemStyle weekendStyle = WeekendDayStyle;
  789. TableItemStyle otherMonthStyle = OtherMonthDayStyle;
  790. Unit size;
  791. bool isWeekMode = (mode == CalendarSelectionMode.DayWeek ||
  792. mode == CalendarSelectionMode.DayWeekMonth);
  793. if (isWeekMode) {
  794. weeksStyle = new TableItemStyle ();
  795. weeksStyle.Width = Unit.Percentage (12);
  796. weeksStyle.HorizontalAlign = HorizontalAlign.Center;
  797. weeksStyle.CopyFrom (SelectorStyle);
  798. size = Unit.Percentage (12);
  799. } else {
  800. size = Unit.Percentage (14);
  801. }
  802. TableItemStyle [] styles = new TableItemStyle [32];
  803. int definedStyles = MASK_SELECTED;
  804. if (weekendStyle != null && !weekendStyle.IsEmpty)
  805. definedStyles |= MASK_WEEKEND;
  806. if (otherMonthStyle != null && !otherMonthStyle.IsEmpty)
  807. definedStyles |= MASK_OMONTH;
  808. if (todayDayStyle != null && !todayDayStyle.IsEmpty)
  809. definedStyles |= MASK_TODAY;
  810. if (dayStyle != null && !dayStyle.IsEmpty)
  811. definedStyles |= MASK_DAY;
  812. bool isCalendar = GetType () == typeof (Calendar);
  813. int month = globCal.GetMonth (activeDate);
  814. DateTime currentDay = firstDay;
  815. int begin = (int) (firstDay - begin_date).TotalDays;
  816. for (int crr = 0; crr < 6; crr++) {
  817. writer.Write ("<tr>");
  818. if (isWeekMode) {
  819. int week_offset = begin + crr * 7;
  820. string cellText = GetCalendarLinkText (
  821. "R" + week_offset + "07",
  822. SelectWeekText,
  823. weeksCell.ForeColor,
  824. isActive);
  825. weeksCell.Text = cellText;
  826. weeksCell.ApplyStyle (weeksStyle);
  827. RenderCalendarCell (writer, weeksCell, cellText);
  828. }
  829. for (int weekDay = 0; weekDay < 7; weekDay++) {
  830. string dayString = currentDay.Day.ToString ();
  831. DayOfWeek dow = currentDay.DayOfWeek;
  832. CalendarDay calDay =
  833. new CalendarDay (
  834. currentDay,
  835. dow == DayOfWeek.Sunday ||
  836. dow == DayOfWeek.Saturday,
  837. currentDay == TodaysDate,
  838. SelectedDates.Contains (currentDay),
  839. globCal.GetMonth (currentDay) != month,
  840. dayString
  841. );
  842. int dayStyles = GetMask (calDay) & definedStyles;
  843. TableItemStyle currentDayStyle = styles [dayStyles];
  844. if (currentDayStyle == null) {
  845. currentDayStyle = new TableItemStyle ();
  846. if ((dayStyles & MASK_DAY) != 0)
  847. currentDayStyle.CopyFrom (DayStyle);
  848. if ((dayStyles & MASK_WEEKEND) != 0)
  849. currentDayStyle.CopyFrom (WeekendDayStyle);
  850. if ((dayStyles & MASK_TODAY) != 0)
  851. currentDayStyle.CopyFrom (TodayDayStyle);
  852. if ((dayStyles & MASK_OMONTH) != 0)
  853. currentDayStyle.CopyFrom (OtherMonthDayStyle);
  854. if ((dayStyles & MASK_SELECTED) != 0) {
  855. currentDayStyle.ForeColor = Color.White;
  856. currentDayStyle.BackColor = Color.Silver;
  857. currentDayStyle.CopyFrom (SelectedDayStyle);
  858. }
  859. currentDayStyle.Width = size;
  860. currentDayStyle.HorizontalAlign = HorizontalAlign.Center;
  861. }
  862. TableCell dayCell = new TableCell ();
  863. dayCell.ApplyStyle (currentDayStyle);
  864. dayCell.Controls.Add (new LiteralControl (dayString));
  865. calDay.IsSelectable = isActive;
  866. if (calDay.IsSelectable)
  867. dayCell.Text = GetCalendarLinkText (
  868. (begin + (crr * 7 + weekDay)).ToString (),
  869. dayString,
  870. dayCell.ForeColor,
  871. isActive);
  872. OnDayRender (dayCell, calDay);
  873. dayCell.RenderControl (writer);
  874. currentDay = globCal.AddDays (currentDay, 1);
  875. }
  876. writer.Write("</tr>");
  877. }
  878. }
  879. private int GetMask (CalendarDay day)
  880. {
  881. int retVal = MASK_DAY;
  882. if(day.IsSelected)
  883. retVal |= MASK_SELECTED;
  884. if(day.IsToday)
  885. retVal |= MASK_TODAY;
  886. if(day.IsOtherMonth)
  887. retVal |= MASK_OMONTH;
  888. if(day.IsWeekend)
  889. retVal |= MASK_WEEKEND;
  890. return retVal;
  891. }
  892. /// <remarks>
  893. /// Refers to the second line of the calendar, that contains a link
  894. /// to select whole month, and weekdays as defined by DayNameFormat
  895. /// </remarks>
  896. private void RenderHeader (HtmlTextWriter writer,
  897. DateTime firstDay,
  898. CalendarSelectionMode mode,
  899. bool isActive,
  900. bool isDownLevel)
  901. {
  902. writer.Write("<tr>");
  903. bool isWeekMode = (mode == CalendarSelectionMode.DayWeek ||
  904. mode == CalendarSelectionMode.DayWeekMonth);
  905. TableCell headerCell = new TableCell ();
  906. headerCell.HorizontalAlign = HorizontalAlign.Center;
  907. string selMthText = String.Empty;
  908. if (isWeekMode) {
  909. if (mode == CalendarSelectionMode.DayWeekMonth) {
  910. DateTime visDate = GetEffectiveVisibleDate ();
  911. DateTime sel_month = new DateTime (visDate.Year, visDate.Month, 1);
  912. int month_offset = (int) (sel_month - begin_date).TotalDays;
  913. headerCell.ApplyStyle (SelectorStyle);
  914. selMthText = GetCalendarLinkText ("R" + month_offset +
  915. globCal.GetDaysInMonth (sel_month.Year,
  916. sel_month.Month).ToString ("d2"), // maybe there are calendars with less then 10 days in a month
  917. SelectMonthText,
  918. SelectorStyle.ForeColor,
  919. isActive);
  920. } else {
  921. headerCell.ApplyStyle (DayHeaderStyle);
  922. selMthText = String.Empty;
  923. }
  924. RenderCalendarCell (writer, headerCell, selMthText);
  925. }
  926. TableCell dayHeaderCell = new TableCell ();
  927. dayHeaderCell.HorizontalAlign = HorizontalAlign.Center;
  928. dayHeaderCell.ApplyStyle (dayHeaderStyle);
  929. int dayOfWeek = (int) globCal.GetDayOfWeek (firstDay);
  930. DateTimeFormatInfo currDTInfo = DateTimeFormatInfo.CurrentInfo;
  931. for(int currDay = dayOfWeek; currDay < dayOfWeek + 7; currDay++) {
  932. DayOfWeek effDay = (DayOfWeek) Enum.ToObject (typeof (DayOfWeek), currDay % 7);
  933. string currDayContent;
  934. switch(DayNameFormat) {
  935. case DayNameFormat.Full:
  936. currDayContent = currDTInfo.GetDayName (effDay);
  937. break;
  938. case DayNameFormat.FirstLetter:
  939. currDayContent = currDTInfo.GetDayName (effDay).Substring (0,1);
  940. break;
  941. case DayNameFormat.FirstTwoLetters:
  942. currDayContent = currDTInfo.GetDayName (effDay).Substring (0,2);
  943. break;
  944. case DayNameFormat.Short:
  945. goto default;
  946. default:
  947. currDayContent = currDTInfo.GetAbbreviatedDayName (effDay);
  948. break;
  949. }
  950. RenderCalendarCell(writer, dayHeaderCell, currDayContent);
  951. }
  952. writer.Write ("</tr>");
  953. }
  954. private void RenderTitle (HtmlTextWriter writer,
  955. DateTime visibleDate,
  956. CalendarSelectionMode mode,
  957. bool isActive)
  958. {
  959. writer.Write("<tr>");
  960. Table innerTable = new Table ();
  961. TableCell titleCell = new TableCell();
  962. bool isWeekMode = (mode == CalendarSelectionMode.DayWeek ||
  963. mode == CalendarSelectionMode.DayWeekMonth);
  964. titleCell.ColumnSpan = (isWeekMode ? 8 : 7);
  965. titleCell.BackColor = Color.Silver;
  966. innerTable.GridLines = GridLines.None;
  967. innerTable.Width = Unit.Percentage (100);
  968. innerTable.CellSpacing = 0;
  969. ApplyTitleStyle (innerTable, titleCell, TitleStyle);
  970. titleCell.RenderBeginTag (writer);
  971. innerTable.RenderBeginTag (writer);
  972. writer.Write ("<tr>");
  973. string prevContent = String.Empty;
  974. if (ShowNextPrevMonth) {
  975. TableCell prevCell = new TableCell ();
  976. prevCell.Width = Unit.Percentage (15);
  977. prevCell.HorizontalAlign = HorizontalAlign.Left;
  978. if (NextPrevFormat == NextPrevFormat.CustomText) {
  979. prevContent = PrevMonthText;
  980. } else {
  981. int pMthInt = globCal.GetMonth(globCal.AddMonths (visibleDate, -1));
  982. if (NextPrevFormat == NextPrevFormat.FullMonth)
  983. prevContent = infoCal.GetMonthName (pMthInt);
  984. else
  985. prevContent = infoCal.GetAbbreviatedMonthName (pMthInt);
  986. }
  987. DateTime prev_month = visibleDate.AddMonths (-1);
  988. int prev_offset = (int) (new DateTime (prev_month.Year,
  989. prev_month.Month, 1) - begin_date).TotalDays;
  990. prevCell.ApplyStyle (NextPrevStyle);
  991. RenderCalendarCell (writer,
  992. prevCell,
  993. GetCalendarLinkText ("V" + prev_offset,
  994. prevContent,
  995. NextPrevStyle.ForeColor,
  996. isActive)
  997. );
  998. }
  999. TableCell currCell = new TableCell ();
  1000. currCell.Width = Unit.Percentage (70);
  1001. if (TitleStyle.HorizontalAlign == HorizontalAlign.NotSet)
  1002. currCell.HorizontalAlign = HorizontalAlign.Center;
  1003. else
  1004. currCell.HorizontalAlign = TitleStyle.HorizontalAlign;
  1005. currCell.Wrap = TitleStyle.Wrap;
  1006. string currMonthContent = String.Empty;
  1007. if (TitleFormat == TitleFormat.Month) {
  1008. currMonthContent = visibleDate.ToString ("MMMM");
  1009. } else {
  1010. string cmcFmt = infoCal.YearMonthPattern;
  1011. if (cmcFmt.IndexOf (',') >= 0)
  1012. cmcFmt = "MMMM yyyy";
  1013. currMonthContent = visibleDate.ToString (cmcFmt);
  1014. }
  1015. RenderCalendarCell (writer, currCell, currMonthContent);
  1016. string nextContent = String.Empty;
  1017. if (ShowNextPrevMonth) {
  1018. TableCell nextCell = new TableCell ();
  1019. nextCell.Width = Unit.Percentage(15);
  1020. nextCell.HorizontalAlign = HorizontalAlign.Right;
  1021. if (NextPrevFormat == NextPrevFormat.CustomText) {
  1022. nextContent = NextMonthText;
  1023. } else {
  1024. int nMthInt = globCal.GetMonth (globCal.AddMonths (visibleDate, 1));
  1025. if(NextPrevFormat == NextPrevFormat.FullMonth)
  1026. nextContent = infoCal.GetMonthName(nMthInt);
  1027. else
  1028. nextContent = infoCal.GetAbbreviatedMonthName(nMthInt);
  1029. }
  1030. DateTime next_month = visibleDate.AddMonths (1);
  1031. int next_offset = (int) (new DateTime (next_month.Year,
  1032. next_month.Month, 1) - begin_date).TotalDays;
  1033. nextCell.ApplyStyle(NextPrevStyle);
  1034. RenderCalendarCell (writer,
  1035. nextCell,
  1036. GetCalendarLinkText ("V" + next_offset,
  1037. nextContent,
  1038. NextPrevStyle.ForeColor,
  1039. isActive)
  1040. );
  1041. }
  1042. writer.Write("</tr>");
  1043. innerTable.RenderEndTag(writer);
  1044. titleCell.RenderEndTag(writer);
  1045. writer.Write("</tr>");
  1046. }
  1047. private void ApplyTitleStyle(Table table, TableCell cell, TableItemStyle style)
  1048. {
  1049. if(style.BackColor != Color.Empty)
  1050. {
  1051. cell.BackColor = style.BackColor;
  1052. }
  1053. if(style.BorderStyle != BorderStyle.NotSet)
  1054. {
  1055. cell.BorderStyle = style.BorderStyle;
  1056. }
  1057. if(style.BorderColor != Color.Empty)
  1058. {
  1059. cell.BorderColor = style.BorderColor;
  1060. }
  1061. if(style.BorderWidth != Unit.Empty)
  1062. {
  1063. cell.BorderWidth = style.BorderWidth;
  1064. }
  1065. if(style.Height != Unit.Empty)
  1066. {
  1067. cell.Height = style.Height;
  1068. }
  1069. if(style.VerticalAlign != VerticalAlign.NotSet)
  1070. {
  1071. cell.VerticalAlign = style.VerticalAlign;
  1072. }
  1073. if(style.ForeColor != Color.Empty)
  1074. {
  1075. table.ForeColor = style.ForeColor;
  1076. } else if(ForeColor != Color.Empty)
  1077. {
  1078. table.ForeColor = ForeColor;
  1079. }
  1080. if (style.CssClass != "") {
  1081. cell.CssClass = style.CssClass;
  1082. }
  1083. table.Font.CopyFrom(style.Font);
  1084. table.Font.MergeWith(Font);
  1085. }
  1086. private void RenderCalendarCell (HtmlTextWriter writer, TableCell cell, string text)
  1087. {
  1088. cell.RenderBeginTag(writer);
  1089. writer.Write(text);
  1090. cell.RenderEndTag(writer);
  1091. }
  1092. private DateTime GetFirstCalendarDay(DateTime visibleDate)
  1093. {
  1094. int fow = (int) FirstDayOfWeek;
  1095. if (fow == 7)
  1096. fow = (int) infoCal.FirstDayOfWeek;
  1097. int days = (int) globCal.GetDayOfWeek (visibleDate) - fow;
  1098. if (days <= 0)
  1099. days += 7;
  1100. return globCal.AddDays (visibleDate, -days);
  1101. }
  1102. private DateTime GetEffectiveVisibleDate()
  1103. {
  1104. DateTime dt = VisibleDate;
  1105. if (VisibleDate == DateTime.MinValue)
  1106. dt = TodaysDate;
  1107. return globCal.AddDays (dt, 1 - globCal.GetDayOfMonth (dt));
  1108. }
  1109. /// <summary>
  1110. /// Creates text to be displayed, with all attributes if to be
  1111. /// shown as a hyperlink
  1112. /// </summary>
  1113. private string GetCalendarLinkText (string eventArg,
  1114. string text,
  1115. Color foreground,
  1116. bool isLink)
  1117. {
  1118. if (isLink) {
  1119. StringBuilder dispVal = new StringBuilder ();
  1120. dispVal.Append ("<a href=\"");
  1121. dispVal.Append (Page.GetPostBackClientHyperlink (this, eventArg));
  1122. dispVal.Append ("\" style=\"color: ");
  1123. if (foreground.IsEmpty) {
  1124. dispVal.Append (ColorTranslator.ToHtml (defaultTextColor));
  1125. } else {
  1126. dispVal.Append (ColorTranslator.ToHtml (foreground));
  1127. }
  1128. dispVal.Append ("\">");
  1129. dispVal.Append (text);
  1130. dispVal.Append ("</a>");
  1131. return dispVal.ToString ();
  1132. }
  1133. return text;
  1134. }
  1135. private string GetHtmlForCell (TableCell cell, bool showLinks)
  1136. {
  1137. StringWriter sw = new StringWriter ();
  1138. HtmlTextWriter htw = new HtmlTextWriter (sw);
  1139. cell.RenderBeginTag (htw);
  1140. if(showLinks) {
  1141. htw.Write (GetCalendarLinkText ("{0}", "{1}", cell.ForeColor, showLinks));
  1142. } else {
  1143. htw.Write ("{0}");
  1144. }
  1145. cell.RenderEndTag (htw);
  1146. return sw.ToString();
  1147. }
  1148. internal void SelectRangeInternal (DateTime fromDate, DateTime toDate, DateTime visibleDate)
  1149. {
  1150. TimeSpan span = toDate - fromDate;
  1151. if (SelectedDates.Count != span.Days + 1 ||
  1152. SelectedDates [0] != fromDate ||
  1153. SelectedDates [SelectedDates.Count - 1] != toDate) {
  1154. SelectedDates.SelectRange (fromDate, toDate);
  1155. OnSelectionChanged ();
  1156. }
  1157. }
  1158. protected bool HasWeekSelectors (CalendarSelectionMode selectionMode)
  1159. {
  1160. return selectionMode == CalendarSelectionMode.DayWeek ||
  1161. selectionMode == CalendarSelectionMode.DayWeekMonth;
  1162. }
  1163. }
  1164. }