Calendar.cs 40 KB

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