Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Updated header location and moved parts of frmSearch into 4 smaller C++ files.
[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::SetupPointers(wxWindow* WindowPtrIn,
113         wxListCtrl* ContactListCtrlIn){
115         WindowPtr = WindowPtrIn;
116         ContactListCtrl = ContactListCtrlIn;
120 void XABContactMenu::SetupPointers(wxWindow* WindowPtrIn,
121         wxListCtrl* ContactListCtrlIn, 
122         bool EnableAccountSettingsIn){
124         WindowPtr = WindowPtrIn;
125         ContactListCtrl = ContactListCtrlIn;
126         EnableAccountSettings = EnableAccountSettingsIn;
130 wxMenu* XABContactMenu::MenuPointer(){
132         // Check for the following before passing the pointer:
133         // If an account has been selected.
134         // - Disable Refresh Address Book if not.
135         // If one or more contacts have been selected.
136         // - Disable New, Edit, Delete and Reveal contact as needed.
138         bool ContactSelected = FALSE;
139         long ItemIndex = -1;
140         int ContactCount = 0;
141         
142         for (;;){
143         
144                 ItemIndex = ContactListCtrl->GetNextItem(ItemIndex,
145                                                wxLIST_NEXT_ALL,
146                                                wxLIST_STATE_SELECTED);
147         
148                 if (ItemIndex == -1){
149             
150                     break;
151             
152                 }
153         
154                 ContactSelected = TRUE;
155                 break;
156         
157         }
159         if (MenuType == XABCONTACTMENU_MAIN){
160         
161                 std::map<std::string, wxMenuItem*>::iterator MenuItemIter = MenuItems.find("refreshab");
162                 
163                 if (EnableAccountSettings == FALSE){
164                         MenuItemIter->second->Enable(FALSE);
165                         MenuItemIter = MenuItems.find("newcontact");
166                         MenuItemIter->second->Enable(FALSE);
167                 }
168                 
169                 MenuItemIter = MenuItems.find("opencontact");
170                 MenuItemIter->second->Enable(ContactSelected);
171                 MenuItemIter = MenuItems.find("editcontact");
172                 MenuItemIter->second->Enable(ContactSelected);
173                 MenuItemIter = MenuItems.find("deletecontact");
174                 MenuItemIter->second->Enable(ContactSelected);
175         
176         } else if (MenuType == XABCONTACTMENU_SEARCH){
177         
178                 std::map<std::string, wxMenuItem*>::iterator MenuItemIter = MenuItems.find("opencontact");
179                 MenuItemIter->second->Enable(ContactSelected);
180                 MenuItemIter = MenuItems.find("editcontact");
181                 MenuItemIter->second->Enable(ContactSelected);
182                 MenuItemIter = MenuItems.find("revealcontact");
183                 MenuItemIter->second->Enable(ContactSelected);
184         
185         }
187         return this;
191 void XABContactMenu::ProcessMenuItemClick( wxCommandEvent& event){
193         int ItemID = event.GetId();
194         
195         if (MenuType == XABCONTACTMENU_MAIN){
196         
197                 switch (ItemID){
198                 
199                         case ID_CONTACTMENU_OPEN:
200                                 {
201                                         wxCommandEvent rcevent(CE_OPENCONTACTLIST);
202                                         wxPostEvent(WindowPtr, rcevent);
203                                 }
204                                 break;
205                         case ID_CONTACTMENU_NEW:
206                                 {
207                                         wxCommandEvent rcevent(CE_NEWCONTACT);
208                                         wxPostEvent(WindowPtr, rcevent);
209                                 }
210                                 break;
211                         case ID_CONTACTMENU_EDIT:
212                                 {
213                                         wxCommandEvent rcevent(CE_EDITCONTACT);
214                                         wxPostEvent(WindowPtr, rcevent);
215                                 }
216                                 break;
217                         case ID_CONTACTMENU_DELETE:
218                                 {
219                                         wxCommandEvent rcevent(CE_DELETECONTACT);
220                                         wxPostEvent(WindowPtr, rcevent);
221                                 }
222                                 break;
223                         case ID_CONTACTMENU_REFRESHAB:
224                                 {
225                                         wxCommandEvent rcevent(REFRESHADDRESSBOOK);
226                                         wxPostEvent(WindowPtr, rcevent);
227                                 }
228                                 break;
229                                 
230                 }
231                 
232         } else if (MenuType == XABCONTACTMENU_SEARCH){
233         
234                 switch (ItemID){
235                 
236                         case ID_CONTACTMENU_OPEN:
237                                 {
238                                         wxCommandEvent rcevent(SE_OPENCONTACT);
239                                         wxPostEvent(WindowPtr, rcevent);
240                                 }
241                                 break;
242                         case ID_CONTACTMENU_EDIT:
243                                 {
244                                         wxCommandEvent rcevent(SE_EDITCONTACT);
245                                         wxPostEvent(WindowPtr, rcevent);
246                                 }
247                                 break;
248                         case ID_CONTACTMENU_REVEAL:
249                                 {
250                                         wxCommandEvent rcevent(SE_REVEALCONTACT);
251                                         wxPostEvent(WindowPtr, rcevent);
252                                 }
253                                 break;
254                                 
255                 }
256         
257         }
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