Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
XCCalendarDay: Removed unused code and added code to add event controls
[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){
30         
31         Connect(wxID_ANY, XCCALENDARDAY_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectOthersEvent));
32         Connect(ID_DESELECTALLITEMS, XCCALENDARDAY_DESELECTALLENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectAllEvent));
34         this->SetMinSize( wxSize( 100,100 ) );
35         
36         // Setip the icons.
37                 
38         wxMemoryInputStream alerticon(icons_alert32_png, sizeof(icons_alert32_png));
39         wxMemoryInputStream priorityicon(icons_priority32_png, sizeof(icons_priority32_png));
40         
41         wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
42         wxBitmap imgAlertIcon(icons_alert_png, -1);
44         wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
45         wxBitmap imgPriorityIcon(icons_priority_png, -1);
46         
47         AlertIcon->SetBitmap(imgAlertIcon);
48         HighPriorityIcon->SetBitmap(imgPriorityIcon);
49         
50         WindowSizer->AddGrowableCol(0);
51         WindowSizer->AddGrowableRow(1);
52         WindowSizer->SetFlexibleDirection( wxBOTH );
53         WindowSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
54         
55         NumberText = new wxStaticText(this, wxID_ANY, wxT("09"), wxDefaultPosition, wxDefaultSize, 0);
56         NumberText->SetFont(wxFont(24, 70, 90, 92, false, wxEmptyString));
57         
58         TopSectionSizer->Add(HighPriorityIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
59         TopSectionSizer->Add(AlertIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
60         TopSectionSizer->Add(0, 0, 1, wxEXPAND, 5);
61         TopSectionSizer->Add(NumberText, 0, wxALL|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
63         // Setup the scrollable section.
64         
65         Colour EventColour;
66         EventColour.red = 40; EventColour.green = 80; EventColour.blue = 80;
67         
68         EventListFrame->SetSizer(EventListFrameSizer);
70         EventListFrame->SetScrollRate(0,1);
71         //EventListFrameSizer->FitInside(EventListFrame);
72         EventListFrameSizer->Fit(EventListFrame);
73         EventListFrameSizer->Layout();
74         WindowSizer->Fit(this);
76         // Setup the scroll window.
77         
78         MainSectionSizer->Add(EventListFrame, 1, wxGROW | wxALL, 10);
79         
80         WindowSizer->Add(TopSectionSizer, 1, wxEXPAND, 5);
81         WindowSizer->Add(MainSectionSizer, 1, wxEXPAND, 5);
83         this->SetSizer(WindowSizer);
84         this->SetSize(size);
85         this->Layout();
86         this->SetBackgroundStyle(wxBG_STYLE_PAINT);
87         this->Centre(wxBOTH);
88         
89         UpdateTopIcons();
90         
91 }
93 XCCalendarDay::~XCCalendarDay(){
94         
95         // Destory the controls from the widget.
96         
97 }
99 void XCCalendarDay::Repaint(){
100         
101         wxPaintDC dc(this);
102         wxPaintDC EventListFrameDC(EventListFrame);
103         
104         // Get the wxSizerItem for the top date and the entries part.
106         wxSizerItem *TopSectionSizerItem = WindowSizer->GetItem((size_t)0);
107         wxSizerItem *MainSectionSizerItem = WindowSizer->GetItem((size_t)1);
108         wxRect TopSizer = wxRect(WindowSizer->GetPosition(), WindowSizer->GetSize());
109         
110         if (IsInMonth == true){
111         
112                 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
113                 dc.SetBrush(wxBrush(wxColor(255,255,255)));
114                 dc.DrawRectangle(TopSectionSizerItem->GetRect());
115                 dc.SetBrush(wxBrush(wxColor(225,225,225)));
116                 dc.DrawRectangle(MainSectionSizerItem->GetRect());
117                 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
118                 EventListFrameDC.SetBrush(wxBrush(wxColor(225,225,225)));
119                 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
120                 
121         } else {
123                 dc.SetPen(wxPen(wxColor(185,185,185), 0, wxPENSTYLE_TRANSPARENT));
124                 dc.SetBrush(wxBrush(wxColor(185,185,185)));
125                 dc.DrawRectangle(TopSectionSizerItem->GetRect());
126                 dc.SetBrush(wxBrush(wxColor(155,155,155)));
127                 dc.DrawRectangle(MainSectionSizerItem->GetRect());
128                 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
129                 EventListFrameDC.SetBrush(wxBrush(wxColor(155,155,155)));
130                 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
131                 
132         }
133         
134         // Draw the border.
136         //dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
138         this->Layout();
139         
142 void XCCalendarDay::UpdateTopIcons(){
143         
144         bool AlarmFound = false;
145         bool HighPriorityFound = false;
146         
147         for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
148                 EntryIter != CalendarEntryList.end(); EntryIter++){
150                 if ((*EntryIter)->GetDisplayAlarm() == true){
151                         
152                         AlarmFound = true;
153                         
154                 }
156                 if ((*EntryIter)->GetDisplayHighPriority() == true){
157                         
158                         HighPriorityFound = true;
159                         
160                 }
161                 
162                 if (AlarmFound == true && HighPriorityFound == true){
163                         
164                         break;
165                         
166                 }
167                 
168         }
169         
170         AlertIcon->Show(AlarmFound);
171         HighPriorityIcon->Show(HighPriorityFound);
172         
175 void XCCalendarDay::PaintFrameEvent(wxPaintEvent &PaintEvent)
178         Repaint();
179         
182 void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &SizeEvent)
185         // TODO: Check if window size is less than 120 pixels and if it is,
186         // switch to the small block mode.
187         
188         // Refresh the window.
189         
190         this->Refresh();
191         
194 void XCCalendarDay::DeselectOthersEvent(wxCommandEvent &DeselectEvent)
197         int SelectedEntryID = DeselectEvent.GetInt();
199         wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
200         
201         for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
202                 EntryIter != CalendarEntryList.end(); EntryIter++){
203                         
204                 if ((*EntryIter)->GetID() != SelectedEntryID){
205                         
206                         wxPostEvent((*EntryIter), DeselectEntryEvent);
207                         
208                 }
209                         
210         }
211         
212         // Send event notification to deselect the other calendar entries.
213         
214         if (this->MonthViewPointer != nullptr){
215                 
216                 wxCommandEvent DeselectEvent(XCCALENDARMONTH_DESELECTOTHERENTRIES);
217                 DeselectEvent.SetClientData(this);
218                 DeselectEvent.SetId(ID_MONTHVIEWCLEARSELECTION);
219                 wxPostEvent(this->MonthViewPointer, DeselectEvent);
220                 
221         }
222         
225 void XCCalendarDay::DeselectAllEvent(wxCommandEvent &DeselectEvent)
227         
228         int SelectedEntryID = DeselectEvent.GetInt();
230         wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
231         
232         for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
233                 EntryIter != CalendarEntryList.end(); EntryIter++){
235                 wxPostEvent((*EntryIter), DeselectEntryEvent);
236                         
237         }
238         
241 void XCCalendarDay::SetupControl(int SetupDay, int SetupMonth, int SetupYear, bool SetupIsInMonth, XCCalendarMonthView *MonthViewPointer, CalendarDataStorage *dataStorage)
243         
244         // Set the day
245         
246         NumberText->SetLabel(wxString::Format("%02i", SetupDay));
247         calendarDay = SetupDay;
248         
249         // Set the month
251         calendarMonth = SetupMonth;
252         
253         // Set the year.
255         calendarYear = SetupYear;
256         
257         // Setup the Is In Month value.
258         
259         IsInMonth = SetupIsInMonth;
260         
261         // Setup the month view pointer.
262         
263         this->MonthViewPointer = MonthViewPointer;
264         
265         // Setup the calendar items.
266         
267         CDSEntryList calendarItems = dataStorage->GetEventListByDate(SetupYear, SetupMonth, SetupDay);
268         
269         for (int entrySeek = 0; entrySeek < calendarItems.entryList.size(); entrySeek++){
270                 
271                 // Get the information about the calendar entry.
272                 
273                 CDSGetCalendarEntryInfo newEntryInfo = dataStorage->GetEvent(calendarItems.entryList[entrySeek]);
274                 CDSGetCalendarInfo newEntryCalendarInfo = dataStorage->GetCalendar(newEntryInfo.calendarID);
275                 
276                 // Setup the calendar entry.
277                 
278                 XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(EventListFrame, newEntryInfo.entryName, wxDefaultPosition, wxDefaultSize, calendarItems.entryList[entrySeek]);
279                 
280                 newEntry->SetColour(&newEntryCalendarInfo.calendarColour);
281                 newEntry->SetTime(newEntryInfo.entryStartHour, newEntryInfo.entryStartMinute, newEntryInfo.entryStartSecond);
282                 newEntry->SetEntryIDs(newEntryCalendarInfo.accountID, newEntryInfo.calendarID, newEntryInfo.calendarEntryID);
283                 
284                 EventListFrameSizer->Add(newEntry, 0, wxEXPAND, 5);
285                 wxSizerItem *afterSpacer = EventListFrameSizer->Add(0, 5, 0, 0, 5);
286                 
287                 newEntry->SetAfterSpacer(afterSpacer);
288                 
289                 CalendarEntryList.push_back(newEntry);
290         }
291         
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