Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added comments to describe functions in widgets/XABContactMenu.cpp
[xestiaab/.git] / source / widgets / XABContactMenu.cpp
1 // XABContactMenu.cpp - XABContactMenu widget
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book 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 Address Book 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 Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "XABContactMenu.h"
20 #include "../frmMain.h"
21 #include "../search/frmSearch.h"
23 enum {
24         ID_CONTACTMENU_OPEN,
25         ID_CONTACTMENU_NEW,
26         ID_CONTACTMENU_EDIT,
27         ID_CONTACTMENU_DELETE,
28         ID_CONTACTMENU_REFRESHAB,
29         ID_CONTACTMENU_REVEAL
30 };
32 XABContactMenu::XABContactMenu(int MenuTypeIn){
34         // Setup the XABContactMenu control.
35         
36         MenuType = MenuTypeIn;
38         // Setup the menu items.
39         
40         AppendMenuItem(wxT("opencontact"), _("Open Contact..."), _(""), ID_CONTACTMENU_OPEN, wxITEM_NORMAL);
41         AppendMenuItem(wxT("sep1"), _(""), _(""), wxID_ANY, wxITEM_SEPARATOR);
42         
43         if (MenuType == XABCONTACTMENU_MAIN){
44         
45                 // Setup up the add contact option if in the main window.
47                 AppendMenuItem(wxT("newcontact"), _("New Contact..."), _(""), ID_CONTACTMENU_NEW, wxITEM_NORMAL);
48         
49         }
50         
51         AppendMenuItem(wxT("editcontact"), _("Edit Contact..."), _(""), ID_CONTACTMENU_EDIT, wxITEM_NORMAL);
53         if (MenuType == XABCONTACTMENU_SEARCH){
54         
55                 // Setup up the reveal contact option if in the search window.
56         
57                 AppendMenuItem(wxT("revealcontact"), _("Reveal Contact..."), _(""), ID_CONTACTMENU_REVEAL, wxITEM_NORMAL);
58         
59         }
60         
61         if (MenuType == XABCONTACTMENU_MAIN){
62         
63                 // Setup the delete and refresh contact options if in the main window.
64         
65                 AppendMenuItem(wxT("deletecontact"), _("Delete Contact..."), _(""), ID_CONTACTMENU_DELETE, wxITEM_NORMAL);
66                 AppendMenuItem(wxT("sep2"), _(""), _(""), wxID_ANY, wxITEM_SEPARATOR);
67                 AppendMenuItem(wxT("refreshab"), _("Refresh Address Book"), _(""), ID_CONTACTMENU_REFRESHAB, wxITEM_NORMAL);
68         
69         }
71 }
73 XABContactMenu::~XABContactMenu(){
75         // Destory the XABContactMenu object.
76         
77         // Delete the menu items.
78         
79         for (std::map<std::string, wxMenuItem*>::iterator MenuItemIter = MenuItems.begin(); 
80                 MenuItemIter != MenuItems.end(); ++MenuItemIter){
81         
82                 // Delete the wxMenuItem object.
83                 
84                 this->Disconnect(MenuItemIter->second->GetId(), wxEVT_COMMAND_MENU_SELECTED, 
85                         wxCommandEventHandler(XABContactMenu::ProcessMenuItemClick) );
86                 delete(MenuItemIter->second);
87                 MenuItemIter->second = NULL;
88         
89         }
90         
91         MenuItems.clear();
92         
93 }
95 void XABContactMenu::AppendMenuItem(wxString ObjectName, 
96         wxString MenuName, 
97         wxString MenuDescription,
98         int ItemID,
99         wxItemKind ItemType){
100         
101         // Append a menu item to the XABContactMenu control.
102                 
103         wxMenuItem *menuitem = new wxMenuItem(
104                 NULL,
105                 ItemID,
106                 MenuName,
107                 MenuDescription,
108                 ItemType,
109                 NULL
110         );
111         
112         this->Connect(menuitem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(XABContactMenu::ProcessMenuItemClick));
113         this->Append(menuitem);
114         MenuItems.insert(std::make_pair(ObjectName.ToStdString(), menuitem));
118 void XABContactMenu::SetupPointersSearch(wxWindow* WindowPtrIn,
119         wxListCtrl* ContactListCtrlIn,
120         bool SearchModeOnlyIn){
122         // Setup the pointers when being used in the search window.
123                 
124         WindowPtr = WindowPtrIn;
125         ContactListCtrl = ContactListCtrlIn;
126         SearchModeOnly = SearchModeOnlyIn;
130 void XABContactMenu::SetupPointers(wxWindow* WindowPtrIn,
131         wxListCtrl* ContactListCtrlIn, 
132         bool EnableAccountSettingsIn){
134         // Setup the pointers.
135                 
136         WindowPtr = WindowPtrIn;
137         ContactListCtrl = ContactListCtrlIn;
138         EnableAccountSettings = EnableAccountSettingsIn;
142 wxMenu* XABContactMenu::MenuPointer(){
144         // Process the menu pointer.
145         
146         // Check for the following before passing the pointer:
147         // If an account has been selected.
148         // - Disable Refresh Address Book if not.
149         // If one or more contacts have been selected.
150         // - Disable New, Edit, Delete and Reveal contact as needed.
152         bool ContactSelected = FALSE;
153         long ItemIndex = -1;
154         int ContactCount = 0;
155         
156         for (;;){
157         
158                 ItemIndex = ContactListCtrl->GetNextItem(ItemIndex,
159                                                wxLIST_NEXT_ALL,
160                                                wxLIST_STATE_SELECTED);
161         
162                 if (ItemIndex == -1){
163             
164                     break;
165             
166                 }
167         
168                 ContactSelected = TRUE;
169                 break;
170         
171         }
173         if (MenuType == XABCONTACTMENU_MAIN){
174         
175                 std::map<std::string, wxMenuItem*>::iterator MenuItemIter = MenuItems.find("refreshab");
176                 
177                 if (EnableAccountSettings == FALSE){
178                         MenuItemIter->second->Enable(FALSE);
179                         MenuItemIter = MenuItems.find("newcontact");
180                         MenuItemIter->second->Enable(FALSE);
181                 }
182                 
183                 MenuItemIter = MenuItems.find("opencontact");
184                 MenuItemIter->second->Enable(ContactSelected);
185                 MenuItemIter = MenuItems.find("editcontact");
186                 MenuItemIter->second->Enable(ContactSelected);
187                 MenuItemIter = MenuItems.find("deletecontact");
188                 MenuItemIter->second->Enable(ContactSelected);
189         
190         } else if (MenuType == XABCONTACTMENU_SEARCH){
191         
192                 std::map<std::string, wxMenuItem*>::iterator MenuItemIter = MenuItems.find("opencontact");
193                 MenuItemIter->second->Enable(ContactSelected);
194                 
195                 if (SearchModeOnly == TRUE){
197                         MenuItemIter = MenuItems.find("editcontact");
198                         MenuItemIter->second->Enable(FALSE);
199                         MenuItemIter = MenuItems.find("revealcontact");
200                         MenuItemIter->second->Enable(FALSE);
201                 
202                 } else {
203                 
204                         MenuItemIter = MenuItems.find("editcontact");
205                         MenuItemIter->second->Enable(ContactSelected);
206                         MenuItemIter = MenuItems.find("revealcontact");
207                         MenuItemIter->second->Enable(ContactSelected);
208         
209                 }
210         
211         }
213         return this;
217 void XABContactMenu::ProcessMenuItemClick( wxCommandEvent& event){
219         // Process an action when a menu item in the XABContactMenu
220         // control is selected.
221         
222         int ItemID = event.GetId();
223         
224         if (MenuType == XABCONTACTMENU_MAIN){
225         
226                 switch (ItemID){
227                 
228                         case ID_CONTACTMENU_OPEN:
229                                 {
230                                         wxCommandEvent rcevent(CE_OPENCONTACTLIST);
231                                         wxPostEvent(WindowPtr, rcevent);
232                                 }
233                                 break;
234                         case ID_CONTACTMENU_NEW:
235                                 {
236                                         wxCommandEvent rcevent(CE_NEWCONTACT);
237                                         wxPostEvent(WindowPtr, rcevent);
238                                 }
239                                 break;
240                         case ID_CONTACTMENU_EDIT:
241                                 {
242                                         wxCommandEvent rcevent(CE_EDITCONTACT);
243                                         wxPostEvent(WindowPtr, rcevent);
244                                 }
245                                 break;
246                         case ID_CONTACTMENU_DELETE:
247                                 {
248                                         wxCommandEvent rcevent(CE_DELETECONTACT);
249                                         wxPostEvent(WindowPtr, rcevent);
250                                 }
251                                 break;
252                         case ID_CONTACTMENU_REFRESHAB:
253                                 {
254                                         wxCommandEvent rcevent(REFRESHADDRESSBOOK);
255                                         wxPostEvent(WindowPtr, rcevent);
256                                 }
257                                 break;
258                                 
259                 }
260                 
261         } else if (MenuType == XABCONTACTMENU_SEARCH){
262         
263                 switch (ItemID){
264                 
265                         case ID_CONTACTMENU_OPEN:
266                                 {
267                                         wxCommandEvent rcevent(SE_OPENCONTACT);
268                                         wxPostEvent(WindowPtr, rcevent);
269                                 }
270                                 break;
271                         case ID_CONTACTMENU_EDIT:
272                                 {
273                                         wxCommandEvent rcevent(SE_EDITCONTACT);
274                                         wxPostEvent(WindowPtr, rcevent);
275                                 }
276                                 break;
277                         case ID_CONTACTMENU_REVEAL:
278                                 {
279                                         wxCommandEvent rcevent(SE_REVEALCONTACT);
280                                         wxPostEvent(WindowPtr, rcevent);
281                                 }
282                                 break;
283                                 
284                 }
285         
286         }
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