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