]>
git.saurik.com Git - wxWidgets.git/blob - src/qt/app.cpp
1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "app.h"
19 #include "wx/gdicmn.h"
22 #include "wx/cursor.h"
24 #include "wx/palette.h"
26 #include "wx/dialog.h"
27 #include "wx/msgdlg.h"
29 #include "wx/module.h"
31 #if wxUSE_WX_RESOURCES
32 #include "wx/resource.h"
37 #if defined(__WIN95__) && !defined(__GNUWIN32__)
38 extern char *wxBuffer
;
39 extern wxList wxPendingDelete
;
41 wxApp
*wxTheApp
= NULL
;
43 #if !USE_SHARED_LIBRARY
44 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
45 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
46 EVT_IDLE(wxApp::OnIdle
)
50 long wxApp::sm_lastMessageTime
= 0;
52 void wxApp::CommonInit()
55 wxBuffer
= new char[1500];
57 wxBuffer
= new char[BUFSIZ
+ 512];
60 wxClassInfo::InitializeClasses();
62 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
63 wxTheColourDatabase
->Initialize();
64 wxInitializeStockObjects();
66 #if wxUSE_WX_RESOURCES
67 wxInitializeResourceSystem();
70 // For PostScript printing
72 wxInitializePrintSetupData();
73 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
74 wxThePrintPaperDatabase
->CreateDatabase();
77 wxBitmap::InitStandardHandlers();
79 wxModule::RegisterModules();
80 wxASSERT( wxModule::InitializeModules() == TRUE
);
83 void wxApp::CommonCleanUp()
85 wxModule::CleanUpModules();
87 #if wxUSE_WX_RESOURCES
88 wxCleanUpResourceSystem();
91 wxDeleteStockObjects() ;
93 // Destroy all GDI lists, etc.
94 delete wxTheBrushList
;
95 wxTheBrushList
= NULL
;
100 delete wxTheFontList
;
101 wxTheFontList
= NULL
;
103 delete wxTheBitmapList
;
104 wxTheBitmapList
= NULL
;
106 delete wxTheColourDatabase
;
107 wxTheColourDatabase
= NULL
;
110 wxInitializePrintSetupData(FALSE
);
111 delete wxThePrintPaperDatabase
;
112 wxThePrintPaperDatabase
= NULL
;
115 wxBitmap::CleanUpHandlers();
120 // do it as the very last thing because everything else can log messages
121 delete wxLog::SetActiveTarget(NULL
);
124 int wxEntry( int argc
, char *argv
[] )
126 wxClassInfo::InitializeClasses();
128 #if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
130 #if !defined(_WINDLL)
131 streambuf
* sBuf
= new wxDebugStreamBuf
;
133 streambuf
* sBuf
= NULL
;
135 ostream
* oStr
= new ostream(sBuf
) ;
136 wxDebugContext::SetStream(oStr
, sBuf
);
142 if (!wxApp::GetInitializerFunction())
144 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
148 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
153 printf( "wxWindows error: wxTheApp == NULL\n" );
157 wxTheApp
->argc
= argc
;
158 wxTheApp
->argv
= argv
;
160 // TODO: your platform-specific initialization.
164 // GUI-specific initialization, such as creating an app context.
165 wxTheApp
->OnInitGui();
167 // Here frames insert themselves automatically
168 // into wxTopLevelWindows by getting created
171 if (!wxTheApp
->OnInit()) return 0;
173 wxTheApp
->m_initialized
= (wxTopLevelWindows
.Number() > 0);
177 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
179 wxTheApp
->DeletePendingObjects();
183 wxApp::CommonCleanUp();
185 #if (WXDEBUG && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
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)
192 wxTrace("There were memory leaks.\n");
193 wxDebugContext::Dump();
194 wxDebugContext::PrintStatistics();
196 wxDebugContext::SetStream(NULL
, NULL
);
202 // Static member initialization
203 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
210 m_wantDebugOutput
= TRUE
;
215 m_printMode
= wxPRINT_WINDOWS
;
217 m_printMode
= wxPRINT_POSTSCRIPT
;
219 m_exitOnFrameDelete
= TRUE
;
223 bool wxApp::Initialized()
231 int wxApp::MainLoop()
235 /* TODO: implement your main loop here, calling ProcessIdle in idle time.
238 while (!::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) &&
248 // Returns TRUE if more time is needed.
249 bool wxApp::ProcessIdle()
252 event
.SetEventObject(this);
255 return event
.MoreRequested();
258 void wxApp::ExitMainLoop()
263 // Is a message/event pending?
264 bool wxApp::Pending()
271 // Dispatch a message.
272 void wxApp::Dispatch()
278 void wxApp::OnIdle(wxIdleEvent
& event
)
280 static bool inOnIdle
= FALSE
;
282 // Avoid recursion (via ProcessEvent default case)
288 // 'Garbage' collection of windows deleted with Close().
289 DeletePendingObjects();
291 // flush the logged messages if any
292 wxLog
*pLog
= wxLog::GetActiveTarget();
293 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
296 // Send OnIdle events to all windows
297 bool needMore
= SendIdleEvents();
300 event
.RequestMore(TRUE
);
305 // Send idle event to all top-level windows
306 bool wxApp::SendIdleEvents()
308 bool needMore
= FALSE
;
309 wxNode
* node
= wxTopLevelWindows
.First();
312 wxWindow
* win
= (wxWindow
*) node
->Data();
313 if (SendIdleEvents(win
))
321 // Send idle event to window and all subwindows
322 bool wxApp::SendIdleEvents(wxWindow
* win
)
324 bool needMore
= FALSE
;
327 event
.SetEventObject(win
);
328 win
->ProcessEvent(event
);
330 if (event
.MoreRequested())
333 wxNode
* node
= win
->GetChildren()->First();
336 wxWindow
* win
= (wxWindow
*) node
->Data();
337 if (SendIdleEvents(win
))
345 void wxApp::DeletePendingObjects()
347 wxNode
*node
= wxPendingDelete
.First();
350 wxObject
*obj
= (wxObject
*)node
->Data();
354 if (wxPendingDelete
.Member(obj
))
357 // Deleting one object may have deleted other pending
358 // objects, so start from beginning of list again.
359 node
= wxPendingDelete
.First();
363 wxLog
* wxApp::CreateLogTarget()
368 wxWindow
* wxApp::GetTopWindow() const
372 else if (wxTopLevelWindows
.Number() > 0)
373 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
380 wxApp::CommonCleanUp();
382 * TODO: Exit in some platform-specific way. Not recommended that the app calls this:
383 * only for emergencies.
387 // Yield to other processes