]> git.saurik.com Git - wxWidgets.git/blame - src/x11/toplevel.cpp
added wxCURSOR_RIGHT_ARROW to wxMGL
[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);
1016f0de
JS
204
205#if 0 // TODO
206 // You will need a compliant window manager for this to work
207 // (e.g. sawfish/enlightenment/kde/icewm/windowmaker)
208 if (style & wxSTAY_ON_TOP)
209 {
210 CARD32 data = 4; // or should this be 6? According to http://developer.gnome.org/doc/standards/wm/c44.html
211 XChangeProperty (xdisplay,
212 xwindow,
213 XInternAtom (xdisplay, "_WIN_LAYER", False),
214 XA_CARDINAL,
215 32,
216 PropModeReplace,
217 (unsigned char *)&data,
218 1);
219 }
220#endif
221
461e93f9 222#endif
952ebeba 223
7e4501ee 224 wxSetWMDecorations( xwindow, style);
83df96d6 225
b513212d 226 SetTitle(title);
952ebeba
RR
227
228 return TRUE;
83df96d6
JS
229}
230
1b0fb34b 231wxTopLevelWindowX11::~wxTopLevelWindowX11()
83df96d6 232{
83df96d6 233 wxTopLevelWindows.DeleteObject(this);
83df96d6 234
1b0fb34b
JS
235 // If this is the last top-level window, exit.
236 if ( wxTheApp && (wxTopLevelWindows.Number() == 0) )
83df96d6
JS
237 {
238 wxTheApp->SetTopWindow(NULL);
239
240 if (wxTheApp->GetExitOnFrameDelete())
241 {
242 // Signal to the app that we're going to close
243 wxTheApp->ExitMainLoop();
244 }
245 }
246}
247
77df2fbc
RR
248void wxTopLevelWindowX11::OnInternalIdle()
249{
250 wxWindow::OnInternalIdle();
251
252 if (m_needResizeInIdle)
253 {
254 wxSizeEvent event( GetClientSize(), GetId() );
255 event.SetEventObject( this );
256 GetEventHandler()->ProcessEvent( event );
c7d86155
RR
257
258 m_needResizeInIdle = FALSE;
77df2fbc
RR
259 }
260}
261
1b0fb34b
JS
262// ----------------------------------------------------------------------------
263// wxTopLevelWindowX11 showing
264// ----------------------------------------------------------------------------
83df96d6 265
1b0fb34b 266bool wxTopLevelWindowX11::Show(bool show)
83df96d6 267{
e25f954b
JS
268 // Nano-X has to force a size event,
269 // else there's no initial size.
270#if wxUSE_NANOX
271 if (show)
77df2fbc
RR
272#else
273 if (show && m_needResizeInIdle)
274#endif
e25f954b
JS
275 {
276 wxSizeEvent event(GetSize(), GetId());
277 event.SetEventObject(this);
278 GetEventHandler()->ProcessEvent(event);
c7d86155
RR
279
280 m_needResizeInIdle = FALSE;
e25f954b 281 }
e25f954b 282
7ded318b
JS
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
b513212d 295 return wxWindowX11::Show(show);
83df96d6
JS
296}
297
1b0fb34b
JS
298// ----------------------------------------------------------------------------
299// wxTopLevelWindowX11 maximize/minimize
300// ----------------------------------------------------------------------------
83df96d6 301
1b0fb34b 302void wxTopLevelWindowX11::Maximize(bool maximize)
83df96d6 303{
1b0fb34b 304 // TODO
83df96d6
JS
305}
306
1b0fb34b 307bool wxTopLevelWindowX11::IsMaximized() const
83df96d6 308{
1b0fb34b
JS
309 // TODO
310 return TRUE;
83df96d6
JS
311}
312
1b0fb34b 313void wxTopLevelWindowX11::Iconize(bool iconize)
83df96d6 314{
b513212d
JS
315 if (!m_iconized && GetMainWindow())
316 {
317 if (XIconifyWindow(wxGlobalDisplay(),
318 (Window) GetMainWindow(), DefaultScreen(wxGlobalDisplay())) != 0)
319 m_iconized = TRUE;
320 }
83df96d6
JS
321}
322
1b0fb34b 323bool wxTopLevelWindowX11::IsIconized() const
83df96d6 324{
1b0fb34b 325 return m_iconized;
83df96d6
JS
326}
327
1b0fb34b 328void wxTopLevelWindowX11::Restore()
83df96d6 329{
b513212d
JS
330 // This is the way to deiconify the window, according to the X FAQ
331 if (m_iconized && GetMainWindow())
332 {
333 XMapWindow(wxGlobalDisplay(), (Window) GetMainWindow());
334 m_iconized = FALSE;
335 }
83df96d6
JS
336}
337
1b0fb34b
JS
338// ----------------------------------------------------------------------------
339// wxTopLevelWindowX11 fullscreen
340// ----------------------------------------------------------------------------
83df96d6 341
1b0fb34b 342bool wxTopLevelWindowX11::ShowFullScreen(bool show, long style)
83df96d6 343{
1b0fb34b 344 if (show)
83df96d6 345 {
1b0fb34b
JS
346 if (IsFullScreen())
347 return FALSE;
83df96d6 348
1b0fb34b
JS
349 m_fsIsShowing = TRUE;
350 m_fsStyle = style;
83df96d6 351
1b0fb34b 352 // TODO
83df96d6 353
1b0fb34b 354 return TRUE;
83df96d6 355 }
1b0fb34b 356 else
83df96d6 357 {
1b0fb34b
JS
358 if (!IsFullScreen())
359 return FALSE;
83df96d6 360
1b0fb34b 361 m_fsIsShowing = FALSE;
83df96d6 362
1b0fb34b
JS
363 // TODO
364 return TRUE;
83df96d6
JS
365 }
366}
367
1b0fb34b
JS
368// ----------------------------------------------------------------------------
369// wxTopLevelWindowX11 misc
370// ----------------------------------------------------------------------------
83df96d6 371
1b0fb34b 372void wxTopLevelWindowX11::SetIcon(const wxIcon& icon)
83df96d6 373{
1b0fb34b
JS
374 // this sets m_icon
375 wxTopLevelWindowBase::SetIcon(icon);
83df96d6 376
b513212d
JS
377 if (icon.Ok() && GetMainWindow())
378 {
461e93f9
JS
379#if wxUSE_NANOX
380#else
b513212d 381 XWMHints *wmHints = XAllocWMHints();
6a44bffd 382 wmHints->icon_pixmap = (Pixmap) icon.GetPixmap();
b513212d 383
6a44bffd 384 wmHints->flags = IconPixmapHint;
b513212d
JS
385
386 if (icon.GetMask())
387 {
6a44bffd 388 wmHints->flags |= IconMaskHint;
a11672a4 389 wmHints->icon_mask = (Pixmap) icon.GetMask()->GetBitmap();
b513212d
JS
390 }
391
1b0b798d 392 XSetWMHints(wxGlobalDisplay(), (Window) GetMainWindow(), wmHints);
b513212d 393 XFree(wmHints);
461e93f9 394#endif
b513212d
JS
395 }
396}
397
398void wxTopLevelWindowX11::SetTitle(const wxString& title)
399{
400 m_title = title;
401 if (GetMainWindow())
402 {
403 XStoreName(wxGlobalDisplay(), (Window) GetMainWindow(),
404 (const char*) title);
405 XSetIconName(wxGlobalDisplay(), (Window) GetMainWindow(),
406 (const char*) title);
b28d3abf
JS
407
408 // Use this if the platform doesn't supply the above functions.
b513212d
JS
409#if 0
410 XTextProperty textProperty;
411 textProperty.value = (unsigned char*) title;
412 textProperty.encoding = XA_STRING;
413 textProperty.format = 8;
414 textProperty.nitems = 1;
415
416 XSetTextProperty(wxGlobalDisplay(), (Window) GetMainWindow(),
417 & textProperty, WM_NAME);
418#endif
419 }
420}
421
422wxString wxTopLevelWindowX11::GetTitle() const
423{
424 return m_title;
425}
426
427#ifndef MWM_DECOR_BORDER
428/* bit definitions for MwmHints.flags */
429#define MWM_HINTS_FUNCTIONS (1L << 0)
430#define MWM_HINTS_DECORATIONS (1L << 1)
431#define MWM_HINTS_INPUT_MODE (1L << 2)
432#define MWM_HINTS_STATUS (1L << 3)
433
434#define MWM_DECOR_ALL (1L << 0)
435#define MWM_DECOR_BORDER (1L << 1)
436#define MWM_DECOR_RESIZEH (1L << 2)
437#define MWM_DECOR_TITLE (1L << 3)
438#define MWM_DECOR_MENU (1L << 4)
439#define MWM_DECOR_MINIMIZE (1L << 5)
440#define MWM_DECOR_MAXIMIZE (1L << 6)
441#endif
442
443struct MwmHints {
444 long flags;
445 long functions;
446 long decorations;
447 long input_mode;
448};
449
450#define PROP_MOTIF_WM_HINTS_ELEMENTS 5
451
452// Set the window manager decorations according to the
453// given wxWindows style
b28d3abf 454bool wxSetWMDecorations(Window w, long style)
b513212d 455{
461e93f9
JS
456#if wxUSE_NANOX
457 GR_WM_PROPERTIES wmProp;
458
459 wmProp.flags = 0;
0b5c0e1a 460 wmProp.props = 0;
461e93f9
JS
461
462 if (style & wxRESIZE_BORDER)
463 {
464 wmProp.props |= GR_WM_PROPS_APPFRAME ;
465 wmProp.flags |= GR_WM_FLAGS_PROPS ;
466 }
467
468 if (style & wxSYSTEM_MENU)
469 {
470 wmProp.props |= GR_WM_PROPS_CLOSEBOX ;
471 wmProp.flags |= GR_WM_FLAGS_PROPS ;
472 }
473
474 if ((style & wxCAPTION) ||
475 (style & wxTINY_CAPTION_HORIZ) ||
476 (style & wxTINY_CAPTION_VERT))
477 {
478 wmProp.props |= GR_WM_PROPS_CAPTION ;
479 wmProp.flags |= GR_WM_FLAGS_PROPS ;
bc55104d
JS
480
481 // The default dialog style doesn't include any kind
482 // of border, which is a bit odd. Anyway, inclusion
483 // of a caption surely implies a border.
484 style |= wxTHICK_FRAME;
461e93f9
JS
485 }
486
487 if (style & wxTHICK_FRAME)
488 {
489 wmProp.props |= GR_WM_PROPS_APPFRAME ;
490 wmProp.flags |= GR_WM_FLAGS_PROPS ;
491 }
492
493 if (style & wxSIMPLE_BORDER)
494 {
495 wmProp.props |= GR_WM_PROPS_BORDER ;
496 wmProp.flags |= GR_WM_FLAGS_PROPS ;
497 }
498
499 if (style & wxMINIMIZE_BOX)
500 {
501 }
502
503 if (style & wxMAXIMIZE_BOX)
504 {
505 wmProp.props |= GR_WM_PROPS_MAXIMIZE ;
506 wmProp.flags |= GR_WM_FLAGS_PROPS ;
507 }
508
509 if (((style & wxBORDER) != wxBORDER) && ((style & wxTHICK_FRAME) != wxTHICK_FRAME)
510 && ((style & wxRESIZE_BORDER) != wxRESIZE_BORDER))
511 {
512 wmProp.props |= GR_WM_PROPS_NODECORATE ;
513 wmProp.flags |= GR_WM_FLAGS_PROPS ;
514 }
515
516 GrSetWMProperties(w, & wmProp);
517
518#else
6a44bffd 519 if (!wxMWMIsRunning(w))
b513212d
JS
520 return FALSE;
521
522 Atom mwm_wm_hints = XInternAtom(wxGlobalDisplay(),"_MOTIF_WM_HINTS", False);
523 MwmHints hints;
524 hints.flags = 0;
525 hints.decorations = 0;
526
527 if (style & wxRESIZE_BORDER)
528 {
9691c806 529 // wxLogDebug("MWM_DECOR_RESIZEH");
b513212d
JS
530 hints.flags |= MWM_HINTS_DECORATIONS;
531 hints.decorations |= MWM_DECOR_RESIZEH;
532 }
533
534 if (style & wxSYSTEM_MENU)
535 {
9691c806 536 // wxLogDebug("MWM_DECOR_MENU");
b513212d
JS
537 hints.flags |= MWM_HINTS_DECORATIONS;
538 hints.decorations |= MWM_DECOR_MENU;
539 }
540
541 if ((style & wxCAPTION) ||
542 (style & wxTINY_CAPTION_HORIZ) ||
543 (style & wxTINY_CAPTION_VERT))
544 {
9691c806 545 // wxLogDebug("MWM_DECOR_TITLE");
b513212d
JS
546 hints.flags |= MWM_HINTS_DECORATIONS;
547 hints.decorations |= MWM_DECOR_TITLE;
548 }
549
16e8bf31 550 if ((style & wxTHICK_FRAME) || (style & wxCAPTION))
b513212d 551 {
9691c806 552 // wxLogDebug("MWM_DECOR_BORDER");
b513212d
JS
553 hints.flags |= MWM_HINTS_DECORATIONS;
554 hints.decorations |= MWM_DECOR_BORDER;
555 }
556
557 if (style & wxMINIMIZE_BOX)
558 {
9691c806 559 // wxLogDebug("MWM_DECOR_MINIMIZE");
b513212d
JS
560 hints.flags |= MWM_HINTS_DECORATIONS;
561 hints.decorations |= MWM_DECOR_MINIMIZE;
562 }
563
564 if (style & wxMAXIMIZE_BOX)
565 {
9691c806 566 // wxLogDebug("MWM_DECOR_MAXIMIZE");
b513212d
JS
567 hints.flags |= MWM_HINTS_DECORATIONS;
568 hints.decorations |= MWM_DECOR_MAXIMIZE;
569 }
570
571 XChangeProperty(wxGlobalDisplay(),
572 w,
6a44bffd 573 mwm_wm_hints, mwm_wm_hints,
b513212d
JS
574 32, PropModeReplace,
575 (unsigned char *) &hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
576
461e93f9 577#endif
b513212d
JS
578 return TRUE;
579}
580
b28d3abf 581bool wxMWMIsRunning(Window w)
b513212d 582{
461e93f9
JS
583#if wxUSE_NANOX
584 return FALSE;
585#else
68e42278 586 Display *dpy = (Display*)wxGetDisplay();
b513212d
JS
587 Atom motifWmInfo = XInternAtom(dpy, "_MOTIF_WM_INFO", False);
588
589 unsigned long length, bytesafter;
590 unsigned char value[20];
68e42278
RR
591 unsigned char *ptr = &value[0];
592 int ret, format;
593 Atom type;
b513212d
JS
594
595 type = format = length = 0;
68e42278 596 value[0] = 0;
b513212d
JS
597
598 ret = XGetWindowProperty(wxGlobalDisplay(), w, motifWmInfo,
599 0L, 2, False, motifWmInfo,
68e42278 600 &type, &format, &length, &bytesafter, &ptr);
b513212d
JS
601
602 return (ret == Success);
461e93f9 603#endif
83df96d6 604}
6a44bffd 605
e5053ade
JS
606// For implementation purposes - sometimes decorations make the client area
607// smaller
608wxPoint wxTopLevelWindowX11::GetClientAreaOrigin() const
609{
59db9cfa 610 // wxFrame::GetClientAreaOrigin
418d4918 611 // does the required calculation already.
e5053ade
JS
612 return wxPoint(0, 0);
613}
614
615void wxTopLevelWindowX11::DoGetClientSize( int *width, int *height ) const
616{
59db9cfa 617 XSync(wxGlobalDisplay(), False);
e5053ade 618 wxWindowX11::DoGetClientSize(width, height);
e5053ade
JS
619}
620
621void wxTopLevelWindowX11::DoSetClientSize(int width, int height)
622{
e5053ade 623 wxWindowX11::DoSetClientSize(width, height);
3a0b23eb 624
15d5a947 625#if !wxUSE_NANOX
59db9cfa
JS
626 // Set the top-level window size
627 XSizeHints size_hints;
628 wxSize oldSize = GetSize();
629 wxSize oldClientSize = GetClientSize();
630
631 size_hints.flags = PSize;
632 size_hints.width = width + (oldSize.x - oldClientSize.x);
633 size_hints.height = height + (oldSize.y - oldClientSize.y);
634 XSetWMNormalHints( (Display*) GetXDisplay(), (Window) GetMainWindow(),
635 &size_hints);
636
637 // This seems to be necessary or resizes don't get performed
638 XSync(wxGlobalDisplay(), False);
639 XSync(wxGlobalDisplay(), False);
640
641#if 0
642 wxLogDebug("DoSetClientSize: Tried to set size to %d, %d", (int) size_hints.width, (int) size_hints.height);
643
644 XSync(wxGlobalDisplay(), False);
645 wxSize newSize = GetSize();
646 wxLogDebug("New size is %d, %d", (int) newSize.x, (int) newSize.y);
647#endif
e5053ade
JS
648#endif
649}
3a0b23eb
JS
650
651void wxTopLevelWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags)
652{
21689736 653#if 0
f809133f 654 // wxLogDebug( "Setting pos: %d, %d", x, y );
3a0b23eb 655 wxWindowX11::DoSetSize(x, y, width, height, sizeFlags);
21689736
JS
656#endif
657 XSync(wxGlobalDisplay(), False);
658 Window window = (Window) m_mainWidget;
659 if (!window)
660 return ;
661
662 Display *display = (Display*) GetXDisplay();
663 Window root = RootWindowOfScreen(DefaultScreenOfDisplay(display));
664 Window parent_window = window,
665 next_parent = window;
666
667 // search for the parent that is child of ROOT, because the WM may
668 // reparent twice and notify only the next parent (like FVWM)
669 while (next_parent != root) {
15d5a947
JS
670 Window *theChildren;
671#if wxUSE_NANOX
672 GR_COUNT n;
673#else
674 unsigned int n;
675#endif
21689736
JS
676 parent_window = next_parent;
677 XQueryTree(display, parent_window, &root,
678 &next_parent, &theChildren, &n);
679 XFree(theChildren); // not needed
680 }
681
682 XWindowChanges windowChanges;
683 windowChanges.x = x;
684 windowChanges.y = y;
685 windowChanges.width = width;
686 windowChanges.height = height;
687 windowChanges.stack_mode = 0;
688 int valueMask = CWX | CWY | CWWidth | CWHeight;
689
690 if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
691 {
692 valueMask |= CWX;
693 }
694 if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
695 {
696 valueMask |= CWY;
697 }
698 if (width != -1)
699 {
700 windowChanges.width = wxMax(1, width);
701 valueMask |= CWWidth;
702 }
703 if (height != -1)
704 {
705 windowChanges.height = wxMax(1, height);
706 valueMask |= CWHeight;
707 }
3a0b23eb 708
21689736 709 XConfigureWindow( display, parent_window, valueMask, &windowChanges );
15d5a947
JS
710
711#if !wxUSE_NANOX
59db9cfa
JS
712 XSizeHints size_hints;
713 size_hints.flags = 0;
714 if (x > -1 && y > -1)
715 size_hints.flags |= PPosition;
716 if (width > -1 && height > -1)
717 size_hints.flags |= PSize;
718 size_hints.width = width;
719 size_hints.height = height;
720 size_hints.x = x;
721 size_hints.y = y;
722 XSetWMNormalHints( (Display*) GetXDisplay(), (Window) GetMainWindow(),
723 &size_hints);
724
725 // This seems to be necessary or resizes don't get performed.
726 // Take them out (or even just one of them), and the About
727 // box of the minimal sample probably won't be resized right.
728 XSync(wxGlobalDisplay(), False);
729 XSync(wxGlobalDisplay(), False);
3a0b23eb
JS
730#endif
731}
732
733void wxTopLevelWindowX11::DoGetPosition(int *x, int *y) const
734{
735 XSync(wxGlobalDisplay(), False);
736 Window window = (Window) m_mainWidget;
21689736
JS
737 if (!window)
738 return ;
739
740 Display *display = (Display*) GetXDisplay();
741 Window root = RootWindowOfScreen(DefaultScreenOfDisplay(display));
742 Window parent_window = window,
743 next_parent = window;
744
745 // search for the parent that is child of ROOT, because the WM may
746 // reparent twice and notify only the next parent (like FVWM)
747 while (next_parent != root) {
15d5a947
JS
748 Window *theChildren;
749#if wxUSE_NANOX
750 GR_COUNT n;
751#else
752 unsigned int n;
753#endif
21689736
JS
754 parent_window = next_parent;
755 XQueryTree(display, parent_window, &root,
756 &next_parent, &theChildren, &n);
757 XFree(theChildren); // not needed
758 }
15d5a947 759#if 0
21689736
JS
760 int xx, yy; unsigned int dummy;
761 XGetGeometry(display, parent_window, &root,
15d5a947 762 &xx, &yy, &dummy, &dummy, &dummy, &dummy);
21689736
JS
763 if (x) *x = xx;
764 if (y) *y = yy;
15d5a947
JS
765#else
766 XWindowAttributes attr;
767 Status status = XGetWindowAttributes((Display*) GetXDisplay(), parent_window, & attr);
768 if (status)
3a0b23eb 769 {
15d5a947
JS
770 if (x) *x = attr.x;
771 if (y) *y = attr.y;
772 }
773 else
774 {
775 if (x) *x = 0;
776 if (y) *y = 0;
3a0b23eb 777 }
21689736 778#endif
3a0b23eb 779}