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