]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/evtloop.cpp
wxFile::Length() return type fix (replaces last check in)
[wxWidgets.git] / src / gtk / evtloop.cpp
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 licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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/app.h"
35 #include "wx/evtloop.h"
36
37 #include <gtk/gtk.h>
38
39 // ----------------------------------------------------------------------------
40 // wxEventLoopImpl
41 // ----------------------------------------------------------------------------
42
43 class WXDLLEXPORT wxEventLoopImpl
44 {
45 public:
46 // ctor
47 wxEventLoopImpl() { SetExitCode(0); }
48
49 // set/get the exit code
50 void SetExitCode(int exitcode) { m_exitcode = exitcode; }
51 int GetExitCode() const { return m_exitcode; }
52
53 private:
54 // the exit code of the event loop
55 int m_exitcode;
56 };
57
58 // ============================================================================
59 // wxEventLoop implementation
60 // ============================================================================
61
62 // ----------------------------------------------------------------------------
63 // wxEventLoop running and exiting
64 // ----------------------------------------------------------------------------
65
66 wxEventLoop *wxEventLoopBase::ms_activeLoop = NULL;
67
68 wxEventLoop::~wxEventLoop()
69 {
70 wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") );
71 }
72
73 int wxEventLoop::Run()
74 {
75 // event loops are not recursive, you need to create another loop!
76 wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );
77
78 wxEventLoop *oldLoop = ms_activeLoop;
79 ms_activeLoop = this;
80
81 m_impl = new wxEventLoopImpl;
82
83 gtk_main();
84
85 int exitcode = m_impl->GetExitCode();
86 delete m_impl;
87 m_impl = NULL;
88
89 ms_activeLoop = oldLoop;
90
91 return exitcode;
92 }
93
94 void wxEventLoop::Exit(int rc)
95 {
96 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
97
98 m_impl->SetExitCode(rc);
99
100 gtk_main_quit();
101 }
102
103 // ----------------------------------------------------------------------------
104 // wxEventLoop message processing dispatching
105 // ----------------------------------------------------------------------------
106
107 extern bool g_isIdle;
108
109 bool wxEventLoop::Pending() const
110 {
111 if (wxTheApp && !g_isIdle)
112 {
113 // We need to remove idle callbacks or gtk_events_pending will
114 // never return false.
115 gtk_idle_remove( wxTheApp->m_idleTag );
116 wxTheApp->m_idleTag = 0;
117 g_isIdle = TRUE;
118 }
119
120 return gtk_events_pending();
121 }
122
123 bool wxEventLoop::Dispatch()
124 {
125 wxCHECK_MSG( IsRunning(), FALSE, _T("can't call Dispatch() if not running") );
126
127 gtk_main_iteration();
128
129 return TRUE;
130 }
131