X-Git-Url: http://Server1/repobrowser/?p=xestiacalendar%2F.git;a=blobdiff_plain;f=source%2Fwidgets%2FXCCalendarDayEntry.cpp;h=034e5e725c09fa50cb8054d44b39f7e27c893c7c;hp=7ec8de0017343aaa4023dadded50dd108ab0874a;hb=902d948e5e45ad483c8e235690dda8f2bf596ad5;hpb=c5716d0f27f0f917282df9121aa97eab7a1bf6b8 diff --git a/source/widgets/XCCalendarDayEntry.cpp b/source/widgets/XCCalendarDayEntry.cpp index 7ec8de0..034e5e7 100644 --- a/source/widgets/XCCalendarDayEntry.cpp +++ b/source/widgets/XCCalendarDayEntry.cpp @@ -18,8 +18,9 @@ #include "XCCalendarDayEntry.h" +wxDEFINE_EVENT(XCCALENDARDAYENTRY_DESELECT, wxCommandEvent); + BEGIN_EVENT_TABLE(XCCalendarDayEntry, wxPanel) -EVT_PAINT(XCCalendarDayEntry::PaintFrameEvent) EVT_SIZE(XCCalendarDayEntry::ResizeFrameEvent) EVT_LEFT_UP(XCCalendarDayEntry::LeftClick) EVT_RIGHT_UP(XCCalendarDayEntry::RightClick) @@ -29,189 +30,221 @@ using namespace std; XCCalendarDayEntry::XCCalendarDayEntry(wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size, const int id) : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){ - - DayPanel = parent->GetParent(); + dayPanel = parent->GetParent(); eventID = id; this->SetMinSize(wxSize(65, 30)); + + // Setup the main panel and main sizer. + + mainPanel = new wxPanel(this, wxID_ANY, wxPoint(0,0), this->GetSize(), wxTAB_TRAVERSAL|wxSIMPLE_BORDER); + mainSizer = new wxBoxSizer( wxVERTICAL ); + + // Setup the calendar colour. - EventTextData = title.mb_str(); - EventText = new wxStaticText(this, wxID_ANY, title, wxPoint(49, 14), wxDefaultSize, wxST_ELLIPSIZE_END); - EventTime = new wxStaticText(this, wxID_ANY, wxT("Time"), wxPoint(49,3), wxDefaultSize, 0); + calendarColour = new wxPanel(mainPanel, wxID_ANY, wxPoint(0,0), wxSize(10, 30), wxTAB_TRAVERSAL|wxEXPAND, "Calendar Colour"); + calendarColour->SetBackgroundColour(wxColour(80, 40, 40, 100)); + + // Setup the event text. - wxFont eventTimeFont = EventTime->GetFont(); + eventTextData = title.mb_str(); + eventText = new wxStaticText(mainPanel, wxID_ANY, title, wxPoint(49, 14), wxDefaultSize, wxST_ELLIPSIZE_END); + eventTime = new wxStaticText(mainPanel, wxID_ANY, wxT("Time"), wxPoint(49,3), wxDefaultSize, 0); + + wxFont eventTimeFont = eventTime->GetFont(); eventTimeFont.MakeBold(); - EventTime->SetFont(eventTimeFont); + eventTime->SetFont(eventTimeFont); + // Setup the images. + wxMemoryInputStream alerticon(icons_alert_png, sizeof(icons_alert_png)); wxMemoryInputStream priorityicon(icons_priority_png, sizeof(icons_priority_png)); wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG); - AlarmIconBitmap = wxBitmap(icons_alert_png, -1); + alarmIconBitmap = wxBitmap(icons_alert_png, -1); wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG); - PriorityIconBitmap = wxBitmap(icons_priority_png, -1); + priorityIconBitmap = wxBitmap(icons_priority_png, -1); - AlarmIcon->SetBitmap(AlarmIconBitmap); - HighPriorityIcon->SetBitmap(PriorityIconBitmap); - - Connect(ID_ENTRYDESELECT, XCCALENDARDAYENTRY_DESELECT, wxCommandEventHandler(XCCalendarDayEntry::Deselect)); + alarmIcon->SetBitmap(alarmIconBitmap); + highPriorityIcon->SetBitmap(priorityIconBitmap); - AlarmIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); - HighPriorityIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); - EventText->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); - EventTime->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); - DayPanel->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + // Setup the connections for the control. - AlarmIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); - HighPriorityIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); - EventText->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); - EventTime->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); - DayPanel->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + calendarColour->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + alarmIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + highPriorityIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + eventText->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + eventTime->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + dayPanel->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + + calendarColour->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + alarmIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + highPriorityIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + eventText->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + eventTime->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + dayPanel->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); UpdateInformation(); + // Bind events to the control. + + Bind(XCCALENDARDAYENTRY_DESELECT, &XCCalendarDayEntry::Deselect, this, ID_ENTRYDESELECT); + + // Set the control's sizer. + + this->SetSizer(mainSizer); + mainSizer->Add(mainPanel, 0, wxEXPAND, 1); } XCCalendarDayEntry::~XCCalendarDayEntry(){ // Destory the controls from the widget. -} - -void XCCalendarDayEntry::Repaint(){ + // Disconnect and unbind. - wxPaintDC dc(this); - - // Get the wxSizerItem for the top date and the entries part. + calendarColour->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + alarmIcon->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + highPriorityIcon->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + eventText->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + eventTime->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + dayPanel->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); - dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT)); + calendarColour->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + alarmIcon->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + highPriorityIcon->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + eventText->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + eventTime->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + dayPanel->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); - /*wxRect Test; + Unbind(XCCALENDARDAYENTRY_DESELECT, &XCCalendarDayEntry::Deselect, this, ID_ENTRYDESELECT); - Test.SetX(this->GetClientRect().GetX()); - Test.SetY(this->GetClientRect().GetY()); - Test.SetHeight(this->GetClientRect().GetHeight()); - Test.SetWidth(this->GetClientRect().GetWidth()); + // Delete the controls. - cout << Test.GetX() << "|" << Test.GetY() << "|" << Test.GetHeight() << "|" << Test.GetWidth() << "|" << endl;*/ + mainSizer->Clear(); - dc.DrawRectangle(this->GetClientRect()); + delete eventText; + eventText = nullptr; - // Draw the calendar colour. + delete eventTime; + eventTime = nullptr; - dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT)); - dc.SetBrush(wxBrush(wxColor(EntryColour.red, - EntryColour.green, - EntryColour.blue), wxBRUSHSTYLE_SOLID)); - dc.DrawRectangle(wxRect(1,1,10,28)); + delete calendarColour; + calendarColour = nullptr; + + delete mainPanel; + mainPanel = nullptr; + + delete highPriorityIcon; + delete alarmIcon; + + this->SetSizer(nullptr, true); } void XCCalendarDayEntry::UpdateInformation(){ - PositionMode = 0; + positionMode = 0; // Check if the high priority icon needs to be displayed. - if (HasHighPriority == true){ + if (hasHighPriority == true){ - HighPriorityIcon->SetPosition(wxPoint(FirstPosition,7)); + highPriorityIcon->SetPosition(wxPoint(firstPosition,7)); - HighPriorityIcon->Show(true); + highPriorityIcon->Show(true); - PositionMode++; + positionMode++; } else { - HighPriorityIcon->Show(false); + highPriorityIcon->Show(false); } // Check if the alarm icon needs to be displayed. - if (HasAlarm == true){ + if (hasAlarm == true){ - switch(PositionMode){ + switch(positionMode){ case 0: - AlarmIcon->SetPosition(wxPoint(FirstPosition,7)); + alarmIcon->SetPosition(wxPoint(firstPosition,7)); break; case 1: - AlarmIcon->SetPosition(wxPoint(SecondPosition,7)); + alarmIcon->SetPosition(wxPoint(secondPosition,7)); break; } - AlarmIcon->Show(true); + alarmIcon->Show(true); - PositionMode++; + positionMode++; } else { - AlarmIcon->Show(false); + alarmIcon->Show(false); } // Now set the text. - switch(PositionMode){ + switch(positionMode){ case 0: - EventText->SetPosition(wxPoint(FirstPosition,14)); - EventTime->SetPosition(wxPoint(FirstPosition,3)); + eventText->SetPosition(wxPoint(firstPosition,14)); + eventTime->SetPosition(wxPoint(firstPosition,3)); break; case 1: - EventText->SetPosition(wxPoint(SecondPosition,14)); - EventTime->SetPosition(wxPoint(FirstPosition,3)); + eventText->SetPosition(wxPoint(secondPosition,14)); + eventTime->SetPosition(wxPoint(firstPosition,3)); break; case 2: - EventText->SetPosition(wxPoint(ThirdPosition,14)); - EventTime->SetPosition(wxPoint(FirstPosition,3)); + eventText->SetPosition(wxPoint(thirdPosition,14)); + eventTime->SetPosition(wxPoint(firstPosition,3)); break; } } -void XCCalendarDayEntry::PaintFrameEvent(wxPaintEvent &PaintEvent){ - - Repaint(); - -} - -void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &SizeEvent){ +void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &sizeEvent){ // Adjust the Event text so it is displayed properly. - switch(PositionMode){ + switch(positionMode){ case 0: - EventText->SetSize(wxSize((this->GetClientRect().width - FirstPosition - 5),15)); - EventTime->SetSize(wxSize((this->GetClientRect().width - FirstPosition - 5),15)); + eventText->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15)); + eventTime->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15)); break; case 1: - EventText->SetSize(wxSize((this->GetClientRect().width - SecondPosition - 5),15)); - EventTime->SetSize(wxSize((this->GetClientRect().width - SecondPosition - 5),15)); + eventText->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15)); + eventTime->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15)); break; case 2: - EventText->SetSize(wxSize((this->GetClientRect().width - ThirdPosition - 5),14)); - EventTime->SetSize(wxSize((this->GetClientRect().width - ThirdPosition - 5),15)); + eventText->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),14)); + eventTime->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),15)); break; } + // Resize the main panel. + + mainPanel->SetSize(this->GetSize()); + // Refresh the window. this->Refresh(); } -void XCCalendarDayEntry::LeftClick(wxMouseEvent &MouseEvent){ +void XCCalendarDayEntry::LeftClick(wxMouseEvent &mouseEvent){ // Change the background of the widget to mark // the entry as selected. - this->SetBackgroundColour(wxColor(255,215,0)); - wxCommandEvent DeselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES); - DeselectOthersEvent.SetInt(eventID); - DeselectOthersEvent.SetId(ID_DESELECTOTHERENTRIES); - wxPostEvent(DayPanel, DeselectOthersEvent); - + mainPanel->SetBackgroundColour(wxColor(255,215,0)); + wxCommandEvent deselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES); + deselectOthersEvent.SetInt(eventID); + deselectOthersEvent.SetId(ID_DESELECTOTHERENTRIES); + wxPostEvent(dayPanel, deselectOthersEvent); + this->Refresh(); + } void XCCalendarDayEntry::RightClick(wxMouseEvent &MouseEvent){ @@ -231,7 +264,8 @@ void XCCalendarDayEntry::RightClick(wxMouseEvent &MouseEvent){ void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){ - this->SetBackgroundColour(wxNullColour); + mainPanel->SetBackgroundColour(wxNullColour); + this->Refresh(); } @@ -242,40 +276,40 @@ void XCCalendarDayEntry::SetTime(int timeHour, int timeMinute, int timeSecond){ this->timeSecond = timeSecond; string timeOutput = BuildEventTime(timeHour, timeMinute); - EventTime->SetLabel(timeOutput); + eventTime->SetLabel(timeOutput); } -void XCCalendarDayEntry::SetColour(Colour *ColourIn){ - - EntryColour = *ColourIn; - Repaint(); +void XCCalendarDayEntry::SetColour(Colour *colourIn){ + calendarColour->SetBackgroundColour(wxColour(colourIn->red, colourIn->green, colourIn->blue, colourIn->alpha)); + this->Refresh(); + } -void XCCalendarDayEntry::SetDisplayAlarm(bool DisplayValue){ +void XCCalendarDayEntry::SetDisplayAlarm(bool displayValue){ - HasAlarm = DisplayValue; + hasAlarm = displayValue; UpdateInformation(); } -void XCCalendarDayEntry::SetDisplayHighPriority(bool DisplayValue){ +void XCCalendarDayEntry::SetDisplayHighPriority(bool displayValue){ - HasHighPriority = DisplayValue; + hasHighPriority = displayValue; UpdateInformation(); } bool XCCalendarDayEntry::GetDisplayAlarm(){ - return HasAlarm; + return hasAlarm; } bool XCCalendarDayEntry::GetDisplayHighPriority(){ - return HasHighPriority; + return hasHighPriority; } @@ -355,7 +389,7 @@ void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){ void XCCalendarDayEntry::SetEventName(string eventName){ - EventText->SetLabel((wxString)eventName); + eventText->SetLabel(wxString(eventName)); } @@ -365,13 +399,13 @@ wxSizerItem* XCCalendarDayEntry::GetAfterSpacer(){ } -bool XCCalendarDayEntry::SetShowAccountStatus(bool statusInput){ +void XCCalendarDayEntry::SetShowAccountStatus(bool statusInput){ showAccount = statusInput; } -bool XCCalendarDayEntry::SetShowCalendarStatus(bool statusInput){ +void XCCalendarDayEntry::SetShowCalendarStatus(bool statusInput){ showCalendar = statusInput;