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