Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Moved DeselectOthersEvent setup to the XCCalendarDay constructor.
[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         AlertIconBitmap.LoadFile("AlertIcon-32.png", wxBITMAP_DEFAULT_TYPE);
37         PriorityIconBitmap.LoadFile("PriorityIcon-32.png", wxBITMAP_DEFAULT_TYPE);
38         
39         AlertIcon->SetBitmap(AlertIconBitmap);
40         HighPriorityIcon->SetBitmap(PriorityIconBitmap);        
41         
42         WindowSizer->AddGrowableCol(0);
43         WindowSizer->AddGrowableRow(1);
44         WindowSizer->SetFlexibleDirection( wxBOTH );
45         WindowSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
46         
47         NumberText = new wxStaticText(this, wxID_ANY, wxT("09"), wxDefaultPosition, wxDefaultSize, 0);
48         NumberText->SetFont(wxFont(24, 70, 90, 92, false, wxEmptyString));
49         
50         TopSectionSizer->Add(HighPriorityIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
51         TopSectionSizer->Add(AlertIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
52         TopSectionSizer->Add(0, 0, 1, wxEXPAND, 5);
53         TopSectionSizer->Add(NumberText, 0, wxALL|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
55         // Setup the scrollable section.
56         
57         Colour EventColour;
58         EventColour.red = 40; EventColour.green = 80; EventColour.blue = 80;
59         
60         EventListFrame->SetSizer(EventListFrameSizer);
61         CalendarEntry1->SetColour(&EventColour);
62         CalendarEntry1->SetDisplayAlarm(false);
63         CalendarEntry1->SetDisplayHighPriority(false);
64         EventListFrameSizer->Add(CalendarEntry1, 0, wxEXPAND, 5);
65         EventListFrameSizer->Add(0, 5, 0, 0, 5);
66         
67         EventColour.red = 255; EventColour.green = 0; EventColour.blue = 0;
68         CalendarEntry2->SetColour(&EventColour);
69         CalendarEntry2->SetDisplayAlarm(true);
70         CalendarEntry2->SetDisplayHighPriority(false);
71         EventListFrameSizer->Add(CalendarEntry2, 0, wxEXPAND, 5);
72         EventListFrameSizer->Add(0, 5, 0, 0, 5);
73         
74         EventColour.red = 0; EventColour.green = 255; EventColour.blue = 0;
75         CalendarEntry3->SetColour(&EventColour);
76         CalendarEntry3->SetDisplayAlarm(false);
77         CalendarEntry3->SetDisplayHighPriority(false);
78         EventListFrameSizer->Add(CalendarEntry3, 0, wxEXPAND, 5);
79         EventListFrameSizer->Add(0, 5, 0, 0, 5);
81         EventColour.red = 0; EventColour.green = 0; EventColour.blue = 255;
82         CalendarEntry4->SetColour(&EventColour);
83         CalendarEntry4->SetDisplayAlarm(false);
84         CalendarEntry4->SetDisplayHighPriority(false);
85         EventListFrameSizer->Add(CalendarEntry4, 0, wxEXPAND, 5);
86         EventListFrameSizer->Add(0, 5, 0, 0, 5);
87         
88         EventListFrameSizer->Add(CalendarEntry5, 0, wxEXPAND, 5);
89         EventListFrameSizer->Add(0, 5, 0, 0, 5);
90         EventListFrameSizer->Add(CalendarEntry6, 0, wxEXPAND, 5);
91         EventListFrameSizer->Add(0, 5, 0, 0, 5);
92         EventListFrameSizer->Add(CalendarEntry7, 0, wxEXPAND, 5);
93         EventListFrameSizer->Add(0, 5, 0, 0, 5);
94         EventListFrameSizer->Add(CalendarEntry8, 0, wxEXPAND, 5);
95         EventListFrameSizer->Add(0, 5, 0, 0, 5);
96         EventListFrameSizer->Add(CalendarEntry9, 0, wxEXPAND, 5);
97         EventListFrameSizer->Add(0, 5, 0, 0, 5);
98         EventListFrameSizer->Add(CalendarEntry10, 0, wxEXPAND, 5);
100         EventListFrame->SetScrollRate(0,1);
101         //EventListFrameSizer->FitInside(EventListFrame);
102         EventListFrameSizer->Fit(EventListFrame);
103         EventListFrameSizer->Layout();
104         WindowSizer->Fit(this);
106         // Setup the scroll window.
107         
108         WindowSizer->Add(TopSectionSizer, 1, wxEXPAND, 5);
109         WindowSizer->Add(MainSectionSizer, 1, wxEXPAND, 5);
110         MainSectionSizer->Add(EventListFrame, 1, wxGROW | wxALL, 10);
112         this->SetSizer(WindowSizer);
113         this->SetSize(size);
114         this->Layout();
115         this->SetBackgroundStyle(wxBG_STYLE_PAINT);
116         this->Centre(wxBOTH);
117         
118         CalendarEntryList.push_back(CalendarEntry1);
119         CalendarEntryList.push_back(CalendarEntry2);
120         CalendarEntryList.push_back(CalendarEntry3);
121         CalendarEntryList.push_back(CalendarEntry4);
122         CalendarEntryList.push_back(CalendarEntry5);
123         CalendarEntryList.push_back(CalendarEntry6);
124         CalendarEntryList.push_back(CalendarEntry7);
125         CalendarEntryList.push_back(CalendarEntry8);
126         CalendarEntryList.push_back(CalendarEntry9);
127         CalendarEntryList.push_back(CalendarEntry10);
128         
129         UpdateTopIcons();
130         
133 XCCalendarDay::~XCCalendarDay(){
134         
135         // Destory the controls from the widget.
136         
139 void XCCalendarDay::Repaint(){
140         
141         wxPaintDC dc(this);
142         wxPaintDC EventListFrameDC(EventListFrame);
143         
144         // Get the wxSizerItem for the top date and the entries part.
146         wxSizerItem *TopSectionSizerItem = WindowSizer->GetItem((size_t)0);
147         wxSizerItem *MainSectionSizerItem = WindowSizer->GetItem((size_t)1);
148         wxRect TopSizer = wxRect(WindowSizer->GetPosition(), WindowSizer->GetSize());
149         
150         if (IsInMonth == true){
151         
152                 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
153                 dc.SetBrush(wxBrush(wxColor(255,255,255)));
154                 dc.DrawRectangle(TopSectionSizerItem->GetRect());
155                 dc.SetBrush(wxBrush(wxColor(225,225,225)));
156                 dc.DrawRectangle(MainSectionSizerItem->GetRect());
157                 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
158                 EventListFrameDC.SetBrush(wxBrush(wxColor(225,225,225)));
159                 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
160                 
161         } else {
163                 dc.SetPen(wxPen(wxColor(185,185,185), 0, wxPENSTYLE_TRANSPARENT));
164                 dc.SetBrush(wxBrush(wxColor(185,185,185)));
165                 dc.DrawRectangle(TopSectionSizerItem->GetRect());
166                 dc.SetBrush(wxBrush(wxColor(155,155,155)));
167                 dc.DrawRectangle(MainSectionSizerItem->GetRect());
168                 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
169                 EventListFrameDC.SetBrush(wxBrush(wxColor(155,155,155)));
170                 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
171                 
172         }
173         
174         // Draw the border.
176         //dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
178         this->Layout();
179         
182 void XCCalendarDay::UpdateTopIcons(){
183         
184         bool AlarmFound = false;
185         bool HighPriorityFound = false;
186         
187         for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
188                 EntryIter != CalendarEntryList.end(); EntryIter++){
190                 if ((*EntryIter)->GetDisplayAlarm() == true){
191                         
192                         AlarmFound = true;
193                         
194                 }
196                 if ((*EntryIter)->GetDisplayHighPriority() == true){
197                         
198                         HighPriorityFound = true;
199                         
200                 }
201                 
202                 if (AlarmFound == true && HighPriorityFound == true){
203                         
204                         break;
205                         
206                 }
207                 
208         }
209         
210         AlertIcon->Show(AlarmFound);
211         HighPriorityIcon->Show(HighPriorityFound);
212         
215 void XCCalendarDay::PaintFrameEvent(wxPaintEvent &PaintEvent)
218         Repaint();
219         
222 void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &SizeEvent)
225         // TODO: Check if window size is less than 120 pixels and if it is,
226         // switch to the small block mode.
227         
228         // Refresh the window.
229         
230         this->Refresh();
231         
234 void XCCalendarDay::DeselectOthersEvent(wxCommandEvent &DeselectEvent)
237         int SelectedEntryID = DeselectEvent.GetInt();
239         wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
240         
241         for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
242                 EntryIter != CalendarEntryList.end(); EntryIter++){
243                         
244                 if ((*EntryIter)->GetID() != SelectedEntryID){
245                         
246                         wxPostEvent((*EntryIter), DeselectEntryEvent);
247                         
248                 }
249                         
250         }
251         
254 void XCCalendarDay::SetupControl(int SetupDay, int SetupMonth, int SetupYear, bool SetupIsInMonth, XCCalendarMonthView *MonthViewPointer)
256         
257         // Set the day
258         
259         NumberText->SetLabel(wxString::Format("%02i", SetupDay));
260         
261         // Set the month
262         
263         // Set the year.
264         
265         // Setup the Is In Month value.
266         
267         IsInMonth = SetupIsInMonth;
268         
269         // Setup the month view pointer.
270         
271         this->MonthViewPointer = MonthViewPointer;
272         
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