]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/evtloop.cpp
fixed wxString::FromAscii signature
[wxWidgets.git] / src / gtk / evtloop.cpp
CommitLineData
8000ae7f 1///////////////////////////////////////////////////////////////////////////////
670f9935 2// Name: src/gtk/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"
68a9527d 28#include "wx/ptr_scpd.h"
670f9935
WS
29
30#ifndef WX_PRECOMP
31 #include "wx/app.h"
32#endif // WX_PRECOMP
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
68a9527d
VZ
59wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoopImpl)
60
8000ae7f
VZ
61// ----------------------------------------------------------------------------
62// wxEventLoop running and exiting
63// ----------------------------------------------------------------------------
64
b46b1d59 65wxGUIEventLoop::~wxGUIEventLoop()
8000ae7f
VZ
66{
67 wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") );
68}
69
b46b1d59 70int wxGUIEventLoop::Run()
8000ae7f
VZ
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
77fb1a02 75 wxEventLoopActivator activate(this);
b9f246f7 76
68a9527d 77 wxEventLoopImplTiedPtr impl(&m_impl, new wxEventLoopImpl);
8000ae7f
VZ
78
79 gtk_main();
80
16d17da6
VZ
81 OnExit();
82
68a9527d 83 return m_impl->GetExitCode();
8000ae7f
VZ
84}
85
b46b1d59 86void wxGUIEventLoop::Exit(int rc)
8000ae7f
VZ
87{
88 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
89
90 m_impl->SetExitCode(rc);
91
92 gtk_main_quit();
93}
94
95// ----------------------------------------------------------------------------
96// wxEventLoop message processing dispatching
97// ----------------------------------------------------------------------------
98
b46b1d59 99bool wxGUIEventLoop::Pending() const
8000ae7f 100{
a1abca32
PC
101 bool pending;
102 wxApp* app = wxTheApp;
103 if (app != NULL)
104 // app->EventsPending() avoids false positives from our idle source
105 pending = app->EventsPending();
106 else
107 pending = gtk_events_pending() != 0;
108 return pending;
8000ae7f
VZ
109}
110
b46b1d59 111bool wxGUIEventLoop::Dispatch()
8000ae7f 112{
670f9935 113 wxCHECK_MSG( IsRunning(), false, _T("can't call Dispatch() if not running") );
8000ae7f
VZ
114
115 gtk_main_iteration();
116
670f9935 117 return true;
8000ae7f 118}