calctrl.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: calctrl.h
  3. // Purpose: interface of wxCalendarCtrl
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. enum
  8. {
  9. // show Sunday as the first day of the week (default)
  10. wxCAL_SUNDAY_FIRST = 0x0000,
  11. // show Monday as the first day of the week
  12. wxCAL_MONDAY_FIRST = 0x0001,
  13. // highlight holidays
  14. wxCAL_SHOW_HOLIDAYS = 0x0002,
  15. // disable the year change control, show only the month change one
  16. // deprecated
  17. wxCAL_NO_YEAR_CHANGE = 0x0004,
  18. // don't allow changing neither month nor year (implies
  19. // wxCAL_NO_YEAR_CHANGE)
  20. wxCAL_NO_MONTH_CHANGE = 0x000c,
  21. // use MS-style month-selection instead of combo-spin combination
  22. wxCAL_SEQUENTIAL_MONTH_SELECTION = 0x0010,
  23. // show the neighbouring weeks in the previous and next month
  24. wxCAL_SHOW_SURROUNDING_WEEKS = 0x0020,
  25. // show week numbers on the left side of the calendar.
  26. wxCAL_SHOW_WEEK_NUMBERS = 0x0040
  27. };
  28. /**
  29. @class wxCalendarEvent
  30. The wxCalendarEvent class is used together with wxCalendarCtrl.
  31. @library{wxadv}
  32. @category{events}
  33. @see wxCalendarCtrl
  34. */
  35. class wxCalendarEvent : public wxDateEvent
  36. {
  37. public:
  38. wxCalendarEvent();
  39. wxCalendarEvent(wxWindow *win, const wxDateTime& dt, wxEventType type);
  40. /**
  41. Returns the week day on which the user clicked in
  42. @c EVT_CALENDAR_WEEKDAY_CLICKED handler. It doesn't make sense to call
  43. this function in other handlers.
  44. */
  45. wxDateTime::WeekDay GetWeekDay() const;
  46. /**
  47. Sets the week day carried by the event, normally only used by the
  48. library internally.
  49. */
  50. void SetWeekDay(const wxDateTime::WeekDay day);
  51. };
  52. wxEventType wxEVT_CALENDAR_SEL_CHANGED;
  53. wxEventType wxEVT_CALENDAR_PAGE_CHANGED;
  54. wxEventType wxEVT_CALENDAR_DOUBLECLICKED;
  55. wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED;
  56. wxEventType wxEVT_CALENDAR_WEEK_CLICKED;
  57. /**
  58. Possible kinds of borders which may be used to decorate a date using
  59. wxCalendarDateAttr.
  60. */
  61. enum wxCalendarDateBorder
  62. {
  63. wxCAL_BORDER_NONE, ///< No Border (Default)
  64. wxCAL_BORDER_SQUARE, ///< Rectangular Border
  65. wxCAL_BORDER_ROUND ///< Round Border
  66. };
  67. /**
  68. @class wxCalendarDateAttr
  69. wxCalendarDateAttr is a custom attributes for a calendar date. The objects
  70. of this class are used with wxCalendarCtrl.
  71. @library{wxadv}
  72. @category{data}
  73. @see wxCalendarCtrl
  74. */
  75. class wxCalendarDateAttr
  76. {
  77. public:
  78. /**
  79. Constructor for specifying all wxCalendarDateAttr properties.
  80. */
  81. wxCalendarDateAttr(const wxColour& colText = wxNullColour,
  82. const wxColour& colBack = wxNullColour,
  83. const wxColour& colBorder = wxNullColour,
  84. const wxFont& font = wxNullFont,
  85. wxCalendarDateBorder border = wxCAL_BORDER_NONE);
  86. /**
  87. Constructor using default properties except the given border.
  88. */
  89. wxCalendarDateAttr(wxCalendarDateBorder border,
  90. const wxColour& colBorder = wxNullColour);
  91. /**
  92. Returns the background colour set for the calendar date.
  93. */
  94. const wxColour& GetBackgroundColour() const;
  95. /**
  96. Returns the border set for the calendar date.
  97. */
  98. wxCalendarDateBorder GetBorder() const;
  99. /**
  100. Returns the border colour set for the calendar date.
  101. */
  102. const wxColour& GetBorderColour() const;
  103. /**
  104. Returns the font set for the calendar date.
  105. */
  106. const wxFont& GetFont() const;
  107. /**
  108. Returns the text colour set for the calendar date.
  109. */
  110. const wxColour& GetTextColour() const;
  111. /**
  112. Returns @true if a non-default text background colour is set.
  113. */
  114. bool HasBackgroundColour() const;
  115. /**
  116. Returns @true if a non-default (i.e.\ any) border is set.
  117. */
  118. bool HasBorder() const;
  119. /**
  120. Returns @true if a non-default border colour is set.
  121. */
  122. bool HasBorderColour() const;
  123. /**
  124. Returns @true if a non-default font is set.
  125. */
  126. bool HasFont() const;
  127. /**
  128. Returns @true if a non-default text foreground colour is set.
  129. */
  130. bool HasTextColour() const;
  131. /**
  132. Returns @true if this calendar day is displayed as a holiday.
  133. */
  134. bool IsHoliday() const;
  135. /**
  136. Sets the text background colour to use.
  137. */
  138. void SetBackgroundColour(const wxColour& colBack);
  139. /**
  140. Sets the border to use.
  141. */
  142. void SetBorder(wxCalendarDateBorder border);
  143. /**
  144. Sets the border colour to use.
  145. */
  146. void SetBorderColour(const wxColour& col);
  147. /**
  148. Sets the font to use.
  149. */
  150. void SetFont(const wxFont& font);
  151. /**
  152. If @a holiday is @true, this calendar day will be displayed as a
  153. holiday.
  154. */
  155. void SetHoliday(bool holiday);
  156. /**
  157. Sets the text (foreground) colour to use.
  158. */
  159. void SetTextColour(const wxColour& colText);
  160. /**
  161. Used (internally) by the generic wxCalendarCtrl::Mark().
  162. */
  163. static const wxCalendarDateAttr& GetMark();
  164. /**
  165. Set the attributes that will be used to Mark() days on the generic
  166. wxCalendarCtrl.
  167. */
  168. static void SetMark(const wxCalendarDateAttr& m);
  169. };
  170. /**
  171. Possible return values from wxCalendarCtrl::HitTest().
  172. */
  173. enum wxCalendarHitTestResult
  174. {
  175. wxCAL_HITTEST_NOWHERE, ///< Hit outside of anything.
  176. wxCAL_HITTEST_HEADER, ///< Hit on the header (weekdays).
  177. wxCAL_HITTEST_DAY, ///< Hit on a day in the calendar.
  178. wxCAL_HITTEST_INCMONTH, ///< Hit on next month arrow (in alternate month selector mode).
  179. wxCAL_HITTEST_DECMONTH, ///< Hit on previous month arrow (in alternate month selector mode).
  180. wxCAL_HITTEST_SURROUNDING_WEEK, ///< Hit on surrounding week of previous/next month (if shown).
  181. wxCAL_HITTEST_WEEK ///< Hit on week of the year number (if shown).
  182. };
  183. /**
  184. @class wxCalendarCtrl
  185. The calendar control allows the user to pick a date. The user can move the
  186. current selection using the keyboard and select the date (generating
  187. @c EVT_CALENDAR event) by pressing @c @<Return@> or double clicking it.
  188. Generic calendar has advanced possibilities for the customization of its
  189. display, described below. If you want to use these possibilities on every
  190. platform, use wxGenericCalendarCtrl instead of wxCalendarCtrl.
  191. All global settings (such as colours and fonts used) can, of course, be
  192. changed. But also, the display style for each day in the month can be set
  193. independently using wxCalendarDateAttr class.
  194. An item without custom attributes is drawn with the default colours and
  195. font and without border, but setting custom attributes with SetAttr()
  196. allows to modify its appearance. Just create a custom attribute object and
  197. set it for the day you want to be displayed specially (note that the
  198. control will take ownership of the pointer, i.e. it will delete it itself).
  199. A day may be marked as being a holiday, even if it is not recognized as
  200. one by wxDateTime using the wxCalendarDateAttr::SetHoliday() method.
  201. As the attributes are specified for each day, they may change when the
  202. month is changed, so you will often want to update them in
  203. @c EVT_CALENDAR_PAGE_CHANGED event handler.
  204. @beginStyleTable
  205. @style{wxCAL_SUNDAY_FIRST}
  206. Show Sunday as the first day in the week (not in wxGTK)
  207. @style{wxCAL_MONDAY_FIRST}
  208. Show Monday as the first day in the week (not in wxGTK)
  209. @style{wxCAL_SHOW_HOLIDAYS}
  210. Highlight holidays in the calendar (only generic)
  211. @style{wxCAL_NO_YEAR_CHANGE}
  212. Disable the year changing (deprecated, only generic)
  213. @style{wxCAL_NO_MONTH_CHANGE}
  214. Disable the month (and, implicitly, the year) changing
  215. @style{wxCAL_SHOW_SURROUNDING_WEEKS}
  216. Show the neighbouring weeks in the previous and next months
  217. (only generic, always on for the native controls)
  218. @style{wxCAL_SEQUENTIAL_MONTH_SELECTION}
  219. Use alternative, more compact, style for the month and year
  220. selection controls. (only generic)
  221. @style{wxCAL_SHOW_WEEK_NUMBERS}
  222. Show week numbers on the left side of the calendar. (not in generic)
  223. @endStyleTable
  224. @beginEventEmissionTable{wxCalendarEvent}
  225. @event{EVT_CALENDAR(id, func)}
  226. A day was double clicked in the calendar.
  227. @event{EVT_CALENDAR_SEL_CHANGED(id, func)}
  228. The selected date changed.
  229. @event{EVT_CALENDAR_PAGE_CHANGED(id, func)}
  230. The selected month (and/or year) changed.
  231. @event{EVT_CALENDAR_WEEKDAY_CLICKED(id, func)}
  232. User clicked on the week day header (only generic).
  233. @event{EVT_CALENDAR_WEEK_CLICKED(id, func)}
  234. User clicked on the week of the year number (only generic).
  235. @endEventTable
  236. @note Changing the selected date will trigger an EVT_CALENDAR_DAY, MONTH or
  237. YEAR event as well as an EVT_CALENDAR_SEL_CHANGED event.
  238. @library{wxadv}
  239. @category{ctrl}
  240. @appearance{calendarctrl}
  241. @nativeimpl{wxgtk,wxmsw}
  242. @see @ref page_samples_calendar, wxCalendarDateAttr, wxCalendarEvent,
  243. wxDatePickerCtrl
  244. */
  245. class wxCalendarCtrl : public wxControl
  246. {
  247. public:
  248. /**
  249. Default constructor.
  250. */
  251. wxCalendarCtrl();
  252. /**
  253. Does the same as Create() method.
  254. */
  255. wxCalendarCtrl(wxWindow* parent, wxWindowID id,
  256. const wxDateTime& date = wxDefaultDateTime,
  257. const wxPoint& pos = wxDefaultPosition,
  258. const wxSize& size = wxDefaultSize,
  259. long style = wxCAL_SHOW_HOLIDAYS,
  260. const wxString& name = wxCalendarNameStr);
  261. /**
  262. Destroys the control.
  263. */
  264. ~wxCalendarCtrl();
  265. /**
  266. Creates the control. See wxWindow::wxWindow() for the meaning of the
  267. parameters and the control overview for the possible styles.
  268. */
  269. bool Create(wxWindow* parent, wxWindowID id,
  270. const wxDateTime& date = wxDefaultDateTime,
  271. const wxPoint& pos = wxDefaultPosition,
  272. const wxSize& size = wxDefaultSize,
  273. long style = wxCAL_SHOW_HOLIDAYS,
  274. const wxString& name = wxCalendarNameStr);
  275. /**
  276. This function should be used instead of changing @c wxCAL_SHOW_HOLIDAYS
  277. style bit directly. It enables or disables the special highlighting of
  278. the holidays.
  279. */
  280. virtual void EnableHolidayDisplay(bool display = true);
  281. /**
  282. This function should be used instead of changing
  283. @c wxCAL_NO_MONTH_CHANGE style bit. It allows or disallows the user to
  284. change the month interactively. Note that if the month cannot be
  285. changed, the year cannot be changed neither.
  286. @return @true if the value of this option really changed or @false if
  287. it was already set to the requested value.
  288. */
  289. virtual bool EnableMonthChange(bool enable = true);
  290. /**
  291. @deprecated
  292. This function should be used instead of changing
  293. @c wxCAL_NO_YEAR_CHANGE style bit directly. It allows or disallows the
  294. user to change the year interactively. Only in generic wxCalendarCtrl.
  295. */
  296. virtual void EnableYearChange(bool enable = true);
  297. /**
  298. Returns the attribute for the given date (should be in the range
  299. 1...31). The returned pointer may be @NULL. Only in generic
  300. wxCalendarCtrl.
  301. */
  302. virtual wxCalendarDateAttr* GetAttr(size_t day) const;
  303. /**
  304. Gets the currently selected date.
  305. */
  306. virtual wxDateTime GetDate() const;
  307. /**
  308. Gets the background colour of the header part of the calendar window.
  309. This method is currently only implemented in generic wxCalendarCtrl and
  310. always returns @c wxNullColour in the native versions.
  311. @see SetHeaderColours()
  312. */
  313. virtual const wxColour& GetHeaderColourBg() const;
  314. /**
  315. Gets the foreground colour of the header part of the calendar window.
  316. This method is currently only implemented in generic wxCalendarCtrl and
  317. always returns @c wxNullColour in the native versions.
  318. @see SetHeaderColours()
  319. */
  320. virtual const wxColour& GetHeaderColourFg() const;
  321. /**
  322. Gets the background highlight colour. Only in generic wxCalendarCtrl.
  323. This method is currently only implemented in generic wxCalendarCtrl and
  324. always returns @c wxNullColour in the native versions.
  325. @see SetHighlightColours()
  326. */
  327. virtual const wxColour& GetHighlightColourBg() const;
  328. /**
  329. Gets the foreground highlight colour. Only in generic wxCalendarCtrl.
  330. This method is currently only implemented in generic wxCalendarCtrl and
  331. always returns @c wxNullColour in the native versions.
  332. @see SetHighlightColours()
  333. */
  334. virtual const wxColour& GetHighlightColourFg() const;
  335. /**
  336. Return the background colour currently used for holiday highlighting.
  337. Only useful with generic wxCalendarCtrl as native versions currently
  338. don't support holidays display at all and always return
  339. @c wxNullColour.
  340. @see SetHolidayColours()
  341. */
  342. virtual const wxColour& GetHolidayColourBg() const;
  343. /**
  344. Return the foreground colour currently used for holiday highlighting.
  345. Only useful with generic wxCalendarCtrl as native versions currently
  346. don't support holidays display at all and always return
  347. @c wxNullColour.
  348. @see SetHolidayColours()
  349. */
  350. virtual const wxColour& GetHolidayColourFg() const;
  351. /**
  352. Returns one of wxCalendarHitTestResult constants and fills either
  353. @a date or @a wd pointer with the corresponding value depending on the
  354. hit test code.
  355. Not implemented in wxGTK currently.
  356. */
  357. virtual wxCalendarHitTestResult HitTest(const wxPoint& pos,
  358. wxDateTime* date = NULL,
  359. wxDateTime::WeekDay* wd = NULL);
  360. /**
  361. Clears any attributes associated with the given day (in the range
  362. 1...31). Only in generic wxCalendarCtrl.
  363. */
  364. virtual void ResetAttr(size_t day);
  365. /**
  366. Associates the attribute with the specified date (in the range 1...31).
  367. If the pointer is @NULL, the items attribute is cleared. Only in
  368. generic wxCalendarCtrl.
  369. */
  370. virtual void SetAttr(size_t day, wxCalendarDateAttr* attr);
  371. /**
  372. Sets the current date.
  373. The @a date parameter must be valid and in the currently valid range as
  374. set by SetDateRange(), otherwise the current date is not changed and
  375. the function returns @false.
  376. */
  377. virtual bool SetDate(const wxDateTime& date);
  378. /**
  379. Set the colours used for painting the weekdays at the top of the
  380. control.
  381. This method is currently only implemented in generic wxCalendarCtrl and
  382. does nothing in the native versions.
  383. */
  384. virtual void SetHeaderColours(const wxColour& colFg,
  385. const wxColour& colBg);
  386. /**
  387. Set the colours to be used for highlighting the currently selected
  388. date.
  389. This method is currently only implemented in generic wxCalendarCtrl and
  390. does nothing in the native versions.
  391. */
  392. virtual void SetHighlightColours(const wxColour& colFg,
  393. const wxColour& colBg);
  394. /**
  395. Marks the specified day as being a holiday in the current month.
  396. This method is only implemented in the generic version of the control
  397. and does nothing in the native ones.
  398. */
  399. virtual void SetHoliday(size_t day);
  400. /**
  401. Sets the colours to be used for the holidays highlighting.
  402. This method is only implemented in the generic version of the control
  403. and does nothing in the native ones. It should also only be called if
  404. the window style includes @c wxCAL_SHOW_HOLIDAYS flag or
  405. EnableHolidayDisplay() had been called.
  406. */
  407. virtual void SetHolidayColours(const wxColour& colFg,
  408. const wxColour& colBg);
  409. /**
  410. Mark or unmark the day. This day of month will be marked in every
  411. month. In generic wxCalendarCtrl,
  412. */
  413. virtual void Mark(size_t day, bool mark);
  414. /**
  415. @name Date Range Functions
  416. */
  417. //@{
  418. /**
  419. Restrict the dates that can be selected in the control to the specified
  420. range.
  421. If either date is set, the corresponding limit will be enforced and
  422. @true returned. If none are set, the existing restrictions are removed
  423. and @false is returned.
  424. @see GetDateRange()
  425. @param lowerdate
  426. The low limit for the dates shown by the control or
  427. ::wxDefaultDateTime.
  428. @param upperdate
  429. The high limit for the dates shown by the control or
  430. ::wxDefaultDateTime.
  431. @return
  432. @true if either limit is valid, @false otherwise
  433. */
  434. virtual bool SetDateRange(const wxDateTime& lowerdate = wxDefaultDateTime,
  435. const wxDateTime& upperdate = wxDefaultDateTime);
  436. /**
  437. Returns the limits currently being used.
  438. @see SetDateRange()
  439. @param lowerdate
  440. If non-@NULL, the value of the low limit for the dates shown by the
  441. control is returned (which may be ::wxDefaultDateTime if no limit
  442. is set).
  443. @param upperdate
  444. If non-@NULL, the value of the upper limit for the dates shown by
  445. the control is returned (which may be ::wxDefaultDateTime if no
  446. limit is set).
  447. @return
  448. @true if either limit is set, @false otherwise
  449. */
  450. virtual bool GetDateRange(wxDateTime *lowerdate,
  451. wxDateTime *upperdate) const;
  452. //@}
  453. };