// 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 "XCCalendarMenu.h"
XCCalendarMenu::XCCalendarMenu(){
// Setup the menu items.
AppendMenuItem(wxT("opencontact"), _("Edit Calendar"), wxT(""), ID_CALENDARMENU_EDIT, wxITEM_NORMAL);
AppendMenuItem(wxT("deletecontact"), _("Delete Calendar"), wxT(""), ID_CALENDARMENU_DELETE, wxITEM_NORMAL);
}
XCCalendarMenu::~XCCalendarMenu(){
// Destory the XCCalendarMenu 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(XCCalendarMenu::ProcessMenuItemClick) );
delete(menuItemIter->second);
menuItemIter->second = NULL;
}
menuItems.clear();
}
void XCCalendarMenu::AppendMenuItem(wxString objectName,
wxString menuName,
wxString menuDescription,
XCCalendarMenuID itemID,
wxItemKind itemType){
if (itemType == wxITEM_SEPARATOR){
this->AppendSeparator();
return;
}
// Append a menu item to the XCCalendarMenu control.
wxMenuItem *menuitem = this->Append(itemID, menuName, menuDescription);
this->Connect(menuitem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(XCCalendarMenu::ProcessMenuItemClick));
menuItems.insert(std::make_pair(objectName.ToStdString(), menuitem));
}
wxMenu* XCCalendarMenu::MenuPointer(){
return this;
}
void XCCalendarMenu::ProcessMenuItemClick( wxCommandEvent& event){
// Process an action when a menu item in the XCCalendarMenu
// control is selected.
int itemID = event.GetId();
popupPtr->Dismiss();
switch (itemID){
case ID_CALENDARMENU_EDIT:
{
wxCommandEvent editCalendar(XCMAIN_EDITCALENDAR);
editCalendar.SetId(ID_EDITCALENDAR);
editCalendar.SetInt(calendarID);
wxPostEvent(windowPtr->GetParent()->GetParent()->GetParent()->GetParent(), editCalendar);
}
break;
case ID_CALENDARMENU_DELETE:
{
CalendarProperties *calendarInfo = new CalendarProperties;
calendarInfo->calendarID = calendarID;
calendarInfo->accountPreferencesID = accountPreferencesID;
wxCommandEvent deleteCalendar(XCMAIN_DELETECALENDAR);
deleteCalendar.SetId(ID_DELETECALENDAR);
deleteCalendar.SetClientData(calendarInfo);
wxPostEvent(windowPtr->GetParent()->GetParent()->GetParent()->GetParent(), deleteCalendar);
}
break;
}
}
void XCCalendarMenu::SetCalendarID(int calendarID){
this->calendarID = calendarID;
}
void XCCalendarMenu::SetAccountPreferencesID(int accountPreferencesID){
this->accountPreferencesID = accountPreferencesID;
}
void XCCalendarMenu::SetWindowPointer(wxWindow *windowPointer){
windowPtr = windowPointer;
}
void XCCalendarMenu::SetPopupPointer(wxPopupTransientWindow *popupPointer){
popupPtr = popupPointer;
}