]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/app.cpp
App declarations modified; cursor was corrupt; needed to add PostScript-related variable.
[wxWidgets.git] / src / gtk1 / app.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: app.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Created: 01/02/97
6 // Id:
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "app.h"
13 #endif
14
15 #include "wx/app.h"
16 #include "wx/gdicmn.h"
17 #include "wx/utils.h"
18 #include "wx/postscrp.h"
19 #include "wx/intl.h"
20 #include "wx/log.h"
21
22 #include "unistd.h"
23
24 #ifdef USE_GDK_IMLIB
25 #include "gdk_imlib.h"
26 #endif
27
28 //-----------------------------------------------------------------------------
29 // global data
30 //-----------------------------------------------------------------------------
31
32 wxApp *wxTheApp = NULL;
33 wxAppInitializerFunction wxApp::m_appInitFn = (wxAppInitializerFunction) NULL;
34
35 extern wxList wxPendingDelete;
36
37 //-----------------------------------------------------------------------------
38 // local functions
39 //-----------------------------------------------------------------------------
40
41 extern void wxFlushResources(void);
42
43 //-----------------------------------------------------------------------------
44 // global functions
45 //-----------------------------------------------------------------------------
46
47 void wxExit(void)
48 {
49 gtk_main_quit();
50 };
51
52 bool wxYield(void)
53 {
54 while (gtk_events_pending() > 0) gtk_main_iteration();
55 return TRUE;
56 };
57
58 //-----------------------------------------------------------------------------
59 // wxApp
60 //-----------------------------------------------------------------------------
61
62 IMPLEMENT_DYNAMIC_CLASS(wxApp,wxEvtHandler)
63
64 gint wxapp_idle_callback( gpointer WXUNUSED(data) )
65 {
66 if (wxTheApp) wxTheApp->OnIdle();
67 usleep( 10000 );
68 return TRUE;
69 };
70
71 wxApp::wxApp()
72 {
73 m_idleTag = 0;
74 m_topWindow = NULL;
75 m_exitOnFrameDelete = TRUE;
76 };
77
78 wxApp::~wxApp(void)
79 {
80 gtk_idle_remove( m_idleTag );
81 };
82
83 bool wxApp::OnInit(void)
84 {
85 return TRUE;
86 };
87
88 bool wxApp::OnInitGui(void)
89 {
90 m_idleTag = gtk_idle_add( wxapp_idle_callback, NULL );
91 return TRUE;
92 };
93
94 int wxApp::OnRun(void)
95 {
96 return MainLoop();
97 };
98
99 bool wxApp::OnIdle(void)
100 {
101 DeletePendingObjects();
102 return FALSE;
103 };
104
105 int wxApp::OnExit(void)
106 {
107 return 0;
108 };
109
110 int wxApp::MainLoop(void)
111 {
112 gtk_main();
113 return 0;
114 };
115
116 void wxApp::ExitMainLoop(void)
117 {
118 gtk_main_quit();
119 };
120
121 bool wxApp::Initialized(void)
122 {
123 return m_initialized;
124 };
125
126 bool wxApp::Pending(void)
127 {
128 return FALSE;
129 };
130
131 void wxApp::Dispatch(void)
132 {
133 };
134
135 void wxApp::DeletePendingObjects(void)
136 {
137 wxNode *node = wxPendingDelete.First();
138 while (node)
139 {
140 wxObject *obj = (wxObject *)node->Data();
141
142 delete obj;
143
144 if (wxPendingDelete.Member(obj))
145 delete node;
146
147 node = wxPendingDelete.First();
148 };
149 };
150
151 wxWindow *wxApp::GetTopWindow(void)
152 {
153 if (m_topWindow) return m_topWindow;
154 wxNode *node = wxTopLevelWindows.First();
155 if (!node) return NULL;
156 return (wxWindow*)node->Data();
157 };
158
159 void wxApp::SetTopWindow( wxWindow *win )
160 {
161 m_topWindow = win;
162 };
163
164 void wxApp::CommonInit(void)
165 {
166
167 /*
168 #if USE_RESOURCES
169 (void) wxGetResource("wxWindows", "OsVersion", &wxOsVersion);
170 #endif
171 */
172
173 wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
174 wxTheColourDatabase->Initialize();
175 wxInitializeStockObjects();
176
177 // For PostScript printing
178 #if USE_POSTSCRIPT
179 wxInitializePrintSetupData();
180 wxThePrintPaperDatabase = new wxPrintPaperDatabase;
181 wxThePrintPaperDatabase->CreateDatabase();
182 #endif
183
184
185 /*
186 wxBitmap::InitStandardHandlers();
187
188 g_globalCursor = new wxCursor;
189 */
190
191 wxInitializeStockObjects();
192 };
193
194 void wxApp::CommonCleanUp(void)
195 {
196 wxDeleteStockObjects();
197
198 wxFlushResources();
199 };
200
201 wxLog *wxApp::CreateLogTarget()
202 {
203 return new wxLogGui;
204 }
205
206 //-----------------------------------------------------------------------------
207 // wxEntry
208 //-----------------------------------------------------------------------------
209
210 int wxEntry( int argc, char *argv[] )
211 {
212 wxBuffer = new char[BUFSIZ + 512];
213
214 wxClassInfo::InitializeClasses();
215
216 if (!wxTheApp)
217 {
218 if (!wxApp::GetInitializerFunction())
219 {
220 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
221 return 0;
222 };
223
224 wxAppInitializerFunction app_ini = wxApp::GetInitializerFunction();
225
226 wxObject *test_app = app_ini();
227
228 wxTheApp = (wxApp*) test_app;
229
230 // wxTheApp = (wxApp*)( app_ini() );
231 };
232
233 if (!wxTheApp)
234 {
235 printf( "wxWindows error: wxTheApp == NULL\n" );
236 return 0;
237 };
238
239 // printf( "Programmstart.\n" );
240
241 wxTheApp->argc = argc;
242 wxTheApp->argv = argv;
243
244 gtk_init( &argc, &argv );
245
246 #ifdef USE_GDK_IMLIB
247
248 gdk_imlib_init();
249
250 gtk_widget_push_visual(gdk_imlib_get_visual());
251
252 gtk_widget_push_colormap(gdk_imlib_get_colormap());
253
254 #endif
255
256 wxApp::CommonInit();
257
258 wxTheApp->OnInitGui();
259
260 // Here frames insert themselves automatically
261 // into wxTopLevelWindows by getting created
262 // in OnInit().
263
264 if (!wxTheApp->OnInit()) return 0;
265
266 wxTheApp->m_initialized = (wxTopLevelWindows.Number() > 0);
267
268 int retValue = 0;
269
270 if (wxTheApp->Initialized()) retValue = wxTheApp->OnRun();
271
272 wxTheApp->DeletePendingObjects();
273
274 wxTheApp->OnExit();
275
276 wxApp::CommonCleanUp();
277
278 return retValue;
279 };