// XCCalendarMenu.cpp - XCCalendarMenu widget
//
// (c) 2012-2017 Xestia Software Development.
//
// This file is part of Xestia Calendar. Original code from Xestia Address Book.
//
// Xestia Calendar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by the
// Free Software Foundation, version 3 of the license.
//
// Xestia Calendar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with Xestia Calendar. If not, see
#include "XCEventMenu.h"
XCEventMenu::XCEventMenu(){
// Setup the menu items.
AppendMenuItem(wxT("editevent"), _("Edit Event"), wxT(""), ID_EVENTMENU_EDIT, wxITEM_NORMAL);
AppendMenuItem(wxT("deleteevent"), _("Delete Event"), wxT(""), ID_EVENTMENU_DELETE, wxITEM_NORMAL);
}
XCEventMenu::~XCEventMenu(){
// Destory the XCEventMenu object.
// Delete the menu items.
for (std::map::iterator menuItemIter = menuItems.begin();
menuItemIter != menuItems.end(); ++menuItemIter){
// Delete the wxMenuItem object.
this->Disconnect(menuItemIter->second->GetId(), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(XCEventMenu::ProcessMenuItemClick) );
delete(menuItemIter->second);
menuItemIter->second = NULL;
}
menuItems.clear();
}
void XCEventMenu::AppendMenuItem(wxString objectName,
wxString menuName,
wxString menuDescription,
XCEventMenuID itemID,
wxItemKind itemType){
if (itemType == wxITEM_SEPARATOR){
this->AppendSeparator();
return;
}
// Append a menu item to the XCEventMenu control.
wxMenuItem *menuitem = this->Append(itemID, menuName, menuDescription);
this->Connect(menuitem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(XCEventMenu::ProcessMenuItemClick));
menuItems.insert(std::make_pair(objectName.ToStdString(), menuitem));
}
wxMenu* XCEventMenu::MenuPointer(){
return this;
}
void XCEventMenu::ProcessMenuItemClick( wxCommandEvent& event){
// Process an action when a menu item in the XCEventMenu
// control is selected.
int itemID = event.GetId();
switch (itemID){
case ID_EVENTMENU_EDIT:
{
wxCommandEvent editEntry(XCMAIN_EDITEVENT);
editEntry.SetId(ID_EDITEVENT);
editEntry.SetInt(eventID);
wxPostEvent(windowPtr, editEntry);
}
break;
case ID_EVENTMENU_DELETE:
{
EventProperties *eventInfo = new EventProperties;
eventInfo->calendarID = calendarID;
eventInfo->eventID = eventID;
wxCommandEvent deleteEvent(XCMAIN_DELETEEVENT);
deleteEvent.SetId(ID_DELETEEVENT);
deleteEvent.SetClientData(eventInfo);
wxPostEvent(windowPtr, deleteEvent);
}
break;
}
}
void XCEventMenu::SetCalendarID(int calendarID){
this->calendarID = calendarID;
}
void XCEventMenu::SetEventID(int eventID){
this->eventID = eventID;
}
void XCEventMenu::SetWindowPointer(wxWindow *windowPointer){
windowPtr = windowPointer;
}