]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/evtloop.cpp
using newer API
[wxWidgets.git] / src / gtk / evtloop.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #include "wx/evtloop.h"
28
29 #ifndef WX_PRECOMP
30 #include "wx/app.h"
31 #endif // WX_PRECOMP
32
33 #include <gtk/gtk.h>
34
35 // ----------------------------------------------------------------------------
36 // wxEventLoopImpl
37 // ----------------------------------------------------------------------------
38
39 class WXDLLEXPORT wxEventLoopImpl
40 {
41 public:
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
49 private:
50 // the exit code of the event loop
51 int m_exitcode;
52 };
53
54 // ============================================================================
55 // wxEventLoop implementation
56 // ============================================================================
57
58 // ----------------------------------------------------------------------------
59 // wxEventLoop running and exiting
60 // ----------------------------------------------------------------------------
61
62 wxEventLoop::~wxEventLoop()
63 {
64 wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") );
65 }
66
67 int wxEventLoop::Run()
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
72 wxEventLoopActivator activate(this);
73
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
82 return exitcode;
83 }
84
85 void wxEventLoop::Exit(int rc)
86 {
87 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
88
89 m_impl->SetExitCode(rc);
90
91 gtk_main_quit();
92 }
93
94 // ----------------------------------------------------------------------------
95 // wxEventLoop message processing dispatching
96 // ----------------------------------------------------------------------------
97
98 bool wxEventLoop::Pending() const
99 {
100 if (wxTheApp)
101 {
102 // We need to remove idle callbacks or gtk_events_pending will
103 // never return false.
104 wxTheApp->RemoveIdleTag();
105 }
106
107 return gtk_events_pending();
108 }
109
110 bool wxEventLoop::Dispatch()
111 {
112 wxCHECK_MSG( IsRunning(), false, _T("can't call Dispatch() if not running") );
113
114 gtk_main_iteration();
115
116 return true;
117 }