1 // XCCalendarMenu.cpp - XCCalendarMenu widget
3 // (c) 2012-2017 Xestia Software Development.
5 // This file is part of Xestia Calendar. Original code from Xestia Address Book.
7 // Xestia Calendar 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.
11 // Xestia Calendar 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.
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 "XCEventMenu.h"
21 XCEventMenu::XCEventMenu(){
23 // Setup the menu items.
25 AppendMenuItem(wxT("editevent"), _("Edit Event"), wxT(""), ID_EVENTMENU_EDIT, wxITEM_NORMAL);
26 AppendMenuItem(wxT("deleteevent"), _("Delete Event"), wxT(""), ID_EVENTMENU_DELETE, wxITEM_NORMAL);
30 XCEventMenu::~XCEventMenu(){
32 // Destory the XCEventMenu object.
34 // Delete the menu items.
36 for (std::map<std::string, wxMenuItem*>::iterator menuItemIter = menuItems.begin();
37 menuItemIter != menuItems.end(); ++menuItemIter){
39 // Delete the wxMenuItem object.
41 this->Disconnect(menuItemIter->second->GetId(), wxEVT_COMMAND_MENU_SELECTED,
42 wxCommandEventHandler(XCEventMenu::ProcessMenuItemClick) );
43 delete(menuItemIter->second);
44 menuItemIter->second = NULL;
52 void XCEventMenu::AppendMenuItem(wxString objectName,
54 wxString menuDescription,
58 if (itemType == wxITEM_SEPARATOR){
59 this->AppendSeparator();
63 // Append a menu item to the XCEventMenu control.
65 wxMenuItem *menuitem = this->Append(itemID, menuName, menuDescription);
66 this->Connect(menuitem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(XCEventMenu::ProcessMenuItemClick));
67 menuItems.insert(std::make_pair(objectName.ToStdString(), menuitem));
71 wxMenu* XCEventMenu::MenuPointer(){
77 void XCEventMenu::ProcessMenuItemClick( wxCommandEvent& event){
79 // Process an action when a menu item in the XCEventMenu
80 // control is selected.
82 int itemID = event.GetId();
86 case ID_EVENTMENU_EDIT:
88 wxCommandEvent editEntry(XCMAIN_EDITEVENT);
89 editEntry.SetId(ID_EDITEVENT);
90 editEntry.SetInt(eventID);
91 wxPostEvent(WindowPtr, editEntry);
94 case ID_EVENTMENU_DELETE:
96 EventProperties *eventInfo = new EventProperties;
98 eventInfo->calendarID = calendarID;
99 eventInfo->eventID = eventID;
101 wxCommandEvent deleteEvent(XCMAIN_DELETEEVENT);
102 deleteEvent.SetId(ID_DELETEEVENT);
103 deleteEvent.SetClientData(eventInfo);
104 wxPostEvent(WindowPtr, deleteEvent);
112 void XCEventMenu::SetCalendarID(int calendarID){
114 this->calendarID = calendarID;
118 void XCEventMenu::SetEventID(int eventID){
120 this->eventID = eventID;
124 void XCEventMenu::SetWindowPointer(wxWindow *windowPointer){
126 windowPtr = windowPointer;