From: Steve Brokenshire Date: Wed, 11 Jan 2017 19:42:33 +0000 (+0000) Subject: widgets: Widget controls updated X-Git-Tag: release-0.02~27 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=c5716d0f27f0f917282df9121aa97eab7a1bf6b8;p=xestiacalendar%2F.git widgets: Widget controls updated --- diff --git a/source/widgets/XCCalendarCtrl.cpp b/source/widgets/XCCalendarCtrl.cpp index b4fe633..44a1eb9 100644 --- a/source/widgets/XCCalendarCtrl.cpp +++ b/source/widgets/XCCalendarCtrl.cpp @@ -52,7 +52,7 @@ XCCalendarCtrl::XCCalendarCtrl(wxWindow *parent, CalendarDataStorage *dataStorag XCCalendarMonthViewGrid CurrentMonthGrid = GenerateMonthGrid(currentMonth, currentYear); szrMain->Add(ManipulatorCtrl, 1, wxEXPAND, 5); - // TODO: Get the list of hidden accounts and calendars. + // Get the list of hidden accounts and calendars. vector hideAccountsList = ManipulatorCtrl->GetHiddenAccountsList(); vector hideCalendarsList = ManipulatorCtrl->GetHiddenCalendarsList(); @@ -67,6 +67,11 @@ XCCalendarCtrl::XCCalendarCtrl(wxWindow *parent, CalendarDataStorage *dataStorag Connect(ID_SHOWENTRIES, XCCALENDARCTRL_SHOWACCOUNTENTRIES, wxCommandEventHandler(XCCalendarCtrl::ShowAccountEntries)); Connect(ID_HIDECALENDARENTRIES, XCCALENDARCTRL_HIDECALENDARENTRIES, wxCommandEventHandler(XCCalendarCtrl::HideCalendarEntries)); Connect(ID_SHOWCALENDARENTRIES, XCCALENDARCTRL_SHOWCALENDARENTRIES, wxCommandEventHandler(XCCalendarCtrl::ShowCalendarEntries)); + Connect(ID_DELETECALENDARENTRIES, XCCALENDARCTRL_DELETECALENDARENTRIES, wxCommandEventHandler(XCCalendarCtrl::DeleteCalendarEntries)); + Connect(ID_DELETEENTRY, XCCALENDARCTRL_DELETEENTRY, wxCommandEventHandler(XCCalendarCtrl::DeleteCalendarEntry)); + Connect(ID_ADDENTRY, XCCALENDARCTRL_ADDENTRY, wxCommandEventHandler(XCCalendarCtrl::AddCalendarEntry)); + Connect(ID_UPDATEENTRY, XCCALENDARCTRL_UPDATEENTRY, wxCommandEventHandler(XCCalendarCtrl::UpdateCalendarEntry)); + Connect(ID_UPDATECOLOUR, XCCALENDARCTRL_UPDATECALENDARCOLOUR, wxCommandEventHandler(XCCalendarCtrl::UpdateCalendarColour)); } @@ -154,4 +159,58 @@ void XCCalendarCtrl::ShowCalendarEntries(wxCommandEvent &calendarData){ event.SetId(ID_SHOWCALENDARENTRIES); wxPostEvent(MonthViewCtrl, event); +} + +void XCCalendarCtrl::DeleteCalendarEntries(wxCommandEvent &calendarData){ + + wxCommandEvent event(XCCALENDARMONTH_DELETECALENDARENTRIES); + event.SetInt(calendarData.GetInt()); + event.SetId(ID_DELETECALENDARENTRIES); + wxPostEvent(MonthViewCtrl, event); + +} + +void XCCalendarCtrl::DeleteCalendarEntry(wxCommandEvent &eventData){ + + wxCommandEvent event(XCCALENDARMONTH_DELETEENTRY); + event.SetInt(eventData.GetInt()); + event.SetId(ID_DELETEENTRY); + wxPostEvent(MonthViewCtrl, event); + +} + +void XCCalendarCtrl::AddCalendarEntry(wxCommandEvent &eventData){ + + EventProperties *eventInfo = (EventProperties*)eventData.GetClientData(); + + eventInfo->hideAccountsList = ManipulatorCtrl->GetHiddenAccountsList(); + eventInfo->hideCalendarsList = ManipulatorCtrl->GetHiddenCalendarsList(); + + wxCommandEvent addEvent(XCCALENDARMONTH_ADDENTRY); + addEvent.SetId(ID_ADDENTRY); + addEvent.SetClientData(eventInfo); + wxPostEvent(MonthViewCtrl, addEvent); + +} + +void XCCalendarCtrl::UpdateCalendarEntry(wxCommandEvent &eventData){ + + EventProperties *eventInfo = (EventProperties*)eventData.GetClientData(); + + wxCommandEvent addEvent(XCCALENDARMONTH_UPDATEENTRY); + addEvent.SetId(ID_UPDATEENTRY); + addEvent.SetClientData(eventInfo); + wxPostEvent(MonthViewCtrl, addEvent); + +} + +void XCCalendarCtrl::UpdateCalendarColour(wxCommandEvent &colourData){ + + ColourUpdateProperties *colourInfo = (ColourUpdateProperties*)colourData.GetClientData(); + + wxCommandEvent colourEvent(XCCALENDARMONTH_UPDATECALENDARCOLOUR); + colourEvent.SetId(ID_UPDATECOLOUR); + colourEvent.SetClientData(colourInfo); + wxPostEvent(MonthViewCtrl, colourEvent); + } \ No newline at end of file diff --git a/source/widgets/XCCalendarCtrl.h b/source/widgets/XCCalendarCtrl.h index d153a69..573d6e9 100644 --- a/source/widgets/XCCalendarCtrl.h +++ b/source/widgets/XCCalendarCtrl.h @@ -20,7 +20,9 @@ #define __WIDGETS_XCCALENDARCTRL_H__ #include +#include +#include "structs.h" #include "events.h" #include "XCCalendarMonthView.h" @@ -44,10 +46,16 @@ class XCCalendarCtrl: public wxPanel void ShowAccountEntries(wxCommandEvent &accountData); void HideCalendarEntries(wxCommandEvent &calendarData); void ShowCalendarEntries(wxCommandEvent &calendarData); + void DeleteCalendarEntries(wxCommandEvent &calendarData); + void DeleteCalendarEntry(wxCommandEvent &eventData); + void AddCalendarEntry(wxCommandEvent &eventData); + void UpdateCalendarEntry(wxCommandEvent &eventData); + void UpdateCalendarColour(wxCommandEvent &colourData); public: XCCalendarCtrl(wxWindow *parent, CalendarDataStorage *storage); ~XCCalendarCtrl(); + DECLARE_EVENT_TABLE() diff --git a/source/widgets/XCCalendarDay.cpp b/source/widgets/XCCalendarDay.cpp index bde3504..14657b9 100644 --- a/source/widgets/XCCalendarDay.cpp +++ b/source/widgets/XCCalendarDay.cpp @@ -91,7 +91,12 @@ XCCalendarDay::XCCalendarDay(wxWindow *parent, const wxString& title, const wxPo Connect(ID_SHOWENTRIES, XCCALENDARDAY_SHOWACCOUNTENTRIES, wxCommandEventHandler(XCCalendarDay::ShowAccountEntries)); Connect(ID_HIDECALENDARENTRIES, XCCALENDARDAY_HIDECALENDARENTRIES, wxCommandEventHandler(XCCalendarDay::HideCalendarEntries)); Connect(ID_SHOWCALENDARENTRIES, XCCALENDARDAY_SHOWCALENDARENTRIES, wxCommandEventHandler(XCCalendarDay::ShowCalendarEntries)); - + Connect(ID_DELETECALENDARENTRIES, XCCALENDARDAY_DELETECALENDARENTRIES, wxCommandEventHandler(XCCalendarDay::DeleteCalendarEntries)); + Connect(ID_DELETEENTRY, XCCALENDARDAY_DELETEENTRY, wxCommandEventHandler(XCCalendarDay::DeleteCalendarEntry)); + Connect(ID_ADDENTRY, XCCALENDARDAY_ADDENTRY, wxCommandEventHandler(XCCalendarDay::AddCalendarEntry)); + Connect(ID_UPDATEENTRY, XCCALENDARDAY_UPDATEENTRY, wxCommandEventHandler(XCCalendarDay::UpdateCalendarEntry)); + Connect(ID_UPDATECOLOUR, XCCALENDARDAY_UPDATECALENDARCOLOUR, wxCommandEventHandler(XCCalendarDay::UpdateCalendarColour)); + } XCCalendarDay::~XCCalendarDay(){ @@ -258,6 +263,8 @@ void XCCalendarDay::DeselectAllEvent(wxCommandEvent &DeselectEvent) void XCCalendarDay::SetupControl(int SetupDay, int SetupMonth, int SetupYear, bool SetupIsInMonth, XCCalendarMonthView *MonthViewPointer, CalendarDataStorage *dataStorage, vector *hideAccounts, vector *hideCalendars) { + this->dataStorage = dataStorage; + // Set the day NumberText->SetLabel(wxString::Format("%02i", SetupDay)); @@ -308,7 +315,7 @@ void XCCalendarDay::SetupControl(int SetupDay, int SetupMonth, int SetupYear, bo for (vector::iterator hideAccountsItem = hideAccounts->begin(); hideAccountsItem != hideAccounts->end(); hideAccountsItem++){ - if (*hideAccountsItem = newEntryCalendarInfo.accountID){ + if (*hideAccountsItem == newEntryCalendarInfo.accountID){ newEntry->Show(false); newEntry->GetAfterSpacer()->Show(false); } @@ -323,7 +330,7 @@ void XCCalendarDay::SetupControl(int SetupDay, int SetupMonth, int SetupYear, bo if (*hideCalendarsItem == newEntryInfo.calendarID){ newEntry->Show(false); newEntry->GetAfterSpacer()->Show(false); - } + } } @@ -467,4 +474,189 @@ void XCCalendarDay::ShowCalendarEntries(wxCommandEvent &calendarData){ this->Refresh(); Repaint(); +} + +void XCCalendarDay::DeleteCalendarEntries(wxCommandEvent &calendarData){ + + vector::iterator> DeleteEntriesList; + + for (vector::iterator CalendarEntryIter = CalendarEntryList.begin(); + CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){ + + if ((*CalendarEntryIter)->GetCalendarID() == calendarData.GetInt()){ + + wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter)); + (*CalendarEntryIter)->Show(false); + + // Get the spacing and hide it as well. + + wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer(); + afterSpacer->Show(false); + afterSpacer->DetachSizer(); + + delete afterSpacer; + afterSpacer = nullptr; + + delete (*CalendarEntryIter); + DeleteEntriesList.push_back(CalendarEntryIter); + + } + + } + + this->Refresh(); + Repaint(); + + for (auto DeleteIter : DeleteEntriesList){ + CalendarEntryList.erase(DeleteIter); + } + +} + +void XCCalendarDay::DeleteCalendarEntry(wxCommandEvent &eventData){ + + vector::iterator> DeleteEntriesList; + + for (vector::iterator CalendarEntryIter = CalendarEntryList.begin(); + CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){ + + if ((*CalendarEntryIter)->GetEventID() == eventData.GetInt()){ + + wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter)); + (*CalendarEntryIter)->Show(false); + + // Get the spacing and hide it as well. + + wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer(); + afterSpacer->Show(false); + afterSpacer->DetachSizer(); + + delete afterSpacer; + afterSpacer = nullptr; + + delete (*CalendarEntryIter); + DeleteEntriesList.push_back(CalendarEntryIter); + + } + + } + + for (auto DeleteIter : DeleteEntriesList){ + CalendarEntryList.erase(DeleteIter); + } + + this->Refresh(); + Repaint(); + +} + +void XCCalendarDay::AddCalendarEntry(wxCommandEvent &eventData){ + + EventProperties *eventInfo = (EventProperties*)eventData.GetClientData(); + + XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(EventListFrame, eventInfo->eventName, wxDefaultPosition, wxDefaultSize, eventInfo->eventID); + + CDSGetCalendarInfo calendarInfo = dataStorage->GetCalendar(eventInfo->calendarID); + + newEntry->SetColour(&calendarInfo.calendarColour); + newEntry->SetTime(eventInfo->eventHour, eventInfo->eventMinute, eventInfo->eventSecond); + newEntry->SetEntryIDs(calendarInfo.accountID, eventInfo->calendarID, eventInfo->eventID); + + EventListFrameSizer->Add(newEntry, 0, wxEXPAND, 5); + wxSizerItem *afterSpacer = EventListFrameSizer->Add(0, 5, 0, 0, 5); + + newEntry->SetAfterSpacer(afterSpacer); + + // Go through the list of calendar entries to hide by account. + + for (vector::iterator hideAccountsItem = eventInfo->hideAccountsList.begin(); + hideAccountsItem != eventInfo->hideAccountsList.end(); hideAccountsItem++){ + + if (*hideAccountsItem = calendarInfo.accountID){ + newEntry->Show(false); + newEntry->GetAfterSpacer()->Show(false); + } + + } + + // Go through the list of calendar entries to hide by calendar. + + for (vector::iterator hideCalendarsItem = eventInfo->hideCalendarsList.begin(); + hideCalendarsItem != eventInfo->hideCalendarsList.end(); hideCalendarsItem++){ + + if (*hideCalendarsItem == eventInfo->calendarID){ + newEntry->Show(false); + newEntry->GetAfterSpacer()->Show(false); + } + + } + + CalendarEntryList.push_back(newEntry); + + this->Refresh(); + Repaint(); + +} + +void XCCalendarDay::UpdateCalendarEntry(wxCommandEvent &eventData){ + + // Go thorugh each of the entries in the day and + // then update it. + + EventProperties *eventInfo = (EventProperties*)eventData.GetClientData(); + + for (vector::iterator CalendarEntryIter = CalendarEntryList.begin(); + CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){ + + if ((*CalendarEntryIter)->GetEventID() == eventInfo->eventID){ + + (*CalendarEntryIter)->SetEventName(eventInfo->eventName); + (*CalendarEntryIter)->SetTime(eventInfo->eventHour, eventInfo->eventMinute, eventInfo->eventSecond); + + + } + + } + + delete eventInfo; + eventInfo = nullptr; + +} + +void XCCalendarDay::UpdateCalendarColour(wxCommandEvent &colourData){ + + // Go thorugh each of the entries in the day and + // then update it. + + ColourUpdateProperties *colourInfo = (ColourUpdateProperties*)colourData.GetClientData(); + + for (vector::iterator CalendarEntryIter = CalendarEntryList.begin(); + CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){ + + if ((*CalendarEntryIter)->GetCalendarID() == colourInfo->calendarID){ + + (*CalendarEntryIter)->SetColour(&colourInfo->newColour); + + } + + } + +} + +int XCCalendarDay::GetCalendarDay(){ + + return calendarDay; + +} + +int XCCalendarDay::GetCalendarMonth(){ + + return calendarMonth; + +} + +int XCCalendarDay::GetCalendarYear(){ + + return calendarYear; + } \ No newline at end of file diff --git a/source/widgets/XCCalendarDay.h b/source/widgets/XCCalendarDay.h index 6ce2186..98241a6 100644 --- a/source/widgets/XCCalendarDay.h +++ b/source/widgets/XCCalendarDay.h @@ -23,6 +23,7 @@ #include #include #include +#include #include "XCCalendarDayEntry.h" #include "XCCalendarMonthView.h" @@ -43,6 +44,7 @@ class XCCalendarDay: public wxPanel wxBoxSizer *EventListFrameSizer = new wxBoxSizer(wxVERTICAL); wxStaticBitmap *HighPriorityIcon = new wxStaticBitmap(this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize(32,32), 0); wxStaticBitmap *AlertIcon = new wxStaticBitmap(this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize(32,32), 0); + CalendarDataStorage *dataStorage = nullptr; wxBitmap AlertIconBitmap; wxBitmap PriorityIconBitmap; wxStaticText *NumberText = nullptr; @@ -54,7 +56,6 @@ class XCCalendarDay: public wxPanel bool IsInMonth = false; vector CalendarEntryList; - vector CalendarEntryListIndex; void Repaint(); @@ -63,6 +64,11 @@ class XCCalendarDay: public wxPanel void ShowAccountEntries(wxCommandEvent &accountData); void HideCalendarEntries(wxCommandEvent &calendarData); void ShowCalendarEntries(wxCommandEvent &calendarData); + void DeleteCalendarEntries(wxCommandEvent &calendarData); + void DeleteCalendarEntry(wxCommandEvent &eventData); + void AddCalendarEntry(wxCommandEvent &eventData); + void UpdateCalendarEntry(wxCommandEvent &eventData); + void UpdateCalendarColour(wxCommandEvent &colourData); public: XCCalendarDay(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size); @@ -73,6 +79,9 @@ class XCCalendarDay: public wxPanel void DeselectAllEvent(wxCommandEvent &DeselectEvent); void UpdateTopIcons(); void SetupControl(int SetupDay, int SetupMonth, int SetupYear, bool SetupIsInMonth, XCCalendarMonthView *MonthViewPointer, CalendarDataStorage *dataStorage, std::vector *hideAccounts, std::vector *hideCalendars); + int GetCalendarDay(); + int GetCalendarMonth(); + int GetCalendarYear(); DECLARE_EVENT_TABLE() diff --git a/source/widgets/XCCalendarDayEntry.cpp b/source/widgets/XCCalendarDayEntry.cpp index d2d9483..7ec8de0 100644 --- a/source/widgets/XCCalendarDayEntry.cpp +++ b/source/widgets/XCCalendarDayEntry.cpp @@ -21,7 +21,8 @@ BEGIN_EVENT_TABLE(XCCalendarDayEntry, wxPanel) EVT_PAINT(XCCalendarDayEntry::PaintFrameEvent) EVT_SIZE(XCCalendarDayEntry::ResizeFrameEvent) -EVT_LEFT_DOWN(XCCalendarDayEntry::LeftClick) +EVT_LEFT_UP(XCCalendarDayEntry::LeftClick) +EVT_RIGHT_UP(XCCalendarDayEntry::RightClick) END_EVENT_TABLE() using namespace std; @@ -30,7 +31,7 @@ XCCalendarDayEntry::XCCalendarDayEntry(wxWindow* parent, const wxString& title, : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){ DayPanel = parent->GetParent(); - entryID = id; + eventID = id; this->SetMinSize(wxSize(65, 30)); @@ -55,12 +56,19 @@ XCCalendarDayEntry::XCCalendarDayEntry(wxWindow* parent, const wxString& title, HighPriorityIcon->SetBitmap(PriorityIconBitmap); Connect(ID_ENTRYDESELECT, XCCALENDARDAYENTRY_DESELECT, wxCommandEventHandler(XCCalendarDayEntry::Deselect)); + AlarmIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); HighPriorityIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); EventText->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); EventTime->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); DayPanel->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + AlarmIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + HighPriorityIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + EventText->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + EventTime->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + DayPanel->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + UpdateInformation(); } @@ -200,12 +208,27 @@ void XCCalendarDayEntry::LeftClick(wxMouseEvent &MouseEvent){ this->SetBackgroundColour(wxColor(255,215,0)); wxCommandEvent DeselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES); - DeselectOthersEvent.SetInt(entryID); + DeselectOthersEvent.SetInt(eventID); DeselectOthersEvent.SetId(ID_DESELECTOTHERENTRIES); wxPostEvent(DayPanel, DeselectOthersEvent); } +void XCCalendarDayEntry::RightClick(wxMouseEvent &MouseEvent){ + + // Sent an event to the month view control. + + EventProperties *eventData = new EventProperties; + eventData->calendarID = calendarID; + eventData->eventID = eventID; + + wxCommandEvent eventMenu(XCCALENDARMONTH_DISPLAYEVENTMENU); + eventMenu.SetClientData(eventData); + eventMenu.SetId(ID_DISPLAYEVENTMENU); + wxPostEvent(this->GetParent()->GetParent(), eventMenu); + +} + void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){ this->SetBackgroundColour(wxNullColour); @@ -258,7 +281,7 @@ bool XCCalendarDayEntry::GetDisplayHighPriority(){ int XCCalendarDayEntry::GetID(){ - return entryID; + return eventID; } @@ -268,6 +291,12 @@ int XCCalendarDayEntry::GetCalendarID(){ } +int XCCalendarDayEntry::GetEventID(){ + + return eventID; + +} + int XCCalendarDayEntry::GetAccountID(){ return accountID; @@ -310,11 +339,11 @@ string XCCalendarDayEntry::BuildEventTime(int timeHour, int timeMinute){ } -void XCCalendarDayEntry::SetEntryIDs(int accountID, int calendarID, int entryID){ +void XCCalendarDayEntry::SetEntryIDs(int accountID, int calendarID, int eventID){ this->accountID = accountID; this->calendarID = calendarID; - this->entryID = entryID; + this->eventID = eventID; } @@ -324,6 +353,12 @@ void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){ } +void XCCalendarDayEntry::SetEventName(string eventName){ + + EventText->SetLabel((wxString)eventName); + +} + wxSizerItem* XCCalendarDayEntry::GetAfterSpacer(){ return afterSpacer; diff --git a/source/widgets/XCCalendarDayEntry.h b/source/widgets/XCCalendarDayEntry.h index 4a74af7..84f6378 100644 --- a/source/widgets/XCCalendarDayEntry.h +++ b/source/widgets/XCCalendarDayEntry.h @@ -27,6 +27,8 @@ #include "../common/events.h" #include "../bitmaps.h" +#include "structs.h" + enum XCCalendarDayEntryMode { XCCALENDARDAYENTRY_NORMAL, XCCALENDARDAYENTRY_SMALL, @@ -56,7 +58,7 @@ class XCCalendarDayEntry: public wxPanel bool HasHighPriority = false; int PositionMode = 0; - int entryID = 0; + int eventID = 0; int accountID = 0; int calendarID =0; bool showAccount = true; @@ -74,6 +76,8 @@ class XCCalendarDayEntry: public wxPanel string BuildEventTime(int timeHour, int timeMinute); protected: + void LeftClick(wxMouseEvent &MouseEvent); + void RightClick(wxMouseEvent &MouseEvent); public: XCCalendarDayEntry(wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size, const int id); @@ -81,17 +85,18 @@ class XCCalendarDayEntry: public wxPanel void PaintFrameEvent(wxPaintEvent &PaintEvent); void ResizeFrameEvent(wxSizeEvent &SizeEvent); - void LeftClick(wxMouseEvent &MouseEvent); void Deselect(wxCommandEvent &DeselectEvent); void SetTime(int timeHour, int timeMinute, int timeSecond); void SetColour(Colour *ColourIn); void SetDisplayAlarm(bool DisplayValue); void SetDisplayHighPriority(bool DisplayValue); - void SetEntryIDs(int accountID, int calendarID, int entryID); + void SetEntryIDs(int accountID, int calendarID, int eventID); void SetAfterSpacer(wxSizerItem *afterSpacer); + void SetEventName(std::string eventName); int GetID(); int GetCalendarID(); + int GetEventID(); int GetAccountID(); wxSizerItem* GetAfterSpacer(); bool GetDisplayAlarm(); diff --git a/source/widgets/XCCalendarList.cpp b/source/widgets/XCCalendarList.cpp index 84662bd..4ee85ac 100644 --- a/source/widgets/XCCalendarList.cpp +++ b/source/widgets/XCCalendarList.cpp @@ -55,7 +55,11 @@ void XCCalendarList::UpdateCalendarList(CalendarDataStorage *dataStorage){ } - // TODO: Delete the old controls. + // Delete the old controls. Remember which setting the checkboxes were hidden so they + // can be restored later on. + + vector calendarHiddenAccountsList = GetHiddenAccountsList(); + vector calendarHiddenCalendarsList = GetHiddenCalendarsList(); for (vector::iterator accountCtrlIter = accountControlList.begin(); accountCtrlIter != accountControlList.end(); accountCtrlIter++){ @@ -76,9 +80,16 @@ void XCCalendarList::UpdateCalendarList(CalendarDataStorage *dataStorage){ XCCalendarListAccountCtrl *newAccountCtrl = new XCCalendarListAccountCtrl(this, accountListData.accountList[AccountSeek].accountName); newAccountCtrl->SetAccountID(accountListData.accountList[AccountSeek].accountID); + newAccountCtrl->SetAccountPreferencesID(accountListData.accountList[AccountSeek].accountPreferencesID); szrMain->Add(newAccountCtrl, 0, wxEXPAND, 5); + if (find(calendarHiddenAccountsList.begin(), calendarHiddenAccountsList.end(), accountListData.accountList[AccountSeek].accountID) != calendarHiddenAccountsList.end()){ + + newAccountCtrl->SetCheckBoxValue(wxCHK_UNCHECKED); + + } + accountControlList.push_back(newAccountCtrl); // Get the list of calendars and create controls. @@ -92,6 +103,14 @@ void XCCalendarList::UpdateCalendarList(CalendarDataStorage *dataStorage){ XCCalendarListCalendarCtrl *newCalendarCtrl = new XCCalendarListCalendarCtrl(this, calendarInfo.calendarName, calendarInfo.calendarColour); newCalendarCtrl->SetCalendarID(accountCalendarList.calendarList[calendarSeek]); + newCalendarCtrl->SetAccountPreferencesID(accountListData.accountList[AccountSeek].accountPreferencesID); + + if (find(calendarHiddenCalendarsList.begin(), calendarHiddenCalendarsList.end(), accountCalendarList.calendarList[calendarSeek]) != calendarHiddenCalendarsList.end()){ + + newCalendarCtrl->SetCheckBoxValue(wxCHK_UNCHECKED); + + } + newAccountCtrl->AddCalendar(newCalendarCtrl); szrMain->Add(newCalendarCtrl, 0, wxEXPAND, 5); diff --git a/source/widgets/XCCalendarListAccountCtrl.cpp b/source/widgets/XCCalendarListAccountCtrl.cpp index 5674da7..46d0e36 100644 --- a/source/widgets/XCCalendarListAccountCtrl.cpp +++ b/source/widgets/XCCalendarListAccountCtrl.cpp @@ -126,6 +126,12 @@ void XCCalendarListAccountCtrl::SetAccountID(int accountID){ } +void XCCalendarListAccountCtrl::SetAccountPreferencesID(int accountID){ + + this->accountPreferencesID = accountPreferencesID; + +} + vector XCCalendarListAccountCtrl::GetHiddenCalendarList(){ vector calendarList; @@ -143,4 +149,16 @@ vector XCCalendarListAccountCtrl::GetHiddenCalendarList(){ return calendarList; +} + +void XCCalendarListAccountCtrl::SetCheckBoxValue(wxCheckBoxState newValue){ + + if (newValue == wxCHK_CHECKED){ + showAccounts = true; + } else { + showAccounts = false; + } + + chkShowAll->SetValue(newValue); + } \ No newline at end of file diff --git a/source/widgets/XCCalendarListAccountCtrl.h b/source/widgets/XCCalendarListAccountCtrl.h index da782bb..737d62a 100644 --- a/source/widgets/XCCalendarListAccountCtrl.h +++ b/source/widgets/XCCalendarListAccountCtrl.h @@ -38,6 +38,7 @@ class XCCalendarListAccountCtrl: public wxPanel{ protected: std::vector calendarControlList; int accountID = 0; + int accountPreferencesID = 0; AccountType accountType = ACCOUNTTYPE_UNKNOWN; std::string accountName = ""; bool showAccounts = true; @@ -50,6 +51,8 @@ class XCCalendarListAccountCtrl: public wxPanel{ wxCheckBoxState GetShowCheckboxState(); int GetAccountID(); void SetAccountID(int accountID); + void SetAccountPreferencesID(int accountID); + void SetCheckBoxValue(wxCheckBoxState newValue); std::vector GetHiddenCalendarList(); DECLARE_EVENT_TABLE(); diff --git a/source/widgets/XCCalendarListCalendarCtrl.cpp b/source/widgets/XCCalendarListCalendarCtrl.cpp index 758fb4b..3729231 100644 --- a/source/widgets/XCCalendarListCalendarCtrl.cpp +++ b/source/widgets/XCCalendarListCalendarCtrl.cpp @@ -30,8 +30,6 @@ XCCalendarListCalendarCtrl::XCCalendarListCalendarCtrl(wxWindow* parent, string // Setup the checkbox. - //chkShowAll = new wxCheckBox(); - chkShowCalendar = new wxCheckBox(this, wxID_ANY, "", wxPoint(0,0), wxDefaultSize, wxCHK_3STATE, wxDefaultValidator, ""); // Setup the label. @@ -43,6 +41,12 @@ XCCalendarListCalendarCtrl::XCCalendarListCalendarCtrl(wxWindow* parent, string pnlColour = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(16,16), 0, ""); pnlColour->SetBackgroundColour(wxColour(calendarColour.red, calendarColour.green, calendarColour.blue, calendarColour.alpha)); + // Setup the popup menu. + + calendarMenu = new XCCalendarMenu(); + calendarMenu->SetWindowPointer(this); + calendarMenu->SetPopupPointer((wxPopupTransientWindow*)this->GetParent()); + // Connect them to the sizer. szrMain->Add(15, 0, 0, 0, 5); @@ -53,6 +57,10 @@ XCCalendarListCalendarCtrl::XCCalendarListCalendarCtrl(wxWindow* parent, string // Connect the events to the controls. chkShowCalendar->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxMouseEventHandler(XCCalendarListCalendarCtrl::ShowAllCheckboxClick), NULL, this); + chkShowCalendar->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this); + lblCalendarName->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this); + pnlColour->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this); + Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this); chkShowCalendar->SetValue(wxCHK_CHECKED); } @@ -78,6 +86,14 @@ int XCCalendarListCalendarCtrl::GetCalendarID(){ void XCCalendarListCalendarCtrl::SetCalendarID(int calendarID){ this->calendarID = calendarID; + calendarMenu->SetCalendarID(this->calendarID); + +} + +void XCCalendarListCalendarCtrl::SetAccountPreferencesID(int accountPreferencesID){ + + this->accountPreferencesID = accountPreferencesID; + calendarMenu->SetAccountPreferencesID(this->accountPreferencesID); } @@ -99,4 +115,22 @@ void XCCalendarListCalendarCtrl::ShowAllCheckboxClick( wxMouseEvent &mouseEvent } +} + +void XCCalendarListCalendarCtrl::SetCheckBoxValue(wxCheckBoxState newValue){ + + if (newValue == wxCHK_CHECKED){ + showCalendar = true; + } else { + showCalendar = false; + } + + chkShowCalendar->SetValue(newValue); + +} + +void XCCalendarListCalendarCtrl::PopupMenu( wxMouseEvent &mouseEvent ){ + + this->GetParent()->GetParent()->GetParent()->GetParent()->PopupMenu(calendarMenu->MenuPointer(), wxDefaultPosition); + } \ No newline at end of file diff --git a/source/widgets/XCCalendarListCalendarCtrl.h b/source/widgets/XCCalendarListCalendarCtrl.h index 3463f94..39c982a 100644 --- a/source/widgets/XCCalendarListCalendarCtrl.h +++ b/source/widgets/XCCalendarListCalendarCtrl.h @@ -26,6 +26,7 @@ #include "types.h" #include "colour.h" #include "events.h" +#include "XCCalendarMenu.h" class XCCalendarListCalendarCtrl: public wxPanel{ @@ -34,18 +35,23 @@ class XCCalendarListCalendarCtrl: public wxPanel{ wxCheckBox *chkShowCalendar = nullptr; wxStaticText *lblCalendarName = nullptr; wxStaticBitmap *imgCalendarIcon = nullptr; + XCCalendarMenu *calendarMenu = nullptr; wxPanel *pnlColour = nullptr; + int accountPreferencesID = 0; protected: int calendarID = 0; std::string calendarName = ""; bool showCalendar = true; void ShowAllCheckboxClick( wxMouseEvent &mouseEvent ); + void PopupMenu( wxMouseEvent &mouseEvent ); public: XCCalendarListCalendarCtrl(wxWindow* parent, string calendarName, Colour calendarColour); ~XCCalendarListCalendarCtrl(); wxCheckBoxState GetShowCheckboxState(); int GetCalendarID(); void SetCalendarID(int calendarID); + void SetAccountPreferencesID(int accountID); + void SetCheckBoxValue(wxCheckBoxState newValue); }; diff --git a/source/widgets/XCCalendarMonthView.cpp b/source/widgets/XCCalendarMonthView.cpp index ffc2346..bd29758 100644 --- a/source/widgets/XCCalendarMonthView.cpp +++ b/source/widgets/XCCalendarMonthView.cpp @@ -36,6 +36,8 @@ XCCalendarMonthView::XCCalendarMonthView(wxWindow *parent, const wxString& title FridayText = new XCCalendarMonthViewDayTitle(this, _("Friday"), wxDefaultPosition, wxDefaultSize); SaturdayText = new XCCalendarMonthViewDayTitle(this, _("Saturday"), wxDefaultPosition, wxDefaultSize); SundayText = new XCCalendarMonthViewDayTitle(this, _("Sunday"), wxDefaultPosition, wxDefaultSize); + + eventMenu = new XCEventMenu; WindowSizer->Add(MondayText, 1, wxEXPAND|wxALL, 0); WindowSizer->Add(TuesdayText, 1, wxEXPAND|wxALL, 0); @@ -71,7 +73,13 @@ XCCalendarMonthView::XCCalendarMonthView(wxWindow *parent, const wxString& title Connect(ID_SHOWENTRIES, XCCALENDARMONTH_SHOWACCOUNTENTRIES, wxCommandEventHandler(XCCalendarMonthView::ShowAccountEntries)); Connect(ID_HIDECALENDARENTRIES, XCCALENDARMONTH_HIDECALENDARENTRIES, wxCommandEventHandler(XCCalendarMonthView::HideCalendarEntries)); Connect(ID_SHOWCALENDARENTRIES, XCCALENDARMONTH_SHOWCALENDARENTRIES, wxCommandEventHandler(XCCalendarMonthView::ShowCalendarEntries)); - + Connect(ID_DELETECALENDARENTRIES, XCCALENDARMONTH_DELETECALENDARENTRIES, wxCommandEventHandler(XCCalendarMonthView::DeleteCalendarEntries)); + Connect(ID_DISPLAYEVENTMENU, XCCALENDARMONTH_DISPLAYEVENTMENU, wxCommandEventHandler(XCCalendarMonthView::ShowEventMenu)); + Connect(ID_DELETEENTRY, XCCALENDARMONTH_DELETEENTRY, wxCommandEventHandler(XCCalendarMonthView::DeleteCalendarEntry)); + Connect(ID_ADDENTRY, XCCALENDARMONTH_ADDENTRY, wxCommandEventHandler(XCCalendarMonthView::AddCalendarEntry)); + Connect(ID_UPDATEENTRY, XCCALENDARMONTH_UPDATEENTRY, wxCommandEventHandler(XCCalendarMonthView::UpdateCalendarEntry)); + Connect(ID_UPDATECOLOUR, XCCALENDARMONTH_UPDATECALENDARCOLOUR, wxCommandEventHandler(XCCalendarMonthView::UpdateCalendarColour)); + } XCCalendarMonthView::XCCalendarMonthView(XCCalendarMonthViewGrid *grid, CalendarDataStorage *dataStorage, std::vector *hideAccounts, std::vector *hideCalendars) @@ -263,4 +271,138 @@ void XCCalendarMonthView::ShowCalendarEntries(wxCommandEvent &accountData){ } +} + +void XCCalendarMonthView::DeleteCalendarEntries(wxCommandEvent &calendarData){ + + for (vector::iterator DayIter = CalendarDayList.begin(); + DayIter != CalendarDayList.end(); DayIter++){ + + wxCommandEvent deleteEvent(XCCALENDARDAY_DELETECALENDARENTRIES); + deleteEvent.SetInt(calendarData.GetInt()); + deleteEvent.SetId(ID_DELETECALENDARENTRIES); + wxPostEvent((*DayIter), deleteEvent); + + } + +} + +void XCCalendarMonthView::DeleteCalendarEntry(wxCommandEvent &eventData){ + + for (vector::iterator DayIter = CalendarDayList.begin(); + DayIter != CalendarDayList.end(); DayIter++){ + + wxCommandEvent deleteEvent(XCCALENDARDAY_DELETEENTRY); + deleteEvent.SetInt(eventData.GetInt()); + deleteEvent.SetId(ID_DELETEENTRY); + wxPostEvent((*DayIter), deleteEvent); + + } + +} + +void XCCalendarMonthView::AddCalendarEntry(wxCommandEvent &eventData){ + + EventProperties *eventInfo = (EventProperties*)eventData.GetClientData(); + bool foundDate = false; + + for (vector::iterator DayIter = CalendarDayList.begin(); + DayIter != CalendarDayList.end(); DayIter++){ + + // Check if the date matches with the date in the day + // widget. If it does, add the widget. + + if ((*DayIter)->GetCalendarYear() == eventInfo->eventYear && + (*DayIter)->GetCalendarMonth() == (eventInfo->eventMonth + 1) && + (*DayIter)->GetCalendarDay() == eventInfo->eventDay){ + + wxCommandEvent addEvent(XCCALENDARDAY_ADDENTRY); + addEvent.SetId(ID_ADDENTRY); + addEvent.SetClientData(eventInfo); + wxPostEvent((*DayIter), addEvent); + foundDate = true; + break; + + } + + } + + if (foundDate == false){ + + delete eventInfo; + eventInfo = nullptr; + + } + +} + +void XCCalendarMonthView::UpdateCalendarEntry(wxCommandEvent &eventData){ + + EventProperties *eventInfo = (EventProperties*)eventData.GetClientData(); + bool foundDate = false; + + for (vector::iterator DayIter = CalendarDayList.begin(); + DayIter != CalendarDayList.end(); DayIter++){ + + // Check if the date matches with the date in the day + // widget. If it does, update the widget. + + if ((*DayIter)->GetCalendarYear() == eventInfo->eventYear && + (*DayIter)->GetCalendarMonth() == (eventInfo->eventMonth + 1) && + (*DayIter)->GetCalendarDay() == eventInfo->eventDay){ + + wxCommandEvent addEvent(XCCALENDARDAY_UPDATEENTRY); + addEvent.SetId(ID_UPDATEENTRY); + addEvent.SetClientData(eventInfo); + wxPostEvent((*DayIter), addEvent); + foundDate = true; + break; + + } + + } + + if (foundDate == false){ + + delete eventInfo; + eventInfo = nullptr; + + } + +} + +void XCCalendarMonthView::UpdateCalendarColour(wxCommandEvent &colourData){ + + ColourUpdateProperties *colourDataInfo = (ColourUpdateProperties*)colourData.GetClientData(); + + for (vector::iterator DayIter = CalendarDayList.begin(); + DayIter != CalendarDayList.end(); DayIter++){ + + // Check if the date matches with the date in the day + // widget. If it does, update the widget. + + ColourUpdateProperties *colourDataPassInfo = colourDataInfo; + + wxCommandEvent updateColour(XCCALENDARDAY_UPDATECALENDARCOLOUR); + updateColour.SetId(ID_UPDATECOLOUR); + updateColour.SetClientData(colourDataPassInfo); + wxPostEvent((*DayIter), updateColour); + + } + +} + +void XCCalendarMonthView::ShowEventMenu(wxCommandEvent &eventData){ + + EventProperties *eventInfo = (EventProperties*)eventData.GetClientData(); + + eventMenu->SetEventID(eventInfo->eventID); + eventMenu->SetCalendarID(eventInfo->calendarID); + eventMenu->SetWindowPointer(this->GetParent()->GetParent()); + + this->PopupMenu(eventMenu, wxDefaultPosition); + + delete eventInfo; + eventInfo = nullptr; + } \ No newline at end of file diff --git a/source/widgets/XCCalendarMonthView.h b/source/widgets/XCCalendarMonthView.h index b0bc5ea..6f06d0a 100644 --- a/source/widgets/XCCalendarMonthView.h +++ b/source/widgets/XCCalendarMonthView.h @@ -22,16 +22,18 @@ #include #include -#include "../common/colour.h" -#include "../common/text.h" -#include "../common/events.h" -#include "../common/monthviewgen.h" +#include "colour.h" +#include "text.h" +#include "events.h" +#include "monthviewgen.h" +#include "structs.h" #include "../libraries/CalendarDataStorage/CalendarDataStorage.h" #include "XCCalendarMonthView.h" #include "XCCalendarMonthViewDayTitle.h" #include "XCCalendarDay.h" +#include "XCEventMenu.h" class XCCalendarDay; @@ -49,7 +51,9 @@ class XCCalendarMonthView: public wxPanel XCCalendarMonthViewDayTitle *FridayText = nullptr; XCCalendarMonthViewDayTitle *SaturdayText = nullptr; XCCalendarMonthViewDayTitle *SundayText = nullptr; + XCEventMenu *eventMenu = nullptr; CalendarDataStorage *calendarStorage = nullptr; + void ProcessGrid(XCCalendarMonthViewGrid *grid, std::vector *hideAccounts, std::vector *hideCalendars); void Repaint(); @@ -59,6 +63,12 @@ class XCCalendarMonthView: public wxPanel void ShowAccountEntries(wxCommandEvent &accountData); void HideCalendarEntries(wxCommandEvent &calendarData); void ShowCalendarEntries(wxCommandEvent &calendarData); + void DeleteCalendarEntries(wxCommandEvent &calendarData); + void DeleteCalendarEntry(wxCommandEvent &eventData); + void AddCalendarEntry(wxCommandEvent &eventData); + void UpdateCalendarEntry(wxCommandEvent &eventData); + void UpdateCalendarColour(wxCommandEvent &colourData); + void ShowEventMenu(wxCommandEvent &eventData); public: XCCalendarMonthView(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size, XCCalendarMonthViewGrid *grid, CalendarDataStorage *dataStorage, std::vector *hideAccounts, std::vector *hideCalendars);