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