]>
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 RR |
64 | |
65 | m_focusWidget = NULL; | |
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 = | |
ea596687 | 121 | CWOverrideRedirect | |
952ebeba | 122 | CWBorderPixel | CWBackPixel; |
461e93f9 | 123 | |
2034b748 | 124 | xattributes.background_pixel = m_backgroundColour.GetPixel(); |
952ebeba | 125 | xattributes.border_pixel = BlackPixel( xdisplay, xscreen ); |
5e29f97a JS |
126 | |
127 | // TODO: if we want no border, caption etc., | |
128 | // I think we set this to True to remove decorations | |
7e4501ee | 129 | // No. RR. |
952ebeba | 130 | xattributes.override_redirect = False; |
461e93f9 | 131 | #endif |
952ebeba | 132 | |
461e93f9 JS |
133 | #if wxUSE_NANOX |
134 | long backColor, foreColor; | |
135 | backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue()); | |
136 | foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue()); | |
137 | ||
138 | Window xwindow = XCreateWindowWithColor( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, | |
139 | 0, 0, InputOutput, xvisual, backColor, foreColor); | |
140 | #else | |
307be31a | 141 | Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, |
461e93f9 JS |
142 | 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); |
143 | #endif | |
307be31a JS |
144 | m_mainWidget = (WXWindow) xwindow; |
145 | ||
461e93f9 | 146 | int extraFlags = 0; |
256d631a | 147 | #if wxUSE_NANOX |
461e93f9 | 148 | extraFlags |= GR_EVENT_MASK_CLOSE_REQ; |
256d631a | 149 | #endif |
461e93f9 JS |
150 | |
151 | XSelectInput( xdisplay, xwindow, | |
70b8ab77 JS |
152 | extraFlags | |
153 | ExposureMask | | |
154 | KeyPressMask | | |
155 | KeyReleaseMask | | |
156 | ButtonPressMask | | |
157 | ButtonReleaseMask | | |
158 | ButtonMotionMask | | |
159 | EnterWindowMask | | |
160 | LeaveWindowMask | | |
161 | PointerMotionMask | | |
162 | KeymapStateMask | | |
163 | FocusChangeMask | | |
164 | ColormapChangeMask | | |
165 | StructureNotifyMask | | |
166 | PropertyChangeMask | |
167 | ); | |
70b8ab77 | 168 | |
307be31a JS |
169 | wxAddWindowToTable( xwindow, (wxWindow*) this ); |
170 | ||
ba696cfa RR |
171 | // Set background to None which will prevent X11 from clearing the |
172 | // background completely. | |
173 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); | |
174 | ||
461e93f9 | 175 | #if !wxUSE_NANOX |
7e4501ee RR |
176 | if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) |
177 | { | |
178 | if (GetParent() && GetParent()->GetMainWindow()) | |
179 | { | |
180 | Window xparentwindow = (Window) GetParent()->GetMainWindow(); | |
181 | XSetTransientForHint( xdisplay, xwindow, xparentwindow ); | |
182 | } | |
183 | } | |
184 | ||
185 | size_hints.flags = PSize | PPosition; | |
186 | size_hints.x = pos2.x; | |
187 | size_hints.y = pos2.y; | |
edaf57a4 JS |
188 | size_hints.width = size2.x; |
189 | size_hints.height = size2.y; | |
952ebeba RR |
190 | XSetWMNormalHints( xdisplay, xwindow, &size_hints); |
191 | ||
461e93f9 | 192 | XWMHints wm_hints; |
952ebeba RR |
193 | wm_hints.flags = InputHint | StateHint /* | WindowGroupHint */; |
194 | wm_hints.input = True; | |
195 | wm_hints.initial_state = NormalState; | |
196 | XSetWMHints( xdisplay, xwindow, &wm_hints); | |
461e93f9 | 197 | |
7e4501ee RR |
198 | Atom wm_protocols[2]; |
199 | wm_protocols[0] = XInternAtom( xdisplay, "WM_DELETE_WINDOW", False ); | |
200 | wm_protocols[1] = XInternAtom( xdisplay, "WM_TAKE_FOCUS", False ); | |
201 | XSetWMProtocols( xdisplay, xwindow, wm_protocols, 2); | |
461e93f9 | 202 | #endif |
952ebeba | 203 | |
7e4501ee | 204 | wxSetWMDecorations( xwindow, style); |
83df96d6 | 205 | |
b513212d | 206 | SetTitle(title); |
952ebeba RR |
207 | |
208 | return TRUE; | |
83df96d6 JS |
209 | } |
210 | ||
1b0fb34b | 211 | wxTopLevelWindowX11::~wxTopLevelWindowX11() |
83df96d6 | 212 | { |
83df96d6 | 213 | wxTopLevelWindows.DeleteObject(this); |
83df96d6 | 214 | |
1b0fb34b JS |
215 | // If this is the last top-level window, exit. |
216 | if ( wxTheApp && (wxTopLevelWindows.Number() == 0) ) | |
83df96d6 JS |
217 | { |
218 | wxTheApp->SetTopWindow(NULL); | |
219 | ||
220 | if (wxTheApp->GetExitOnFrameDelete()) | |
221 | { | |
222 | // Signal to the app that we're going to close | |
223 | wxTheApp->ExitMainLoop(); | |
224 | } | |
225 | } | |
226 | } | |
227 | ||
1b0fb34b JS |
228 | // ---------------------------------------------------------------------------- |
229 | // wxTopLevelWindowX11 showing | |
230 | // ---------------------------------------------------------------------------- | |
83df96d6 | 231 | |
1b0fb34b | 232 | bool wxTopLevelWindowX11::Show(bool show) |
83df96d6 | 233 | { |
e25f954b JS |
234 | // Nano-X has to force a size event, |
235 | // else there's no initial size. | |
236 | #if wxUSE_NANOX | |
237 | if (show) | |
238 | { | |
239 | wxSizeEvent event(GetSize(), GetId()); | |
240 | event.SetEventObject(this); | |
241 | GetEventHandler()->ProcessEvent(event); | |
242 | } | |
243 | #endif | |
244 | ||
b513212d | 245 | return wxWindowX11::Show(show); |
83df96d6 JS |
246 | } |
247 | ||
1b0fb34b JS |
248 | // ---------------------------------------------------------------------------- |
249 | // wxTopLevelWindowX11 maximize/minimize | |
250 | // ---------------------------------------------------------------------------- | |
83df96d6 | 251 | |
1b0fb34b | 252 | void wxTopLevelWindowX11::Maximize(bool maximize) |
83df96d6 | 253 | { |
1b0fb34b | 254 | // TODO |
83df96d6 JS |
255 | } |
256 | ||
1b0fb34b | 257 | bool wxTopLevelWindowX11::IsMaximized() const |
83df96d6 | 258 | { |
1b0fb34b JS |
259 | // TODO |
260 | return TRUE; | |
83df96d6 JS |
261 | } |
262 | ||
1b0fb34b | 263 | void wxTopLevelWindowX11::Iconize(bool iconize) |
83df96d6 | 264 | { |
b513212d JS |
265 | if (!m_iconized && GetMainWindow()) |
266 | { | |
267 | if (XIconifyWindow(wxGlobalDisplay(), | |
268 | (Window) GetMainWindow(), DefaultScreen(wxGlobalDisplay())) != 0) | |
269 | m_iconized = TRUE; | |
270 | } | |
83df96d6 JS |
271 | } |
272 | ||
1b0fb34b | 273 | bool wxTopLevelWindowX11::IsIconized() const |
83df96d6 | 274 | { |
1b0fb34b | 275 | return m_iconized; |
83df96d6 JS |
276 | } |
277 | ||
1b0fb34b | 278 | void wxTopLevelWindowX11::Restore() |
83df96d6 | 279 | { |
b513212d JS |
280 | // This is the way to deiconify the window, according to the X FAQ |
281 | if (m_iconized && GetMainWindow()) | |
282 | { | |
283 | XMapWindow(wxGlobalDisplay(), (Window) GetMainWindow()); | |
284 | m_iconized = FALSE; | |
285 | } | |
83df96d6 JS |
286 | } |
287 | ||
1b0fb34b JS |
288 | // ---------------------------------------------------------------------------- |
289 | // wxTopLevelWindowX11 fullscreen | |
290 | // ---------------------------------------------------------------------------- | |
83df96d6 | 291 | |
1b0fb34b | 292 | bool wxTopLevelWindowX11::ShowFullScreen(bool show, long style) |
83df96d6 | 293 | { |
1b0fb34b | 294 | if (show) |
83df96d6 | 295 | { |
1b0fb34b JS |
296 | if (IsFullScreen()) |
297 | return FALSE; | |
83df96d6 | 298 | |
1b0fb34b JS |
299 | m_fsIsShowing = TRUE; |
300 | m_fsStyle = style; | |
83df96d6 | 301 | |
1b0fb34b | 302 | // TODO |
83df96d6 | 303 | |
1b0fb34b | 304 | return TRUE; |
83df96d6 | 305 | } |
1b0fb34b | 306 | else |
83df96d6 | 307 | { |
1b0fb34b JS |
308 | if (!IsFullScreen()) |
309 | return FALSE; | |
83df96d6 | 310 | |
1b0fb34b | 311 | m_fsIsShowing = FALSE; |
83df96d6 | 312 | |
1b0fb34b JS |
313 | // TODO |
314 | return TRUE; | |
83df96d6 JS |
315 | } |
316 | } | |
317 | ||
1b0fb34b JS |
318 | // ---------------------------------------------------------------------------- |
319 | // wxTopLevelWindowX11 misc | |
320 | // ---------------------------------------------------------------------------- | |
83df96d6 | 321 | |
1b0fb34b | 322 | void wxTopLevelWindowX11::SetIcon(const wxIcon& icon) |
83df96d6 | 323 | { |
1b0fb34b JS |
324 | // this sets m_icon |
325 | wxTopLevelWindowBase::SetIcon(icon); | |
83df96d6 | 326 | |
b513212d JS |
327 | if (icon.Ok() && GetMainWindow()) |
328 | { | |
461e93f9 JS |
329 | #if wxUSE_NANOX |
330 | #else | |
b513212d | 331 | XWMHints *wmHints = XAllocWMHints(); |
6a44bffd | 332 | wmHints->icon_pixmap = (Pixmap) icon.GetPixmap(); |
b513212d | 333 | |
6a44bffd | 334 | wmHints->flags = IconPixmapHint; |
b513212d JS |
335 | |
336 | if (icon.GetMask()) | |
337 | { | |
6a44bffd | 338 | wmHints->flags |= IconMaskHint; |
a11672a4 | 339 | wmHints->icon_mask = (Pixmap) icon.GetMask()->GetBitmap(); |
b513212d JS |
340 | } |
341 | ||
1b0b798d | 342 | XSetWMHints(wxGlobalDisplay(), (Window) GetMainWindow(), wmHints); |
b513212d | 343 | XFree(wmHints); |
461e93f9 | 344 | #endif |
b513212d JS |
345 | } |
346 | } | |
347 | ||
348 | void wxTopLevelWindowX11::SetTitle(const wxString& title) | |
349 | { | |
350 | m_title = title; | |
351 | if (GetMainWindow()) | |
352 | { | |
353 | XStoreName(wxGlobalDisplay(), (Window) GetMainWindow(), | |
354 | (const char*) title); | |
355 | XSetIconName(wxGlobalDisplay(), (Window) GetMainWindow(), | |
356 | (const char*) title); | |
b28d3abf JS |
357 | |
358 | // Use this if the platform doesn't supply the above functions. | |
b513212d JS |
359 | #if 0 |
360 | XTextProperty textProperty; | |
361 | textProperty.value = (unsigned char*) title; | |
362 | textProperty.encoding = XA_STRING; | |
363 | textProperty.format = 8; | |
364 | textProperty.nitems = 1; | |
365 | ||
366 | XSetTextProperty(wxGlobalDisplay(), (Window) GetMainWindow(), | |
367 | & textProperty, WM_NAME); | |
368 | #endif | |
369 | } | |
370 | } | |
371 | ||
372 | wxString wxTopLevelWindowX11::GetTitle() const | |
373 | { | |
374 | return m_title; | |
375 | } | |
376 | ||
377 | #ifndef MWM_DECOR_BORDER | |
378 | /* bit definitions for MwmHints.flags */ | |
379 | #define MWM_HINTS_FUNCTIONS (1L << 0) | |
380 | #define MWM_HINTS_DECORATIONS (1L << 1) | |
381 | #define MWM_HINTS_INPUT_MODE (1L << 2) | |
382 | #define MWM_HINTS_STATUS (1L << 3) | |
383 | ||
384 | #define MWM_DECOR_ALL (1L << 0) | |
385 | #define MWM_DECOR_BORDER (1L << 1) | |
386 | #define MWM_DECOR_RESIZEH (1L << 2) | |
387 | #define MWM_DECOR_TITLE (1L << 3) | |
388 | #define MWM_DECOR_MENU (1L << 4) | |
389 | #define MWM_DECOR_MINIMIZE (1L << 5) | |
390 | #define MWM_DECOR_MAXIMIZE (1L << 6) | |
391 | #endif | |
392 | ||
393 | struct MwmHints { | |
394 | long flags; | |
395 | long functions; | |
396 | long decorations; | |
397 | long input_mode; | |
398 | }; | |
399 | ||
400 | #define PROP_MOTIF_WM_HINTS_ELEMENTS 5 | |
401 | ||
402 | // Set the window manager decorations according to the | |
403 | // given wxWindows style | |
b28d3abf | 404 | bool wxSetWMDecorations(Window w, long style) |
b513212d | 405 | { |
461e93f9 JS |
406 | #if wxUSE_NANOX |
407 | GR_WM_PROPERTIES wmProp; | |
408 | ||
409 | wmProp.flags = 0; | |
0b5c0e1a | 410 | wmProp.props = 0; |
461e93f9 JS |
411 | |
412 | if (style & wxRESIZE_BORDER) | |
413 | { | |
414 | wmProp.props |= GR_WM_PROPS_APPFRAME ; | |
415 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
416 | } | |
417 | ||
418 | if (style & wxSYSTEM_MENU) | |
419 | { | |
420 | wmProp.props |= GR_WM_PROPS_CLOSEBOX ; | |
421 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
422 | } | |
423 | ||
424 | if ((style & wxCAPTION) || | |
425 | (style & wxTINY_CAPTION_HORIZ) || | |
426 | (style & wxTINY_CAPTION_VERT)) | |
427 | { | |
428 | wmProp.props |= GR_WM_PROPS_CAPTION ; | |
429 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
bc55104d JS |
430 | |
431 | // The default dialog style doesn't include any kind | |
432 | // of border, which is a bit odd. Anyway, inclusion | |
433 | // of a caption surely implies a border. | |
434 | style |= wxTHICK_FRAME; | |
461e93f9 JS |
435 | } |
436 | ||
437 | if (style & wxTHICK_FRAME) | |
438 | { | |
439 | wmProp.props |= GR_WM_PROPS_APPFRAME ; | |
440 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
441 | } | |
442 | ||
443 | if (style & wxSIMPLE_BORDER) | |
444 | { | |
445 | wmProp.props |= GR_WM_PROPS_BORDER ; | |
446 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
447 | } | |
448 | ||
449 | if (style & wxMINIMIZE_BOX) | |
450 | { | |
451 | } | |
452 | ||
453 | if (style & wxMAXIMIZE_BOX) | |
454 | { | |
455 | wmProp.props |= GR_WM_PROPS_MAXIMIZE ; | |
456 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
457 | } | |
458 | ||
459 | if (((style & wxBORDER) != wxBORDER) && ((style & wxTHICK_FRAME) != wxTHICK_FRAME) | |
460 | && ((style & wxRESIZE_BORDER) != wxRESIZE_BORDER)) | |
461 | { | |
462 | wmProp.props |= GR_WM_PROPS_NODECORATE ; | |
463 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
464 | } | |
465 | ||
466 | GrSetWMProperties(w, & wmProp); | |
467 | ||
468 | #else | |
6a44bffd | 469 | if (!wxMWMIsRunning(w)) |
b513212d JS |
470 | return FALSE; |
471 | ||
472 | Atom mwm_wm_hints = XInternAtom(wxGlobalDisplay(),"_MOTIF_WM_HINTS", False); | |
473 | MwmHints hints; | |
474 | hints.flags = 0; | |
475 | hints.decorations = 0; | |
476 | ||
477 | if (style & wxRESIZE_BORDER) | |
478 | { | |
9691c806 | 479 | // wxLogDebug("MWM_DECOR_RESIZEH"); |
b513212d JS |
480 | hints.flags |= MWM_HINTS_DECORATIONS; |
481 | hints.decorations |= MWM_DECOR_RESIZEH; | |
482 | } | |
483 | ||
484 | if (style & wxSYSTEM_MENU) | |
485 | { | |
9691c806 | 486 | // wxLogDebug("MWM_DECOR_MENU"); |
b513212d JS |
487 | hints.flags |= MWM_HINTS_DECORATIONS; |
488 | hints.decorations |= MWM_DECOR_MENU; | |
489 | } | |
490 | ||
491 | if ((style & wxCAPTION) || | |
492 | (style & wxTINY_CAPTION_HORIZ) || | |
493 | (style & wxTINY_CAPTION_VERT)) | |
494 | { | |
9691c806 | 495 | // wxLogDebug("MWM_DECOR_TITLE"); |
b513212d JS |
496 | hints.flags |= MWM_HINTS_DECORATIONS; |
497 | hints.decorations |= MWM_DECOR_TITLE; | |
498 | } | |
499 | ||
307be31a | 500 | if ((style & wxTHICK_FRAME) || (style & wxSIMPLE_BORDER) || (style & wxCAPTION)) |
b513212d | 501 | { |
9691c806 | 502 | // wxLogDebug("MWM_DECOR_BORDER"); |
b513212d JS |
503 | hints.flags |= MWM_HINTS_DECORATIONS; |
504 | hints.decorations |= MWM_DECOR_BORDER; | |
505 | } | |
506 | ||
507 | if (style & wxMINIMIZE_BOX) | |
508 | { | |
9691c806 | 509 | // wxLogDebug("MWM_DECOR_MINIMIZE"); |
b513212d JS |
510 | hints.flags |= MWM_HINTS_DECORATIONS; |
511 | hints.decorations |= MWM_DECOR_MINIMIZE; | |
512 | } | |
513 | ||
514 | if (style & wxMAXIMIZE_BOX) | |
515 | { | |
9691c806 | 516 | // wxLogDebug("MWM_DECOR_MAXIMIZE"); |
b513212d JS |
517 | hints.flags |= MWM_HINTS_DECORATIONS; |
518 | hints.decorations |= MWM_DECOR_MAXIMIZE; | |
519 | } | |
520 | ||
521 | XChangeProperty(wxGlobalDisplay(), | |
522 | w, | |
6a44bffd | 523 | mwm_wm_hints, mwm_wm_hints, |
b513212d JS |
524 | 32, PropModeReplace, |
525 | (unsigned char *) &hints, PROP_MOTIF_WM_HINTS_ELEMENTS); | |
526 | ||
461e93f9 | 527 | #endif |
b513212d JS |
528 | return TRUE; |
529 | } | |
530 | ||
b28d3abf | 531 | bool wxMWMIsRunning(Window w) |
b513212d | 532 | { |
461e93f9 JS |
533 | #if wxUSE_NANOX |
534 | return FALSE; | |
535 | #else | |
68e42278 | 536 | Display *dpy = (Display*)wxGetDisplay(); |
b513212d JS |
537 | Atom motifWmInfo = XInternAtom(dpy, "_MOTIF_WM_INFO", False); |
538 | ||
539 | unsigned long length, bytesafter; | |
540 | unsigned char value[20]; | |
68e42278 RR |
541 | unsigned char *ptr = &value[0]; |
542 | int ret, format; | |
543 | Atom type; | |
b513212d JS |
544 | |
545 | type = format = length = 0; | |
68e42278 | 546 | value[0] = 0; |
b513212d JS |
547 | |
548 | ret = XGetWindowProperty(wxGlobalDisplay(), w, motifWmInfo, | |
549 | 0L, 2, False, motifWmInfo, | |
68e42278 | 550 | &type, &format, &length, &bytesafter, &ptr); |
b513212d JS |
551 | |
552 | return (ret == Success); | |
461e93f9 | 553 | #endif |
83df96d6 | 554 | } |
6a44bffd | 555 | |
e5053ade JS |
556 | // For implementation purposes - sometimes decorations make the client area |
557 | // smaller | |
558 | wxPoint wxTopLevelWindowX11::GetClientAreaOrigin() const | |
559 | { | |
59db9cfa | 560 | // wxFrame::GetClientAreaOrigin |
418d4918 | 561 | // does the required calculation already. |
e5053ade JS |
562 | return wxPoint(0, 0); |
563 | } | |
564 | ||
565 | void wxTopLevelWindowX11::DoGetClientSize( int *width, int *height ) const | |
566 | { | |
59db9cfa | 567 | XSync(wxGlobalDisplay(), False); |
e5053ade | 568 | wxWindowX11::DoGetClientSize(width, height); |
e5053ade JS |
569 | } |
570 | ||
571 | void wxTopLevelWindowX11::DoSetClientSize(int width, int height) | |
572 | { | |
e5053ade | 573 | wxWindowX11::DoSetClientSize(width, height); |
3a0b23eb | 574 | |
59db9cfa JS |
575 | // Set the top-level window size |
576 | XSizeHints size_hints; | |
577 | wxSize oldSize = GetSize(); | |
578 | wxSize oldClientSize = GetClientSize(); | |
579 | ||
580 | size_hints.flags = PSize; | |
581 | size_hints.width = width + (oldSize.x - oldClientSize.x); | |
582 | size_hints.height = height + (oldSize.y - oldClientSize.y); | |
583 | XSetWMNormalHints( (Display*) GetXDisplay(), (Window) GetMainWindow(), | |
584 | &size_hints); | |
585 | ||
586 | // This seems to be necessary or resizes don't get performed | |
587 | XSync(wxGlobalDisplay(), False); | |
588 | XSync(wxGlobalDisplay(), False); | |
589 | ||
590 | #if 0 | |
591 | wxLogDebug("DoSetClientSize: Tried to set size to %d, %d", (int) size_hints.width, (int) size_hints.height); | |
592 | ||
593 | XSync(wxGlobalDisplay(), False); | |
594 | wxSize newSize = GetSize(); | |
595 | wxLogDebug("New size is %d, %d", (int) newSize.x, (int) newSize.y); | |
596 | #endif | |
597 | ||
e5053ade JS |
598 | #if 0 |
599 | if (!GetMainWindow()) | |
600 | return; | |
601 | ||
602 | XWindowChanges windowChanges; | |
603 | int valueMask = 0; | |
604 | ||
605 | if (width != -1) | |
606 | { | |
607 | windowChanges.width = width ; | |
608 | valueMask |= CWWidth; | |
609 | } | |
610 | if (height != -1) | |
611 | { | |
612 | windowChanges.height = height ; | |
613 | valueMask |= CWHeight; | |
614 | } | |
615 | XConfigureWindow(wxGlobalDisplay(), (Window) GetMainWindow(), | |
616 | valueMask, & windowChanges); | |
617 | #endif | |
618 | } | |
3a0b23eb JS |
619 | |
620 | void wxTopLevelWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
621 | { | |
21689736 | 622 | #if 0 |
f809133f | 623 | // wxLogDebug( "Setting pos: %d, %d", x, y ); |
3a0b23eb | 624 | wxWindowX11::DoSetSize(x, y, width, height, sizeFlags); |
21689736 JS |
625 | #endif |
626 | XSync(wxGlobalDisplay(), False); | |
627 | Window window = (Window) m_mainWidget; | |
628 | if (!window) | |
629 | return ; | |
630 | ||
631 | Display *display = (Display*) GetXDisplay(); | |
632 | Window root = RootWindowOfScreen(DefaultScreenOfDisplay(display)); | |
633 | Window parent_window = window, | |
634 | next_parent = window; | |
635 | ||
636 | // search for the parent that is child of ROOT, because the WM may | |
637 | // reparent twice and notify only the next parent (like FVWM) | |
638 | while (next_parent != root) { | |
639 | Window *theChildren; unsigned int n; | |
640 | parent_window = next_parent; | |
641 | XQueryTree(display, parent_window, &root, | |
642 | &next_parent, &theChildren, &n); | |
643 | XFree(theChildren); // not needed | |
644 | } | |
645 | ||
646 | XWindowChanges windowChanges; | |
647 | windowChanges.x = x; | |
648 | windowChanges.y = y; | |
649 | windowChanges.width = width; | |
650 | windowChanges.height = height; | |
651 | windowChanges.stack_mode = 0; | |
652 | int valueMask = CWX | CWY | CWWidth | CWHeight; | |
653 | ||
654 | if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
655 | { | |
656 | valueMask |= CWX; | |
657 | } | |
658 | if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
659 | { | |
660 | valueMask |= CWY; | |
661 | } | |
662 | if (width != -1) | |
663 | { | |
664 | windowChanges.width = wxMax(1, width); | |
665 | valueMask |= CWWidth; | |
666 | } | |
667 | if (height != -1) | |
668 | { | |
669 | windowChanges.height = wxMax(1, height); | |
670 | valueMask |= CWHeight; | |
671 | } | |
3a0b23eb | 672 | |
21689736 JS |
673 | XConfigureWindow( display, parent_window, valueMask, &windowChanges ); |
674 | ||
59db9cfa JS |
675 | XSizeHints size_hints; |
676 | size_hints.flags = 0; | |
677 | if (x > -1 && y > -1) | |
678 | size_hints.flags |= PPosition; | |
679 | if (width > -1 && height > -1) | |
680 | size_hints.flags |= PSize; | |
681 | size_hints.width = width; | |
682 | size_hints.height = height; | |
683 | size_hints.x = x; | |
684 | size_hints.y = y; | |
685 | XSetWMNormalHints( (Display*) GetXDisplay(), (Window) GetMainWindow(), | |
686 | &size_hints); | |
687 | ||
688 | // This seems to be necessary or resizes don't get performed. | |
689 | // Take them out (or even just one of them), and the About | |
690 | // box of the minimal sample probably won't be resized right. | |
691 | XSync(wxGlobalDisplay(), False); | |
692 | XSync(wxGlobalDisplay(), False); | |
693 | ||
694 | #if 0 | |
695 | wxLogDebug("DoSetSize: Tried to set size to %d, %d", (int) size_hints.width, (int) size_hints.height); | |
696 | ||
697 | XSync(wxGlobalDisplay(), False); | |
698 | wxSize newSize = GetSize(); | |
699 | wxLogDebug("New size is %d, %d", (int) newSize.x, (int) newSize.y); | |
700 | #endif | |
701 | ||
cb78397f | 702 | #if 0 |
3a0b23eb | 703 | wxPoint pt = GetPosition(); |
f809133f | 704 | // wxLogDebug( "After, pos: %d, %d", pt.x, pt.y ); |
cb78397f | 705 | |
3a0b23eb JS |
706 | XSync(wxGlobalDisplay(), False); |
707 | int w, h; | |
708 | GetSize(& w, & h); | |
709 | wxString msg; | |
710 | msg.Printf("Before setting size: %d, %d", w, h); | |
711 | wxLogDebug(msg); | |
712 | if (!GetMainWindow()) | |
713 | return; | |
714 | ||
715 | XWindowChanges windowChanges; | |
716 | int valueMask = 0; | |
717 | ||
718 | if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
719 | { | |
f809133f | 720 | int yy = 0; |
3a0b23eb JS |
721 | AdjustForParentClientOrigin( x, yy, sizeFlags); |
722 | windowChanges.x = x; | |
723 | valueMask |= CWX; | |
724 | } | |
725 | if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
726 | { | |
f809133f | 727 | int xx = 0; |
3a0b23eb JS |
728 | AdjustForParentClientOrigin( xx, y, sizeFlags); |
729 | windowChanges.y = y; | |
730 | valueMask |= CWY; | |
731 | } | |
732 | if (width != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
733 | { | |
734 | windowChanges.width = width /* - m_borderSize*2 */; | |
735 | valueMask |= CWWidth; | |
736 | } | |
737 | if (height != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
738 | { | |
739 | windowChanges.height = height /* -m_borderSize*2*/; | |
740 | valueMask |= CWHeight; | |
741 | } | |
742 | ||
743 | XConfigureWindow(wxGlobalDisplay(), (Window) GetMainWindow(), | |
744 | valueMask, & windowChanges); | |
745 | XSync(wxGlobalDisplay(), False); | |
746 | GetSize(& w, & h); | |
747 | msg.Printf("Tried to set to %d, %d. After setting size: %d, %d", width, height, w, h); | |
748 | wxLogDebug(msg); | |
749 | #endif | |
750 | } | |
751 | ||
752 | void wxTopLevelWindowX11::DoGetPosition(int *x, int *y) const | |
753 | { | |
754 | XSync(wxGlobalDisplay(), False); | |
755 | Window window = (Window) m_mainWidget; | |
21689736 JS |
756 | if (!window) |
757 | return ; | |
758 | ||
759 | Display *display = (Display*) GetXDisplay(); | |
760 | Window root = RootWindowOfScreen(DefaultScreenOfDisplay(display)); | |
761 | Window parent_window = window, | |
762 | next_parent = window; | |
763 | ||
764 | // search for the parent that is child of ROOT, because the WM may | |
765 | // reparent twice and notify only the next parent (like FVWM) | |
766 | while (next_parent != root) { | |
767 | Window *theChildren; unsigned int n; | |
768 | parent_window = next_parent; | |
769 | XQueryTree(display, parent_window, &root, | |
770 | &next_parent, &theChildren, &n); | |
771 | XFree(theChildren); // not needed | |
772 | } | |
773 | int xx, yy; unsigned int dummy; | |
774 | XGetGeometry(display, parent_window, &root, | |
775 | &xx, &yy, &dummy, &dummy, &dummy, &dummy); | |
776 | if (x) *x = xx; | |
777 | if (y) *y = yy; | |
778 | ||
779 | #if 0 | |
3a0b23eb JS |
780 | if (window) |
781 | { | |
9691c806 RR |
782 | int offsetX = 0; |
783 | int offsetY = 0; | |
3a0b23eb | 784 | |
461e93f9 | 785 | #if !wxUSE_NANOX |
f809133f | 786 | // wxLogDebug("Translating..."); |
3a0b23eb JS |
787 | Window childWindow; |
788 | XTranslateCoordinates(wxGlobalDisplay(), window, XDefaultRootWindow(wxGlobalDisplay()), | |
789 | 0, 0, & offsetX, & offsetY, & childWindow); | |
790 | ||
f809133f | 791 | // wxLogDebug("Offset: %d, %d", offsetX, offsetY); |
461e93f9 | 792 | #endif |
3a0b23eb JS |
793 | |
794 | XWindowAttributes attr; | |
795 | Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr); | |
796 | wxASSERT(status); | |
797 | ||
798 | if (status) | |
799 | { | |
800 | *x = attr.x + offsetX; | |
801 | *y = attr.y + offsetY; | |
802 | } | |
803 | } | |
21689736 | 804 | #endif |
3a0b23eb | 805 | } |