]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/evtloop.cpp
ac59d77edbda27c8c045cd377c0116a98b5cbf63
[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 #include "wx/evtloop.h"
32 #include "wx/app.h"
33
34 #include <gtk/gtk.h>
35
36 // ----------------------------------------------------------------------------
37 // wxEventLoopImpl
38 // ----------------------------------------------------------------------------
39
40 class WXDLLEXPORT wxEventLoopImpl
41 {
42 public:
43 // ctor
44 wxEventLoopImpl() { SetExitCode(0); }
45
46 // set/get the exit code
47 void SetExitCode(int exitcode) { m_exitcode = exitcode; }
48 int GetExitCode() const { return m_exitcode; }
49
50 private:
51 // the exit code of the event loop
52 int m_exitcode;
53 };
54
55 // ============================================================================
56 // wxEventLoop implementation
57 // ============================================================================
58
59 // ----------------------------------------------------------------------------
60 // wxEventLoop running and exiting
61 // ----------------------------------------------------------------------------
62
63 wxEventLoop *wxEventLoopBase::ms_activeLoop = NULL;
64
65 wxEventLoop::~wxEventLoop()
66 {
67 wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") );
68 }
69
70 int wxEventLoop::Run()
71 {
72 // event loops are not recursive, you need to create another loop!
73 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
74
75 wxEventLoop *oldLoop = ms_activeLoop;
76 ms_activeLoop = this;
77
78 m_impl = new wxEventLoopImpl;
79
80 gtk_main();
81
82 int exitcode = m_impl->GetExitCode();
83 delete m_impl;
84 m_impl = NULL;
85
86 ms_activeLoop = oldLoop;
87
88 return exitcode;
89 }
90
91 void wxEventLoop::Exit(int rc)
92 {
93 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
94
95 m_impl->SetExitCode(rc);
96
97 gtk_main_quit();
98 }
99
100 // ----------------------------------------------------------------------------
101 // wxEventLoop message processing dispatching
102 // ----------------------------------------------------------------------------
103
104 bool wxEventLoop::Pending() const
105 {
106 if (wxTheApp)
107 {
108 // We need to remove idle callbacks or gtk_events_pending will
109 // never return false.
110 wxTheApp->RemoveIdleTag();
111 }
112
113 return gtk_events_pending();
114 }
115
116 bool wxEventLoop::Dispatch()
117 {
118 wxCHECK_MSG( IsRunning(), FALSE, _T("can't call Dispatch() if not running") );
119
120 gtk_main_iteration();
121
122 return TRUE;
123 }
124