]>
Commit | Line | Data |
---|---|---|
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 | ||
36 | class WXDLLEXPORT wxEventLoopImpl | |
37 | { | |
38 | public: | |
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 | ||
46 | private: | |
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 | ||
59 | wxEventLoop::~wxEventLoop() | |
60 | { | |
61 | wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") ); | |
62 | } | |
63 | ||
8000ae7f VZ |
64 | int wxEventLoop::Run() |
65 | { | |
66 | // event loops are not recursive, you need to create another loop! | |
67 | wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") ); | |
68 | ||
77fb1a02 | 69 | wxEventLoopActivator activate(this); |
b9f246f7 | 70 | |
8000ae7f VZ |
71 | m_impl = new wxEventLoopImpl; |
72 | ||
73 | gtk_main(); | |
74 | ||
75 | int exitcode = m_impl->GetExitCode(); | |
76 | delete m_impl; | |
77 | m_impl = NULL; | |
78 | ||
79 | return exitcode; | |
80 | } | |
81 | ||
82 | void wxEventLoop::Exit(int rc) | |
83 | { | |
84 | wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") ); | |
85 | ||
86 | m_impl->SetExitCode(rc); | |
87 | ||
88 | gtk_main_quit(); | |
89 | } | |
90 | ||
91 | // ---------------------------------------------------------------------------- | |
92 | // wxEventLoop message processing dispatching | |
93 | // ---------------------------------------------------------------------------- | |
94 | ||
95 | bool wxEventLoop::Pending() const | |
96 | { | |
c263eb03 | 97 | if (wxTheApp) |
9213ca5d RD |
98 | { |
99 | // We need to remove idle callbacks or gtk_events_pending will | |
100 | // never return false. | |
fe593cc5 | 101 | wxTheApp->RemoveIdleTag(); |
9213ca5d RD |
102 | } |
103 | ||
104 | return gtk_events_pending(); | |
8000ae7f VZ |
105 | } |
106 | ||
107 | bool wxEventLoop::Dispatch() | |
108 | { | |
109 | wxCHECK_MSG( IsRunning(), FALSE, _T("can't call Dispatch() if not running") ); | |
110 | ||
111 | gtk_main_iteration(); | |
112 | ||
113 | return TRUE; | |
114 | } | |
115 |