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