datectrl.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: datectrl.h
  3. // Purpose: interface of wxDatePickerCtrl
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /// wxDatePickerCtrl styles
  8. enum
  9. {
  10. /// default style on this platform, either wxDP_SPIN or wxDP_DROPDOWN
  11. wxDP_DEFAULT = 0,
  12. /// a spin control-like date picker (not supported in generic version)
  13. wxDP_SPIN = 1,
  14. /// a combobox-like date picker (not supported in mac version)
  15. wxDP_DROPDOWN = 2,
  16. /// always show century in the default date display (otherwise it depends on
  17. /// the system date format which may include the century or not)
  18. wxDP_SHOWCENTURY = 4,
  19. /// allow not having any valid date in the control (by default it always has
  20. /// some date, today initially if no valid date specified in ctor)
  21. wxDP_ALLOWNONE = 8
  22. };
  23. /**
  24. @class wxDatePickerCtrl
  25. This control allows the user to select a date. Unlike wxCalendarCtrl, which
  26. is a relatively big control, wxDatePickerCtrl is implemented as a small
  27. window showing the currently selected date. The control can be edited using
  28. the keyboard, and can also display a popup window for more user-friendly
  29. date selection, depending on the styles used and the platform.
  30. It is only available if @c wxUSE_DATEPICKCTRL is set to 1.
  31. @beginStyleTable
  32. @style{wxDP_SPIN}
  33. Creates a control without a month calendar drop down but with
  34. spin-control-like arrows to change individual date components. This
  35. style is not supported by the generic version.
  36. @style{wxDP_DROPDOWN}
  37. Creates a control with a month calendar drop-down part from which
  38. the user can select a date. This style is not supported in OSX/Cocoa
  39. native version.
  40. @style{wxDP_DEFAULT}
  41. Creates a control with the style that is best supported for the
  42. current platform (currently wxDP_SPIN under Windows and OSX/Cocoa
  43. and wxDP_DROPDOWN elsewhere).
  44. @style{wxDP_ALLOWNONE}
  45. With this style, the control allows the user to not enter any valid
  46. date at all. Without it - the default - the control always has some
  47. valid date. This style is not supported in OSX/Cocoa native version.
  48. @style{wxDP_SHOWCENTURY}
  49. Forces display of the century in the default date format. Without
  50. this style the century could be displayed, or not, depending on the
  51. default date representation in the system. This style is not
  52. supported in OSX/Cocoa native version currently.
  53. @endStyleTable
  54. As can be seen from the remarks above, most of the control style are only
  55. supported in the native MSW implementation. In portable code it's
  56. recommended to use @c wxDP_DEFAULT style only, possibly combined with @c
  57. wxDP_SHOWCENTURY (this is also the style used by default if none is
  58. specified).
  59. @beginEventEmissionTable{wxDateEvent}
  60. @event{EVT_DATE_CHANGED(id, func)}
  61. This event fires when the user changes the current selection in the
  62. control.
  63. @endEventTable
  64. @library{wxadv}
  65. @category{pickers}
  66. @appearance{datepickerctrl}
  67. @see wxCalendarCtrl, wxDateEvent
  68. */
  69. class wxDatePickerCtrl : public wxControl
  70. {
  71. public:
  72. /**
  73. Default constructor.
  74. */
  75. wxDatePickerCtrl();
  76. /**
  77. Initializes the object and calls Create() with all the parameters.
  78. */
  79. wxDatePickerCtrl(wxWindow* parent, wxWindowID id,
  80. const wxDateTime& dt = wxDefaultDateTime,
  81. const wxPoint& pos = wxDefaultPosition,
  82. const wxSize& size = wxDefaultSize,
  83. long style = wxDP_DEFAULT | wxDP_SHOWCENTURY,
  84. const wxValidator& validator = wxDefaultValidator,
  85. const wxString& name = "datectrl");
  86. /**
  87. Create the control window.
  88. This method should only be used for objects created using default
  89. constructor.
  90. @param parent
  91. Parent window, must not be non-@NULL.
  92. @param id
  93. The identifier for the control.
  94. @param dt
  95. The initial value of the control, if an invalid date (such as the
  96. default value) is used, the control is set to today.
  97. @param pos
  98. Initial position.
  99. @param size
  100. Initial size. If left at default value, the control chooses its own
  101. best size by using the height approximately equal to a text control
  102. and width large enough to show the date string fully.
  103. @param style
  104. The window style, see the description of the styles in the class
  105. documentation.
  106. @param validator
  107. Validator which can be used for additional date checks.
  108. @param name
  109. Control name.
  110. @return @true if the control was successfully created or @false if
  111. creation failed.
  112. */
  113. bool Create(wxWindow* parent, wxWindowID id,
  114. const wxDateTime& dt = wxDefaultDateTime,
  115. const wxPoint& pos = wxDefaultPosition,
  116. const wxSize& size = wxDefaultSize,
  117. long style = wxDP_DEFAULT | wxDP_SHOWCENTURY,
  118. const wxValidator& validator = wxDefaultValidator,
  119. const wxString& name = "datectrl");
  120. /**
  121. If the control had been previously limited to a range of dates using
  122. SetRange(), returns the lower and upper bounds of this range. If no
  123. range is set (or only one of the bounds is set), @a dt1 and/or @a dt2
  124. are set to be invalid.
  125. Notice that when using a native MSW implementation of this control the
  126. lower range is always set, even if SetRange() hadn't been called
  127. explicitly, as the native control only supports dates later than year
  128. 1601.
  129. @param dt1
  130. Pointer to the object which receives the lower range limit or
  131. becomes invalid if it is not set. May be @NULL if the caller is not
  132. interested in lower limit.
  133. @param dt2
  134. Same as above but for the upper limit.
  135. @return @false if no range limits are currently set, @true if at least
  136. one bound is set.
  137. */
  138. virtual bool GetRange(wxDateTime* dt1, wxDateTime* dt2) const;
  139. /**
  140. Returns the currently entered date.
  141. For a control with @c wxDP_ALLOWNONE style the returned value may be
  142. invalid if no date is entered, otherwise it is always valid.
  143. */
  144. virtual wxDateTime GetValue() const;
  145. /**
  146. Sets the valid range for the date selection. If @a dt1 is valid, it
  147. becomes the earliest date (inclusive) accepted by the control. If
  148. @a dt2 is valid, it becomes the latest possible date.
  149. @remarks If the current value of the control is outside of the newly
  150. set range bounds, the behaviour is undefined.
  151. */
  152. virtual void SetRange(const wxDateTime& dt1, const wxDateTime& dt2);
  153. /**
  154. Changes the current value of the control.
  155. The date should be valid unless the control was created with @c
  156. wxDP_ALLOWNONE style and included in the currently selected range, if
  157. any.
  158. Calling this method does not result in a date change event.
  159. */
  160. virtual void SetValue(const wxDateTime& dt);
  161. };