Provide native implementation of wx{Date,Time}PickerCtrl for wxOSX/Cocoa.

Use NSDatePicker to implement both of these controls. Almost all of
wxDatePickerCtrl styles are not supported in the native version but the basic
functionality does work and looks much better than the generic version (which
is still available as wxDatePickerCtrlGeneric if needed) under Mac.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70071 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-12-20 21:27:14 +00:00
parent 36d07f78e4
commit fceac6bbfe
17 changed files with 732 additions and 23 deletions

View File

@@ -0,0 +1,71 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/osx/core/private/datetime.h
// Purpose:
// Author: Vadim Zeitlin
// Created: 2011-12-19
// 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_OSX_CORE_PRIVATE_DATETIMECTRL_H_
#define _WX_OSX_CORE_PRIVATE_DATETIMECTRL_H_
#if wxUSE_DATEPICKCTRL
#include "wx/osx/private.h"
#include "wx/datetime.h"
enum wxDateTimeWidgetKind
{
wxDateTimeWidget_YearMonthDay,
wxDateTimeWidget_HourMinuteSecond
};
// ----------------------------------------------------------------------------
// wxDateTimeWidgetImpl: peer class for wxDateTimePickerCtrl.
// ----------------------------------------------------------------------------
class wxDateTimeWidgetImpl
#if wxOSX_USE_COCOA
: public wxWidgetCocoaImpl
#elif wxOSX_USE_CARBON
: public wxMacControl
#else
#error "Unsupported platform"
#endif
{
public:
static wxDateTimeWidgetImpl*
CreateDateTimePicker(wxDateTimePickerCtrl* wxpeer,
const wxDateTime& dt,
const wxPoint& pos,
const wxSize& size,
long style,
wxDateTimeWidgetKind kind);
virtual void SetDateTime(const wxDateTime& dt) = 0;
virtual wxDateTime GetDateTime() const = 0;
virtual void SetDateRange(const wxDateTime& dt1, const wxDateTime& dt2) = 0;
virtual bool GetDateRange(wxDateTime* dt1, wxDateTime* dt2) = 0;
virtual ~wxDateTimeWidgetImpl() { }
protected:
#if wxOSX_USE_COCOA
wxDateTimeWidgetImpl(wxDateTimePickerCtrl* wxpeer, WXWidget view)
: wxWidgetCocoaImpl(wxpeer, view)
{
}
#elif wxOSX_USE_CARBON
// There is no Carbon implementation of this control yet so we don't need
// any ctor for it yet but it should be added here if Carbon version is
// written later.
#endif
};
#endif // wxUSE_DATEPICKCTRL
#endif // _WX_OSX_CORE_PRIVATE_DATETIMECTRL_H_

55
include/wx/osx/datectrl.h Normal file
View File

@@ -0,0 +1,55 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/osx/datectrl.h
// Purpose: Declaration of wxOSX-specific wxDatePickerCtrl class.
// Author: Vadim Zeitlin
// Created: 2011-12-18
// 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_OSX_DATECTRL_H_
#define _WX_OSX_DATECTRL_H_
// ----------------------------------------------------------------------------
// wxDatePickerCtrl
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxDatePickerCtrl : public wxDatePickerCtrlBase
{
public:
// Constructors.
wxDatePickerCtrl() { }
wxDatePickerCtrl(wxWindow *parent,
wxWindowID id,
const wxDateTime& dt = wxDefaultDateTime,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxDP_DEFAULT | wxDP_SHOWCENTURY,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxDatePickerCtrlNameStr)
{
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 = wxDP_DEFAULT | wxDP_SHOWCENTURY,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxDatePickerCtrlNameStr);
// Implement the base class pure virtuals.
virtual void SetRange(const wxDateTime& dt1, const wxDateTime& dt2);
virtual bool GetRange(wxDateTime *dt1, wxDateTime *dt2) const;
virtual void OSXGenerateEvent(const wxDateTime& dt);
private:
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDatePickerCtrl);
};
#endif // _WX_OSX_DATECTRL_H_

View File

@@ -0,0 +1,34 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/osx/datetimectrl.h
// Purpose: Declaration of wxOSX-specific wxDateTimePickerCtrl class.
// Author: Vadim Zeitlin
// Created: 2011-12-18
// 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_OSX_DATETIMECTRL_H_
#define _WX_OSX_DATETIMECTRL_H_
class wxDateTimeWidgetImpl;
// ----------------------------------------------------------------------------
// wxDateTimePickerCtrl
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxDateTimePickerCtrl : public wxDateTimePickerCtrlBase
{
public:
// Implement the base class pure virtuals.
virtual void SetValue(const wxDateTime& dt);
virtual wxDateTime GetValue() const;
// Implementation only.
virtual void OSXGenerateEvent(const wxDateTime& dt) = 0;
protected:
wxDateTimeWidgetImpl* GetDateTimePeer() const;
};
#endif // _WX_OSX_DATETIMECTRL_H_

51
include/wx/osx/timectrl.h Normal file
View File

@@ -0,0 +1,51 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/osx/timectrl.h
// Purpose: Declaration of wxOSX-specific wxTimePickerCtrl class.
// Author: Vadim Zeitlin
// Created: 2011-12-18
// 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_OSX_TIMECTRL_H_
#define _WX_OSX_TIMECTRL_H_
// ----------------------------------------------------------------------------
// wxTimePickerCtrl
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxTimePickerCtrl : public wxTimePickerCtrlBase
{
public:
// Constructors.
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);
virtual void OSXGenerateEvent(const wxDateTime& dt);
private:
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxTimePickerCtrl);
};
#endif // _WX_OSX_TIMECTRL_H_