Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
macOS: Implemented macOS specific paths and variable name fixes
[xestiacalendar/.git] / source / widgets / XCCalendarManipulator.cpp
1 // XCCalendarManipulator.cpp - Xestia Calendar XCCalendarManipulator widget class.
2 //
3 // (c) 2016 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/> 
19 #include "XCCalendarManipulator.h"
21 wxDEFINE_EVENT(XCCALENDARMANIPULATOR_CHANGEGRID, wxCommandEvent);
23 using namespace std;
25 XCCalendarManipulator::XCCalendarManipulator(wxWindow* parent, const wxString& title, 
26         const wxPoint& pos, const wxSize& size, CalendarDataStorage *dataStorage)
27         : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
28         szrMain = new wxBoxSizer( wxVERTICAL );
29         pnlMain = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(500, 50), wxTAB_TRAVERSAL);
30 #if defined(__APPLE__)
31         pnlMain->SetBackgroundColour(wxColour(120,120,120));
32 #else
33         pnlMain->SetBackgroundColour(wxColour(40,40,40));
34 #endif
35         this->SetSizer(szrMain);
36         szrMain->Add(pnlMain, 0, wxEXPAND, 0);
37         
38         // Setup the navigation section.
39                 
40         szrNavigation = new wxBoxSizer( wxHORIZONTAL );
41         pnlMain->SetSizer(szrNavigation);
42                 
43         // Add next month and previous month buttons.
44                 
45         previousButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
46         nextButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
47         calendarsButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
48         
49         wxMemoryInputStream previousIcon(icons_previous_png, sizeof(icons_previous_png));
50         wxMemoryInputStream nextIcon(icons_next_png, sizeof(icons_next_png));
51         wxMemoryInputStream calendarsIcon(icons_calendars_png, sizeof(icons_calendars_png));
52                 
53         wxImage icons_previous_png(previousIcon, wxBITMAP_TYPE_PNG);
54         previousIconBitmap = wxBitmap(icons_previous_png, -1);
56         wxImage icons_next_png(nextIcon, wxBITMAP_TYPE_PNG);
57         nextIconBitmap = wxBitmap(icons_next_png, -1);
59         wxImage icons_calendars_png(calendarsIcon, wxBITMAP_TYPE_PNG);
60         calendarsIconBitmap = wxBitmap(icons_calendars_png, -1);
62         previousButton->SetBitmap(previousIconBitmap);
63         nextButton->SetBitmap(nextIconBitmap);
64         calendarsButton->SetBitmap(calendarsIconBitmap);
65         previousButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
66         nextButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
67         calendarsButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
68                 
69         // Setup the static text.
70                 
71         dateButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 0|wxNO_BORDER);
72                 
73         wxFont test;
74         
75         test.SetWeight(wxFONTWEIGHT_BOLD);
76         test.SetPointSize(18);
77                 
78         dateButton->SetFont(test);
79         dateButton->SetForegroundColour(wxColour(255,255,255));
80         dateButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
81         
82         // Setup the manipulator control.
84         szrNavigation->Add(previousButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
85         szrNavigation->Add(calendarsButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
86         szrNavigation->Add( 0, 0, 1, wxEXPAND, 5 );
87         szrNavigation->Add(dateButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
88         szrNavigation->Add( 0, 0, 1, wxEXPAND, 5 );
89         szrNavigation->Add(nextButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
90         szrNavigation->Layout();
91                 
92         // Setup the month selection control.
93         
94         wxDateTime dtNow = wxDateTime::Now();
96 #if defined(WIN32) || defined(__APPLE__)
97         moo = new frmCalendarSelectMonth(this);
98 #else
99         moo = new XCCalendarMonthSelect(this);
100 #endif
101         month = ((int)dtNow.GetMonth() + 1);
102         year = dtNow.GetYear();
103         moo->UpdateDate(month, year);
104         UpdateDateButtonText();
105         
106         // Setup the calendars list.
107         
108         calendarList = new XCCalendarList(this);
109         
110         // Setup the calendar data storage pointer.
111         
112         this->dataStorage = dataStorage;
113                 
114         // Setup the event controls.
116         dateButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::DateTextClick), NULL, this);
117         nextButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::NextMonth), NULL, this);
118         calendarsButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::ShowCalendarsList), NULL, this);
119         previousButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::PreviousMonth), NULL, this);
120         
121 #if defined(WIN32)
122         dateButton->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this);
123         dateButton->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this);
124         nextButton->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this);
125         nextButton->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this);
126         calendarsButton->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this);
127         calendarsButton->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this);
128         previousButton->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this);
129         previousButton->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this);
130 #endif
132         Bind(XCCALENDARMANIPULATOR_CHANGEGRID, &XCCalendarManipulator::ChangeGrid, this, ID_CHANGEGRID);
134         this->Refresh();
137 XCCalendarManipulator::~XCCalendarManipulator(){
138         
139         // Destory the controls from the widget.
140         
143 void XCCalendarManipulator::DateTextClick(wxCommandEvent &event){
144         
145         // Bring up a popup control to select the month and year.
146         
147         // Do something different for Win32 and macOS.
149         moo->SetPosition(wxPoint(dateButton->GetScreenRect().GetLeft(), dateButton->GetScreenRect().GetBottom()));
150         moo->UpdateDate(month, year);
151 #if defined(WIN32) || defined(__APPLE__)
152         moo->ShowModal();
153 #else
154         moo->Popup();
155 #endif
159 void XCCalendarManipulator::ChangeGrid(wxCommandEvent &event){
160         
161         if (month == moo->GetMonth() && year == moo->GetYear()){
162                 return;
163         }
164         
165         month = moo->GetMonth();
166         year = moo->GetYear();
167         
168         // Post an event to the parent control to update the grid.
169         
170         wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
171         changeGrid.SetId(ID_CHANGEGRID);
172         wxPostEvent(this->GetParent(), changeGrid);
173         
174         UpdateDateButtonText();
175         
178 void XCCalendarManipulator::NextMonth(wxCommandEvent &event){
179         
180         int newMonth = 1;
181         int newYear = 0;
182         
183         // Get the current month and year.
184         
185         newMonth = moo->GetMonth();
186         newYear = moo->GetYear();
188         if (newMonth == 12){
189                 newMonth = 1;
190                 newYear++;
191         } else {
192                 newMonth++;
193         }
194         
195         month = newMonth;
196         year = newYear;
198         moo->UpdateDate(month, year);
199         
200         // Post an event to the parent control to update the grid.
201         
202         wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
203         changeGrid.SetId(ID_CHANGEGRID);
204         wxPostEvent(this->GetParent(), changeGrid);
206         UpdateDateButtonText();
207         
210 void XCCalendarManipulator::PreviousMonth(wxCommandEvent &event){
211         
212         int newMonth = 1;
213         int newYear = 0;
214         
215         // Get the current month and year.
216         
217         newMonth = moo->GetMonth();
218         newYear = moo->GetYear();
220         if (newMonth == 1){
221                 newMonth = 12;
222                 newYear--;
223         } else {
224                 newMonth--;
225         }
227         month = newMonth;
228         year = newYear;
229         
230         moo->UpdateDate(month, year);
231         
232         // Post an event to the parent control to update the grid.
233         
234         wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
235         changeGrid.SetId(ID_CHANGEGRID);
236         wxPostEvent(this->GetParent(), changeGrid);
237         
238         UpdateDateButtonText();
239         
242 void XCCalendarManipulator::ShowCalendarsList(wxCommandEvent &event){
243         
244         // Update the list of calendars before showing.
245         
246         calendarList->SetPosition(wxPoint(calendarsButton->GetScreenRect().GetLeft(), calendarsButton->GetScreenRect().GetBottom()));
247         calendarList->UpdateCalendarList(dataStorage);
248 #if defined(__APPLE__)
250     if (calendarListShow == false)
251     {
252         calendarList->Show();
253         calendarListShow = true;
254     }
255     else
256     {
257         calendarList->Hide();
258         calendarListShow = false;
259     }
260 #else
261         calendarList->Popup();
262 #endif
263     
266 void XCCalendarManipulator::UpdateDateButtonText(){
267         
268         // Update the date text.
269         
270         string newDateText = "";
271         
272         switch (moo->GetMonth()){
273                 case 1:
274                         newDateText = _("January");
275                         break;
276                 case 2:
277                         newDateText = _("February");
278                         break;
279                 case 3:
280                         newDateText = _("March");
281                         break;
282                 case 4:
283                         newDateText = _("April");
284                         break;
285                 case 5:
286                         newDateText = _("May");
287                         break;
288                 case 6:
289                         newDateText = _("June");
290                         break;
291                 case 7:
292                         newDateText = _("July");
293                         break;
294                 case 8:
295                         newDateText = _("August");
296                         break;
297                 case 9:
298                         newDateText = _("September");
299                         break;
300                 case 10:
301                         newDateText = _("October");
302                         break;
303                 case 11:
304                         newDateText = _("November");
305                         break;
306                 case 12:
307                         newDateText = _("December");
308                         break;
309         }
310         
311         newDateText += " ";
312         
313         newDateText += to_string(year);
314         
315         dateButton->SetLabel(newDateText);
316         szrMain->Layout();
317         
320 int XCCalendarManipulator::GetMonth(){
321         
322         return month;
323         
326 int XCCalendarManipulator::GetYear(){
327         
328         return year;
329         
332 vector<int> XCCalendarManipulator::GetHiddenAccountsList(){
333         
334         return calendarList->GetHiddenAccountsList();
335         
338 vector<int> XCCalendarManipulator::GetHiddenCalendarsList(){
339         
340         return calendarList->GetHiddenCalendarsList();
341         
344 void XCCalendarManipulator::ButtonMouseover(wxMouseEvent &event)
346         wxWindow *eventObject = (wxWindow*)event.GetEventObject();
347         eventObject->SetWindowStyle(0 | wxSIMPLE_BORDER);
350 void XCCalendarManipulator::ButtonMouseout(wxMouseEvent &event)
352         wxWindow *eventObject = (wxWindow*)event.GetEventObject();
353         eventObject->SetWindowStyle(0 | wxNO_BORDER);
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy