Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmMain: Implemented code to hide/show calendar entries
[xestiacalendar/.git] / source / widgets / XCCalendarDay.cpp
index 37ce112..bde3504 100644 (file)
@@ -23,21 +23,26 @@ using namespace std;
 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);
+       // Setip the icons.
+               
+       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);
+       
+       AlertIcon->SetBitmap(imgAlertIcon);
+       HighPriorityIcon->SetBitmap(imgPriorityIcon);
        
        WindowSizer->AddGrowableCol(0);
        WindowSizer->AddGrowableRow(1);
@@ -58,44 +63,6 @@ XCCalendarDay::XCCalendarDay(wxWindow *parent, const wxString& title, const wxPo
        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);
@@ -105,9 +72,10 @@ XCCalendarDay::XCCalendarDay(wxWindow *parent, const wxString& title, const wxPo
 
        // Setup the scroll window.
        
+       MainSectionSizer->Add(EventListFrame, 1, wxGROW | wxALL, 10);
+       
        WindowSizer->Add(TopSectionSizer, 1, wxEXPAND, 5);
        WindowSizer->Add(MainSectionSizer, 1, wxEXPAND, 5);
-       MainSectionSizer->Add(EventListFrame, 1, wxGROW | wxALL, 10);
 
        this->SetSizer(WindowSizer);
        this->SetSize(size);
@@ -115,25 +83,32 @@ XCCalendarDay::XCCalendarDay(wxWindow *parent, const wxString& title, const wxPo
        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();
        
+       Connect(ID_DESELECTOTHERENTRIES, XCCALENDARDAY_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectOthersEvent));
+       Connect(ID_DESELECTALLITEMS, XCCALENDARDAY_DESELECTALLENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectAllEvent));
+       Connect(ID_HIDEENTRIES, XCCALENDARDAY_HIDEACCOUNTENTRIES, wxCommandEventHandler(XCCalendarDay::HideAccountEntries));
+       Connect(ID_SHOWENTRIES, XCCALENDARDAY_SHOWACCOUNTENTRIES, wxCommandEventHandler(XCCalendarDay::ShowAccountEntries));
+       Connect(ID_HIDECALENDARENTRIES, XCCALENDARDAY_HIDECALENDARENTRIES, wxCommandEventHandler(XCCalendarDay::HideCalendarEntries));
+       Connect(ID_SHOWCALENDARENTRIES, XCCALENDARDAY_SHOWCALENDARENTRIES, wxCommandEventHandler(XCCalendarDay::ShowCalendarEntries));
+       
 }
 
 XCCalendarDay::~XCCalendarDay(){
        
        // Destory the controls from the widget.
        
+       for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
+               CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
+       
+               delete((*CalendarEntryIter));
+                       
+       }
+       
+       CalendarEntryList.clear();
+       
+       this->Refresh();
+       
 }
 
 void XCCalendarDay::Repaint(){
@@ -233,10 +208,11 @@ void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &SizeEvent)
 
 void XCCalendarDay::DeselectOthersEvent(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++){
@@ -249,18 +225,51 @@ void XCCalendarDay::DeselectOthersEvent(wxCommandEvent &DeselectEvent)
                        
        }
        
+       // Send event notification to deselect the other calendar entries.
+       
+       if (this->MonthViewPointer != nullptr){
+               
+               wxCommandEvent DeselectEvent(XCCALENDARMONTH_DESELECTOTHERENTRIES);
+               DeselectEvent.SetClientData(this);
+               DeselectEvent.SetId(ID_MONTHVIEWCLEARSELECTION);
+               wxPostEvent(this->MonthViewPointer, DeselectEvent);
+               
+       }
+       
 }
 
-void XCCalendarDay::SetupControl(int SetupDay, int SetupMonth, int SetupYear, bool SetupIsInMonth, XCCalendarMonthView *MonthViewPointer)
+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, CalendarDataStorage *dataStorage, vector<int> *hideAccounts, vector<int> *hideCalendars)
 {
        
        // Set the day
        
        NumberText->SetLabel(wxString::Format("%02i", SetupDay));
+       calendarDay = SetupDay;
        
        // Set the month
+
+       calendarMonth = SetupMonth;
        
        // Set the year.
+
+       calendarYear = SetupYear;
        
        // Setup the Is In Month value.
        
@@ -270,4 +279,192 @@ void XCCalendarDay::SetupControl(int SetupDay, int SetupMonth, int SetupYear, bo
        
        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();
+       Repaint();
+       
+}
+
+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();
+       Repaint();
+       
+}
+
+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();
+       Repaint();
+       
+}
+
+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();
+       Repaint();
+       
 }
\ 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