Added SetActive to wxEventLoop
[wxWidgets.git] / src / x11 / toplevel.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: x11/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for X11
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 24.09.01
7 // RCS-ID: $Id$
8 // Copyright: (c) 2002 Julian Smart
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "toplevel.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/app.h"
33 #include "wx/toplevel.h"
34 #include "wx/string.h"
35 #include "wx/log.h"
36 #include "wx/intl.h"
37 #include "wx/frame.h"
38 #include "wx/menu.h"
39 #include "wx/statusbr.h"
40 #endif //WX_PRECOMP
41
42 #include "wx/settings.h"
43 #include "wx/x11/private.h"
44 #include "X11/Xutil.h"
45
46 bool wxMWMIsRunning(Window w);
47
48 // ----------------------------------------------------------------------------
49 // wxTopLevelWindowX11 creation
50 // ----------------------------------------------------------------------------
51
52 void wxTopLevelWindowX11::Init()
53 {
54 m_iconized =
55 m_maximizeOnShow = FALSE;
56
57 // unlike (almost?) all other windows, frames are created hidden
58 m_isShown = FALSE;
59
60 // Data to save/restore when calling ShowFullScreen
61 m_fsStyle = 0;
62 m_fsIsMaximized = FALSE;
63 m_fsIsShowing = FALSE;
64
65 m_needResizeInIdle = FALSE;
66 }
67
68 bool wxTopLevelWindowX11::Create(wxWindow *parent,
69 wxWindowID id,
70 const wxString& title,
71 const wxPoint& pos,
72 const wxSize& size,
73 long style,
74 const wxString& name)
75 {
76 // init our fields
77 Init();
78
79 m_windowStyle = style;
80 m_parent = parent;
81
82 SetName(name);
83
84 m_windowId = id == -1 ? NewControlId() : id;
85
86 if (parent)
87 parent->AddChild(this);
88
89 wxTopLevelWindows.Append(this);
90
91 Display *xdisplay = wxGlobalDisplay();
92 int xscreen = DefaultScreen( xdisplay );
93 Visual *xvisual = DefaultVisual( xdisplay, xscreen );
94 Window xparent = RootWindow( xdisplay, xscreen );
95 Colormap cm = DefaultColormap( xdisplay, xscreen );
96
97 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)
98 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
99 else
100 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
101 m_backgroundColour.CalcPixel( (WXColormap) cm );
102 m_hasBgCol = TRUE;
103
104 wxSize size2(size);
105 if (size2.x == -1)
106 size2.x = 100;
107 if (size2.y == -1)
108 size2.y = 100;
109
110 wxPoint pos2(pos);
111 if (pos2.x == -1)
112 pos2.x = 100;
113 if (pos2.y == -1)
114 pos2.y = 100;
115
116 #if !wxUSE_NANOX
117 XSetWindowAttributes xattributes;
118 XSizeHints size_hints;
119
120 long xattributes_mask =
121 CWBorderPixel | CWBackPixel;
122
123 xattributes.background_pixel = m_backgroundColour.GetPixel();
124 xattributes.border_pixel = BlackPixel( xdisplay, xscreen );
125
126 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE ))
127 {
128 xattributes_mask |= CWBitGravity;
129 xattributes.bit_gravity = StaticGravity;
130 }
131
132 xattributes_mask |= CWEventMask;
133 xattributes.event_mask =
134 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
135 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
136 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
137 PropertyChangeMask;
138
139 Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y,
140 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
141 #else
142 long backColor, foreColor;
143 backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue());
144 foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue());
145
146 Window xwindow = XCreateWindowWithColor( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y,
147 0, 0, InputOutput, xvisual, backColor, foreColor);
148 #endif
149
150 m_mainWidget = (WXWindow) xwindow;
151
152 #if wxUSE_NANOX
153 XSelectInput( xdisplay, xwindow,
154 GR_EVENT_MASK_CLOSE_REQ |
155 ExposureMask |
156 KeyPressMask |
157 KeyReleaseMask |
158 ButtonPressMask |
159 ButtonReleaseMask |
160 ButtonMotionMask |
161 EnterWindowMask |
162 LeaveWindowMask |
163 PointerMotionMask |
164 KeymapStateMask |
165 FocusChangeMask |
166 ColormapChangeMask |
167 StructureNotifyMask |
168 PropertyChangeMask
169 );
170 #endif
171
172 wxAddWindowToTable( xwindow, (wxWindow*) this );
173
174 // Set background to None which will prevent X11 from clearing the
175 // background completely.
176 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
177
178 #if !wxUSE_NANOX
179 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)
180 {
181 if (GetParent() && GetParent()->GetMainWindow())
182 {
183 Window xparentwindow = (Window) GetParent()->GetMainWindow();
184 XSetTransientForHint( xdisplay, xwindow, xparentwindow );
185 }
186 }
187
188 size_hints.flags = PSize | PPosition;
189 size_hints.x = pos2.x;
190 size_hints.y = pos2.y;
191 size_hints.width = size2.x;
192 size_hints.height = size2.y;
193 XSetWMNormalHints( xdisplay, xwindow, &size_hints);
194
195 XWMHints wm_hints;
196 wm_hints.flags = InputHint | StateHint /* | WindowGroupHint */;
197 wm_hints.input = True;
198 wm_hints.initial_state = NormalState;
199 XSetWMHints( xdisplay, xwindow, &wm_hints);
200
201 Atom wm_protocols[2];
202 wm_protocols[0] = XInternAtom( xdisplay, "WM_DELETE_WINDOW", False );
203 wm_protocols[1] = XInternAtom( xdisplay, "WM_TAKE_FOCUS", False );
204 XSetWMProtocols( xdisplay, xwindow, wm_protocols, 2);
205
206 #if 0 // TODO
207 // You will need a compliant window manager for this to work
208 // (e.g. sawfish/enlightenment/kde/icewm/windowmaker)
209 if (style & wxSTAY_ON_TOP)
210 {
211 CARD32 data = 4; // or should this be 6? According to http://developer.gnome.org/doc/standards/wm/c44.html
212 XChangeProperty (xdisplay,
213 xwindow,
214 XInternAtom (xdisplay, "_WIN_LAYER", False),
215 XA_CARDINAL,
216 32,
217 PropModeReplace,
218 (unsigned char *)&data,
219 1);
220 }
221 #endif
222
223 #endif
224
225 wxSetWMDecorations( xwindow, style);
226
227 SetTitle(title);
228
229 return TRUE;
230 }
231
232 wxTopLevelWindowX11::~wxTopLevelWindowX11()
233 {
234 wxTopLevelWindows.DeleteObject(this);
235
236 // If this is the last top-level window, exit.
237 if ( wxTheApp && (wxTopLevelWindows.Number() == 0) )
238 {
239 wxTheApp->SetTopWindow(NULL);
240
241 if (wxTheApp->GetExitOnFrameDelete())
242 {
243 // Signal to the app that we're going to close
244 wxTheApp->ExitMainLoop();
245 }
246 }
247 }
248
249 void wxTopLevelWindowX11::OnInternalIdle()
250 {
251 wxWindow::OnInternalIdle();
252
253 if (m_needResizeInIdle)
254 {
255 wxSizeEvent event( GetClientSize(), GetId() );
256 event.SetEventObject( this );
257 GetEventHandler()->ProcessEvent( event );
258
259 m_needResizeInIdle = FALSE;
260 }
261 }
262
263 // ----------------------------------------------------------------------------
264 // wxTopLevelWindowX11 showing
265 // ----------------------------------------------------------------------------
266
267 bool wxTopLevelWindowX11::Show(bool show)
268 {
269 // Nano-X has to force a size event,
270 // else there's no initial size.
271 #if wxUSE_NANOX
272 if (show)
273 #else
274 if (show && m_needResizeInIdle)
275 #endif
276 {
277 wxSizeEvent event(GetSize(), GetId());
278 event.SetEventObject(this);
279 GetEventHandler()->ProcessEvent(event);
280
281 m_needResizeInIdle = FALSE;
282 }
283 if (show)
284 {
285 // This does the layout _before_ the
286 // window is shown, else the items are
287 // drawn first at the wrong positions,
288 // then at the correct positions.
289 if (GetAutoLayout())
290 {
291 Layout();
292 }
293 }
294 wxYield();
295
296 bool ret = wxWindowX11::Show(show);
297 return ret;
298 }
299
300 // ----------------------------------------------------------------------------
301 // wxTopLevelWindowX11 maximize/minimize
302 // ----------------------------------------------------------------------------
303
304 void wxTopLevelWindowX11::Maximize(bool maximize)
305 {
306 // TODO
307 }
308
309 bool wxTopLevelWindowX11::IsMaximized() const
310 {
311 // TODO
312 return TRUE;
313 }
314
315 void wxTopLevelWindowX11::Iconize(bool iconize)
316 {
317 if (!m_iconized && GetMainWindow())
318 {
319 if (XIconifyWindow(wxGlobalDisplay(),
320 (Window) GetMainWindow(), DefaultScreen(wxGlobalDisplay())) != 0)
321 m_iconized = TRUE;
322 }
323 }
324
325 bool wxTopLevelWindowX11::IsIconized() const
326 {
327 return m_iconized;
328 }
329
330 void wxTopLevelWindowX11::Restore()
331 {
332 // This is the way to deiconify the window, according to the X FAQ
333 if (m_iconized && GetMainWindow())
334 {
335 XMapWindow(wxGlobalDisplay(), (Window) GetMainWindow());
336 m_iconized = FALSE;
337 }
338 }
339
340 // ----------------------------------------------------------------------------
341 // wxTopLevelWindowX11 fullscreen
342 // ----------------------------------------------------------------------------
343
344 bool wxTopLevelWindowX11::ShowFullScreen(bool show, long style)
345 {
346 if (show)
347 {
348 if (IsFullScreen())
349 return FALSE;
350
351 m_fsIsShowing = TRUE;
352 m_fsStyle = style;
353
354 // TODO
355
356 return TRUE;
357 }
358 else
359 {
360 if (!IsFullScreen())
361 return FALSE;
362
363 m_fsIsShowing = FALSE;
364
365 // TODO
366 return TRUE;
367 }
368 }
369
370 // ----------------------------------------------------------------------------
371 // wxTopLevelWindowX11 misc
372 // ----------------------------------------------------------------------------
373
374 void wxTopLevelWindowX11::SetIcon(const wxIcon& icon)
375 {
376 // this sets m_icon
377 wxTopLevelWindowBase::SetIcon(icon);
378
379 if (icon.Ok() && GetMainWindow())
380 {
381 #if wxUSE_NANOX
382 #else
383 XWMHints *wmHints = XAllocWMHints();
384 wmHints->icon_pixmap = (Pixmap) icon.GetPixmap();
385
386 wmHints->flags = IconPixmapHint;
387
388 if (icon.GetMask())
389 {
390 wmHints->flags |= IconMaskHint;
391 wmHints->icon_mask = (Pixmap) icon.GetMask()->GetBitmap();
392 }
393
394 XSetWMHints(wxGlobalDisplay(), (Window) GetMainWindow(), wmHints);
395 XFree(wmHints);
396 #endif
397 }
398 }
399
400 void wxTopLevelWindowX11::SetTitle(const wxString& title)
401 {
402 m_title = title;
403 if (GetMainWindow())
404 {
405 XStoreName(wxGlobalDisplay(), (Window) GetMainWindow(),
406 (const char*) title);
407 XSetIconName(wxGlobalDisplay(), (Window) GetMainWindow(),
408 (const char*) title);
409
410 // Use this if the platform doesn't supply the above functions.
411 #if 0
412 XTextProperty textProperty;
413 textProperty.value = (unsigned char*) title;
414 textProperty.encoding = XA_STRING;
415 textProperty.format = 8;
416 textProperty.nitems = 1;
417
418 XSetTextProperty(wxGlobalDisplay(), (Window) GetMainWindow(),
419 & textProperty, WM_NAME);
420 #endif
421 }
422 }
423
424 wxString wxTopLevelWindowX11::GetTitle() const
425 {
426 return m_title;
427 }
428
429 #ifndef MWM_DECOR_BORDER
430
431 #define MWM_HINTS_FUNCTIONS (1L << 0)
432 #define MWM_HINTS_DECORATIONS (1L << 1)
433 #define MWM_HINTS_INPUT_MODE (1L << 2)
434 #define MWM_HINTS_STATUS (1L << 3)
435
436 #define MWM_DECOR_ALL (1L << 0)
437 #define MWM_DECOR_BORDER (1L << 1)
438 #define MWM_DECOR_RESIZEH (1L << 2)
439 #define MWM_DECOR_TITLE (1L << 3)
440 #define MWM_DECOR_MENU (1L << 4)
441 #define MWM_DECOR_MINIMIZE (1L << 5)
442 #define MWM_DECOR_MAXIMIZE (1L << 6)
443
444 #define MWM_FUNC_ALL (1L << 0)
445 #define MWM_FUNC_RESIZE (1L << 1)
446 #define MWM_FUNC_MOVE (1L << 2)
447 #define MWM_FUNC_MINIMIZE (1L << 3)
448 #define MWM_FUNC_MAXIMIZE (1L << 4)
449 #define MWM_FUNC_CLOSE (1L << 5)
450
451 #define MWM_INPUT_MODELESS 0
452 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
453 #define MWM_INPUT_SYSTEM_MODAL 2
454 #define MWM_INPUT_FULL_APPLICATION_MODAL 3
455 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
456
457 #define MWM_TEAROFF_WINDOW (1L<<0)
458
459 #endif
460
461 struct MwmHints {
462 long flags;
463 long functions;
464 long decorations;
465 long input_mode;
466 };
467
468 #define PROP_MOTIF_WM_HINTS_ELEMENTS 5
469
470 // Set the window manager decorations according to the
471 // given wxWindows style
472 bool wxSetWMDecorations(Window w, long style)
473 {
474 #if wxUSE_NANOX
475 GR_WM_PROPERTIES wmProp;
476
477 wmProp.flags = 0;
478 wmProp.props = 0;
479
480 if (style & wxRESIZE_BORDER)
481 {
482 wmProp.props |= GR_WM_PROPS_APPFRAME ;
483 wmProp.flags |= GR_WM_FLAGS_PROPS ;
484 }
485
486 if (style & wxSYSTEM_MENU)
487 {
488 wmProp.props |= GR_WM_PROPS_CLOSEBOX ;
489 wmProp.flags |= GR_WM_FLAGS_PROPS ;
490 }
491
492 if ((style & wxCAPTION) ||
493 (style & wxTINY_CAPTION_HORIZ) ||
494 (style & wxTINY_CAPTION_VERT))
495 {
496 wmProp.props |= GR_WM_PROPS_CAPTION ;
497 wmProp.flags |= GR_WM_FLAGS_PROPS ;
498
499 // The default dialog style doesn't include any kind
500 // of border, which is a bit odd. Anyway, inclusion
501 // of a caption surely implies a border.
502 style |= wxTHICK_FRAME;
503 }
504
505 if (style & wxTHICK_FRAME)
506 {
507 wmProp.props |= GR_WM_PROPS_APPFRAME ;
508 wmProp.flags |= GR_WM_FLAGS_PROPS ;
509 }
510
511 if (style & wxSIMPLE_BORDER)
512 {
513 wmProp.props |= GR_WM_PROPS_BORDER ;
514 wmProp.flags |= GR_WM_FLAGS_PROPS ;
515 }
516
517 if (style & wxMINIMIZE_BOX)
518 {
519 }
520
521 if (style & wxMAXIMIZE_BOX)
522 {
523 wmProp.props |= GR_WM_PROPS_MAXIMIZE ;
524 wmProp.flags |= GR_WM_FLAGS_PROPS ;
525 }
526
527 if (((style & wxBORDER) != wxBORDER) && ((style & wxTHICK_FRAME) != wxTHICK_FRAME)
528 && ((style & wxRESIZE_BORDER) != wxRESIZE_BORDER))
529 {
530 wmProp.props |= GR_WM_PROPS_NODECORATE ;
531 wmProp.flags |= GR_WM_FLAGS_PROPS ;
532 }
533
534 GrSetWMProperties(w, & wmProp);
535
536 #else
537
538 Atom mwm_wm_hints = XInternAtom(wxGlobalDisplay(),"_MOTIF_WM_HINTS", False);
539 if (mwm_wm_hints == 0)
540 return FALSE;
541
542 MwmHints hints;
543 hints.flags = MWM_HINTS_DECORATIONS | MWM_HINTS_FUNCTIONS;
544 hints.decorations = 0;
545 hints.functions = 0;
546
547 if ((style & wxSIMPLE_BORDER) || (style & wxNO_BORDER))
548 {
549 // leave zeros
550 }
551 else
552 {
553 hints.decorations = MWM_DECOR_BORDER;
554 hints.functions = MWM_FUNC_MOVE;
555
556 if ((style & wxCAPTION) != 0)
557 hints.decorations |= MWM_DECOR_TITLE;
558
559 if ((style & wxSYSTEM_MENU) != 0)
560 {
561 hints.functions |= MWM_FUNC_CLOSE;
562 hints.decorations |= MWM_DECOR_MENU;
563 }
564
565 if ((style & wxMINIMIZE_BOX) != 0)
566 {
567 hints.functions |= MWM_FUNC_MINIMIZE;
568 hints.decorations |= MWM_DECOR_MINIMIZE;
569 }
570
571 if ((style & wxMAXIMIZE_BOX) != 0)
572 {
573 hints.functions |= MWM_FUNC_MAXIMIZE;
574 hints.decorations |= MWM_DECOR_MAXIMIZE;
575 }
576
577 if ((style & wxRESIZE_BORDER) != 0)
578 {
579 hints.functions |= MWM_FUNC_RESIZE;
580 hints.decorations |= MWM_DECOR_RESIZEH;
581 }
582 }
583
584 XChangeProperty(wxGlobalDisplay(),
585 w,
586 mwm_wm_hints, mwm_wm_hints,
587 32, PropModeReplace,
588 (unsigned char *) &hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
589
590 #endif
591 return TRUE;
592 }
593
594 // For implementation purposes - sometimes decorations make the client area
595 // smaller
596 wxPoint wxTopLevelWindowX11::GetClientAreaOrigin() const
597 {
598 // wxFrame::GetClientAreaOrigin
599 // does the required calculation already.
600 return wxPoint(0, 0);
601 }
602
603 void wxTopLevelWindowX11::DoGetClientSize( int *width, int *height ) const
604 {
605 XSync(wxGlobalDisplay(), False);
606 wxWindowX11::DoGetClientSize(width, height);
607 }
608
609 void wxTopLevelWindowX11::DoSetClientSize(int width, int height)
610 {
611 wxWindowX11::DoSetClientSize(width, height);
612
613 #if !wxUSE_NANOX
614 // Set the top-level window size
615 XSizeHints size_hints;
616 wxSize oldSize = GetSize();
617 wxSize oldClientSize = GetClientSize();
618
619 size_hints.flags = PSize;
620 size_hints.width = width + (oldSize.x - oldClientSize.x);
621 size_hints.height = height + (oldSize.y - oldClientSize.y);
622 XSetWMNormalHints( (Display*) GetXDisplay(), (Window) GetMainWindow(),
623 &size_hints);
624
625 // This seems to be necessary or resizes don't get performed
626 XSync(wxGlobalDisplay(), False);
627 XSync(wxGlobalDisplay(), False);
628
629 #if 0
630 wxLogDebug("DoSetClientSize: Tried to set size to %d, %d", (int) size_hints.width, (int) size_hints.height);
631
632 XSync(wxGlobalDisplay(), False);
633 wxSize newSize = GetSize();
634 wxLogDebug("New size is %d, %d", (int) newSize.x, (int) newSize.y);
635 #endif
636 #endif
637 }
638
639 void wxTopLevelWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags)
640 {
641 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
642
643 #if 0
644 wxWindowX11::DoSetSize(x, y, width, height, sizeFlags);
645 #endif
646 XSync(wxGlobalDisplay(), False);
647 Window window = (Window) m_mainWidget;
648 if (!window)
649 return ;
650
651 Display *display = (Display*) GetXDisplay();
652 Window root = RootWindowOfScreen(DefaultScreenOfDisplay(display));
653 Window parent_window = window,
654 next_parent = window;
655
656 // search for the parent that is child of ROOT, because the WM may
657 // reparent twice and notify only the next parent (like FVWM)
658 while (next_parent != root) {
659 Window *theChildren;
660 #if wxUSE_NANOX
661 GR_COUNT n;
662 #else
663 unsigned int n;
664 #endif
665 parent_window = next_parent;
666 XQueryTree(display, parent_window, &root,
667 &next_parent, &theChildren, &n);
668 XFree(theChildren); // not needed
669 }
670
671 XWindowChanges windowChanges;
672 windowChanges.x = x;
673 windowChanges.y = y;
674 windowChanges.width = width;
675 windowChanges.height = height;
676 windowChanges.stack_mode = 0;
677 int valueMask = CWX | CWY | CWWidth | CWHeight;
678
679 if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
680 {
681 valueMask |= CWX;
682 }
683 if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
684 {
685 valueMask |= CWY;
686 }
687 if (width != -1)
688 {
689 windowChanges.width = wxMax(1, width);
690 valueMask |= CWWidth;
691 }
692 if (height != -1)
693 {
694 windowChanges.height = wxMax(1, height);
695 valueMask |= CWHeight;
696 }
697
698 XConfigureWindow( display, parent_window, valueMask, &windowChanges );
699
700 #if !wxUSE_NANOX
701 XSizeHints size_hints;
702 size_hints.flags = 0;
703 if (x > -1 && y > -1)
704 size_hints.flags |= PPosition;
705 if (width > -1 && height > -1)
706 size_hints.flags |= PSize;
707 size_hints.width = width;
708 size_hints.height = height;
709 size_hints.x = x;
710 size_hints.y = y;
711 XSetWMNormalHints( (Display*) GetXDisplay(), (Window) GetMainWindow(),
712 &size_hints);
713
714 // This seems to be necessary or resizes don't get performed.
715 // Take them out (or even just one of them), and the About
716 // box of the minimal sample probably won't be resized right.
717 XSync(wxGlobalDisplay(), False);
718 XSync(wxGlobalDisplay(), False);
719 #endif
720 #if 1
721 wxSizeEvent event(wxSize(width, height), GetId());
722 event.SetEventObject(this);
723 GetEventHandler()->ProcessEvent(event);
724 #endif
725 }
726
727 void wxTopLevelWindowX11::DoGetPosition(int *x, int *y) const
728 {
729 XSync(wxGlobalDisplay(), False);
730 Window window = (Window) m_mainWidget;
731 if (!window)
732 return ;
733
734 Display *display = (Display*) GetXDisplay();
735 Window root = RootWindowOfScreen(DefaultScreenOfDisplay(display));
736 Window parent_window = window,
737 next_parent = window;
738
739 // search for the parent that is child of ROOT, because the WM may
740 // reparent twice and notify only the next parent (like FVWM)
741 while (next_parent != root) {
742 Window *theChildren;
743 #if wxUSE_NANOX
744 GR_COUNT n;
745 #else
746 unsigned int n;
747 #endif
748 parent_window = next_parent;
749 XQueryTree(display, parent_window, &root,
750 &next_parent, &theChildren, &n);
751 XFree(theChildren); // not needed
752 }
753 #if 0
754 int xx, yy; unsigned int dummy;
755 XGetGeometry(display, parent_window, &root,
756 &xx, &yy, &dummy, &dummy, &dummy, &dummy);
757 if (x) *x = xx;
758 if (y) *y = yy;
759 #else
760 XWindowAttributes attr;
761 Status status = XGetWindowAttributes((Display*) GetXDisplay(), parent_window, & attr);
762 if (status)
763 {
764 if (x) *x = attr.x;
765 if (y) *y = attr.y;
766 }
767 else
768 {
769 if (x) *x = 0;
770 if (y) *y = 0;
771 }
772 #endif
773 }