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