]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/evtloop.cpp
STL build fix
[wxWidgets.git] / src / gtk1 / evtloop.cpp
CommitLineData
8000ae7f 1///////////////////////////////////////////////////////////////////////////////
670f9935 2// Name: src/gtk1/evtloop.cpp
8000ae7f
VZ
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
8000ae7f
VZ
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
8000ae7f 27#include "wx/evtloop.h"
670f9935
WS
28
29#ifndef WX_PRECOMP
30 #include "wx/app.h"
31#endif // WX_PRECOMP
8000ae7f
VZ
32
33#include <gtk/gtk.h>
34
35// ----------------------------------------------------------------------------
36// wxEventLoopImpl
37// ----------------------------------------------------------------------------
38
39class WXDLLEXPORT wxEventLoopImpl
40{
41public:
42 // ctor
43 wxEventLoopImpl() { SetExitCode(0); }
44
45 // set/get the exit code
46 void SetExitCode(int exitcode) { m_exitcode = exitcode; }
47 int GetExitCode() const { return m_exitcode; }
48
49private:
50 // the exit code of the event loop
51 int m_exitcode;
52};
53
54// ============================================================================
b46b1d59 55// wxGUIEventLoop implementation
8000ae7f
VZ
56// ============================================================================
57
58// ----------------------------------------------------------------------------
b46b1d59 59// wxGUIEventLoop running and exiting
8000ae7f
VZ
60// ----------------------------------------------------------------------------
61
b46b1d59 62wxGUIEventLoop::~wxGUIEventLoop()
8000ae7f
VZ
63{
64 wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") );
65}
66
b46b1d59 67int wxGUIEventLoop::Run()
8000ae7f
VZ
68{
69 // event loops are not recursive, you need to create another loop!
70 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
71
77fb1a02 72 wxEventLoopActivator activate(this);
b9f246f7 73
8000ae7f
VZ
74 m_impl = new wxEventLoopImpl;
75
76 gtk_main();
77
16d17da6
VZ
78 OnExit();
79
8000ae7f
VZ
80 int exitcode = m_impl->GetExitCode();
81 delete m_impl;
82 m_impl = NULL;
83
84 return exitcode;
85}
86
b46b1d59 87void wxGUIEventLoop::Exit(int rc)
8000ae7f
VZ
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
b46b1d59 100bool wxGUIEventLoop::Pending() const
8000ae7f 101{
c263eb03 102 if (wxTheApp)
9213ca5d
RD
103 {
104 // We need to remove idle callbacks or gtk_events_pending will
105 // never return false.
fe593cc5 106 wxTheApp->RemoveIdleTag();
9213ca5d
RD
107 }
108
109 return gtk_events_pending();
8000ae7f
VZ
110}
111
b46b1d59 112bool wxGUIEventLoop::Dispatch()
8000ae7f 113{
670f9935 114 wxCHECK_MSG( IsRunning(), false, _T("can't call Dispatch() if not running") );
8000ae7f
VZ
115
116 gtk_main_iteration();
117
670f9935 118 return true;
8000ae7f 119}