1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/calctrl.cpp
3 // Purpose: implementation of the wxGtkCalendarCtrl
4 // Author: Marcin Wojdyr
6 // Copyright: (c) 2008 Marcin Wojdyr
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #include "wx/wxprec.h"
19 #if wxUSE_CALENDARCTRL
21 #include "wx/gtk/private.h"
22 #include "wx/calctrl.h"
23 #include "wx/gtk/calctrl.h"
28 static void gtk_day_selected_callback(GtkWidget
*WXUNUSED(widget
),
29 wxGtkCalendarCtrl
*cal
)
31 cal
->GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED
);
32 cal
->GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED
);
35 static void gtk_day_selected_double_click_callback(GtkWidget
*WXUNUSED(widget
),
36 wxGtkCalendarCtrl
*cal
)
38 cal
->GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED
);
41 static void gtk_month_changed_callback(GtkWidget
*WXUNUSED(widget
),
42 wxGtkCalendarCtrl
*cal
)
44 cal
->GenerateEvent(wxEVT_CALENDAR_PAGE_CHANGED
);
47 // callbacks that send deprecated events
49 static void gtk_prev_month_callback(GtkWidget
*WXUNUSED(widget
),
50 wxGtkCalendarCtrl
*cal
)
52 cal
->GenerateEvent(wxEVT_CALENDAR_MONTH_CHANGED
);
55 static void gtk_prev_year_callback(GtkWidget
*WXUNUSED(widget
),
56 wxGtkCalendarCtrl
*cal
)
58 cal
->GenerateEvent(wxEVT_CALENDAR_YEAR_CHANGED
);
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
68 bool wxGtkCalendarCtrl::Create(wxWindow
*parent
,
70 const wxDateTime
& date
,
76 if (!PreCreation(parent
, pos
, size
) ||
77 !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
79 wxFAIL_MSG(wxT("wxGtkCalendarCtrl creation failed"));
83 m_widget
= gtk_calendar_new();
84 SetDate(date
.IsValid() ? date
: wxDateTime::Today());
86 if (style
& wxCAL_NO_MONTH_CHANGE
)
87 g_object_set (G_OBJECT (m_widget
), "no-month-change", true, NULL
);
89 g_signal_connect_after(m_widget
, "day-selected",
90 G_CALLBACK (gtk_day_selected_callback
),
92 g_signal_connect_after(m_widget
, "day-selected-double-click",
93 G_CALLBACK (gtk_day_selected_double_click_callback
),
95 g_signal_connect_after(m_widget
, "month-changed",
96 G_CALLBACK (gtk_month_changed_callback
),
99 // connect callbacks that send deprecated events
100 g_signal_connect_after(m_widget
, "prev-month",
101 G_CALLBACK (gtk_prev_month_callback
),
103 g_signal_connect_after(m_widget
, "next-month",
104 G_CALLBACK (gtk_prev_month_callback
),
106 g_signal_connect_after(m_widget
, "prev-year",
107 G_CALLBACK (gtk_prev_year_callback
),
109 g_signal_connect_after(m_widget
, "next-year",
110 G_CALLBACK (gtk_prev_year_callback
),
113 m_parent
->DoAddChild(this);
120 bool wxGtkCalendarCtrl::EnableMonthChange(bool enable
)
122 if ( !wxCalendarCtrlBase::EnableMonthChange(enable
) )
125 g_object_set (G_OBJECT (m_widget
), "no-month-change", !enable
, NULL
);
130 bool wxGtkCalendarCtrl::SetDate(const wxDateTime
& date
)
132 int year
= date
.GetYear();
133 int month
= date
.GetMonth();
134 int day
= date
.GetDay();
135 gtk_calendar_select_month(GTK_CALENDAR(m_widget
), month
, year
);
136 gtk_calendar_select_day(GTK_CALENDAR(m_widget
), day
);
140 wxDateTime
wxGtkCalendarCtrl::GetDate() const
142 guint year
, month
, day
;
143 gtk_calendar_get_date(GTK_CALENDAR(m_widget
), &year
, &month
, &day
);
144 return wxDateTime(day
, (wxDateTime::Month
) month
, year
);
147 void wxGtkCalendarCtrl::Mark(size_t day
, bool mark
)
150 gtk_calendar_mark_day(GTK_CALENDAR(m_widget
), day
);
152 gtk_calendar_unmark_day(GTK_CALENDAR(m_widget
), day
);
155 IMPLEMENT_DYNAMIC_CLASS(wxGtkCalendarCtrl
, wxControl
)
158 #endif // wxUSE_CALENDARCTRL