Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
widgets: Updated and added widgets
[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);
69         /*CalendarEntry1->SetColour(&EventColour);
70         CalendarEntry1->SetDisplayAlarm(false);
71         CalendarEntry1->SetDisplayHighPriority(false);
72         EventListFrameSizer->Add(CalendarEntry1, 0, wxEXPAND, 5);
73         EventListFrameSizer->Add(0, 5, 0, 0, 5);
74         
75         EventColour.red = 255; EventColour.green = 0; EventColour.blue = 0;
76         CalendarEntry2->SetColour(&EventColour);
77         CalendarEntry2->SetDisplayAlarm(true);
78         CalendarEntry2->SetDisplayHighPriority(false);
79         EventListFrameSizer->Add(CalendarEntry2, 0, wxEXPAND, 5);
80         EventListFrameSizer->Add(0, 5, 0, 0, 5);
81         
82         EventColour.red = 0; EventColour.green = 255; EventColour.blue = 0;
83         CalendarEntry3->SetColour(&EventColour);
84         CalendarEntry3->SetDisplayAlarm(false);
85         CalendarEntry3->SetDisplayHighPriority(false);
86         EventListFrameSizer->Add(CalendarEntry3, 0, wxEXPAND, 5);
87         EventListFrameSizer->Add(0, 5, 0, 0, 5);
89         EventColour.red = 0; EventColour.green = 0; EventColour.blue = 255;
90         CalendarEntry4->SetColour(&EventColour);
91         CalendarEntry4->SetDisplayAlarm(false);
92         CalendarEntry4->SetDisplayHighPriority(false);
93         EventListFrameSizer->Add(CalendarEntry4, 0, wxEXPAND, 5);
94         EventListFrameSizer->Add(0, 5, 0, 0, 5);
95         
96         EventListFrameSizer->Add(CalendarEntry5, 0, wxEXPAND, 5);
97         EventListFrameSizer->Add(0, 5, 0, 0, 5);
98         EventListFrameSizer->Add(CalendarEntry6, 0, wxEXPAND, 5);
99         EventListFrameSizer->Add(0, 5, 0, 0, 5);
100         EventListFrameSizer->Add(CalendarEntry7, 0, wxEXPAND, 5);
101         EventListFrameSizer->Add(0, 5, 0, 0, 5);
102         EventListFrameSizer->Add(CalendarEntry8, 0, wxEXPAND, 5);
103         EventListFrameSizer->Add(0, 5, 0, 0, 5);
104         EventListFrameSizer->Add(CalendarEntry9, 0, wxEXPAND, 5);
105         EventListFrameSizer->Add(0, 5, 0, 0, 5);
106         EventListFrameSizer->Add(CalendarEntry10, 0, wxEXPAND, 5);*/
108         EventListFrame->SetScrollRate(0,1);
109         //EventListFrameSizer->FitInside(EventListFrame);
110         EventListFrameSizer->Fit(EventListFrame);
111         EventListFrameSizer->Layout();
112         WindowSizer->Fit(this);
114         // Setup the scroll window.
115         
116         WindowSizer->Add(TopSectionSizer, 1, wxEXPAND, 5);
117         WindowSizer->Add(MainSectionSizer, 1, wxEXPAND, 5);
118         MainSectionSizer->Add(EventListFrame, 1, wxGROW | wxALL, 10);
120         this->SetSizer(WindowSizer);
121         this->SetSize(size);
122         this->Layout();
123         this->SetBackgroundStyle(wxBG_STYLE_PAINT);
124         this->Centre(wxBOTH);
125         
126         /*CalendarEntryList.push_back(CalendarEntry1);
127         CalendarEntryList.push_back(CalendarEntry2);
128         CalendarEntryList.push_back(CalendarEntry3);
129         CalendarEntryList.push_back(CalendarEntry4);
130         CalendarEntryList.push_back(CalendarEntry5);
131         CalendarEntryList.push_back(CalendarEntry6);
132         CalendarEntryList.push_back(CalendarEntry7);
133         CalendarEntryList.push_back(CalendarEntry8);
134         CalendarEntryList.push_back(CalendarEntry9);
135         CalendarEntryList.push_back(CalendarEntry10);*/
136         
137         UpdateTopIcons();
138         
141 XCCalendarDay::~XCCalendarDay(){
142         
143         // Destory the controls from the widget.
144         
147 void XCCalendarDay::Repaint(){
148         
149         wxPaintDC dc(this);
150         wxPaintDC EventListFrameDC(EventListFrame);
151         
152         // Get the wxSizerItem for the top date and the entries part.
154         wxSizerItem *TopSectionSizerItem = WindowSizer->GetItem((size_t)0);
155         wxSizerItem *MainSectionSizerItem = WindowSizer->GetItem((size_t)1);
156         wxRect TopSizer = wxRect(WindowSizer->GetPosition(), WindowSizer->GetSize());
157         
158         if (IsInMonth == true){
159         
160                 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
161                 dc.SetBrush(wxBrush(wxColor(255,255,255)));
162                 dc.DrawRectangle(TopSectionSizerItem->GetRect());
163                 dc.SetBrush(wxBrush(wxColor(225,225,225)));
164                 dc.DrawRectangle(MainSectionSizerItem->GetRect());
165                 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
166                 EventListFrameDC.SetBrush(wxBrush(wxColor(225,225,225)));
167                 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
168                 
169         } else {
171                 dc.SetPen(wxPen(wxColor(185,185,185), 0, wxPENSTYLE_TRANSPARENT));
172                 dc.SetBrush(wxBrush(wxColor(185,185,185)));
173                 dc.DrawRectangle(TopSectionSizerItem->GetRect());
174                 dc.SetBrush(wxBrush(wxColor(155,155,155)));
175                 dc.DrawRectangle(MainSectionSizerItem->GetRect());
176                 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
177                 EventListFrameDC.SetBrush(wxBrush(wxColor(155,155,155)));
178                 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
179                 
180         }
181         
182         // Draw the border.
184         //dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
186         this->Layout();
187         
190 void XCCalendarDay::UpdateTopIcons(){
191         
192         bool AlarmFound = false;
193         bool HighPriorityFound = false;
194         
195         for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
196                 EntryIter != CalendarEntryList.end(); EntryIter++){
198                 if ((*EntryIter)->GetDisplayAlarm() == true){
199                         
200                         AlarmFound = true;
201                         
202                 }
204                 if ((*EntryIter)->GetDisplayHighPriority() == true){
205                         
206                         HighPriorityFound = true;
207                         
208                 }
209                 
210                 if (AlarmFound == true && HighPriorityFound == true){
211                         
212                         break;
213                         
214                 }
215                 
216         }
217         
218         AlertIcon->Show(AlarmFound);
219         HighPriorityIcon->Show(HighPriorityFound);
220         
223 void XCCalendarDay::PaintFrameEvent(wxPaintEvent &PaintEvent)
226         Repaint();
227         
230 void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &SizeEvent)
233         // TODO: Check if window size is less than 120 pixels and if it is,
234         // switch to the small block mode.
235         
236         // Refresh the window.
237         
238         this->Refresh();
239         
242 void XCCalendarDay::DeselectOthersEvent(wxCommandEvent &DeselectEvent)
245         int SelectedEntryID = DeselectEvent.GetInt();
247         wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
248         
249         for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
250                 EntryIter != CalendarEntryList.end(); EntryIter++){
251                         
252                 if ((*EntryIter)->GetID() != SelectedEntryID){
253                         
254                         wxPostEvent((*EntryIter), DeselectEntryEvent);
255                         
256                 }
257                         
258         }
259         
260         // Send event notification to deselect the other calendar entries.
261         
262         if (this->MonthViewPointer != nullptr){
263                 
264                 wxCommandEvent DeselectEvent(XCCALENDARMONTH_DESELECTOTHERENTRIES);
265                 DeselectEvent.SetClientData(this);
266                 DeselectEvent.SetId(ID_MONTHVIEWCLEARSELECTION);
267                 wxPostEvent(this->MonthViewPointer, DeselectEvent);
268                 
269         }
270         
273 void XCCalendarDay::DeselectAllEvent(wxCommandEvent &DeselectEvent)
275         
276         int SelectedEntryID = DeselectEvent.GetInt();
278         wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
279         
280         for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
281                 EntryIter != CalendarEntryList.end(); EntryIter++){
283                 wxPostEvent((*EntryIter), DeselectEntryEvent);
284                         
285         }
286         
289 void XCCalendarDay::SetupControl(int SetupDay, int SetupMonth, int SetupYear, bool SetupIsInMonth, XCCalendarMonthView *MonthViewPointer)
291         
292         // Set the day
293         
294         NumberText->SetLabel(wxString::Format("%02i", SetupDay));
295         
296         // Set the month
297         
298         // Set the year.
299         
300         // Setup the Is In Month value.
301         
302         IsInMonth = SetupIsInMonth;
303         
304         // Setup the month view pointer.
305         
306         this->MonthViewPointer = MonthViewPointer;
307         
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