Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
XCCalendarManipulator: Show simple border for buttons on mouse over and no border...
[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         dateButton->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this);
114         dateButton->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this);
115         nextButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::NextMonth), NULL, this);
116         nextButton->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this);
117         nextButton->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this);
118         calendarsButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::ShowCalendarsList), NULL, this);
119         calendarsButton->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this);
120         calendarsButton->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this);
121         previousButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::PreviousMonth), NULL, this);
122         previousButton->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this);
123         previousButton->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this);
124         Bind(XCCALENDARMANIPULATOR_CHANGEGRID, &XCCalendarManipulator::ChangeGrid, this, ID_CHANGEGRID);
126         this->Refresh();
129 XCCalendarManipulator::~XCCalendarManipulator(){
130         
131         // Destory the controls from the widget.
132         
135 void XCCalendarManipulator::DateTextClick(wxCommandEvent &event){
136         
137         // Bring up a popup control to select the month and year.
138         
139         // TODO: Do something different for Win32.
141         moo->SetPosition(wxPoint(dateButton->GetScreenRect().GetLeft(), dateButton->GetScreenRect().GetBottom()));
142         moo->UpdateDate(month, year);
143 #if defined(WIN32)
144         moo->ShowModal();
145 #else
146         moo->Popup();
147 #endif
151 void XCCalendarManipulator::ChangeGrid(wxCommandEvent &event){
152         
153         if (month == moo->GetMonth() && year == moo->GetYear()){
154                 return;
155         }
156         
157         month = moo->GetMonth();
158         year = moo->GetYear();
159         
160         // Post an event to the parent control to update the grid.
161         
162         wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
163         changeGrid.SetId(ID_CHANGEGRID);
164         wxPostEvent(this->GetParent(), changeGrid);
165         
166         UpdateDateButtonText();
167         
170 void XCCalendarManipulator::NextMonth(wxCommandEvent &event){
171         
172         int newMonth = 1;
173         int newYear = 0;
174         
175         // Get the current month and year.
176         
177         newMonth = moo->GetMonth();
178         newYear = moo->GetYear();
180         if (newMonth == 12){
181                 newMonth = 1;
182                 newYear++;
183         } else {
184                 newMonth++;
185         }
186         
187         month = newMonth;
188         year = newYear;
190         moo->UpdateDate(month, year);
191         
192         // Post an event to the parent control to update the grid.
193         
194         wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
195         changeGrid.SetId(ID_CHANGEGRID);
196         wxPostEvent(this->GetParent(), changeGrid);
198         UpdateDateButtonText();
199         
202 void XCCalendarManipulator::PreviousMonth(wxCommandEvent &event){
203         
204         int newMonth = 1;
205         int newYear = 0;
206         
207         // Get the current month and year.
208         
209         newMonth = moo->GetMonth();
210         newYear = moo->GetYear();
212         if (newMonth == 1){
213                 newMonth = 12;
214                 newYear--;
215         } else {
216                 newMonth--;
217         }
219         month = newMonth;
220         year = newYear;
221         
222         moo->UpdateDate(month, year);
223         
224         // Post an event to the parent control to update the grid.
225         
226         wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
227         changeGrid.SetId(ID_CHANGEGRID);
228         wxPostEvent(this->GetParent(), changeGrid);
229         
230         UpdateDateButtonText();
231         
234 void XCCalendarManipulator::ShowCalendarsList(wxCommandEvent &event){
235         
236         // Update the list of calendars before showing.
237         
238         calendarList->SetPosition(wxPoint(calendarsButton->GetScreenRect().GetLeft(), calendarsButton->GetScreenRect().GetBottom()));
239         calendarList->UpdateCalendarList(dataStorage);
240         calendarList->Popup();
241         
244 void XCCalendarManipulator::UpdateDateButtonText(){
245         
246         // Update the date text.
247         
248         string newDateText = "";
249         
250         switch (moo->GetMonth()){
251                 case 1:
252                         newDateText = _("January");
253                         break;
254                 case 2:
255                         newDateText = _("February");
256                         break;
257                 case 3:
258                         newDateText = _("March");
259                         break;
260                 case 4:
261                         newDateText = _("April");
262                         break;
263                 case 5:
264                         newDateText = _("May");
265                         break;
266                 case 6:
267                         newDateText = _("June");
268                         break;
269                 case 7:
270                         newDateText = _("July");
271                         break;
272                 case 8:
273                         newDateText = _("August");
274                         break;
275                 case 9:
276                         newDateText = _("September");
277                         break;
278                 case 10:
279                         newDateText = _("October");
280                         break;
281                 case 11:
282                         newDateText = _("November");
283                         break;
284                 case 12:
285                         newDateText = _("December");
286                         break;
287         }
288         
289         newDateText += " ";
290         
291         newDateText += to_string(year);
292         
293         dateButton->SetLabel(newDateText);
294         szrMain->Layout();
295         
298 int XCCalendarManipulator::GetMonth(){
299         
300         return month;
301         
304 int XCCalendarManipulator::GetYear(){
305         
306         return year;
307         
310 vector<int> XCCalendarManipulator::GetHiddenAccountsList(){
311         
312         return calendarList->GetHiddenAccountsList();
313         
316 vector<int> XCCalendarManipulator::GetHiddenCalendarsList(){
317         
318         return calendarList->GetHiddenCalendarsList();
319         
322 void XCCalendarManipulator::ButtonMouseover(wxMouseEvent &event)
324         wxWindow *eventObject = (wxWindow*)event.GetEventObject();
325         eventObject->SetWindowStyle(0 | wxSIMPLE_BORDER);
328 void XCCalendarManipulator::ButtonMouseout(wxMouseEvent &event)
330         wxWindow *eventObject = (wxWindow*)event.GetEventObject();
331         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