Have the calendar control handle events from it's combo and spin controls

using Connect().


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34326 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Michael Wetherell 2005-05-24 21:50:06 +00:00
parent 6c75a4cf0f
commit 61581d48be
2 changed files with 62 additions and 91 deletions

View File

@ -31,9 +31,6 @@ class WXDLLEXPORT wxSpinCtrl;
class WXDLLIMPEXP_ADV wxCalendarCtrl : public wxControl
{
friend class wxMonthComboBox;
friend class wxYearSpinCtrl;
public:
// construction
wxCalendarCtrl() { Init(); }
@ -179,6 +176,7 @@ private:
void OnChar(wxKeyEvent& event);
void OnMonthChange(wxCommandEvent& event);
void OnYearChange(wxCommandEvent& event);
void OnYearTextChange(wxCommandEvent& event);
// override some base class virtuals
virtual wxSize DoGetBestSize() const;
@ -248,6 +246,10 @@ private:
// show the correct controls
void ShowCurrentControls();
// create the month combo and year spin controls
void CreateMonthComboBox();
void CreateYearSpinCtrl();
public:
// get the currently shown control for month/year
wxControl *GetMonthControl() const;

View File

@ -52,43 +52,6 @@
#define DEBUG_PAINT 0
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
class wxMonthComboBox : public wxComboBox
{
public:
wxMonthComboBox(wxCalendarCtrl *cal);
void OnMonthChange(wxCommandEvent& event) { m_cal->OnMonthChange(event); }
private:
wxCalendarCtrl *m_cal;
DECLARE_EVENT_TABLE()
DECLARE_NO_COPY_CLASS(wxMonthComboBox)
};
class wxYearSpinCtrl : public wxSpinCtrl
{
public:
wxYearSpinCtrl(wxCalendarCtrl *cal);
void OnYearTextChange(wxCommandEvent& event)
{
m_cal->SetUserChangedYear();
m_cal->OnYearChange(event);
}
void OnYearChange(wxSpinEvent& event) { m_cal->OnYearChange(event); }
private:
wxCalendarCtrl *m_cal;
DECLARE_EVENT_TABLE()
DECLARE_NO_COPY_CLASS(wxYearSpinCtrl)
};
// ----------------------------------------------------------------------------
// wxWin macros
// ----------------------------------------------------------------------------
@ -102,15 +65,6 @@ BEGIN_EVENT_TABLE(wxCalendarCtrl, wxControl)
EVT_LEFT_DCLICK(wxCalendarCtrl::OnDClick)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxMonthComboBox, wxComboBox)
EVT_COMBOBOX(wxID_ANY, wxMonthComboBox::OnMonthChange)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxYearSpinCtrl, wxSpinCtrl)
EVT_TEXT(wxID_ANY, wxYearSpinCtrl::OnYearTextChange)
EVT_SPINCTRL(wxID_ANY, wxYearSpinCtrl::OnYearChange)
END_EVENT_TABLE()
#if wxUSE_EXTENDED_RTTI
WX_DEFINE_FLAGS( wxCalendarCtrlStyle )
@ -185,46 +139,6 @@ DEFINE_EVENT_TYPE(wxEVT_CALENDAR_WEEKDAY_CLICKED)
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxMonthComboBox and wxYearSpinCtrl
// ----------------------------------------------------------------------------
wxMonthComboBox::wxMonthComboBox(wxCalendarCtrl *cal)
: wxComboBox(cal->GetParent(), wxID_ANY,
wxEmptyString,
wxDefaultPosition,
wxDefaultSize,
0, NULL,
wxCB_READONLY | wxCLIP_SIBLINGS)
{
m_cal = cal;
wxDateTime::Month m;
for ( m = wxDateTime::Jan; m < wxDateTime::Inv_Month; wxNextMonth(m) )
{
Append(wxDateTime::GetMonthName(m));
}
SetSelection(m_cal->GetDate().GetMonth());
SetSize(wxDefaultCoord,
wxDefaultCoord,
wxDefaultCoord,
wxDefaultCoord,
wxSIZE_AUTO_WIDTH|wxSIZE_AUTO_HEIGHT);
}
wxYearSpinCtrl::wxYearSpinCtrl(wxCalendarCtrl *cal)
: wxSpinCtrl(cal->GetParent(), wxID_ANY,
cal->GetDate().Format(_T("%Y")),
wxDefaultPosition,
wxDefaultSize,
wxSP_ARROW_KEYS | wxCLIP_SIBLINGS,
-4300, 10000, cal->GetDate().GetYear())
{
m_cal = cal;
}
// ----------------------------------------------------------------------------
// wxCalendarCtrl
// ----------------------------------------------------------------------------
@ -300,12 +214,12 @@ bool wxCalendarCtrl::Create(wxWindow *parent,
if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION) )
{
m_spinYear = new wxYearSpinCtrl(this);
CreateYearSpinCtrl();
m_staticYear = new wxStaticText(GetParent(), wxID_ANY, m_date.Format(_T("%Y")),
wxDefaultPosition, wxDefaultSize,
wxALIGN_CENTRE);
m_comboMonth = new wxMonthComboBox(this);
CreateMonthComboBox();
m_staticMonth = new wxStaticText(GetParent(), wxID_ANY, m_date.Format(_T("%B")),
wxDefaultPosition, wxDefaultSize,
wxALIGN_CENTRE);
@ -336,6 +250,55 @@ wxCalendarCtrl::~wxCalendarCtrl()
}
}
// ----------------------------------------------------------------------------
// Create the wxComboBox and wxSpinCtrl
// ----------------------------------------------------------------------------
void wxCalendarCtrl::CreateMonthComboBox()
{
m_comboMonth = new wxComboBox(GetParent(), wxID_ANY,
wxEmptyString,
wxDefaultPosition,
wxDefaultSize,
0, NULL,
wxCB_READONLY | wxCLIP_SIBLINGS);
wxDateTime::Month m;
for ( m = wxDateTime::Jan; m < wxDateTime::Inv_Month; wxNextMonth(m) )
{
m_comboMonth->Append(wxDateTime::GetMonthName(m));
}
m_comboMonth->SetSelection(GetDate().GetMonth());
m_comboMonth->SetSize(wxDefaultCoord,
wxDefaultCoord,
wxDefaultCoord,
wxDefaultCoord,
wxSIZE_AUTO_WIDTH|wxSIZE_AUTO_HEIGHT);
m_comboMonth->Connect(wxEVT_COMMAND_COMBOBOX_SELECTED,
wxCommandEventHandler(wxCalendarCtrl::OnMonthChange),
NULL, this);
}
void wxCalendarCtrl::CreateYearSpinCtrl()
{
m_spinYear = new wxSpinCtrl(GetParent(), wxID_ANY,
GetDate().Format(_T("%Y")),
wxDefaultPosition,
wxDefaultSize,
wxSP_ARROW_KEYS | wxCLIP_SIBLINGS,
-4300, 10000, GetDate().GetYear());
m_spinYear->Connect(wxEVT_COMMAND_TEXT_UPDATED,
wxCommandEventHandler(wxCalendarCtrl::OnYearTextChange),
NULL, this);
m_spinYear->Connect(wxEVT_COMMAND_SPINCTRL_UPDATED,
wxCommandEventHandler(wxCalendarCtrl::OnYearChange),
NULL, this);
}
// ----------------------------------------------------------------------------
// forward wxWin functions to subcontrols
// ----------------------------------------------------------------------------
@ -1622,6 +1585,12 @@ void wxCalendarCtrl::OnYearChange(wxCommandEvent& event)
}
}
void wxCalendarCtrl::OnYearTextChange(wxCommandEvent& event)
{
SetUserChangedYear();
OnYearChange(event);
}
// ----------------------------------------------------------------------------
// keyboard interface
// ----------------------------------------------------------------------------