]> git.saurik.com Git - wxWidgets.git/blame - src/qt/app.cpp
Changed order of #ifdefs to get native version on OS/2, even if
[wxWidgets.git] / src / qt / app.cpp
CommitLineData
7c78e7c7
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: app.cpp
01b2eeec
KB
3// Purpose: wxApp
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
7c78e7c7
RR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "app.h"
14#endif
15
01b2eeec 16#include "wx/frame.h"
7c78e7c7 17#include "wx/app.h"
7c78e7c7 18#include "wx/utils.h"
01b2eeec
KB
19#include "wx/gdicmn.h"
20#include "wx/pen.h"
21#include "wx/brush.h"
22#include "wx/cursor.h"
23#include "wx/icon.h"
24#include "wx/palette.h"
25#include "wx/dc.h"
26#include "wx/dialog.h"
27#include "wx/msgdlg.h"
7c78e7c7 28#include "wx/log.h"
01b2eeec 29#include "wx/module.h"
7c78e7c7 30
47d67540 31#if wxUSE_WX_RESOURCES
01b2eeec
KB
32#include "wx/resource.h"
33#endif
7c78e7c7 34
01b2eeec 35#include <string.h>
7c78e7c7 36
01b2eeec
KB
37#if defined(__WIN95__) && !defined(__GNUWIN32__)
38extern char *wxBuffer;
7c78e7c7
RR
39extern wxList wxPendingDelete;
40
01b2eeec 41wxApp *wxTheApp = NULL;
7c78e7c7 42
01b2eeec 43IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
7c78e7c7
RR
44BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
45 EVT_IDLE(wxApp::OnIdle)
46END_EVENT_TABLE()
47
01b2eeec 48long wxApp::sm_lastMessageTime = 0;
7c78e7c7 49
01b2eeec 50void wxApp::CommonInit()
7c78e7c7 51{
01b2eeec
KB
52#ifdef __WXMSW__
53 wxBuffer = new char[1500];
54#else
55 wxBuffer = new char[BUFSIZ + 512];
56#endif
7c78e7c7 57
01b2eeec 58 wxClassInfo::InitializeClasses();
7c78e7c7 59
01b2eeec
KB
60 wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
61 wxTheColourDatabase->Initialize();
62 wxInitializeStockObjects();
7c78e7c7 63
47d67540 64#if wxUSE_WX_RESOURCES
01b2eeec
KB
65 wxInitializeResourceSystem();
66#endif
7c78e7c7 67
01b2eeec 68 // For PostScript printing
47d67540 69#if wxUSE_POSTSCRIPT
01b2eeec
KB
70 wxInitializePrintSetupData();
71 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
72 wxThePrintPaperDatabase->CreateDatabase();
73#endif
7c78e7c7 74
01b2eeec 75 wxBitmap::InitStandardHandlers();
7c78e7c7 76
01b2eeec
KB
77 wxModule::RegisterModules();
78 wxASSERT( wxModule::InitializeModules() == TRUE );
79}
7c78e7c7 80
01b2eeec 81void wxApp::CommonCleanUp()
7c78e7c7 82{
01b2eeec 83 wxModule::CleanUpModules();
7c78e7c7 84
47d67540 85#if wxUSE_WX_RESOURCES
01b2eeec
KB
86 wxCleanUpResourceSystem();
87#endif
7c78e7c7 88
01b2eeec 89 wxDeleteStockObjects() ;
7c78e7c7 90
01b2eeec
KB
91 // Destroy all GDI lists, etc.
92 delete wxTheBrushList;
93 wxTheBrushList = NULL;
7c78e7c7 94
01b2eeec
KB
95 delete wxThePenList;
96 wxThePenList = NULL;
7c78e7c7 97
01b2eeec
KB
98 delete wxTheFontList;
99 wxTheFontList = NULL;
7c78e7c7 100
01b2eeec
KB
101 delete wxTheBitmapList;
102 wxTheBitmapList = NULL;
7c78e7c7 103
01b2eeec
KB
104 delete wxTheColourDatabase;
105 wxTheColourDatabase = NULL;
7c78e7c7 106
47d67540 107#if wxUSE_POSTSCRIPT
01b2eeec
KB
108 wxInitializePrintSetupData(FALSE);
109 delete wxThePrintPaperDatabase;
110 wxThePrintPaperDatabase = NULL;
7c78e7c7
RR
111#endif
112
01b2eeec 113 wxBitmap::CleanUpHandlers();
7c78e7c7 114
01b2eeec
KB
115 delete[] wxBuffer;
116 wxBuffer = NULL;
7c78e7c7 117
01b2eeec
KB
118 // do it as the very last thing because everything else can log messages
119 delete wxLog::SetActiveTarget(NULL);
7c78e7c7
RR
120}
121
7c78e7c7
RR
122int wxEntry( int argc, char *argv[] )
123{
7c78e7c7
RR
124 wxClassInfo::InitializeClasses();
125
47d67540 126#if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
7c78e7c7
RR
127
128#if !defined(_WINDLL)
129 streambuf* sBuf = new wxDebugStreamBuf;
130#else
131 streambuf* sBuf = NULL;
132#endif
133 ostream* oStr = new ostream(sBuf) ;
134 wxDebugContext::SetStream(oStr, sBuf);
135
136#endif
137
138 if (!wxTheApp)
139 {
140 if (!wxApp::GetInitializerFunction())
141 {
142 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
143 return 0;
144 };
145
01b2eeec 146 wxTheApp = (* wxApp::GetInitializerFunction()) ();
7c78e7c7
RR
147 };
148
149 if (!wxTheApp)
150 {
151 printf( "wxWindows error: wxTheApp == NULL\n" );
152 return 0;
153 };
154
7c78e7c7
RR
155 wxTheApp->argc = argc;
156 wxTheApp->argv = argv;
157
01b2eeec
KB
158 // TODO: your platform-specific initialization.
159
7c78e7c7
RR
160 wxApp::CommonInit();
161
01b2eeec 162 // GUI-specific initialization, such as creating an app context.
7c78e7c7
RR
163 wxTheApp->OnInitGui();
164
165 // Here frames insert themselves automatically
166 // into wxTopLevelWindows by getting created
167 // in OnInit().
168
169 if (!wxTheApp->OnInit()) return 0;
170
171 wxTheApp->m_initialized = (wxTopLevelWindows.Number() > 0);
172
173 int retValue = 0;
174
175 if (wxTheApp->Initialized()) retValue = wxTheApp->OnRun();
176
177 wxTheApp->DeletePendingObjects();
178
179 wxTheApp->OnExit();
180
181 wxApp::CommonCleanUp();
182
47d67540 183#if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
7c78e7c7
RR
184 // At this point we want to check if there are any memory
185 // blocks that aren't part of the wxDebugContext itself,
186 // as a special case. Then when dumping we need to ignore
187 // wxDebugContext, too.
188 if (wxDebugContext::CountObjectsLeft() > 0)
189 {
190 wxTrace("There were memory leaks.\n");
191 wxDebugContext::Dump();
192 wxDebugContext::PrintStatistics();
193 }
194 wxDebugContext::SetStream(NULL, NULL);
195#endif
196
197 return retValue;
198};
199
01b2eeec
KB
200// Static member initialization
201wxAppInitializerFunction wxApp::m_appInitFn = (wxAppInitializerFunction) NULL;
7c78e7c7 202
01b2eeec
KB
203wxApp::wxApp()
204{
205 m_topWindow = NULL;
206 wxTheApp = this;
207 m_className = "";
208 m_wantDebugOutput = TRUE ;
209 m_appName = "";
210 argc = 0;
211 argv = NULL;
212#ifdef __WXMSW__
213 m_printMode = wxPRINT_WINDOWS;
214#else
215 m_printMode = wxPRINT_POSTSCRIPT;
216#endif
217 m_exitOnFrameDelete = TRUE;
218 m_auto3D = TRUE;
219}
7c78e7c7 220
01b2eeec
KB
221bool wxApp::Initialized()
222{
223 if (GetTopWindow())
224 return TRUE;
225 else
226 return FALSE;
227}
7c78e7c7 228
01b2eeec
KB
229int wxApp::MainLoop()
230{
231 m_keepGoing = TRUE;
7c78e7c7 232
01b2eeec
KB
233/* TODO: implement your main loop here, calling ProcessIdle in idle time.
234 while (m_keepGoing)
235 {
236 while (!::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) &&
237 ProcessIdle()) {}
238 if (!DoMessage())
239 m_keepGoing = FALSE;
240 }
241*/
7c78e7c7 242
01b2eeec
KB
243 return 0;
244}
245
246// Returns TRUE if more time is needed.
247bool wxApp::ProcessIdle()
248{
249 wxIdleEvent event;
250 event.SetEventObject(this);
251 ProcessEvent(event);
252
253 return event.MoreRequested();
254}
255
256void wxApp::ExitMainLoop()
257{
258 m_keepGoing = FALSE;
259}
260
261// Is a message/event pending?
262bool wxApp::Pending()
263{
264/* TODO.
265 */
266 return FALSE;
267}
268
269// Dispatch a message.
270void wxApp::Dispatch()
271{
272/* TODO.
273 */
274}
275
276void wxApp::OnIdle(wxIdleEvent& event)
277{
278 static bool inOnIdle = FALSE;
279
280 // Avoid recursion (via ProcessEvent default case)
281 if (inOnIdle)
282 return;
283
284 inOnIdle = TRUE;
285
286 // 'Garbage' collection of windows deleted with Close().
287 DeletePendingObjects();
288
289 // flush the logged messages if any
290 wxLog *pLog = wxLog::GetActiveTarget();
291 if ( pLog != NULL && pLog->HasPendingMessages() )
292 pLog->Flush();
293
294 // Send OnIdle events to all windows
295 bool needMore = SendIdleEvents();
296
297 if (needMore)
298 event.RequestMore(TRUE);
299
300 inOnIdle = FALSE;
301}
302
303// Send idle event to all top-level windows
304bool wxApp::SendIdleEvents()
305{
306 bool needMore = FALSE;
307 wxNode* node = wxTopLevelWindows.First();
308 while (node)
309 {
310 wxWindow* win = (wxWindow*) node->Data();
311 if (SendIdleEvents(win))
312 needMore = TRUE;
7c78e7c7 313
01b2eeec
KB
314 node = node->Next();
315 }
316 return needMore;
317}
318
319// Send idle event to window and all subwindows
320bool wxApp::SendIdleEvents(wxWindow* win)
321{
322 bool needMore = FALSE;
323
324 wxIdleEvent event;
325 event.SetEventObject(win);
326 win->ProcessEvent(event);
327
328 if (event.MoreRequested())
329 needMore = TRUE;
330
331 wxNode* node = win->GetChildren()->First();
332 while (node)
333 {
334 wxWindow* win = (wxWindow*) node->Data();
335 if (SendIdleEvents(win))
336 needMore = TRUE;
337
338 node = node->Next();
339 }
340 return needMore ;
341}
342
343void wxApp::DeletePendingObjects()
344{
345 wxNode *node = wxPendingDelete.First();
346 while (node)
347 {
348 wxObject *obj = (wxObject *)node->Data();
349
350 delete obj;
351
352 if (wxPendingDelete.Member(obj))
353 delete node;
354
355 // Deleting one object may have deleted other pending
356 // objects, so start from beginning of list again.
357 node = wxPendingDelete.First();
358 }
359}
360
361wxLog* wxApp::CreateLogTarget()
362{
363 return new wxLogGui;
364}
365
366wxWindow* wxApp::GetTopWindow() const
367{
368 if (m_topWindow)
369 return m_topWindow;
370 else if (wxTopLevelWindows.Number() > 0)
371 return (wxWindow*) wxTopLevelWindows.First()->Data();
372 else
373 return NULL;
374}
375
376void wxExit()
377{
378 wxApp::CommonCleanUp();
379/*
380 * TODO: Exit in some platform-specific way. Not recommended that the app calls this:
381 * only for emergencies.
382 */
383}
384
385// Yield to other processes
386bool wxYield()
387{
388 /*
389 * TODO
390 */
391 return TRUE;
392}
7c78e7c7 393