]>
Commit | Line | Data |
---|---|---|
8000ae7f | 1 | /////////////////////////////////////////////////////////////////////////////// |
670f9935 | 2 | // Name: src/gtk1/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 | ||
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 | ||
8000ae7f VZ |
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 | ||
77fb1a02 | 72 | wxEventLoopActivator activate(this); |
b9f246f7 | 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 | ||
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 | { | |
c263eb03 | 100 | if (wxTheApp) |
9213ca5d RD |
101 | { |
102 | // We need to remove idle callbacks or gtk_events_pending will | |
103 | // never return false. | |
fe593cc5 | 104 | wxTheApp->RemoveIdleTag(); |
9213ca5d RD |
105 | } |
106 | ||
107 | return gtk_events_pending(); | |
8000ae7f VZ |
108 | } |
109 | ||
110 | bool wxEventLoop::Dispatch() | |
111 | { | |
670f9935 | 112 | wxCHECK_MSG( IsRunning(), false, _T("can't call Dispatch() if not running") ); |
8000ae7f VZ |
113 | |
114 | gtk_main_iteration(); | |
115 | ||
670f9935 | 116 | return true; |
8000ae7f | 117 | } |