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