]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/evtloop.cpp
fixed typo
[wxWidgets.git] / src / gtk1 / 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
34#include "wx/evtloop.h"
35
36#include <gtk/gtk.h>
37
38// ----------------------------------------------------------------------------
39// wxEventLoopImpl
40// ----------------------------------------------------------------------------
41
42class WXDLLEXPORT wxEventLoopImpl
43{
44public:
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
52private:
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
3754265e 65wxEventLoop *wxEventLoopBase::ms_activeLoop = NULL;
b9f246f7 66
8000ae7f
VZ
67wxEventLoop::~wxEventLoop()
68{
69 wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") );
70}
71
8000ae7f
VZ
72int 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
b9f246f7
VS
77 wxEventLoop *oldLoop = ms_activeLoop;
78 ms_activeLoop = this;
79
8000ae7f
VZ
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
b9f246f7
VS
88 ms_activeLoop = oldLoop;
89
8000ae7f
VZ
90 return exitcode;
91}
92
93void 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
106bool wxEventLoop::Pending() const
107{
108 return gtk_events_pending() > 0;
109}
110
111bool 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