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> | |
9 | // License: wxWindows license | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
21 | #pragma implementation "evtloop.h" | |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #ifndef WX_PRECOMP | |
32 | #endif //WX_PRECOMP | |
33 | ||
34 | #include "wx/evtloop.h" | |
35 | ||
36 | #include <gtk/gtk.h> | |
37 | ||
38 | // ---------------------------------------------------------------------------- | |
39 | // wxEventLoopImpl | |
40 | // ---------------------------------------------------------------------------- | |
41 | ||
42 | class WXDLLEXPORT wxEventLoopImpl | |
43 | { | |
44 | public: | |
45 | // ctor | |
46 | wxEventLoopImpl() { SetExitCode(0); } | |
47 | ||
48 | // set/get the exit code | |
49 | void SetExitCode(int exitcode) { m_exitcode = exitcode; } | |
50 | int GetExitCode() const { return m_exitcode; } | |
51 | ||
52 | private: | |
53 | // the exit code of the event loop | |
54 | int m_exitcode; | |
55 | }; | |
56 | ||
57 | // ============================================================================ | |
58 | // wxEventLoop implementation | |
59 | // ============================================================================ | |
60 | ||
61 | // ---------------------------------------------------------------------------- | |
62 | // wxEventLoop running and exiting | |
63 | // ---------------------------------------------------------------------------- | |
64 | ||
b9f246f7 VS |
65 | wxEventLoop *wxEventLoop::ms_activeLoop = NULL; |
66 | ||
8000ae7f VZ |
67 | wxEventLoop::~wxEventLoop() |
68 | { | |
69 | wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") ); | |
70 | } | |
71 | ||
72 | bool wxEventLoop::IsRunning() const | |
73 | { | |
74 | return m_impl != NULL; | |
75 | } | |
76 | ||
77 | int wxEventLoop::Run() | |
78 | { | |
79 | // event loops are not recursive, you need to create another loop! | |
80 | wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") ); | |
81 | ||
b9f246f7 VS |
82 | wxEventLoop *oldLoop = ms_activeLoop; |
83 | ms_activeLoop = this; | |
84 | ||
8000ae7f VZ |
85 | m_impl = new wxEventLoopImpl; |
86 | ||
87 | gtk_main(); | |
88 | ||
89 | int exitcode = m_impl->GetExitCode(); | |
90 | delete m_impl; | |
91 | m_impl = NULL; | |
92 | ||
b9f246f7 VS |
93 | ms_activeLoop = oldLoop; |
94 | ||
8000ae7f VZ |
95 | return exitcode; |
96 | } | |
97 | ||
98 | void wxEventLoop::Exit(int rc) | |
99 | { | |
100 | wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") ); | |
101 | ||
102 | m_impl->SetExitCode(rc); | |
103 | ||
104 | gtk_main_quit(); | |
105 | } | |
106 | ||
107 | // ---------------------------------------------------------------------------- | |
108 | // wxEventLoop message processing dispatching | |
109 | // ---------------------------------------------------------------------------- | |
110 | ||
111 | bool wxEventLoop::Pending() const | |
112 | { | |
113 | return gtk_events_pending() > 0; | |
114 | } | |
115 | ||
116 | bool wxEventLoop::Dispatch() | |
117 | { | |
118 | wxCHECK_MSG( IsRunning(), FALSE, _T("can't call Dispatch() if not running") ); | |
119 | ||
120 | gtk_main_iteration(); | |
121 | ||
122 | return TRUE; | |
123 | } | |
124 |