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