#include "XCCalendarManipulator.h"
-BEGIN_EVENT_TABLE(XCCalendarManipulator, wxPanel)
-END_EVENT_TABLE()
+wxDEFINE_EVENT(XCCALENDARMANIPULATOR_CHANGEGRID, wxCommandEvent);
using namespace std;
-XCCalendarManipulator::XCCalendarManipulator(wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size)
+XCCalendarManipulator::XCCalendarManipulator(wxWindow* parent, const wxString& title,
+ const wxPoint& pos, const wxSize& size, CalendarDataStorage *dataStorage)
: wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
-
szrMain = new wxBoxSizer( wxVERTICAL );
pnlMain = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(500, 50), wxTAB_TRAVERSAL);
+#if defined(__APPLE__)
+ pnlMain->SetBackgroundColour(wxColour(120,120,120));
+#else
pnlMain->SetBackgroundColour(wxColour(40,40,40));
+#endif
this->SetSizer(szrMain);
szrMain->Add(pnlMain, 0, wxEXPAND, 0);
-
+
// Setup the navigation section.
szrNavigation = new wxBoxSizer( wxHORIZONTAL );
// Add next month and previous month buttons.
- PreviousButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
- NextButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
+ previousButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
+ nextButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
+ calendarsButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
- wxMemoryInputStream PreviousIcon(icons_previous_png, sizeof(icons_previous_png));
- wxMemoryInputStream NextIcon(icons_next_png, sizeof(icons_next_png));
+ wxMemoryInputStream previousIcon(icons_previous_png, sizeof(icons_previous_png));
+ wxMemoryInputStream nextIcon(icons_next_png, sizeof(icons_next_png));
+ wxMemoryInputStream calendarsIcon(icons_calendars_png, sizeof(icons_calendars_png));
- wxImage icons_previous_png(PreviousIcon, wxBITMAP_TYPE_PNG);
- PreviousIconBitmap = wxBitmap(icons_previous_png, -1);
+ wxImage icons_previous_png(previousIcon, wxBITMAP_TYPE_PNG);
+ previousIconBitmap = wxBitmap(icons_previous_png, -1);
- wxImage icons_next_png(NextIcon, wxBITMAP_TYPE_PNG);
- NextIconBitmap = wxBitmap(icons_next_png, -1);
-
- PreviousButton->SetBitmap(PreviousIconBitmap);
- NextButton->SetBitmap(NextIconBitmap);
+ wxImage icons_next_png(nextIcon, wxBITMAP_TYPE_PNG);
+ nextIconBitmap = wxBitmap(icons_next_png, -1);
+
+ wxImage icons_calendars_png(calendarsIcon, wxBITMAP_TYPE_PNG);
+ calendarsIconBitmap = wxBitmap(icons_calendars_png, -1);
+
+ previousButton->SetBitmap(previousIconBitmap);
+ nextButton->SetBitmap(nextIconBitmap);
+ calendarsButton->SetBitmap(calendarsIconBitmap);
+ previousButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
+ nextButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
+ calendarsButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
// Setup the static text.
- DateButton = new wxButton(pnlMain, wxID_ANY, _("November 2016"), wxDefaultPosition, wxDefaultSize, 0|wxNO_BORDER);
+ dateButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 0|wxNO_BORDER);
- wxFont Test;
+ wxFont test;
- Test.SetWeight(wxFONTWEIGHT_BOLD);
- Test.SetPointSize(18);
+ test.SetWeight(wxFONTWEIGHT_BOLD);
+ test.SetPointSize(18);
- DateButton->SetFont(Test);
- DateButton->SetForegroundColour(wxColour(255,255,255));
-
- // Setup the event controls.
-
- DateButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::DateTextClick), NULL, this);
- NextButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::NextMonth), NULL, this);
- PreviousButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::PreviousMonth), NULL, this);
-
- Connect(wxID_ANY, XCCALENDARMANIPULATOR_CHANGEGRID, wxCommandEventHandler(XCCalendarManipulator::ChangeGrid));
+ dateButton->SetFont(test);
+ dateButton->SetForegroundColour(wxColour(255,255,255));
+ dateButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
// Setup the manipulator control.
- szrNavigation->Add(PreviousButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
+ szrNavigation->Add(previousButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
+ szrNavigation->Add(calendarsButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
szrNavigation->Add( 0, 0, 1, wxEXPAND, 5 );
- szrNavigation->Add(DateButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
+ szrNavigation->Add(dateButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
szrNavigation->Add( 0, 0, 1, wxEXPAND, 5 );
- szrNavigation->Add(NextButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
+ szrNavigation->Add(nextButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
szrNavigation->Layout();
// Setup the month selection control.
- wxDateTime DTNow = wxDateTime::Now();
+ wxDateTime dtNow = wxDateTime::Now();
+
+#if defined(WIN32) || defined(__APPLE__)
+ moo = new frmCalendarSelectMonth(this);
+#else
+ moo = new XCCalendarMonthSelect(this);
+#endif
+ month = ((int)dtNow.GetMonth() + 1);
+ year = dtNow.GetYear();
+ moo->UpdateDate(month, year);
+ UpdateDateButtonText();
+
+ // Setup the calendars list.
+
+ calendarList = new XCCalendarList(this);
- Moo = new XCCalendarMonthSelect(this);
- Month = ((int)DTNow.GetMonth() + 1);
- Year = DTNow.GetYear();
- Moo->UpdateDate(Month, Year);
+ // Setup the calendar data storage pointer.
+
+ this->dataStorage = dataStorage;
+ // Setup the event controls.
+
+ dateButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::DateTextClick), NULL, this);
+ nextButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::NextMonth), NULL, this);
+ calendarsButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::ShowCalendarsList), NULL, this);
+ previousButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::PreviousMonth), NULL, this);
+
+#if defined(WIN32)
+ dateButton->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this);
+ dateButton->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this);
+ nextButton->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this);
+ nextButton->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this);
+ calendarsButton->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this);
+ calendarsButton->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this);
+ previousButton->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this);
+ previousButton->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this);
+#endif
+
+ Bind(XCCALENDARMANIPULATOR_CHANGEGRID, &XCCalendarManipulator::ChangeGrid, this, ID_CHANGEGRID);
+
+ this->Refresh();
}
XCCalendarManipulator::~XCCalendarManipulator(){
// Bring up a popup control to select the month and year.
- Moo->SetPosition(wxPoint(DateButton->GetScreenRect().GetLeft(), DateButton->GetScreenRect().GetBottom()));
- Moo->UpdateDate(Month, Year);
- Moo->Popup();
-
+ // Do something different for Win32 and macOS.
+
+ moo->SetPosition(wxPoint(dateButton->GetScreenRect().GetLeft(), dateButton->GetScreenRect().GetBottom()));
+ moo->UpdateDate(month, year);
+#if defined(WIN32) || defined(__APPLE__)
+ moo->ShowModal();
+#else
+ moo->Popup();
+#endif
+
}
void XCCalendarManipulator::ChangeGrid(wxCommandEvent &event){
- if (Month == Moo->GetMonth() && Year == Moo->GetYear()){
+ if (month == moo->GetMonth() && year == moo->GetYear()){
return;
}
- Month = Moo->GetMonth();
- Year = Moo->GetYear();
+ month = moo->GetMonth();
+ year = moo->GetYear();
// Post an event to the parent control to update the grid.
- wxCommandEvent ChangeGrid(XCCALENDARCTRL_CHANGEGRID);
- wxPostEvent(this->GetParent(), ChangeGrid);
+ wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
+ changeGrid.SetId(ID_CHANGEGRID);
+ wxPostEvent(this->GetParent(), changeGrid);
UpdateDateButtonText();
void XCCalendarManipulator::NextMonth(wxCommandEvent &event){
- int NewMonth = 1;
- int NewYear = 0;
+ int newMonth = 1;
+ int newYear = 0;
// Get the current month and year.
- NewMonth = Moo->GetMonth();
- NewYear = Moo->GetYear();
+ newMonth = moo->GetMonth();
+ newYear = moo->GetYear();
- if (NewMonth == 12){
- NewMonth = 1;
- NewYear++;
+ if (newMonth == 12){
+ newMonth = 1;
+ newYear++;
} else {
- NewMonth++;
+ newMonth++;
}
- Month = NewMonth;
- Year = NewYear;
+ month = newMonth;
+ year = newYear;
- Moo->UpdateDate(Month, Year);
+ moo->UpdateDate(month, year);
// Post an event to the parent control to update the grid.
- wxCommandEvent ChangeGrid(XCCALENDARCTRL_CHANGEGRID);
- wxPostEvent(this->GetParent(), ChangeGrid);
+ wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
+ changeGrid.SetId(ID_CHANGEGRID);
+ wxPostEvent(this->GetParent(), changeGrid);
UpdateDateButtonText();
void XCCalendarManipulator::PreviousMonth(wxCommandEvent &event){
- int NewMonth = 1;
- int NewYear = 0;
+ int newMonth = 1;
+ int newYear = 0;
// Get the current month and year.
- NewMonth = Moo->GetMonth();
- NewYear = Moo->GetYear();
+ newMonth = moo->GetMonth();
+ newYear = moo->GetYear();
- if (NewMonth == 1){
- NewMonth = 12;
- NewYear--;
+ if (newMonth == 1){
+ newMonth = 12;
+ newYear--;
} else {
- NewMonth--;
+ newMonth--;
}
- Month = NewMonth;
- Year = NewYear;
+ month = newMonth;
+ year = newYear;
- Moo->UpdateDate(Month, Year);
+ moo->UpdateDate(month, year);
// Post an event to the parent control to update the grid.
- wxCommandEvent ChangeGrid(XCCALENDARCTRL_CHANGEGRID);
- wxPostEvent(this->GetParent(), ChangeGrid);
+ wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
+ changeGrid.SetId(ID_CHANGEGRID);
+ wxPostEvent(this->GetParent(), changeGrid);
UpdateDateButtonText();
}
+void XCCalendarManipulator::ShowCalendarsList(wxCommandEvent &event){
+
+ // Update the list of calendars before showing.
+
+ calendarList->SetPosition(wxPoint(calendarsButton->GetScreenRect().GetLeft(), calendarsButton->GetScreenRect().GetBottom()));
+ calendarList->UpdateCalendarList(dataStorage);
+#if defined(__APPLE__)
+
+ if (calendarListShow == false)
+ {
+ calendarList->Show();
+ calendarListShow = true;
+ }
+ else
+ {
+ calendarList->Hide();
+ calendarListShow = false;
+ }
+#else
+ calendarList->Popup();
+#endif
+
+}
+
void XCCalendarManipulator::UpdateDateButtonText(){
// Update the date text.
- string NewDateText = "";
+ string newDateText = "";
- switch (Moo->GetMonth()){
+ switch (moo->GetMonth()){
case 1:
- NewDateText = _("January");
+ newDateText = _("January");
break;
case 2:
- NewDateText = _("February");
+ newDateText = _("February");
break;
case 3:
- NewDateText = _("March");
+ newDateText = _("March");
break;
case 4:
- NewDateText = _("April");
+ newDateText = _("April");
break;
case 5:
- NewDateText = _("May");
+ newDateText = _("May");
break;
case 6:
- NewDateText = _("June");
+ newDateText = _("June");
break;
case 7:
- NewDateText = _("July");
+ newDateText = _("July");
break;
case 8:
- NewDateText = _("August");
+ newDateText = _("August");
break;
case 9:
- NewDateText = _("September");
+ newDateText = _("September");
break;
case 10:
- NewDateText = _("October");
+ newDateText = _("October");
break;
case 11:
- NewDateText = _("November");
+ newDateText = _("November");
break;
case 12:
- NewDateText = _("December");
+ newDateText = _("December");
break;
}
- NewDateText += " ";
+ newDateText += " ";
- NewDateText += to_string(Year);
+ newDateText += to_string(year);
- DateButton->SetLabel(NewDateText);
+ dateButton->SetLabel(newDateText);
szrMain->Layout();
}
int XCCalendarManipulator::GetMonth(){
- return Month;
+ return month;
}
int XCCalendarManipulator::GetYear(){
- return Year;
+ return year;
+
+}
+
+vector<int> XCCalendarManipulator::GetHiddenAccountsList(){
+
+ return calendarList->GetHiddenAccountsList();
+
+}
+
+vector<int> XCCalendarManipulator::GetHiddenCalendarsList(){
+
+ return calendarList->GetHiddenCalendarsList();
+}
+
+void XCCalendarManipulator::ButtonMouseover(wxMouseEvent &event)
+{
+ wxWindow *eventObject = (wxWindow*)event.GetEventObject();
+ eventObject->SetWindowStyle(0 | wxSIMPLE_BORDER);
+}
+
+void XCCalendarManipulator::ButtonMouseout(wxMouseEvent &event)
+{
+ wxWindow *eventObject = (wxWindow*)event.GetEventObject();
+ eventObject->SetWindowStyle(0 | wxNO_BORDER);
}
\ No newline at end of file