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