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