Add wxTimePickerCtrl class.

Implement wxTimePickerCtrl natively for MSW and add a generic implementation
(very loosely based on the original class by Paul Breen) for the other
platforms.

Also update the calendar sample to show the new control.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69224 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-09-29 13:43:15 +00:00
parent 1319b2684f
commit 569c7d8ccb
39 changed files with 2140 additions and 166 deletions

View File

@@ -1101,6 +1101,14 @@
# endif
#endif /* !defined(wxUSE_TEXTCTRL) */
#ifndef wxUSE_TIMEPICKCTRL
# ifdef wxABORT_ON_CONFIG_ERROR
# error "wxUSE_TIMEPICKCTRL must be defined, please read comment near the top of this file."
# else
# define wxUSE_TIMEPICKCTRL 0
# endif
#endif /* !defined(wxUSE_TIMEPICKCTRL) */
#ifndef wxUSE_TIPWINDOW
# ifdef wxABORT_ON_CONFIG_ERROR
# error "wxUSE_TIPWINDOW must be defined, please read comment near the top of this file."
@@ -1713,16 +1721,16 @@
# endif
#endif /* wxUSE_CALENDARCTRL */
#if wxUSE_DATEPICKCTRL
#if wxUSE_DATEPICKCTRL || wxUSE_TIMEPICKCTRL
# if !wxUSE_DATETIME
# ifdef wxABORT_ON_CONFIG_ERROR
# error "wxDatePickerCtrl requires wxUSE_DATETIME"
# error "wxDatePickerCtrl and wxTimePickerCtrl requires wxUSE_DATETIME"
# else
# undef wxUSE_DATETIME
# define wxUSE_DATETIME 1
# endif
# endif
#endif /* wxUSE_DATEPICKCTRL */
#endif /* wxUSE_DATEPICKCTRL || wxUSE_TIMEPICKCTRL */
#if wxUSE_CHECKLISTBOX
# if !wxUSE_LISTBOX

View File

@@ -17,7 +17,7 @@
#include "wx/window.h"
// ----------------------------------------------------------------------------
// wxDateEvent: used by wxCalendarCtrl and wxDatePickerCtrl
// wxDateEvent: used by wxCalendarCtrl, wxDatePickerCtrl and wxTimePickerCtrl.
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxDateEvent : public wxCommandEvent
@@ -48,6 +48,7 @@ private:
// ----------------------------------------------------------------------------
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_ADV, wxEVT_DATE_CHANGED, wxDateEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_ADV, wxEVT_TIME_CHANGED, wxDateEvent);
typedef void (wxEvtHandler::*wxDateEventFunction)(wxDateEvent&);
@@ -57,5 +58,8 @@ typedef void (wxEvtHandler::*wxDateEventFunction)(wxDateEvent&);
#define EVT_DATE_CHANGED(id, fn) \
wx__DECLARE_EVT1(wxEVT_DATE_CHANGED, id, wxDateEventHandler(fn))
#define EVT_TIME_CHANGED(id, fn) \
wx__DECLARE_EVT1(wxEVT_TIME_CHANGED, id, wxDateEventHandler(fn))
#endif // _WX_DATEEVT_H_

View File

@@ -13,7 +13,7 @@
#include "wx/defs.h"
#if wxUSE_DATEPICKCTRL
#if wxUSE_DATEPICKCTRL || wxUSE_TIMEPICKCTRL
#define wxNEEDS_DATETIMEPICKCTRL
@@ -43,6 +43,6 @@ public:
typedef wxDateTimePickerCtrlBase wxDateTimePickerCtrl;
#endif
#endif // wxUSE_DATEPICKCTRL
#endif // wxUSE_DATEPICKCTRL || wxUSE_TIMEPICKCTRL
#endif // _WX_DATETIME_CTRL_H_

View File

@@ -0,0 +1,93 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/generic/timectrl.h
// Purpose: Generic implementation of wxTimePickerCtrl.
// Author: Paul Breen, Vadim Zeitlin
// Created: 2011-09-22
// RCS-ID: $Id: wxhead.h,v 1.12 2010-04-22 12:44:51 zeitlin Exp $
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GENERIC_TIMECTRL_H_
#define _WX_GENERIC_TIMECTRL_H_
#include "wx/containr.h"
#include "wx/compositewin.h"
class WXDLLIMPEXP_ADV wxTimePickerCtrlGeneric
: public wxCompositeWindow< wxNavigationEnabled<wxTimePickerCtrlBase> >
{
public:
typedef wxCompositeWindow< wxNavigationEnabled<wxTimePickerCtrlBase> > Base;
// Creating the control.
wxTimePickerCtrlGeneric() { Init(); }
virtual ~wxTimePickerCtrlGeneric();
wxTimePickerCtrlGeneric(wxWindow *parent,
wxWindowID id,
const wxDateTime& date = wxDefaultDateTime,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxTP_DEFAULT,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxTimePickerCtrlNameStr)
{
Init();
(void)Create(parent, id, date, pos, size, style, validator, name);
}
bool Create(wxWindow *parent,
wxWindowID id,
const wxDateTime& date = wxDefaultDateTime,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxTP_DEFAULT,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxTimePickerCtrlNameStr);
// Implement pure virtual wxTimePickerCtrlBase methods.
virtual void SetValue(const wxDateTime& date);
virtual wxDateTime GetValue() const;
protected:
virtual wxSize DoGetBestSize() const;
virtual void DoMoveWindow(int x, int y, int width, int height);
// This is a really ugly hack but to compile this class in wxMSW we must
// define these functions even though they are never called because they're
// only used by the native implementation.
#ifdef __WXMSW__
virtual wxLocaleInfo MSWGetFormat() const
{
wxFAIL_MSG( "Unreachable" );
return wxLOCALE_TIME_FMT;
}
virtual bool MSWAllowsNone() const
{
wxFAIL_MSG( "Unreachable" );
return false;
}
virtual bool MSWOnDateTimeChange(const tagNMDATETIMECHANGE& WXUNUSED(dtch))
{
wxFAIL_MSG( "Unreachable" );
return false;
}
#endif // __WXMSW__
private:
void Init();
// Return the list of the windows composing this one.
virtual wxWindowList GetCompositeWindowParts() const;
// Implementation data.
class wxTimePickerGenericImpl* m_impl;
wxDECLARE_NO_COPY_CLASS(wxTimePickerCtrlGeneric);
};
#endif // _WX_GENERIC_TIMECTRL_H_

View File

@@ -867,6 +867,7 @@
#define wxUSE_STATTEXT 1 // wxStaticText
#define wxUSE_STATBMP 1 // wxStaticBitmap
#define wxUSE_TEXTCTRL 1 // wxTextCtrl
#define wxUSE_TIMEPICKCTRL 1 // wxTimePickerCtrl
#define wxUSE_TOGGLEBTN 1 // requires wxButton
#define wxUSE_TREECTRL 1 // wxTreeCtrl
#define wxUSE_TREELISTCTRL 1 // wxTreeListCtrl

View File

@@ -867,6 +867,7 @@
#define wxUSE_STATTEXT 1 // wxStaticText
#define wxUSE_STATBMP 1 // wxStaticBitmap
#define wxUSE_TEXTCTRL 1 // wxTextCtrl
#define wxUSE_TIMEPICKCTRL 1 // wxTimePickerCtrl
#define wxUSE_TOGGLEBTN 1 // requires wxButton
#define wxUSE_TREECTRL 1 // wxTreeCtrl
#define wxUSE_TREELISTCTRL 1 // wxTreeListCtrl
@@ -1604,6 +1605,14 @@
// Recommended setting: 0, this is mainly used for testing
#define wxUSE_DATEPICKCTRL_GENERIC 0
// Set this to 1 to be able to use wxTimePickerCtrlGeneric in addition to the
// native wxTimePickerCtrl for the platforms that have the latter (MSW).
//
// Default is 0.
//
// Recommended setting: 0, this is mainly used for testing
#define wxUSE_TIMEPICKCTRL_GENERIC 0
// ----------------------------------------------------------------------------
// Crash debugging helpers
// ----------------------------------------------------------------------------

View File

@@ -144,6 +144,14 @@
// Recommended setting: 0, this is mainly used for testing
#define wxUSE_DATEPICKCTRL_GENERIC 0
// Set this to 1 to be able to use wxTimePickerCtrlGeneric in addition to the
// native wxTimePickerCtrl for the platforms that have the latter (MSW).
//
// Default is 0.
//
// Recommended setting: 0, this is mainly used for testing
#define wxUSE_TIMEPICKCTRL_GENERIC 0
// ----------------------------------------------------------------------------
// Crash debugging helpers
// ----------------------------------------------------------------------------

61
include/wx/msw/timectrl.h Normal file
View File

@@ -0,0 +1,61 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/timectrl.h
// Purpose: wxTimePickerCtrl for Windows.
// Author: Vadim Zeitlin
// Created: 2011-09-22
// RCS-ID: $Id$
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwindows.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MSW_TIMECTRL_H_
#define _WX_MSW_TIMECTRL_H_
// ----------------------------------------------------------------------------
// wxTimePickerCtrl
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxTimePickerCtrl : public wxTimePickerCtrlBase
{
public:
// ctors
wxTimePickerCtrl() { }
wxTimePickerCtrl(wxWindow *parent,
wxWindowID id,
const wxDateTime& dt = wxDefaultDateTime,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxTP_DEFAULT,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxTimePickerCtrlNameStr)
{
Create(parent, id, dt, pos, size, style, validator, name);
}
bool Create(wxWindow *parent,
wxWindowID id,
const wxDateTime& dt = wxDefaultDateTime,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxTP_DEFAULT,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxTimePickerCtrlNameStr)
{
return MSWCreateDateTimePicker(parent, id, dt,
pos, size, style,
validator, name);
}
// Override MSW-specific functions used during control creation.
virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
protected:
virtual wxLocaleInfo MSWGetFormat() const;
virtual bool MSWAllowsNone() const { return false; }
virtual bool MSWOnDateTimeChange(const tagNMDATETIMECHANGE& dtch);
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxTimePickerCtrl);
};
#endif // _WX_MSW_TIMECTRL_H_

View File

@@ -867,6 +867,7 @@
#define wxUSE_STATTEXT 1 // wxStaticText
#define wxUSE_STATBMP 1 // wxStaticBitmap
#define wxUSE_TEXTCTRL 1 // wxTextCtrl
#define wxUSE_TIMEPICKCTRL 1 // wxTimePickerCtrl
#define wxUSE_TOGGLEBTN 1 // requires wxButton
#define wxUSE_TREECTRL 1 // wxTreeCtrl
#define wxUSE_TREELISTCTRL 1 // wxTreeListCtrl

View File

@@ -867,6 +867,7 @@
#define wxUSE_STATTEXT 1 // wxStaticText
#define wxUSE_STATBMP 1 // wxStaticBitmap
#define wxUSE_TEXTCTRL 1 // wxTextCtrl
#define wxUSE_TIMEPICKCTRL 1 // wxTimePickerCtrl
#define wxUSE_TOGGLEBTN 1 // requires wxButton
#define wxUSE_TREECTRL 1 // wxTreeCtrl
#define wxUSE_TREELISTCTRL 1 // wxTreeListCtrl

View File

@@ -868,6 +868,7 @@
#define wxUSE_STATTEXT 1 // wxStaticText
#define wxUSE_STATBMP 1 // wxStaticBitmap
#define wxUSE_TEXTCTRL 1 // wxTextCtrl
#define wxUSE_TIMEPICKCTRL 1 // wxTimePickerCtrl
#define wxUSE_TOGGLEBTN 1 // requires wxButton
#define wxUSE_TREECTRL 1 // wxTreeCtrl
#define wxUSE_TREELISTCTRL 1 // wxTreeListCtrl

View File

@@ -867,6 +867,7 @@
#define wxUSE_STATTEXT 1 // wxStaticText
#define wxUSE_STATBMP 1 // wxStaticBitmap
#define wxUSE_TEXTCTRL 1 // wxTextCtrl
#define wxUSE_TIMEPICKCTRL 1 // wxTimePickerCtrl
#define wxUSE_TOGGLEBTN 1 // requires wxButton
#define wxUSE_TREECTRL 1 // wxTreeCtrl
#define wxUSE_TREELISTCTRL 1 // wxTreeListCtrl

View File

@@ -863,6 +863,7 @@
#define wxUSE_STATTEXT 1 // wxStaticText
#define wxUSE_STATBMP 1 // wxStaticBitmap
#define wxUSE_TEXTCTRL 1 // wxTextCtrl
#define wxUSE_TIMEPICKCTRL 1 // wxTimePickerCtrl
#define wxUSE_TOGGLEBTN 1 // requires wxButton
#define wxUSE_TREECTRL 1 // wxTreeCtrl
#define wxUSE_TREELISTCTRL 1 // wxTreeListCtrl

88
include/wx/timectrl.h Normal file
View File

@@ -0,0 +1,88 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/timectrl.h
// Purpose: Declaration of wxTimePickerCtrl class.
// Author: Vadim Zeitlin
// Created: 2011-09-22
// RCS-ID: $Id: wxhead.h,v 1.12 2010-04-22 12:44:51 zeitlin Exp $
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TIMECTRL_H_
#define _WX_TIMECTRL_H_
#include "wx/defs.h"
#if wxUSE_TIMEPICKCTRL
#include "wx/datetimectrl.h"
#define wxTimePickerCtrlNameStr wxS("timectrl")
// No special styles are currently defined for this control but still define a
// symbolic constant for the default style for consistency.
enum
{
wxTP_DEFAULT = 0
};
// ----------------------------------------------------------------------------
// wxTimePickerCtrl: Allow the user to enter the time.
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxTimePickerCtrlBase : public wxDateTimePickerCtrl
{
public:
/*
The derived classes should implement ctor and Create() method with the
following signature:
bool Create(wxWindow *parent,
wxWindowID id,
const wxDateTime& dt = wxDefaultDateTime,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxTP_DEFAULT,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxTimePickerCtrlNameStr);
*/
/*
We also inherit Set/GetValue() methods from the base class which define
our public API. Notice that the date portion of the date passed as
input is ignored and for the result date it's always today, but only
the time part of wxDateTime objects is really significant here.
*/
};
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
#include "wx/msw/timectrl.h"
#define wxHAS_NATIVE_TIMEPICKERCTRL
#else
#include "wx/generic/timectrl.h"
class WXDLLIMPEXP_ADV wxTimePickerCtrl : public wxTimePickerCtrlGeneric
{
public:
wxTimePickerCtrl() { }
wxTimePickerCtrl(wxWindow *parent,
wxWindowID id,
const wxDateTime& date = wxDefaultDateTime,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxTP_DEFAULT,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxTimePickerCtrlNameStr)
: wxTimePickerCtrlGeneric(parent, id, date, pos, size, style, validator, name)
{
}
private:
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxTimePickerCtrl);
};
#endif
#endif // wxUSE_TIMEPICKCTRL
#endif // _WX_TIMECTRL_H_

View File

@@ -866,6 +866,7 @@
#define wxUSE_STATTEXT 1 // wxStaticText
#define wxUSE_STATBMP 1 // wxStaticBitmap
#define wxUSE_TEXTCTRL 1 // wxTextCtrl
#define wxUSE_TIMEPICKCTRL 1 // wxTimePickerCtrl
#define wxUSE_TOGGLEBTN 1 // requires wxButton
#define wxUSE_TREECTRL 1 // wxTreeCtrl
#define wxUSE_TREELISTCTRL 1 // wxTreeListCtrl