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