]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/evtloop.cpp
don't recompute nonbreakable space character every time a text fragment is added...
[wxWidgets.git] / src / gtk1 / evtloop.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/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 // wxGUIEventLoop implementation
56 // ============================================================================
57
58 // ----------------------------------------------------------------------------
59 // wxGUIEventLoop running and exiting
60 // ----------------------------------------------------------------------------
61
62 wxGUIEventLoop::~wxGUIEventLoop()
63 {
64 wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") );
65 }
66
67 int wxGUIEventLoop::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 OnExit();
79
80 int exitcode = m_impl->GetExitCode();
81 delete m_impl;
82 m_impl = NULL;
83
84 return exitcode;
85 }
86
87 void wxGUIEventLoop::Exit(int rc)
88 {
89 wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
90
91 m_impl->SetExitCode(rc);
92
93 gtk_main_quit();
94 }
95
96 // ----------------------------------------------------------------------------
97 // wxEventLoop message processing dispatching
98 // ----------------------------------------------------------------------------
99
100 bool wxGUIEventLoop::Pending() const
101 {
102 if (wxTheApp)
103 {
104 // We need to remove idle callbacks or gtk_events_pending will
105 // never return false.
106 wxTheApp->RemoveIdleTag();
107 }
108
109 return gtk_events_pending();
110 }
111
112 bool wxGUIEventLoop::Dispatch()
113 {
114 wxCHECK_MSG( IsRunning(), false, _T("can't call Dispatch() if not running") );
115
116 gtk_main_iteration();
117
118 return true;
119 }