1 // frmMain-Window.h - frmMain form window functions.
3 // (c) 2017 Xestia Software Development.
5 // This file is part of Xestia Calendar.
7 // Xestia Calendar 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 Calendar 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 Calendar. If not, see <http://www.gnu.org/licenses/>
21 void frmMain::WindowAdd( wxCommandEvent &event ){
23 // Add a window to the window list.
25 WindowData *receivedWindowData = (WindowData*)event.GetClientData();
29 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, receivedWindowData->WindowID, wxT("Event Window #") + wxString::Format(wxT("%i"), receivedWindowData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
30 mnuNewItem->SetId(receivedWindowData->WindowID);
31 mnuWindow->Append(mnuNewItem);
32 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowEventWindow));
34 frmEventEditor *frmEventEditorPtr = static_cast<frmEventEditor*>(receivedWindowData->WindowPointer);
35 wxString windowTitle = frmEventEditorPtr->GetTitle();
36 mnuNewItem->SetItemLabel(windowTitle);
38 WindowListPointersMenu.insert(std::make_pair(receivedWindowData->WindowID, mnuNewItem));
39 WindowListPointers.insert(std::make_pair(receivedWindowData->WindowID, receivedWindowData->WindowPointer));
40 WindowListType.insert(std::make_pair(receivedWindowData->WindowID, 0));
42 delete receivedWindowData;
43 receivedWindowData = NULL;
47 void frmMain::WindowUpdate( wxCommandEvent &event ){
49 // Add a window to the window list.
51 WindowData *receivedWindowData = (WindowData*)event.GetClientData();
55 frmEventEditor *frmEventEditorPtr = static_cast<frmEventEditor*>(receivedWindowData->WindowPointer);
57 wxString windowTitle = frmEventEditorPtr->GetTitle();
59 std::map<int, wxMenuItem*>::iterator MenuIter = WindowListPointersMenu.find(receivedWindowData->WindowID);
61 MenuIter->second->SetItemLabel(windowTitle);
63 delete receivedWindowData;
64 receivedWindowData = NULL;
68 void frmMain::WindowDelete( wxCommandEvent &event ){
70 // Delete the window from the window list.
72 WindowData *receivedWindowData = (WindowData*)event.GetClientData();
76 std::map<int, wxMenuItem*>::iterator menuIter = WindowListPointersMenu.find(receivedWindowData->WindowID);
78 mnuWindow->Destroy(menuIter->second);
80 WindowListPointersMenu.erase(receivedWindowData->WindowID);
81 WindowListPointers.erase(receivedWindowData->WindowID);
82 WindowListType.erase(receivedWindowData->WindowID);
84 delete receivedWindowData;
85 receivedWindowData = NULL;
89 void frmMain::ShowEventWindow( wxCommandEvent &event ){
91 // Show a contact window from the window list.
93 std::map<int, void*>::iterator WindowIter = WindowListPointers.find(event.GetId());
95 frmEventEditor *frmEventEditorPtr = static_cast<frmEventEditor*>(WindowIter->second);
97 frmEventEditorPtr->Show();
98 frmEventEditorPtr->Raise();
102 bool frmMain::CloseAllWindows()
104 // Attempt to close all windows.
106 if (WindowListPointersMenu.size() == 0)
111 if (wxMessageBox(_("Before preforming the action, all windows that are open will need to close. Do you wish to continue?"), _("Close All Windowss"), wxYES_NO) == wxYES)
113 for(std::map<int, void*>::iterator windowIter = WindowListPointers.begin();
114 windowIter != WindowListPointers.end(); windowIter++)
116 wxWindow *windowPointer = static_cast<wxWindow*>(windowIter->second);
117 windowPointer->Close();