]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/evtloop.cpp
avoid hidden GetImageList
[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
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"
e1bf3ad3 28#include "wx/app.h"
8000ae7f
VZ
29
30#include <gtk/gtk.h>
31
32// ----------------------------------------------------------------------------
33// wxEventLoopImpl
34// ----------------------------------------------------------------------------
35
36class WXDLLEXPORT wxEventLoopImpl
37{
38public:
39 // ctor
40 wxEventLoopImpl() { SetExitCode(0); }
41
42 // set/get the exit code
43 void SetExitCode(int exitcode) { m_exitcode = exitcode; }
44 int GetExitCode() const { return m_exitcode; }
45
46private:
47 // the exit code of the event loop
48 int m_exitcode;
49};
50
51// ============================================================================
52// wxEventLoop implementation
53// ============================================================================
54
55// ----------------------------------------------------------------------------
56// wxEventLoop running and exiting
57// ----------------------------------------------------------------------------
58
3754265e 59wxEventLoop *wxEventLoopBase::ms_activeLoop = NULL;
b9f246f7 60
8000ae7f
VZ
61wxEventLoop::~wxEventLoop()
62{
63 wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") );
64}
65
8000ae7f
VZ
66int wxEventLoop::Run()
67{
68 // event loops are not recursive, you need to create another loop!
69 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
70
b9f246f7
VS
71 wxEventLoop *oldLoop = ms_activeLoop;
72 ms_activeLoop = this;
73
8000ae7f
VZ
74 m_impl = new wxEventLoopImpl;
75
76 gtk_main();
77
78 int exitcode = m_impl->GetExitCode();
79 delete m_impl;
80 m_impl = NULL;
81
b9f246f7
VS
82 ms_activeLoop = oldLoop;
83
8000ae7f
VZ
84 return exitcode;
85}
86
87void wxEventLoop::Exit(int rc)
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
100bool wxEventLoop::Pending() const
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
112bool wxEventLoop::Dispatch()
113{
114 wxCHECK_MSG( IsRunning(), FALSE, _T("can't call Dispatch() if not running") );
115
116 gtk_main_iteration();
117
118 return TRUE;
119}
120