X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/628e155d8c70da0f962289cf1e1dea3699255707..565804f2b9ec017360122cda08181d287919160b:/src/generic/calctrlg.cpp diff --git a/src/generic/calctrlg.cpp b/src/generic/calctrlg.cpp index 9ac23cf05a..ec7a53158e 100644 --- a/src/generic/calctrlg.cpp +++ b/src/generic/calctrlg.cpp @@ -211,7 +211,7 @@ void wxGenericCalendarCtrl::InitColours() m_colHighlightFg = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); m_colHighlightBg = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); m_colBackground = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); - m_colSorrounding = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT); + m_colSurrounding = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT); m_colHolidayFg = *wxRED; // don't set m_colHolidayBg - by default, same as our bg colour @@ -249,7 +249,6 @@ bool wxGenericCalendarCtrl::Create(wxWindow *parent, m_staticYear = new wxStaticText(GetParent(), wxID_ANY, m_date.Format(_T("%Y")), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); - CreateMonthComboBox(); m_staticMonth = new wxStaticText(GetParent(), wxID_ANY, m_date.Format(_T("%B")), wxDefaultPosition, wxDefaultSize, @@ -339,6 +338,9 @@ void wxGenericCalendarCtrl::CreateYearSpinCtrl() wxDefaultSize, wxSP_ARROW_KEYS | wxCLIP_SIBLINGS, -4300, 10000, GetDate().GetYear()); +#ifdef __WXMAC__ + m_spinYear->SetSize( 90, -1 ); +#endif m_spinYear->Connect(m_spinYear->GetId(), wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(wxGenericCalendarCtrl::OnYearTextChange), @@ -560,27 +562,10 @@ void wxGenericCalendarCtrl::ChangeDay(const wxDateTime& date) void wxGenericCalendarCtrl::SetDateAndNotify(const wxDateTime& date) { - wxDateTime::Tm tm1 = m_date.GetTm(), - tm2 = date.GetTm(); - - const bool pageChanged = tm1.year != tm2.year || tm1.mon != tm2.mon; - - if ( !pageChanged && tm1.mday == tm2.mday ) - return; - - if ( SetDate(date) ) + const wxDateTime dateOld = GetDate(); + if ( date != dateOld && SetDate(date) ) { - GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED); - if ( !pageChanged ) - GenerateEvent(wxEVT_CALENDAR_PAGE_CHANGED); - - // send also one of the deprecated events - if ( tm1.year != tm2.year ) - GenerateEvent(wxEVT_CALENDAR_YEAR_CHANGED); - else if ( tm1.mon != tm2.mon ) - GenerateEvent(wxEVT_CALENDAR_MONTH_CHANGED); - else - GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED); + GenerateAllChangeEvents(dateOld); } } @@ -639,6 +624,17 @@ bool wxGenericCalendarCtrl::SetDateRange(const wxDateTime& lowerdate /* = wxDefa return retval; } +bool wxGenericCalendarCtrl::GetDateRange(wxDateTime *lowerdate, + wxDateTime *upperdate) const +{ + if ( lowerdate ) + *lowerdate = m_lowdate; + if ( upperdate ) + *upperdate = m_highdate; + + return m_lowdate.IsValid() || m_highdate.IsValid(); +} + // ---------------------------------------------------------------------------- // date helpers // ---------------------------------------------------------------------------- @@ -783,51 +779,44 @@ size_t wxGenericCalendarCtrl::GetWeek(const wxDateTime& date) const // the same space // the constants used for the layout -#define VERT_MARGIN 5 // distance between combo and calendar -#ifdef __WXMAC__ +#define VERT_MARGIN 5 // distance between combo and calendar #define HORZ_MARGIN 5 // spin -#else -#define HORZ_MARGIN 15 // spin -#endif + wxSize wxGenericCalendarCtrl::DoGetBestSize() const { // calc the size of the calendar - wx_const_cast(wxGenericCalendarCtrl *, this)->RecalcGeometry(); + const_cast(this)->RecalcGeometry(); wxCoord width = 7*m_widthCol, - height = 7*m_heightRow + m_rowOffset + VERT_MARGIN; + height = 7*m_heightRow + m_rowOffset; if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION) ) { - // the combobox doesn't report its height correctly (it returns the - // height including the drop down list) so don't use it - height += m_spinYear->GetBestSize().y; + const wxSize bestSizeCombo = m_comboMonth->GetBestSize(); + height += wxMax(bestSizeCombo.y, m_spinYear->GetBestSize().y) + + VERT_MARGIN; +#ifdef __WXMAC__ + // the spin control get clipped otherwise + width += 10; +#endif - wxCoord w2 = m_comboMonth->GetBestSize().x + HORZ_MARGIN + GetCharWidth()*6; - if (width < w2) + wxCoord w2 = bestSizeCombo.x + HORZ_MARGIN + GetCharWidth()*6; + if ( width < w2 ) width = w2; } + wxSize best(width, height); if ( !HasFlag(wxBORDER_NONE) ) { - // the border would clip the last line otherwise - height += 6; - width += 4; + best += GetWindowBorderSize(); } - wxSize best(width, height); CacheBestSize(best); + return best; } -void wxGenericCalendarCtrl::DoSetSize(int x, int y, - int width, int height, - int sizeFlags) -{ - wxControl::DoSetSize(x, y, width, height, sizeFlags); -} - void wxGenericCalendarCtrl::DoMoveWindow(int x, int y, int width, int height) { int yDiff; @@ -838,26 +827,21 @@ void wxGenericCalendarCtrl::DoMoveWindow(int x, int y, int width, int height) wxSize sizeStatic = m_staticMonth->GetSize(); wxSize sizeSpin = m_spinYear->GetSize(); - // wxMSW sometimes reports the wrong combo height, - // so on this platform we'll use the spin control - // height instead. -#ifdef __WXMSW__ - int maxHeight = sizeSpin.y; - int requiredSpinHeight = -1; + int maxHeight = wxMax(sizeSpin.y, sizeCombo.y); + int dy = (maxHeight - sizeStatic.y) / 2; +#ifdef __WXMAC__ + m_comboMonth->Move(x, y + (maxHeight - sizeCombo.y)/2 + 2); // FIXME, something is reporting the wrong size.. #else - int maxHeight = sizeCombo.y; - int requiredSpinHeight = sizeCombo.y; + m_comboMonth->Move(x, y + (maxHeight - sizeCombo.y)/2); #endif - int dy = (maxHeight - sizeStatic.y) / 2; - m_comboMonth->Move(x, y); m_staticMonth->SetSize(x, y + dy, sizeCombo.x, -1, sizeStatic.y); int xDiff = sizeCombo.x + HORZ_MARGIN; - m_spinYear->SetSize(x + xDiff, y, width - xDiff, requiredSpinHeight); + m_spinYear->SetSize(x + xDiff, y + (maxHeight - sizeSpin.y)/2, width - xDiff, maxHeight); m_staticYear->SetSize(x + xDiff, y + dy, width - xDiff, sizeStatic.y); - yDiff = wxMax(sizeSpin.y, maxHeight) + VERT_MARGIN; + yDiff = maxHeight + VERT_MARGIN; } else // no controls on the top { @@ -867,33 +851,21 @@ void wxGenericCalendarCtrl::DoMoveWindow(int x, int y, int width, int height) wxControl::DoMoveWindow(x, y + yDiff, width, height - yDiff); } -void wxGenericCalendarCtrl::DoGetPosition(int *x, int *y) const -{ - wxControl::DoGetPosition(x, y); -#ifndef __WXPM__ - if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION) && GetMonthControl() ) - { - // our real top corner is not in this position - if ( y ) - { - *y -= GetMonthControl()->GetSize().y + VERT_MARGIN; - } - } -#endif -} - void wxGenericCalendarCtrl::DoGetSize(int *width, int *height) const { - wxControl::DoGetSize(width, height); -#ifndef __WXPM__ - if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION) ) +#ifdef __WXMAC__ + wxControl::DoGetSize( width, height ); + + if ( !HasFlag(wxCAL_SEQUENTIAL_MONTH_SELECTION) && m_staticMonth && height ) { - // our real height is bigger - if ( height && GetMonthControl()) - { - *height += GetMonthControl()->GetSize().y + VERT_MARGIN; - } + wxSize sizeCombo = m_comboMonth->GetEffectiveMinSize(); + wxSize sizeSpin = m_spinYear->GetSize(); + + int maxHeight = wxMax(sizeSpin.y, sizeCombo.y); + *height += maxHeight + VERT_MARGIN; } +#else + wxControl::DoGetSize( width, height ); #endif } @@ -1098,9 +1070,8 @@ void wxGenericCalendarCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) if ( date.GetMonth() != m_date.GetMonth() || !IsDateInRange(date) ) { - // surrounding week or out-of-range - // draw "disabled" - dc.SetTextForeground(m_colSorrounding); + // draw the days of adjacent months in different colour + dc.SetTextForeground(m_colSurrounding); changedColours = true; } else @@ -1475,6 +1446,10 @@ void wxGenericCalendarCtrl::OnClick(wxMouseEvent& event) ChangeDay(date); GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED); + + // we know that the month/year never change when the user + // clicks on the control so there is no need to call + // GenerateAllChangeEvents() here, we know which event to send GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED); } break; @@ -1502,6 +1477,10 @@ void wxGenericCalendarCtrl::OnClick(wxMouseEvent& event) event.Skip(); break; } + + // as we don't (always) skip the message, we're not going to receive the + // focus on click by default if we don't do it ourselves + SetFocus(); } wxCalendarHitTestResult wxGenericCalendarCtrl::HitTest(const wxPoint& pos, @@ -1781,45 +1760,6 @@ void wxGenericCalendarCtrl::OnChar(wxKeyEvent& event) // holidays handling // ---------------------------------------------------------------------------- -void wxGenericCalendarCtrl::EnableHolidayDisplay(bool display) -{ - long style = GetWindowStyle(); - if ( display ) - style |= wxCAL_SHOW_HOLIDAYS; - else - style &= ~wxCAL_SHOW_HOLIDAYS; - - SetWindowStyle(style); - - if ( display ) - SetHolidayAttrs(); - else - ResetHolidayAttrs(); - - Refresh(); -} - -void wxGenericCalendarCtrl::SetHolidayAttrs() -{ - if ( GetWindowStyle() & wxCAL_SHOW_HOLIDAYS ) - { - ResetHolidayAttrs(); - - wxDateTime::Tm tm = m_date.GetTm(); - wxDateTime dtStart(1, tm.mon, tm.year), - dtEnd = dtStart.GetLastMonthDay(); - - wxDateTimeArray hol; - wxDateTimeHolidayAuthority::GetHolidaysInRange(dtStart, dtEnd, hol); - - size_t count = hol.GetCount(); - for ( size_t n = 0; n < count; n++ ) - { - SetHoliday(hol[n].GetDay()); - } - } -} - void wxGenericCalendarCtrl::SetHoliday(size_t day) { wxCHECK_RET( day > 0 && day < 32, _T("invalid day in SetHoliday") );