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