Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmEditAccount: Moved code to forms/editaccount
[xestiacalendar/.git] / source / widgets / XCCalendarDay.cpp
1 // XCCalendarDay.cpp - Xestia Calendar XCCalendarDay widget class.
2 //
3 // (c) 2016 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
19 #include "XCCalendarDay.h"
21 using namespace std;
23 BEGIN_EVENT_TABLE(XCCalendarDay, wxPanel)
24 EVT_PAINT(XCCalendarDay::PaintFrameEvent)
25 EVT_SIZE(XCCalendarDay::ResizeFrameEvent)
26 END_EVENT_TABLE()
28 XCCalendarDay::XCCalendarDay(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size)
29         : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
31         this->SetMinSize( wxSize( 100,100 ) );
32         
33         // Setip the icons.
34                 
35         wxMemoryInputStream alerticon(icons_alert32_png, sizeof(icons_alert32_png));
36         wxMemoryInputStream priorityicon(icons_priority32_png, sizeof(icons_priority32_png));
37         
38         wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
39         wxBitmap imgAlertIcon(icons_alert_png, -1);
41         wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
42         wxBitmap imgPriorityIcon(icons_priority_png, -1);
43         
44         AlertIcon->SetBitmap(imgAlertIcon);
45         HighPriorityIcon->SetBitmap(imgPriorityIcon);
46         
47         WindowSizer->AddGrowableCol(0);
48         WindowSizer->AddGrowableRow(1);
49         WindowSizer->SetFlexibleDirection( wxBOTH );
50         WindowSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
51         
52         NumberText = new wxStaticText(this, wxID_ANY, wxT("09"), wxDefaultPosition, wxDefaultSize, 0);
53         NumberText->SetFont(wxFont(24, 70, 90, 92, false, wxEmptyString));
54         
55         TopSectionSizer->Add(HighPriorityIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
56         TopSectionSizer->Add(AlertIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
57         TopSectionSizer->Add(0, 0, 1, wxEXPAND, 5);
58         TopSectionSizer->Add(NumberText, 0, wxALL|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
60         // Setup the scrollable section.
61         
62         Colour EventColour;
63         EventColour.red = 40; EventColour.green = 80; EventColour.blue = 80;
64         
65         EventListFrame->SetSizer(EventListFrameSizer);
67         EventListFrame->SetScrollRate(0,1);
68         //EventListFrameSizer->FitInside(EventListFrame);
69         EventListFrameSizer->Fit(EventListFrame);
70         EventListFrameSizer->Layout();
71         WindowSizer->Fit(this);
73         // Setup the scroll window.
74         
75         MainSectionSizer->Add(EventListFrame, 1, wxGROW | wxALL, 10);
76         
77         WindowSizer->Add(TopSectionSizer, 1, wxEXPAND, 5);
78         WindowSizer->Add(MainSectionSizer, 1, wxEXPAND, 5);
80         this->SetSizer(WindowSizer);
81         this->SetSize(size);
82         this->Layout();
83         this->SetBackgroundStyle(wxBG_STYLE_PAINT);
84         this->Centre(wxBOTH);
85         
86         UpdateTopIcons();
87         
88         Connect(ID_DESELECTOTHERENTRIES, XCCALENDARDAY_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectOthersEvent));
89         Connect(ID_DESELECTALLITEMS, XCCALENDARDAY_DESELECTALLENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectAllEvent));
90         Connect(ID_HIDEENTRIES, XCCALENDARDAY_HIDEACCOUNTENTRIES, wxCommandEventHandler(XCCalendarDay::HideAccountEntries));
91         Connect(ID_SHOWENTRIES, XCCALENDARDAY_SHOWACCOUNTENTRIES, wxCommandEventHandler(XCCalendarDay::ShowAccountEntries));
92         Connect(ID_HIDECALENDARENTRIES, XCCALENDARDAY_HIDECALENDARENTRIES, wxCommandEventHandler(XCCalendarDay::HideCalendarEntries));
93         Connect(ID_SHOWCALENDARENTRIES, XCCALENDARDAY_SHOWCALENDARENTRIES, wxCommandEventHandler(XCCalendarDay::ShowCalendarEntries));
94         
95 }
97 XCCalendarDay::~XCCalendarDay(){
98         
99         // Destory the controls from the widget.
100         
101         for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
102                 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
103         
104                 delete((*CalendarEntryIter));
105                         
106         }
107         
108         CalendarEntryList.clear();
109         
110         this->Refresh();
111         
114 void XCCalendarDay::Repaint(){
115         
116         wxPaintDC dc(this);
117         wxPaintDC EventListFrameDC(EventListFrame);
118         
119         // Get the wxSizerItem for the top date and the entries part.
121         wxSizerItem *TopSectionSizerItem = WindowSizer->GetItem((size_t)0);
122         wxSizerItem *MainSectionSizerItem = WindowSizer->GetItem((size_t)1);
123         wxRect TopSizer = wxRect(WindowSizer->GetPosition(), WindowSizer->GetSize());
124         
125         if (IsInMonth == true){
126         
127                 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
128                 dc.SetBrush(wxBrush(wxColor(255,255,255)));
129                 dc.DrawRectangle(TopSectionSizerItem->GetRect());
130                 dc.SetBrush(wxBrush(wxColor(225,225,225)));
131                 dc.DrawRectangle(MainSectionSizerItem->GetRect());
132                 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
133                 EventListFrameDC.SetBrush(wxBrush(wxColor(225,225,225)));
134                 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
135                 
136         } else {
138                 dc.SetPen(wxPen(wxColor(185,185,185), 0, wxPENSTYLE_TRANSPARENT));
139                 dc.SetBrush(wxBrush(wxColor(185,185,185)));
140                 dc.DrawRectangle(TopSectionSizerItem->GetRect());
141                 dc.SetBrush(wxBrush(wxColor(155,155,155)));
142                 dc.DrawRectangle(MainSectionSizerItem->GetRect());
143                 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
144                 EventListFrameDC.SetBrush(wxBrush(wxColor(155,155,155)));
145                 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
146                 
147         }
148         
149         // Draw the border.
151         //dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
153         this->Layout();
154         
157 void XCCalendarDay::UpdateTopIcons(){
158         
159         bool AlarmFound = false;
160         bool HighPriorityFound = false;
161         
162         for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
163                 EntryIter != CalendarEntryList.end(); EntryIter++){
165                 if ((*EntryIter)->GetDisplayAlarm() == true){
166                         
167                         AlarmFound = true;
168                         
169                 }
171                 if ((*EntryIter)->GetDisplayHighPriority() == true){
172                         
173                         HighPriorityFound = true;
174                         
175                 }
176                 
177                 if (AlarmFound == true && HighPriorityFound == true){
178                         
179                         break;
180                         
181                 }
182                 
183         }
184         
185         AlertIcon->Show(AlarmFound);
186         HighPriorityIcon->Show(HighPriorityFound);
187         
190 void XCCalendarDay::PaintFrameEvent(wxPaintEvent &PaintEvent)
193         Repaint();
194         
197 void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &SizeEvent)
200         // TODO: Check if window size is less than 120 pixels and if it is,
201         // switch to the small block mode.
202         
203         // Refresh the window.
204         
205         this->Refresh();
206         
209 void XCCalendarDay::DeselectOthersEvent(wxCommandEvent &DeselectEvent)
211         
212         int SelectedEntryID = DeselectEvent.GetInt();
214         wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
215         DeselectEntryEvent.SetId(ID_ENTRYDESELECT);
216         
217         for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
218                 EntryIter != CalendarEntryList.end(); EntryIter++){
219                         
220                 if ((*EntryIter)->GetID() != SelectedEntryID){
221                         
222                         wxPostEvent((*EntryIter), DeselectEntryEvent);
223                         
224                 }
225                         
226         }
227         
228         // Send event notification to deselect the other calendar entries.
229         
230         if (this->MonthViewPointer != nullptr){
231                 
232                 wxCommandEvent DeselectEvent(XCCALENDARMONTH_DESELECTOTHERENTRIES);
233                 DeselectEvent.SetClientData(this);
234                 DeselectEvent.SetId(ID_MONTHVIEWCLEARSELECTION);
235                 wxPostEvent(this->MonthViewPointer, DeselectEvent);
236                 
237         }
238         
241 void XCCalendarDay::DeselectAllEvent(wxCommandEvent &DeselectEvent)
243         
244         int SelectedEntryID = DeselectEvent.GetInt();
245         
246         wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
247         DeselectEntryEvent.SetId(ID_ENTRYDESELECT);
248         
249         for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
250                 EntryIter != CalendarEntryList.end(); EntryIter++){
252                 wxPostEvent((*EntryIter), DeselectEntryEvent);
253                         
254         }
255         
258 void XCCalendarDay::SetupControl(int SetupDay, int SetupMonth, int SetupYear, bool SetupIsInMonth, XCCalendarMonthView *MonthViewPointer, CalendarDataStorage *dataStorage, vector<int> *hideAccounts, vector<int> *hideCalendars)
260         
261         // Set the day
262         
263         NumberText->SetLabel(wxString::Format("%02i", SetupDay));
264         calendarDay = SetupDay;
265         
266         // Set the month
268         calendarMonth = SetupMonth;
269         
270         // Set the year.
272         calendarYear = SetupYear;
273         
274         // Setup the Is In Month value.
275         
276         IsInMonth = SetupIsInMonth;
277         
278         // Setup the month view pointer.
279         
280         this->MonthViewPointer = MonthViewPointer;
281         
282         // Setup the calendar items.
283         
284         CDSEntryList calendarItems = dataStorage->GetEventListByDate(SetupYear, SetupMonth, SetupDay);
285         
286         for (int entrySeek = 0; entrySeek < calendarItems.entryList.size(); entrySeek++){
287                 
288                 // Get the information about the calendar entry.
289                 
290                 CDSGetCalendarEntryInfo newEntryInfo = dataStorage->GetEvent(calendarItems.entryList[entrySeek]);
291                 CDSGetCalendarInfo newEntryCalendarInfo = dataStorage->GetCalendar(newEntryInfo.calendarID);
292                 
293                 // Setup the calendar entry.
294                 
295                 XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(EventListFrame, newEntryInfo.entryName, wxDefaultPosition, wxDefaultSize, calendarItems.entryList[entrySeek]);
296                 
297                 newEntry->SetColour(&newEntryCalendarInfo.calendarColour);
298                 newEntry->SetTime(newEntryInfo.entryStartHour, newEntryInfo.entryStartMinute, newEntryInfo.entryStartSecond);
299                 newEntry->SetEntryIDs(newEntryCalendarInfo.accountID, newEntryInfo.calendarID, newEntryInfo.calendarEntryID);           
300                 
301                 EventListFrameSizer->Add(newEntry, 0, wxEXPAND, 5);
302                 wxSizerItem *afterSpacer = EventListFrameSizer->Add(0, 5, 0, 0, 5);
303                 
304                 newEntry->SetAfterSpacer(afterSpacer);
305                 
306                 // Go through the list of calendar entries to hide by account.
307                 
308                 for (vector<int>::iterator hideAccountsItem = hideAccounts->begin();
309                         hideAccountsItem != hideAccounts->end(); hideAccountsItem++){
310                                 
311                         if (*hideAccountsItem = newEntryCalendarInfo.accountID){
312                                 newEntry->Show(false);
313                                 newEntry->GetAfterSpacer()->Show(false);
314                         }
315                                 
316                 }
317                 
318                 // Go through the list of calendar entries to hide by calendar.
319                 
320                 for (vector<int>::iterator hideCalendarsItem = hideCalendars->begin();
321                         hideCalendarsItem != hideCalendars->end(); hideCalendarsItem++){
322                                 
323                         if (*hideCalendarsItem == newEntryInfo.calendarID){
324                                 newEntry->Show(false);
325                                 newEntry->GetAfterSpacer()->Show(false);
326                         }                       
327                                 
328                 }
329                 
330                 CalendarEntryList.push_back(newEntry);
331         }
332         
335 void XCCalendarDay::HideAccountEntries(wxCommandEvent &accountData){
336         
337         // Go through each of the controls and hide the controls (and spacing) that
338         // have the matched account IDs.
339         
340         int sizerPosition = 0;
341         
342         for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
343                 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
344                 
345                 (*CalendarEntryIter)->SetShowAccountStatus(false);
346                         
347                 if ((*CalendarEntryIter)->GetAccountID() == accountData.GetInt()){
348                         
349                         wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
350                         (*CalendarEntryIter)->Show(false);
351                         
352                         // Get the spacing and hide it as well.
353                         
354                         wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
355                         afterSpacer->Show(false);
356                         
357                 }
358                         
359         }
360         
361         this->Refresh();
362         Repaint();
363         
366 void XCCalendarDay::ShowAccountEntries(wxCommandEvent &accountData){
367         
368         // Go through each of the controls and hide the controls (and spacing) that
369         // have the matched account IDs.
370         
371         int sizerPosition = 0;
372         
373         for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
374                 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
375                 
376                 (*CalendarEntryIter)->SetShowAccountStatus(true);
377                         
378                 if ((*CalendarEntryIter)->GetShowCalendarStatus() == false){
379                         continue;
380                 }
381                         
382                 if ((*CalendarEntryIter)->GetAccountID() == accountData.GetInt()){
383                         
384                         wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
385                         (*CalendarEntryIter)->Show(true);
386                         
387                         // Get the spacing and hide it as well.
388                         
389                         wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
390                         afterSpacer->Show(true);
391                         
392                 }
393                         
394         }
395         
396         this->Refresh();
397         Repaint();
398         
401 void XCCalendarDay::HideCalendarEntries(wxCommandEvent &calendarData){
402         
403         // Go through each of the controls and hide the controls (and spacing) that
404         // have the matched account IDs.
405         
406         int sizerPosition = 0;
407         
408         for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
409                 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
410                         
411                 if ((*CalendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
412                         
413                         (*CalendarEntryIter)->SetShowCalendarStatus(false);
414                         
415                         wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
416                         (*CalendarEntryIter)->Show(false);
417                         
418                         // Get the spacing and hide it as well.
419                         
420                         wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
421                         afterSpacer->Show(false);
422                         
423                 }
424                         
425         }
426         
427         this->Refresh();
428         Repaint();
429         
432 void XCCalendarDay::ShowCalendarEntries(wxCommandEvent &calendarData){
433         
434         // Go through each of the controls and hide the controls (and spacing) that
435         // have the matched account IDs.
436         
437         int sizerPosition = 0;
438         
439         for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
440                 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
441                         
442                 if ((*CalendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
443                         
444                         (*CalendarEntryIter)->SetShowCalendarStatus(true);
445                         
446                         if ((*CalendarEntryIter)->GetShowAccountStatus() == false){
447                                 
448                                 // Don't show the calendar entry because the account status
449                                 // is set to hidden. Continue to the next one.
450                                 
451                                 continue;
452                                 
453                         }
454                         
455                         wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
456                         (*CalendarEntryIter)->Show(true);
457                         
458                         // Get the spacing and hide it as well.
459                         
460                         wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
461                         afterSpacer->Show(true);
462                         
463                 }
464                         
465         }
466         
467         this->Refresh();
468         Repaint();
469         
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