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