X-Git-Url: http://Server1/repobrowser/?p=xestiacalendar%2F.git;a=blobdiff_plain;f=source%2Fwidgets%2FXCCalendarManipulator.cpp;h=4ca64bc9aced30497f2aa2c475d5bf8714beae65;hp=bc00983a4096885b3b04f3109ba5b7418e86316c;hb=df012cf9ec9670db199095c4f4408dff556c4d5f;hpb=baa27c175ee6111fd4b88a3c53614a9b6be3541e diff --git a/source/widgets/XCCalendarManipulator.cpp b/source/widgets/XCCalendarManipulator.cpp index bc00983..4ca64bc 100644 --- a/source/widgets/XCCalendarManipulator.cpp +++ b/source/widgets/XCCalendarManipulator.cpp @@ -18,18 +18,20 @@ #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, 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); @@ -40,66 +42,65 @@ XCCalendarManipulator::XCCalendarManipulator(wxWindow* parent, const wxString& t // 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); - CalendarsButton = 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 CalendarsIcon(icons_calendars_png, sizeof(icons_calendars_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); + 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); + wxImage icons_calendars_png(calendarsIcon, wxBITMAP_TYPE_PNG); + calendarsIconBitmap = wxBitmap(icons_calendars_png, -1); - PreviousButton->SetBitmap(PreviousIconBitmap); - NextButton->SetBitmap(NextIconBitmap); - CalendarsButton->SetBitmap(CalendarsIconBitmap); + 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, wxT(""), 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); - CalendarsButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::ShowCalendarsList), NULL, this); - PreviousButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::PreviousMonth), NULL, this); - - Connect(ID_CHANGEGRID, 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(CalendarsButton, 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(); - - Moo = new XCCalendarMonthSelect(this); - Month = ((int)DTNow.GetMonth() + 1); - Year = DTNow.GetYear(); - Moo->UpdateDate(Month, Year); + 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. @@ -110,6 +111,27 @@ XCCalendarManipulator::XCCalendarManipulator(wxWindow* parent, const wxString& t 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(){ @@ -122,26 +144,32 @@ void XCCalendarManipulator::DateTextClick(wxCommandEvent &event){ // 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); - ChangeGrid.SetId(ID_CHANGEGRID); - wxPostEvent(this->GetParent(), ChangeGrid); + wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID); + changeGrid.SetId(ID_CHANGEGRID); + wxPostEvent(this->GetParent(), changeGrid); UpdateDateButtonText(); @@ -149,31 +177,31 @@ void XCCalendarManipulator::ChangeGrid(wxCommandEvent &event){ 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); - ChangeGrid.SetId(ID_CHANGEGRID); - wxPostEvent(this->GetParent(), ChangeGrid); + wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID); + changeGrid.SetId(ID_CHANGEGRID); + wxPostEvent(this->GetParent(), changeGrid); UpdateDateButtonText(); @@ -181,31 +209,31 @@ void XCCalendarManipulator::NextMonth(wxCommandEvent &event){ 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); - ChangeGrid.SetId(ID_CHANGEGRID); - wxPostEvent(this->GetParent(), ChangeGrid); + wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID); + changeGrid.SetId(ID_CHANGEGRID); + wxPostEvent(this->GetParent(), changeGrid); UpdateDateButtonText(); @@ -215,75 +243,89 @@ void XCCalendarManipulator::ShowCalendarsList(wxCommandEvent &event){ // Update the list of calendars before showing. - calendarList->SetPosition(wxPoint(CalendarsButton->GetScreenRect().GetLeft(), CalendarsButton->GetScreenRect().GetBottom())); + 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; } @@ -297,4 +339,16 @@ vector 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