]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/evtloop.cpp
This commit was generated by cvs2svn to compensate for changes in r30285,
[wxWidgets.git] / src / gtk / evtloop.cpp
CommitLineData
8000ae7f
VZ
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>
65571936 9// License: wxWindows licence
8000ae7f
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
8000ae7f
VZ
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
8000ae7f 31#include "wx/evtloop.h"
e1bf3ad3 32#include "wx/app.h"
8000ae7f
VZ
33
34#include <gtk/gtk.h>
35
36// ----------------------------------------------------------------------------
37// wxEventLoopImpl
38// ----------------------------------------------------------------------------
39
40class WXDLLEXPORT wxEventLoopImpl
41{
42public:
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
50private:
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
3754265e 63wxEventLoop *wxEventLoopBase::ms_activeLoop = NULL;
b9f246f7 64
8000ae7f
VZ
65wxEventLoop::~wxEventLoop()
66{
67 wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") );
68}
69
8000ae7f
VZ
70int 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
b9f246f7
VS
75 wxEventLoop *oldLoop = ms_activeLoop;
76 ms_activeLoop = this;
77
8000ae7f
VZ
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
b9f246f7
VS
86 ms_activeLoop = oldLoop;
87
8000ae7f
VZ
88 return exitcode;
89}
90
91void 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
9213ca5d
RD
104extern bool g_isIdle;
105
8000ae7f
VZ
106bool wxEventLoop::Pending() const
107{
9213ca5d
RD
108 if (wxTheApp && !g_isIdle)
109 {
110 // We need to remove idle callbacks or gtk_events_pending will
111 // never return false.
fe593cc5 112 wxTheApp->RemoveIdleTag();
9213ca5d
RD
113 g_isIdle = TRUE;
114 }
115
116 return gtk_events_pending();
8000ae7f
VZ
117}
118
119bool wxEventLoop::Dispatch()
120{
121 wxCHECK_MSG( IsRunning(), FALSE, _T("can't call Dispatch() if not running") );
122
123 gtk_main_iteration();
124
125 return TRUE;
126}
127