timectrl.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/timectrl.h
  3. // Purpose: Declaration of wxTimePickerCtrl class.
  4. // Author: Vadim Zeitlin
  5. // Created: 2011-09-22
  6. // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_TIMECTRL_H_
  10. #define _WX_TIMECTRL_H_
  11. #include "wx/defs.h"
  12. #if wxUSE_TIMEPICKCTRL
  13. #include "wx/datetimectrl.h"
  14. #define wxTimePickerCtrlNameStr wxS("timectrl")
  15. // No special styles are currently defined for this control but still define a
  16. // symbolic constant for the default style for consistency.
  17. enum
  18. {
  19. wxTP_DEFAULT = 0
  20. };
  21. // ----------------------------------------------------------------------------
  22. // wxTimePickerCtrl: Allow the user to enter the time.
  23. // ----------------------------------------------------------------------------
  24. class WXDLLIMPEXP_ADV wxTimePickerCtrlBase : public wxDateTimePickerCtrl
  25. {
  26. public:
  27. /*
  28. The derived classes should implement ctor and Create() method with the
  29. following signature:
  30. bool Create(wxWindow *parent,
  31. wxWindowID id,
  32. const wxDateTime& dt = wxDefaultDateTime,
  33. const wxPoint& pos = wxDefaultPosition,
  34. const wxSize& size = wxDefaultSize,
  35. long style = wxTP_DEFAULT,
  36. const wxValidator& validator = wxDefaultValidator,
  37. const wxString& name = wxTimePickerCtrlNameStr);
  38. */
  39. /*
  40. We also inherit Set/GetValue() methods from the base class which define
  41. our public API. Notice that the date portion of the date passed as
  42. input or received as output is or should be ignored, only the time part
  43. of wxDateTime objects is really significant here. Use Set/GetTime()
  44. below for possibly simpler interface.
  45. */
  46. // Set the given time.
  47. bool SetTime(int hour, int min, int sec)
  48. {
  49. // Notice that we should use a date on which DST doesn't change to
  50. // avoid any problems with time discontinuity so use a fixed date (on
  51. // which nobody changes DST) instead of e.g. today.
  52. wxDateTime dt(1, wxDateTime::Jan, 2012, hour, min, sec);
  53. if ( !dt.IsValid() )
  54. {
  55. // No need to assert here, wxDateTime already does it for us.
  56. return false;
  57. }
  58. SetValue(dt);
  59. return true;
  60. }
  61. // Get the current time components. All pointers must be non-NULL.
  62. bool GetTime(int* hour, int* min, int* sec) const
  63. {
  64. wxCHECK_MSG( hour && min && sec, false,
  65. wxS("Time component pointers must be non-NULL") );
  66. const wxDateTime::Tm tm = GetValue().GetTm();
  67. *hour = tm.hour;
  68. *min = tm.min;
  69. *sec = tm.sec;
  70. return true;
  71. }
  72. };
  73. #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
  74. #include "wx/msw/timectrl.h"
  75. #define wxHAS_NATIVE_TIMEPICKERCTRL
  76. #elif defined(__WXOSX_COCOA__) && !defined(__WXUNIVERSAL__)
  77. #include "wx/osx/timectrl.h"
  78. #define wxHAS_NATIVE_TIMEPICKERCTRL
  79. #else
  80. #include "wx/generic/timectrl.h"
  81. class WXDLLIMPEXP_ADV wxTimePickerCtrl : public wxTimePickerCtrlGeneric
  82. {
  83. public:
  84. wxTimePickerCtrl() { }
  85. wxTimePickerCtrl(wxWindow *parent,
  86. wxWindowID id,
  87. const wxDateTime& date = wxDefaultDateTime,
  88. const wxPoint& pos = wxDefaultPosition,
  89. const wxSize& size = wxDefaultSize,
  90. long style = wxTP_DEFAULT,
  91. const wxValidator& validator = wxDefaultValidator,
  92. const wxString& name = wxTimePickerCtrlNameStr)
  93. : wxTimePickerCtrlGeneric(parent, id, date, pos, size, style, validator, name)
  94. {
  95. }
  96. private:
  97. wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxTimePickerCtrl);
  98. };
  99. #endif
  100. #endif // wxUSE_TIMEPICKCTRL
  101. #endif // _WX_TIMECTRL_H_