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 )
24 // Add a window to the window list.
26 WindowData *receivedWindowData = (WindowData*)event.GetClientData();
30 wxMenuItem *mnuNewItem = new wxMenuItem(NULL, receivedWindowData->WindowID, wxT("Event Window #") + wxString::Format(wxT("%i"), receivedWindowData->WindowID), wxEmptyString, wxITEM_NORMAL, NULL);
31 mnuNewItem->SetId(receivedWindowData->WindowID);
32 mnuWindow->Append(mnuNewItem);
33 this->Connect(mnuNewItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(frmMain::ShowEventWindow));
35 frmEventEditor *frmEventEditorPtr = static_cast<frmEventEditor*>(receivedWindowData->WindowPointer);
36 wxString windowTitle = frmEventEditorPtr->GetTitle();
37 mnuNewItem->SetItemLabel(windowTitle);
39 windowListPointersMenu.insert(std::make_pair(receivedWindowData->WindowID, mnuNewItem));
40 windowListPointers.insert(std::make_pair(receivedWindowData->WindowID, receivedWindowData->WindowPointer));
41 windowListType.insert(std::make_pair(receivedWindowData->WindowID, 0));
43 delete receivedWindowData;
44 receivedWindowData = NULL;
48 void frmMain::WindowUpdate( wxCommandEvent &event )
51 // Add a window to the window list.
53 WindowData *receivedWindowData = (WindowData*)event.GetClientData();
57 frmEventEditor *frmEventEditorPtr = static_cast<frmEventEditor*>(receivedWindowData->WindowPointer);
59 wxString windowTitle = frmEventEditorPtr->GetTitle();
61 std::map<int, wxMenuItem*>::iterator MenuIter = windowListPointersMenu.find(receivedWindowData->WindowID);
63 MenuIter->second->SetItemLabel(windowTitle);
65 delete receivedWindowData;
66 receivedWindowData = NULL;
70 void frmMain::WindowDelete( wxCommandEvent &event )
73 // Delete the window from the window list.
75 WindowData *receivedWindowData = (WindowData*)event.GetClientData();
79 std::map<int, wxMenuItem*>::iterator menuIter = windowListPointersMenu.find(receivedWindowData->WindowID);
81 mnuWindow->Destroy(menuIter->second);
83 windowListPointersMenu.erase(receivedWindowData->WindowID);
84 windowListPointers.erase(receivedWindowData->WindowID);
85 windowListType.erase(receivedWindowData->WindowID);
87 delete receivedWindowData;
88 receivedWindowData = NULL;
92 void frmMain::ShowEventWindow( wxCommandEvent &event )
95 // Show a contact window from the window list.
97 std::map<int, void*>::iterator WindowIter = windowListPointers.find(event.GetId());
99 frmEventEditor *frmEventEditorPtr = static_cast<frmEventEditor*>(WindowIter->second);
101 frmEventEditorPtr->Show();
102 frmEventEditorPtr->Raise();
106 bool frmMain::CloseAllWindows()
108 // Attempt to close all windows.
110 if (windowListPointersMenu.size() == 0)
115 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)
117 for(std::map<int, void*>::iterator windowIter = windowListPointers.begin();
118 windowIter != windowListPointers.end(); windowIter++)
120 wxWindow *windowPointer = static_cast<wxWindow*>(windowIter->second);
121 windowPointer->Close();