1 // XCCalendarManipulator.cpp - Xestia Calendar XCCalendarManipulator widget class.
3 // (c) 2016 Xestia Software Development.
5 // This file is part of Xestia Calendar.
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.
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.
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);
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);
34 // Setup the navigation section.
36 szrNavigation = new wxBoxSizer( wxHORIZONTAL );
37 pnlMain->SetSizer(szrNavigation);
39 // Add next month and previous month buttons.
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);
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));
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());
65 // Setup the static text.
67 dateButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 0|wxNO_BORDER);
71 test.SetWeight(wxFONTWEIGHT_BOLD);
72 test.SetPointSize(18);
74 dateButton->SetFont(test);
75 dateButton->SetForegroundColour(wxColour(255,255,255));
76 dateButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
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();
88 // Setup the month selection control.
90 wxDateTime dtNow = wxDateTime::Now();
93 moo = new frmCalendarSelectMonth(this);
95 moo = new XCCalendarMonthSelect(this);
97 month = ((int)dtNow.GetMonth() + 1);
98 year = dtNow.GetYear();
99 moo->UpdateDate(month, year);
100 UpdateDateButtonText();
102 // Setup the calendars list.
104 calendarList = new XCCalendarList(this);
106 // Setup the calendar data storage pointer.
108 this->dataStorage = dataStorage;
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);
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);
128 Bind(XCCALENDARMANIPULATOR_CHANGEGRID, &XCCalendarManipulator::ChangeGrid, this, ID_CHANGEGRID);
133 XCCalendarManipulator::~XCCalendarManipulator(){
135 // Destory the controls from the widget.
139 void XCCalendarManipulator::DateTextClick(wxCommandEvent &event){
141 // Bring up a popup control to select the month and year.
143 // TODO: Do something different for Win32.
145 moo->SetPosition(wxPoint(dateButton->GetScreenRect().GetLeft(), dateButton->GetScreenRect().GetBottom()));
146 moo->UpdateDate(month, year);
155 void XCCalendarManipulator::ChangeGrid(wxCommandEvent &event){
157 if (month == moo->GetMonth() && year == moo->GetYear()){
161 month = moo->GetMonth();
162 year = moo->GetYear();
164 // Post an event to the parent control to update the grid.
166 wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
167 changeGrid.SetId(ID_CHANGEGRID);
168 wxPostEvent(this->GetParent(), changeGrid);
170 UpdateDateButtonText();
174 void XCCalendarManipulator::NextMonth(wxCommandEvent &event){
179 // Get the current month and year.
181 newMonth = moo->GetMonth();
182 newYear = moo->GetYear();
194 moo->UpdateDate(month, year);
196 // Post an event to the parent control to update the grid.
198 wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
199 changeGrid.SetId(ID_CHANGEGRID);
200 wxPostEvent(this->GetParent(), changeGrid);
202 UpdateDateButtonText();
206 void XCCalendarManipulator::PreviousMonth(wxCommandEvent &event){
211 // Get the current month and year.
213 newMonth = moo->GetMonth();
214 newYear = moo->GetYear();
226 moo->UpdateDate(month, year);
228 // Post an event to the parent control to update the grid.
230 wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
231 changeGrid.SetId(ID_CHANGEGRID);
232 wxPostEvent(this->GetParent(), changeGrid);
234 UpdateDateButtonText();
238 void XCCalendarManipulator::ShowCalendarsList(wxCommandEvent &event){
240 // Update the list of calendars before showing.
242 calendarList->SetPosition(wxPoint(calendarsButton->GetScreenRect().GetLeft(), calendarsButton->GetScreenRect().GetBottom()));
243 calendarList->UpdateCalendarList(dataStorage);
244 calendarList->Popup();
248 void XCCalendarManipulator::UpdateDateButtonText(){
250 // Update the date text.
252 string newDateText = "";
254 switch (moo->GetMonth()){
256 newDateText = _("January");
259 newDateText = _("February");
262 newDateText = _("March");
265 newDateText = _("April");
268 newDateText = _("May");
271 newDateText = _("June");
274 newDateText = _("July");
277 newDateText = _("August");
280 newDateText = _("September");
283 newDateText = _("October");
286 newDateText = _("November");
289 newDateText = _("December");
295 newDateText += to_string(year);
297 dateButton->SetLabel(newDateText);
302 int XCCalendarManipulator::GetMonth(){
308 int XCCalendarManipulator::GetYear(){
314 vector<int> XCCalendarManipulator::GetHiddenAccountsList(){
316 return calendarList->GetHiddenAccountsList();
320 vector<int> XCCalendarManipulator::GetHiddenCalendarsList(){
322 return calendarList->GetHiddenCalendarsList();
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);