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