Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
widgets: Cleanup objects in destructors and minor code cleanup
[xestiacalendar/.git] / source / widgets / XCCalendarDay.cpp
index 37ce112..656ad75 100644 (file)
 
 using namespace std;
 
+wxDEFINE_EVENT(XCCALENDARDAY_DESELECTOTHERENTRIES, wxCommandEvent);
+wxDEFINE_EVENT(XCCALENDARDAY_DESELECTALLENTRIES, wxCommandEvent);
+wxDEFINE_EVENT(XCCALENDARDAY_HIDEACCOUNTENTRIES, wxCommandEvent);
+wxDEFINE_EVENT(XCCALENDARDAY_SHOWACCOUNTENTRIES, wxCommandEvent);
+wxDEFINE_EVENT(XCCALENDARDAY_HIDECALENDARENTRIES, wxCommandEvent);
+wxDEFINE_EVENT(XCCALENDARDAY_SHOWCALENDARENTRIES, wxCommandEvent);
+wxDEFINE_EVENT(XCCALENDARDAY_DELETECALENDARENTRIES, wxCommandEvent);
+wxDEFINE_EVENT(XCCALENDARDAY_DELETEENTRY, wxCommandEvent);
+wxDEFINE_EVENT(XCCALENDARDAY_ADDENTRY, wxCommandEvent);
+wxDEFINE_EVENT(XCCALENDARDAY_UPDATEENTRY, wxCommandEvent);
+wxDEFINE_EVENT(XCCALENDARDAY_UPDATECALENDARCOLOUR, wxCommandEvent);
+
 BEGIN_EVENT_TABLE(XCCalendarDay, wxPanel)
-EVT_PAINT(XCCalendarDay::PaintFrameEvent)
-EVT_SIZE(XCCalendarDay::ResizeFrameEvent)
-//EVT_COMMAND(wxID_ANY, XCCALENDARDAY_DESELECTOTHERENTRIES, XCCalendarDay::DeselectOthersEvent)
 END_EVENT_TABLE()
 
 XCCalendarDay::XCCalendarDay(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size)
         : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
-       
-       Connect(wxID_ANY, XCCALENDARDAY_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectOthersEvent));
-       
        this->SetMinSize( wxSize( 100,100 ) );
        
-       AlertIconBitmap.LoadFile("AlertIcon-32.png", wxBITMAP_DEFAULT_TYPE);
-       PriorityIconBitmap.LoadFile("PriorityIcon-32.png", wxBITMAP_DEFAULT_TYPE);
+       // Setup the top panel.
+               
+       topPanel = new wxPanel(this, wxID_ANY, wxPoint(0,0), wxSize(50, 40), wxTAB_TRAVERSAL);
+       mainPanel = new wxPanel(this, wxID_ANY, wxPoint(0,0), wxSize(200, 200), wxTAB_TRAVERSAL);
+               
+       // Setip the icons.
+               
+       highPriorityIcon = new wxStaticBitmap(topPanel, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize(32,32), 0);
+       alertIcon = new wxStaticBitmap(topPanel, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize(32,32), 0);
+               
+       wxMemoryInputStream alerticon(icons_alert32_png, sizeof(icons_alert32_png));
+       wxMemoryInputStream priorityicon(icons_priority32_png, sizeof(icons_priority32_png));
        
-       AlertIcon->SetBitmap(AlertIconBitmap);
-       HighPriorityIcon->SetBitmap(PriorityIconBitmap);        
+       wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
+       wxBitmap imgAlertIcon(icons_alert_png, -1);
+
+       wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
+       wxBitmap imgPriorityIcon(icons_priority_png, -1);
        
-       WindowSizer->AddGrowableCol(0);
-       WindowSizer->AddGrowableRow(1);
-       WindowSizer->SetFlexibleDirection( wxBOTH );
-       WindowSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
+       alertIcon->SetBitmap(imgAlertIcon);
+       highPriorityIcon->SetBitmap(imgPriorityIcon);
        
-       NumberText = new wxStaticText(this, wxID_ANY, wxT("09"), wxDefaultPosition, wxDefaultSize, 0);
-       NumberText->SetFont(wxFont(24, 70, 90, 92, false, wxEmptyString));
+       numberText = new wxStaticText(topPanel, wxID_ANY, wxT("09"), wxDefaultPosition, wxDefaultSize, 0);
+       numberText->SetFont(wxFont(24, 70, 90, 92, false, wxEmptyString));
        
-       TopSectionSizer->Add(HighPriorityIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
-       TopSectionSizer->Add(AlertIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
-       TopSectionSizer->Add(0, 0, 1, wxEXPAND, 5);
-       TopSectionSizer->Add(NumberText, 0, wxALL|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
+       topSectionSizer->Add(highPriorityIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
+       topSectionSizer->Add(alertIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
+       topSectionSizer->Add(0, 0, 1, wxEXPAND, 5);
+       topSectionSizer->Add(numberText, 0, wxALL|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
 
        // Setup the scrollable section.
        
-       Colour EventColour;
-       EventColour.red = 40; EventColour.green = 80; EventColour.blue = 80;
-       
-       EventListFrame->SetSizer(EventListFrameSizer);
-       CalendarEntry1->SetColour(&EventColour);
-       CalendarEntry1->SetDisplayAlarm(false);
-       CalendarEntry1->SetDisplayHighPriority(false);
-       EventListFrameSizer->Add(CalendarEntry1, 0, wxEXPAND, 5);
-       EventListFrameSizer->Add(0, 5, 0, 0, 5);
-       
-       EventColour.red = 255; EventColour.green = 0; EventColour.blue = 0;
-       CalendarEntry2->SetColour(&EventColour);
-       CalendarEntry2->SetDisplayAlarm(true);
-       CalendarEntry2->SetDisplayHighPriority(false);
-       EventListFrameSizer->Add(CalendarEntry2, 0, wxEXPAND, 5);
-       EventListFrameSizer->Add(0, 5, 0, 0, 5);
-       
-       EventColour.red = 0; EventColour.green = 255; EventColour.blue = 0;
-       CalendarEntry3->SetColour(&EventColour);
-       CalendarEntry3->SetDisplayAlarm(false);
-       CalendarEntry3->SetDisplayHighPriority(false);
-       EventListFrameSizer->Add(CalendarEntry3, 0, wxEXPAND, 5);
-       EventListFrameSizer->Add(0, 5, 0, 0, 5);
-
-       EventColour.red = 0; EventColour.green = 0; EventColour.blue = 255;
-       CalendarEntry4->SetColour(&EventColour);
-       CalendarEntry4->SetDisplayAlarm(false);
-       CalendarEntry4->SetDisplayHighPriority(false);
-       EventListFrameSizer->Add(CalendarEntry4, 0, wxEXPAND, 5);
-       EventListFrameSizer->Add(0, 5, 0, 0, 5);
-       
-       EventListFrameSizer->Add(CalendarEntry5, 0, wxEXPAND, 5);
-       EventListFrameSizer->Add(0, 5, 0, 0, 5);
-       EventListFrameSizer->Add(CalendarEntry6, 0, wxEXPAND, 5);
-       EventListFrameSizer->Add(0, 5, 0, 0, 5);
-       EventListFrameSizer->Add(CalendarEntry7, 0, wxEXPAND, 5);
-       EventListFrameSizer->Add(0, 5, 0, 0, 5);
-       EventListFrameSizer->Add(CalendarEntry8, 0, wxEXPAND, 5);
-       EventListFrameSizer->Add(0, 5, 0, 0, 5);
-       EventListFrameSizer->Add(CalendarEntry9, 0, wxEXPAND, 5);
-       EventListFrameSizer->Add(0, 5, 0, 0, 5);
-       EventListFrameSizer->Add(CalendarEntry10, 0, wxEXPAND, 5);
-
-       EventListFrame->SetScrollRate(0,1);
-       //EventListFrameSizer->FitInside(EventListFrame);
-       EventListFrameSizer->Fit(EventListFrame);
-       EventListFrameSizer->Layout();
-       WindowSizer->Fit(this);
+       eventListFrame = new wxScrolledWindow(mainPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL);
+       
+       Colour eventColour;
+       eventColour.red = 40; eventColour.green = 80; eventColour.blue = 80;
+       
+       eventListFrame->SetSizer(eventListFrameSizer);
+
+       eventListFrame->SetScrollRate(0,1);
+       eventListFrameSizer->Fit(eventListFrame);
+       eventListFrameSizer->Layout();
 
        // Setup the scroll window.
        
-       WindowSizer->Add(TopSectionSizer, 1, wxEXPAND, 5);
-       WindowSizer->Add(MainSectionSizer, 1, wxEXPAND, 5);
-       MainSectionSizer->Add(EventListFrame, 1, wxGROW | wxALL, 10);
+       mainSectionSizer->Add(eventListFrame, 1, wxGROW | wxALL, 5);
+       
+       topPanel->SetSizer(topSectionSizer);
+       mainPanel->SetSizer(mainSectionSizer);
+       
+       windowSizer->Add(topPanel, 1, wxEXPAND, 0);
+       windowSizer->Add(mainPanel, 1, wxEXPAND, 0);
 
-       this->SetSizer(WindowSizer);
+       this->SetSizer(windowSizer);
        this->SetSize(size);
        this->Layout();
-       this->SetBackgroundStyle(wxBG_STYLE_PAINT);
        this->Centre(wxBOTH);
        
-       CalendarEntryList.push_back(CalendarEntry1);
-       CalendarEntryList.push_back(CalendarEntry2);
-       CalendarEntryList.push_back(CalendarEntry3);
-       CalendarEntryList.push_back(CalendarEntry4);
-       CalendarEntryList.push_back(CalendarEntry5);
-       CalendarEntryList.push_back(CalendarEntry6);
-       CalendarEntryList.push_back(CalendarEntry7);
-       CalendarEntryList.push_back(CalendarEntry8);
-       CalendarEntryList.push_back(CalendarEntry9);
-       CalendarEntryList.push_back(CalendarEntry10);
-       
        UpdateTopIcons();
        
+       // Bind events to the control.
+       
+       Bind(XCCALENDARDAY_DESELECTOTHERENTRIES, &XCCalendarDay::DeselectOthersEvent, this, ID_DESELECTOTHERENTRIES);
+       Bind(XCCALENDARDAY_DESELECTALLENTRIES, &XCCalendarDay::DeselectAllEvent, this, ID_DESELECTALLITEMS);
+       Bind(XCCALENDARDAY_HIDEACCOUNTENTRIES, &XCCalendarDay::HideAccountEntries, this, ID_HIDEENTRIES);
+       Bind(XCCALENDARDAY_SHOWACCOUNTENTRIES, &XCCalendarDay::ShowAccountEntries, this, ID_SHOWENTRIES);
+       Bind(XCCALENDARDAY_HIDECALENDARENTRIES, &XCCalendarDay::HideCalendarEntries, this, ID_HIDECALENDARENTRIES);
+       Bind(XCCALENDARDAY_SHOWCALENDARENTRIES, &XCCalendarDay::ShowCalendarEntries, this, ID_SHOWCALENDARENTRIES);
+       Bind(XCCALENDARDAY_DELETECALENDARENTRIES, &XCCalendarDay::DeleteCalendarEntries, this, ID_DELETECALENDARENTRIES);
+       Bind(XCCALENDARDAY_DELETEENTRY, &XCCalendarDay::DeleteCalendarEntry, this, ID_DELETEENTRY);
+       Bind(XCCALENDARDAY_ADDENTRY, &XCCalendarDay::AddCalendarEntry, this, ID_ADDENTRY);
+       Bind(XCCALENDARDAY_UPDATEENTRY, &XCCalendarDay::UpdateCalendarEntry, this, ID_UPDATEENTRY);
+       Bind(XCCALENDARDAY_UPDATECALENDARCOLOUR, &XCCalendarDay::UpdateCalendarColour, this, ID_UPDATECOLOUR);
 }
 
 XCCalendarDay::~XCCalendarDay(){
        
        // Destory the controls from the widget.
        
-}
+       Unbind(XCCALENDARDAY_DESELECTOTHERENTRIES, &XCCalendarDay::DeselectOthersEvent, this, ID_DESELECTOTHERENTRIES);
+       Unbind(XCCALENDARDAY_DESELECTALLENTRIES, &XCCalendarDay::DeselectAllEvent, this, ID_DESELECTALLITEMS);
+       Unbind(XCCALENDARDAY_HIDEACCOUNTENTRIES, &XCCalendarDay::HideAccountEntries, this, ID_HIDEENTRIES);
+       Unbind(XCCALENDARDAY_SHOWACCOUNTENTRIES, &XCCalendarDay::ShowAccountEntries, this, ID_SHOWENTRIES);
+       Unbind(XCCALENDARDAY_HIDECALENDARENTRIES, &XCCalendarDay::HideCalendarEntries, this, ID_HIDECALENDARENTRIES);
+       Unbind(XCCALENDARDAY_SHOWCALENDARENTRIES, &XCCalendarDay::ShowCalendarEntries, this, ID_SHOWCALENDARENTRIES);
+       Unbind(XCCALENDARDAY_DELETECALENDARENTRIES, &XCCalendarDay::DeleteCalendarEntries, this, ID_DELETECALENDARENTRIES);
+       Unbind(XCCALENDARDAY_DELETEENTRY, &XCCalendarDay::DeleteCalendarEntry, this, ID_DELETEENTRY);
+       Unbind(XCCALENDARDAY_ADDENTRY, &XCCalendarDay::AddCalendarEntry, this, ID_ADDENTRY);
+       Unbind(XCCALENDARDAY_UPDATEENTRY, &XCCalendarDay::UpdateCalendarEntry, this, ID_UPDATEENTRY);
+       Unbind(XCCALENDARDAY_UPDATECALENDARCOLOUR, &XCCalendarDay::UpdateCalendarColour, this, ID_UPDATECOLOUR);
+       
+       for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
+               calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
+                       
+               delete((*calendarEntryIter));
+                       
+       }
 
-void XCCalendarDay::Repaint(){
+       eventListFrameSizer->Clear();
        
-       wxPaintDC dc(this);
-       wxPaintDC EventListFrameDC(EventListFrame);
+       eventListFrame->SetSizer(nullptr, true);
        
-       // Get the wxSizerItem for the top date and the entries part.
+       mainSectionSizer->Clear();
+       topSectionSizer->Clear();
+       windowSizer->Clear();
 
-       wxSizerItem *TopSectionSizerItem = WindowSizer->GetItem((size_t)0);
-       wxSizerItem *MainSectionSizerItem = WindowSizer->GetItem((size_t)1);
-       wxRect TopSizer = wxRect(WindowSizer->GetPosition(), WindowSizer->GetSize());
+       delete alertIcon;
+       alertIcon = nullptr;
        
-       if (IsInMonth == true){
+       delete highPriorityIcon;
+       highPriorityIcon = nullptr;
        
-               dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
-               dc.SetBrush(wxBrush(wxColor(255,255,255)));
-               dc.DrawRectangle(TopSectionSizerItem->GetRect());
-               dc.SetBrush(wxBrush(wxColor(225,225,225)));
-               dc.DrawRectangle(MainSectionSizerItem->GetRect());
-               EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
-               EventListFrameDC.SetBrush(wxBrush(wxColor(225,225,225)));
-               EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
-               
-       } else {
-
-               dc.SetPen(wxPen(wxColor(185,185,185), 0, wxPENSTYLE_TRANSPARENT));
-               dc.SetBrush(wxBrush(wxColor(185,185,185)));
-               dc.DrawRectangle(TopSectionSizerItem->GetRect());
-               dc.SetBrush(wxBrush(wxColor(155,155,155)));
-               dc.DrawRectangle(MainSectionSizerItem->GetRect());
-               EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
-               EventListFrameDC.SetBrush(wxBrush(wxColor(155,155,155)));
-               EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
-               
-       }
+       delete eventListFrame;
+       eventListFrame = nullptr;
        
-       // Draw the border.
+       delete numberText;
+       numberText = nullptr;
 
-       //dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
+       delete topPanel;
+       topPanel = nullptr;
 
-       this->Layout();
+       delete mainPanel;
+       mainPanel = nullptr;
+       
+       calendarEntryList.clear();
+       
+       this->SetSizer(nullptr, true);
+       
+       monthViewPointer = nullptr;
+       dataStorage = nullptr;
        
 }
 
 void XCCalendarDay::UpdateTopIcons(){
        
-       bool AlarmFound = false;
-       bool HighPriorityFound = false;
+       bool alarmFound = false;
+       bool highPriorityFound = false;
        
-       for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
-               EntryIter != CalendarEntryList.end(); EntryIter++){
+       for (vector<XCCalendarDayEntry*>::iterator entryIter = calendarEntryList.begin();
+               entryIter != calendarEntryList.end(); entryIter++){
 
-               if ((*EntryIter)->GetDisplayAlarm() == true){
+               if ((*entryIter)->GetDisplayAlarm() == true){
                        
-                       AlarmFound = true;
+                       alarmFound = true;
                        
                }
 
-               if ((*EntryIter)->GetDisplayHighPriority() == true){
+               if ((*entryIter)->GetDisplayHighPriority() == true){
                        
-                       HighPriorityFound = true;
+                       highPriorityFound = true;
                        
                }
                
-               if (AlarmFound == true && HighPriorityFound == true){
+               if (alarmFound == true && highPriorityFound == true){
                        
                        break;
                        
@@ -207,19 +200,12 @@ void XCCalendarDay::UpdateTopIcons(){
                
        }
        
-       AlertIcon->Show(AlarmFound);
-       HighPriorityIcon->Show(HighPriorityFound);
+       alertIcon->Show(alarmFound);
+       highPriorityIcon->Show(highPriorityFound);
        
 }
 
-void XCCalendarDay::PaintFrameEvent(wxPaintEvent &PaintEvent)
-{
-
-       Repaint();
-       
-}
-
-void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &SizeEvent)
+void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &sizeEvent)
 {
 
        // TODO: Check if window size is less than 120 pixels and if it is,
@@ -228,46 +214,469 @@ void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &SizeEvent)
        // Refresh the window.
        
        this->Refresh();
+       topPanel->Refresh();
+       mainPanel->Refresh();
+       topSectionSizer->Layout();
+       mainSectionSizer->Layout();
+       windowSizer->Layout();
        
 }
 
-void XCCalendarDay::DeselectOthersEvent(wxCommandEvent &DeselectEvent)
+void XCCalendarDay::DeselectOthersEvent(wxCommandEvent &deselectEvent)
 {
+       
+       int selectedEntryID = deselectEvent.GetInt();
 
-       int SelectedEntryID = DeselectEvent.GetInt();
-
-       wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
+       wxCommandEvent deselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
+       deselectEntryEvent.SetId(ID_ENTRYDESELECT);
        
-       for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
-               EntryIter != CalendarEntryList.end(); EntryIter++){
+       for (vector<XCCalendarDayEntry*>::iterator entryIter = calendarEntryList.begin();
+               entryIter != calendarEntryList.end(); entryIter++){
                        
-               if ((*EntryIter)->GetID() != SelectedEntryID){
+               if ((*entryIter)->GetID() != selectedEntryID){
                        
-                       wxPostEvent((*EntryIter), DeselectEntryEvent);
+                       wxPostEvent((*entryIter), deselectEntryEvent);
                        
                }
+               
+       }
+       
+       // Send event notification to deselect the other calendar entries.
+       
+       if (this->monthViewPointer != nullptr){
+               
+               wxCommandEvent deselectMonthEvent(XCCALENDARMONTH_DESELECTOTHERENTRIES);
+               deselectMonthEvent.SetClientData(this);
+               deselectMonthEvent.SetId(ID_MONTHVIEWCLEARSELECTION);
+               wxPostEvent(this->monthViewPointer, deselectMonthEvent);
+               
+       }
+       
+}
+
+void XCCalendarDay::DeselectAllEvent(wxCommandEvent &deselectEvent)
+{
+       
+       int selectedEntryID = deselectEvent.GetInt();
+       
+       wxCommandEvent deselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
+       deselectEntryEvent.SetId(ID_ENTRYDESELECT);
+       
+       for (vector<XCCalendarDayEntry*>::iterator entryIter = calendarEntryList.begin();
+               entryIter != calendarEntryList.end(); entryIter++){
+
+               wxPostEvent((*entryIter), deselectEntryEvent);
                        
        }
        
 }
 
-void XCCalendarDay::SetupControl(int SetupDay, int SetupMonth, int SetupYear, bool SetupIsInMonth, XCCalendarMonthView *MonthViewPointer)
+void XCCalendarDay::SetupControl(int setupDay, int setupMonth, int setupYear, bool setupIsInMonth, XCCalendarMonthView *monthViewPointer, CalendarDataStorage *dataStorage, vector<int> *hideAccounts, vector<int> *hideCalendars)
 {
        
+       this->dataStorage = dataStorage;
+       
        // Set the day
        
-       NumberText->SetLabel(wxString::Format("%02i", SetupDay));
+       numberText->SetLabel(wxString::Format("%02i", setupDay));
+       calendarDay = setupDay;
        
        // Set the month
+
+       calendarMonth = setupMonth;
        
        // Set the year.
+
+       calendarYear = setupYear;
        
        // Setup the Is In Month value.
        
-       IsInMonth = SetupIsInMonth;
+       isInMonth = setupIsInMonth;
+       if (isInMonth)
+       {
+               topPanel->SetBackgroundColour(wxColor(255,255,255));
+               mainPanel->SetBackgroundColour(wxColor(225,225,225));
+               eventListFrame->SetBackgroundColour(wxColor(225,225,225));
+       }
+       else
+       {
+               topPanel->SetBackgroundColour(wxColor(185,185,185));
+               mainPanel->SetBackgroundColour(wxColor(155,155,155));
+               eventListFrame->SetBackgroundColour(wxColor(155,155,155));
+       }
        
        // Setup the month view pointer.
        
-       this->MonthViewPointer = MonthViewPointer;
+       this->monthViewPointer = monthViewPointer;
+       
+       // Setup the calendar items.
+       
+       CDSEntryList calendarItems = dataStorage->GetEventListByDate(setupYear, setupMonth, setupDay);
+       
+       for (int entrySeek = 0; entrySeek < calendarItems.entryList.size(); entrySeek++){
+               
+               // Get the information about the calendar entry.
+               
+               CDSGetCalendarEntryInfo newEntryInfo = dataStorage->GetEvent(calendarItems.entryList[entrySeek]);
+               CDSGetCalendarInfo newEntryCalendarInfo = dataStorage->GetCalendar(newEntryInfo.calendarID);
+               
+               // Setup the calendar entry.
+               
+               XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(eventListFrame, newEntryInfo.entryName, wxDefaultPosition, wxDefaultSize, calendarItems.entryList[entrySeek]);
+               
+               newEntry->SetColour(&newEntryCalendarInfo.calendarColour);
+               newEntry->SetTime(newEntryInfo.entryStartHour, newEntryInfo.entryStartMinute, newEntryInfo.entryStartSecond);
+               newEntry->SetEntryIDs(newEntryCalendarInfo.accountID, newEntryInfo.calendarID, newEntryInfo.calendarEntryID);           
+               
+               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<int>::iterator hideAccountsItem = hideAccounts->begin();
+                       hideAccountsItem != hideAccounts->end(); hideAccountsItem++){
+                               
+                       if (*hideAccountsItem == newEntryCalendarInfo.accountID){
+                               newEntry->Show(false);
+                               newEntry->GetAfterSpacer()->Show(false);
+                       }
+                               
+               }
+               
+               // Go through the list of calendar entries to hide by calendar.
+               
+               for (vector<int>::iterator hideCalendarsItem = hideCalendars->begin();
+                       hideCalendarsItem != hideCalendars->end(); hideCalendarsItem++){
+                               
+                       if (*hideCalendarsItem == newEntryInfo.calendarID){
+                               newEntry->Show(false);
+                               newEntry->GetAfterSpacer()->Show(false);
+                       }
+                               
+               }
+               
+               calendarEntryList.push_back(newEntry);
+       }
+       
+}
+
+void XCCalendarDay::HideAccountEntries(wxCommandEvent &accountData){
+       
+       // Go through each of the controls and hide the controls (and spacing) that
+       // have the matched account IDs.
+       
+       int sizerPosition = 0;
+       
+       for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
+               calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
+               
+               (*calendarEntryIter)->SetShowAccountStatus(false);
+                       
+               if ((*calendarEntryIter)->GetAccountID() == accountData.GetInt()){
+                       
+                       wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
+                       (*calendarEntryIter)->Show(false);
+                       
+                       // Get the spacing and hide it as well.
+                       
+                       wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
+                       afterSpacer->Show(false);
+                       
+               }
+                       
+       }
+       
+       this->Refresh();
+       
+}
+
+void XCCalendarDay::ShowAccountEntries(wxCommandEvent &accountData){
+       
+       // Go through each of the controls and hide the controls (and spacing) that
+       // have the matched account IDs.
+       
+       int sizerPosition = 0;
+       
+       for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
+               calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
+               
+               (*calendarEntryIter)->SetShowAccountStatus(true);
+                       
+               if ((*calendarEntryIter)->GetShowCalendarStatus() == false){
+                       continue;
+               }
+                       
+               if ((*calendarEntryIter)->GetAccountID() == accountData.GetInt()){
+                       
+                       wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
+                       (*calendarEntryIter)->Show(true);
+                       
+                       // Get the spacing and hide it as well.
+                       
+                       wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
+                       afterSpacer->Show(true);
+                       
+               }
+               
+       }
+       
+       this->Refresh();
+       
+}
+
+void XCCalendarDay::HideCalendarEntries(wxCommandEvent &calendarData){
+       
+       // Go through each of the controls and hide the controls (and spacing) that
+       // have the matched account IDs.
+       
+       int sizerPosition = 0;
+       
+       for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
+               calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
+                       
+               if ((*calendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
+                       
+                       (*calendarEntryIter)->SetShowCalendarStatus(false);
+                       
+                       wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
+                       (*calendarEntryIter)->Show(false);
+                       
+                       // Get the spacing and hide it as well.
+                       
+                       wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
+                       afterSpacer->Show(false);
+                       
+               }
+                       
+       }
+       
+       this->Refresh();
+       
+}
+
+void XCCalendarDay::ShowCalendarEntries(wxCommandEvent &calendarData){
+       
+       // Go through each of the controls and hide the controls (and spacing) that
+       // have the matched account IDs.
+       
+       int sizerPosition = 0;
+       
+       for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
+               calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
+                       
+               if ((*calendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
+                       
+                       (*calendarEntryIter)->SetShowCalendarStatus(true);
+                       
+                       if ((*calendarEntryIter)->GetShowAccountStatus() == false){
+                               
+                               // Don't show the calendar entry because the account status
+                               // is set to hidden. Continue to the next one.
+                               
+                               continue;
+                               
+                       }
+                       
+                       wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
+                       (*calendarEntryIter)->Show(true);
+                       
+                       // Get the spacing and hide it as well.
+                       
+                       wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
+                       afterSpacer->Show(true);
+                       
+               }
+                       
+       }
+       
+       this->Refresh();
+       
+}
+
+void XCCalendarDay::DeleteCalendarEntries(wxCommandEvent &calendarData){
+       
+       vector<vector<XCCalendarDayEntry*>::iterator> deleteEntriesList;
+       
+       for (vector<XCCalendarDayEntry*>::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);
+                       
+                       delete afterSpacer;
+                       afterSpacer = nullptr;
+       
+                       delete (*calendarEntryIter);
+                       deleteEntriesList.push_back(calendarEntryIter);
+                       
+               }               
+                       
+       }
+       
+       this->Refresh();
+       mainPanel->Layout();
+       eventListFrame->Layout();
+       eventListFrameSizer->Layout();
+       
+       for (auto deleteIter : deleteEntriesList){
+               calendarEntryList.erase(deleteIter);
+       }
+       
+}
+
+void XCCalendarDay::DeleteCalendarEntry(wxCommandEvent &eventData){
+       
+       vector<vector<XCCalendarDayEntry*>::iterator> deleteEntriesList;
+       
+       for (vector<XCCalendarDayEntry*>::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);
+                       
+                       delete (*calendarEntryIter);
+                       deleteEntriesList.push_back(calendarEntryIter);                 
+                       
+               }               
+                       
+       }
+       
+       for (auto deleteIter : deleteEntriesList){
+               calendarEntryList.erase(deleteIter);
+       }
+       
+       this->Refresh();
+       this->Layout();
+       eventListFrame->Layout();
+       eventListFrameSizer->Layout();
+       
+}
+
+void XCCalendarDay::AddCalendarEntry(wxCommandEvent &eventData){
+       
+       EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
+       
+       // TODO: Fix conversion from string to wxString
+       XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(eventListFrame, wxString(eventInfo->eventName.c_str(), wxConvUTF8), 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<int>::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<int>::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();
+       mainPanel->Layout();
+       eventListFrame->Layout();
+       eventListFrameSizer->Layout();
+       
+}
+
+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<XCCalendarDayEntry*>::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<XCCalendarDayEntry*>::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
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