]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/app.cpp
bug preventing compilation of wxLogGui under !Windows corrected
[wxWidgets.git] / src / gtk / app.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: app.cpp
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#ifdef __GNUG__
12#pragma implementation "app.h"
13#endif
14
15#include "wx/app.h"
16#include "wx/gdicmn.h"
17#include "wx/utils.h"
18#include "wx/postscrp.h"
19#include "wx/intl.h"
20#include "wx/log.h"
21
22#include "unistd.h"
23
24#ifdef USE_GDK_IMLIB
25#include "gdk_imlib.h"
26#endif
27
28//-----------------------------------------------------------------------------
29// global data
30//-----------------------------------------------------------------------------
31
32wxApp *wxTheApp = NULL;
33wxAppInitializerFunction wxApp::m_appInitFn = (wxAppInitializerFunction) NULL;
34
35extern wxList wxPendingDelete;
36
37//-----------------------------------------------------------------------------
38// local functions
39//-----------------------------------------------------------------------------
40
41extern void wxFlushResources(void);
42
43//-----------------------------------------------------------------------------
44// global functions
45//-----------------------------------------------------------------------------
46
47void wxExit(void)
48{
49 gtk_main_quit();
50};
51
52bool wxYield(void)
53{
54 while (gtk_events_pending() > 0) gtk_main_iteration();
55 return TRUE;
56};
57
58//-----------------------------------------------------------------------------
59// wxApp
60//-----------------------------------------------------------------------------
61
62IMPLEMENT_DYNAMIC_CLASS(wxApp,wxEvtHandler)
63
64gint wxapp_idle_callback( gpointer WXUNUSED(data) )
65{
66 if (wxTheApp) wxTheApp->OnIdle();
67 usleep( 10000 );
68 return TRUE;
69};
70
71wxApp::wxApp()
72{
73 m_idleTag = 0;
74 m_topWindow = NULL;
75 m_exitOnFrameDelete = TRUE;
76};
77
78wxApp::~wxApp(void)
79{
80 gtk_idle_remove( m_idleTag );
81};
82
83bool wxApp::OnInit(void)
84{
85 return TRUE;
86};
87
88bool wxApp::OnInitGui(void)
89{
90 m_idleTag = gtk_idle_add( wxapp_idle_callback, NULL );
91 return TRUE;
92};
93
94int wxApp::OnRun(void)
95{
96 return MainLoop();
97};
98
99bool wxApp::OnIdle(void)
100{
101 DeletePendingObjects();
102 return FALSE;
103};
104
105int wxApp::OnExit(void)
106{
107 return 0;
108};
109
110int wxApp::MainLoop(void)
111{
112 gtk_main();
113 return 0;
114};
115
116void wxApp::ExitMainLoop(void)
117{
118 gtk_main_quit();
119};
120
121bool wxApp::Initialized(void)
122{
123 return m_initialized;
124};
125
126bool wxApp::Pending(void)
127{
128 return FALSE;
129};
130
131void wxApp::Dispatch(void)
132{
133};
134
135void wxApp::DeletePendingObjects(void)
136{
137 wxNode *node = wxPendingDelete.First();
138 while (node)
139 {
140 wxObject *obj = (wxObject *)node->Data();
141
142 delete obj;
143
144 if (wxPendingDelete.Member(obj))
145 delete node;
146
147 node = wxPendingDelete.First();
148 };
149};
150
151wxWindow *wxApp::GetTopWindow(void)
152{
153 if (m_topWindow) return m_topWindow;
154 wxNode *node = wxTopLevelWindows.First();
155 if (!node) return NULL;
156 return (wxWindow*)node->Data();
157};
158
159void wxApp::SetTopWindow( wxWindow *win )
160{
161 m_topWindow = win;
162};
163
164void wxApp::CommonInit(void)
165{
166
167/*
168#if USE_RESOURCES
169 (void) wxGetResource("wxWindows", "OsVersion", &wxOsVersion);
170#endif
171*/
172
173 wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
174 wxTheColourDatabase->Initialize();
175 wxInitializeStockObjects();
176
177 // For PostScript printing
178#if USE_POSTSCRIPT
179 wxInitializePrintSetupData();
180 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
181 wxThePrintPaperDatabase->CreateDatabase();
182#endif
183
184
185/*
186 wxBitmap::InitStandardHandlers();
187
188 g_globalCursor = new wxCursor;
189*/
190
191 wxInitializeStockObjects();
192};
193
194void wxApp::CommonCleanUp(void)
195{
196 wxDeleteStockObjects();
197
198 wxFlushResources();
199};
200
201wxLog *wxApp::CreateLogTarget()
202{
203 return new wxLogGui;
204}
205
206//-----------------------------------------------------------------------------
207// wxEntry
208//-----------------------------------------------------------------------------
209
210int wxEntry( int argc, char *argv[] )
211{
212 wxBuffer = new char[BUFSIZ + 512];
213
214 wxClassInfo::InitializeClasses();
215
216 if (!wxTheApp)
217 {
218 if (!wxApp::GetInitializerFunction())
219 {
220 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
221 return 0;
222 };
223
224 wxAppInitializerFunction app_ini = wxApp::GetInitializerFunction();
225
226 wxObject *test_app = app_ini();
227
228 wxTheApp = (wxApp*) test_app;
229
230// wxTheApp = (wxApp*)( app_ini() );
231 };
232
233 if (!wxTheApp)
234 {
235 printf( "wxWindows error: wxTheApp == NULL\n" );
236 return 0;
237 };
238
239// printf( "Programmstart.\n" );
240
241 wxTheApp->argc = argc;
242 wxTheApp->argv = argv;
243
244 gtk_init( &argc, &argv );
245
246#ifdef USE_GDK_IMLIB
247
248 gdk_imlib_init();
249
250 gtk_widget_push_visual(gdk_imlib_get_visual());
251
252 gtk_widget_push_colormap(gdk_imlib_get_colormap());
253
254#endif
255
256 wxApp::CommonInit();
257
258 wxTheApp->OnInitGui();
259
260 // Here frames insert themselves automatically
261 // into wxTopLevelWindows by getting created
262 // in OnInit().
263
264 if (!wxTheApp->OnInit()) return 0;
265
266 wxTheApp->m_initialized = (wxTopLevelWindows.Number() > 0);
267
268 int retValue = 0;
269
270 if (wxTheApp->Initialized()) retValue = wxTheApp->OnRun();
271
272 wxTheApp->DeletePendingObjects();
273
274 wxTheApp->OnExit();
275
276 wxApp::CommonCleanUp();
277
278 return retValue;
279};
1a56f55c
RR
280
281//-----------------------------------------------------------------------------
282// main()
283//-----------------------------------------------------------------------------
284
7f4dc78d 285#if defined(AIX) || defined(AIX4) || defined(____HPUX__)
1a56f55c
RR
286
287 // main in IMPLEMENT_WX_MAIN in IMPLEMENT_APP in app.h
288
289#else
290
291 int main(int argc, char *argv[]) { return wxEntry(argc, argv); }
292
293#endif
294
295