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 "XCCalendarMenu.h"
21 XCCalendarMenu::XCCalendarMenu(){
23 // Setup the menu items.
25 AppendMenuItem(wxT("opencontact"), _("Edit Calendar"), wxT(""), ID_CALENDARMENU_EDIT, wxITEM_NORMAL);
26 AppendMenuItem(wxT("deletecontact"), _("Delete Calendar"), wxT(""), ID_CALENDARMENU_DELETE, wxITEM_NORMAL);
30 XCCalendarMenu::~XCCalendarMenu(){
32 // Destory the XCCalendarMenu 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(XCCalendarMenu::ProcessMenuItemClick) );
43 delete(menuItemIter->second);
44 menuItemIter->second = NULL;
52 void XCCalendarMenu::AppendMenuItem(wxString objectName,
54 wxString menuDescription,
55 XCCalendarMenuID itemID,
58 if (itemType == wxITEM_SEPARATOR){
59 this->AppendSeparator();
63 // Append a menu item to the XCCalendarMenu control.
65 wxMenuItem *menuitem = this->Append(itemID, menuName, menuDescription);
66 this->Connect(menuitem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(XCCalendarMenu::ProcessMenuItemClick));
67 menuItems.insert(std::make_pair(objectName.ToStdString(), menuitem));
71 wxMenu* XCCalendarMenu::MenuPointer(){
77 void XCCalendarMenu::ProcessMenuItemClick( wxCommandEvent& event){
79 // Process an action when a menu item in the XCCalendarMenu
80 // control is selected.
82 int itemID = event.GetId();
88 case ID_CALENDARMENU_EDIT:
90 wxCommandEvent editCalendar(XCMAIN_EDITCALENDAR);
91 editCalendar.SetId(ID_EDITCALENDAR);
92 editCalendar.SetInt(calendarID);
93 wxPostEvent(windowPtr->GetParent()->GetParent()->GetParent()->GetParent(), editCalendar);
96 case ID_CALENDARMENU_DELETE:
98 CalendarProperties *calendarInfo = new CalendarProperties;
100 calendarInfo->calendarID = calendarID;
101 calendarInfo->accountPreferencesID = accountPreferencesID;
103 wxCommandEvent deleteCalendar(XCMAIN_DELETECALENDAR);
104 deleteCalendar.SetId(ID_DELETECALENDAR);
105 deleteCalendar.SetClientData(calendarInfo);
106 wxPostEvent(windowPtr->GetParent()->GetParent()->GetParent()->GetParent(), deleteCalendar);
114 void XCCalendarMenu::SetCalendarID(int calendarID){
116 this->calendarID = calendarID;
120 void XCCalendarMenu::SetAccountPreferencesID(int accountPreferencesID){
122 this->accountPreferencesID = accountPreferencesID;
126 void XCCalendarMenu::SetWindowPointer(wxWindow *windowPointer){
128 windowPtr = windowPointer;
132 void XCCalendarMenu::SetPopupPointer(wxPopupTransientWindow *popupPointer){
134 popupPtr = popupPointer;