X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8ea26eedce3a50c4021bcf8b971e432d93684de2..f7f8a13c0466725ffffc0cbe9f10da729c3423dd:/src/gtk/calctrl.cpp diff --git a/src/gtk/calctrl.cpp b/src/gtk/calctrl.cpp index 09104839e0..aa325ae0b6 100644 --- a/src/gtk/calctrl.cpp +++ b/src/gtk/calctrl.cpp @@ -2,7 +2,6 @@ // Name: src/gtk/calctrl.cpp // Purpose: implementation of the wxGtkCalendarCtrl // Author: Marcin Wojdyr -// RCS-ID: $Id$ // Copyright: (c) 2008 Marcin Wojdyr // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -13,42 +12,33 @@ #pragma hdrstop #endif +#if wxUSE_CALENDARCTRL + #ifndef WX_PRECOMP #endif //WX_PRECOMP -#if wxUSE_CALENDARCTRL - -#include "wx/gtk/private.h" #include "wx/calctrl.h" -#include "wx/gtk/calctrl.h" +#include extern "C" { static void gtk_day_selected_callback(GtkWidget *WXUNUSED(widget), wxGtkCalendarCtrl *cal) { - wxDateTime date = cal->GetDate(); - if (cal->m_selectedDate == date) - return; - - cal->m_selectedDate = date; - - cal->GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED); - // send deprecated event - cal->GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED); + cal->GTKGenerateEvent(wxEVT_CALENDAR_SEL_CHANGED); } static void gtk_day_selected_double_click_callback(GtkWidget *WXUNUSED(widget), wxGtkCalendarCtrl *cal) { - cal->GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED); + cal->GTKGenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED); } static void gtk_month_changed_callback(GtkWidget *WXUNUSED(widget), wxGtkCalendarCtrl *cal) { - cal->GenerateEvent(wxEVT_CALENDAR_PAGE_CHANGED); + cal->GTKGenerateEvent(wxEVT_CALENDAR_PAGE_CHANGED); } // callbacks that send deprecated events @@ -56,13 +46,13 @@ static void gtk_month_changed_callback(GtkWidget *WXUNUSED(widget), static void gtk_prev_month_callback(GtkWidget *WXUNUSED(widget), wxGtkCalendarCtrl *cal) { - cal->GenerateEvent(wxEVT_CALENDAR_MONTH_CHANGED); + cal->GTKGenerateEvent(wxEVT_CALENDAR_MONTH_CHANGED); } static void gtk_prev_year_callback(GtkWidget *WXUNUSED(widget), wxGtkCalendarCtrl *cal) { - cal->GenerateEvent(wxEVT_CALENDAR_YEAR_CHANGED); + cal->GTKGenerateEvent(wxEVT_CALENDAR_YEAR_CHANGED); } } @@ -127,6 +117,74 @@ bool wxGtkCalendarCtrl::Create(wxWindow *parent, return true; } +void wxGtkCalendarCtrl::GTKGenerateEvent(wxEventType type) +{ + // First check if the new date is in the specified range. + wxDateTime dt = GetDate(); + if ( !IsInValidRange(dt) ) + { + if ( m_validStart.IsValid() && dt < m_validStart ) + dt = m_validStart; + else + dt = m_validEnd; + + SetDate(dt); + + return; + } + + if ( type == wxEVT_CALENDAR_SEL_CHANGED ) + { + // Don't generate this event if the new date is the same as the old + // one. + if ( m_selectedDate == dt ) + return; + + m_selectedDate = dt; + + GenerateEvent(type); + + // Also send the deprecated event together with the new one. + GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED); + } + else + { + GenerateEvent(type); + } +} + +bool wxGtkCalendarCtrl::IsInValidRange(const wxDateTime& dt) const +{ + return (!m_validStart.IsValid() || m_validStart <= dt) && + (!m_validEnd.IsValid() || dt <= m_validEnd); +} + +bool +wxGtkCalendarCtrl::SetDateRange(const wxDateTime& lowerdate, + const wxDateTime& upperdate) +{ + if ( lowerdate.IsValid() && upperdate.IsValid() && lowerdate >= upperdate ) + return false; + + m_validStart = lowerdate; + m_validEnd = upperdate; + + return true; +} + +bool +wxGtkCalendarCtrl::GetDateRange(wxDateTime *lowerdate, + wxDateTime *upperdate) const +{ + if ( lowerdate ) + *lowerdate = m_validStart; + if ( upperdate ) + *upperdate = m_validEnd; + + return m_validStart.IsValid() || m_validEnd.IsValid(); +} + + bool wxGtkCalendarCtrl::EnableMonthChange(bool enable) { if ( !wxCalendarCtrlBase::EnableMonthChange(enable) ) @@ -140,6 +198,9 @@ bool wxGtkCalendarCtrl::EnableMonthChange(bool enable) bool wxGtkCalendarCtrl::SetDate(const wxDateTime& date) { + if ( date.IsValid() && !IsInValidRange(date) ) + return false; + g_signal_handlers_block_by_func(m_widget, (gpointer) gtk_day_selected_callback, this); g_signal_handlers_block_by_func(m_widget,