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