]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/calctrl.cpp
Improve wxMenu docs
[wxWidgets.git] / src / gtk / calctrl.cpp
CommitLineData
628e155d
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/calctrl.cpp
3// Purpose: implementation of the wxGtkCalendarCtrl
4// Author: Marcin Wojdyr
5// RCS-ID: $Id$
6// Copyright: (c) 2008 Marcin Wojdyr
7// Licence: wxWindows licence
8///////////////////////////////////////////////////////////////////////////////
9
10#include "wx/wxprec.h"
11
12#ifdef __BORLANDC__
13 #pragma hdrstop
14#endif
15
16#ifndef WX_PRECOMP
17#endif //WX_PRECOMP
18
19#if wxUSE_CALENDARCTRL
20
21#include "wx/gtk/private.h"
22#include "wx/calctrl.h"
23#include "wx/gtk/calctrl.h"
24
25
26extern "C" {
27
28static void gtk_day_selected_callback(GtkWidget *WXUNUSED(widget),
29 wxGtkCalendarCtrl *cal)
30{
31 cal->GenerateEvent(wxEVT_CALENDAR_SEL_CHANGED);
32 cal->GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED);
33}
34
35static void gtk_day_selected_double_click_callback(GtkWidget *WXUNUSED(widget),
36 wxGtkCalendarCtrl *cal)
37{
38 cal->GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED);
39}
40
41static void gtk_month_changed_callback(GtkWidget *WXUNUSED(widget),
42 wxGtkCalendarCtrl *cal)
43{
44 cal->GenerateEvent(wxEVT_CALENDAR_PAGE_CHANGED);
45}
46
47// callbacks that send deprecated events
48
49static void gtk_prev_month_callback(GtkWidget *WXUNUSED(widget),
50 wxGtkCalendarCtrl *cal)
51{
52 cal->GenerateEvent(wxEVT_CALENDAR_MONTH_CHANGED);
53}
54
55static void gtk_prev_year_callback(GtkWidget *WXUNUSED(widget),
56 wxGtkCalendarCtrl *cal)
57{
58 cal->GenerateEvent(wxEVT_CALENDAR_YEAR_CHANGED);
59}
60
61}
62
63// ----------------------------------------------------------------------------
64// wxGtkCalendarCtrl
65// ----------------------------------------------------------------------------
66
67
68bool wxGtkCalendarCtrl::Create(wxWindow *parent,
69 wxWindowID id,
70 const wxDateTime& date,
71 const wxPoint& pos,
72 const wxSize& size,
73 long style,
74 const wxString& name)
75{
76 if (!PreCreation(parent, pos, size) ||
77 !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name))
78 {
79 wxFAIL_MSG(wxT("wxGtkCalendarCtrl creation failed"));
80 return false;
81 }
82
83 m_widget = gtk_calendar_new();
84 SetDate(date.IsValid() ? date : wxDateTime::Today());
85
86 if (style & wxCAL_NO_MONTH_CHANGE)
87 g_object_set (G_OBJECT (m_widget), "no-month-change", true, NULL);
88
89 g_signal_connect_after(m_widget, "day-selected",
90 G_CALLBACK (gtk_day_selected_callback),
91 this);
92 g_signal_connect_after(m_widget, "day-selected-double-click",
93 G_CALLBACK (gtk_day_selected_double_click_callback),
94 this);
95 g_signal_connect_after(m_widget, "month-changed",
96 G_CALLBACK (gtk_month_changed_callback),
97 this);
98
99 // connect callbacks that send deprecated events
100 g_signal_connect_after(m_widget, "prev-month",
101 G_CALLBACK (gtk_prev_month_callback),
102 this);
103 g_signal_connect_after(m_widget, "next-month",
104 G_CALLBACK (gtk_prev_month_callback),
105 this);
106 g_signal_connect_after(m_widget, "prev-year",
107 G_CALLBACK (gtk_prev_year_callback),
108 this);
109 g_signal_connect_after(m_widget, "next-year",
110 G_CALLBACK (gtk_prev_year_callback),
111 this);
112
113 m_parent->DoAddChild(this);
114
115 PostCreation(size);
116
117 return true;
118}
119
120bool wxGtkCalendarCtrl::EnableMonthChange(bool enable)
121{
122 if ( !wxCalendarCtrlBase::EnableMonthChange(enable) )
123 return false;
124
125 g_object_set (G_OBJECT (m_widget), "no-month-change", !enable, NULL);
126
127 return true;
128}
129
130bool wxGtkCalendarCtrl::SetDate(const wxDateTime& date)
131{
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);
137 return true;
138}
139
140wxDateTime wxGtkCalendarCtrl::GetDate() const
141{
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);
145}
146
147void wxGtkCalendarCtrl::Mark(size_t day, bool mark)
148{
149 if (mark)
150 gtk_calendar_mark_day(GTK_CALENDAR(m_widget), day);
151 else
152 gtk_calendar_unmark_day(GTK_CALENDAR(m_widget), day);
153}
154
155IMPLEMENT_DYNAMIC_CLASS(wxGtkCalendarCtrl, wxControl)
156
157
158#endif // wxUSE_CALENDARCTRL