]> git.saurik.com Git - wxWidgets.git/blame - src/x11/app.cpp
reSWIGged
[wxWidgets.git] / src / x11 / app.cpp
CommitLineData
83df96d6
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: app.cpp
3// Purpose: wxApp
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
83df96d6
JS
10/////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
83df96d6
JS
13 #pragma implementation "app.h"
14#endif
15
83df96d6
JS
16#include "wx/frame.h"
17#include "wx/app.h"
18#include "wx/utils.h"
19#include "wx/gdicmn.h"
83df96d6 20#include "wx/icon.h"
83df96d6 21#include "wx/dialog.h"
83df96d6
JS
22#include "wx/log.h"
23#include "wx/module.h"
24#include "wx/memory.h"
25#include "wx/log.h"
26#include "wx/intl.h"
1b0fb34b 27#include "wx/evtloop.h"
868741e9 28#include "wx/timer.h"
2b5f62a0 29#include "wx/filename.h"
ed39ff57 30#include "wx/hash.h"
83df96d6 31
ef8c973b
VS
32#include "wx/univ/theme.h"
33#include "wx/univ/renderer.h"
34
83df96d6
JS
35#if wxUSE_THREADS
36 #include "wx/thread.h"
37#endif
38
7eaac9f5 39#include "wx/x11/private.h"
83df96d6
JS
40
41#include <string.h>
42
9d2cef1c
RR
43//------------------------------------------------------------------------
44// global data
45//------------------------------------------------------------------------
46
83df96d6
JS
47extern wxList wxPendingDelete;
48
b8033a5d
VZ
49wxWindowHash *wxWidgetHashTable = NULL;
50wxWindowHash *wxClientWidgetHashTable = NULL;
9d2cef1c 51
9d2cef1c
RR
52static bool g_showIconic = FALSE;
53static wxSize g_initialSize = wxDefaultSize;
83df96d6 54
9d2cef1c
RR
55// This is required for wxFocusEvent::SetWindow(). It will only
56// work for focus events which we provoke ourselves (by calling
57// SetFocus()). It will not work for those events, which X11
58// generates itself.
59static wxWindow *g_nextFocus = NULL;
60static wxWindow *g_prevFocus = NULL;
83df96d6 61
9d2cef1c
RR
62//------------------------------------------------------------------------
63// X11 error handling
64//------------------------------------------------------------------------
83df96d6
JS
65
66#ifdef __WXDEBUG__
1b0fb34b 67typedef int (*XErrorHandlerFunc)(Display *, XErrorEvent *);
83df96d6 68
1b0fb34b 69XErrorHandlerFunc gs_pfnXErrorHandler = 0;
83df96d6 70
1b0fb34b
JS
71static int wxXErrorHandler(Display *dpy, XErrorEvent *xevent)
72{
73 // just forward to the default handler for now
c79a329d
JS
74 if (gs_pfnXErrorHandler)
75 return gs_pfnXErrorHandler(dpy, xevent);
76 else
77 return 0;
1b0fb34b 78}
83df96d6
JS
79#endif // __WXDEBUG__
80
9d2cef1c
RR
81//------------------------------------------------------------------------
82// wxApp
83//------------------------------------------------------------------------
84
83df96d6 85long wxApp::sm_lastMessageTime = 0;
a11672a4 86WXDisplay *wxApp::ms_display = NULL;
83df96d6 87
9d2cef1c
RR
88IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
89
90BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
955a9197 91 EVT_IDLE(wxAppBase::OnIdle)
9d2cef1c 92END_EVENT_TABLE()
256d631a 93
05e2b077 94bool wxApp::Initialize(int& argc, wxChar **argv)
83df96d6 95{
05e2b077 96#if defined(__WXDEBUG__) && !wxUSE_NANOX
a11672a4
RR
97 // install the X error handler
98 gs_pfnXErrorHandler = XSetErrorHandler( wxXErrorHandler );
99#endif // __WXDEBUG__
100
c6441a0d 101 wxString displayName;
256d631a
JS
102 bool syncDisplay = FALSE;
103
05e2b077
VZ
104 int argcOrig = argc;
105 for ( int i = 0; i < argcOrig; i++ )
256d631a 106 {
05e2b077 107 if (wxStrcmp( argv[i], _T("-display") ) == 0)
256d631a
JS
108 {
109 if (i < (argc - 1))
110 {
05e2b077
VZ
111 argv[i++] = NULL;
112
256d631a 113 displayName = argv[i];
05e2b077
VZ
114
115 argv[i] = NULL;
116 argc -= 2;
256d631a
JS
117 }
118 }
05e2b077 119 else if (wxStrcmp( argv[i], _T("-geometry") ) == 0)
256d631a
JS
120 {
121 if (i < (argc - 1))
122 {
05e2b077
VZ
123 argv[i++] = NULL;
124
256d631a 125 int w, h;
05e2b077 126 if (wxSscanf(argv[i], _T("%dx%d"), &w, &h) != 2)
256d631a 127 {
05e2b077 128 wxLogError( _("Invalid geometry specification '%s'"),
c6441a0d 129 wxString(argv[i]).c_str() );
256d631a
JS
130 }
131 else
132 {
133 g_initialSize = wxSize(w, h);
134 }
05e2b077
VZ
135
136 argv[i] = NULL;
137 argc -= 2;
256d631a
JS
138 }
139 }
05e2b077 140 else if (wxStrcmp( argv[i], _T("-sync") ) == 0)
256d631a
JS
141 {
142 syncDisplay = TRUE;
05e2b077
VZ
143
144 argv[i] = NULL;
145 argc--;
256d631a 146 }
05e2b077 147 else if (wxStrcmp( argv[i], _T("-iconic") ) == 0)
256d631a
JS
148 {
149 g_showIconic = TRUE;
45ff6421 150
05e2b077
VZ
151 argv[i] = NULL;
152 argc--;
256d631a 153 }
05e2b077 154 }
256d631a 155
05e2b077
VZ
156 if ( argc != argcOrig )
157 {
158 // remove the argumens we consumed
159 for ( int i = 0; i < argc; i++ )
160 {
161 while ( !argv[i] )
162 {
163 memmove(argv + i, argv + i + 1, argcOrig - i);
164 }
165 }
256d631a 166 }
a11672a4 167
7c9955d1 168 // X11 display stuff
c6441a0d
VS
169 Display *xdisplay;
170 if ( displayName.empty() )
171 xdisplay = XOpenDisplay( NULL );
172 else
173 xdisplay = XOpenDisplay( displayName.ToAscii() );
a11672a4
RR
174 if (!xdisplay)
175 {
77ffb593 176 wxLogError( _("wxWidgets could not open display. Exiting.") );
05e2b077
VZ
177 return false;
178 }
179
256d631a 180 if (syncDisplay)
256d631a 181 XSynchronize(xdisplay, True);
e2386592 182
05e2b077 183 ms_display = (WXDisplay*) xdisplay;
7c9955d1 184
a11672a4 185 XSelectInput( xdisplay, XDefaultRootWindow(xdisplay), PropertyChangeMask);
e2386592 186
2b5f62a0 187 // Misc.
7e4501ee 188 wxSetDetectableAutoRepeat( TRUE );
a11672a4 189
5b004007
VZ
190 if ( !wxAppBase::Initialize(argc, argv) )
191 {
192 XCloseDisplay(xdisplay);
193
194 return false;
195 }
196
2b5f62a0
VZ
197#if wxUSE_UNICODE
198 // Glib's type system required by Pango
199 g_type_init();
7c9955d1 200#endif
2b5f62a0 201
05e2b077
VZ
202#if wxUSE_INTL
203 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
204#endif
a11672a4 205
b8033a5d
VZ
206 wxWidgetHashTable = new wxWindowHash;
207 wxClientWidgetHashTable = new wxWindowHash;
a11672a4 208
05e2b077 209 return true;
a11672a4
RR
210}
211
05e2b077 212void wxApp::CleanUp()
83df96d6 213{
05e2b077
VZ
214 delete wxWidgetHashTable;
215 wxWidgetHashTable = NULL;
216 delete wxClientWidgetHashTable;
217 wxClientWidgetHashTable = NULL;
83df96d6 218
05e2b077
VZ
219 wxAppBase::CleanUp();
220}
83df96d6 221
83df96d6
JS
222wxApp::wxApp()
223{
00344dd0 224 // TODO: parse the command line
83df96d6
JS
225 argc = 0;
226 argv = NULL;
00344dd0 227
83df96d6 228 m_mainColormap = (WXColormap) NULL;
7eaac9f5 229 m_topLevelWidget = (WXWindow) NULL;
83df96d6 230 m_maxRequestSize = 0;
256d631a
JS
231 m_showIconic = FALSE;
232 m_initialSize = wxDefaultSize;
366e8ae6 233
8601b2e1 234#if !wxUSE_NANOX
9ce8d6a2 235 m_visualInfo = NULL;
8601b2e1 236#endif
dc4025af
RR
237}
238
239wxApp::~wxApp()
240{
8601b2e1 241#if !wxUSE_NANOX
9ce8d6a2 242 delete m_visualInfo;
8601b2e1 243#endif
83df96d6
JS
244}
245
70b8ab77 246#if !wxUSE_NANOX
f809133f
RR
247//-----------------------------------------------------------------------
248// X11 predicate function for exposure compression
249//-----------------------------------------------------------------------
250
251struct wxExposeInfo
252{
253 Window window;
254 Bool found_non_matching;
255};
256
257static Bool expose_predicate (Display *display, XEvent *xevent, XPointer arg)
258{
259 wxExposeInfo *info = (wxExposeInfo*) arg;
e2386592 260
f809133f
RR
261 if (info->found_non_matching)
262 return FALSE;
e2386592 263
f809133f
RR
264 if (xevent->xany.type != Expose)
265 {
266 info->found_non_matching = TRUE;
267 return FALSE;
268 }
e2386592 269
f809133f
RR
270 if (xevent->xexpose.window != info->window)
271 {
272 info->found_non_matching = TRUE;
273 return FALSE;
274 }
e2386592 275
f809133f
RR
276 return TRUE;
277}
70b8ab77
JS
278#endif
279 // wxUSE_NANOX
f809133f
RR
280
281//-----------------------------------------------------------------------
086fd560 282// Processes an X event, returning TRUE if the event was processed.
f809133f
RR
283//-----------------------------------------------------------------------
284
086fd560 285bool wxApp::ProcessXEvent(WXEvent* _event)
1b0fb34b
JS
286{
287 XEvent* event = (XEvent*) _event;
83df96d6 288
1b0fb34b 289 wxWindow* win = NULL;
c79a329d 290 Window window = XEventGetWindow(event);
e2386592 291#if 0
1b0fb34b 292 Window actualWindow = window;
e2386592 293#endif
0b5c0e1a 294
1b0fb34b 295 // Find the first wxWindow that corresponds to this event window
774b90fb
JS
296 // Because we're receiving events after a window
297 // has been destroyed, assume a 1:1 match between
298 // Window and wxWindow, so if it's not in the table,
299 // it must have been destroyed.
e2386592 300
774b90fb
JS
301 win = wxGetWindowFromTable(window);
302 if (!win)
ab6b6b15
RR
303 {
304#if wxUSE_TWO_WINDOWS
305 win = wxGetClientWindowFromTable(window);
306 if (!win)
307#endif
308 return FALSE;
309 }
83df96d6 310
0b5c0e1a
JS
311#ifdef __WXDEBUG__
312 wxString windowClass = win->GetClassInfo()->GetClassName();
313#endif
e2386592 314
1b0fb34b
JS
315 switch (event->type)
316 {
2f12683e
RR
317 case Expose:
318 {
8601b2e1 319#if wxUSE_TWO_WINDOWS && !wxUSE_NANOX
f41bc3e3 320 if (event->xexpose.window != (Window)win->GetClientAreaWindow())
ab6b6b15
RR
321 {
322 XEvent tmp_event;
323 wxExposeInfo info;
324 info.window = event->xexpose.window;
325 info.found_non_matching = FALSE;
326 while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event, expose_predicate, (XPointer) &info ))
327 {
328 // Don't worry about optimizing redrawing the border etc.
329 }
330 win->NeedUpdateNcAreaInIdle();
331 }
332 else
333#endif
334 {
335 win->GetUpdateRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event),
336 XExposeEventGetWidth(event), XExposeEventGetHeight(event));
ab6b6b15 337 win->GetClearRegion().Union( XExposeEventGetX(event), XExposeEventGetY(event),
2f12683e
RR
338 XExposeEventGetWidth(event), XExposeEventGetHeight(event));
339
340#if !wxUSE_NANOX
ab6b6b15
RR
341 XEvent tmp_event;
342 wxExposeInfo info;
343 info.window = event->xexpose.window;
344 info.found_non_matching = FALSE;
345 while (XCheckIfEvent( wxGlobalDisplay(), &tmp_event, expose_predicate, (XPointer) &info ))
346 {
347 win->GetUpdateRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y,
348 tmp_event.xexpose.width, tmp_event.xexpose.height );
e2386592 349
ab6b6b15
RR
350 win->GetClearRegion().Union( tmp_event.xexpose.x, tmp_event.xexpose.y,
351 tmp_event.xexpose.width, tmp_event.xexpose.height );
352 }
2f12683e 353#endif
c2c0dabf
RR
354
355 // This simplifies the expose and clear areas to simple
356 // rectangles.
357 win->GetUpdateRegion() = win->GetUpdateRegion().GetBox();
358 win->GetClearRegion() = win->GetClearRegion().GetBox();
e2386592 359
c2c0dabf 360 // If we only have one X11 window, always indicate
e2386592 361 // that borders might have to be redrawn.
f41bc3e3 362 if (win->GetMainWindow() == win->GetClientAreaWindow())
ab6b6b15 363 win->NeedUpdateNcAreaInIdle();
2f12683e 364
ab6b6b15
RR
365 // Only erase background, paint in idle time.
366 win->SendEraseEvents();
09a1dffa
JS
367
368 // EXPERIMENT
369 //win->Update();
ab6b6b15 370 }
2f12683e
RR
371
372 return TRUE;
373 }
e2386592 374
2f12683e
RR
375#if !wxUSE_NANOX
376 case GraphicsExpose:
377 {
89cd4125 378 wxLogTrace( _T("expose"), _T("GraphicsExpose from %s"), win->GetName().c_str());
e2386592 379
2f12683e
RR
380 win->GetUpdateRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y,
381 event->xgraphicsexpose.width, event->xgraphicsexpose.height);
e2386592 382
2f12683e
RR
383 win->GetClearRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y,
384 event->xgraphicsexpose.width, event->xgraphicsexpose.height);
e2386592 385
2f12683e
RR
386 if (event->xgraphicsexpose.count == 0)
387 {
388 // Only erase background, paint in idle time.
389 win->SendEraseEvents();
c2c0dabf 390 // win->Update();
2f12683e
RR
391 }
392
393 return TRUE;
394 }
395#endif
396
1b0fb34b 397 case KeyPress:
83df96d6 398 {
9d2cef1c 399 if (!win->IsEnabled())
086fd560 400 return FALSE;
b513212d 401
9d2cef1c
RR
402 wxKeyEvent keyEvent(wxEVT_KEY_DOWN);
403 wxTranslateKeyEvent(keyEvent, win, window, event);
e2386592 404
9d2cef1c 405 // wxLogDebug( "OnKey from %s", win->GetName().c_str() );
e2386592 406
120b822d
RR
407 // We didn't process wxEVT_KEY_DOWN, so send wxEVT_CHAR
408 if (win->GetEventHandler()->ProcessEvent( keyEvent ))
409 return TRUE;
e2386592 410
120b822d 411 keyEvent.SetEventType(wxEVT_CHAR);
2b5f62a0
VZ
412 // Do the translation again, retaining the ASCII
413 // code.
414 wxTranslateKeyEvent(keyEvent, win, window, event, TRUE);
120b822d
RR
415 if (win->GetEventHandler()->ProcessEvent( keyEvent ))
416 return TRUE;
e2386592 417
120b822d
RR
418 if ( (keyEvent.m_keyCode == WXK_TAB) &&
419 win->GetParent() && (win->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )
9d2cef1c 420 {
120b822d
RR
421 wxNavigationKeyEvent new_event;
422 new_event.SetEventObject( win->GetParent() );
423 /* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
424 new_event.SetDirection( (keyEvent.m_keyCode == WXK_TAB) );
425 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
426 new_event.SetWindowChange( keyEvent.ControlDown() );
427 new_event.SetCurrentFocus( win );
428 return win->GetParent()->GetEventHandler()->ProcessEvent( new_event );
1b0fb34b 429 }
120b822d
RR
430
431 return FALSE;
83df96d6 432 }
1b0fb34b 433 case KeyRelease:
7eaac9f5 434 {
9d2cef1c 435 if (!win->IsEnabled())
086fd560 436 return FALSE;
b513212d 437
9d2cef1c
RR
438 wxKeyEvent keyEvent(wxEVT_KEY_UP);
439 wxTranslateKeyEvent(keyEvent, win, window, event);
e2386592 440
086fd560 441 return win->GetEventHandler()->ProcessEvent( keyEvent );
7eaac9f5 442 }
256d631a
JS
443 case ConfigureNotify:
444 {
c79a329d 445#if wxUSE_NANOX
9d2cef1c 446 if (event->update.utype == GR_UPDATE_SIZE)
c79a329d 447#endif
256d631a 448 {
3cd2f0bd
VZ
449 wxTopLevelWindow *tlw = wxDynamicCast(win, wxTopLevelWindow);
450 if ( tlw )
c2c0dabf 451 {
c2c0dabf
RR
452 tlw->SetConfigureGeometry( XConfigureEventGetX(event), XConfigureEventGetY(event),
453 XConfigureEventGetWidth(event), XConfigureEventGetHeight(event) );
454 }
e2386592 455
3cd2f0bd 456 if ( tlw && tlw->IsShown() )
77df2fbc 457 {
77df2fbc
RR
458 tlw->SetNeedResizeInIdle();
459 }
460 else
461 {
462 wxSizeEvent sizeEvent( wxSize(XConfigureEventGetWidth(event), XConfigureEventGetHeight(event)), win->GetId() );
463 sizeEvent.SetEventObject( win );
e2386592 464
77df2fbc
RR
465 return win->GetEventHandler()->ProcessEvent( sizeEvent );
466 }
256d631a 467 }
086fd560 468 return FALSE;
256d631a
JS
469 }
470#if !wxUSE_NANOX
1b0fb34b 471 case PropertyNotify:
7eaac9f5 472 {
0b5c0e1a 473 //wxLogDebug("PropertyNotify: %s", windowClass.c_str());
086fd560 474 return HandlePropertyChange(_event);
7eaac9f5 475 }
b513212d 476 case ClientMessage:
3a0b23eb 477 {
9d2cef1c 478 if (!win->IsEnabled())
086fd560 479 return FALSE;
3a0b23eb 480
7e4501ee
RR
481 Atom wm_delete_window = XInternAtom(wxGlobalDisplay(), "WM_DELETE_WINDOW", True);
482 Atom wm_protocols = XInternAtom(wxGlobalDisplay(), "WM_PROTOCOLS", True);
b513212d
JS
483
484 if (event->xclient.message_type == wm_protocols)
485 {
6a44bffd 486 if ((Atom) (event->xclient.data.l[0]) == wm_delete_window)
b513212d 487 {
9d2cef1c 488 win->Close(FALSE);
086fd560 489 return TRUE;
b513212d
JS
490 }
491 }
086fd560 492 return FALSE;
b513212d 493 }
2f12683e
RR
494#if 0
495 case DestroyNotify:
496 {
497 printf( "destroy from %s\n", win->GetName().c_str() );
498 break;
499 }
500 case CreateNotify:
501 {
502 printf( "create from %s\n", win->GetName().c_str() );
503 break;
504 }
505 case MapRequest:
506 {
507 printf( "map request from %s\n", win->GetName().c_str() );
508 break;
509 }
1b0fb34b 510 case ResizeRequest:
7eaac9f5 511 {
2f12683e 512 printf( "resize request from %s\n", win->GetName().c_str() );
e2386592 513
7266b672 514 Display *disp = (Display*) wxGetDisplay();
1b0fb34b 515 XEvent report;
e2386592 516
1b0fb34b
JS
517 // to avoid flicker
518 report = * event;
519 while( XCheckTypedWindowEvent (disp, actualWindow, ResizeRequest, &report));
e2386592 520
b1633d20
RR
521 wxSize sz = win->GetSize();
522 wxSizeEvent sizeEvent(sz, win->GetId());
523 sizeEvent.SetEventObject(win);
1b0fb34b 524
b1633d20 525 return win->GetEventHandler()->ProcessEvent( sizeEvent );
7eaac9f5 526 }
256d631a 527#endif
b1633d20 528#endif
256d631a
JS
529#if wxUSE_NANOX
530 case GR_EVENT_TYPE_CLOSE_REQ:
531 {
532 if (win)
533 {
534 win->Close(FALSE);
086fd560 535 return TRUE;
256d631a 536 }
086fd560 537 return FALSE;
256d631a
JS
538 break;
539 }
c79a329d 540#endif
1b0fb34b
JS
541 case EnterNotify:
542 case LeaveNotify:
543 case ButtonPress:
544 case ButtonRelease:
545 case MotionNotify:
7eaac9f5 546 {
7e4501ee 547 if (!win->IsEnabled())
086fd560 548 return FALSE;
366e8ae6 549
9691c806
RR
550 // Here we check if the top level window is
551 // disabled, which is one aspect of modality.
552 wxWindow *tlw = win;
553 while (tlw && !tlw->IsTopLevel())
554 tlw = tlw->GetParent();
555 if (tlw && !tlw->IsEnabled())
086fd560 556 return FALSE;
e2386592 557
7e4501ee 558 if (event->type == ButtonPress)
1b0fb34b 559 {
7e4501ee 560 if ((win != wxWindow::FindFocus()) && win->AcceptsFocus())
9d2cef1c
RR
561 {
562 // This might actually be done in wxWindow::SetFocus()
ea1ad04b 563 // and not here. TODO.
9d2cef1c
RR
564 g_prevFocus = wxWindow::FindFocus();
565 g_nextFocus = win;
e2386592 566
58ec2255
JS
567 wxLogTrace( _T("focus"), _T("About to call SetFocus on %s of type %s due to button press"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
568
569 // Record the fact that this window is
570 // getting the focus, because we'll need to
571 // check if its parent is getting a bogus
572 // focus and duly ignore it.
573 // TODO: may need to have this code in SetFocus, too.
574 extern wxWindow* g_GettingFocus;
575 g_GettingFocus = win;
9d2cef1c
RR
576 win->SetFocus();
577 }
1b0fb34b 578 }
e2386592 579
ea1ad04b
RR
580#if !wxUSE_NANOX
581 if (event->type == LeaveNotify || event->type == EnterNotify)
582 {
583 // Throw out NotifyGrab and NotifyUngrab
584 if (event->xcrossing.mode != NotifyNormal)
086fd560 585 return FALSE;
ea1ad04b
RR
586 }
587#endif
7e4501ee
RR
588 wxMouseEvent wxevent;
589 wxTranslateMouseEvent(wxevent, win, window, event);
086fd560 590 return win->GetEventHandler()->ProcessEvent( wxevent );
7eaac9f5 591 }
1b0fb34b 592 case FocusIn:
256d631a 593#if !wxUSE_NANOX
bcd3832a
VZ
594 if ((event->xfocus.detail != NotifyPointer) &&
595 (event->xfocus.mode == NotifyNormal))
256d631a 596#endif
bcd3832a
VZ
597 {
598 wxLogTrace( _T("focus"), _T("FocusIn from %s of type %s"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
599
600 extern wxWindow* g_GettingFocus;
601 if (g_GettingFocus && g_GettingFocus->GetParent() == win)
602 {
603 // Ignore this, this can be a spurious FocusIn
604 // caused by a child having its focus set.
605 g_GettingFocus = NULL;
606 wxLogTrace( _T("focus"), _T("FocusIn from %s of type %s being deliberately ignored"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
607 return TRUE;
608 }
609 else
1b0fb34b 610 {
bcd3832a
VZ
611 wxFocusEvent focusEvent(wxEVT_SET_FOCUS, win->GetId());
612 focusEvent.SetEventObject(win);
613 focusEvent.SetWindow( g_prevFocus );
614 g_prevFocus = NULL;
366e8ae6 615
bcd3832a 616 return win->GetEventHandler()->ProcessEvent(focusEvent);
1b0fb34b 617 }
1b0fb34b 618 }
bcd3832a
VZ
619 return FALSE;
620
1b0fb34b 621 case FocusOut:
256d631a 622#if !wxUSE_NANOX
bcd3832a
VZ
623 if ((event->xfocus.detail != NotifyPointer) &&
624 (event->xfocus.mode == NotifyNormal))
256d631a 625#endif
bcd3832a
VZ
626 {
627 wxLogTrace( _T("focus"), _T("FocusOut from %s of type %s"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
e2386592 628
bcd3832a
VZ
629 wxFocusEvent focusEvent(wxEVT_KILL_FOCUS, win->GetId());
630 focusEvent.SetEventObject(win);
631 focusEvent.SetWindow( g_nextFocus );
632 g_nextFocus = NULL;
633 return win->GetEventHandler()->ProcessEvent(focusEvent);
1b0fb34b 634 }
bcd3832a
VZ
635 return FALSE;
636
45ff6421 637#ifdef __WXDEBUG__
bcd3832a 638 default:
45ff6421
JS
639 //wxString eventName = wxGetXEventName(XEvent& event);
640 //wxLogDebug(wxT("Event %s not handled"), eventName.c_str());
5b3b52ef 641 break;
bcd3832a 642#endif // __WXDEBUG__
83df96d6 643 }
83df96d6 644
bcd3832a 645 return FALSE;
83df96d6
JS
646}
647
648// This should be redefined in a derived class for
649// handling property change events for XAtom IPC.
086fd560 650bool wxApp::HandlePropertyChange(WXEvent *event)
83df96d6
JS
651{
652 // by default do nothing special
7eaac9f5 653 // TODO: what to do for X11
256d631a 654 // XtDispatchEvent((XEvent*) event);
086fd560 655 return FALSE;
83df96d6
JS
656}
657
e2478fde 658void wxApp::WakeUpIdle()
83df96d6 659{
e2478fde
VZ
660 // TODO: use wxMotif implementation?
661
83df96d6
JS
662 // Wake up the idle handler processor, even if it is in another thread...
663}
664
665
256d631a 666// Create display, and other initialization
83df96d6
JS
667bool wxApp::OnInitGui()
668{
ca7497c2
JS
669 // Eventually this line will be removed, but for
670 // now we don't want to try popping up a dialog
671 // for error messages.
672 delete wxLog::SetActiveTarget(new wxLogStderr);
e2386592 673
ea596687 674 if (!wxAppBase::OnInitGui())
dc4025af 675 return FALSE;
e2386592 676
a11672a4 677 GetMainColormap( wxApp::GetDisplay() );
256d631a 678
a11672a4 679 m_maxRequestSize = XMaxRequestSize( (Display*) wxApp::GetDisplay() );
83df96d6 680
8601b2e1 681#if !wxUSE_NANOX
9ce8d6a2
MB
682 m_visualInfo = new wxXVisualInfo;
683 wxFillXVisualInfo( m_visualInfo, (Display*) wxApp::GetDisplay() );
8601b2e1 684#endif
366e8ae6 685
83df96d6
JS
686 return TRUE;
687}
688
2b5f62a0
VZ
689#if wxUSE_UNICODE
690
691#include <pango/pango.h>
692#include <pango/pangox.h>
4ae1af05
MB
693#ifdef HAVE_PANGO_XFT
694 #include <pango/pangoxft.h>
695#endif
2b5f62a0
VZ
696
697PangoContext* wxApp::GetPangoContext()
698{
699 static PangoContext *ret = NULL;
700 if (ret)
701 return ret;
7c9955d1 702
2b5f62a0 703 Display *xdisplay = (Display*) wxApp::GetDisplay();
7c9955d1 704
4ae1af05 705#ifdef HAVE_PANGO_XFT
2b5f62a0
VZ
706 int xscreen = DefaultScreen(xdisplay);
707 static int use_xft = -1;
708 if (use_xft == -1)
709 {
710 wxString val = wxGetenv( L"GDK_USE_XFT" );
711 use_xft = (val == L"1");
712 }
7c9955d1 713
2b5f62a0
VZ
714 if (use_xft)
715 ret = pango_xft_get_context( xdisplay, xscreen );
716 else
717#endif
718 ret = pango_x_get_context( xdisplay );
7c9955d1 719
2b5f62a0
VZ
720 if (!PANGO_IS_CONTEXT(ret))
721 wxLogError( wxT("No pango context.") );
7c9955d1 722
2b5f62a0
VZ
723 return ret;
724}
725#endif
726
83df96d6
JS
727WXColormap wxApp::GetMainColormap(WXDisplay* display)
728{
729 if (!display) /* Must be called first with non-NULL display */
730 return m_mainColormap;
731
732 int defaultScreen = DefaultScreen((Display*) display);
733 Screen* screen = XScreenOfDisplay((Display*) display, defaultScreen);
734
735 Colormap c = DefaultColormapOfScreen(screen);
736
737 if (!m_mainColormap)
738 m_mainColormap = (WXColormap) c;
739
740 return (WXColormap) c;
741}
742
8354aa92 743Window wxGetWindowParent(Window window)
7eaac9f5 744{
54385bdb 745 wxASSERT_MSG( window, _T("invalid window") );
e2386592 746
86fd8bda
RR
747 return (Window) 0;
748
a371f703
JJ
749#ifndef __VMS
750 // VMS chokes on unreacheable code
751 Window parent, root = 0;
c79a329d
JS
752#if wxUSE_NANOX
753 int noChildren = 0;
754#else
7eaac9f5 755 unsigned int noChildren = 0;
c79a329d 756#endif
ea596687 757 Window* children = NULL;
c79a329d 758
ee351013 759 // #define XQueryTree(d,w,r,p,c,nc) GrQueryTree(w,p,c,nc)
c79a329d
JS
760 int res = 1;
761#if !wxUSE_NANOX
762 res =
763#endif
764 XQueryTree((Display*) wxGetDisplay(), window, & root, & parent,
ee351013 765 & children, & noChildren);
ea596687
JS
766 if (children)
767 XFree(children);
768 if (res)
7eaac9f5
JS
769 return parent;
770 else
771 return (Window) 0;
a371f703 772#endif
7eaac9f5
JS
773}
774
e2478fde 775void wxApp::Exit()
83df96d6 776{
83df96d6 777 wxApp::CleanUp();
e2478fde
VZ
778
779 wxAppConsole::Exit();
83df96d6
JS
780}
781
782// Yield to other processes
783
784bool wxApp::Yield(bool onlyIfNeeded)
785{
bbcd408a
JS
786 // Sometimes only 2 yields seem
787 // to do the trick, e.g. in the
788 // progress dialog
789 int i;
790 for (i = 0; i < 2; i++)
83df96d6 791 {
f6afb56a 792 static bool s_inYield = FALSE;
bbcd408a
JS
793
794 if ( s_inYield )
83df96d6 795 {
bbcd408a
JS
796 if ( !onlyIfNeeded )
797 {
798 wxFAIL_MSG( wxT("wxYield called recursively" ) );
799 }
83df96d6 800
bbcd408a
JS
801 return FALSE;
802 }
83df96d6 803
bbcd408a 804 s_inYield = TRUE;
83df96d6 805
bbcd408a
JS
806 // Make sure we have an event loop object,
807 // or Pending/Dispatch will fail
808 wxEventLoop* eventLoop = wxEventLoop::GetActive();
809 wxEventLoop* newEventLoop = NULL;
810 if (!eventLoop)
811 {
812 newEventLoop = new wxEventLoop;
813 wxEventLoop::SetActive(newEventLoop);
814 }
df0e1b64 815
2b5f62a0
VZ
816 // Call dispatch at least once so that sockets
817 // can be tested
818 wxTheApp->Dispatch();
7c9955d1 819
bbcd408a
JS
820 while (wxTheApp && wxTheApp->Pending())
821 wxTheApp->Dispatch();
83df96d6 822
868741e9 823#if wxUSE_TIMER
bbcd408a 824 wxTimer::NotifyTimers();
868741e9 825#endif
bbcd408a 826 ProcessIdle();
868741e9 827
bbcd408a
JS
828 if (newEventLoop)
829 {
830 wxEventLoop::SetActive(NULL);
831 delete newEventLoop;
832 }
df0e1b64 833
bbcd408a
JS
834 s_inYield = FALSE;
835 }
83df96d6
JS
836
837 return TRUE;
838}
839
d715d419
VZ
840#ifdef __WXDEBUG__
841
5968a0dc 842void wxApp::OnAssert(const wxChar *file, int line, const wxChar* cond, const wxChar *msg)
7edcafa4
JS
843{
844 // While the GUI isn't working that well, just print out the
845 // message.
193e19cf 846#if 1
5968a0dc 847 wxAppBase::OnAssert(file, line, cond, msg);
7edcafa4
JS
848#else
849 wxString msg2;
850 msg2.Printf("At file %s:%d: %s", file, line, msg);
851 wxLogDebug(msg2);
852#endif
853}
854
d715d419
VZ
855#endif // __WXDEBUG__
856