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