/[pcsx2_0.9.7]/trunk/3rdparty/wxWidgets/src/common/evtloopcmn.cpp
ViewVC logotype

Contents of /trunk/3rdparty/wxWidgets/src/common/evtloopcmn.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (10 years, 2 months ago) by william
File size: 5577 byte(s)
committing r3113 initial commit again...
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/evtloopcmn.cpp
3 // Purpose: common wxEventLoop-related stuff
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 2006-01-12
7 // RCS-ID: $Id: evtloopcmn.cpp 45938 2007-05-10 02:07:41Z VZ $
8 // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #include "wx/evtloop.h"
28
29 #ifndef WX_PRECOMP
30 #include "wx/app.h"
31 #endif //WX_PRECOMP
32
33 // see the comment near the declaration of wxRunningEventLoopCount in
34 // src/msw/thread.cpp for the explanation of this hack
35 #if defined(__WXMSW__) && wxUSE_THREADS
36
37 extern WXDLLIMPEXP_DATA_BASE(int) wxRunningEventLoopCount;
38 struct wxRunningEventLoopCounter
39 {
40 wxRunningEventLoopCounter() { wxRunningEventLoopCount++; }
41 ~wxRunningEventLoopCounter() { wxRunningEventLoopCount--; }
42 };
43
44 #endif // __WXMSW__
45
46 // ----------------------------------------------------------------------------
47 // globals
48 // ----------------------------------------------------------------------------
49
50 wxEventLoop *wxEventLoopBase::ms_activeLoop = NULL;
51
52 // wxEventLoopManual is unused in the other ports
53 #if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXDFB__)
54
55 // ============================================================================
56 // wxEventLoopManual implementation
57 // ============================================================================
58
59 wxEventLoopManual::wxEventLoopManual()
60 {
61 m_exitcode = 0;
62 m_shouldExit = false;
63 }
64
65 int wxEventLoopManual::Run()
66 {
67 // event loops are not recursive, you need to create another loop!
68 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
69
70 // ProcessIdle() and Dispatch() below may throw so the code here should
71 // be exception-safe, hence we must use local objects for all actions we
72 // should undo
73 wxEventLoopActivator activate(wx_static_cast(wxEventLoop *, this));
74
75 #if defined(__WXMSW__) && wxUSE_THREADS
76 wxRunningEventLoopCounter evtLoopCounter;
77 #endif // __WXMSW__
78
79 // we must ensure that OnExit() is called even if an exception is thrown
80 // from inside Dispatch() but we must call it from Exit() in normal
81 // situations because it is supposed to be called synchronously,
82 // wxModalEventLoop depends on this (so we can't just use ON_BLOCK_EXIT or
83 // something similar here)
84 #if wxUSE_EXCEPTIONS
85 for ( ;; )
86 {
87 try
88 {
89 #endif // wxUSE_EXCEPTIONS
90
91 // this is the event loop itself
92 for ( ;; )
93 {
94 // give them the possibility to do whatever they want
95 OnNextIteration();
96
97 // generate and process idle events for as long as we don't
98 // have anything else to do
99 while ( !Pending() && (wxTheApp && wxTheApp->ProcessIdle()) )
100 ;
101
102 // if the "should exit" flag is set, the loop should terminate
103 // but not before processing any remaining messages so while
104 // Pending() returns true, do process them
105 if ( m_shouldExit )
106 {
107 while ( Pending() )
108 Dispatch();
109
110 break;
111 }
112
113 // a message came or no more idle processing to do, sit in
114 // Dispatch() waiting for the next message
115 if ( !Dispatch() )
116 {
117 // we got WM_QUIT
118 break;
119 }
120 }
121
122 #if wxUSE_EXCEPTIONS
123 // exit the outer loop as well
124 break;
125 }
126 catch ( ... )
127 {
128 try
129 {
130 if ( !wxTheApp || !wxTheApp->OnExceptionInMainLoop() )
131 {
132 OnExit();
133 break;
134 }
135 //else: continue running the event loop
136 }
137 catch ( ... )
138 {
139 // OnException() throwed, possibly rethrowing the same
140 // exception again: very good, but we still need OnExit() to
141 // be called
142 OnExit();
143 throw;
144 }
145 }
146 }
147 #endif // wxUSE_EXCEPTIONS
148
149 return m_exitcode;
150 }
151
152 void wxEventLoopManual::Exit(int rc)
153 {
154 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
155
156 m_exitcode = rc;
157 m_shouldExit = true;
158
159 OnExit();
160
161 // all we have to do to exit from the loop is to (maybe) wake it up so that
162 // it can notice that Exit() had been called
163 //
164 // in particular, do *not* use here calls such as PostQuitMessage() (under
165 // MSW) which terminate the current event loop here because we're not sure
166 // that it is going to be processed by the correct event loop: it would be
167 // possible that another one is started and terminated by mistake if we do
168 // this
169 WakeUp();
170 }
171
172 #endif // __WXMSW__ || __WXMAC__ || __WXDFB__

  ViewVC Help
Powered by ViewVC 1.1.22