From 61581d48be4b9b8818d5d743dc12c5e1ca2afd0e Mon Sep 17 00:00:00 2001 From: Michael Wetherell Date: Tue, 24 May 2005 21:50:06 +0000 Subject: [PATCH] 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 --- include/wx/generic/calctrl.h | 8 +- src/generic/calctrl.cpp | 145 ++++++++++++++--------------------- 2 files changed, 62 insertions(+), 91 deletions(-) diff --git a/include/wx/generic/calctrl.h b/include/wx/generic/calctrl.h index cb10d1019b..0ac0091442 100644 --- a/include/wx/generic/calctrl.h +++ b/include/wx/generic/calctrl.h @@ -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; diff --git a/src/generic/calctrl.cpp b/src/generic/calctrl.cpp index 5f701be1ca..92fb7051e9 100644 --- a/src/generic/calctrl.cpp +++ b/src/generic/calctrl.cpp @@ -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 // ---------------------------------------------------------------------------- -- 2.45.2