Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
widgets: Cleanup objects in destructors and minor code cleanup
[xestiacalendar/.git] / source / widgets / XCCalendarMenu.cpp
1 // XCCalendarMenu.cpp - XCCalendarMenu widget
2 //
3 // (c) 2012-2017 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar. Original code from Xestia Address Book.
6 //
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.
10 //
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.
15 //
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(){
22         
23         // Setup the menu items.
24         
25         AppendMenuItem(wxT("opencontact"), _("Edit Calendar"), wxT(""), ID_CALENDARMENU_EDIT, wxITEM_NORMAL);
26         AppendMenuItem(wxT("deletecontact"), _("Delete Calendar"), wxT(""), ID_CALENDARMENU_DELETE, wxITEM_NORMAL);
28 }
30 XCCalendarMenu::~XCCalendarMenu(){
32         // Destory the XCCalendarMenu object.
33         
34         // Delete the list of items in menuItems (not the menu items themselves).
35         
36         menuItems.clear();
37         
38         // Menu items are deleted through ~wxMenuBase()
39         
40 }
42 void XCCalendarMenu::AppendMenuItem(wxString objectName, 
43         wxString menuName, 
44         wxString menuDescription,
45         XCCalendarMenuID itemID,
46         wxItemKind itemType){
47         
48         if (itemType == wxITEM_SEPARATOR){
49                 this->AppendSeparator();
50                 return;
51         }
52         
53         // Append a menu item to the XCCalendarMenu control.
55         wxMenuItem *menuitem = this->Append(itemID, menuName, menuDescription);
56         this->Connect(menuitem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(XCCalendarMenu::ProcessMenuItemClick));
57         menuItems.insert(std::make_pair(objectName.ToStdString(), menuitem));
59 }
61 wxMenu* XCCalendarMenu::MenuPointer(){
63         return this;
65 }
67 void XCCalendarMenu::ProcessMenuItemClick( wxCommandEvent& event){
69         // Process an action when a menu item in the XCCalendarMenu
70         // control is selected.
71         
72         int itemID = event.GetId();
73         
74         popupPtr->Dismiss();
75         
76         switch (itemID){
77                 
78                 case ID_CALENDARMENU_EDIT:
79                         {
80                                 wxCommandEvent editCalendar(XCMAIN_EDITCALENDAR);
81                                 editCalendar.SetId(ID_EDITCALENDAR);
82                                 editCalendar.SetInt(calendarID);
83                                 wxPostEvent(windowPtr->GetParent()->GetParent()->GetParent()->GetParent(), editCalendar);
84                         }
85                         break;
86                 case ID_CALENDARMENU_DELETE:
87                         {
88                                 CalendarProperties *calendarInfo = new CalendarProperties;
90                                 calendarInfo->calendarID = calendarID;
91                                 calendarInfo->accountPreferencesID = accountPreferencesID;
92                                 
93                                 wxCommandEvent deleteCalendar(XCMAIN_DELETECALENDAR);
94                                 deleteCalendar.SetId(ID_DELETECALENDAR);
95                                 deleteCalendar.SetClientData(calendarInfo);
96                                 wxPostEvent(windowPtr->GetParent()->GetParent()->GetParent()->GetParent(), deleteCalendar);
97                         }
98                         break;
99                         
100         }
104 void XCCalendarMenu::SetCalendarID(int calendarID){
105         
106         this->calendarID = calendarID;
107         
110 void XCCalendarMenu::SetAccountPreferencesID(int accountPreferencesID){
111         
112         this->accountPreferencesID = accountPreferencesID;
113         
116 void XCCalendarMenu::SetWindowPointer(wxWindow *windowPointer){
117         
118         windowPtr = windowPointer;
119         
122 void XCCalendarMenu::SetPopupPointer(wxPopupTransientWindow *popupPointer){
123         
124         popupPtr = popupPointer;
125         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy