Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Initial version of the XCCalendarDayEntry widget
[xestiacalendar/.git] / source / widgets / XCCalendarDayEntry.cpp
1 // XCCalendarDayEntry.cpp - Xestia Calendar XCCalendarDayEntry 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 "XCCalendarDayEntry.h"
21 BEGIN_EVENT_TABLE(XCCalendarDayEntry, wxPanel)
22 EVT_PAINT(XCCalendarDayEntry::PaintFrameEvent)
23 EVT_SIZE(XCCalendarDayEntry::ResizeFrameEvent)
24 EVT_LEFT_DOWN(XCCalendarDayEntry::LeftClick)
25 END_EVENT_TABLE()
27 using namespace std;
29 XCCalendarDayEntry::XCCalendarDayEntry(wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size, const int id)
30         : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title)
31 {
33         Connect(wxID_ANY, XCCALENDARDAYENTRY_DESELECT, wxCommandEventHandler(XCCalendarDayEntry::Deselect));
34         
35         DayPanel = parent->GetParent();
36         EntryID = id;
37         
38         this->SetMinSize(wxSize(65, 30));
39         
40         EventTextData = title.mb_str();
41         EventText = new wxStaticText(this, wxID_ANY, title, wxPoint(49, 8), wxDefaultSize, wxST_ELLIPSIZE_END);
42         
43         AlarmIconBitmap.LoadFile("AlertIcon.png", wxBITMAP_DEFAULT_TYPE);
44         PriorityIconBitmap.LoadFile("PriorityIcon.png", wxBITMAP_DEFAULT_TYPE);
46         AlarmIcon->SetBitmap(AlarmIconBitmap);
47         HighPriorityIcon->SetBitmap(PriorityIconBitmap);
48         
49         UpdateInformation();
50         
51 }
53 XCCalendarDayEntry::~XCCalendarDayEntry(){
54         
55         // Destory the controls from the widget.
56         
57 }
59 void XCCalendarDayEntry::Repaint(){
60         
61         wxPaintDC dc(this);
63         // Get the wxSizerItem for the top date and the entries part.
65         dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
66         
67         /*wxRect Test;
68         
69         Test.SetX(this->GetClientRect().GetX());
70         Test.SetY(this->GetClientRect().GetY());
71         Test.SetHeight(this->GetClientRect().GetHeight());
72         Test.SetWidth(this->GetClientRect().GetWidth());
73         
74         cout << Test.GetX() << "|" << Test.GetY() << "|" << Test.GetHeight() << "|" << Test.GetWidth() << "|" << endl;*/
75         
76         dc.DrawRectangle(this->GetClientRect());
77         
78         // Draw the calendar colour.
79         
80         dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
81         dc.SetBrush(wxBrush(wxColor(EntryColour.red,
82                 EntryColour.green,
83                 EntryColour.blue), wxBRUSHSTYLE_SOLID));
84         dc.DrawRectangle(wxRect(1,1,10,28));
85         
86 }
88 void XCCalendarDayEntry::UpdateInformation(){
90         PositionMode = 0;
92         // Check if the high priority icon needs to be displayed.
93         
94         if (HasHighPriority == true){
95                 
96                 HighPriorityIcon->SetPosition(wxPoint(FirstPosition,7));
98                 HighPriorityIcon->Show(true);
99                 
100                 PositionMode++;
101                 
102         } else {
103                 
104                 HighPriorityIcon->Show(false);
105                 
106         }
107         
108         // Check if the alarm icon needs to be displayed.
109         
110         if (HasAlarm == true){
111                 
112                 switch(PositionMode){
113                         case 0:
114                                 AlarmIcon->SetPosition(wxPoint(FirstPosition,7));
115                                 break;
116                         case 1:
117                                 AlarmIcon->SetPosition(wxPoint(SecondPosition,7));
118                                 break;
119                 }
120                 
121                 AlarmIcon->Show(true);
122                 
123                 PositionMode++;
124                 
125         } else {
126                 
127                 AlarmIcon->Show(false);
128                 
129         }
130         
131         // Now set the text.
132         
133         switch(PositionMode){
134                 case 0:
135                         EventText->SetPosition(wxPoint(FirstPosition,8));
136                         break;
137                 case 1:
138                         EventText->SetPosition(wxPoint(SecondPosition,8));
139                         break;
140                 case 2:
141                         EventText->SetPosition(wxPoint(ThirdPosition,8));
142                         break;
143         }
144         
147 void XCCalendarDayEntry::PaintFrameEvent(wxPaintEvent &PaintEvent)
150         Repaint();
151         
154 void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &SizeEvent)
156         
157         // Adjust the Event text so it is displayed properly.
158         
159         switch(PositionMode){
160                 case 0:
161                         EventText->SetSize(wxSize((this->GetClientRect().width - FirstPosition - 5),15));
162                         break;
163                 case 1:
164                         EventText->SetSize(wxSize((this->GetClientRect().width - SecondPosition - 5),15));
165                         break;
166                 case 2:
167                         EventText->SetSize(wxSize((this->GetClientRect().width - ThirdPosition - 5),15));
168                         break;
169         }
170         
171         // Refresh the window.
172         
173         this->Refresh();
174         
177 void XCCalendarDayEntry::LeftClick(wxMouseEvent &MouseEvent)
179         
180         // Change the background of the widget to mark 
181         // the entry as selected.
182         
183         this->SetBackgroundColour(wxColor(255,215,0));
184         wxCommandEvent DeselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES);
185         DeselectOthersEvent.SetInt(EntryID);
186         wxPostEvent(DayPanel, DeselectOthersEvent);
187         
190 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
191         
192         this->SetBackgroundColour(wxNullColour);
193         
196 void XCCalendarDayEntry::SetColour(Colour *ColourIn){
197         
198         EntryColour = *ColourIn;
199         
202 void XCCalendarDayEntry::SetDisplayAlarm(bool DisplayValue){
203         
204         HasAlarm = DisplayValue;
205         UpdateInformation();
206         
209 void XCCalendarDayEntry::SetDisplayHighPriority(bool DisplayValue){
210         
211         HasHighPriority = DisplayValue;
212         UpdateInformation();    
213         
216 bool XCCalendarDayEntry::GetDisplayAlarm(){
217         
218         return HasAlarm;
219         
222 bool XCCalendarDayEntry::GetDisplayHighPriority(){
223         
224         return HasHighPriority;
225         
228 int XCCalendarDayEntry::GetID(){
229         
230         return EntryID;
231         
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