]> git.saurik.com Git - wxWidgets.git/blame - src/x11/toplevel.cpp
fix bug with adding entries to a root group containing only subgroups (as shown by...
[wxWidgets.git] / src / x11 / toplevel.cpp
CommitLineData
1b0fb34b 1///////////////////////////////////////////////////////////////////////////////
ffd84c94 2// Name: src/x11/toplevel.cpp
1b0fb34b 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 8// Copyright: (c) 2002 Julian Smart
65571936 9// License: wxWindows licence
1b0fb34b 10///////////////////////////////////////////////////////////////////////////////
83df96d6
JS
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
1b0fb34b
JS
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
83df96d6 22
1b0fb34b
JS
23#ifdef __BORLANDC__
24 #pragma hdrstop
83df96d6
JS
25#endif
26
1832043f
WS
27#include "wx/toplevel.h"
28
1b0fb34b
JS
29#ifndef WX_PRECOMP
30 #include "wx/app.h"
1b0fb34b
JS
31 #include "wx/string.h"
32 #include "wx/log.h"
33 #include "wx/intl.h"
34 #include "wx/frame.h"
e5053ade
JS
35 #include "wx/menu.h"
36 #include "wx/statusbr.h"
9eddec69 37 #include "wx/settings.h"
1b0fb34b 38#endif //WX_PRECOMP
83df96d6 39
1b0fb34b 40#include "wx/x11/private.h"
2034b748 41#include "X11/Xutil.h"
b513212d 42
f618020a
MB
43#include "wx/unix/utilsx11.h"
44
1b0b798d 45bool wxMWMIsRunning(Window w);
b513212d 46
83df96d6 47// ----------------------------------------------------------------------------
1b0fb34b 48// wxTopLevelWindowX11 creation
83df96d6
JS
49// ----------------------------------------------------------------------------
50
1b0fb34b
JS
51void wxTopLevelWindowX11::Init()
52{
53 m_iconized =
ffd84c94 54 m_maximizeOnShow = false;
83df96d6 55
1b0fb34b 56 // unlike (almost?) all other windows, frames are created hidden
ffd84c94 57 m_isShown = false;
83df96d6 58
1b0fb34b
JS
59 // Data to save/restore when calling ShowFullScreen
60 m_fsStyle = 0;
ffd84c94
WS
61 m_fsIsMaximized = false;
62 m_fsIsShowing = false;
63
64 m_needResizeInIdle = false;
65
66 m_x = wxDefaultCoord;
67 m_y = wxDefaultCoord;
c2c0dabf
RR
68 m_width = 20;
69 m_height = 20;
1b0fb34b 70}
83df96d6 71
1b0fb34b
JS
72bool wxTopLevelWindowX11::Create(wxWindow *parent,
73 wxWindowID id,
74 const wxString& title,
75 const wxPoint& pos,
76 const wxSize& size,
77 long style,
78 const wxString& name)
79{
80 // init our fields
81 Init();
83df96d6
JS
82
83 m_windowStyle = style;
b28d3abf 84 m_parent = parent;
83df96d6 85
1b0fb34b 86 SetName(name);
83df96d6 87
ffd84c94 88 m_windowId = id == wxID_ANY ? NewControlId() : id;
83df96d6 89
b28d3abf
JS
90 if (parent)
91 parent->AddChild(this);
92
1b0fb34b 93 wxTopLevelWindows.Append(this);
ffd84c94 94
952ebeba
RR
95 Display *xdisplay = wxGlobalDisplay();
96 int xscreen = DefaultScreen( xdisplay );
97 Visual *xvisual = DefaultVisual( xdisplay, xscreen );
98 Window xparent = RootWindow( xdisplay, xscreen );
2034b748 99 Colormap cm = DefaultColormap( xdisplay, xscreen );
ffd84c94 100
7e085304
RR
101 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)
102 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
103 else
104 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
2034b748 105 m_backgroundColour.CalcPixel( (WXColormap) cm );
ffd84c94
WS
106 m_hasBgCol = true;
107
c2c0dabf
RR
108 m_x = pos.x;
109 if (m_x < -1)
110 m_x = 10;
ffd84c94 111
c2c0dabf
RR
112 m_y = pos.y;
113 if (m_y < 0)
114 m_y = 10;
ffd84c94 115
c2c0dabf
RR
116 m_width = size.x;
117 if (m_width < 0)
118 m_width = 500;
ffd84c94 119
c2c0dabf
RR
120 m_height = size.y;
121 if (m_height < 0)
122 m_height = 380;
ffd84c94 123
461e93f9 124#if !wxUSE_NANOX
952ebeba 125 XSetWindowAttributes xattributes;
ffd84c94 126
952ebeba 127 long xattributes_mask =
952ebeba 128 CWBorderPixel | CWBackPixel;
461e93f9 129
2034b748 130 xattributes.background_pixel = m_backgroundColour.GetPixel();
952ebeba 131 xattributes.border_pixel = BlackPixel( xdisplay, xscreen );
5e29f97a 132
ab6b6b15
RR
133 if (HasFlag( wxNO_BORDER ))
134 {
135 xattributes_mask |= CWOverrideRedirect;
136 xattributes.override_redirect = True;
137 }
ffd84c94 138
e441e1f4 139 if (!HasFlag( wxFULL_REPAINT_ON_RESIZE ))
2f12683e
RR
140 {
141 xattributes_mask |= CWBitGravity;
065722d7 142 xattributes.bit_gravity = NorthWestGravity;
2f12683e 143 }
ffd84c94 144
2f12683e 145 xattributes_mask |= CWEventMask;
ffd84c94 146 xattributes.event_mask =
2f12683e
RR
147 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
148 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
149 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
150 PropertyChangeMask;
ffd84c94 151
c2c0dabf 152 Window xwindow = XCreateWindow( xdisplay, xparent, m_x, m_y, m_width, m_height,
2f12683e
RR
153 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
154#else
461e93f9
JS
155 long backColor, foreColor;
156 backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue());
157 foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue());
ffd84c94 158
c2c0dabf 159 Window xwindow = XCreateWindowWithColor( xdisplay, xparent, m_x, m_y, m_width, m_height,
461e93f9 160 0, 0, InputOutput, xvisual, backColor, foreColor);
461e93f9 161#endif
2f12683e 162
ab6b6b15
RR
163 m_mainWindow = (WXWindow) xwindow;
164 m_clientWindow = (WXWindow) xwindow;
165 wxAddWindowToTable( xwindow, (wxWindow*) this );
307be31a 166
256d631a 167#if wxUSE_NANOX
461e93f9 168 XSelectInput( xdisplay, xwindow,
2f12683e 169 GR_EVENT_MASK_CLOSE_REQ |
70b8ab77
JS
170 ExposureMask |
171 KeyPressMask |
172 KeyReleaseMask |
173 ButtonPressMask |
174 ButtonReleaseMask |
175 ButtonMotionMask |
176 EnterWindowMask |
177 LeaveWindowMask |
178 PointerMotionMask |
179 KeymapStateMask |
180 FocusChangeMask |
181 ColormapChangeMask |
182 StructureNotifyMask |
183 PropertyChangeMask
184 );
2f12683e 185#endif
307be31a 186
ba696cfa
RR
187 // Set background to None which will prevent X11 from clearing the
188 // background completely.
189 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
190
461e93f9 191#if !wxUSE_NANOX
ab6b6b15 192 if (HasFlag( wxSTAY_ON_TOP ))
7e4501ee 193 {
ab6b6b15
RR
194 Window xroot = RootWindow( xdisplay, xscreen );
195 XSetTransientForHint( xdisplay, xwindow, xroot );
196 }
197 else
198 {
199 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)
200 {
201 if (GetParent() && GetParent()->GetMainWindow())
202 {
203 Window xparentwindow = (Window) GetParent()->GetMainWindow();
204 XSetTransientForHint( xdisplay, xwindow, xparentwindow );
205 }
7e4501ee
RR
206 }
207 }
208
c2c0dabf 209 XSizeHints size_hints;
065722d7 210 size_hints.flags = PSize | PPosition | PWinGravity;
c2c0dabf
RR
211 size_hints.x = m_x;
212 size_hints.y = m_y;
213 size_hints.width = m_width;
214 size_hints.height = m_height;
065722d7 215 size_hints.win_gravity = NorthWestGravity;
952ebeba 216 XSetWMNormalHints( xdisplay, xwindow, &size_hints);
ffd84c94 217
461e93f9 218 XWMHints wm_hints;
ab6b6b15
RR
219 wm_hints.flags = InputHint | StateHint;
220 if (GetParent())
ffd84c94 221 {
ab6b6b15
RR
222 wm_hints.flags |= WindowGroupHint;
223 wm_hints.window_group = (Window) GetParent()->GetMainWindow();
224 }
952ebeba
RR
225 wm_hints.input = True;
226 wm_hints.initial_state = NormalState;
227 XSetWMHints( xdisplay, xwindow, &wm_hints);
461e93f9 228
7e4501ee
RR
229 Atom wm_protocols[2];
230 wm_protocols[0] = XInternAtom( xdisplay, "WM_DELETE_WINDOW", False );
231 wm_protocols[1] = XInternAtom( xdisplay, "WM_TAKE_FOCUS", False );
232 XSetWMProtocols( xdisplay, xwindow, wm_protocols, 2);
1016f0de 233
461e93f9 234#endif
ffd84c94 235
7e4501ee 236 wxSetWMDecorations( xwindow, style);
83df96d6 237
b513212d 238 SetTitle(title);
ffd84c94
WS
239
240 return true;
83df96d6
JS
241}
242
1b0fb34b 243wxTopLevelWindowX11::~wxTopLevelWindowX11()
83df96d6 244{
83df96d6 245 wxTopLevelWindows.DeleteObject(this);
83df96d6 246
1b0fb34b 247 // If this is the last top-level window, exit.
09a1dffa 248 if ( wxTheApp && (wxTopLevelWindows.GetCount() == 0) )
83df96d6
JS
249 {
250 wxTheApp->SetTopWindow(NULL);
251
252 if (wxTheApp->GetExitOnFrameDelete())
253 {
254 // Signal to the app that we're going to close
255 wxTheApp->ExitMainLoop();
256 }
257 }
258}
259
77df2fbc
RR
260void wxTopLevelWindowX11::OnInternalIdle()
261{
262 wxWindow::OnInternalIdle();
ffd84c94 263
193e19cf
RR
264 // Do this only after the last idle event so that
265 // all windows have been updated before a new
266 // round of size events is sent
267 if (m_needResizeInIdle && !wxTheApp->Pending())
77df2fbc
RR
268 {
269 wxSizeEvent event( GetClientSize(), GetId() );
270 event.SetEventObject( this );
271 GetEventHandler()->ProcessEvent( event );
ffd84c94
WS
272
273 m_needResizeInIdle = false;
77df2fbc
RR
274 }
275}
276
1b0fb34b
JS
277// ----------------------------------------------------------------------------
278// wxTopLevelWindowX11 showing
279// ----------------------------------------------------------------------------
83df96d6 280
1b0fb34b 281bool wxTopLevelWindowX11::Show(bool show)
83df96d6 282{
e25f954b
JS
283 if (show)
284 {
285 wxSizeEvent event(GetSize(), GetId());
ffd84c94 286
e25f954b
JS
287 event.SetEventObject(this);
288 GetEventHandler()->ProcessEvent(event);
ffd84c94
WS
289
290 m_needResizeInIdle = false;
e25f954b 291 }
7ded318b 292
df0e1b64 293 bool ret = wxWindowX11::Show(show);
ffd84c94 294
df0e1b64 295 return ret;
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 309 // TODO
ffd84c94 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)
ffd84c94 319 m_iconized = true;
b513212d 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());
ffd84c94 334 m_iconized = false;
b513212d 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 346 if (IsFullScreen())
ffd84c94 347 return false;
83df96d6 348
ffd84c94 349 m_fsIsShowing = true;
1b0fb34b 350 m_fsStyle = style;
83df96d6 351
1b0fb34b 352 // TODO
83df96d6 353
ffd84c94 354 return true;
83df96d6 355 }
1b0fb34b 356 else
83df96d6 357 {
1b0fb34b 358 if (!IsFullScreen())
ffd84c94 359 return false;
83df96d6 360
ffd84c94 361 m_fsIsShowing = false;
83df96d6 362
1b0fb34b 363 // TODO
ffd84c94 364 return true;
83df96d6
JS
365 }
366}
367
1b0fb34b
JS
368// ----------------------------------------------------------------------------
369// wxTopLevelWindowX11 misc
370// ----------------------------------------------------------------------------
83df96d6 371
f618020a 372void wxTopLevelWindowX11::DoSetIcon(const wxIcon& icon)
83df96d6 373{
b513212d
JS
374 if (icon.Ok() && GetMainWindow())
375 {
ea098413 376#if !wxUSE_NANOX
b513212d 377 XWMHints *wmHints = XAllocWMHints();
6a44bffd 378 wmHints->icon_pixmap = (Pixmap) icon.GetPixmap();
b513212d 379
6a44bffd 380 wmHints->flags = IconPixmapHint;
b513212d
JS
381
382 if (icon.GetMask())
383 {
6a44bffd 384 wmHints->flags |= IconMaskHint;
a11672a4 385 wmHints->icon_mask = (Pixmap) icon.GetMask()->GetBitmap();
b513212d
JS
386 }
387
1b0b798d 388 XSetWMHints(wxGlobalDisplay(), (Window) GetMainWindow(), wmHints);
b513212d 389 XFree(wmHints);
461e93f9 390#endif
b513212d
JS
391 }
392}
393
f618020a
MB
394void wxTopLevelWindowX11::SetIcons(const wxIconBundle& icons )
395{
396 // this sets m_icon
397 wxTopLevelWindowBase::SetIcons( icons );
398
399 DoSetIcon( icons.GetIcon( -1 ) );
85cb693c 400 wxSetIconsX11( wxGlobalDisplay(), GetMainWindow(), icons );
f618020a
MB
401}
402
f7f78039
MB
403bool wxTopLevelWindowX11::SetShape(const wxRegion& region)
404{
405 return wxDoSetShape( wxGlobalDisplay(),
406 (Window)GetMainWindow(),
407 region );
408}
409
b513212d
JS
410void wxTopLevelWindowX11::SetTitle(const wxString& title)
411{
412 m_title = title;
ffd84c94 413
b513212d
JS
414 if (GetMainWindow())
415 {
2b5f62a0
VZ
416#if wxUSE_UNICODE
417 // I wonder of e.g. Metacity takes UTF-8 here
418 XStoreName(wxGlobalDisplay(), (Window) GetMainWindow(),
419 (const char*) title.ToAscii() );
420 XSetIconName(wxGlobalDisplay(), (Window) GetMainWindow(),
421 (const char*) title.ToAscii() );
422#else
b513212d
JS
423 XStoreName(wxGlobalDisplay(), (Window) GetMainWindow(),
424 (const char*) title);
425 XSetIconName(wxGlobalDisplay(), (Window) GetMainWindow(),
426 (const char*) title);
2b5f62a0 427#endif
c2c0dabf
RR
428 }
429}
430
431wxString wxTopLevelWindowX11::GetTitle() const
432{
433 return m_title;
434}
b28d3abf 435
c2c0dabf
RR
436// For implementation purposes - sometimes decorations make the client area
437// smaller
438wxPoint wxTopLevelWindowX11::GetClientAreaOrigin() const
439{
440 // wxFrame::GetClientAreaOrigin
441 // does the required calculation already.
442 return wxPoint(0, 0);
443}
444
445void wxTopLevelWindowX11::DoGetClientSize( int *width, int *height ) const
446{
447 if (width)
448 *width = m_width;
449 if (height)
450 *height = m_height;
451}
452
e97d2576
RR
453void wxTopLevelWindowX11::DoGetSize( int *width, int *height ) const
454{
455 // TODO add non-client size
456
457 if (width)
458 *width = m_width;
459 if (height)
460 *height = m_height;
461}
462
c2c0dabf
RR
463void wxTopLevelWindowX11::DoSetClientSize(int width, int height)
464{
e97d2576
RR
465 int old_width = m_width;
466 int old_height = m_height;
467
c2c0dabf
RR
468 m_width = width;
469 m_height = height;
ffd84c94 470
e97d2576
RR
471 if (m_width == old_width && m_height == old_height)
472 return;
ffd84c94 473
e97d2576 474 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
ffd84c94 475
c2c0dabf
RR
476#if !wxUSE_NANOX
477 XSizeHints size_hints;
478 size_hints.flags = PSize;
479 size_hints.width = width;
480 size_hints.height = height;
481 XSetWMNormalHints( wxGlobalDisplay(), (Window) GetMainWindow(), &size_hints );
482#endif
ffd84c94 483
c2c0dabf
RR
484 wxWindowX11::DoSetClientSize(width, height);
485}
486
487void wxTopLevelWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags)
488{
e97d2576
RR
489 int old_x = m_x;
490 int old_y = m_y;
491 int old_width = m_width;
492 int old_height = m_height;
c2c0dabf 493
ffd84c94 494 if (x != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
c2c0dabf 495 m_x = x;
ffd84c94
WS
496
497 if (y != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
c2c0dabf 498 m_y = y;
ffd84c94
WS
499
500 if (width != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
c2c0dabf 501 m_width = width;
ffd84c94
WS
502
503 if (height != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
c2c0dabf 504 m_height = height;
ffd84c94 505
e97d2576
RR
506 if (m_x == old_x && m_y == old_y && m_width == old_width && m_height == old_height)
507 return;
ffd84c94 508
e97d2576
RR
509 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
510
ffd84c94 511#if !wxUSE_NANOX
c2c0dabf
RR
512 XSizeHints size_hints;
513 size_hints.flags = 0;
514 size_hints.flags |= PPosition;
515 size_hints.flags |= PSize;
516 size_hints.x = m_x;
517 size_hints.y = m_y;
518 size_hints.width = m_width;
519 size_hints.height = m_height;
520 XSetWMNormalHints( wxGlobalDisplay(), (Window) GetMainWindow(), &size_hints);
521#endif
522
523 wxWindowX11::DoSetSize(x, y, width, height, sizeFlags);
ffd84c94 524
b513212d 525#if 0
c2c0dabf
RR
526 Display *display = wxGlobalDisplay();
527 Window root = RootWindowOfScreen(DefaultScreenOfDisplay(display));
528 Window parent_window = window,
529 next_parent = window;
530
531 // search for the parent that is child of ROOT, because the WM may
532 // reparent twice and notify only the next parent (like FVWM)
533 while (next_parent != root) {
534 Window *theChildren;
535#if wxUSE_NANOX
536 GR_COUNT n;
537#else
538 unsigned int n;
b513212d 539#endif
c2c0dabf
RR
540 parent_window = next_parent;
541 XQueryTree(display, parent_window, &root,
542 &next_parent, &theChildren, &n);
543 XFree(theChildren); // not needed
544 }
545
546 XWindowChanges windowChanges;
547 windowChanges.x = x;
548 windowChanges.y = y;
549 windowChanges.width = width;
550 windowChanges.height = height;
551 windowChanges.stack_mode = 0;
552 int valueMask = CWX | CWY | CWWidth | CWHeight;
553
ffd84c94 554 if (x != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
c2c0dabf
RR
555 {
556 valueMask |= CWX;
557 }
ffd84c94 558 if (y != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
c2c0dabf
RR
559 {
560 valueMask |= CWY;
b513212d 561 }
ffd84c94 562 if (width != wxDefaultCoord)
c2c0dabf
RR
563 {
564 windowChanges.width = wxMax(1, width);
565 valueMask |= CWWidth;
566 }
ffd84c94 567 if (height != wxDefaultCoord)
c2c0dabf
RR
568 {
569 windowChanges.height = wxMax(1, height);
570 valueMask |= CWHeight;
571 }
572
573 XConfigureWindow( display, parent_window, valueMask, &windowChanges );
574#endif
b513212d
JS
575}
576
c2c0dabf 577void wxTopLevelWindowX11::DoGetPosition(int *x, int *y) const
b513212d 578{
c2c0dabf
RR
579 XSync(wxGlobalDisplay(), False);
580 Window window = (Window) m_mainWindow;
581 if (!window)
582 return ;
583
584 Display *display = wxGlobalDisplay();
585 Window root = RootWindowOfScreen(DefaultScreenOfDisplay(display));
586 Window parent_window = window,
587 next_parent = window;
588
589 // search for the parent that is child of ROOT, because the WM may
590 // reparent twice and notify only the next parent (like FVWM)
591 while (next_parent != root) {
592 Window *theChildren;
593#if wxUSE_NANOX
594 GR_COUNT n;
595#else
596 unsigned int n;
597#endif
598 parent_window = next_parent;
599 XQueryTree(display, parent_window, &root,
600 &next_parent, &theChildren, &n);
601 XFree(theChildren); // not needed
602 }
603#if 0
604 int xx, yy; unsigned int dummy;
605 XGetGeometry(display, parent_window, &root,
606 &xx, &yy, &dummy, &dummy, &dummy, &dummy);
607 if (x) *x = xx;
608 if (y) *y = yy;
609#else
610 XWindowAttributes attr;
611 Status status = XGetWindowAttributes( wxGlobalDisplay(), parent_window, & attr);
612 if (status)
613 {
614 if (x) *x = attr.x;
615 if (y) *y = attr.y;
616 }
617 else
618 {
619 if (x) *x = 0;
620 if (y) *y = 0;
621 }
622#endif
b513212d
JS
623}
624
c2c0dabf 625
b513212d 626#ifndef MWM_DECOR_BORDER
5268c5a3
RR
627
628#define MWM_HINTS_FUNCTIONS (1L << 0)
629#define MWM_HINTS_DECORATIONS (1L << 1)
630#define MWM_HINTS_INPUT_MODE (1L << 2)
631#define MWM_HINTS_STATUS (1L << 3)
b513212d
JS
632
633#define MWM_DECOR_ALL (1L << 0)
634#define MWM_DECOR_BORDER (1L << 1)
635#define MWM_DECOR_RESIZEH (1L << 2)
636#define MWM_DECOR_TITLE (1L << 3)
637#define MWM_DECOR_MENU (1L << 4)
638#define MWM_DECOR_MINIMIZE (1L << 5)
639#define MWM_DECOR_MAXIMIZE (1L << 6)
5268c5a3
RR
640
641#define MWM_FUNC_ALL (1L << 0)
642#define MWM_FUNC_RESIZE (1L << 1)
643#define MWM_FUNC_MOVE (1L << 2)
644#define MWM_FUNC_MINIMIZE (1L << 3)
645#define MWM_FUNC_MAXIMIZE (1L << 4)
646#define MWM_FUNC_CLOSE (1L << 5)
647
648#define MWM_INPUT_MODELESS 0
649#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
650#define MWM_INPUT_SYSTEM_MODAL 2
651#define MWM_INPUT_FULL_APPLICATION_MODAL 3
652#define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
653
ffd84c94 654#define MWM_TEAROFF_WINDOW (1L<<0)
5268c5a3 655
b513212d
JS
656#endif
657
658struct MwmHints {
659 long flags;
660 long functions;
661 long decorations;
662 long input_mode;
663};
664
665#define PROP_MOTIF_WM_HINTS_ELEMENTS 5
666
667// Set the window manager decorations according to the
77ffb593 668// given wxWidgets style
b28d3abf 669bool wxSetWMDecorations(Window w, long style)
b513212d 670{
461e93f9
JS
671#if wxUSE_NANOX
672 GR_WM_PROPERTIES wmProp;
673
674 wmProp.flags = 0;
0b5c0e1a 675 wmProp.props = 0;
461e93f9
JS
676
677 if (style & wxRESIZE_BORDER)
678 {
679 wmProp.props |= GR_WM_PROPS_APPFRAME ;
680 wmProp.flags |= GR_WM_FLAGS_PROPS ;
681 }
682
850c6ed4 683 if (style & wxCLOSE_BOX)
461e93f9
JS
684 {
685 wmProp.props |= GR_WM_PROPS_CLOSEBOX ;
686 wmProp.flags |= GR_WM_FLAGS_PROPS ;
687 }
688
689 if ((style & wxCAPTION) ||
690 (style & wxTINY_CAPTION_HORIZ) ||
691 (style & wxTINY_CAPTION_VERT))
692 {
693 wmProp.props |= GR_WM_PROPS_CAPTION ;
694 wmProp.flags |= GR_WM_FLAGS_PROPS ;
bc55104d
JS
695
696 // The default dialog style doesn't include any kind
697 // of border, which is a bit odd. Anyway, inclusion
698 // of a caption surely implies a border.
1c067fe3 699 style |= wxRESIZE_BORDER;
461e93f9
JS
700 }
701
1c067fe3 702 if (style & wxRESIZE_BORDER)
461e93f9
JS
703 {
704 wmProp.props |= GR_WM_PROPS_APPFRAME ;
705 wmProp.flags |= GR_WM_FLAGS_PROPS ;
706 }
707
708 if (style & wxSIMPLE_BORDER)
709 {
710 wmProp.props |= GR_WM_PROPS_BORDER ;
711 wmProp.flags |= GR_WM_FLAGS_PROPS ;
712 }
713
714 if (style & wxMINIMIZE_BOX)
715 {
716 }
717
718 if (style & wxMAXIMIZE_BOX)
719 {
720 wmProp.props |= GR_WM_PROPS_MAXIMIZE ;
721 wmProp.flags |= GR_WM_FLAGS_PROPS ;
722 }
723
1c067fe3 724 if (((style & wxBORDER) != wxBORDER) && ((style & wxRESIZE_BORDER) != wxRESIZE_BORDER)
461e93f9
JS
725 && ((style & wxRESIZE_BORDER) != wxRESIZE_BORDER))
726 {
727 wmProp.props |= GR_WM_PROPS_NODECORATE ;
728 wmProp.flags |= GR_WM_FLAGS_PROPS ;
729 }
730
731 GrSetWMProperties(w, & wmProp);
ffd84c94 732
461e93f9 733#else
b513212d
JS
734
735 Atom mwm_wm_hints = XInternAtom(wxGlobalDisplay(),"_MOTIF_WM_HINTS", False);
5268c5a3 736 if (mwm_wm_hints == 0)
ffd84c94
WS
737 return false;
738
b513212d 739 MwmHints hints;
5268c5a3 740 hints.flags = MWM_HINTS_DECORATIONS | MWM_HINTS_FUNCTIONS;
b513212d 741 hints.decorations = 0;
5268c5a3 742 hints.functions = 0;
ffd84c94 743
5268c5a3 744 if ((style & wxSIMPLE_BORDER) || (style & wxNO_BORDER))
b513212d 745 {
5268c5a3 746 // leave zeros
b513212d 747 }
5268c5a3 748 else
b513212d 749 {
5268c5a3
RR
750 hints.decorations = MWM_DECOR_BORDER;
751 hints.functions = MWM_FUNC_MOVE;
b513212d 752
5268c5a3
RR
753 if ((style & wxCAPTION) != 0)
754 hints.decorations |= MWM_DECOR_TITLE;
ffd84c94 755
5268c5a3 756 if ((style & wxSYSTEM_MENU) != 0)
5268c5a3 757 hints.decorations |= MWM_DECOR_MENU;
ffd84c94 758
850c6ed4 759 if ((style & wxCLOSE_BOX) != 0)
c3d8ee42 760 hints.functions |= MWM_FUNC_CLOSE;
ffd84c94 761
5268c5a3
RR
762 if ((style & wxMINIMIZE_BOX) != 0)
763 {
764 hints.functions |= MWM_FUNC_MINIMIZE;
765 hints.decorations |= MWM_DECOR_MINIMIZE;
766 }
ffd84c94 767
5268c5a3
RR
768 if ((style & wxMAXIMIZE_BOX) != 0)
769 {
770 hints.functions |= MWM_FUNC_MAXIMIZE;
771 hints.decorations |= MWM_DECOR_MAXIMIZE;
772 }
ffd84c94 773
5268c5a3
RR
774 if ((style & wxRESIZE_BORDER) != 0)
775 {
776 hints.functions |= MWM_FUNC_RESIZE;
777 hints.decorations |= MWM_DECOR_RESIZEH;
778 }
b513212d
JS
779 }
780
781 XChangeProperty(wxGlobalDisplay(),
ffd84c94
WS
782 w,
783 mwm_wm_hints, mwm_wm_hints,
784 32, PropModeReplace,
785 (unsigned char *) &hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
b513212d 786
461e93f9 787#endif
ffd84c94 788 return true;
b513212d 789}