]> git.saurik.com Git - wxWidgets.git/blob - src/common/modalhook.cpp
Move wxEventLoopManual::m_shouldExit to wxEventLoopBase.
[wxWidgets.git] / src / common / modalhook.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/modalhook.cpp
3 // Purpose: wxModalDialogHook implementation
4 // Author: Vadim Zeitlin
5 // Created: 2013-05-19
6 // RCS-ID: $Id$
7 // Copyright: (c) 2013 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #include "wx/modalhook.h"
27
28 #ifndef WX_PRECOMP
29 #endif // WX_PRECOMP
30
31 wxModalDialogHook::Hooks wxModalDialogHook::ms_hooks;
32
33 // ============================================================================
34 // wxModalDialogHook implementation
35 // ============================================================================
36
37 // ----------------------------------------------------------------------------
38 // Hooks management
39 // ----------------------------------------------------------------------------
40
41 void wxModalDialogHook::Register()
42 {
43 #if wxDEBUG_LEVEL
44 for ( Hooks::const_iterator it = ms_hooks.begin();
45 it != ms_hooks.end();
46 ++it)
47 {
48 if ( *it == this )
49 {
50 wxFAIL_MSG( wxS("Registering already registered hook?") );
51 return;
52 }
53 }
54 #endif // wxDEBUG_LEVEL
55
56 ms_hooks.insert(ms_hooks.begin(), this);
57 }
58
59 void wxModalDialogHook::Unregister()
60 {
61 if ( !DoUnregister() )
62 {
63 wxFAIL_MSG( wxS("Unregistering not registered hook?") );
64 }
65 }
66
67 bool wxModalDialogHook::DoUnregister()
68 {
69 for ( Hooks::iterator it = ms_hooks.begin();
70 it != ms_hooks.end();
71 ++it )
72 {
73 if ( *it == this )
74 {
75 ms_hooks.erase(it);
76 return true;
77 }
78 }
79
80 return false;
81 }
82
83 // ----------------------------------------------------------------------------
84 // Invoking hooks methods
85 // ----------------------------------------------------------------------------
86
87 /* static */
88 int wxModalDialogHook::CallEnter(wxDialog* dialog)
89 {
90 // Make a copy of the hooks list to avoid problems if it's modified while
91 // we're iterating over it: this is unlikely to happen in our case, but
92 // quite possible in CallExit() as the hooks may remove themselves after
93 // the call to their Exit(), so do it here for symmetry as well.
94 const Hooks hooks = ms_hooks;
95
96 for ( Hooks::const_iterator it = hooks.begin(); it != hooks.end(); ++it )
97 {
98 const int rc = (*it)->Enter(dialog);
99 if ( rc != wxID_NONE )
100 {
101 // Skip calling all the rest of the hooks if one of them preempts
102 // showing the dialog completely.
103 return rc;
104 }
105 }
106
107 return wxID_NONE;
108 }
109
110 /* static */
111 void wxModalDialogHook::CallExit(wxDialog* dialog)
112 {
113 // See comment in CallEnter() for the reasons for making a copy here.
114 const Hooks hooks = ms_hooks;
115
116 for ( Hooks::const_iterator it = hooks.begin(); it != hooks.end(); ++it )
117 {
118 (*it)->Exit(dialog);
119 }
120 }