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"
26 #include "../gdk_imlib/gdk_imlib.h"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 wxApp
*wxTheApp
= NULL
;
34 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
36 extern wxList wxPendingDelete
;
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 extern void wxFlushResources(void);
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
55 while (gtk_events_pending() > 0) gtk_main_iteration();
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
63 IMPLEMENT_DYNAMIC_CLASS(wxApp
,wxEvtHandler
)
65 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
66 EVT_IDLE(wxApp::OnIdle
)
69 gint
wxapp_idle_callback( gpointer
WXUNUSED(data
) )
71 if (wxTheApp
) while (wxTheApp
->ProcessIdle()) {};
80 m_exitOnFrameDelete
= TRUE
;
85 gtk_idle_remove( m_idleTag
);
88 bool wxApp::OnInit(void)
93 bool wxApp::OnInitGui(void)
95 m_idleTag
= gtk_idle_add( wxapp_idle_callback
, NULL
);
99 int wxApp::OnRun(void)
104 bool wxApp::ProcessIdle(void)
107 event
.SetEventObject( this );
108 ProcessEvent( event
);
110 return event
.MoreRequested();
113 void wxApp::OnIdle( wxIdleEvent
&event
)
115 static bool inOnIdle
= FALSE
;
117 // Avoid recursion (via ProcessEvent default case)
123 // 'Garbage' collection of windows deleted with Close().
124 DeletePendingObjects();
126 // flush the logged messages if any
127 wxLog
*pLog
= wxLog::GetActiveTarget();
128 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
131 // Send OnIdle events to all windows
132 bool needMore
= SendIdleEvents();
135 event
.RequestMore(TRUE
);
140 bool wxApp::SendIdleEvents(void)
142 bool needMore
= FALSE
;
143 wxNode
* node
= wxTopLevelWindows
.First();
146 wxWindow
* win
= (wxWindow
*) node
->Data();
147 if (SendIdleEvents(win
))
155 bool wxApp::SendIdleEvents( wxWindow
* win
)
157 bool needMore
= FALSE
;
160 event
.SetEventObject(win
);
161 win
->ProcessEvent(event
);
163 if (event
.MoreRequested())
166 wxNode
* node
= win
->GetChildren()->First();
169 wxWindow
* win
= (wxWindow
*) node
->Data();
170 if (SendIdleEvents(win
))
178 int wxApp::OnExit(void)
183 int wxApp::MainLoop(void)
189 void wxApp::ExitMainLoop(void)
194 bool wxApp::Initialized(void)
196 return m_initialized
;
199 bool wxApp::Pending(void)
204 void wxApp::Dispatch(void)
208 void wxApp::DeletePendingObjects(void)
210 wxNode
*node
= wxPendingDelete
.First();
213 wxObject
*obj
= (wxObject
*)node
->Data();
217 if (wxPendingDelete
.Member(obj
))
220 node
= wxPendingDelete
.First();
224 wxWindow
*wxApp::GetTopWindow(void)
226 if (m_topWindow
) return m_topWindow
;
227 wxNode
*node
= wxTopLevelWindows
.First();
228 if (!node
) return NULL
;
229 return (wxWindow
*)node
->Data();
232 void wxApp::SetTopWindow( wxWindow
*win
)
237 void wxApp::CommonInit(void)
242 (void) wxGetResource("wxWindows", "OsVersion", &wxOsVersion);
246 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
247 wxTheColourDatabase
->Initialize();
248 wxInitializeStockObjects();
250 // For PostScript printing
252 wxInitializePrintSetupData();
253 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
254 wxThePrintPaperDatabase
->CreateDatabase();
259 wxBitmap::InitStandardHandlers();
261 g_globalCursor = new wxCursor;
264 wxInitializeStockObjects();
267 void wxApp::CommonCleanUp(void)
269 wxDeleteStockObjects();
274 wxLog
*wxApp::CreateLogTarget()
279 //-----------------------------------------------------------------------------
281 //-----------------------------------------------------------------------------
283 int wxEntry( int argc
, char *argv
[] )
285 wxBuffer
= new char[BUFSIZ
+ 512];
287 wxClassInfo::InitializeClasses();
289 #if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
291 #if !defined(_WINDLL)
292 streambuf
* sBuf
= new wxDebugStreamBuf
;
294 streambuf
* sBuf
= NULL
;
296 ostream
* oStr
= new ostream(sBuf
) ;
297 wxDebugContext::SetStream(oStr
, sBuf
);
303 if (!wxApp::GetInitializerFunction())
305 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
309 wxAppInitializerFunction app_ini
= wxApp::GetInitializerFunction();
311 wxObject
*test_app
= app_ini();
313 wxTheApp
= (wxApp
*) test_app
;
315 // wxTheApp = (wxApp*)( app_ini() );
320 printf( "wxWindows error: wxTheApp == NULL\n" );
324 // printf( "Programmstart.\n" );
326 wxTheApp
->argc
= argc
;
327 wxTheApp
->argv
= argv
;
329 gtk_init( &argc
, &argv
);
335 gtk_widget_push_visual(gdk_imlib_get_visual());
337 gtk_widget_push_colormap(gdk_imlib_get_colormap());
343 wxTheApp
->OnInitGui();
345 // Here frames insert themselves automatically
346 // into wxTopLevelWindows by getting created
349 if (!wxTheApp
->OnInit()) return 0;
351 wxTheApp
->m_initialized
= (wxTopLevelWindows
.Number() > 0);
355 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
357 wxTheApp
->DeletePendingObjects();
361 wxApp::CommonCleanUp();
363 #if (WXDEBUG && USE_MEMORY_TRACING) || USE_DEBUG_CONTEXT
364 // At this point we want to check if there are any memory
365 // blocks that aren't part of the wxDebugContext itself,
366 // as a special case. Then when dumping we need to ignore
367 // wxDebugContext, too.
368 if (wxDebugContext::CountObjectsLeft() > 0)
370 wxTrace("There were memory leaks.\n");
371 wxDebugContext::Dump();
372 wxDebugContext::PrintStatistics();
374 wxDebugContext::SetStream(NULL
, NULL
);
380 //-----------------------------------------------------------------------------
382 //-----------------------------------------------------------------------------
384 #if defined(AIX) || defined(AIX4) || defined(____HPUX__)
386 // main in IMPLEMENT_WX_MAIN in IMPLEMENT_APP in app.h
390 int main(int argc
, char *argv
[]) { return wxEntry(argc
, argv
); }