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