Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
047bc4a0bd303a03e9ee9037daa925424b640028
[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         
32         DayPanel = parent->GetParent();
33         EntryID = id;
34         
35         this->SetMinSize(wxSize(65, 30));
36         
37         EventTextData = title.mb_str();
38         EventText = new wxStaticText(this, wxID_ANY, title, wxPoint(49, 8), wxDefaultSize, wxST_ELLIPSIZE_END);
40         wxMemoryInputStream alerticon(icons_alert_png, sizeof(icons_alert_png));
41         wxMemoryInputStream priorityicon(icons_priority_png, sizeof(icons_priority_png));
42                 
43         wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
44         AlarmIconBitmap = wxBitmap(icons_alert_png, -1);
46         wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
47         PriorityIconBitmap = wxBitmap(icons_priority_png, -1);
48                 
49         AlarmIcon->SetBitmap(AlarmIconBitmap);
50         HighPriorityIcon->SetBitmap(PriorityIconBitmap);
52         Connect(wxID_ANY, XCCALENDARDAYENTRY_DESELECT, wxCommandEventHandler(XCCalendarDayEntry::Deselect));
53         AlarmIcon->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
54         HighPriorityIcon->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
55         EventText->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
56         
57         UpdateInformation();
58         
59 }
61 XCCalendarDayEntry::~XCCalendarDayEntry(){
62         
63         // Destory the controls from the widget.
64         
65 }
67 void XCCalendarDayEntry::Repaint(){
68         
69         wxPaintDC dc(this);
71         // Get the wxSizerItem for the top date and the entries part.
73         dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
74         
75         /*wxRect Test;
76         
77         Test.SetX(this->GetClientRect().GetX());
78         Test.SetY(this->GetClientRect().GetY());
79         Test.SetHeight(this->GetClientRect().GetHeight());
80         Test.SetWidth(this->GetClientRect().GetWidth());
81         
82         cout << Test.GetX() << "|" << Test.GetY() << "|" << Test.GetHeight() << "|" << Test.GetWidth() << "|" << endl;*/
83         
84         dc.DrawRectangle(this->GetClientRect());
85         
86         // Draw the calendar colour.
87         
88         dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
89         dc.SetBrush(wxBrush(wxColor(EntryColour.red,
90                 EntryColour.green,
91                 EntryColour.blue), wxBRUSHSTYLE_SOLID));
92         dc.DrawRectangle(wxRect(1,1,10,28));
93         
94 }
96 void XCCalendarDayEntry::UpdateInformation(){
98         PositionMode = 0;
100         // Check if the high priority icon needs to be displayed.
101         
102         if (HasHighPriority == true){
103                 
104                 HighPriorityIcon->SetPosition(wxPoint(FirstPosition,7));
106                 HighPriorityIcon->Show(true);
107                 
108                 PositionMode++;
109                 
110         } else {
111                 
112                 HighPriorityIcon->Show(false);
113                 
114         }
115         
116         // Check if the alarm icon needs to be displayed.
117         
118         if (HasAlarm == true){
119                 
120                 switch(PositionMode){
121                         case 0:
122                                 AlarmIcon->SetPosition(wxPoint(FirstPosition,7));
123                                 break;
124                         case 1:
125                                 AlarmIcon->SetPosition(wxPoint(SecondPosition,7));
126                                 break;
127                 }
128                 
129                 AlarmIcon->Show(true);
130                 
131                 PositionMode++;
132                 
133         } else {
134                 
135                 AlarmIcon->Show(false);
136                 
137         }
138         
139         // Now set the text.
140         
141         switch(PositionMode){
142                 case 0:
143                         EventText->SetPosition(wxPoint(FirstPosition,8));
144                         break;
145                 case 1:
146                         EventText->SetPosition(wxPoint(SecondPosition,8));
147                         break;
148                 case 2:
149                         EventText->SetPosition(wxPoint(ThirdPosition,8));
150                         break;
151         }
152         
155 void XCCalendarDayEntry::PaintFrameEvent(wxPaintEvent &PaintEvent){
157         Repaint();
158         
161 void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &SizeEvent){
162         
163         // Adjust the Event text so it is displayed properly.
164         
165         switch(PositionMode){
166                 case 0:
167                         EventText->SetSize(wxSize((this->GetClientRect().width - FirstPosition - 5),15));
168                         break;
169                 case 1:
170                         EventText->SetSize(wxSize((this->GetClientRect().width - SecondPosition - 5),15));
171                         break;
172                 case 2:
173                         EventText->SetSize(wxSize((this->GetClientRect().width - ThirdPosition - 5),15));
174                         break;
175         }
176         
177         // Refresh the window.
178         
179         this->Refresh();
180         
183 void XCCalendarDayEntry::LeftClick(wxMouseEvent &MouseEvent){
184         
185         // Change the background of the widget to mark 
186         // the entry as selected.
187         
188         this->SetBackgroundColour(wxColor(255,215,0));
189         wxCommandEvent DeselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES);
190         DeselectOthersEvent.SetInt(EntryID);
191         wxPostEvent(DayPanel, DeselectOthersEvent);
192         
195 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
196         
197         this->SetBackgroundColour(wxNullColour);
198         
201 void XCCalendarDayEntry::SetColour(Colour *ColourIn){
202         
203         EntryColour = *ColourIn;
204         
207 void XCCalendarDayEntry::SetDisplayAlarm(bool DisplayValue){
208         
209         HasAlarm = DisplayValue;
210         UpdateInformation();
211         
214 void XCCalendarDayEntry::SetDisplayHighPriority(bool DisplayValue){
215         
216         HasHighPriority = DisplayValue;
217         UpdateInformation();    
218         
221 bool XCCalendarDayEntry::GetDisplayAlarm(){
222         
223         return HasAlarm;
224         
227 bool XCCalendarDayEntry::GetDisplayHighPriority(){
228         
229         return HasHighPriority;
230         
233 int XCCalendarDayEntry::GetID(){
234         
235         return EntryID;
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