1 // XABContactMenu.cpp - XABContactMenu widget
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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"
27 ID_CONTACTMENU_DELETE,
28 ID_CONTACTMENU_REFRESHAB,
32 XABContactMenu::XABContactMenu(int MenuTypeIn){
34 MenuType = MenuTypeIn;
36 // Setup the menu items.
38 AppendMenuItem(wxT("opencontact"), _("Open Contact..."), _(""), ID_CONTACTMENU_OPEN, wxITEM_NORMAL);
39 AppendMenuItem(wxT("sep1"), _(""), _(""), wxID_ANY, wxITEM_SEPARATOR);
41 if (MenuType == XABCONTACTMENU_MAIN){
43 // Setup up the add contact option if in the main window.
45 AppendMenuItem(wxT("newcontact"), _("New Contact..."), _(""), ID_CONTACTMENU_NEW, wxITEM_NORMAL);
49 AppendMenuItem(wxT("editcontact"), _("Edit Contact..."), _(""), ID_CONTACTMENU_EDIT, wxITEM_NORMAL);
51 if (MenuType == XABCONTACTMENU_SEARCH){
53 // Setup up the reveal contact option if in the search window.
55 AppendMenuItem(wxT("revealcontact"), _("Reveal Contact..."), _(""), ID_CONTACTMENU_REVEAL, wxITEM_NORMAL);
59 if (MenuType == XABCONTACTMENU_MAIN){
61 // Setup the delete and refresh contact options if in the main window.
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);
71 XABContactMenu::~XABContactMenu(){
73 // Delete the menu items.
75 for (std::map<std::string, wxMenuItem*>::iterator MenuItemIter = MenuItems.begin();
76 MenuItemIter != MenuItems.end(); ++MenuItemIter){
78 // Delete the wxMenuItem object.
80 this->Disconnect(MenuItemIter->second->GetId(), wxEVT_COMMAND_MENU_SELECTED,
81 wxCommandEventHandler(XABContactMenu::ProcessMenuItemClick) );
82 delete(MenuItemIter->second);
83 MenuItemIter->second = NULL;
91 void XABContactMenu::AppendMenuItem(wxString ObjectName,
93 wxString MenuDescription,
97 wxMenuItem *menuitem = new wxMenuItem(
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;
142 int ContactCount = 0;
146 ItemIndex = ContactListCtrl->GetNextItem(ItemIndex,
148 wxLIST_STATE_SELECTED);
150 if (ItemIndex == -1){
156 ContactSelected = TRUE;
161 if (MenuType == XABCONTACTMENU_MAIN){
163 std::map<std::string, wxMenuItem*>::iterator MenuItemIter = MenuItems.find("refreshab");
165 if (EnableAccountSettings == FALSE){
166 MenuItemIter->second->Enable(FALSE);
167 MenuItemIter = MenuItems.find("newcontact");
168 MenuItemIter->second->Enable(FALSE);
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);
178 } else if (MenuType == XABCONTACTMENU_SEARCH){
180 std::map<std::string, wxMenuItem*>::iterator MenuItemIter = MenuItems.find("opencontact");
181 MenuItemIter->second->Enable(ContactSelected);
183 if (SearchModeOnly == TRUE){
185 MenuItemIter = MenuItems.find("editcontact");
186 MenuItemIter->second->Enable(FALSE);
187 MenuItemIter = MenuItems.find("revealcontact");
188 MenuItemIter->second->Enable(FALSE);
192 MenuItemIter = MenuItems.find("editcontact");
193 MenuItemIter->second->Enable(ContactSelected);
194 MenuItemIter = MenuItems.find("revealcontact");
195 MenuItemIter->second->Enable(ContactSelected);
205 void XABContactMenu::ProcessMenuItemClick( wxCommandEvent& event){
207 int ItemID = event.GetId();
209 if (MenuType == XABCONTACTMENU_MAIN){
213 case ID_CONTACTMENU_OPEN:
215 wxCommandEvent rcevent(CE_OPENCONTACTLIST);
216 wxPostEvent(WindowPtr, rcevent);
219 case ID_CONTACTMENU_NEW:
221 wxCommandEvent rcevent(CE_NEWCONTACT);
222 wxPostEvent(WindowPtr, rcevent);
225 case ID_CONTACTMENU_EDIT:
227 wxCommandEvent rcevent(CE_EDITCONTACT);
228 wxPostEvent(WindowPtr, rcevent);
231 case ID_CONTACTMENU_DELETE:
233 wxCommandEvent rcevent(CE_DELETECONTACT);
234 wxPostEvent(WindowPtr, rcevent);
237 case ID_CONTACTMENU_REFRESHAB:
239 wxCommandEvent rcevent(REFRESHADDRESSBOOK);
240 wxPostEvent(WindowPtr, rcevent);
246 } else if (MenuType == XABCONTACTMENU_SEARCH){
250 case ID_CONTACTMENU_OPEN:
252 wxCommandEvent rcevent(SE_OPENCONTACT);
253 wxPostEvent(WindowPtr, rcevent);
256 case ID_CONTACTMENU_EDIT:
258 wxCommandEvent rcevent(SE_EDITCONTACT);
259 wxPostEvent(WindowPtr, rcevent);
262 case ID_CONTACTMENU_REVEAL:
264 wxCommandEvent rcevent(SE_REVEALCONTACT);
265 wxPostEvent(WindowPtr, rcevent);