From 5d37f902b48963b3d578773d5baea7dc0b7cd175 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Wed, 11 Jan 2017 18:19:12 +0000 Subject: [PATCH] XCCalendarMenu: Added menu when right clicking calendars --- source/widgets/XCCalendarMenu.cpp | 136 ++++++++++++++++++++++++++++++ source/widgets/XCCalendarMenu.h | 74 ++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 source/widgets/XCCalendarMenu.cpp create mode 100644 source/widgets/XCCalendarMenu.h diff --git a/source/widgets/XCCalendarMenu.cpp b/source/widgets/XCCalendarMenu.cpp new file mode 100644 index 0000000..7c2ec51 --- /dev/null +++ b/source/widgets/XCCalendarMenu.cpp @@ -0,0 +1,136 @@ +// 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; + +} \ No newline at end of file diff --git a/source/widgets/XCCalendarMenu.h b/source/widgets/XCCalendarMenu.h new file mode 100644 index 0000000..9a5bb2c --- /dev/null +++ b/source/widgets/XCCalendarMenu.h @@ -0,0 +1,74 @@ +// XCCalendarMenu.cpp - XCCalendarMenu 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_XCCALENDARMENU__ +#define __WIDGETS_XCCALENDARMENU__ + +#include +#include +#include +#include +#include +#include + +#include "structs.h" +#include "events.h" + +class XCCalendarMenuADT : public wxMenu +{ + + private: + + protected: + virtual void ProcessMenuItemClick(wxCommandEvent& event) {event.Skip();}; + public: + XCCalendarMenuADT(){}; + ~XCCalendarMenuADT(){}; + +}; + +class XCCalendarMenu : public XCCalendarMenuADT +{ + private: + std::map MenuItems = {}; + wxListCtrl *ContactListCtrl = NULL; + wxWindow *WindowPtr = NULL; + wxPopupTransientWindow *PopupPtr = NULL; + bool EnableAccountSettings = FALSE; + bool SearchModeOnly = FALSE; + void AppendMenuItem(wxString ObjectName, + wxString MenuName, + wxString MenuDescription, + XCCalendarMenuID ItemID, + wxItemKind ItemType); + int calendarID = 0; + int accountPreferencesID = 0; + protected: + void ProcessMenuItemClick(wxCommandEvent& event); + public: + XCCalendarMenu(); + ~XCCalendarMenu(); + wxMenu* MenuPointer(); + void SetCalendarID(int calendarID); + void SetAccountPreferencesID(int accountPreferencesID); + void SetWindowPointer(wxWindow *windowPointer); + void SetPopupPointer(wxPopupTransientWindow *popupPointer); + +}; + +#endif \ No newline at end of file -- 2.39.5