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