]>
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 | ||
461e93f9 | 104 | #if !wxUSE_NANOX |
952ebeba RR |
105 | XSetWindowAttributes xattributes; |
106 | XSizeHints size_hints; | |
952ebeba RR |
107 | |
108 | long xattributes_mask = | |
ea596687 | 109 | CWOverrideRedirect | |
952ebeba | 110 | CWBorderPixel | CWBackPixel; |
461e93f9 | 111 | |
2034b748 | 112 | xattributes.background_pixel = m_backgroundColour.GetPixel(); |
952ebeba | 113 | xattributes.border_pixel = BlackPixel( xdisplay, xscreen ); |
5e29f97a JS |
114 | |
115 | // TODO: if we want no border, caption etc., | |
116 | // I think we set this to True to remove decorations | |
7e4501ee | 117 | // No. RR. |
952ebeba | 118 | xattributes.override_redirect = False; |
461e93f9 | 119 | #endif |
952ebeba | 120 | |
edaf57a4 JS |
121 | wxSize size2(size); |
122 | if (size2.x == -1) | |
123 | size2.x = 100; | |
124 | if (size2.y == -1) | |
125 | size2.y = 100; | |
126 | ||
127 | wxPoint pos2(pos); | |
128 | if (pos2.x == -1) | |
129 | pos2.x = 100; | |
130 | if (pos2.y == -1) | |
131 | pos2.y = 100; | |
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, | |
152 | extraFlags | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
307be31a JS |
153 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | |
154 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
155 | PropertyChangeMask ); | |
156 | ||
157 | wxAddWindowToTable( xwindow, (wxWindow*) this ); | |
158 | ||
ba696cfa RR |
159 | // Set background to None which will prevent X11 from clearing the |
160 | // background completely. | |
161 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); | |
162 | ||
461e93f9 | 163 | #if !wxUSE_NANOX |
7e4501ee RR |
164 | if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) |
165 | { | |
166 | if (GetParent() && GetParent()->GetMainWindow()) | |
167 | { | |
168 | Window xparentwindow = (Window) GetParent()->GetMainWindow(); | |
169 | XSetTransientForHint( xdisplay, xwindow, xparentwindow ); | |
170 | } | |
171 | } | |
172 | ||
173 | size_hints.flags = PSize | PPosition; | |
174 | size_hints.x = pos2.x; | |
175 | size_hints.y = pos2.y; | |
edaf57a4 JS |
176 | size_hints.width = size2.x; |
177 | size_hints.height = size2.y; | |
952ebeba RR |
178 | XSetWMNormalHints( xdisplay, xwindow, &size_hints); |
179 | ||
461e93f9 | 180 | XWMHints wm_hints; |
952ebeba RR |
181 | wm_hints.flags = InputHint | StateHint /* | WindowGroupHint */; |
182 | wm_hints.input = True; | |
183 | wm_hints.initial_state = NormalState; | |
184 | XSetWMHints( xdisplay, xwindow, &wm_hints); | |
461e93f9 | 185 | |
7e4501ee RR |
186 | Atom wm_protocols[2]; |
187 | wm_protocols[0] = XInternAtom( xdisplay, "WM_DELETE_WINDOW", False ); | |
188 | wm_protocols[1] = XInternAtom( xdisplay, "WM_TAKE_FOCUS", False ); | |
189 | XSetWMProtocols( xdisplay, xwindow, wm_protocols, 2); | |
461e93f9 | 190 | #endif |
952ebeba | 191 | |
7e4501ee | 192 | wxSetWMDecorations( xwindow, style); |
83df96d6 | 193 | |
b513212d | 194 | SetTitle(title); |
952ebeba RR |
195 | |
196 | return TRUE; | |
83df96d6 JS |
197 | } |
198 | ||
1b0fb34b | 199 | wxTopLevelWindowX11::~wxTopLevelWindowX11() |
83df96d6 | 200 | { |
83df96d6 | 201 | wxTopLevelWindows.DeleteObject(this); |
83df96d6 | 202 | |
1b0fb34b JS |
203 | // If this is the last top-level window, exit. |
204 | if ( wxTheApp && (wxTopLevelWindows.Number() == 0) ) | |
83df96d6 JS |
205 | { |
206 | wxTheApp->SetTopWindow(NULL); | |
207 | ||
208 | if (wxTheApp->GetExitOnFrameDelete()) | |
209 | { | |
210 | // Signal to the app that we're going to close | |
211 | wxTheApp->ExitMainLoop(); | |
212 | } | |
213 | } | |
214 | } | |
215 | ||
1b0fb34b JS |
216 | // ---------------------------------------------------------------------------- |
217 | // wxTopLevelWindowX11 showing | |
218 | // ---------------------------------------------------------------------------- | |
83df96d6 | 219 | |
1b0fb34b | 220 | bool wxTopLevelWindowX11::Show(bool show) |
83df96d6 | 221 | { |
b513212d | 222 | return wxWindowX11::Show(show); |
83df96d6 JS |
223 | } |
224 | ||
1b0fb34b JS |
225 | // ---------------------------------------------------------------------------- |
226 | // wxTopLevelWindowX11 maximize/minimize | |
227 | // ---------------------------------------------------------------------------- | |
83df96d6 | 228 | |
1b0fb34b | 229 | void wxTopLevelWindowX11::Maximize(bool maximize) |
83df96d6 | 230 | { |
1b0fb34b | 231 | // TODO |
83df96d6 JS |
232 | } |
233 | ||
1b0fb34b | 234 | bool wxTopLevelWindowX11::IsMaximized() const |
83df96d6 | 235 | { |
1b0fb34b JS |
236 | // TODO |
237 | return TRUE; | |
83df96d6 JS |
238 | } |
239 | ||
1b0fb34b | 240 | void wxTopLevelWindowX11::Iconize(bool iconize) |
83df96d6 | 241 | { |
b513212d JS |
242 | if (!m_iconized && GetMainWindow()) |
243 | { | |
244 | if (XIconifyWindow(wxGlobalDisplay(), | |
245 | (Window) GetMainWindow(), DefaultScreen(wxGlobalDisplay())) != 0) | |
246 | m_iconized = TRUE; | |
247 | } | |
83df96d6 JS |
248 | } |
249 | ||
1b0fb34b | 250 | bool wxTopLevelWindowX11::IsIconized() const |
83df96d6 | 251 | { |
1b0fb34b | 252 | return m_iconized; |
83df96d6 JS |
253 | } |
254 | ||
1b0fb34b | 255 | void wxTopLevelWindowX11::Restore() |
83df96d6 | 256 | { |
b513212d JS |
257 | // This is the way to deiconify the window, according to the X FAQ |
258 | if (m_iconized && GetMainWindow()) | |
259 | { | |
260 | XMapWindow(wxGlobalDisplay(), (Window) GetMainWindow()); | |
261 | m_iconized = FALSE; | |
262 | } | |
83df96d6 JS |
263 | } |
264 | ||
1b0fb34b JS |
265 | // ---------------------------------------------------------------------------- |
266 | // wxTopLevelWindowX11 fullscreen | |
267 | // ---------------------------------------------------------------------------- | |
83df96d6 | 268 | |
1b0fb34b | 269 | bool wxTopLevelWindowX11::ShowFullScreen(bool show, long style) |
83df96d6 | 270 | { |
1b0fb34b | 271 | if (show) |
83df96d6 | 272 | { |
1b0fb34b JS |
273 | if (IsFullScreen()) |
274 | return FALSE; | |
83df96d6 | 275 | |
1b0fb34b JS |
276 | m_fsIsShowing = TRUE; |
277 | m_fsStyle = style; | |
83df96d6 | 278 | |
1b0fb34b | 279 | // TODO |
83df96d6 | 280 | |
1b0fb34b | 281 | return TRUE; |
83df96d6 | 282 | } |
1b0fb34b | 283 | else |
83df96d6 | 284 | { |
1b0fb34b JS |
285 | if (!IsFullScreen()) |
286 | return FALSE; | |
83df96d6 | 287 | |
1b0fb34b | 288 | m_fsIsShowing = FALSE; |
83df96d6 | 289 | |
1b0fb34b JS |
290 | // TODO |
291 | return TRUE; | |
83df96d6 JS |
292 | } |
293 | } | |
294 | ||
1b0fb34b JS |
295 | // ---------------------------------------------------------------------------- |
296 | // wxTopLevelWindowX11 misc | |
297 | // ---------------------------------------------------------------------------- | |
83df96d6 | 298 | |
1b0fb34b | 299 | void wxTopLevelWindowX11::SetIcon(const wxIcon& icon) |
83df96d6 | 300 | { |
1b0fb34b JS |
301 | // this sets m_icon |
302 | wxTopLevelWindowBase::SetIcon(icon); | |
83df96d6 | 303 | |
b513212d JS |
304 | if (icon.Ok() && GetMainWindow()) |
305 | { | |
461e93f9 JS |
306 | #if wxUSE_NANOX |
307 | #else | |
b513212d | 308 | XWMHints *wmHints = XAllocWMHints(); |
6a44bffd | 309 | wmHints->icon_pixmap = (Pixmap) icon.GetPixmap(); |
b513212d | 310 | |
6a44bffd | 311 | wmHints->flags = IconPixmapHint; |
b513212d JS |
312 | |
313 | if (icon.GetMask()) | |
314 | { | |
6a44bffd | 315 | wmHints->flags |= IconMaskHint; |
a11672a4 | 316 | wmHints->icon_mask = (Pixmap) icon.GetMask()->GetBitmap(); |
b513212d JS |
317 | } |
318 | ||
1b0b798d | 319 | XSetWMHints(wxGlobalDisplay(), (Window) GetMainWindow(), wmHints); |
b513212d | 320 | XFree(wmHints); |
461e93f9 | 321 | #endif |
b513212d JS |
322 | } |
323 | } | |
324 | ||
325 | void wxTopLevelWindowX11::SetTitle(const wxString& title) | |
326 | { | |
327 | m_title = title; | |
328 | if (GetMainWindow()) | |
329 | { | |
330 | XStoreName(wxGlobalDisplay(), (Window) GetMainWindow(), | |
331 | (const char*) title); | |
332 | XSetIconName(wxGlobalDisplay(), (Window) GetMainWindow(), | |
333 | (const char*) title); | |
b28d3abf JS |
334 | |
335 | // Use this if the platform doesn't supply the above functions. | |
b513212d JS |
336 | #if 0 |
337 | XTextProperty textProperty; | |
338 | textProperty.value = (unsigned char*) title; | |
339 | textProperty.encoding = XA_STRING; | |
340 | textProperty.format = 8; | |
341 | textProperty.nitems = 1; | |
342 | ||
343 | XSetTextProperty(wxGlobalDisplay(), (Window) GetMainWindow(), | |
344 | & textProperty, WM_NAME); | |
345 | #endif | |
346 | } | |
347 | } | |
348 | ||
349 | wxString wxTopLevelWindowX11::GetTitle() const | |
350 | { | |
351 | return m_title; | |
352 | } | |
353 | ||
354 | #ifndef MWM_DECOR_BORDER | |
355 | /* bit definitions for MwmHints.flags */ | |
356 | #define MWM_HINTS_FUNCTIONS (1L << 0) | |
357 | #define MWM_HINTS_DECORATIONS (1L << 1) | |
358 | #define MWM_HINTS_INPUT_MODE (1L << 2) | |
359 | #define MWM_HINTS_STATUS (1L << 3) | |
360 | ||
361 | #define MWM_DECOR_ALL (1L << 0) | |
362 | #define MWM_DECOR_BORDER (1L << 1) | |
363 | #define MWM_DECOR_RESIZEH (1L << 2) | |
364 | #define MWM_DECOR_TITLE (1L << 3) | |
365 | #define MWM_DECOR_MENU (1L << 4) | |
366 | #define MWM_DECOR_MINIMIZE (1L << 5) | |
367 | #define MWM_DECOR_MAXIMIZE (1L << 6) | |
368 | #endif | |
369 | ||
370 | struct MwmHints { | |
371 | long flags; | |
372 | long functions; | |
373 | long decorations; | |
374 | long input_mode; | |
375 | }; | |
376 | ||
377 | #define PROP_MOTIF_WM_HINTS_ELEMENTS 5 | |
378 | ||
379 | // Set the window manager decorations according to the | |
380 | // given wxWindows style | |
b28d3abf | 381 | bool wxSetWMDecorations(Window w, long style) |
b513212d | 382 | { |
461e93f9 JS |
383 | #if wxUSE_NANOX |
384 | GR_WM_PROPERTIES wmProp; | |
385 | ||
386 | wmProp.flags = 0; | |
387 | ||
388 | if (style & wxRESIZE_BORDER) | |
389 | { | |
390 | wmProp.props |= GR_WM_PROPS_APPFRAME ; | |
391 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
392 | } | |
393 | ||
394 | if (style & wxSYSTEM_MENU) | |
395 | { | |
396 | wmProp.props |= GR_WM_PROPS_CLOSEBOX ; | |
397 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
398 | } | |
399 | ||
400 | if ((style & wxCAPTION) || | |
401 | (style & wxTINY_CAPTION_HORIZ) || | |
402 | (style & wxTINY_CAPTION_VERT)) | |
403 | { | |
404 | wmProp.props |= GR_WM_PROPS_CAPTION ; | |
405 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
406 | } | |
407 | ||
408 | if (style & wxTHICK_FRAME) | |
409 | { | |
410 | wmProp.props |= GR_WM_PROPS_APPFRAME ; | |
411 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
412 | } | |
413 | ||
414 | if (style & wxSIMPLE_BORDER) | |
415 | { | |
416 | wmProp.props |= GR_WM_PROPS_BORDER ; | |
417 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
418 | } | |
419 | ||
420 | if (style & wxMINIMIZE_BOX) | |
421 | { | |
422 | } | |
423 | ||
424 | if (style & wxMAXIMIZE_BOX) | |
425 | { | |
426 | wmProp.props |= GR_WM_PROPS_MAXIMIZE ; | |
427 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
428 | } | |
429 | ||
430 | if (((style & wxBORDER) != wxBORDER) && ((style & wxTHICK_FRAME) != wxTHICK_FRAME) | |
431 | && ((style & wxRESIZE_BORDER) != wxRESIZE_BORDER)) | |
432 | { | |
433 | wmProp.props |= GR_WM_PROPS_NODECORATE ; | |
434 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
435 | } | |
436 | ||
437 | GrSetWMProperties(w, & wmProp); | |
438 | ||
439 | #else | |
6a44bffd | 440 | if (!wxMWMIsRunning(w)) |
b513212d JS |
441 | return FALSE; |
442 | ||
443 | Atom mwm_wm_hints = XInternAtom(wxGlobalDisplay(),"_MOTIF_WM_HINTS", False); | |
444 | MwmHints hints; | |
445 | hints.flags = 0; | |
446 | hints.decorations = 0; | |
447 | ||
448 | if (style & wxRESIZE_BORDER) | |
449 | { | |
9691c806 | 450 | // wxLogDebug("MWM_DECOR_RESIZEH"); |
b513212d JS |
451 | hints.flags |= MWM_HINTS_DECORATIONS; |
452 | hints.decorations |= MWM_DECOR_RESIZEH; | |
453 | } | |
454 | ||
455 | if (style & wxSYSTEM_MENU) | |
456 | { | |
9691c806 | 457 | // wxLogDebug("MWM_DECOR_MENU"); |
b513212d JS |
458 | hints.flags |= MWM_HINTS_DECORATIONS; |
459 | hints.decorations |= MWM_DECOR_MENU; | |
460 | } | |
461 | ||
462 | if ((style & wxCAPTION) || | |
463 | (style & wxTINY_CAPTION_HORIZ) || | |
464 | (style & wxTINY_CAPTION_VERT)) | |
465 | { | |
9691c806 | 466 | // wxLogDebug("MWM_DECOR_TITLE"); |
b513212d JS |
467 | hints.flags |= MWM_HINTS_DECORATIONS; |
468 | hints.decorations |= MWM_DECOR_TITLE; | |
469 | } | |
470 | ||
307be31a | 471 | if ((style & wxTHICK_FRAME) || (style & wxSIMPLE_BORDER) || (style & wxCAPTION)) |
b513212d | 472 | { |
9691c806 | 473 | // wxLogDebug("MWM_DECOR_BORDER"); |
b513212d JS |
474 | hints.flags |= MWM_HINTS_DECORATIONS; |
475 | hints.decorations |= MWM_DECOR_BORDER; | |
476 | } | |
477 | ||
478 | if (style & wxMINIMIZE_BOX) | |
479 | { | |
9691c806 | 480 | // wxLogDebug("MWM_DECOR_MINIMIZE"); |
b513212d JS |
481 | hints.flags |= MWM_HINTS_DECORATIONS; |
482 | hints.decorations |= MWM_DECOR_MINIMIZE; | |
483 | } | |
484 | ||
485 | if (style & wxMAXIMIZE_BOX) | |
486 | { | |
9691c806 | 487 | // wxLogDebug("MWM_DECOR_MAXIMIZE"); |
b513212d JS |
488 | hints.flags |= MWM_HINTS_DECORATIONS; |
489 | hints.decorations |= MWM_DECOR_MAXIMIZE; | |
490 | } | |
491 | ||
492 | XChangeProperty(wxGlobalDisplay(), | |
493 | w, | |
6a44bffd | 494 | mwm_wm_hints, mwm_wm_hints, |
b513212d JS |
495 | 32, PropModeReplace, |
496 | (unsigned char *) &hints, PROP_MOTIF_WM_HINTS_ELEMENTS); | |
497 | ||
461e93f9 | 498 | #endif |
b513212d JS |
499 | return TRUE; |
500 | } | |
501 | ||
b28d3abf | 502 | bool wxMWMIsRunning(Window w) |
b513212d | 503 | { |
461e93f9 JS |
504 | #if wxUSE_NANOX |
505 | return FALSE; | |
506 | #else | |
68e42278 | 507 | Display *dpy = (Display*)wxGetDisplay(); |
b513212d JS |
508 | Atom motifWmInfo = XInternAtom(dpy, "_MOTIF_WM_INFO", False); |
509 | ||
510 | unsigned long length, bytesafter; | |
511 | unsigned char value[20]; | |
68e42278 RR |
512 | unsigned char *ptr = &value[0]; |
513 | int ret, format; | |
514 | Atom type; | |
b513212d JS |
515 | |
516 | type = format = length = 0; | |
68e42278 | 517 | value[0] = 0; |
b513212d JS |
518 | |
519 | ret = XGetWindowProperty(wxGlobalDisplay(), w, motifWmInfo, | |
520 | 0L, 2, False, motifWmInfo, | |
68e42278 | 521 | &type, &format, &length, &bytesafter, &ptr); |
b513212d JS |
522 | |
523 | return (ret == Success); | |
461e93f9 | 524 | #endif |
83df96d6 | 525 | } |
6a44bffd | 526 | |
e5053ade JS |
527 | // For implementation purposes - sometimes decorations make the client area |
528 | // smaller | |
529 | wxPoint wxTopLevelWindowX11::GetClientAreaOrigin() const | |
530 | { | |
418d4918 JS |
531 | // In fact wxFrame::GetClientAreaOrigin |
532 | // does the required calculation already. | |
533 | #if 0 | |
e5053ade JS |
534 | if (this->IsKindOf(CLASSINFO(wxFrame))) |
535 | { | |
536 | wxFrame* frame = (wxFrame*) this; | |
537 | if (frame->GetMenuBar()) | |
538 | return wxPoint(0, frame->GetMenuBar()->GetSize().y); | |
539 | } | |
418d4918 | 540 | #endif |
e5053ade JS |
541 | return wxPoint(0, 0); |
542 | } | |
543 | ||
544 | void wxTopLevelWindowX11::DoGetClientSize( int *width, int *height ) const | |
545 | { | |
546 | wxWindowX11::DoGetClientSize(width, height); | |
418d4918 JS |
547 | // Done by wxTopLevelWindow |
548 | #if 0 | |
e5053ade JS |
549 | if (this->IsKindOf(CLASSINFO(wxFrame))) |
550 | { | |
551 | wxFrame* frame = (wxFrame*) this; | |
552 | if (frame->GetMenuBar()) | |
553 | (*height) -= frame->GetMenuBar()->GetSize().y; | |
554 | if (frame->GetStatusBar()) | |
555 | (*height) -= frame->GetStatusBar()->GetSize().y; | |
556 | } | |
418d4918 | 557 | #endif |
e5053ade JS |
558 | } |
559 | ||
560 | void wxTopLevelWindowX11::DoSetClientSize(int width, int height) | |
561 | { | |
e5053ade | 562 | wxWindowX11::DoSetClientSize(width, height); |
3a0b23eb | 563 | |
e5053ade JS |
564 | #if 0 |
565 | if (!GetMainWindow()) | |
566 | return; | |
567 | ||
568 | XWindowChanges windowChanges; | |
569 | int valueMask = 0; | |
570 | ||
571 | if (width != -1) | |
572 | { | |
573 | windowChanges.width = width ; | |
574 | valueMask |= CWWidth; | |
575 | } | |
576 | if (height != -1) | |
577 | { | |
578 | windowChanges.height = height ; | |
579 | valueMask |= CWHeight; | |
580 | } | |
581 | XConfigureWindow(wxGlobalDisplay(), (Window) GetMainWindow(), | |
582 | valueMask, & windowChanges); | |
583 | #endif | |
584 | } | |
3a0b23eb JS |
585 | |
586 | void wxTopLevelWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
587 | { | |
9691c806 | 588 | wxLogDebug( "Setting pos: %d, %d", x, y ); |
3a0b23eb JS |
589 | wxWindowX11::DoSetSize(x, y, width, height, sizeFlags); |
590 | ||
591 | wxPoint pt = GetPosition(); | |
9691c806 | 592 | wxLogDebug( "After, pos: %d, %d", pt.x, pt.y ); |
3a0b23eb JS |
593 | #if 0 |
594 | XSync(wxGlobalDisplay(), False); | |
595 | int w, h; | |
596 | GetSize(& w, & h); | |
597 | wxString msg; | |
598 | msg.Printf("Before setting size: %d, %d", w, h); | |
599 | wxLogDebug(msg); | |
600 | if (!GetMainWindow()) | |
601 | return; | |
602 | ||
603 | XWindowChanges windowChanges; | |
604 | int valueMask = 0; | |
605 | ||
606 | if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
607 | { | |
608 | int yy = 0; | |
609 | AdjustForParentClientOrigin( x, yy, sizeFlags); | |
610 | windowChanges.x = x; | |
611 | valueMask |= CWX; | |
612 | } | |
613 | if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
614 | { | |
615 | int xx = 0; | |
616 | AdjustForParentClientOrigin( xx, y, sizeFlags); | |
617 | windowChanges.y = y; | |
618 | valueMask |= CWY; | |
619 | } | |
620 | if (width != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
621 | { | |
622 | windowChanges.width = width /* - m_borderSize*2 */; | |
623 | valueMask |= CWWidth; | |
624 | } | |
625 | if (height != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
626 | { | |
627 | windowChanges.height = height /* -m_borderSize*2*/; | |
628 | valueMask |= CWHeight; | |
629 | } | |
630 | ||
631 | XConfigureWindow(wxGlobalDisplay(), (Window) GetMainWindow(), | |
632 | valueMask, & windowChanges); | |
633 | XSync(wxGlobalDisplay(), False); | |
634 | GetSize(& w, & h); | |
635 | msg.Printf("Tried to set to %d, %d. After setting size: %d, %d", width, height, w, h); | |
636 | wxLogDebug(msg); | |
637 | #endif | |
638 | } | |
639 | ||
640 | void wxTopLevelWindowX11::DoGetPosition(int *x, int *y) const | |
641 | { | |
642 | XSync(wxGlobalDisplay(), False); | |
643 | Window window = (Window) m_mainWidget; | |
644 | if (window) | |
645 | { | |
9691c806 RR |
646 | int offsetX = 0; |
647 | int offsetY = 0; | |
3a0b23eb | 648 | |
461e93f9 | 649 | #if !wxUSE_NANOX |
3a0b23eb JS |
650 | wxLogDebug("Translating..."); |
651 | Window childWindow; | |
652 | XTranslateCoordinates(wxGlobalDisplay(), window, XDefaultRootWindow(wxGlobalDisplay()), | |
653 | 0, 0, & offsetX, & offsetY, & childWindow); | |
654 | ||
9691c806 | 655 | wxLogDebug("Offset: %d, %d", offsetX, offsetY); |
461e93f9 | 656 | #endif |
3a0b23eb JS |
657 | |
658 | XWindowAttributes attr; | |
659 | Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr); | |
660 | wxASSERT(status); | |
661 | ||
662 | if (status) | |
663 | { | |
664 | *x = attr.x + offsetX; | |
665 | *y = attr.y + offsetY; | |
666 | } | |
667 | } | |
668 | } |