Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Documentation (en-GB).fodt: Updated documentation with new screenshots
[xestiaab/.git] / source / widgets / XABContactMenu.cpp
1 // XABContactMenu.cpp - XABContactMenu widget
2 //
3 // (c) 2012-2016 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 XABContactMenu::XABContactMenu(XABContactMenuType MenuTypeIn){
25         // Setup the XABContactMenu control.
26         
27         MenuType = MenuTypeIn;
29         // Setup the menu items.
30         
31         AppendMenuItem(wxT("opencontact"), _("Open Contact..."), wxT(""), ID_CONTACTMENU_OPEN, wxITEM_NORMAL);
32         AppendMenuItem(wxT("sep1"), wxT(""), wxT(""), ID_CONTACTMENU_SEPARATOR, wxITEM_SEPARATOR);
33         
34         if (MenuType == XABCONTACTMENU_MAIN){
35         
36                 // Setup up the add contact option if in the main window.
38                 AppendMenuItem(wxT("newcontact"), _("New Contact..."), wxT(""), ID_CONTACTMENU_NEW, wxITEM_NORMAL);
39         
40         }
41         
42         AppendMenuItem(wxT("editcontact"), _("Edit Contact..."), wxT(""), ID_CONTACTMENU_EDIT, wxITEM_NORMAL);
44         if (MenuType == XABCONTACTMENU_SEARCH){
45         
46                 // Setup up the reveal contact option if in the search window.
47         
48                 AppendMenuItem(wxT("revealcontact"), _("Reveal Contact..."), wxT(""), ID_CONTACTMENU_REVEAL, wxITEM_NORMAL);
49         
50         }
51         
52         if (MenuType == XABCONTACTMENU_MAIN){
53         
54                 // Setup the delete and refresh contact options if in the main window.
55         
56                 AppendMenuItem(wxT("deletecontact"), _("Delete Contact..."), wxT(""), ID_CONTACTMENU_DELETE, wxITEM_NORMAL);
57                 AppendMenuItem(wxT("sep2"), wxT(""), wxT(""), ID_CONTACTMENU_SEPARATOR, wxITEM_SEPARATOR);
58                 AppendMenuItem(wxT("refreshab"), _("Refresh Address Book"), wxT(""), ID_CONTACTMENU_REFRESHAB, wxITEM_NORMAL);
59         
60         }
62 }
64 XABContactMenu::~XABContactMenu(){
66         // Destory the XABContactMenu object.
67         
68         // Delete the menu items.
69         
70         for (std::map<std::string, wxMenuItem*>::iterator MenuItemIter = MenuItems.begin(); 
71                 MenuItemIter != MenuItems.end(); ++MenuItemIter){
72         
73                 // Delete the wxMenuItem object.
74                 
75                 this->Disconnect(MenuItemIter->second->GetId(), wxEVT_COMMAND_MENU_SELECTED, 
76                         wxCommandEventHandler(XABContactMenu::ProcessMenuItemClick) );
77                 delete(MenuItemIter->second);
78                 MenuItemIter->second = NULL;
79         
80         }
81         
82         MenuItems.clear();
83         
84 }
86 void XABContactMenu::AppendMenuItem(wxString ObjectName, 
87         wxString MenuName, 
88         wxString MenuDescription,
89         XABContactMenuID ItemID,
90         wxItemKind ItemType){
91         
92         if (ItemType == wxITEM_SEPARATOR){
93                 this->AppendSeparator();
94                 return;
95         }
96         
97         // Append a menu item to the XABContactMenu control.
99         wxMenuItem *menuitem = this->Append(ItemID, MenuName, MenuDescription);
100         this->Connect(menuitem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(XABContactMenu::ProcessMenuItemClick));
101         MenuItems.insert(std::make_pair(ObjectName.ToStdString(), menuitem));
105 void XABContactMenu::SetupPointersSearch(wxWindow* WindowPtrIn,
106         wxListCtrl* ContactListCtrlIn,
107         bool SearchModeOnlyIn){
109         // Setup the pointers when being used in the search window.
110                 
111         WindowPtr = WindowPtrIn;
112         ContactListCtrl = ContactListCtrlIn;
113         SearchModeOnly = SearchModeOnlyIn;
117 void XABContactMenu::SetupPointers(wxWindow* WindowPtrIn,
118         wxListCtrl* ContactListCtrlIn, 
119         bool EnableAccountSettingsIn){
121         // Setup the pointers.
122                 
123         WindowPtr = WindowPtrIn;
124         ContactListCtrl = ContactListCtrlIn;
125         EnableAccountSettings = EnableAccountSettingsIn;
129 wxMenu* XABContactMenu::MenuPointer(){
131         // Process the menu pointer.
132         
133         // Check for the following before passing the pointer:
134         // If an account has been selected.
135         // - Disable Refresh Address Book if not.
136         // If one or more contacts have been selected.
137         // - Disable New, Edit, Delete and Reveal contact as needed.
139         bool ContactSelected = FALSE;
140         long ItemIndex = -1;
141         int ContactCount = 0;
142         
143         for (;;){
144         
145                 ItemIndex = ContactListCtrl->GetNextItem(ItemIndex,
146                                                wxLIST_NEXT_ALL,
147                                                wxLIST_STATE_SELECTED);
148         
149                 if (ItemIndex == -1){
150             
151                     break;
152             
153                 }
154         
155                 ContactSelected = TRUE;
156                 break;
157         
158         }
160         if (MenuType == XABCONTACTMENU_MAIN){
161         
162                 std::map<std::string, wxMenuItem*>::iterator MenuItemIter = MenuItems.find("refreshab");
163                 
164                 if (EnableAccountSettings == FALSE){
165                         MenuItemIter->second->Enable(FALSE);
166                         MenuItemIter = MenuItems.find("newcontact");
167                         MenuItemIter->second->Enable(FALSE);
168                 }
169                 
170                 MenuItemIter = MenuItems.find("opencontact");
171                 MenuItemIter->second->Enable(ContactSelected);
172                 MenuItemIter = MenuItems.find("editcontact");
173                 MenuItemIter->second->Enable(ContactSelected);
174                 MenuItemIter = MenuItems.find("deletecontact");
175                 MenuItemIter->second->Enable(ContactSelected);
176         
177         } else if (MenuType == XABCONTACTMENU_SEARCH){
178         
179                 std::map<std::string, wxMenuItem*>::iterator MenuItemIter = MenuItems.find("opencontact");
180                 MenuItemIter->second->Enable(ContactSelected);
181                 
182                 if (SearchModeOnly == TRUE){
184                         MenuItemIter = MenuItems.find("editcontact");
185                         MenuItemIter->second->Enable(FALSE);
186                         MenuItemIter = MenuItems.find("revealcontact");
187                         MenuItemIter->second->Enable(FALSE);
188                 
189                 } else {
190                 
191                         MenuItemIter = MenuItems.find("editcontact");
192                         MenuItemIter->second->Enable(ContactSelected);
193                         MenuItemIter = MenuItems.find("revealcontact");
194                         MenuItemIter->second->Enable(ContactSelected);
195         
196                 }
197         
198         }
200         return this;
204 void XABContactMenu::ProcessMenuItemClick( wxCommandEvent& event){
206         // Process an action when a menu item in the XABContactMenu
207         // control is selected.
208         
209         int ItemID = event.GetId();
210         
211         if (MenuType == XABCONTACTMENU_MAIN){
212         
213                 switch (ItemID){
214                 
215                         case ID_CONTACTMENU_OPEN:
216                                 {
217                                         wxCommandEvent rcevent(CE_OPENCONTACTLIST);
218                                         wxPostEvent(WindowPtr, rcevent);
219                                 }
220                                 break;
221                         case ID_CONTACTMENU_NEW:
222                                 {
223                                         wxCommandEvent rcevent(CE_NEWCONTACT);
224                                         wxPostEvent(WindowPtr, rcevent);
225                                 }
226                                 break;
227                         case ID_CONTACTMENU_EDIT:
228                                 {
229                                         wxCommandEvent rcevent(CE_EDITCONTACT);
230                                         wxPostEvent(WindowPtr, rcevent);
231                                 }
232                                 break;
233                         case ID_CONTACTMENU_DELETE:
234                                 {
235                                         wxCommandEvent rcevent(CE_DELETECONTACT);
236                                         wxPostEvent(WindowPtr, rcevent);
237                                 }
238                                 break;
239                         case ID_CONTACTMENU_REFRESHAB:
240                                 {
241                                         wxCommandEvent rcevent(REFRESHADDRESSBOOK);
242                                         wxPostEvent(WindowPtr, rcevent);
243                                 }
244                                 break;
245                                 
246                 }
247                 
248         } else if (MenuType == XABCONTACTMENU_SEARCH){
249         
250                 switch (ItemID){
251                 
252                         case ID_CONTACTMENU_OPEN:
253                                 {
254                                         wxCommandEvent rcevent(SE_OPENCONTACT);
255                                         wxPostEvent(WindowPtr, rcevent);
256                                 }
257                                 break;
258                         case ID_CONTACTMENU_EDIT:
259                                 {
260                                         wxCommandEvent rcevent(SE_EDITCONTACT);
261                                         wxPostEvent(WindowPtr, rcevent);
262                                 }
263                                 break;
264                         case ID_CONTACTMENU_REVEAL:
265                                 {
266                                         wxCommandEvent rcevent(SE_REVEALCONTACT);
267                                         wxPostEvent(WindowPtr, rcevent);
268                                 }
269                                 break;
270                                 
271                 }
272         
273         }
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