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