]> git.saurik.com Git - wxWidgets.git/blame - src/qt/app.cpp
stray #include "wincmn.cpp" removed
[wxWidgets.git] / src / qt / app.cpp
CommitLineData
7c78e7c7
RR
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#include "wx/memory.h"
22
23#include "unistd.h"
24
25//-----------------------------------------------------------------------------
26// global data
27//-----------------------------------------------------------------------------
28
29wxApp *wxTheApp = NULL;
30wxAppInitializerFunction wxApp::m_appInitFn = (wxAppInitializerFunction) NULL;
31
32extern wxList wxPendingDelete;
33
34//-----------------------------------------------------------------------------
35// local functions
36//-----------------------------------------------------------------------------
37
38extern void wxFlushResources(void);
39
40//-----------------------------------------------------------------------------
41// global functions
42//-----------------------------------------------------------------------------
43
44void wxExit(void)
45{
46};
47
48bool wxYield(void)
49{
50 return TRUE;
51};
52
53//-----------------------------------------------------------------------------
54// wxApp
55//-----------------------------------------------------------------------------
56
57IMPLEMENT_DYNAMIC_CLASS(wxApp,wxEvtHandler)
58
59BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
60 EVT_IDLE(wxApp::OnIdle)
61END_EVENT_TABLE()
62
63wxApp::wxApp()
64{
65 m_topWindow = NULL;
66 m_exitOnFrameDelete = TRUE;
67};
68
69wxApp::~wxApp(void)
70{
71};
72
73bool wxApp::OnInit(void)
74{
75 return TRUE;
76};
77
78bool wxApp::OnInitGui(void)
79{
80 return TRUE;
81};
82
83int wxApp::OnRun(void)
84{
85 return MainLoop();
86};
87
88bool wxApp::ProcessIdle(void)
89{
90 wxIdleEvent event;
91 event.SetEventObject( this );
92 ProcessEvent( event );
93
94 return event.MoreRequested();
95};
96
97void wxApp::OnIdle( wxIdleEvent &event )
98{
99 static bool inOnIdle = FALSE;
100
101 // Avoid recursion (via ProcessEvent default case)
102 if (inOnIdle)
103 return;
104
105 inOnIdle = TRUE;
106
107 // 'Garbage' collection of windows deleted with Close().
108 DeletePendingObjects();
109
110 // flush the logged messages if any
111 wxLog *pLog = wxLog::GetActiveTarget();
112 if ( pLog != NULL && pLog->HasPendingMessages() )
113 pLog->Flush();
114
115 // Send OnIdle events to all windows
116 bool needMore = SendIdleEvents();
117
118 if (needMore)
119 event.RequestMore(TRUE);
120
121 inOnIdle = FALSE;
122};
123
124bool wxApp::SendIdleEvents(void)
125{
126 bool needMore = FALSE;
127 wxNode* node = wxTopLevelWindows.First();
128 while (node)
129 {
130 wxWindow* win = (wxWindow*) node->Data();
131 if (SendIdleEvents(win))
132 needMore = TRUE;
133
134 node = node->Next();
135 }
136 return needMore;
137};
138
139bool wxApp::SendIdleEvents( wxWindow* win )
140{
141 bool needMore = FALSE;
142
143 wxIdleEvent event;
144 event.SetEventObject(win);
145 win->ProcessEvent(event);
146
147 if (event.MoreRequested())
148 needMore = TRUE;
149
150 wxNode* node = win->GetChildren()->First();
151 while (node)
152 {
153 wxWindow* win = (wxWindow*) node->Data();
154 if (SendIdleEvents(win))
155 needMore = TRUE;
156
157 node = node->Next();
158 }
159 return needMore ;
160};
161
162int wxApp::OnExit(void)
163{
164 return 0;
165};
166
167int wxApp::MainLoop(void)
168{
169 return 0;
170};
171
172void wxApp::ExitMainLoop(void)
173{
174};
175
176bool wxApp::Initialized(void)
177{
178 return m_initialized;
179};
180
181bool wxApp::Pending(void)
182{
183 return FALSE;
184};
185
186void wxApp::Dispatch(void)
187{
188};
189
190void wxApp::DeletePendingObjects(void)
191{
192 wxNode *node = wxPendingDelete.First();
193 while (node)
194 {
195 wxObject *obj = (wxObject *)node->Data();
196
197 delete obj;
198
199 if (wxPendingDelete.Member(obj))
200 delete node;
201
202 node = wxPendingDelete.First();
203 };
204};
205
206wxWindow *wxApp::GetTopWindow(void)
207{
208 if (m_topWindow) return m_topWindow;
209 wxNode *node = wxTopLevelWindows.First();
210 if (!node) return NULL;
211 return (wxWindow*)node->Data();
212};
213
214void wxApp::SetTopWindow( wxWindow *win )
215{
216 m_topWindow = win;
217};
218
219void wxApp::CommonInit(void)
220{
221
222/*
223#if USE_RESOURCES
224 (void) wxGetResource("wxWindows", "OsVersion", &wxOsVersion);
225#endif
226*/
227
228 wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
229 wxTheColourDatabase->Initialize();
230 wxInitializeStockObjects();
231
232 // For PostScript printing
233#if USE_POSTSCRIPT
234 wxInitializePrintSetupData();
235 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
236 wxThePrintPaperDatabase->CreateDatabase();
237#endif
238
239
240/*
241 wxBitmap::InitStandardHandlers();
242
243 g_globalCursor = new wxCursor;
244*/
245
246 wxInitializeStockObjects();
247};
248
249void wxApp::CommonCleanUp(void)
250{
251 wxDeleteStockObjects();
252
253 wxFlushResources();
254};
255
256wxLog *wxApp::CreateLogTarget()
257{
258 return new wxLogGui;
259}
260
261//-----------------------------------------------------------------------------
262// wxEntry
263//-----------------------------------------------------------------------------
264
265int wxEntry( int argc, char *argv[] )
266{
267 wxBuffer = new char[BUFSIZ + 512];
268
269 wxClassInfo::InitializeClasses();
270
271#if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
272
273#if !defined(_WINDLL)
274 streambuf* sBuf = new wxDebugStreamBuf;
275#else
276 streambuf* sBuf = NULL;
277#endif
278 ostream* oStr = new ostream(sBuf) ;
279 wxDebugContext::SetStream(oStr, sBuf);
280
281#endif
282
283 if (!wxTheApp)
284 {
285 if (!wxApp::GetInitializerFunction())
286 {
287 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
288 return 0;
289 };
290
291 wxAppInitializerFunction app_ini = wxApp::GetInitializerFunction();
292
293 wxObject *test_app = app_ini();
294
295 wxTheApp = (wxApp*) test_app;
296
297// wxTheApp = (wxApp*)( app_ini() );
298 };
299
300 if (!wxTheApp)
301 {
302 printf( "wxWindows error: wxTheApp == NULL\n" );
303 return 0;
304 };
305
306// printf( "Programmstart.\n" );
307
308 wxTheApp->argc = argc;
309 wxTheApp->argv = argv;
310
311// Your init here !!!!
312
313 wxApp::CommonInit();
314
315 wxTheApp->OnInitGui();
316
317 // Here frames insert themselves automatically
318 // into wxTopLevelWindows by getting created
319 // in OnInit().
320
321 if (!wxTheApp->OnInit()) return 0;
322
323 wxTheApp->m_initialized = (wxTopLevelWindows.Number() > 0);
324
325 int retValue = 0;
326
327 if (wxTheApp->Initialized()) retValue = wxTheApp->OnRun();
328
329 wxTheApp->DeletePendingObjects();
330
331 wxTheApp->OnExit();
332
333 wxApp::CommonCleanUp();
334
335#if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
336 // At this point we want to check if there are any memory
337 // blocks that aren't part of the wxDebugContext itself,
338 // as a special case. Then when dumping we need to ignore
339 // wxDebugContext, too.
340 if (wxDebugContext::CountObjectsLeft() > 0)
341 {
342 wxTrace("There were memory leaks.\n");
343 wxDebugContext::Dump();
344 wxDebugContext::PrintStatistics();
345 }
346 wxDebugContext::SetStream(NULL, NULL);
347#endif
348
349 return retValue;
350};
351
352//-----------------------------------------------------------------------------
353// main()
354//-----------------------------------------------------------------------------
355
356#if defined(AIX) || defined(AIX4) || defined(____HPUX__)
357
358 // main in IMPLEMENT_WX_MAIN in IMPLEMENT_APP in app.h
359
360#else
361
362 int main(int argc, char *argv[]) { return wxEntry(argc, argv); }
363
364#endif
365
366