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"
25 #include "gdk_imlib.h"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 wxApp
*wxTheApp
= NULL
;
33 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
35 extern wxList wxPendingDelete
;
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 extern void wxFlushResources(void);
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
54 while (gtk_events_pending() > 0) gtk_main_iteration();
58 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
62 IMPLEMENT_DYNAMIC_CLASS(wxApp
,wxEvtHandler
)
64 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
65 EVT_IDLE(wxApp::OnIdle
)
68 gint
wxapp_idle_callback( gpointer
WXUNUSED(data
) )
70 if (wxTheApp
) while (wxTheApp
->ProcessIdle()) {};
79 m_exitOnFrameDelete
= TRUE
;
84 gtk_idle_remove( m_idleTag
);
87 bool wxApp::OnInit(void)
92 bool wxApp::OnInitGui(void)
94 m_idleTag
= gtk_idle_add( wxapp_idle_callback
, NULL
);
98 int wxApp::OnRun(void)
103 bool wxApp::ProcessIdle(void)
106 event
.SetEventObject( this );
107 ProcessEvent( event
);
109 return event
.MoreRequested();
112 void wxApp::OnIdle( wxIdleEvent
&event
)
114 static bool inOnIdle
= FALSE
;
116 // Avoid recursion (via ProcessEvent default case)
122 // 'Garbage' collection of windows deleted with Close().
123 DeletePendingObjects();
125 // flush the logged messages if any
126 wxLog
*pLog
= wxLog::GetActiveTarget();
127 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
130 // Send OnIdle events to all windows
131 bool needMore
= SendIdleEvents();
134 event
.RequestMore(TRUE
);
139 bool wxApp::SendIdleEvents(void)
141 bool needMore
= FALSE
;
142 wxNode
* node
= wxTopLevelWindows
.First();
145 wxWindow
* win
= (wxWindow
*) node
->Data();
146 if (SendIdleEvents(win
))
154 bool wxApp::SendIdleEvents( wxWindow
* win
)
156 bool needMore
= FALSE
;
159 event
.SetEventObject(win
);
160 win
->ProcessEvent(event
);
162 if (event
.MoreRequested())
165 wxNode
* node
= win
->GetChildren()->First();
168 wxWindow
* win
= (wxWindow
*) node
->Data();
169 if (SendIdleEvents(win
))
177 int wxApp::OnExit(void)
182 int wxApp::MainLoop(void)
188 void wxApp::ExitMainLoop(void)
193 bool wxApp::Initialized(void)
195 return m_initialized
;
198 bool wxApp::Pending(void)
203 void wxApp::Dispatch(void)
207 void wxApp::DeletePendingObjects(void)
209 wxNode
*node
= wxPendingDelete
.First();
212 wxObject
*obj
= (wxObject
*)node
->Data();
216 if (wxPendingDelete
.Member(obj
))
219 node
= wxPendingDelete
.First();
223 wxWindow
*wxApp::GetTopWindow(void)
225 if (m_topWindow
) return m_topWindow
;
226 wxNode
*node
= wxTopLevelWindows
.First();
227 if (!node
) return NULL
;
228 return (wxWindow
*)node
->Data();
231 void wxApp::SetTopWindow( wxWindow
*win
)
236 void wxApp::CommonInit(void)
241 (void) wxGetResource("wxWindows", "OsVersion", &wxOsVersion);
245 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
246 wxTheColourDatabase
->Initialize();
247 wxInitializeStockObjects();
249 // For PostScript printing
251 wxInitializePrintSetupData();
252 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
253 wxThePrintPaperDatabase
->CreateDatabase();
258 wxBitmap::InitStandardHandlers();
260 g_globalCursor = new wxCursor;
263 wxInitializeStockObjects();
266 void wxApp::CommonCleanUp(void)
268 wxDeleteStockObjects();
273 wxLog
*wxApp::CreateLogTarget()
278 //-----------------------------------------------------------------------------
280 //-----------------------------------------------------------------------------
282 int wxEntry( int argc
, char *argv
[] )
284 wxBuffer
= new char[BUFSIZ
+ 512];
286 wxClassInfo::InitializeClasses();
290 if (!wxApp::GetInitializerFunction())
292 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
296 wxAppInitializerFunction app_ini
= wxApp::GetInitializerFunction();
298 wxObject
*test_app
= app_ini();
300 wxTheApp
= (wxApp
*) test_app
;
302 // wxTheApp = (wxApp*)( app_ini() );
307 printf( "wxWindows error: wxTheApp == NULL\n" );
311 // printf( "Programmstart.\n" );
313 wxTheApp
->argc
= argc
;
314 wxTheApp
->argv
= argv
;
316 gtk_init( &argc
, &argv
);
322 gtk_widget_push_visual(gdk_imlib_get_visual());
324 gtk_widget_push_colormap(gdk_imlib_get_colormap());
330 wxTheApp
->OnInitGui();
332 // Here frames insert themselves automatically
333 // into wxTopLevelWindows by getting created
336 if (!wxTheApp
->OnInit()) return 0;
338 wxTheApp
->m_initialized
= (wxTopLevelWindows
.Number() > 0);
342 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
344 wxTheApp
->DeletePendingObjects();
348 wxApp::CommonCleanUp();
353 //-----------------------------------------------------------------------------
355 //-----------------------------------------------------------------------------
357 #if defined(AIX) || defined(AIX4) || defined(____HPUX__)
359 // main in IMPLEMENT_WX_MAIN in IMPLEMENT_APP in app.h
363 int main(int argc
, char *argv
[]) { return wxEntry(argc
, argv
); }