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 wxDateTime date
= cal
->GetDate();
32 if (cal
->m_selectedDate
== date
)
35 cal
->m_selectedDate
= date
;
37 cal
->GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED
);
38 // send deprecated event
39 cal
->GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED
);
42 static void gtk_day_selected_double_click_callback(GtkWidget
*WXUNUSED(widget
),
43 wxGtkCalendarCtrl
*cal
)
45 cal
->GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED
);
48 static void gtk_month_changed_callback(GtkWidget
*WXUNUSED(widget
),
49 wxGtkCalendarCtrl
*cal
)
51 cal
->GenerateEvent(wxEVT_CALENDAR_PAGE_CHANGED
);
54 // callbacks that send deprecated events
56 static void gtk_prev_month_callback(GtkWidget
*WXUNUSED(widget
),
57 wxGtkCalendarCtrl
*cal
)
59 cal
->GenerateEvent(wxEVT_CALENDAR_MONTH_CHANGED
);
62 static void gtk_prev_year_callback(GtkWidget
*WXUNUSED(widget
),
63 wxGtkCalendarCtrl
*cal
)
65 cal
->GenerateEvent(wxEVT_CALENDAR_YEAR_CHANGED
);
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
75 bool wxGtkCalendarCtrl::Create(wxWindow
*parent
,
77 const wxDateTime
& date
,
83 if (!PreCreation(parent
, pos
, size
) ||
84 !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
86 wxFAIL_MSG(wxT("wxGtkCalendarCtrl creation failed"));
90 m_widget
= gtk_calendar_new();
91 SetDate(date
.IsValid() ? date
: wxDateTime::Today());
93 if (style
& wxCAL_NO_MONTH_CHANGE
)
94 g_object_set (G_OBJECT (m_widget
), "no-month-change", true, NULL
);
95 if (style
& wxCAL_SHOW_WEEK_NUMBERS
)
96 g_object_set (G_OBJECT (m_widget
), "show-week-numbers", true, NULL
);
98 g_signal_connect_after(m_widget
, "day-selected",
99 G_CALLBACK (gtk_day_selected_callback
),
101 g_signal_connect_after(m_widget
, "day-selected-double-click",
102 G_CALLBACK (gtk_day_selected_double_click_callback
),
104 g_signal_connect_after(m_widget
, "month-changed",
105 G_CALLBACK (gtk_month_changed_callback
),
108 // connect callbacks that send deprecated events
109 g_signal_connect_after(m_widget
, "prev-month",
110 G_CALLBACK (gtk_prev_month_callback
),
112 g_signal_connect_after(m_widget
, "next-month",
113 G_CALLBACK (gtk_prev_month_callback
),
115 g_signal_connect_after(m_widget
, "prev-year",
116 G_CALLBACK (gtk_prev_year_callback
),
118 g_signal_connect_after(m_widget
, "next-year",
119 G_CALLBACK (gtk_prev_year_callback
),
122 m_parent
->DoAddChild(this);
129 bool wxGtkCalendarCtrl::EnableMonthChange(bool enable
)
131 if ( !wxCalendarCtrlBase::EnableMonthChange(enable
) )
134 g_object_set (G_OBJECT (m_widget
), "no-month-change", !enable
, NULL
);
140 bool wxGtkCalendarCtrl::SetDate(const wxDateTime
& date
)
142 g_signal_handlers_block_by_func(m_widget
,
143 (gpointer
) gtk_day_selected_callback
, this);
145 m_selectedDate
= date
;
146 int year
= date
.GetYear();
147 int month
= date
.GetMonth();
148 int day
= date
.GetDay();
149 gtk_calendar_select_month(GTK_CALENDAR(m_widget
), month
, year
);
150 gtk_calendar_select_day(GTK_CALENDAR(m_widget
), day
);
152 g_signal_handlers_unblock_by_func( m_widget
,
153 (gpointer
) gtk_day_selected_callback
, this);
158 wxDateTime
wxGtkCalendarCtrl::GetDate() const
160 guint year
, month
, day
;
161 gtk_calendar_get_date(GTK_CALENDAR(m_widget
), &year
, &month
, &day
);
162 return wxDateTime(day
, (wxDateTime::Month
) month
, year
);
165 void wxGtkCalendarCtrl::Mark(size_t day
, bool mark
)
168 gtk_calendar_mark_day(GTK_CALENDAR(m_widget
), day
);
170 gtk_calendar_unmark_day(GTK_CALENDAR(m_widget
), day
);
173 IMPLEMENT_DYNAMIC_CLASS(wxGtkCalendarCtrl
, wxControl
)
176 #endif // wxUSE_CALENDARCTRL