]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/app.cpp
Use GetItem to get item info for events, even for virtual wxListCtrl.
[wxWidgets.git] / src / gtk / app.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
88a7a4e1 2// Name: src/gtk/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"
5b56bffb 25 #include "wx/memory.h"
48a1108e 26 #include "wx/font.h"
88a7a4e1
WS
27#endif
28
b1ac3b56 29#include "wx/file.h"
2b5f62a0 30#include "wx/filename.h"
fe593cc5 31#include "wx/thread.h"
afb74891 32
62be94e1 33#ifdef __WXGPE__
88a7a4e1 34 #include <gpe/init.h>
62be94e1
RR
35#endif
36
df028524
VS
37#ifdef __WXUNIVERSAL__
38 #include "wx/univ/theme.h"
39 #include "wx/univ/renderer.h"
40#endif
41
20e05ffb 42#include <unistd.h>
2b5f62a0
VZ
43
44#ifdef HAVE_POLL
45 #if defined(__VMS)
46 #include <poll.h>
47 #else
48 // bug in the OpenBSD headers: at least in 3.1 there is no extern "C"
49 // in neither poll.h nor sys/poll.h which results in link errors later
50 #ifdef __OPENBSD__
51 extern "C"
52 {
53 #endif
54
55 #include <sys/poll.h>
56
57 #ifdef __OPENBSD__
58 };
59 #endif
60 #endif // platform
61#else // !HAVE_POLL
62 // we implement poll() ourselves using select() which is supposed exist in
63 // all modern Unices
64 #include <sys/types.h>
65 #include <sys/time.h>
66 #include <unistd.h>
bc023abb
MW
67 #ifdef HAVE_SYS_SELECT_H
68 #include <sys/select.h>
69 #endif
2b5f62a0
VZ
70#endif // HAVE_POLL/!HAVE_POLL
71
17a1ebd1 72#include "wx/unix/private.h"
e8106239 73#include "wx/gtk/win_gtk.h"
84833214 74#include "wx/gtk/private.h"
c801d85f 75
c259ffdf 76#include <gdk/gdkx.h>
24178e4a 77
2b850ae1
RR
78//-----------------------------------------------------------------------------
79// link GnomeVFS
80//-----------------------------------------------------------------------------
81
82#if wxUSE_LIBGNOMEVFS
83#include "wx/html/forcelnk.h"
84FORCE_LINK(gnome_vfs)
85#endif
86
c801d85f
KB
87//-----------------------------------------------------------------------------
88// global data
89//-----------------------------------------------------------------------------
90
de6185e2 91bool g_mainThreadLocked = false;
3ac8d3bc 92
c2fa61e8 93static GtkWidget *gs_RootWindow = (GtkWidget*) NULL;
d76fe38b 94
c801d85f 95//-----------------------------------------------------------------------------
3133cb9f 96// idle system
c801d85f
KB
97//-----------------------------------------------------------------------------
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
88a7a4e1 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
88a7a4e1 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
88a7a4e1 130 return true;
6dc5fd71
VZ
131 }
132#endif // wxUSE_THREADS
133
88a7a4e1 134 wxIsInsideYield = true;
e90c1d2a 135
c263eb03
VS
136 // We need to remove idle callbacks or the loop will
137 // never finish.
67461bd1 138 SuspendIdleCallback();
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
88a7a4e1 162 wxIsInsideYield = false;
99ba739f 163
88a7a4e1 164 return true;
acfd422a
RR
165}
166
bf9e3e73
RR
167//-----------------------------------------------------------------------------
168// wxWakeUpIdle
169//-----------------------------------------------------------------------------
170
68567a96
MR
171// RR/KH: No wxMutexGui calls are needed here according to the GTK faq,
172// http://www.gtk.org/faq/#AEN500 - this caused problems for wxPostEvent.
19722331 173
e2478fde 174void wxApp::WakeUpIdle()
bf9e3e73 175{
c263eb03 176 wxapp_install_idle_handler();
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
14819684
PC
187// One-shot emission hook for "event" signal, to install idle handler.
188// This will be called when the "event" signal is issued on any GtkWidget object.
189static gboolean
190event_emission_hook(GSignalInvocationHint*, guint, const GValue*, gpointer)
191{
192 wxapp_install_idle_handler();
193 // remove hook
194 return false;
195}
196
176d9824 197// add emission hook for "event" signal, to re-install idle handler when needed
8a378a9e
PC
198static inline void wxAddEmissionHook()
199{
176d9824
PC
200 GType widgetType = GTK_TYPE_WIDGET;
201 // if GtkWidget type is loaded
202 if (g_type_class_peek(widgetType) != NULL)
203 {
204 guint sig_id = g_signal_lookup("event", widgetType);
205 g_signal_add_emission_hook(sig_id, 0, event_emission_hook, NULL, NULL);
206 }
8a378a9e
PC
207}
208
3133cb9f 209static gint wxapp_idle_callback( gpointer WXUNUSED(data) )
96997d65 210{
ec439571 211 // this does not look possible, but just in case...
a5f1fd3e 212 if (!wxTheApp)
1136ac0b 213 return false;
a5f1fd3e 214
ec439571
PC
215 bool moreIdles = false;
216
a5f1fd3e 217#ifdef __WXDEBUG__
6d477bb4 218 // don't generate the idle events while the assert modal dialog is shown,
ec439571
PC
219 // this matches the behavior of wxMSW
220 if (!wxTheApp->IsInAssert())
a5f1fd3e 221#endif // __WXDEBUG__
ec439571 222 {
046c2f14
PC
223 guint idleID_save;
224 {
225 // Allow another idle source to be added while this one is busy.
226 // Needed if an idle event handler runs a new event loop,
227 // for example by showing a dialog.
228#if wxUSE_THREADS
229 wxMutexLocker lock(gs_idleTagsMutex);
230#endif
231 idleID_save = wxTheApp->m_idleTag;
232 wxTheApp->m_idleTag = 0;
233 g_isIdle = true;
234 wxAddEmissionHook();
235 }
236
ec439571
PC
237 // When getting called from GDK's time-out handler
238 // we are no longer within GDK's grab on the GUI
239 // thread so we must lock it here ourselves.
240 gdk_threads_enter();
241
242 // Send idle event to all who request them as long as
243 // no events have popped up in the event queue.
244 do {
245 moreIdles = wxTheApp->ProcessIdle();
246 } while (moreIdles && gtk_events_pending() == 0);
247
248 // Release lock again
249 gdk_threads_leave();
046c2f14
PC
250
251 {
252 // If another idle source was added, remove it
253#if wxUSE_THREADS
254 wxMutexLocker lock(gs_idleTagsMutex);
255#endif
256 if (wxTheApp->m_idleTag != 0)
257 g_source_remove(wxTheApp->m_idleTag);
258 wxTheApp->m_idleTag = idleID_save;
259 g_isIdle = false;
260 }
ec439571 261 }
acfd422a 262
14819684 263 if (!moreIdles)
9a5c9a0c
PC
264 {
265#if wxUSE_THREADS
266 wxMutexLocker lock(gs_idleTagsMutex);
267#endif
268 // Indicate that we are now in idle mode and event handlers
269 // will have to reinstall the idle handler again.
270 g_isIdle = true;
271 wxTheApp->m_idleTag = 0;
272
8a378a9e 273 wxAddEmissionHook();
9a5c9a0c 274 }
14819684 275
8ab9a536
RR
276 // Return FALSE if no more idle events are to be sent
277 return moreIdles;
acfd422a 278}
8801832d 279
90350682
VZ
280#if wxUSE_THREADS
281
2b5f62a0
VZ
282#ifdef HAVE_POLL
283 #define wxPoll poll
284 #define wxPollFd pollfd
285#else // !HAVE_POLL
286
287typedef GPollFD wxPollFd;
288
289int wxPoll(wxPollFd *ufds, unsigned int nfds, int timeout)
290{
291 // convert timeout from ms to struct timeval (s/us)
292 timeval tv_timeout;
293 tv_timeout.tv_sec = timeout/1000;
294 tv_timeout.tv_usec = (timeout%1000)*1000;
295
296 // remember the highest fd used here
297 int fdMax = -1;
298
299 // and fill the sets for select()
300 fd_set readfds;
301 fd_set writefds;
302 fd_set exceptfds;
17a1ebd1
VZ
303 wxFD_ZERO(&readfds);
304 wxFD_ZERO(&writefds);
305 wxFD_ZERO(&exceptfds);
2b5f62a0
VZ
306
307 unsigned int i;
308 for ( i = 0; i < nfds; i++ )
309 {
7f5ff1b2 310 wxASSERT_MSG( ufds[i].fd < FD_SETSIZE, _T("fd out of range") );
2b5f62a0
VZ
311
312 if ( ufds[i].events & G_IO_IN )
17a1ebd1 313 wxFD_SET(ufds[i].fd, &readfds);
2b5f62a0
VZ
314
315 if ( ufds[i].events & G_IO_PRI )
17a1ebd1 316 wxFD_SET(ufds[i].fd, &exceptfds);
2b5f62a0
VZ
317
318 if ( ufds[i].events & G_IO_OUT )
17a1ebd1 319 wxFD_SET(ufds[i].fd, &writefds);
2b5f62a0
VZ
320
321 if ( ufds[i].fd > fdMax )
322 fdMax = ufds[i].fd;
323 }
324
325 fdMax++;
326 int res = select(fdMax, &readfds, &writefds, &exceptfds, &tv_timeout);
327
328 // translate the results back
329 for ( i = 0; i < nfds; i++ )
330 {
331 ufds[i].revents = 0;
332
17a1ebd1 333 if ( wxFD_ISSET(ufds[i].fd, &readfds ) )
2b5f62a0
VZ
334 ufds[i].revents |= G_IO_IN;
335
17a1ebd1 336 if ( wxFD_ISSET(ufds[i].fd, &exceptfds ) )
2b5f62a0
VZ
337 ufds[i].revents |= G_IO_PRI;
338
17a1ebd1 339 if ( wxFD_ISSET(ufds[i].fd, &writefds ) )
2b5f62a0
VZ
340 ufds[i].revents |= G_IO_OUT;
341 }
342
343 return res;
344}
345
346#endif // HAVE_POLL/!HAVE_POLL
347
3133cb9f 348static gint wxapp_poll_func( GPollFD *ufds, guint nfds, gint timeout )
acfd422a 349{
90350682 350 gdk_threads_enter();
7b90a8f2 351
90350682 352 wxMutexGuiLeave();
e4db172a 353 g_mainThreadLocked = true;
7941ba11 354
2b5f62a0
VZ
355 // we rely on the fact that glib GPollFD struct is really just pollfd but
356 // I wonder how wise is this in the long term (VZ)
357 gint res = wxPoll( (wxPollFd *) ufds, nfds, timeout );
90350682 358
90350682 359 wxMutexGuiEnter();
de6185e2 360 g_mainThreadLocked = false;
90350682 361
90350682
VZ
362 gdk_threads_leave();
363
3133cb9f 364 return res;
ff7b1510 365}
c801d85f 366
90350682
VZ
367#endif // wxUSE_THREADS
368
369} // extern "C"
370
3133cb9f 371void wxapp_install_idle_handler()
b453e1b2 372{
7482aa19
PC
373 if (wxTheApp == NULL)
374 return;
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 // This routine gets called by all event handlers
395 // indicating that the idle is over. It may also
396 // get called from other thread for sending events
397 // to the main thread (and processing these in
398 // idle time). Very low priority.
6a555739 399 wxTheApp->m_idleTag = g_idle_add_full(G_PRIORITY_LOW, wxapp_idle_callback, NULL, NULL);
b453e1b2
RR
400}
401
005f5d18
RR
402//-----------------------------------------------------------------------------
403// Access to the root window global
404//-----------------------------------------------------------------------------
405
406GtkWidget* wxGetRootWindow()
407{
408 if (gs_RootWindow == NULL)
409 {
410 gs_RootWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL );
411 gtk_widget_realize( gs_RootWindow );
412 }
413 return gs_RootWindow;
414}
415
c801d85f
KB
416//-----------------------------------------------------------------------------
417// wxApp
418//-----------------------------------------------------------------------------
419
420IMPLEMENT_DYNAMIC_CLASS(wxApp,wxEvtHandler)
421
53010e52 422BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
955a9197 423 EVT_IDLE(wxAppBase::OnIdle)
53010e52
RR
424END_EVENT_TABLE()
425
c801d85f
KB
426wxApp::wxApp()
427{
a5f1fd3e 428#ifdef __WXDEBUG__
de6185e2 429 m_isInAssert = false;
a5f1fd3e
VZ
430#endif // __WXDEBUG__
431
df5ddbca 432 m_idleTag = 0;
e4db172a 433 g_isIdle = true;
df5ddbca 434 wxapp_install_idle_handler();
094637f6 435
6b3eb77a 436#if wxUSE_THREADS
15894949 437 g_main_context_set_poll_func( NULL, wxapp_poll_func );
6b3eb77a 438#endif
60acb947 439
a6f5aa49
VZ
440 // this is NULL for a "regular" wxApp, but is set (and freed) by a wxGLApp
441 m_glVisualInfo = (void *) NULL;
34a34b02 442 m_glFBCInfo = (void *) NULL;
ff7b1510 443}
c801d85f 444
60acb947 445wxApp::~wxApp()
c801d85f 446{
5d038ec5
MR
447 if (m_idleTag)
448 g_source_remove( m_idleTag );
ff7b1510 449}
c801d85f 450
0d2a2b60 451bool wxApp::OnInitGui()
c801d85f 452{
1e6feb95 453 if ( !wxAppBase::OnInitGui() )
de6185e2 454 return false;
1e6feb95 455
a6f5aa49
VZ
456 // if this is a wxGLApp (derived from wxApp), and we've already
457 // chosen a specific visual, then derive the GdkVisual from that
005f5d18
RR
458 if (m_glVisualInfo != NULL)
459 {
a6f5aa49 460 GdkVisual* vis = gtk_widget_get_default_visual();
a6f5aa49
VZ
461
462 GdkColormap *colormap = gdk_colormap_new( vis, FALSE );
463 gtk_widget_set_default_colormap( colormap );
a6f5aa49 464 }
005f5d18 465 else
b134516c 466 {
c77eea28
RR
467 // On some machines, the default visual is just 256 colours, so
468 // we make sure we get the best. This can sometimes be wasteful.
469 if (m_useBestVisual)
470 {
471 if (m_forceTrueColour)
472 {
473 GdkVisual* visual = gdk_visual_get_best_with_both( 24, GDK_VISUAL_TRUE_COLOR );
474 if (!visual)
475 {
476 wxLogError(wxT("Unable to initialize TrueColor visual."));
477 return false;
478 }
479 GdkColormap *colormap = gdk_colormap_new( visual, FALSE );
480 gtk_widget_set_default_colormap( colormap );
481 }
482 else
483 {
484 if (gdk_visual_get_best() != gdk_visual_get_system())
485 {
486 GdkVisual* visual = gdk_visual_get_best();
487 GdkColormap *colormap = gdk_colormap_new( visual, FALSE );
488 gtk_widget_set_default_colormap( colormap );
489 }
490 }
491 }
f6fcbb63 492 }
c801d85f 493
88a7a4e1 494 return true;
bbe0af5b
RR
495}
496
005f5d18
RR
497GdkVisual *wxApp::GetGdkVisual()
498{
499 GdkVisual *visual = NULL;
be88a6ad 500
005f5d18 501 if (m_glVisualInfo)
7b775074 502 visual = gdkx_visual_get( ((XVisualInfo *) m_glVisualInfo)->visualid );
005f5d18 503 else
22a3bce4 504 visual = gdk_drawable_get_visual( wxGetRootWindow()->window );
be88a6ad 505
005f5d18 506 wxASSERT( visual );
be88a6ad 507
005f5d18
RR
508 return visual;
509}
510
abca8ebf 511bool wxApp::Initialize(int& argc, wxChar **argv)
c801d85f 512{
c156411a 513 bool init_result;
68567a96 514
924ef850 515#if wxUSE_THREADS
ac131bab
MR
516 if (!g_thread_supported())
517 g_thread_init(NULL);
05e2b077 518#endif // wxUSE_THREADS
2286341c 519
0d2a2b60 520 gtk_set_locale();
c801d85f 521
f9862abd
JS
522 // We should have the wxUSE_WCHAR_T test on the _outside_
523#if wxUSE_WCHAR_T
68567a96
MR
524 // gtk+ 2.0 supports Unicode through UTF-8 strings
525 wxConvCurrent = &wxConvUTF8;
05e2b077
VZ
526#else // !wxUSE_WCHAR_T
527 if (!wxOKlibc())
528 wxConvCurrent = (wxMBConv*) NULL;
529#endif // wxUSE_WCHAR_T/!wxUSE_WCHAR_T
002f4218 530
845905d5
MW
531 // decide which conversion to use for the file names
532
533 // (1) this variable exists for the sole purpose of specifying the encoding
534 // of the filenames for GTK+ programs, so use it if it is set
535 wxString encName(wxGetenv(_T("G_FILENAME_ENCODING")));
29c326b7 536 encName = encName.BeforeFirst(_T(','));
7c8ec100 537 if (encName.CmpNoCase(_T("@locale")) == 0)
d24b23b7 538 encName.clear();
845905d5 539 encName.MakeUpper();
68567a96 540#if wxUSE_INTL
845905d5
MW
541 if (encName.empty())
542 {
543 // (2) if a non default locale is set, assume that the user wants his
544 // filenames in this locale too
545 encName = wxLocale::GetSystemEncodingName().Upper();
546 // (3) finally use UTF-8 by default
547 if (encName.empty() || encName == _T("US-ASCII"))
548 encName = _T("UTF-8");
549 wxSetEnv(_T("G_FILENAME_ENCODING"), encName);
550 }
551#else
552 if (encName.empty())
553 encName = _T("UTF-8");
554#endif // wxUSE_INTL
555 static wxConvBrokenFileNames fileconv(encName);
556 wxConvFileName = &fileconv;
66bf0099 557
05e2b077
VZ
558#if wxUSE_UNICODE
559 // gtk_init() wants UTF-8, not wchar_t, so convert
560 int i;
0d8dda32 561 char **argvGTK = new char *[argc + 1];
05e2b077 562 for ( i = 0; i < argc; i++ )
924ef850 563 {
05e2b077 564 argvGTK[i] = wxStrdupA(wxConvUTF8.cWX2MB(argv[i]));
924ef850 565 }
0cf2cb36 566
05e2b077 567 argvGTK[argc] = NULL;
954de0f1 568
05e2b077 569 int argcGTK = argc;
68567a96 570
62be94e1 571#ifdef __WXGPE__
c156411a 572 init_result = true; // is there a _check() version of this?
62be94e1
RR
573 gpe_application_init( &argcGTK, &argvGTK );
574#else
c156411a 575 init_result = gtk_init_check( &argcGTK, &argvGTK );
62be94e1 576#endif
954de0f1 577
05e2b077 578 if ( argcGTK != argc )
924ef850 579 {
05e2b077
VZ
580 // we have to drop the parameters which were consumed by GTK+
581 for ( i = 0; i < argcGTK; i++ )
582 {
0d8dda32 583 while ( strcmp(wxConvUTF8.cWX2MB(argv[i]), argvGTK[i]) != 0 )
05e2b077
VZ
584 {
585 memmove(argv + i, argv + i + 1, argc - i);
586 }
587 }
0cf2cb36 588
05e2b077 589 argc = argcGTK;
2b5f62a0 590 }
05e2b077 591 //else: gtk_init() didn't modify our parameters
e0253070 592
05e2b077
VZ
593 // free our copy
594 for ( i = 0; i < argcGTK; i++ )
0151c3eb 595 {
05e2b077 596 free(argvGTK[i]);
0151c3eb 597 }
0cf2cb36 598
05e2b077
VZ
599 delete [] argvGTK;
600#else // !wxUSE_UNICODE
601 // gtk_init() shouldn't actually change argv itself (just its contents) so
602 // it's ok to pass pointer to it
c156411a 603 init_result = gtk_init_check( &argc, &argv );
05e2b077 604#endif // wxUSE_UNICODE/!wxUSE_UNICODE
0cf2cb36 605
c156411a
RD
606 if (!init_result) {
607 wxLogError(wxT("Unable to initialize gtk, is DISPLAY set properly?"));
608 return false;
609 }
68567a96 610
05e2b077
VZ
611 // we can not enter threads before gtk_init is done
612 gdk_threads_enter();
0cf2cb36 613
abca8ebf
VZ
614 if ( !wxAppBase::Initialize(argc, argv) )
615 {
616 gdk_threads_leave();
617
618 return false;
619 }
620
e4db172a 621 wxSetDetectableAutoRepeat( true );
be88a6ad 622
05e2b077
VZ
623#if wxUSE_INTL
624 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
625#endif
be88a6ad 626
05e2b077
VZ
627 return true;
628}
0cf2cb36 629
05e2b077
VZ
630void wxApp::CleanUp()
631{
05e2b077 632 gdk_threads_leave();
abca8ebf
VZ
633
634 wxAppBase::CleanUp();
ff7b1510 635}
1a56f55c 636
a5f1fd3e
VZ
637#ifdef __WXDEBUG__
638
2d97237d
VZ
639void wxApp::OnAssertFailure(const wxChar *file,
640 int line,
641 const wxChar* func,
642 const wxChar* cond,
643 const wxChar *msg)
a5f1fd3e 644{
ec439571
PC
645
646 // block wx idle events while assert dialog is showing
647 m_isInAssert = true;
a5f1fd3e 648
2d97237d 649 wxAppBase::OnAssertFailure(file, line, func, cond, msg);
a5f1fd3e 650
ec439571 651 m_isInAssert = false;
a5f1fd3e
VZ
652}
653
654#endif // __WXDEBUG__
655
67461bd1 656void wxApp::SuspendIdleCallback()
fe593cc5
VS
657{
658#if wxUSE_THREADS
659 wxMutexLocker lock(gs_idleTagsMutex);
660#endif
8a378a9e 661 if (m_idleTag != 0)
c263eb03 662 {
8a378a9e
PC
663 g_source_remove(m_idleTag);
664 m_idleTag = 0;
e4db172a 665 g_isIdle = true;
8a378a9e 666 wxAddEmissionHook();
c263eb03 667 }
fe593cc5 668}