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