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