]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
88a7a4e1 | 2 | // Name: src/gtk1/app.cpp |
c801d85f KB |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
32e9da8b | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling, Julian Smart |
65571936 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
f3858bf5 JJ |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
c801d85f | 13 | #include "wx/app.h" |
88a7a4e1 WS |
14 | |
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/intl.h" | |
e4db172a | 17 | #include "wx/log.h" |
de6185e2 | 18 | #include "wx/utils.h" |
fdf565fe | 19 | #include "wx/dialog.h" |
9eddec69 | 20 | #include "wx/settings.h" |
246c5004 | 21 | #include "wx/msgdlg.h" |
5b56bffb | 22 | #include "wx/memory.h" |
48a1108e | 23 | #include "wx/font.h" |
dd05139a | 24 | #include "wx/gdicmn.h" |
155ecd4c | 25 | #include "wx/image.h" |
02761f6c | 26 | #include "wx/module.h" |
88a7a4e1 WS |
27 | #endif |
28 | ||
b1ac3b56 | 29 | #include "wx/file.h" |
2b5f62a0 | 30 | #include "wx/filename.h" |
fe593cc5 | 31 | #include "wx/thread.h" |
afb74891 | 32 | |
62be94e1 RR |
33 | #ifdef __WXGPE__ |
34 | #include <gpe/init.h> | |
35 | #endif | |
36 | ||
df028524 VS |
37 | #ifdef __WXUNIVERSAL__ |
38 | #include "wx/univ/theme.h" | |
39 | #include "wx/univ/renderer.h" | |
40 | #endif | |
41 | ||
91b8de8d | 42 | #if wxUSE_THREADS |
a37a5a73 | 43 | #include "wx/thread.h" |
91b8de8d | 44 | #endif |
afb74891 | 45 | |
20e05ffb | 46 | #include <unistd.h> |
2b5f62a0 VZ |
47 | |
48 | #ifdef HAVE_POLL | |
49 | #if defined(__VMS) | |
50 | #include <poll.h> | |
51 | #else | |
52 | // bug in the OpenBSD headers: at least in 3.1 there is no extern "C" | |
53 | // in neither poll.h nor sys/poll.h which results in link errors later | |
54 | #ifdef __OPENBSD__ | |
55 | extern "C" | |
56 | { | |
57 | #endif | |
58 | ||
59 | #include <sys/poll.h> | |
60 | ||
61 | #ifdef __OPENBSD__ | |
62 | }; | |
63 | #endif | |
64 | #endif // platform | |
65 | #else // !HAVE_POLL | |
66 | // we implement poll() ourselves using select() which is supposed exist in | |
67 | // all modern Unices | |
68 | #include <sys/types.h> | |
69 | #include <sys/time.h> | |
70 | #include <unistd.h> | |
bc023abb MW |
71 | #ifdef HAVE_SYS_SELECT_H |
72 | #include <sys/select.h> | |
73 | #endif | |
2b5f62a0 VZ |
74 | #endif // HAVE_POLL/!HAVE_POLL |
75 | ||
17a1ebd1 | 76 | #include "wx/unix/private.h" |
3cbab641 | 77 | #include "wx/gtk1/win_gtk.h" |
c801d85f | 78 | |
20e05ffb | 79 | #include <gtk/gtk.h> |
24178e4a | 80 | |
c801d85f KB |
81 | //----------------------------------------------------------------------------- |
82 | // global data | |
83 | //----------------------------------------------------------------------------- | |
84 | ||
de6185e2 | 85 | bool g_mainThreadLocked = false; |
96997d65 | 86 | gint g_pendingTag = 0; |
3ac8d3bc | 87 | |
d3b9f782 | 88 | static GtkWidget *gs_RootWindow = NULL; |
d76fe38b | 89 | |
c801d85f | 90 | //----------------------------------------------------------------------------- |
3133cb9f | 91 | // idle system |
c801d85f KB |
92 | //----------------------------------------------------------------------------- |
93 | ||
3133cb9f | 94 | extern bool g_isIdle; |
c4fda16b | 95 | |
90350682 | 96 | void wxapp_install_idle_handler(); |
bf9e3e73 | 97 | |
fe593cc5 VS |
98 | #if wxUSE_THREADS |
99 | static wxMutex gs_idleTagsMutex; | |
100 | #endif | |
101 | ||
acfd422a | 102 | |
bf9e3e73 RR |
103 | //----------------------------------------------------------------------------- |
104 | // wxWakeUpIdle | |
105 | //----------------------------------------------------------------------------- | |
106 | ||
19722331 KH |
107 | // RR/KH: The wxMutexGui calls are not needed on GTK2 according to |
108 | // the GTK faq, http://www.gtk.org/faq/#AEN500 | |
109 | // The calls to gdk_threads_enter() and leave() are specifically noted | |
110 | // as not being necessary. The MutexGui calls are still left in for GTK1. | |
111 | // Eliminating the MutexGui calls fixes the long-standing "random" lockup | |
112 | // when using wxPostEvent (which calls WakeUpIdle) from a thread. | |
113 | ||
e2478fde | 114 | void wxApp::WakeUpIdle() |
bf9e3e73 | 115 | { |
924ef850 RR |
116 | #if wxUSE_THREADS |
117 | if (!wxThread::IsMain()) | |
ce6d2511 | 118 | wxMutexGuiEnter(); |
b0f76951 | 119 | #endif // wxUSE_THREADS |
924ef850 | 120 | |
c263eb03 | 121 | wxapp_install_idle_handler(); |
2286341c | 122 | |
924ef850 RR |
123 | #if wxUSE_THREADS |
124 | if (!wxThread::IsMain()) | |
ce6d2511 | 125 | wxMutexGuiLeave(); |
b0f76951 | 126 | #endif // wxUSE_THREADS |
bf9e3e73 RR |
127 | } |
128 | ||
129 | //----------------------------------------------------------------------------- | |
130 | // local functions | |
131 | //----------------------------------------------------------------------------- | |
132 | ||
90350682 VZ |
133 | // the callback functions must be extern "C" to comply with GTK+ declarations |
134 | extern "C" | |
135 | { | |
136 | ||
3133cb9f | 137 | static gint wxapp_pending_callback( gpointer WXUNUSED(data) ) |
acfd422a RR |
138 | { |
139 | if (!wxTheApp) return TRUE; | |
c2fa61e8 | 140 | |
5375a1f5 | 141 | // When getting called from GDK's time-out handler |
96997d65 | 142 | // we are no longer within GDK's grab on the GUI |
5375a1f5 | 143 | // thread so we must lock it here ourselves. |
96997d65 RR |
144 | gdk_threads_enter(); |
145 | ||
5375a1f5 | 146 | // Sent idle event to all who request them. |
96997d65 | 147 | wxTheApp->ProcessPendingEvents(); |
e90c1d2a | 148 | |
fe593cc5 VS |
149 | { |
150 | #if wxUSE_THREADS | |
151 | wxMutexLocker lock(gs_idleTagsMutex); | |
152 | #endif | |
153 | g_pendingTag = 0; | |
154 | } | |
96997d65 | 155 | |
5375a1f5 | 156 | // Flush the logged messages if any. |
1b2dab34 RR |
157 | #if wxUSE_LOG |
158 | wxLog::FlushActive(); | |
159 | #endif // wxUSE_LOG | |
160 | ||
96997d65 RR |
161 | // Release lock again |
162 | gdk_threads_leave(); | |
163 | ||
164 | // Return FALSE to indicate that no more idle events are | |
165 | // to be sent (single shot instead of continuous stream) | |
166 | return FALSE; | |
167 | } | |
168 | ||
3133cb9f | 169 | static gint wxapp_idle_callback( gpointer WXUNUSED(data) ) |
96997d65 | 170 | { |
a5f1fd3e VZ |
171 | if (!wxTheApp) |
172 | return TRUE; | |
173 | ||
657a8a35 | 174 | #if wxDEBUG_LEVEL |
6d477bb4 VZ |
175 | // don't generate the idle events while the assert modal dialog is shown, |
176 | // this completely confuses the apps which don't expect to be reentered | |
177 | // from some safely-looking functions | |
a5f1fd3e VZ |
178 | if ( wxTheApp->IsInAssert() ) |
179 | { | |
94a6f0f8 JS |
180 | // But repaint the assertion message if necessary |
181 | if (wxTopLevelWindows.GetCount() > 0) | |
182 | { | |
b1d4dd7a | 183 | wxWindow* win = (wxWindow*) wxTopLevelWindows.GetLast()->GetData(); |
94a6f0f8 JS |
184 | if (win->IsKindOf(CLASSINFO(wxGenericMessageDialog))) |
185 | win->OnInternalIdle(); | |
186 | } | |
6d477bb4 | 187 | return TRUE; |
a5f1fd3e | 188 | } |
657a8a35 | 189 | #endif // wxDEBUG_LEVEL |
c2fa61e8 | 190 | |
5375a1f5 | 191 | // When getting called from GDK's time-out handler |
924ef850 | 192 | // we are no longer within GDK's grab on the GUI |
5375a1f5 | 193 | // thread so we must lock it here ourselves. |
924ef850 | 194 | gdk_threads_enter(); |
094637f6 | 195 | |
5375a1f5 RR |
196 | // Indicate that we are now in idle mode and event handlers |
197 | // will have to reinstall the idle handler again. | |
fe593cc5 VS |
198 | { |
199 | #if wxUSE_THREADS | |
200 | wxMutexLocker lock(gs_idleTagsMutex); | |
201 | #endif | |
202 | g_isIdle = TRUE; | |
203 | wxTheApp->m_idleTag = 0; | |
204 | } | |
094637f6 | 205 | |
3133cb9f | 206 | // Send idle event to all who request them as long as |
5375a1f5 RR |
207 | // no events have popped up in the event queue. |
208 | while (wxTheApp->ProcessIdle() && (gtk_events_pending() == 0)) | |
6d477bb4 | 209 | ; |
c9e35272 | 210 | |
96997d65 | 211 | // Release lock again |
924ef850 | 212 | gdk_threads_leave(); |
acfd422a | 213 | |
96997d65 | 214 | // Return FALSE to indicate that no more idle events are |
5375a1f5 | 215 | // to be sent (single shot instead of continuous stream). |
96997d65 | 216 | return FALSE; |
acfd422a | 217 | } |
8801832d | 218 | |
90350682 VZ |
219 | #if wxUSE_THREADS |
220 | ||
2b5f62a0 VZ |
221 | #ifdef HAVE_POLL |
222 | #define wxPoll poll | |
223 | #define wxPollFd pollfd | |
224 | #else // !HAVE_POLL | |
225 | ||
226 | typedef GPollFD wxPollFd; | |
227 | ||
228 | int wxPoll(wxPollFd *ufds, unsigned int nfds, int timeout) | |
229 | { | |
230 | // convert timeout from ms to struct timeval (s/us) | |
231 | timeval tv_timeout; | |
232 | tv_timeout.tv_sec = timeout/1000; | |
233 | tv_timeout.tv_usec = (timeout%1000)*1000; | |
234 | ||
235 | // remember the highest fd used here | |
236 | int fdMax = -1; | |
237 | ||
238 | // and fill the sets for select() | |
239 | fd_set readfds; | |
240 | fd_set writefds; | |
241 | fd_set exceptfds; | |
17a1ebd1 VZ |
242 | wxFD_ZERO(&readfds); |
243 | wxFD_ZERO(&writefds); | |
244 | wxFD_ZERO(&exceptfds); | |
2b5f62a0 VZ |
245 | |
246 | unsigned int i; | |
247 | for ( i = 0; i < nfds; i++ ) | |
248 | { | |
9a83f860 | 249 | wxASSERT_MSG( ufds[i].fd < FD_SETSIZE, wxT("fd out of range") ); |
2b5f62a0 VZ |
250 | |
251 | if ( ufds[i].events & G_IO_IN ) | |
17a1ebd1 | 252 | wxFD_SET(ufds[i].fd, &readfds); |
2b5f62a0 VZ |
253 | |
254 | if ( ufds[i].events & G_IO_PRI ) | |
17a1ebd1 | 255 | wxFD_SET(ufds[i].fd, &exceptfds); |
2b5f62a0 VZ |
256 | |
257 | if ( ufds[i].events & G_IO_OUT ) | |
17a1ebd1 | 258 | wxFD_SET(ufds[i].fd, &writefds); |
2b5f62a0 VZ |
259 | |
260 | if ( ufds[i].fd > fdMax ) | |
261 | fdMax = ufds[i].fd; | |
262 | } | |
263 | ||
264 | fdMax++; | |
265 | int res = select(fdMax, &readfds, &writefds, &exceptfds, &tv_timeout); | |
266 | ||
267 | // translate the results back | |
268 | for ( i = 0; i < nfds; i++ ) | |
269 | { | |
270 | ufds[i].revents = 0; | |
271 | ||
17a1ebd1 | 272 | if ( wxFD_ISSET(ufds[i].fd, &readfds ) ) |
2b5f62a0 VZ |
273 | ufds[i].revents |= G_IO_IN; |
274 | ||
17a1ebd1 | 275 | if ( wxFD_ISSET(ufds[i].fd, &exceptfds ) ) |
2b5f62a0 VZ |
276 | ufds[i].revents |= G_IO_PRI; |
277 | ||
17a1ebd1 | 278 | if ( wxFD_ISSET(ufds[i].fd, &writefds ) ) |
2b5f62a0 VZ |
279 | ufds[i].revents |= G_IO_OUT; |
280 | } | |
281 | ||
282 | return res; | |
283 | } | |
284 | ||
285 | #endif // HAVE_POLL/!HAVE_POLL | |
286 | ||
3133cb9f | 287 | static gint wxapp_poll_func( GPollFD *ufds, guint nfds, gint timeout ) |
acfd422a | 288 | { |
90350682 | 289 | gdk_threads_enter(); |
7b90a8f2 | 290 | |
90350682 | 291 | wxMutexGuiLeave(); |
de6185e2 | 292 | g_mainThreadLocked = true; |
7941ba11 | 293 | |
2b5f62a0 VZ |
294 | // we rely on the fact that glib GPollFD struct is really just pollfd but |
295 | // I wonder how wise is this in the long term (VZ) | |
296 | gint res = wxPoll( (wxPollFd *) ufds, nfds, timeout ); | |
90350682 | 297 | |
90350682 | 298 | wxMutexGuiEnter(); |
de6185e2 | 299 | g_mainThreadLocked = false; |
90350682 | 300 | |
90350682 VZ |
301 | gdk_threads_leave(); |
302 | ||
3133cb9f | 303 | return res; |
ff7b1510 | 304 | } |
c801d85f | 305 | |
90350682 VZ |
306 | #endif // wxUSE_THREADS |
307 | ||
308 | } // extern "C" | |
309 | ||
3133cb9f | 310 | void wxapp_install_idle_handler() |
b453e1b2 | 311 | { |
fe593cc5 VS |
312 | #if wxUSE_THREADS |
313 | wxMutexLocker lock(gs_idleTagsMutex); | |
314 | #endif | |
315 | ||
c263eb03 VS |
316 | // Don't install the handler if it's already installed. This test *MUST* |
317 | // be done when gs_idleTagsMutex is locked! | |
318 | if (!g_isIdle) | |
319 | return; | |
320 | ||
e8617760 GD |
321 | // GD: this assert is raised when using the thread sample (which works) |
322 | // so the test is probably not so easy. Can widget callbacks be | |
323 | // triggered from child threads and, if so, for which widgets? | |
324 | // wxASSERT_MSG( wxThread::IsMain() || gs_WakeUpIdle, wxT("attempt to install idle handler from widget callback in child thread (should be exclusively from wxWakeUpIdle)") ); | |
d5f3e1eb | 325 | |
3133cb9f | 326 | wxASSERT_MSG( wxTheApp->m_idleTag == 0, wxT("attempt to install idle handler twice") ); |
c2fa61e8 | 327 | |
de6185e2 | 328 | g_isIdle = false; |
96997d65 | 329 | |
3133cb9f RR |
330 | if (g_pendingTag == 0) |
331 | g_pendingTag = gtk_idle_add_priority( 900, wxapp_pending_callback, (gpointer) NULL ); | |
e90c1d2a | 332 | |
3133cb9f RR |
333 | // This routine gets called by all event handlers |
334 | // indicating that the idle is over. It may also | |
335 | // get called from other thread for sending events | |
336 | // to the main thread (and processing these in | |
337 | // idle time). Very low priority. | |
338 | wxTheApp->m_idleTag = gtk_idle_add_priority( 1000, wxapp_idle_callback, (gpointer) NULL ); | |
b453e1b2 RR |
339 | } |
340 | ||
960b1f94 VS |
341 | static bool wxOKlibc() |
342 | { | |
343 | #if defined(__UNIX__) && defined(__GLIBC__) | |
344 | // glibc 2.0 uses UTF-8 even when it shouldn't | |
345 | wchar_t res = 0; | |
346 | if ((MB_CUR_MAX == 2) && | |
347 | (wxMB2WC(&res, "\xdd\xa5", 1) == 1) && | |
348 | (res==0x765)) | |
349 | { | |
350 | // this is UTF-8 allright, check whether that's what we want | |
351 | char *cur_locale = setlocale(LC_CTYPE, NULL); | |
352 | if ((strlen(cur_locale) < 4) || | |
353 | (strcasecmp(cur_locale + strlen(cur_locale) - 4, "utf8")) || | |
354 | (strcasecmp(cur_locale + strlen(cur_locale) - 5, "utf-8"))) { | |
355 | // nope, don't use libc conversion | |
356 | return false; | |
357 | } | |
358 | } | |
359 | #endif | |
360 | return true; | |
361 | } | |
362 | ||
005f5d18 RR |
363 | //----------------------------------------------------------------------------- |
364 | // Access to the root window global | |
365 | //----------------------------------------------------------------------------- | |
366 | ||
367 | GtkWidget* wxGetRootWindow() | |
368 | { | |
369 | if (gs_RootWindow == NULL) | |
370 | { | |
371 | gs_RootWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL ); | |
372 | gtk_widget_realize( gs_RootWindow ); | |
373 | } | |
374 | return gs_RootWindow; | |
375 | } | |
376 | ||
c801d85f KB |
377 | //----------------------------------------------------------------------------- |
378 | // wxApp | |
379 | //----------------------------------------------------------------------------- | |
380 | ||
381 | IMPLEMENT_DYNAMIC_CLASS(wxApp,wxEvtHandler) | |
382 | ||
c801d85f KB |
383 | wxApp::wxApp() |
384 | { | |
de6185e2 | 385 | m_isInAssert = false; |
a5f1fd3e | 386 | |
df5ddbca | 387 | m_idleTag = 0; |
c263eb03 | 388 | g_isIdle = TRUE; |
df5ddbca | 389 | wxapp_install_idle_handler(); |
094637f6 | 390 | |
6b3eb77a | 391 | #if wxUSE_THREADS |
3133cb9f | 392 | g_main_set_poll_func( wxapp_poll_func ); |
6b3eb77a | 393 | #endif |
60acb947 | 394 | |
f6fcbb63 | 395 | m_colorCube = (unsigned char*) NULL; |
be88a6ad | 396 | |
a6f5aa49 | 397 | // this is NULL for a "regular" wxApp, but is set (and freed) by a wxGLApp |
d3b9f782 VZ |
398 | m_glVisualInfo = NULL; |
399 | m_glFBCInfo = NULL; | |
ff7b1510 | 400 | } |
c801d85f | 401 | |
60acb947 | 402 | wxApp::~wxApp() |
c801d85f | 403 | { |
acfd422a | 404 | if (m_idleTag) gtk_idle_remove( m_idleTag ); |
60acb947 | 405 | |
f6fcbb63 | 406 | if (m_colorCube) free(m_colorCube); |
ff7b1510 | 407 | } |
c801d85f | 408 | |
0d2a2b60 | 409 | bool wxApp::OnInitGui() |
c801d85f | 410 | { |
1e6feb95 | 411 | if ( !wxAppBase::OnInitGui() ) |
de6185e2 | 412 | return false; |
1e6feb95 | 413 | |
b134516c RR |
414 | GdkVisual *visual = gdk_visual_get_system(); |
415 | ||
a6f5aa49 VZ |
416 | // if this is a wxGLApp (derived from wxApp), and we've already |
417 | // chosen a specific visual, then derive the GdkVisual from that | |
005f5d18 RR |
418 | if (m_glVisualInfo != NULL) |
419 | { | |
be88a6ad | 420 | GdkVisual* vis = gdkx_visual_get( |
a6f5aa49 VZ |
421 | ((XVisualInfo *) m_glVisualInfo) ->visualid ); |
422 | gtk_widget_set_default_visual( vis ); | |
a6f5aa49 VZ |
423 | |
424 | GdkColormap *colormap = gdk_colormap_new( vis, FALSE ); | |
425 | gtk_widget_set_default_colormap( colormap ); | |
426 | ||
427 | visual = vis; | |
428 | } | |
be88a6ad | 429 | |
005f5d18 RR |
430 | // On some machines, the default visual is just 256 colours, so |
431 | // we make sure we get the best. This can sometimes be wasteful. | |
2286341c | 432 | |
005f5d18 RR |
433 | else |
434 | if ((gdk_visual_get_best() != gdk_visual_get_system()) && (m_useBestVisual)) | |
b134516c RR |
435 | { |
436 | GdkVisual* vis = gdk_visual_get_best(); | |
437 | gtk_widget_set_default_visual( vis ); | |
f6fcbb63 | 438 | |
b134516c RR |
439 | GdkColormap *colormap = gdk_colormap_new( vis, FALSE ); |
440 | gtk_widget_set_default_colormap( colormap ); | |
094637f6 VZ |
441 | |
442 | visual = vis; | |
b134516c | 443 | } |
d76fe38b | 444 | |
005f5d18 | 445 | // Nothing to do for 15, 16, 24, 32 bit displays |
f6fcbb63 | 446 | if (visual->depth > 8) return TRUE; |
60acb947 | 447 | |
005f5d18 | 448 | // initialize color cube for 8-bit color reduction dithering |
60acb947 | 449 | |
f6fcbb63 | 450 | GdkColormap *cmap = gtk_widget_get_default_colormap(); |
60acb947 | 451 | |
f6fcbb63 RR |
452 | m_colorCube = (unsigned char*)malloc(32 * 32 * 32); |
453 | ||
f03fc89f VZ |
454 | for (int r = 0; r < 32; r++) |
455 | { | |
8801832d VZ |
456 | for (int g = 0; g < 32; g++) |
457 | { | |
458 | for (int b = 0; b < 32; b++) | |
459 | { | |
460 | int rr = (r << 3) | (r >> 2); | |
461 | int gg = (g << 3) | (g >> 2); | |
462 | int bb = (b << 3) | (b >> 2); | |
60acb947 | 463 | |
f03fc89f VZ |
464 | int index = -1; |
465 | ||
f6fcbb63 | 466 | GdkColor *colors = cmap->colors; |
ca26177c | 467 | if (colors) |
f03fc89f VZ |
468 | { |
469 | int max = 3 * 65536; | |
470 | ||
471 | for (int i = 0; i < cmap->size; i++) | |
472 | { | |
473 | int rdiff = ((rr << 8) - colors[i].red); | |
474 | int gdiff = ((gg << 8) - colors[i].green); | |
475 | int bdiff = ((bb << 8) - colors[i].blue); | |
476 | int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff); | |
477 | if (sum < max) | |
094637f6 | 478 | { |
f03fc89f VZ |
479 | index = i; max = sum; |
480 | } | |
481 | } | |
f6fcbb63 | 482 | } |
094637f6 VZ |
483 | else |
484 | { | |
005f5d18 | 485 | // assume 8-bit true or static colors. this really exists |
094637f6 VZ |
486 | GdkVisual* vis = gdk_colormap_get_visual( cmap ); |
487 | index = (r >> (5 - vis->red_prec)) << vis->red_shift; | |
488 | index |= (g >> (5 - vis->green_prec)) << vis->green_shift; | |
489 | index |= (b >> (5 - vis->blue_prec)) << vis->blue_shift; | |
094637f6 | 490 | } |
8801832d VZ |
491 | m_colorCube[ (r*1024) + (g*32) + b ] = index; |
492 | } | |
493 | } | |
f6fcbb63 | 494 | } |
c801d85f | 495 | |
de6185e2 | 496 | return true; |
bbe0af5b RR |
497 | } |
498 | ||
005f5d18 RR |
499 | GdkVisual *wxApp::GetGdkVisual() |
500 | { | |
501 | GdkVisual *visual = NULL; | |
be88a6ad | 502 | |
005f5d18 | 503 | if (m_glVisualInfo) |
7b775074 | 504 | visual = gdkx_visual_get( ((XVisualInfo *) m_glVisualInfo)->visualid ); |
005f5d18 RR |
505 | else |
506 | visual = gdk_window_get_visual( wxGetRootWindow()->window ); | |
be88a6ad | 507 | |
005f5d18 | 508 | wxASSERT( visual ); |
be88a6ad | 509 | |
005f5d18 RR |
510 | return visual; |
511 | } | |
512 | ||
abca8ebf | 513 | bool wxApp::Initialize(int& argc, wxChar **argv) |
c801d85f | 514 | { |
c156411a | 515 | bool init_result; |
3cbab641 | 516 | |
924ef850 | 517 | #if wxUSE_THREADS |
005f5d18 RR |
518 | // GTK 1.2 up to version 1.2.3 has broken threads |
519 | if ((gtk_major_version == 1) && | |
8f75cb6c | 520 | (gtk_minor_version == 2) && |
2286341c | 521 | (gtk_micro_version < 4)) |
96997d65 | 522 | { |
77ffb593 | 523 | printf( "wxWidgets warning: GUI threading disabled due to outdated GTK version\n" ); |
8f75cb6c RR |
524 | } |
525 | else | |
526 | { | |
863136de RR |
527 | if (!g_thread_supported()) |
528 | g_thread_init(NULL); | |
8f75cb6c | 529 | } |
05e2b077 | 530 | #endif // wxUSE_THREADS |
2286341c | 531 | |
0d2a2b60 | 532 | gtk_set_locale(); |
c801d85f | 533 | |
05e2b077 | 534 | if (!wxOKlibc()) |
960b1f94 | 535 | wxConvCurrent = &wxConvLocal; |
002f4218 | 536 | |
05e2b077 VZ |
537 | #if wxUSE_UNICODE |
538 | // gtk_init() wants UTF-8, not wchar_t, so convert | |
539 | int i; | |
0d8dda32 | 540 | char **argvGTK = new char *[argc + 1]; |
05e2b077 | 541 | for ( i = 0; i < argc; i++ ) |
924ef850 | 542 | { |
05e2b077 | 543 | argvGTK[i] = wxStrdupA(wxConvUTF8.cWX2MB(argv[i])); |
924ef850 | 544 | } |
0cf2cb36 | 545 | |
05e2b077 | 546 | argvGTK[argc] = NULL; |
954de0f1 | 547 | |
05e2b077 | 548 | int argcGTK = argc; |
3cbab641 | 549 | |
62be94e1 | 550 | #ifdef __WXGPE__ |
c156411a | 551 | init_result = true; // is there a _check() version of this? |
62be94e1 RR |
552 | gpe_application_init( &argcGTK, &argvGTK ); |
553 | #else | |
c156411a | 554 | init_result = gtk_init_check( &argcGTK, &argvGTK ); |
62be94e1 | 555 | #endif |
954de0f1 | 556 | |
05e2b077 | 557 | if ( argcGTK != argc ) |
924ef850 | 558 | { |
05e2b077 VZ |
559 | // we have to drop the parameters which were consumed by GTK+ |
560 | for ( i = 0; i < argcGTK; i++ ) | |
561 | { | |
0d8dda32 | 562 | while ( strcmp(wxConvUTF8.cWX2MB(argv[i]), argvGTK[i]) != 0 ) |
05e2b077 VZ |
563 | { |
564 | memmove(argv + i, argv + i + 1, argc - i); | |
565 | } | |
566 | } | |
0cf2cb36 | 567 | |
05e2b077 | 568 | argc = argcGTK; |
2b5f62a0 | 569 | } |
05e2b077 | 570 | //else: gtk_init() didn't modify our parameters |
e0253070 | 571 | |
05e2b077 VZ |
572 | // free our copy |
573 | for ( i = 0; i < argcGTK; i++ ) | |
0151c3eb | 574 | { |
05e2b077 | 575 | free(argvGTK[i]); |
0151c3eb | 576 | } |
0cf2cb36 | 577 | |
05e2b077 VZ |
578 | delete [] argvGTK; |
579 | #else // !wxUSE_UNICODE | |
580 | // gtk_init() shouldn't actually change argv itself (just its contents) so | |
581 | // it's ok to pass pointer to it | |
c156411a | 582 | init_result = gtk_init_check( &argc, &argv ); |
05e2b077 | 583 | #endif // wxUSE_UNICODE/!wxUSE_UNICODE |
0cf2cb36 | 584 | |
c156411a RD |
585 | if (!init_result) { |
586 | wxLogError(wxT("Unable to initialize gtk, is DISPLAY set properly?")); | |
587 | return false; | |
588 | } | |
3cbab641 | 589 | |
05e2b077 VZ |
590 | // we can not enter threads before gtk_init is done |
591 | gdk_threads_enter(); | |
0cf2cb36 | 592 | |
abca8ebf VZ |
593 | if ( !wxAppBase::Initialize(argc, argv) ) |
594 | { | |
595 | gdk_threads_leave(); | |
596 | ||
597 | return false; | |
598 | } | |
599 | ||
05e2b077 | 600 | wxSetDetectableAutoRepeat( TRUE ); |
be88a6ad | 601 | |
05e2b077 VZ |
602 | #if wxUSE_INTL |
603 | wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding()); | |
604 | #endif | |
be88a6ad | 605 | |
05e2b077 VZ |
606 | return true; |
607 | } | |
0cf2cb36 | 608 | |
05e2b077 VZ |
609 | void wxApp::CleanUp() |
610 | { | |
05e2b077 | 611 | gdk_threads_leave(); |
abca8ebf VZ |
612 | |
613 | wxAppBase::CleanUp(); | |
ff7b1510 | 614 | } |
1a56f55c | 615 | |
657a8a35 VZ |
616 | void wxApp::OnAssertFailure(const wxChar *file, |
617 | int line, | |
618 | const wxChar* func, | |
619 | const wxChar* cond, | |
620 | const wxChar *msg) | |
a5f1fd3e | 621 | { |
657a8a35 VZ |
622 | // there is no need to do anything if asserts are disabled in this build |
623 | // anyhow | |
624 | #if wxDEBUG_LEVEL | |
625 | // block wx idle events while assert dialog is showing | |
de6185e2 | 626 | m_isInAssert = true; |
a5f1fd3e | 627 | |
657a8a35 | 628 | wxAppBase::OnAssertFailure(file, line, func, cond, msg); |
a5f1fd3e | 629 | |
de6185e2 | 630 | m_isInAssert = false; |
657a8a35 VZ |
631 | #else // !wxDEBUG_LEVEL |
632 | wxUnusedVar(file); | |
633 | wxUnusedVar(line); | |
634 | wxUnusedVar(func); | |
635 | wxUnusedVar(cond); | |
636 | wxUnusedVar(msg); | |
637 | #endif // wxDEBUG_LEVEL/!wxDEBUG_LEVEL | |
a5f1fd3e VZ |
638 | } |
639 | ||
fe593cc5 VS |
640 | void wxApp::RemoveIdleTag() |
641 | { | |
642 | #if wxUSE_THREADS | |
643 | wxMutexLocker lock(gs_idleTagsMutex); | |
644 | #endif | |
c263eb03 VS |
645 | if (!g_isIdle) |
646 | { | |
647 | gtk_idle_remove( wxTheApp->m_idleTag ); | |
648 | wxTheApp->m_idleTag = 0; | |
de6185e2 | 649 | g_isIdle = true; |
c263eb03 | 650 | } |
fe593cc5 | 651 | } |