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