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