]> git.saurik.com Git - wxWidgets.git/blame - src/x11/app.cpp
Commit mentioned fix/hack to enable controls
[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
9// Licence: wxWindows licence
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
9d2cef1c 49wxHashTable *wxWidgetHashTable = NULL;
ab6b6b15 50wxHashTable *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 {
176 wxLogError( _("wxWindows 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
05e2b077
VZ
206 wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER);
207 wxClientWidgetHashTable = new wxHashTable(wxKEY_INTEGER);
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 {
c2c0dabf
RR
449 if (win->IsTopLevel())
450 {
451 wxTopLevelWindow *tlw = (wxTopLevelWindow*) win;
452 tlw->SetConfigureGeometry( XConfigureEventGetX(event), XConfigureEventGetY(event),
453 XConfigureEventGetWidth(event), XConfigureEventGetHeight(event) );
454 }
e2386592 455
2f12683e 456 if (win->IsTopLevel() && win->IsShown())
77df2fbc
RR
457 {
458 wxTopLevelWindowX11 *tlw = (wxTopLevelWindowX11 *) win;
459 tlw->SetNeedResizeInIdle();
460 }
461 else
462 {
463 wxSizeEvent sizeEvent( wxSize(XConfigureEventGetWidth(event), XConfigureEventGetHeight(event)), win->GetId() );
464 sizeEvent.SetEventObject( win );
e2386592 465
77df2fbc
RR
466 return win->GetEventHandler()->ProcessEvent( sizeEvent );
467 }
256d631a 468 }
086fd560 469 return FALSE;
c2ff68d3 470 break;
256d631a
JS
471 }
472#if !wxUSE_NANOX
1b0fb34b 473 case PropertyNotify:
7eaac9f5 474 {
0b5c0e1a 475 //wxLogDebug("PropertyNotify: %s", windowClass.c_str());
086fd560 476 return HandlePropertyChange(_event);
7eaac9f5 477 }
b513212d 478 case ClientMessage:
3a0b23eb 479 {
9d2cef1c 480 if (!win->IsEnabled())
086fd560 481 return FALSE;
3a0b23eb 482
7e4501ee
RR
483 Atom wm_delete_window = XInternAtom(wxGlobalDisplay(), "WM_DELETE_WINDOW", True);
484 Atom wm_protocols = XInternAtom(wxGlobalDisplay(), "WM_PROTOCOLS", True);
b513212d
JS
485
486 if (event->xclient.message_type == wm_protocols)
487 {
6a44bffd 488 if ((Atom) (event->xclient.data.l[0]) == wm_delete_window)
b513212d 489 {
9d2cef1c 490 win->Close(FALSE);
086fd560 491 return TRUE;
b513212d
JS
492 }
493 }
086fd560 494 return FALSE;
b513212d 495 }
2f12683e
RR
496#if 0
497 case DestroyNotify:
498 {
499 printf( "destroy from %s\n", win->GetName().c_str() );
500 break;
501 }
502 case CreateNotify:
503 {
504 printf( "create from %s\n", win->GetName().c_str() );
505 break;
506 }
507 case MapRequest:
508 {
509 printf( "map request from %s\n", win->GetName().c_str() );
510 break;
511 }
1b0fb34b 512 case ResizeRequest:
7eaac9f5 513 {
2f12683e 514 printf( "resize request from %s\n", win->GetName().c_str() );
e2386592 515
7266b672 516 Display *disp = (Display*) wxGetDisplay();
1b0fb34b 517 XEvent report;
e2386592 518
1b0fb34b
JS
519 // to avoid flicker
520 report = * event;
521 while( XCheckTypedWindowEvent (disp, actualWindow, ResizeRequest, &report));
e2386592 522
b1633d20
RR
523 wxSize sz = win->GetSize();
524 wxSizeEvent sizeEvent(sz, win->GetId());
525 sizeEvent.SetEventObject(win);
1b0fb34b 526
b1633d20 527 return win->GetEventHandler()->ProcessEvent( sizeEvent );
7eaac9f5 528 }
256d631a 529#endif
b1633d20 530#endif
256d631a
JS
531#if wxUSE_NANOX
532 case GR_EVENT_TYPE_CLOSE_REQ:
533 {
534 if (win)
535 {
536 win->Close(FALSE);
086fd560 537 return TRUE;
256d631a 538 }
086fd560 539 return FALSE;
256d631a
JS
540 break;
541 }
c79a329d 542#endif
1b0fb34b
JS
543 case EnterNotify:
544 case LeaveNotify:
545 case ButtonPress:
546 case ButtonRelease:
547 case MotionNotify:
7eaac9f5 548 {
7e4501ee 549 if (!win->IsEnabled())
086fd560 550 return FALSE;
366e8ae6 551
9691c806
RR
552 // Here we check if the top level window is
553 // disabled, which is one aspect of modality.
554 wxWindow *tlw = win;
555 while (tlw && !tlw->IsTopLevel())
556 tlw = tlw->GetParent();
557 if (tlw && !tlw->IsEnabled())
086fd560 558 return FALSE;
e2386592 559
7e4501ee 560 if (event->type == ButtonPress)
1b0fb34b 561 {
7e4501ee 562 if ((win != wxWindow::FindFocus()) && win->AcceptsFocus())
9d2cef1c
RR
563 {
564 // This might actually be done in wxWindow::SetFocus()
ea1ad04b 565 // and not here. TODO.
9d2cef1c
RR
566 g_prevFocus = wxWindow::FindFocus();
567 g_nextFocus = win;
e2386592 568
58ec2255
JS
569 wxLogTrace( _T("focus"), _T("About to call SetFocus on %s of type %s due to button press"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
570
571 // Record the fact that this window is
572 // getting the focus, because we'll need to
573 // check if its parent is getting a bogus
574 // focus and duly ignore it.
575 // TODO: may need to have this code in SetFocus, too.
576 extern wxWindow* g_GettingFocus;
577 g_GettingFocus = win;
9d2cef1c
RR
578 win->SetFocus();
579 }
1b0fb34b 580 }
e2386592 581
ea1ad04b
RR
582#if !wxUSE_NANOX
583 if (event->type == LeaveNotify || event->type == EnterNotify)
584 {
585 // Throw out NotifyGrab and NotifyUngrab
586 if (event->xcrossing.mode != NotifyNormal)
086fd560 587 return FALSE;
ea1ad04b
RR
588 }
589#endif
7e4501ee
RR
590 wxMouseEvent wxevent;
591 wxTranslateMouseEvent(wxevent, win, window, event);
086fd560 592 return win->GetEventHandler()->ProcessEvent( wxevent );
7eaac9f5 593 }
1b0fb34b 594 case FocusIn:
256d631a 595#if !wxUSE_NANOX
bcd3832a
VZ
596 if ((event->xfocus.detail != NotifyPointer) &&
597 (event->xfocus.mode == NotifyNormal))
256d631a 598#endif
bcd3832a
VZ
599 {
600 wxLogTrace( _T("focus"), _T("FocusIn from %s of type %s"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
601
602 extern wxWindow* g_GettingFocus;
603 if (g_GettingFocus && g_GettingFocus->GetParent() == win)
604 {
605 // Ignore this, this can be a spurious FocusIn
606 // caused by a child having its focus set.
607 g_GettingFocus = NULL;
608 wxLogTrace( _T("focus"), _T("FocusIn from %s of type %s being deliberately ignored"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
609 return TRUE;
610 }
611 else
1b0fb34b 612 {
bcd3832a
VZ
613 wxFocusEvent focusEvent(wxEVT_SET_FOCUS, win->GetId());
614 focusEvent.SetEventObject(win);
615 focusEvent.SetWindow( g_prevFocus );
616 g_prevFocus = NULL;
366e8ae6 617
bcd3832a 618 return win->GetEventHandler()->ProcessEvent(focusEvent);
1b0fb34b 619 }
1b0fb34b 620 }
bcd3832a
VZ
621 return FALSE;
622
1b0fb34b 623 case FocusOut:
256d631a 624#if !wxUSE_NANOX
bcd3832a
VZ
625 if ((event->xfocus.detail != NotifyPointer) &&
626 (event->xfocus.mode == NotifyNormal))
256d631a 627#endif
bcd3832a
VZ
628 {
629 wxLogTrace( _T("focus"), _T("FocusOut from %s of type %s"), win->GetName().c_str(), win->GetClassInfo()->GetClassName() );
e2386592 630
bcd3832a
VZ
631 wxFocusEvent focusEvent(wxEVT_KILL_FOCUS, win->GetId());
632 focusEvent.SetEventObject(win);
633 focusEvent.SetWindow( g_nextFocus );
634 g_nextFocus = NULL;
635 return win->GetEventHandler()->ProcessEvent(focusEvent);
1b0fb34b 636 }
bcd3832a
VZ
637 return FALSE;
638
45ff6421 639#ifdef __WXDEBUG__
bcd3832a 640 default:
45ff6421
JS
641 //wxString eventName = wxGetXEventName(XEvent& event);
642 //wxLogDebug(wxT("Event %s not handled"), eventName.c_str());
5b3b52ef 643 break;
bcd3832a 644#endif // __WXDEBUG__
83df96d6 645 }
83df96d6 646
bcd3832a 647 return FALSE;
83df96d6
JS
648}
649
650// This should be redefined in a derived class for
651// handling property change events for XAtom IPC.
086fd560 652bool wxApp::HandlePropertyChange(WXEvent *event)
83df96d6
JS
653{
654 // by default do nothing special
7eaac9f5 655 // TODO: what to do for X11
256d631a 656 // XtDispatchEvent((XEvent*) event);
086fd560 657 return FALSE;
83df96d6
JS
658}
659
e2478fde 660void wxApp::WakeUpIdle()
83df96d6 661{
e2478fde
VZ
662 // TODO: use wxMotif implementation?
663
83df96d6
JS
664 // Wake up the idle handler processor, even if it is in another thread...
665}
666
667
256d631a 668// Create display, and other initialization
83df96d6
JS
669bool wxApp::OnInitGui()
670{
ca7497c2
JS
671 // Eventually this line will be removed, but for
672 // now we don't want to try popping up a dialog
673 // for error messages.
674 delete wxLog::SetActiveTarget(new wxLogStderr);
e2386592 675
ea596687 676 if (!wxAppBase::OnInitGui())
dc4025af 677 return FALSE;
e2386592 678
a11672a4 679 GetMainColormap( wxApp::GetDisplay() );
256d631a 680
a11672a4 681 m_maxRequestSize = XMaxRequestSize( (Display*) wxApp::GetDisplay() );
83df96d6 682
8601b2e1 683#if !wxUSE_NANOX
9ce8d6a2
MB
684 m_visualInfo = new wxXVisualInfo;
685 wxFillXVisualInfo( m_visualInfo, (Display*) wxApp::GetDisplay() );
8601b2e1 686#endif
366e8ae6 687
83df96d6
JS
688 return TRUE;
689}
690
2b5f62a0
VZ
691#if wxUSE_UNICODE
692
693#include <pango/pango.h>
694#include <pango/pangox.h>
695#include <pango/pangoxft.h>
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
2b5f62a0
VZ
705#if 1
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
7eaac9f5 749 Window parent, root = 0;
c79a329d
JS
750#if wxUSE_NANOX
751 int noChildren = 0;
752#else
7eaac9f5 753 unsigned int noChildren = 0;
c79a329d 754#endif
ea596687 755 Window* children = NULL;
c79a329d 756
ee351013 757 // #define XQueryTree(d,w,r,p,c,nc) GrQueryTree(w,p,c,nc)
c79a329d
JS
758 int res = 1;
759#if !wxUSE_NANOX
760 res =
761#endif
762 XQueryTree((Display*) wxGetDisplay(), window, & root, & parent,
ee351013 763 & children, & noChildren);
ea596687
JS
764 if (children)
765 XFree(children);
766 if (res)
7eaac9f5
JS
767 return parent;
768 else
769 return (Window) 0;
770}
771
e2478fde 772void wxApp::Exit()
83df96d6 773{
83df96d6 774 wxApp::CleanUp();
e2478fde
VZ
775
776 wxAppConsole::Exit();
83df96d6
JS
777}
778
779// Yield to other processes
780
781bool wxApp::Yield(bool onlyIfNeeded)
782{
bbcd408a
JS
783 // Sometimes only 2 yields seem
784 // to do the trick, e.g. in the
785 // progress dialog
786 int i;
787 for (i = 0; i < 2; i++)
83df96d6 788 {
f6afb56a 789 static bool s_inYield = FALSE;
bbcd408a
JS
790
791 if ( s_inYield )
83df96d6 792 {
bbcd408a
JS
793 if ( !onlyIfNeeded )
794 {
795 wxFAIL_MSG( wxT("wxYield called recursively" ) );
796 }
83df96d6 797
bbcd408a
JS
798 return FALSE;
799 }
83df96d6 800
bbcd408a 801 s_inYield = TRUE;
83df96d6 802
bbcd408a
JS
803 // Make sure we have an event loop object,
804 // or Pending/Dispatch will fail
805 wxEventLoop* eventLoop = wxEventLoop::GetActive();
806 wxEventLoop* newEventLoop = NULL;
807 if (!eventLoop)
808 {
809 newEventLoop = new wxEventLoop;
810 wxEventLoop::SetActive(newEventLoop);
811 }
df0e1b64 812
2b5f62a0
VZ
813 // Call dispatch at least once so that sockets
814 // can be tested
815 wxTheApp->Dispatch();
7c9955d1 816
bbcd408a
JS
817 while (wxTheApp && wxTheApp->Pending())
818 wxTheApp->Dispatch();
83df96d6 819
868741e9 820#if wxUSE_TIMER
bbcd408a 821 wxTimer::NotifyTimers();
868741e9 822#endif
bbcd408a 823 ProcessIdle();
868741e9 824
bbcd408a
JS
825 if (newEventLoop)
826 {
827 wxEventLoop::SetActive(NULL);
828 delete newEventLoop;
829 }
df0e1b64 830
bbcd408a
JS
831 s_inYield = FALSE;
832 }
83df96d6
JS
833
834 return TRUE;
835}
836
d715d419
VZ
837#ifdef __WXDEBUG__
838
5968a0dc 839void wxApp::OnAssert(const wxChar *file, int line, const wxChar* cond, const wxChar *msg)
7edcafa4
JS
840{
841 // While the GUI isn't working that well, just print out the
842 // message.
193e19cf 843#if 1
5968a0dc 844 wxAppBase::OnAssert(file, line, cond, msg);
7edcafa4
JS
845#else
846 wxString msg2;
847 msg2.Printf("At file %s:%d: %s", file, line, msg);
848 wxLogDebug(msg2);
849#endif
850}
851
d715d419
VZ
852#endif // __WXDEBUG__
853