timectrl.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/timectrl.h
  3. // Purpose: interface of wxTimePickerCtrl
  4. // Author: Vadim Zeitlin
  5. // Created: 2011-09-22
  6. // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. /**
  10. Styles used with wxTimePickerCtrl.
  11. Currently no special styles are defined for this object.
  12. @library{wxadv}
  13. @category{pickers}
  14. @since 2.9.3
  15. */
  16. enum
  17. {
  18. wxTP_DEFAULT = 0
  19. };
  20. /**
  21. @class wxTimePickerCtrl
  22. This control allows the user to enter time.
  23. It is similar to wxDatePickerCtrl but is used for time, and not date,
  24. selection. While GetValue() and SetValue() still work with values of type
  25. wxDateTime (because wxWidgets doesn't provide a time-only class), their
  26. date part is ignored by this control.
  27. It is only available if @c wxUSE_TIMEPICKCTRL is set to 1.
  28. This control currently doesn't have any specific flags.
  29. @beginEventEmissionTable{wxDateEvent}
  30. @event{EVT_TIME_CHANGED(id, func)}
  31. This event fires when the user changes the current selection in the
  32. control.
  33. @endEventTable
  34. @library{wxadv}
  35. @category{pickers}
  36. @appearance{timepickerctrl}
  37. @see wxDatePickerCtrl, wxDateEvent
  38. @since 2.9.3
  39. */
  40. class wxTimePickerCtrl : public wxControl
  41. {
  42. public:
  43. /**
  44. Default constructor.
  45. */
  46. wxTimePickerCtrl();
  47. /**
  48. Initializes the object and calls Create() with all the parameters.
  49. */
  50. wxTimePickerCtrl(wxWindow* parent, wxWindowID id,
  51. const wxDateTime& dt = wxDefaultDateTime,
  52. const wxPoint& pos = wxDefaultPosition,
  53. const wxSize& size = wxDefaultSize,
  54. long style = wxTP_DEFAULT,
  55. const wxValidator& validator = wxDefaultValidator,
  56. const wxString& name = "timectrl");
  57. /**
  58. Create the control window.
  59. This method should only be used for objects created using default
  60. constructor.
  61. @param parent
  62. Parent window, must not be non-@NULL.
  63. @param id
  64. The identifier for the control.
  65. @param dt
  66. The initial value of the control, if an invalid date (such as the
  67. default value) is used, the control is set to current time.
  68. @param pos
  69. Initial position.
  70. @param size
  71. Initial size. If left at default value, the control chooses its own
  72. best size by using the height approximately equal to a text control
  73. and width large enough to show the time fully.
  74. @param style
  75. The window style, should be left at 0 as there are no special
  76. styles for this control in this version.
  77. @param validator
  78. Validator which can be used for additional checks.
  79. @param name
  80. Control name.
  81. @return @true if the control was successfully created or @false if
  82. creation failed.
  83. */
  84. bool Create(wxWindow* parent, wxWindowID id,
  85. const wxDateTime& dt = wxDefaultDateTime,
  86. const wxPoint& pos = wxDefaultPosition,
  87. const wxSize& size = wxDefaultSize,
  88. long style = wxDP_DEFAULT | wxDP_SHOWCENTURY,
  89. const wxValidator& validator = wxDefaultValidator,
  90. const wxString& name = "timectrl");
  91. /**
  92. Returns the currently entered time as hours, minutes and seconds.
  93. All the arguments must be non-@NULL, @false is returned otherwise and
  94. none of them is modified.
  95. @see SetTime()
  96. @since 2.9.4
  97. */
  98. bool GetTime(int* hour, int* min, int* sec) const;
  99. /**
  100. Returns the currently entered time.
  101. The date part of the returned wxDateTime object is always set to today
  102. and should be ignored, only the time part is relevant.
  103. */
  104. virtual wxDateTime GetValue() const;
  105. /**
  106. Changes the current time of the control.
  107. Calling this method does not result in a time change event.
  108. @param hour The new hour value in 0..23 interval.
  109. @param min The new minute value in 0..59 interval.
  110. @param sec The new second value in 0..59 interval.
  111. @return @true if the time was changed or @false on failure, e.g. if the
  112. time components were invalid.
  113. @see GetTime()
  114. @since 2.9.4
  115. */
  116. bool SetTime(int hour, int min, int sec);
  117. /**
  118. Changes the current value of the control.
  119. The date part of @a dt is ignored, only the time part is displayed in
  120. the control. The @a dt object must however be valid.
  121. In particular notice that it is a bad idea to use default wxDateTime
  122. constructor from hour, minute and second values as it uses the today
  123. date for the date part which means that some times can be invalid if
  124. today happens to be the day of DST change. For example, when switching
  125. to summer time the time 2:00 typically doesn't exist as the clocks jump
  126. directly to 3:00. To avoid this problem, use a fixed date on which DST
  127. is known not to change (e.g. Jan 1, 2012) for the date part of the
  128. argument or use SetTime().
  129. Calling this method does not result in a time change event.
  130. */
  131. virtual void SetValue(const wxDateTime& dt);
  132. };