]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/evtloop.cpp
another fix
[wxWidgets.git] / src / gtk1 / evtloop.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/evtloop.cpp
3 // Purpose: implements wxEventLoop for GTK+
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 10.07.01
7 // RCS-ID: $Id$
8 // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "evtloop.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #endif //WX_PRECOMP
33
34 #include "wx/evtloop.h"
35
36 #include <gtk/gtk.h>
37
38 // ----------------------------------------------------------------------------
39 // wxEventLoopImpl
40 // ----------------------------------------------------------------------------
41
42 class WXDLLEXPORT wxEventLoopImpl
43 {
44 public:
45 // ctor
46 wxEventLoopImpl() { SetExitCode(0); }
47
48 // set/get the exit code
49 void SetExitCode(int exitcode) { m_exitcode = exitcode; }
50 int GetExitCode() const { return m_exitcode; }
51
52 private:
53 // the exit code of the event loop
54 int m_exitcode;
55 };
56
57 // ============================================================================
58 // wxEventLoop implementation
59 // ============================================================================
60
61 // ----------------------------------------------------------------------------
62 // wxEventLoop running and exiting
63 // ----------------------------------------------------------------------------
64
65 wxEventLoop *wxEventLoopBase::ms_activeLoop = NULL;
66
67 wxEventLoop::~wxEventLoop()
68 {
69 wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") );
70 }
71
72 int wxEventLoop::Run()
73 {
74 // event loops are not recursive, you need to create another loop!
75 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
76
77 wxEventLoop *oldLoop = ms_activeLoop;
78 ms_activeLoop = this;
79
80 m_impl = new wxEventLoopImpl;
81
82 gtk_main();
83
84 int exitcode = m_impl->GetExitCode();
85 delete m_impl;
86 m_impl = NULL;
87
88 ms_activeLoop = oldLoop;
89
90 return exitcode;
91 }
92
93 void wxEventLoop::Exit(int rc)
94 {
95 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
96
97 m_impl->SetExitCode(rc);
98
99 gtk_main_quit();
100 }
101
102 // ----------------------------------------------------------------------------
103 // wxEventLoop message processing dispatching
104 // ----------------------------------------------------------------------------
105
106 bool wxEventLoop::Pending() const
107 {
108 return gtk_events_pending() > 0;
109 }
110
111 bool wxEventLoop::Dispatch()
112 {
113 wxCHECK_MSG( IsRunning(), FALSE, _T("can't call Dispatch() if not running") );
114
115 gtk_main_iteration();
116
117 return TRUE;
118 }
119