Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
2b5eabbfe9c89381403478bd4b355914c7bdd095
[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 //EVT_COMMAND(wxID_ANY, XCCALENDARDAY_DESELECTOTHERENTRIES, XCCalendarDay::DeselectOthersEvent)
27 END_EVENT_TABLE()
29 XCCalendarDay::XCCalendarDay(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size)
30         : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
31         
32         Connect(wxID_ANY, XCCALENDARDAY_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectOthersEvent));
33         
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);
143         // Get the wxSizerItem for the top date and the entries part.
145         wxSizerItem *TopSectionSizerItem = WindowSizer->GetItem((size_t)0);
146         wxSizerItem *MainSectionSizerItem = WindowSizer->GetItem((size_t)1);
147         wxRect TopSizer = wxRect(WindowSizer->GetPosition(), WindowSizer->GetSize());
148         
149         dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
150         dc.DrawRectangle(TopSectionSizerItem->GetRect());
151         dc.SetBrush(wxBrush(wxColor(225,225,225)));
152         dc.DrawRectangle(MainSectionSizerItem->GetRect());
153         
154         // Draw the border.
155         
156         this->Layout();
158         dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
159         
160         wxPaintDC EventListFrameDC(EventListFrame);
161         EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
162         EventListFrameDC.SetBrush(wxBrush(wxColor(225,225,225)));
163         EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
167 void XCCalendarDay::UpdateTopIcons(){
168         
169         bool AlarmFound = false;
170         bool HighPriorityFound = false;
171         
172         for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
173                 EntryIter != CalendarEntryList.end(); EntryIter++){
175                 if ((*EntryIter)->GetDisplayAlarm() == true){
176                         
177                         AlarmFound = true;
178                         
179                 }
181                 if ((*EntryIter)->GetDisplayHighPriority() == true){
182                         
183                         HighPriorityFound = true;
184                         
185                 }
186                 
187                 if (AlarmFound == true && HighPriorityFound == true){
188                         
189                         break;
190                         
191                 }
192                 
193         }
194         
195         AlertIcon->Show(AlarmFound);
196         HighPriorityIcon->Show(HighPriorityFound);
197         
200 void XCCalendarDay::PaintFrameEvent(wxPaintEvent &PaintEvent)
203         Repaint();
204         
207 void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &SizeEvent)
210         // TODO: Check if window size is less than 120 pixels and if it is,
211         // switch to the small block mode.
212         
213         // Refresh the window.
214         
215         this->Refresh();
216         
219 void XCCalendarDay::DeselectOthersEvent(wxCommandEvent &DeselectEvent)
222         int SelectedEntryID = DeselectEvent.GetInt();
224         wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
225         
226         for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
227                 EntryIter != CalendarEntryList.end(); EntryIter++){
228                         
229                 if ((*EntryIter)->GetID() != SelectedEntryID){
230                         
231                         wxPostEvent((*EntryIter), DeselectEntryEvent);
232                         
233                 }
234                         
235         }
236         
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