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