]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/evtloop.cpp
renamed wxDynamicThisCast to wxDynamicCastThis, removed 1st parameter, and documented
[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>
9// License: wxWindows license
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
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
65wxEventLoop::~wxEventLoop()
66{
67 wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") );
68}
69
70bool wxEventLoop::IsRunning() const
71{
72 return m_impl != NULL;
73}
74
75int wxEventLoop::Run()
76{
77 // event loops are not recursive, you need to create another loop!
78 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
79
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
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
104bool wxEventLoop::Pending() const
105{
106 return gtk_events_pending() > 0;
107}
108
109bool wxEventLoop::Dispatch()
110{
111 wxCHECK_MSG( IsRunning(), FALSE, _T("can't call Dispatch() if not running") );
112
113 gtk_main_iteration();
114
115 return TRUE;
116}
117