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