]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/evtloop.cpp
remove also wxT(); it's confusing, too; do load wxstd.mo catalog after calling wxLoca...
[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"
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
8000ae7f
VZ
35// ============================================================================
36// wxEventLoop implementation
37// ============================================================================
38
39// ----------------------------------------------------------------------------
40// wxEventLoop running and exiting
41// ----------------------------------------------------------------------------
42
564c7fc4 43wxGUIEventLoop::wxGUIEventLoop()
8000ae7f 44{
564c7fc4 45 m_exitcode = 0;
8000ae7f
VZ
46}
47
b46b1d59 48int wxGUIEventLoop::Run()
8000ae7f
VZ
49{
50 // event loops are not recursive, you need to create another loop!
564c7fc4 51 wxCHECK_MSG( !IsRunning(), -1, "can't reenter a message loop" );
8000ae7f 52
77fb1a02 53 wxEventLoopActivator activate(this);
b9f246f7 54
8000ae7f
VZ
55 gtk_main();
56
16d17da6
VZ
57 OnExit();
58
564c7fc4 59 return m_exitcode;
8000ae7f
VZ
60}
61
b46b1d59 62void wxGUIEventLoop::Exit(int rc)
8000ae7f 63{
564c7fc4 64 wxCHECK_RET( IsRunning(), "can't call Exit() if not running" );
8000ae7f 65
564c7fc4 66 m_exitcode = rc;
8000ae7f
VZ
67
68 gtk_main_quit();
69}
70
564c7fc4
VZ
71void wxGUIEventLoop::WakeUp()
72{
73 // TODO: idle events handling should really be done by wxEventLoop itself
74 // but for now it's completely in gtk/app.cpp so just call there when
75 // we have wxTheApp and hope that it doesn't matter that we do
76 // nothing when we don't...
77 if ( wxTheApp )
78 wxTheApp->WakeUpIdle();
79}
80
8000ae7f
VZ
81// ----------------------------------------------------------------------------
82// wxEventLoop message processing dispatching
83// ----------------------------------------------------------------------------
84
b46b1d59 85bool wxGUIEventLoop::Pending() const
8000ae7f 86{
564c7fc4
VZ
87 if ( wxTheApp )
88 {
89 // this avoids false positives from our idle source
90 return wxTheApp->EventsPending();
91 }
92
93 return gtk_events_pending() != 0;
8000ae7f
VZ
94}
95
b46b1d59 96bool wxGUIEventLoop::Dispatch()
8000ae7f 97{
670f9935 98 wxCHECK_MSG( IsRunning(), false, _T("can't call Dispatch() if not running") );
8000ae7f 99
4b8af4ac
VZ
100 // gtk_main_iteration() returns TRUE only if gtk_main_quit() was called
101 return !gtk_main_iteration();
8000ae7f 102}
564c7fc4
VZ
103
104extern "C" {
105static gboolean wx_event_loop_timeout(void* data)
106{
107 bool* expired = static_cast<bool*>(data);
108 *expired = true;
109
110 // return FALSE to remove this timeout
111 return FALSE;
112}
113}
114
115int wxGUIEventLoop::DispatchTimeout(unsigned long timeout)
116{
117 bool expired = false;
118 const unsigned id = g_timeout_add(timeout, wx_event_loop_timeout, &expired);
119 bool quit = gtk_main_iteration() != 0;
120
121 if ( expired )
122 return -1;
123
124 g_source_remove(id);
125
126 return !quit;
127}
128
129