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