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