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