Debian Codegraph @

code/apis/CmdLineManager.cpp

raw
1 /*
2 Copyright (C) 2009-2011 wxLauncher Team
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include "apis/CmdLineManager.h"
20
21 /** \class CmdLineManager
22 CmdLineManager is used to notify controls that have registered with it
23 that the command line or custom flags have changed. */
24
25 EventHandlers CmdLineManager::CmdLineChangedHandlers;
26 EventHandlers CmdLineManager::CustomFlagsChangedHandlers;
27
28 LAUNCHER_DEFINE_EVENT_TYPE(EVT_CMD_LINE_CHANGED);
29 LAUNCHER_DEFINE_EVENT_TYPE(EVT_CUSTOM_FLAGS_CHANGED);
30
31 void CmdLineManager::RegisterCmdLineChanged(wxEvtHandler *handler) {
32 wxASSERT_MSG(CmdLineChangedHandlers.IndexOf(handler) == wxNOT_FOUND,
33 wxString::Format(
34 _T("RegisterCmdLineChanged(): Handler at %p already registered."),
35 handler));
36 CmdLineChangedHandlers.Append(handler);
37 }
38 void CmdLineManager::RegisterCustomFlagsChanged(wxEvtHandler *handler) {
39 wxASSERT_MSG(CustomFlagsChangedHandlers.IndexOf(handler) == wxNOT_FOUND,
40 wxString::Format(
41 _T("RegisterCustomFlagsChanged(): Handler at %p already registered."),
42 handler));
43 CustomFlagsChangedHandlers.Append(handler);
44 }
45 void CmdLineManager::UnRegisterCmdLineChanged(wxEvtHandler *handler) {
46 wxASSERT_MSG(CmdLineChangedHandlers.IndexOf(handler) != wxNOT_FOUND,
47 wxString::Format(
48 _T("UnRegisterCmdLineChanged(): Handler at %p not registered."),
49 handler));
50 CmdLineChangedHandlers.DeleteObject(handler);
51 }
52 void CmdLineManager::UnRegisterCustomFlagsChanged(wxEvtHandler *handler) {
53 wxASSERT_MSG(CustomFlagsChangedHandlers.IndexOf(handler) != wxNOT_FOUND,
54 wxString::Format(
55 _T("UnRegisterCustomFlagsChanged(): Handler at %p not registered."),
56 handler));
57 CustomFlagsChangedHandlers.DeleteObject(handler);
58 }
59
60 void CmdLineManager::GenerateCmdLineChanged() {
61 wxCommandEvent event(EVT_CMD_LINE_CHANGED, wxID_NONE);
62 wxLogDebug(_T("Generating EVT_CMD_LINE_CHANGED event"));
63 for (EventHandlers::iterator iter = CmdLineChangedHandlers.begin(),
64 end = CmdLineChangedHandlers.end(); iter != end; ++iter) {
65 wxEvtHandler* current = *iter;
66 current->AddPendingEvent(event);
67 wxLogDebug(_T(" Sent EVT_CMD_LINE_CHANGED event to %p"), current);
68 }
69 }
70
71 void CmdLineManager::GenerateCustomFlagsChanged() {
72 wxCommandEvent event(EVT_CUSTOM_FLAGS_CHANGED, wxID_NONE);
73 wxLogDebug(_T("Generating EVT_CUSTOM_FLAGS_CHANGED event"));
74 for (EventHandlers::iterator iter = CustomFlagsChangedHandlers.begin(),
75 end = CustomFlagsChangedHandlers.end(); iter != end; ++iter) {
76 wxEvtHandler* current = *iter;
77 current->AddPendingEvent(event);
78 wxLogDebug(_T(" Sent EVT_CUSTOM_FLAGS_CHANGED event to %p"), current);
79 }
80 }