Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
XCCalendarManipulator: Moved connections for enter/leave window for Win32
[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         pnlMain->SetBackgroundColour(wxColour(40,40,40));
31         this->SetSizer(szrMain);
32         szrMain->Add(pnlMain, 0, wxEXPAND, 0);
33         
34         // Setup the navigation section.
35                 
36         szrNavigation = new wxBoxSizer( wxHORIZONTAL );
37         pnlMain->SetSizer(szrNavigation);
38                 
39         // Add next month and previous month buttons.
40                 
41         previousButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
42         nextButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
43         calendarsButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
44         
45         wxMemoryInputStream previousIcon(icons_previous_png, sizeof(icons_previous_png));
46         wxMemoryInputStream nextIcon(icons_next_png, sizeof(icons_next_png));
47         wxMemoryInputStream calendarsIcon(icons_calendars_png, sizeof(icons_calendars_png));
48                 
49         wxImage icons_previous_png(previousIcon, wxBITMAP_TYPE_PNG);
50         previousIconBitmap = wxBitmap(icons_previous_png, -1);
52         wxImage icons_next_png(nextIcon, wxBITMAP_TYPE_PNG);
53         nextIconBitmap = wxBitmap(icons_next_png, -1);
55         wxImage icons_calendars_png(calendarsIcon, wxBITMAP_TYPE_PNG);
56         calendarsIconBitmap = wxBitmap(icons_calendars_png, -1);
58         previousButton->SetBitmap(previousIconBitmap);
59         nextButton->SetBitmap(nextIconBitmap);
60         calendarsButton->SetBitmap(calendarsIconBitmap);
61         previousButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
62         nextButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
63         calendarsButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
64                 
65         // Setup the static text.
66                 
67         dateButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 0|wxNO_BORDER);
68                 
69         wxFont test;
70         
71         test.SetWeight(wxFONTWEIGHT_BOLD);
72         test.SetPointSize(18);
73                 
74         dateButton->SetFont(test);
75         dateButton->SetForegroundColour(wxColour(255,255,255));
76         dateButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
77         
78         // Setup the manipulator control.
80         szrNavigation->Add(previousButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
81         szrNavigation->Add(calendarsButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
82         szrNavigation->Add( 0, 0, 1, wxEXPAND, 5 );
83         szrNavigation->Add(dateButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
84         szrNavigation->Add( 0, 0, 1, wxEXPAND, 5 );
85         szrNavigation->Add(nextButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
86         szrNavigation->Layout();
87                 
88         // Setup the month selection control.
89         
90         wxDateTime dtNow = wxDateTime::Now();
92 #if defined(WIN32)
93         moo = new frmCalendarSelectMonth(this);
94 #else
95         moo = new XCCalendarMonthSelect(this);
96 #endif
97         month = ((int)dtNow.GetMonth() + 1);
98         year = dtNow.GetYear();
99         moo->UpdateDate(month, year);
100         UpdateDateButtonText();
101         
102         // Setup the calendars list.
103         
104         calendarList = new XCCalendarList(this);
105         
106         // Setup the calendar data storage pointer.
107         
108         this->dataStorage = dataStorage;
109                 
110         // Setup the event controls.
112         dateButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::DateTextClick), NULL, this);
113         nextButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::NextMonth), NULL, this);
114         calendarsButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::ShowCalendarsList), NULL, this);
115         previousButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::PreviousMonth), NULL, this);
116         
117 #if defined(WIN32)
118         dateButton->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this);
119         dateButton->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this);
120         nextButton->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this);
121         nextButton->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this);
122         calendarsButton->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this);
123         calendarsButton->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this);
124         previousButton->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this);
125         previousButton->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this);
126 #endif
128         Bind(XCCALENDARMANIPULATOR_CHANGEGRID, &XCCalendarManipulator::ChangeGrid, this, ID_CHANGEGRID);
130         this->Refresh();
133 XCCalendarManipulator::~XCCalendarManipulator(){
134         
135         // Destory the controls from the widget.
136         
139 void XCCalendarManipulator::DateTextClick(wxCommandEvent &event){
140         
141         // Bring up a popup control to select the month and year.
142         
143         // TODO: Do something different for Win32.
145         moo->SetPosition(wxPoint(dateButton->GetScreenRect().GetLeft(), dateButton->GetScreenRect().GetBottom()));
146         moo->UpdateDate(month, year);
147 #if defined(WIN32)
148         moo->ShowModal();
149 #else
150         moo->Popup();
151 #endif
155 void XCCalendarManipulator::ChangeGrid(wxCommandEvent &event){
156         
157         if (month == moo->GetMonth() && year == moo->GetYear()){
158                 return;
159         }
160         
161         month = moo->GetMonth();
162         year = moo->GetYear();
163         
164         // Post an event to the parent control to update the grid.
165         
166         wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
167         changeGrid.SetId(ID_CHANGEGRID);
168         wxPostEvent(this->GetParent(), changeGrid);
169         
170         UpdateDateButtonText();
171         
174 void XCCalendarManipulator::NextMonth(wxCommandEvent &event){
175         
176         int newMonth = 1;
177         int newYear = 0;
178         
179         // Get the current month and year.
180         
181         newMonth = moo->GetMonth();
182         newYear = moo->GetYear();
184         if (newMonth == 12){
185                 newMonth = 1;
186                 newYear++;
187         } else {
188                 newMonth++;
189         }
190         
191         month = newMonth;
192         year = newYear;
194         moo->UpdateDate(month, year);
195         
196         // Post an event to the parent control to update the grid.
197         
198         wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
199         changeGrid.SetId(ID_CHANGEGRID);
200         wxPostEvent(this->GetParent(), changeGrid);
202         UpdateDateButtonText();
203         
206 void XCCalendarManipulator::PreviousMonth(wxCommandEvent &event){
207         
208         int newMonth = 1;
209         int newYear = 0;
210         
211         // Get the current month and year.
212         
213         newMonth = moo->GetMonth();
214         newYear = moo->GetYear();
216         if (newMonth == 1){
217                 newMonth = 12;
218                 newYear--;
219         } else {
220                 newMonth--;
221         }
223         month = newMonth;
224         year = newYear;
225         
226         moo->UpdateDate(month, year);
227         
228         // Post an event to the parent control to update the grid.
229         
230         wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
231         changeGrid.SetId(ID_CHANGEGRID);
232         wxPostEvent(this->GetParent(), changeGrid);
233         
234         UpdateDateButtonText();
235         
238 void XCCalendarManipulator::ShowCalendarsList(wxCommandEvent &event){
239         
240         // Update the list of calendars before showing.
241         
242         calendarList->SetPosition(wxPoint(calendarsButton->GetScreenRect().GetLeft(), calendarsButton->GetScreenRect().GetBottom()));
243         calendarList->UpdateCalendarList(dataStorage);
244         calendarList->Popup();
245         
248 void XCCalendarManipulator::UpdateDateButtonText(){
249         
250         // Update the date text.
251         
252         string newDateText = "";
253         
254         switch (moo->GetMonth()){
255                 case 1:
256                         newDateText = _("January");
257                         break;
258                 case 2:
259                         newDateText = _("February");
260                         break;
261                 case 3:
262                         newDateText = _("March");
263                         break;
264                 case 4:
265                         newDateText = _("April");
266                         break;
267                 case 5:
268                         newDateText = _("May");
269                         break;
270                 case 6:
271                         newDateText = _("June");
272                         break;
273                 case 7:
274                         newDateText = _("July");
275                         break;
276                 case 8:
277                         newDateText = _("August");
278                         break;
279                 case 9:
280                         newDateText = _("September");
281                         break;
282                 case 10:
283                         newDateText = _("October");
284                         break;
285                 case 11:
286                         newDateText = _("November");
287                         break;
288                 case 12:
289                         newDateText = _("December");
290                         break;
291         }
292         
293         newDateText += " ";
294         
295         newDateText += to_string(year);
296         
297         dateButton->SetLabel(newDateText);
298         szrMain->Layout();
299         
302 int XCCalendarManipulator::GetMonth(){
303         
304         return month;
305         
308 int XCCalendarManipulator::GetYear(){
309         
310         return year;
311         
314 vector<int> XCCalendarManipulator::GetHiddenAccountsList(){
315         
316         return calendarList->GetHiddenAccountsList();
317         
320 vector<int> XCCalendarManipulator::GetHiddenCalendarsList(){
321         
322         return calendarList->GetHiddenCalendarsList();
323         
326 void XCCalendarManipulator::ButtonMouseover(wxMouseEvent &event)
328         wxWindow *eventObject = (wxWindow*)event.GetEventObject();
329         eventObject->SetWindowStyle(0 | wxSIMPLE_BORDER);
332 void XCCalendarManipulator::ButtonMouseout(wxMouseEvent &event)
334         wxWindow *eventObject = (wxWindow*)event.GetEventObject();
335         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