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 gint
wxapp_idle_callback( gpointer
WXUNUSED(data
) )
66 if (wxTheApp
) wxTheApp
->OnIdle();
75 m_exitOnFrameDelete
= TRUE
;
80 gtk_idle_remove( m_idleTag
);
83 bool wxApp::OnInit(void)
88 bool wxApp::OnInitGui(void)
90 m_idleTag
= gtk_idle_add( wxapp_idle_callback
, NULL
);
94 int wxApp::OnRun(void)
99 bool wxApp::OnIdle(void)
101 DeletePendingObjects();
105 int wxApp::OnExit(void)
110 int wxApp::MainLoop(void)
116 void wxApp::ExitMainLoop(void)
121 bool wxApp::Initialized(void)
123 return m_initialized
;
126 bool wxApp::Pending(void)
131 void wxApp::Dispatch(void)
135 void wxApp::DeletePendingObjects(void)
137 wxNode
*node
= wxPendingDelete
.First();
140 wxObject
*obj
= (wxObject
*)node
->Data();
144 if (wxPendingDelete
.Member(obj
))
147 node
= wxPendingDelete
.First();
151 wxWindow
*wxApp::GetTopWindow(void)
153 if (m_topWindow
) return m_topWindow
;
154 wxNode
*node
= wxTopLevelWindows
.First();
155 if (!node
) return NULL
;
156 return (wxWindow
*)node
->Data();
159 void wxApp::SetTopWindow( wxWindow
*win
)
164 void wxApp::CommonInit(void)
169 (void) wxGetResource("wxWindows", "OsVersion", &wxOsVersion);
173 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
174 wxTheColourDatabase
->Initialize();
175 wxInitializeStockObjects();
177 // For PostScript printing
179 wxInitializePrintSetupData();
180 wxThePrintPaperDatabase
= new wxPrintPaperDatabase
;
181 wxThePrintPaperDatabase
->CreateDatabase();
186 wxBitmap::InitStandardHandlers();
188 g_globalCursor = new wxCursor;
191 wxInitializeStockObjects();
194 void wxApp::CommonCleanUp(void)
196 wxDeleteStockObjects();
201 wxLog
*wxApp::CreateLogTarget()
206 //-----------------------------------------------------------------------------
208 //-----------------------------------------------------------------------------
210 int wxEntry( int argc
, char *argv
[] )
212 wxBuffer
= new char[BUFSIZ
+ 512];
214 wxClassInfo::InitializeClasses();
218 if (!wxApp::GetInitializerFunction())
220 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
224 wxAppInitializerFunction app_ini
= wxApp::GetInitializerFunction();
226 wxObject
*test_app
= app_ini();
228 wxTheApp
= (wxApp
*) test_app
;
230 // wxTheApp = (wxApp*)( app_ini() );
235 printf( "wxWindows error: wxTheApp == NULL\n" );
239 // printf( "Programmstart.\n" );
241 wxTheApp
->argc
= argc
;
242 wxTheApp
->argv
= argv
;
244 gtk_init( &argc
, &argv
);
250 gtk_widget_push_visual(gdk_imlib_get_visual());
252 gtk_widget_push_colormap(gdk_imlib_get_colormap());
258 wxTheApp
->OnInitGui();
260 // Here frames insert themselves automatically
261 // into wxTopLevelWindows by getting created
264 if (!wxTheApp
->OnInit()) return 0;
266 wxTheApp
->m_initialized
= (wxTopLevelWindows
.Number() > 0);
270 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
272 wxTheApp
->DeletePendingObjects();
276 wxApp::CommonCleanUp();