From: Steve Brokenshire Date: Wed, 11 Jan 2017 18:18:58 +0000 (+0000) Subject: XCEventMenu: Added menu when right clicking events. X-Git-Tag: release-0.02~38 X-Git-Url: http://Server1/repobrowser/?p=xestiacalendar%2F.git;a=commitdiff_plain;h=d695a662d768eb20351008eb6ff359c7ff3d33a7 XCEventMenu: Added menu when right clicking events. --- diff --git a/source/widgets/XCEventMenu.cpp b/source/widgets/XCEventMenu.cpp new file mode 100644 index 0000000..c526987 --- /dev/null +++ b/source/widgets/XCEventMenu.cpp @@ -0,0 +1,128 @@ +// 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; + +} \ No newline at end of file diff --git a/source/widgets/XCEventMenu.h b/source/widgets/XCEventMenu.h new file mode 100644 index 0000000..b4411af --- /dev/null +++ b/source/widgets/XCEventMenu.h @@ -0,0 +1,71 @@ +// XCEventMenu.cpp - XCEventMenu widget header +// +// (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 + +#ifndef __WIDGETS_XCEVENTMENU__ +#define __WIDGETS_XCEVENTMENU__ + +#include +#include +#include +#include +#include +#include + +#include "structs.h" +#include "events.h" + +class XCEventMenuADT : public wxMenu +{ + + private: + + protected: + virtual void ProcessMenuItemClick(wxCommandEvent& event) {event.Skip();}; + public: + XCEventMenuADT(){}; + ~XCEventMenuADT(){}; + +}; + +class XCEventMenu : public XCEventMenuADT +{ + private: + std::map MenuItems = {}; + wxWindow *WindowPtr = NULL; + bool EnableAccountSettings = FALSE; + bool SearchModeOnly = FALSE; + void AppendMenuItem(wxString ObjectName, + wxString MenuName, + wxString MenuDescription, + XCEventMenuID ItemID, + wxItemKind ItemType); + int calendarID = 0; + int eventID = 0; + protected: + void ProcessMenuItemClick(wxCommandEvent& event); + public: + XCEventMenu(); + ~XCEventMenu(); + wxMenu* MenuPointer(); + void SetCalendarID(int calendarID); + void SetEventID(int eventID); + void SetWindowPointer(wxWindow *windowPointer); + +}; + +#endif \ No newline at end of file