1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "app.h"
16 #include "wx/gdicmn.h"
18 #include "wx/postscrp.h"
21 #include "wx/memory.h"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 wxApp
*wxTheApp
= NULL
;
30 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
32 extern wxList wxPendingDelete
;
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 extern void wxFlushResources(void);
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
57 IMPLEMENT_DYNAMIC_CLASS(wxApp
,wxEvtHandler
)
59 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
60 EVT_IDLE(wxApp::OnIdle
)
66 m_exitOnFrameDelete
= TRUE
;
73 bool wxApp::OnInit(void)
78 bool wxApp::OnInitGui(void)
83 int wxApp::OnRun(void)
88 bool wxApp::ProcessIdle(void)
91 event
.SetEventObject( this );
92 ProcessEvent( event
);
94 return event
.MoreRequested();
97 void wxApp::OnIdle( wxIdleEvent
&event
)
99 static bool inOnIdle
= FALSE
;
101 // Avoid recursion (via ProcessEvent default case)
107 // 'Garbage' collection of windows deleted with Close().
108 DeletePendingObjects();
110 // flush the logged messages if any
111 wxLog
*pLog
= wxLog::GetActiveTarget();
112 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
115 // Send OnIdle events to all windows
116 bool needMore
= SendIdleEvents();
119 event
.RequestMore(TRUE
);
124 bool wxApp::SendIdleEvents(void)
126 bool needMore
= FALSE
;
127 wxNode
* node
= wxTopLevelWindows
.First();
130 wxWindow
* win
= (wxWindow
*) node
->Data();
131 if (SendIdleEvents(win
))
139 bool wxApp::SendIdleEvents( wxWindow
* win
)
141 bool needMore
= FALSE
;
144 event
.SetEventObject(win
);
145 win
->ProcessEvent(event
);
147 if (event
.MoreRequested())
150 wxNode
* node
= win
->GetChildren()->First();
153 wxWindow
* win
= (wxWindow
*) node
->Data();
154 if (SendIdleEvents(win
))
162 int wxApp::OnExit(void)
167 int wxApp::MainLoop(void)
172 void wxApp::ExitMainLoop(void)
176 bool wxApp::Initialized(void)
178 return m_initialized
;
181 bool wxApp::Pending(void)
186 void wxApp::Dispatch(void)
190 void wxApp::DeletePendingObjects(void)
192 wxNode
*node
= wxPendingDelete
.First();
195 wxObject
*obj
= (wxObject
*)node
->Data();
199 if (wxPendingDelete
.Member(obj
))
202 node
= wxPendingDelete
.First();
206 wxWindow
*wxApp::GetTopWindow(void)
208 if (m_topWindow
) return m_topWindow
;
209 wxNode
*node
= wxTopLevelWindows
.First();
210 if (!node
) return NULL
;
211 return (wxWindow
*)node
->Data();
214 void wxApp::SetTopWindow( wxWindow
*win
)
219 void wxApp::CommonInit(void)
224 (void) wxGetResource("wxWindows", "OsVersion", &wxOsVersion);
228 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
229 wxTheColourDatabase
->Initialize();
230 wxInitializeStockObjects();
232 // For PostScript printing
234 wxInitializePrintSetupData();
235 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
236 wxThePrintPaperDatabase
->CreateDatabase();
241 wxBitmap::InitStandardHandlers();
243 g_globalCursor = new wxCursor;
246 wxInitializeStockObjects();
249 void wxApp::CommonCleanUp(void)
251 wxDeleteStockObjects();
256 wxLog
*wxApp::CreateLogTarget()
261 //-----------------------------------------------------------------------------
263 //-----------------------------------------------------------------------------
265 int wxEntry( int argc
, char *argv
[] )
267 wxBuffer
= new char[BUFSIZ
+ 512];
269 wxClassInfo::InitializeClasses();
271 #if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
273 #if !defined(_WINDLL)
274 streambuf
* sBuf
= new wxDebugStreamBuf
;
276 streambuf
* sBuf
= NULL
;
278 ostream
* oStr
= new ostream(sBuf
) ;
279 wxDebugContext::SetStream(oStr
, sBuf
);
285 if (!wxApp::GetInitializerFunction())
287 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
291 wxAppInitializerFunction app_ini
= wxApp::GetInitializerFunction();
293 wxObject
*test_app
= app_ini();
295 wxTheApp
= (wxApp
*) test_app
;
297 // wxTheApp = (wxApp*)( app_ini() );
302 printf( "wxWindows error: wxTheApp == NULL\n" );
306 // printf( "Programmstart.\n" );
308 wxTheApp
->argc
= argc
;
309 wxTheApp
->argv
= argv
;
311 // Your init here !!!!
315 wxTheApp
->OnInitGui();
317 // Here frames insert themselves automatically
318 // into wxTopLevelWindows by getting created
321 if (!wxTheApp
->OnInit()) return 0;
323 wxTheApp
->m_initialized
= (wxTopLevelWindows
.Number() > 0);
327 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
329 wxTheApp
->DeletePendingObjects();
333 wxApp::CommonCleanUp();
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)
342 wxTrace("There were memory leaks.\n");
343 wxDebugContext::Dump();
344 wxDebugContext::PrintStatistics();
346 wxDebugContext::SetStream(NULL
, NULL
);
352 //-----------------------------------------------------------------------------
354 //-----------------------------------------------------------------------------
356 #if defined(AIX) || defined(AIX4) || defined(____HPUX__)
358 // main in IMPLEMENT_WX_MAIN in IMPLEMENT_APP in app.h
362 int main(int argc
, char *argv
[]) { return wxEntry(argc
, argv
); }