]> git.saurik.com Git - wxWidgets.git/blame - src/x11/toplevel.cpp
New code for greying out.
[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
RR
64
65 m_focusWidget = NULL;
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
461e93f9 104#if !wxUSE_NANOX
952ebeba
RR
105 XSetWindowAttributes xattributes;
106 XSizeHints size_hints;
952ebeba
RR
107
108 long xattributes_mask =
ea596687 109 CWOverrideRedirect |
952ebeba 110 CWBorderPixel | CWBackPixel;
461e93f9 111
2034b748 112 xattributes.background_pixel = m_backgroundColour.GetPixel();
952ebeba 113 xattributes.border_pixel = BlackPixel( xdisplay, xscreen );
5e29f97a
JS
114
115 // TODO: if we want no border, caption etc.,
116 // I think we set this to True to remove decorations
7e4501ee 117 // No. RR.
952ebeba 118 xattributes.override_redirect = False;
461e93f9 119#endif
952ebeba 120
edaf57a4
JS
121 wxSize size2(size);
122 if (size2.x == -1)
123 size2.x = 100;
124 if (size2.y == -1)
125 size2.y = 100;
126
127 wxPoint pos2(pos);
128 if (pos2.x == -1)
129 pos2.x = 100;
130 if (pos2.y == -1)
131 pos2.y = 100;
952ebeba 132
461e93f9
JS
133#if wxUSE_NANOX
134 long backColor, foreColor;
135 backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue());
136 foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue());
137
138 Window xwindow = XCreateWindowWithColor( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y,
139 0, 0, InputOutput, xvisual, backColor, foreColor);
140#else
307be31a 141 Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y,
461e93f9
JS
142 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
143#endif
307be31a
JS
144 m_mainWidget = (WXWindow) xwindow;
145
461e93f9 146 int extraFlags = 0;
256d631a 147#if wxUSE_NANOX
461e93f9 148 extraFlags |= GR_EVENT_MASK_CLOSE_REQ;
256d631a 149#endif
461e93f9 150
70b8ab77 151#if wxUSE_NANOX
461e93f9 152 XSelectInput( xdisplay, xwindow,
70b8ab77
JS
153 extraFlags |
154 ExposureMask |
155 KeyPressMask |
156 KeyReleaseMask |
157 ButtonPressMask |
158 ButtonReleaseMask |
159 ButtonMotionMask |
160 EnterWindowMask |
161 LeaveWindowMask |
162 PointerMotionMask |
163 KeymapStateMask |
164 FocusChangeMask |
165 ColormapChangeMask |
166 StructureNotifyMask |
167 PropertyChangeMask
168 );
169#else
170 XSelectInput( xdisplay, xwindow,
171 extraFlags |
172 ExposureMask |
173 KeyPressMask |
174 KeyReleaseMask |
175 ButtonPressMask |
176 ButtonReleaseMask |
177 ButtonMotionMask |
178 EnterWindowMask |
179 LeaveWindowMask |
180 PointerMotionMask |
181 KeymapStateMask |
182 FocusChangeMask |
183 ColormapChangeMask |
184 StructureNotifyMask |
185 PropertyChangeMask
186 );
187#endif
188
307be31a
JS
189 wxAddWindowToTable( xwindow, (wxWindow*) this );
190
ba696cfa
RR
191 // Set background to None which will prevent X11 from clearing the
192 // background completely.
193 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
194
461e93f9 195#if !wxUSE_NANOX
7e4501ee
RR
196 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)
197 {
198 if (GetParent() && GetParent()->GetMainWindow())
199 {
200 Window xparentwindow = (Window) GetParent()->GetMainWindow();
201 XSetTransientForHint( xdisplay, xwindow, xparentwindow );
202 }
203 }
204
205 size_hints.flags = PSize | PPosition;
206 size_hints.x = pos2.x;
207 size_hints.y = pos2.y;
edaf57a4
JS
208 size_hints.width = size2.x;
209 size_hints.height = size2.y;
952ebeba
RR
210 XSetWMNormalHints( xdisplay, xwindow, &size_hints);
211
461e93f9 212 XWMHints wm_hints;
952ebeba
RR
213 wm_hints.flags = InputHint | StateHint /* | WindowGroupHint */;
214 wm_hints.input = True;
215 wm_hints.initial_state = NormalState;
216 XSetWMHints( xdisplay, xwindow, &wm_hints);
461e93f9 217
7e4501ee
RR
218 Atom wm_protocols[2];
219 wm_protocols[0] = XInternAtom( xdisplay, "WM_DELETE_WINDOW", False );
220 wm_protocols[1] = XInternAtom( xdisplay, "WM_TAKE_FOCUS", False );
221 XSetWMProtocols( xdisplay, xwindow, wm_protocols, 2);
461e93f9 222#endif
952ebeba 223
70b8ab77
JS
224#if 0 // wxUSE_NANOX
225 GR_WM_PROPERTIES props;
226 props.flags = GR_WM_FLAGS_TITLE;
227 props.title = (GR_CHAR*) "Hello";
228 GrSetWMProperties(xwindow, &props);
229#else
7e4501ee 230 wxSetWMDecorations( xwindow, style);
70b8ab77 231#endif
83df96d6 232
b513212d 233 SetTitle(title);
952ebeba
RR
234
235 return TRUE;
83df96d6
JS
236}
237
1b0fb34b 238wxTopLevelWindowX11::~wxTopLevelWindowX11()
83df96d6 239{
83df96d6 240 wxTopLevelWindows.DeleteObject(this);
83df96d6 241
1b0fb34b
JS
242 // If this is the last top-level window, exit.
243 if ( wxTheApp && (wxTopLevelWindows.Number() == 0) )
83df96d6
JS
244 {
245 wxTheApp->SetTopWindow(NULL);
246
247 if (wxTheApp->GetExitOnFrameDelete())
248 {
249 // Signal to the app that we're going to close
250 wxTheApp->ExitMainLoop();
251 }
252 }
253}
254
1b0fb34b
JS
255// ----------------------------------------------------------------------------
256// wxTopLevelWindowX11 showing
257// ----------------------------------------------------------------------------
83df96d6 258
1b0fb34b 259bool wxTopLevelWindowX11::Show(bool show)
83df96d6 260{
b513212d 261 return wxWindowX11::Show(show);
83df96d6
JS
262}
263
1b0fb34b
JS
264// ----------------------------------------------------------------------------
265// wxTopLevelWindowX11 maximize/minimize
266// ----------------------------------------------------------------------------
83df96d6 267
1b0fb34b 268void wxTopLevelWindowX11::Maximize(bool maximize)
83df96d6 269{
1b0fb34b 270 // TODO
83df96d6
JS
271}
272
1b0fb34b 273bool wxTopLevelWindowX11::IsMaximized() const
83df96d6 274{
1b0fb34b
JS
275 // TODO
276 return TRUE;
83df96d6
JS
277}
278
1b0fb34b 279void wxTopLevelWindowX11::Iconize(bool iconize)
83df96d6 280{
b513212d
JS
281 if (!m_iconized && GetMainWindow())
282 {
283 if (XIconifyWindow(wxGlobalDisplay(),
284 (Window) GetMainWindow(), DefaultScreen(wxGlobalDisplay())) != 0)
285 m_iconized = TRUE;
286 }
83df96d6
JS
287}
288
1b0fb34b 289bool wxTopLevelWindowX11::IsIconized() const
83df96d6 290{
1b0fb34b 291 return m_iconized;
83df96d6
JS
292}
293
1b0fb34b 294void wxTopLevelWindowX11::Restore()
83df96d6 295{
b513212d
JS
296 // This is the way to deiconify the window, according to the X FAQ
297 if (m_iconized && GetMainWindow())
298 {
299 XMapWindow(wxGlobalDisplay(), (Window) GetMainWindow());
300 m_iconized = FALSE;
301 }
83df96d6
JS
302}
303
1b0fb34b
JS
304// ----------------------------------------------------------------------------
305// wxTopLevelWindowX11 fullscreen
306// ----------------------------------------------------------------------------
83df96d6 307
1b0fb34b 308bool wxTopLevelWindowX11::ShowFullScreen(bool show, long style)
83df96d6 309{
1b0fb34b 310 if (show)
83df96d6 311 {
1b0fb34b
JS
312 if (IsFullScreen())
313 return FALSE;
83df96d6 314
1b0fb34b
JS
315 m_fsIsShowing = TRUE;
316 m_fsStyle = style;
83df96d6 317
1b0fb34b 318 // TODO
83df96d6 319
1b0fb34b 320 return TRUE;
83df96d6 321 }
1b0fb34b 322 else
83df96d6 323 {
1b0fb34b
JS
324 if (!IsFullScreen())
325 return FALSE;
83df96d6 326
1b0fb34b 327 m_fsIsShowing = FALSE;
83df96d6 328
1b0fb34b
JS
329 // TODO
330 return TRUE;
83df96d6
JS
331 }
332}
333
1b0fb34b
JS
334// ----------------------------------------------------------------------------
335// wxTopLevelWindowX11 misc
336// ----------------------------------------------------------------------------
83df96d6 337
1b0fb34b 338void wxTopLevelWindowX11::SetIcon(const wxIcon& icon)
83df96d6 339{
1b0fb34b
JS
340 // this sets m_icon
341 wxTopLevelWindowBase::SetIcon(icon);
83df96d6 342
b513212d
JS
343 if (icon.Ok() && GetMainWindow())
344 {
461e93f9
JS
345#if wxUSE_NANOX
346#else
b513212d 347 XWMHints *wmHints = XAllocWMHints();
6a44bffd 348 wmHints->icon_pixmap = (Pixmap) icon.GetPixmap();
b513212d 349
6a44bffd 350 wmHints->flags = IconPixmapHint;
b513212d
JS
351
352 if (icon.GetMask())
353 {
6a44bffd 354 wmHints->flags |= IconMaskHint;
a11672a4 355 wmHints->icon_mask = (Pixmap) icon.GetMask()->GetBitmap();
b513212d
JS
356 }
357
1b0b798d 358 XSetWMHints(wxGlobalDisplay(), (Window) GetMainWindow(), wmHints);
b513212d 359 XFree(wmHints);
461e93f9 360#endif
b513212d
JS
361 }
362}
363
364void wxTopLevelWindowX11::SetTitle(const wxString& title)
365{
366 m_title = title;
367 if (GetMainWindow())
368 {
369 XStoreName(wxGlobalDisplay(), (Window) GetMainWindow(),
370 (const char*) title);
371 XSetIconName(wxGlobalDisplay(), (Window) GetMainWindow(),
372 (const char*) title);
b28d3abf
JS
373
374 // Use this if the platform doesn't supply the above functions.
b513212d
JS
375#if 0
376 XTextProperty textProperty;
377 textProperty.value = (unsigned char*) title;
378 textProperty.encoding = XA_STRING;
379 textProperty.format = 8;
380 textProperty.nitems = 1;
381
382 XSetTextProperty(wxGlobalDisplay(), (Window) GetMainWindow(),
383 & textProperty, WM_NAME);
384#endif
385 }
386}
387
388wxString wxTopLevelWindowX11::GetTitle() const
389{
390 return m_title;
391}
392
393#ifndef MWM_DECOR_BORDER
394/* bit definitions for MwmHints.flags */
395#define MWM_HINTS_FUNCTIONS (1L << 0)
396#define MWM_HINTS_DECORATIONS (1L << 1)
397#define MWM_HINTS_INPUT_MODE (1L << 2)
398#define MWM_HINTS_STATUS (1L << 3)
399
400#define MWM_DECOR_ALL (1L << 0)
401#define MWM_DECOR_BORDER (1L << 1)
402#define MWM_DECOR_RESIZEH (1L << 2)
403#define MWM_DECOR_TITLE (1L << 3)
404#define MWM_DECOR_MENU (1L << 4)
405#define MWM_DECOR_MINIMIZE (1L << 5)
406#define MWM_DECOR_MAXIMIZE (1L << 6)
407#endif
408
409struct MwmHints {
410 long flags;
411 long functions;
412 long decorations;
413 long input_mode;
414};
415
416#define PROP_MOTIF_WM_HINTS_ELEMENTS 5
417
418// Set the window manager decorations according to the
419// given wxWindows style
b28d3abf 420bool wxSetWMDecorations(Window w, long style)
b513212d 421{
461e93f9
JS
422#if wxUSE_NANOX
423 GR_WM_PROPERTIES wmProp;
424
425 wmProp.flags = 0;
426
427 if (style & wxRESIZE_BORDER)
428 {
429 wmProp.props |= GR_WM_PROPS_APPFRAME ;
430 wmProp.flags |= GR_WM_FLAGS_PROPS ;
431 }
432
433 if (style & wxSYSTEM_MENU)
434 {
435 wmProp.props |= GR_WM_PROPS_CLOSEBOX ;
436 wmProp.flags |= GR_WM_FLAGS_PROPS ;
437 }
438
439 if ((style & wxCAPTION) ||
440 (style & wxTINY_CAPTION_HORIZ) ||
441 (style & wxTINY_CAPTION_VERT))
442 {
443 wmProp.props |= GR_WM_PROPS_CAPTION ;
444 wmProp.flags |= GR_WM_FLAGS_PROPS ;
445 }
446
447 if (style & wxTHICK_FRAME)
448 {
449 wmProp.props |= GR_WM_PROPS_APPFRAME ;
450 wmProp.flags |= GR_WM_FLAGS_PROPS ;
451 }
452
453 if (style & wxSIMPLE_BORDER)
454 {
455 wmProp.props |= GR_WM_PROPS_BORDER ;
456 wmProp.flags |= GR_WM_FLAGS_PROPS ;
457 }
458
459 if (style & wxMINIMIZE_BOX)
460 {
461 }
462
463 if (style & wxMAXIMIZE_BOX)
464 {
465 wmProp.props |= GR_WM_PROPS_MAXIMIZE ;
466 wmProp.flags |= GR_WM_FLAGS_PROPS ;
467 }
468
469 if (((style & wxBORDER) != wxBORDER) && ((style & wxTHICK_FRAME) != wxTHICK_FRAME)
470 && ((style & wxRESIZE_BORDER) != wxRESIZE_BORDER))
471 {
472 wmProp.props |= GR_WM_PROPS_NODECORATE ;
473 wmProp.flags |= GR_WM_FLAGS_PROPS ;
474 }
475
476 GrSetWMProperties(w, & wmProp);
477
478#else
6a44bffd 479 if (!wxMWMIsRunning(w))
b513212d
JS
480 return FALSE;
481
482 Atom mwm_wm_hints = XInternAtom(wxGlobalDisplay(),"_MOTIF_WM_HINTS", False);
483 MwmHints hints;
484 hints.flags = 0;
485 hints.decorations = 0;
486
487 if (style & wxRESIZE_BORDER)
488 {
9691c806 489 // wxLogDebug("MWM_DECOR_RESIZEH");
b513212d
JS
490 hints.flags |= MWM_HINTS_DECORATIONS;
491 hints.decorations |= MWM_DECOR_RESIZEH;
492 }
493
494 if (style & wxSYSTEM_MENU)
495 {
9691c806 496 // wxLogDebug("MWM_DECOR_MENU");
b513212d
JS
497 hints.flags |= MWM_HINTS_DECORATIONS;
498 hints.decorations |= MWM_DECOR_MENU;
499 }
500
501 if ((style & wxCAPTION) ||
502 (style & wxTINY_CAPTION_HORIZ) ||
503 (style & wxTINY_CAPTION_VERT))
504 {
9691c806 505 // wxLogDebug("MWM_DECOR_TITLE");
b513212d
JS
506 hints.flags |= MWM_HINTS_DECORATIONS;
507 hints.decorations |= MWM_DECOR_TITLE;
508 }
509
307be31a 510 if ((style & wxTHICK_FRAME) || (style & wxSIMPLE_BORDER) || (style & wxCAPTION))
b513212d 511 {
9691c806 512 // wxLogDebug("MWM_DECOR_BORDER");
b513212d
JS
513 hints.flags |= MWM_HINTS_DECORATIONS;
514 hints.decorations |= MWM_DECOR_BORDER;
515 }
516
517 if (style & wxMINIMIZE_BOX)
518 {
9691c806 519 // wxLogDebug("MWM_DECOR_MINIMIZE");
b513212d
JS
520 hints.flags |= MWM_HINTS_DECORATIONS;
521 hints.decorations |= MWM_DECOR_MINIMIZE;
522 }
523
524 if (style & wxMAXIMIZE_BOX)
525 {
9691c806 526 // wxLogDebug("MWM_DECOR_MAXIMIZE");
b513212d
JS
527 hints.flags |= MWM_HINTS_DECORATIONS;
528 hints.decorations |= MWM_DECOR_MAXIMIZE;
529 }
530
531 XChangeProperty(wxGlobalDisplay(),
532 w,
6a44bffd 533 mwm_wm_hints, mwm_wm_hints,
b513212d
JS
534 32, PropModeReplace,
535 (unsigned char *) &hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
536
461e93f9 537#endif
b513212d
JS
538 return TRUE;
539}
540
b28d3abf 541bool wxMWMIsRunning(Window w)
b513212d 542{
461e93f9
JS
543#if wxUSE_NANOX
544 return FALSE;
545#else
68e42278 546 Display *dpy = (Display*)wxGetDisplay();
b513212d
JS
547 Atom motifWmInfo = XInternAtom(dpy, "_MOTIF_WM_INFO", False);
548
549 unsigned long length, bytesafter;
550 unsigned char value[20];
68e42278
RR
551 unsigned char *ptr = &value[0];
552 int ret, format;
553 Atom type;
b513212d
JS
554
555 type = format = length = 0;
68e42278 556 value[0] = 0;
b513212d
JS
557
558 ret = XGetWindowProperty(wxGlobalDisplay(), w, motifWmInfo,
559 0L, 2, False, motifWmInfo,
68e42278 560 &type, &format, &length, &bytesafter, &ptr);
b513212d
JS
561
562 return (ret == Success);
461e93f9 563#endif
83df96d6 564}
6a44bffd 565
e5053ade
JS
566// For implementation purposes - sometimes decorations make the client area
567// smaller
568wxPoint wxTopLevelWindowX11::GetClientAreaOrigin() const
569{
418d4918
JS
570 // In fact wxFrame::GetClientAreaOrigin
571 // does the required calculation already.
572#if 0
e5053ade
JS
573 if (this->IsKindOf(CLASSINFO(wxFrame)))
574 {
575 wxFrame* frame = (wxFrame*) this;
576 if (frame->GetMenuBar())
577 return wxPoint(0, frame->GetMenuBar()->GetSize().y);
578 }
418d4918 579#endif
e5053ade
JS
580 return wxPoint(0, 0);
581}
582
583void wxTopLevelWindowX11::DoGetClientSize( int *width, int *height ) const
584{
585 wxWindowX11::DoGetClientSize(width, height);
418d4918
JS
586 // Done by wxTopLevelWindow
587#if 0
e5053ade
JS
588 if (this->IsKindOf(CLASSINFO(wxFrame)))
589 {
590 wxFrame* frame = (wxFrame*) this;
591 if (frame->GetMenuBar())
592 (*height) -= frame->GetMenuBar()->GetSize().y;
593 if (frame->GetStatusBar())
594 (*height) -= frame->GetStatusBar()->GetSize().y;
595 }
418d4918 596#endif
e5053ade
JS
597}
598
599void wxTopLevelWindowX11::DoSetClientSize(int width, int height)
600{
e5053ade 601 wxWindowX11::DoSetClientSize(width, height);
3a0b23eb 602
e5053ade
JS
603#if 0
604 if (!GetMainWindow())
605 return;
606
607 XWindowChanges windowChanges;
608 int valueMask = 0;
609
610 if (width != -1)
611 {
612 windowChanges.width = width ;
613 valueMask |= CWWidth;
614 }
615 if (height != -1)
616 {
617 windowChanges.height = height ;
618 valueMask |= CWHeight;
619 }
620 XConfigureWindow(wxGlobalDisplay(), (Window) GetMainWindow(),
621 valueMask, & windowChanges);
622#endif
623}
3a0b23eb
JS
624
625void wxTopLevelWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags)
626{
f809133f 627 // wxLogDebug( "Setting pos: %d, %d", x, y );
3a0b23eb
JS
628 wxWindowX11::DoSetSize(x, y, width, height, sizeFlags);
629
630 wxPoint pt = GetPosition();
f809133f 631 // wxLogDebug( "After, pos: %d, %d", pt.x, pt.y );
3a0b23eb
JS
632#if 0
633 XSync(wxGlobalDisplay(), False);
634 int w, h;
635 GetSize(& w, & h);
636 wxString msg;
637 msg.Printf("Before setting size: %d, %d", w, h);
638 wxLogDebug(msg);
639 if (!GetMainWindow())
640 return;
641
642 XWindowChanges windowChanges;
643 int valueMask = 0;
644
645 if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
646 {
f809133f 647 int yy = 0;
3a0b23eb
JS
648 AdjustForParentClientOrigin( x, yy, sizeFlags);
649 windowChanges.x = x;
650 valueMask |= CWX;
651 }
652 if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
653 {
f809133f 654 int xx = 0;
3a0b23eb
JS
655 AdjustForParentClientOrigin( xx, y, sizeFlags);
656 windowChanges.y = y;
657 valueMask |= CWY;
658 }
659 if (width != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
660 {
661 windowChanges.width = width /* - m_borderSize*2 */;
662 valueMask |= CWWidth;
663 }
664 if (height != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
665 {
666 windowChanges.height = height /* -m_borderSize*2*/;
667 valueMask |= CWHeight;
668 }
669
670 XConfigureWindow(wxGlobalDisplay(), (Window) GetMainWindow(),
671 valueMask, & windowChanges);
672 XSync(wxGlobalDisplay(), False);
673 GetSize(& w, & h);
674 msg.Printf("Tried to set to %d, %d. After setting size: %d, %d", width, height, w, h);
675 wxLogDebug(msg);
676#endif
677}
678
679void wxTopLevelWindowX11::DoGetPosition(int *x, int *y) const
680{
681 XSync(wxGlobalDisplay(), False);
682 Window window = (Window) m_mainWidget;
683 if (window)
684 {
9691c806
RR
685 int offsetX = 0;
686 int offsetY = 0;
3a0b23eb 687
461e93f9 688#if !wxUSE_NANOX
f809133f 689 // wxLogDebug("Translating...");
3a0b23eb
JS
690 Window childWindow;
691 XTranslateCoordinates(wxGlobalDisplay(), window, XDefaultRootWindow(wxGlobalDisplay()),
692 0, 0, & offsetX, & offsetY, & childWindow);
693
f809133f 694 // wxLogDebug("Offset: %d, %d", offsetX, offsetY);
461e93f9 695#endif
3a0b23eb
JS
696
697 XWindowAttributes attr;
698 Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr);
699 wxASSERT(status);
700
701 if (status)
702 {
703 *x = attr.x + offsetX;
704 *y = attr.y + offsetY;
705 }
706 }
707}