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