Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Fixed right click menu which showed active menu items when it shouldn't in Search...
[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         MenuType = MenuTypeIn;
36         // Setup the menu items.
37         
38         AppendMenuItem(wxT("opencontact"), _("Open Contact..."), _(""), ID_CONTACTMENU_OPEN, wxITEM_NORMAL);
39         AppendMenuItem(wxT("sep1"), _(""), _(""), wxID_ANY, wxITEM_SEPARATOR);
40         
41         if (MenuType == XABCONTACTMENU_MAIN){
42         
43                 // Setup up the add contact option if in the main window.
45                 AppendMenuItem(wxT("newcontact"), _("New Contact..."), _(""), ID_CONTACTMENU_NEW, wxITEM_NORMAL);
46         
47         }
48         
49         AppendMenuItem(wxT("editcontact"), _("Edit Contact..."), _(""), ID_CONTACTMENU_EDIT, wxITEM_NORMAL);
51         if (MenuType == XABCONTACTMENU_SEARCH){
52         
53                 // Setup up the reveal contact option if in the search window.
54         
55                 AppendMenuItem(wxT("revealcontact"), _("Reveal Contact..."), _(""), ID_CONTACTMENU_REVEAL, wxITEM_NORMAL);
56         
57         }
58         
59         if (MenuType == XABCONTACTMENU_MAIN){
60         
61                 // Setup the delete and refresh contact options if in the main window.
62         
63                 AppendMenuItem(wxT("deletecontact"), _("Delete Contact..."), _(""), ID_CONTACTMENU_DELETE, wxITEM_NORMAL);
64                 AppendMenuItem(wxT("sep2"), _(""), _(""), wxID_ANY, wxITEM_SEPARATOR);
65                 AppendMenuItem(wxT("refreshab"), _("Refresh Address Book"), _(""), ID_CONTACTMENU_REFRESHAB, wxITEM_NORMAL);
66         
67         }
69 }
71 XABContactMenu::~XABContactMenu(){
73         // Delete the menu items.
74         
75         for (std::map<std::string, wxMenuItem*>::iterator MenuItemIter = MenuItems.begin(); 
76                 MenuItemIter != MenuItems.end(); ++MenuItemIter){
77         
78                 // Delete the wxMenuItem object.
79                 
80                 this->Disconnect(MenuItemIter->second->GetId(), wxEVT_COMMAND_MENU_SELECTED, 
81                         wxCommandEventHandler(XABContactMenu::ProcessMenuItemClick) );
82                 delete(MenuItemIter->second);
83                 MenuItemIter->second = NULL;
84         
85         }
86         
87         MenuItems.clear();
88         
89 }
91 void XABContactMenu::AppendMenuItem(wxString ObjectName, 
92         wxString MenuName, 
93         wxString MenuDescription,
94         int ItemID,
95         wxItemKind ItemType){
96         
97         wxMenuItem *menuitem = new wxMenuItem(
98                 NULL,
99                 ItemID,
100                 MenuName,
101                 MenuDescription,
102                 ItemType,
103                 NULL
104         );
105         
106         this->Connect(menuitem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(XABContactMenu::ProcessMenuItemClick));
107         this->Append(menuitem);
108         MenuItems.insert(std::make_pair(ObjectName.ToStdString(), menuitem));
112 void XABContactMenu::SetupPointersSearch(wxWindow* WindowPtrIn,
113         wxListCtrl* ContactListCtrlIn,
114         bool SearchModeOnlyIn){
116         WindowPtr = WindowPtrIn;
117         ContactListCtrl = ContactListCtrlIn;
118         SearchModeOnly = SearchModeOnlyIn;
122 void XABContactMenu::SetupPointers(wxWindow* WindowPtrIn,
123         wxListCtrl* ContactListCtrlIn, 
124         bool EnableAccountSettingsIn){
126         WindowPtr = WindowPtrIn;
127         ContactListCtrl = ContactListCtrlIn;
128         EnableAccountSettings = EnableAccountSettingsIn;
132 wxMenu* XABContactMenu::MenuPointer(){
134         // Check for the following before passing the pointer:
135         // If an account has been selected.
136         // - Disable Refresh Address Book if not.
137         // If one or more contacts have been selected.
138         // - Disable New, Edit, Delete and Reveal contact as needed.
140         bool ContactSelected = FALSE;
141         long ItemIndex = -1;
142         int ContactCount = 0;
143         
144         for (;;){
145         
146                 ItemIndex = ContactListCtrl->GetNextItem(ItemIndex,
147                                                wxLIST_NEXT_ALL,
148                                                wxLIST_STATE_SELECTED);
149         
150                 if (ItemIndex == -1){
151             
152                     break;
153             
154                 }
155         
156                 ContactSelected = TRUE;
157                 break;
158         
159         }
161         if (MenuType == XABCONTACTMENU_MAIN){
162         
163                 std::map<std::string, wxMenuItem*>::iterator MenuItemIter = MenuItems.find("refreshab");
164                 
165                 if (EnableAccountSettings == FALSE){
166                         MenuItemIter->second->Enable(FALSE);
167                         MenuItemIter = MenuItems.find("newcontact");
168                         MenuItemIter->second->Enable(FALSE);
169                 }
170                 
171                 MenuItemIter = MenuItems.find("opencontact");
172                 MenuItemIter->second->Enable(ContactSelected);
173                 MenuItemIter = MenuItems.find("editcontact");
174                 MenuItemIter->second->Enable(ContactSelected);
175                 MenuItemIter = MenuItems.find("deletecontact");
176                 MenuItemIter->second->Enable(ContactSelected);
177         
178         } else if (MenuType == XABCONTACTMENU_SEARCH){
179         
180                 std::map<std::string, wxMenuItem*>::iterator MenuItemIter = MenuItems.find("opencontact");
181                 MenuItemIter->second->Enable(ContactSelected);
182                 
183                 if (SearchModeOnly == TRUE){
185                         MenuItemIter = MenuItems.find("editcontact");
186                         MenuItemIter->second->Enable(FALSE);
187                         MenuItemIter = MenuItems.find("revealcontact");
188                         MenuItemIter->second->Enable(FALSE);
189                 
190                 } else {
191                 
192                         MenuItemIter = MenuItems.find("editcontact");
193                         MenuItemIter->second->Enable(ContactSelected);
194                         MenuItemIter = MenuItems.find("revealcontact");
195                         MenuItemIter->second->Enable(ContactSelected);
196         
197                 }
198         
199         }
201         return this;
205 void XABContactMenu::ProcessMenuItemClick( wxCommandEvent& event){
207         int ItemID = event.GetId();
208         
209         if (MenuType == XABCONTACTMENU_MAIN){
210         
211                 switch (ItemID){
212                 
213                         case ID_CONTACTMENU_OPEN:
214                                 {
215                                         wxCommandEvent rcevent(CE_OPENCONTACTLIST);
216                                         wxPostEvent(WindowPtr, rcevent);
217                                 }
218                                 break;
219                         case ID_CONTACTMENU_NEW:
220                                 {
221                                         wxCommandEvent rcevent(CE_NEWCONTACT);
222                                         wxPostEvent(WindowPtr, rcevent);
223                                 }
224                                 break;
225                         case ID_CONTACTMENU_EDIT:
226                                 {
227                                         wxCommandEvent rcevent(CE_EDITCONTACT);
228                                         wxPostEvent(WindowPtr, rcevent);
229                                 }
230                                 break;
231                         case ID_CONTACTMENU_DELETE:
232                                 {
233                                         wxCommandEvent rcevent(CE_DELETECONTACT);
234                                         wxPostEvent(WindowPtr, rcevent);
235                                 }
236                                 break;
237                         case ID_CONTACTMENU_REFRESHAB:
238                                 {
239                                         wxCommandEvent rcevent(REFRESHADDRESSBOOK);
240                                         wxPostEvent(WindowPtr, rcevent);
241                                 }
242                                 break;
243                                 
244                 }
245                 
246         } else if (MenuType == XABCONTACTMENU_SEARCH){
247         
248                 switch (ItemID){
249                 
250                         case ID_CONTACTMENU_OPEN:
251                                 {
252                                         wxCommandEvent rcevent(SE_OPENCONTACT);
253                                         wxPostEvent(WindowPtr, rcevent);
254                                 }
255                                 break;
256                         case ID_CONTACTMENU_EDIT:
257                                 {
258                                         wxCommandEvent rcevent(SE_EDITCONTACT);
259                                         wxPostEvent(WindowPtr, rcevent);
260                                 }
261                                 break;
262                         case ID_CONTACTMENU_REVEAL:
263                                 {
264                                         wxCommandEvent rcevent(SE_REVEALCONTACT);
265                                         wxPostEvent(WindowPtr, rcevent);
266                                 }
267                                 break;
268                                 
269                 }
270         
271         }
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