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