]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/x11/toplevel.cpp | |
3 | // Purpose: implements wxTopLevelWindow for X11 | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 24.09.01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2002 Julian Smart | |
9 | // License: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // For compilers that support precompilation, includes "wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #include "wx/toplevel.h" | |
28 | ||
29 | #ifndef WX_PRECOMP | |
30 | #include "wx/app.h" | |
31 | #include "wx/string.h" | |
32 | #include "wx/log.h" | |
33 | #include "wx/intl.h" | |
34 | #include "wx/frame.h" | |
35 | #include "wx/menu.h" | |
36 | #include "wx/statusbr.h" | |
37 | #include "wx/settings.h" | |
38 | #endif //WX_PRECOMP | |
39 | ||
40 | #include "wx/x11/private.h" | |
41 | #include "X11/Xutil.h" | |
42 | ||
43 | #include "wx/unix/utilsx11.h" | |
44 | ||
45 | bool wxMWMIsRunning(Window w); | |
46 | ||
47 | // ---------------------------------------------------------------------------- | |
48 | // wxTopLevelWindowX11 creation | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
51 | void wxTopLevelWindowX11::Init() | |
52 | { | |
53 | m_iconized = | |
54 | m_maximizeOnShow = false; | |
55 | ||
56 | // unlike (almost?) all other windows, frames are created hidden | |
57 | m_isShown = false; | |
58 | ||
59 | // Data to save/restore when calling ShowFullScreen | |
60 | m_fsStyle = 0; | |
61 | m_fsIsMaximized = false; | |
62 | m_fsIsShowing = false; | |
63 | ||
64 | m_needResizeInIdle = false; | |
65 | ||
66 | m_x = wxDefaultCoord; | |
67 | m_y = wxDefaultCoord; | |
68 | m_width = 20; | |
69 | m_height = 20; | |
70 | } | |
71 | ||
72 | bool wxTopLevelWindowX11::Create(wxWindow *parent, | |
73 | wxWindowID id, | |
74 | const wxString& title, | |
75 | const wxPoint& pos, | |
76 | const wxSize& size, | |
77 | long style, | |
78 | const wxString& name) | |
79 | { | |
80 | // init our fields | |
81 | Init(); | |
82 | ||
83 | m_windowStyle = style; | |
84 | m_parent = parent; | |
85 | ||
86 | SetName(name); | |
87 | ||
88 | m_windowId = id == wxID_ANY ? NewControlId() : id; | |
89 | ||
90 | if (parent) | |
91 | parent->AddChild(this); | |
92 | ||
93 | wxTopLevelWindows.Append(this); | |
94 | ||
95 | Display *xdisplay = wxGlobalDisplay(); | |
96 | int xscreen = DefaultScreen( xdisplay ); | |
97 | Visual *xvisual = DefaultVisual( xdisplay, xscreen ); | |
98 | Window xparent = RootWindow( xdisplay, xscreen ); | |
99 | Colormap cm = DefaultColormap( xdisplay, xscreen ); | |
100 | ||
101 | if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) | |
102 | m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); | |
103 | else | |
104 | m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE); | |
105 | m_backgroundColour.CalcPixel( (WXColormap) cm ); | |
106 | m_hasBgCol = true; | |
107 | ||
108 | m_x = pos.x; | |
109 | if (m_x < -1) | |
110 | m_x = 10; | |
111 | ||
112 | m_y = pos.y; | |
113 | if (m_y < 0) | |
114 | m_y = 10; | |
115 | ||
116 | m_width = size.x; | |
117 | if (m_width < 0) | |
118 | m_width = 500; | |
119 | ||
120 | m_height = size.y; | |
121 | if (m_height < 0) | |
122 | m_height = 380; | |
123 | ||
124 | #if !wxUSE_NANOX | |
125 | XSetWindowAttributes xattributes; | |
126 | ||
127 | long xattributes_mask = | |
128 | CWBorderPixel | CWBackPixel; | |
129 | ||
130 | xattributes.background_pixel = m_backgroundColour.GetPixel(); | |
131 | xattributes.border_pixel = BlackPixel( xdisplay, xscreen ); | |
132 | ||
133 | if (HasFlag( wxNO_BORDER )) | |
134 | { | |
135 | xattributes_mask |= CWOverrideRedirect; | |
136 | xattributes.override_redirect = True; | |
137 | } | |
138 | ||
139 | if (!HasFlag( wxFULL_REPAINT_ON_RESIZE )) | |
140 | { | |
141 | xattributes_mask |= CWBitGravity; | |
142 | xattributes.bit_gravity = NorthWestGravity; | |
143 | } | |
144 | ||
145 | xattributes_mask |= CWEventMask; | |
146 | xattributes.event_mask = | |
147 | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
148 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
149 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
150 | PropertyChangeMask; | |
151 | ||
152 | Window xwindow = XCreateWindow( xdisplay, xparent, m_x, m_y, m_width, m_height, | |
153 | 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); | |
154 | #else | |
155 | long backColor, foreColor; | |
156 | backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue()); | |
157 | foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue()); | |
158 | ||
159 | Window xwindow = XCreateWindowWithColor( xdisplay, xparent, m_x, m_y, m_width, m_height, | |
160 | 0, 0, InputOutput, xvisual, backColor, foreColor); | |
161 | #endif | |
162 | ||
163 | m_mainWindow = (WXWindow) xwindow; | |
164 | m_clientWindow = (WXWindow) xwindow; | |
165 | wxAddWindowToTable( xwindow, (wxWindow*) this ); | |
166 | ||
167 | #if wxUSE_NANOX | |
168 | XSelectInput( xdisplay, xwindow, | |
169 | GR_EVENT_MASK_CLOSE_REQ | | |
170 | ExposureMask | | |
171 | KeyPressMask | | |
172 | KeyReleaseMask | | |
173 | ButtonPressMask | | |
174 | ButtonReleaseMask | | |
175 | ButtonMotionMask | | |
176 | EnterWindowMask | | |
177 | LeaveWindowMask | | |
178 | PointerMotionMask | | |
179 | KeymapStateMask | | |
180 | FocusChangeMask | | |
181 | ColormapChangeMask | | |
182 | StructureNotifyMask | | |
183 | PropertyChangeMask | |
184 | ); | |
185 | #endif | |
186 | ||
187 | // Set background to None which will prevent X11 from clearing the | |
188 | // background completely. | |
189 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); | |
190 | ||
191 | #if !wxUSE_NANOX | |
192 | if (HasFlag( wxSTAY_ON_TOP )) | |
193 | { | |
194 | Window xroot = RootWindow( xdisplay, xscreen ); | |
195 | XSetTransientForHint( xdisplay, xwindow, xroot ); | |
196 | } | |
197 | else | |
198 | { | |
199 | if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) | |
200 | { | |
201 | if (GetParent() && GetParent()->GetMainWindow()) | |
202 | { | |
203 | Window xparentwindow = (Window) GetParent()->GetMainWindow(); | |
204 | XSetTransientForHint( xdisplay, xwindow, xparentwindow ); | |
205 | } | |
206 | } | |
207 | } | |
208 | ||
209 | XSizeHints size_hints; | |
210 | size_hints.flags = PSize | PPosition | PWinGravity; | |
211 | size_hints.x = m_x; | |
212 | size_hints.y = m_y; | |
213 | size_hints.width = m_width; | |
214 | size_hints.height = m_height; | |
215 | size_hints.win_gravity = NorthWestGravity; | |
216 | XSetWMNormalHints( xdisplay, xwindow, &size_hints); | |
217 | ||
218 | XWMHints wm_hints; | |
219 | wm_hints.flags = InputHint | StateHint; | |
220 | if (GetParent()) | |
221 | { | |
222 | wm_hints.flags |= WindowGroupHint; | |
223 | wm_hints.window_group = (Window) GetParent()->GetMainWindow(); | |
224 | } | |
225 | wm_hints.input = True; | |
226 | wm_hints.initial_state = NormalState; | |
227 | XSetWMHints( xdisplay, xwindow, &wm_hints); | |
228 | ||
229 | Atom wm_protocols[2]; | |
230 | wm_protocols[0] = XInternAtom( xdisplay, "WM_DELETE_WINDOW", False ); | |
231 | wm_protocols[1] = XInternAtom( xdisplay, "WM_TAKE_FOCUS", False ); | |
232 | XSetWMProtocols( xdisplay, xwindow, wm_protocols, 2); | |
233 | ||
234 | #endif | |
235 | ||
236 | wxSetWMDecorations( xwindow, style); | |
237 | ||
238 | SetTitle(title); | |
239 | ||
240 | return true; | |
241 | } | |
242 | ||
243 | wxTopLevelWindowX11::~wxTopLevelWindowX11() | |
244 | { | |
245 | wxTopLevelWindows.DeleteObject(this); | |
246 | ||
247 | // If this is the last top-level window, exit. | |
248 | if ( wxTheApp && (wxTopLevelWindows.GetCount() == 0) ) | |
249 | { | |
250 | wxTheApp->SetTopWindow(NULL); | |
251 | ||
252 | if (wxTheApp->GetExitOnFrameDelete()) | |
253 | { | |
254 | // Signal to the app that we're going to close | |
255 | wxTheApp->ExitMainLoop(); | |
256 | } | |
257 | } | |
258 | } | |
259 | ||
260 | void wxTopLevelWindowX11::OnInternalIdle() | |
261 | { | |
262 | wxWindow::OnInternalIdle(); | |
263 | ||
264 | // Do this only after the last idle event so that | |
265 | // all windows have been updated before a new | |
266 | // round of size events is sent | |
267 | if (m_needResizeInIdle && !wxTheApp->Pending()) | |
268 | { | |
269 | wxSizeEvent event( GetClientSize(), GetId() ); | |
270 | event.SetEventObject( this ); | |
271 | GetEventHandler()->ProcessEvent( event ); | |
272 | ||
273 | m_needResizeInIdle = false; | |
274 | } | |
275 | } | |
276 | ||
277 | // ---------------------------------------------------------------------------- | |
278 | // wxTopLevelWindowX11 showing | |
279 | // ---------------------------------------------------------------------------- | |
280 | ||
281 | bool wxTopLevelWindowX11::Show(bool show) | |
282 | { | |
283 | if (show) | |
284 | { | |
285 | wxSizeEvent event(GetSize(), GetId()); | |
286 | ||
287 | event.SetEventObject(this); | |
288 | GetEventHandler()->ProcessEvent(event); | |
289 | ||
290 | m_needResizeInIdle = false; | |
291 | } | |
292 | ||
293 | bool ret = wxWindowX11::Show(show); | |
294 | ||
295 | return ret; | |
296 | } | |
297 | ||
298 | // ---------------------------------------------------------------------------- | |
299 | // wxTopLevelWindowX11 maximize/minimize | |
300 | // ---------------------------------------------------------------------------- | |
301 | ||
302 | void wxTopLevelWindowX11::Maximize(bool maximize) | |
303 | { | |
304 | // TODO | |
305 | } | |
306 | ||
307 | bool wxTopLevelWindowX11::IsMaximized() const | |
308 | { | |
309 | // TODO | |
310 | return true; | |
311 | } | |
312 | ||
313 | void wxTopLevelWindowX11::Iconize(bool iconize) | |
314 | { | |
315 | if (!m_iconized && GetMainWindow()) | |
316 | { | |
317 | if (XIconifyWindow(wxGlobalDisplay(), | |
318 | (Window) GetMainWindow(), DefaultScreen(wxGlobalDisplay())) != 0) | |
319 | m_iconized = true; | |
320 | } | |
321 | } | |
322 | ||
323 | bool wxTopLevelWindowX11::IsIconized() const | |
324 | { | |
325 | return m_iconized; | |
326 | } | |
327 | ||
328 | void wxTopLevelWindowX11::Restore() | |
329 | { | |
330 | // This is the way to deiconify the window, according to the X FAQ | |
331 | if (m_iconized && GetMainWindow()) | |
332 | { | |
333 | XMapWindow(wxGlobalDisplay(), (Window) GetMainWindow()); | |
334 | m_iconized = false; | |
335 | } | |
336 | } | |
337 | ||
338 | // ---------------------------------------------------------------------------- | |
339 | // wxTopLevelWindowX11 fullscreen | |
340 | // ---------------------------------------------------------------------------- | |
341 | ||
342 | bool wxTopLevelWindowX11::ShowFullScreen(bool show, long style) | |
343 | { | |
344 | if (show) | |
345 | { | |
346 | if (IsFullScreen()) | |
347 | return false; | |
348 | ||
349 | m_fsIsShowing = true; | |
350 | m_fsStyle = style; | |
351 | ||
352 | // TODO | |
353 | ||
354 | return true; | |
355 | } | |
356 | else | |
357 | { | |
358 | if (!IsFullScreen()) | |
359 | return false; | |
360 | ||
361 | m_fsIsShowing = false; | |
362 | ||
363 | // TODO | |
364 | return true; | |
365 | } | |
366 | } | |
367 | ||
368 | // ---------------------------------------------------------------------------- | |
369 | // wxTopLevelWindowX11 misc | |
370 | // ---------------------------------------------------------------------------- | |
371 | ||
372 | void wxTopLevelWindowX11::DoSetIcon(const wxIcon& icon) | |
373 | { | |
374 | if (icon.Ok() && GetMainWindow()) | |
375 | { | |
376 | #if wxUSE_NANOX | |
377 | #else | |
378 | XWMHints *wmHints = XAllocWMHints(); | |
379 | wmHints->icon_pixmap = (Pixmap) icon.GetPixmap(); | |
380 | ||
381 | wmHints->flags = IconPixmapHint; | |
382 | ||
383 | if (icon.GetMask()) | |
384 | { | |
385 | wmHints->flags |= IconMaskHint; | |
386 | wmHints->icon_mask = (Pixmap) icon.GetMask()->GetBitmap(); | |
387 | } | |
388 | ||
389 | XSetWMHints(wxGlobalDisplay(), (Window) GetMainWindow(), wmHints); | |
390 | XFree(wmHints); | |
391 | #endif | |
392 | } | |
393 | } | |
394 | ||
395 | void wxTopLevelWindowX11::SetIcons(const wxIconBundle& icons ) | |
396 | { | |
397 | // this sets m_icon | |
398 | wxTopLevelWindowBase::SetIcons( icons ); | |
399 | ||
400 | DoSetIcon( icons.GetIcon( -1 ) ); | |
401 | wxSetIconsX11( wxGlobalDisplay(), GetMainWindow(), icons ); | |
402 | } | |
403 | ||
404 | bool wxTopLevelWindowX11::SetShape(const wxRegion& region) | |
405 | { | |
406 | return wxDoSetShape( wxGlobalDisplay(), | |
407 | (Window)GetMainWindow(), | |
408 | region ); | |
409 | } | |
410 | ||
411 | void wxTopLevelWindowX11::SetTitle(const wxString& title) | |
412 | { | |
413 | m_title = title; | |
414 | ||
415 | if (GetMainWindow()) | |
416 | { | |
417 | #if wxUSE_UNICODE | |
418 | // I wonder of e.g. Metacity takes UTF-8 here | |
419 | XStoreName(wxGlobalDisplay(), (Window) GetMainWindow(), | |
420 | (const char*) title.ToAscii() ); | |
421 | XSetIconName(wxGlobalDisplay(), (Window) GetMainWindow(), | |
422 | (const char*) title.ToAscii() ); | |
423 | #else | |
424 | XStoreName(wxGlobalDisplay(), (Window) GetMainWindow(), | |
425 | (const char*) title); | |
426 | XSetIconName(wxGlobalDisplay(), (Window) GetMainWindow(), | |
427 | (const char*) title); | |
428 | #endif | |
429 | } | |
430 | } | |
431 | ||
432 | wxString wxTopLevelWindowX11::GetTitle() const | |
433 | { | |
434 | return m_title; | |
435 | } | |
436 | ||
437 | // For implementation purposes - sometimes decorations make the client area | |
438 | // smaller | |
439 | wxPoint wxTopLevelWindowX11::GetClientAreaOrigin() const | |
440 | { | |
441 | // wxFrame::GetClientAreaOrigin | |
442 | // does the required calculation already. | |
443 | return wxPoint(0, 0); | |
444 | } | |
445 | ||
446 | void wxTopLevelWindowX11::DoGetClientSize( int *width, int *height ) const | |
447 | { | |
448 | if (width) | |
449 | *width = m_width; | |
450 | if (height) | |
451 | *height = m_height; | |
452 | } | |
453 | ||
454 | void wxTopLevelWindowX11::DoGetSize( int *width, int *height ) const | |
455 | { | |
456 | // TODO add non-client size | |
457 | ||
458 | if (width) | |
459 | *width = m_width; | |
460 | if (height) | |
461 | *height = m_height; | |
462 | } | |
463 | ||
464 | void wxTopLevelWindowX11::DoSetClientSize(int width, int height) | |
465 | { | |
466 | int old_width = m_width; | |
467 | int old_height = m_height; | |
468 | ||
469 | m_width = width; | |
470 | m_height = height; | |
471 | ||
472 | if (m_width == old_width && m_height == old_height) | |
473 | return; | |
474 | ||
475 | // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height); | |
476 | ||
477 | #if !wxUSE_NANOX | |
478 | XSizeHints size_hints; | |
479 | size_hints.flags = PSize; | |
480 | size_hints.width = width; | |
481 | size_hints.height = height; | |
482 | XSetWMNormalHints( wxGlobalDisplay(), (Window) GetMainWindow(), &size_hints ); | |
483 | #endif | |
484 | ||
485 | wxWindowX11::DoSetClientSize(width, height); | |
486 | } | |
487 | ||
488 | void wxTopLevelWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
489 | { | |
490 | int old_x = m_x; | |
491 | int old_y = m_y; | |
492 | int old_width = m_width; | |
493 | int old_height = m_height; | |
494 | ||
495 | if (x != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
496 | m_x = x; | |
497 | ||
498 | if (y != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
499 | m_y = y; | |
500 | ||
501 | if (width != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
502 | m_width = width; | |
503 | ||
504 | if (height != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
505 | m_height = height; | |
506 | ||
507 | if (m_x == old_x && m_y == old_y && m_width == old_width && m_height == old_height) | |
508 | return; | |
509 | ||
510 | // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height); | |
511 | ||
512 | #if !wxUSE_NANOX | |
513 | XSizeHints size_hints; | |
514 | size_hints.flags = 0; | |
515 | size_hints.flags |= PPosition; | |
516 | size_hints.flags |= PSize; | |
517 | size_hints.x = m_x; | |
518 | size_hints.y = m_y; | |
519 | size_hints.width = m_width; | |
520 | size_hints.height = m_height; | |
521 | XSetWMNormalHints( wxGlobalDisplay(), (Window) GetMainWindow(), &size_hints); | |
522 | #endif | |
523 | ||
524 | wxWindowX11::DoSetSize(x, y, width, height, sizeFlags); | |
525 | ||
526 | #if 0 | |
527 | Display *display = wxGlobalDisplay(); | |
528 | Window root = RootWindowOfScreen(DefaultScreenOfDisplay(display)); | |
529 | Window parent_window = window, | |
530 | next_parent = window; | |
531 | ||
532 | // search for the parent that is child of ROOT, because the WM may | |
533 | // reparent twice and notify only the next parent (like FVWM) | |
534 | while (next_parent != root) { | |
535 | Window *theChildren; | |
536 | #if wxUSE_NANOX | |
537 | GR_COUNT n; | |
538 | #else | |
539 | unsigned int n; | |
540 | #endif | |
541 | parent_window = next_parent; | |
542 | XQueryTree(display, parent_window, &root, | |
543 | &next_parent, &theChildren, &n); | |
544 | XFree(theChildren); // not needed | |
545 | } | |
546 | ||
547 | XWindowChanges windowChanges; | |
548 | windowChanges.x = x; | |
549 | windowChanges.y = y; | |
550 | windowChanges.width = width; | |
551 | windowChanges.height = height; | |
552 | windowChanges.stack_mode = 0; | |
553 | int valueMask = CWX | CWY | CWWidth | CWHeight; | |
554 | ||
555 | if (x != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
556 | { | |
557 | valueMask |= CWX; | |
558 | } | |
559 | if (y != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
560 | { | |
561 | valueMask |= CWY; | |
562 | } | |
563 | if (width != wxDefaultCoord) | |
564 | { | |
565 | windowChanges.width = wxMax(1, width); | |
566 | valueMask |= CWWidth; | |
567 | } | |
568 | if (height != wxDefaultCoord) | |
569 | { | |
570 | windowChanges.height = wxMax(1, height); | |
571 | valueMask |= CWHeight; | |
572 | } | |
573 | ||
574 | XConfigureWindow( display, parent_window, valueMask, &windowChanges ); | |
575 | #endif | |
576 | } | |
577 | ||
578 | void wxTopLevelWindowX11::DoGetPosition(int *x, int *y) const | |
579 | { | |
580 | XSync(wxGlobalDisplay(), False); | |
581 | Window window = (Window) m_mainWindow; | |
582 | if (!window) | |
583 | return ; | |
584 | ||
585 | Display *display = wxGlobalDisplay(); | |
586 | Window root = RootWindowOfScreen(DefaultScreenOfDisplay(display)); | |
587 | Window parent_window = window, | |
588 | next_parent = window; | |
589 | ||
590 | // search for the parent that is child of ROOT, because the WM may | |
591 | // reparent twice and notify only the next parent (like FVWM) | |
592 | while (next_parent != root) { | |
593 | Window *theChildren; | |
594 | #if wxUSE_NANOX | |
595 | GR_COUNT n; | |
596 | #else | |
597 | unsigned int n; | |
598 | #endif | |
599 | parent_window = next_parent; | |
600 | XQueryTree(display, parent_window, &root, | |
601 | &next_parent, &theChildren, &n); | |
602 | XFree(theChildren); // not needed | |
603 | } | |
604 | #if 0 | |
605 | int xx, yy; unsigned int dummy; | |
606 | XGetGeometry(display, parent_window, &root, | |
607 | &xx, &yy, &dummy, &dummy, &dummy, &dummy); | |
608 | if (x) *x = xx; | |
609 | if (y) *y = yy; | |
610 | #else | |
611 | XWindowAttributes attr; | |
612 | Status status = XGetWindowAttributes( wxGlobalDisplay(), parent_window, & attr); | |
613 | if (status) | |
614 | { | |
615 | if (x) *x = attr.x; | |
616 | if (y) *y = attr.y; | |
617 | } | |
618 | else | |
619 | { | |
620 | if (x) *x = 0; | |
621 | if (y) *y = 0; | |
622 | } | |
623 | #endif | |
624 | } | |
625 | ||
626 | ||
627 | #ifndef MWM_DECOR_BORDER | |
628 | ||
629 | #define MWM_HINTS_FUNCTIONS (1L << 0) | |
630 | #define MWM_HINTS_DECORATIONS (1L << 1) | |
631 | #define MWM_HINTS_INPUT_MODE (1L << 2) | |
632 | #define MWM_HINTS_STATUS (1L << 3) | |
633 | ||
634 | #define MWM_DECOR_ALL (1L << 0) | |
635 | #define MWM_DECOR_BORDER (1L << 1) | |
636 | #define MWM_DECOR_RESIZEH (1L << 2) | |
637 | #define MWM_DECOR_TITLE (1L << 3) | |
638 | #define MWM_DECOR_MENU (1L << 4) | |
639 | #define MWM_DECOR_MINIMIZE (1L << 5) | |
640 | #define MWM_DECOR_MAXIMIZE (1L << 6) | |
641 | ||
642 | #define MWM_FUNC_ALL (1L << 0) | |
643 | #define MWM_FUNC_RESIZE (1L << 1) | |
644 | #define MWM_FUNC_MOVE (1L << 2) | |
645 | #define MWM_FUNC_MINIMIZE (1L << 3) | |
646 | #define MWM_FUNC_MAXIMIZE (1L << 4) | |
647 | #define MWM_FUNC_CLOSE (1L << 5) | |
648 | ||
649 | #define MWM_INPUT_MODELESS 0 | |
650 | #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 | |
651 | #define MWM_INPUT_SYSTEM_MODAL 2 | |
652 | #define MWM_INPUT_FULL_APPLICATION_MODAL 3 | |
653 | #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL | |
654 | ||
655 | #define MWM_TEAROFF_WINDOW (1L<<0) | |
656 | ||
657 | #endif | |
658 | ||
659 | struct MwmHints { | |
660 | long flags; | |
661 | long functions; | |
662 | long decorations; | |
663 | long input_mode; | |
664 | }; | |
665 | ||
666 | #define PROP_MOTIF_WM_HINTS_ELEMENTS 5 | |
667 | ||
668 | // Set the window manager decorations according to the | |
669 | // given wxWidgets style | |
670 | bool wxSetWMDecorations(Window w, long style) | |
671 | { | |
672 | #if wxUSE_NANOX | |
673 | GR_WM_PROPERTIES wmProp; | |
674 | ||
675 | wmProp.flags = 0; | |
676 | wmProp.props = 0; | |
677 | ||
678 | if (style & wxRESIZE_BORDER) | |
679 | { | |
680 | wmProp.props |= GR_WM_PROPS_APPFRAME ; | |
681 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
682 | } | |
683 | ||
684 | if (style & wxCLOSE_BOX) | |
685 | { | |
686 | wmProp.props |= GR_WM_PROPS_CLOSEBOX ; | |
687 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
688 | } | |
689 | ||
690 | if ((style & wxCAPTION) || | |
691 | (style & wxTINY_CAPTION_HORIZ) || | |
692 | (style & wxTINY_CAPTION_VERT)) | |
693 | { | |
694 | wmProp.props |= GR_WM_PROPS_CAPTION ; | |
695 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
696 | ||
697 | // The default dialog style doesn't include any kind | |
698 | // of border, which is a bit odd. Anyway, inclusion | |
699 | // of a caption surely implies a border. | |
700 | style |= wxRESIZE_BORDER; | |
701 | } | |
702 | ||
703 | if (style & wxRESIZE_BORDER) | |
704 | { | |
705 | wmProp.props |= GR_WM_PROPS_APPFRAME ; | |
706 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
707 | } | |
708 | ||
709 | if (style & wxSIMPLE_BORDER) | |
710 | { | |
711 | wmProp.props |= GR_WM_PROPS_BORDER ; | |
712 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
713 | } | |
714 | ||
715 | if (style & wxMINIMIZE_BOX) | |
716 | { | |
717 | } | |
718 | ||
719 | if (style & wxMAXIMIZE_BOX) | |
720 | { | |
721 | wmProp.props |= GR_WM_PROPS_MAXIMIZE ; | |
722 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
723 | } | |
724 | ||
725 | if (((style & wxBORDER) != wxBORDER) && ((style & wxRESIZE_BORDER) != wxRESIZE_BORDER) | |
726 | && ((style & wxRESIZE_BORDER) != wxRESIZE_BORDER)) | |
727 | { | |
728 | wmProp.props |= GR_WM_PROPS_NODECORATE ; | |
729 | wmProp.flags |= GR_WM_FLAGS_PROPS ; | |
730 | } | |
731 | ||
732 | GrSetWMProperties(w, & wmProp); | |
733 | ||
734 | #else | |
735 | ||
736 | Atom mwm_wm_hints = XInternAtom(wxGlobalDisplay(),"_MOTIF_WM_HINTS", False); | |
737 | if (mwm_wm_hints == 0) | |
738 | return false; | |
739 | ||
740 | MwmHints hints; | |
741 | hints.flags = MWM_HINTS_DECORATIONS | MWM_HINTS_FUNCTIONS; | |
742 | hints.decorations = 0; | |
743 | hints.functions = 0; | |
744 | ||
745 | if ((style & wxSIMPLE_BORDER) || (style & wxNO_BORDER)) | |
746 | { | |
747 | // leave zeros | |
748 | } | |
749 | else | |
750 | { | |
751 | hints.decorations = MWM_DECOR_BORDER; | |
752 | hints.functions = MWM_FUNC_MOVE; | |
753 | ||
754 | if ((style & wxCAPTION) != 0) | |
755 | hints.decorations |= MWM_DECOR_TITLE; | |
756 | ||
757 | if ((style & wxSYSTEM_MENU) != 0) | |
758 | hints.decorations |= MWM_DECOR_MENU; | |
759 | ||
760 | if ((style & wxCLOSE_BOX) != 0) | |
761 | hints.functions |= MWM_FUNC_CLOSE; | |
762 | ||
763 | if ((style & wxMINIMIZE_BOX) != 0) | |
764 | { | |
765 | hints.functions |= MWM_FUNC_MINIMIZE; | |
766 | hints.decorations |= MWM_DECOR_MINIMIZE; | |
767 | } | |
768 | ||
769 | if ((style & wxMAXIMIZE_BOX) != 0) | |
770 | { | |
771 | hints.functions |= MWM_FUNC_MAXIMIZE; | |
772 | hints.decorations |= MWM_DECOR_MAXIMIZE; | |
773 | } | |
774 | ||
775 | if ((style & wxRESIZE_BORDER) != 0) | |
776 | { | |
777 | hints.functions |= MWM_FUNC_RESIZE; | |
778 | hints.decorations |= MWM_DECOR_RESIZEH; | |
779 | } | |
780 | } | |
781 | ||
782 | XChangeProperty(wxGlobalDisplay(), | |
783 | w, | |
784 | mwm_wm_hints, mwm_wm_hints, | |
785 | 32, PropModeReplace, | |
786 | (unsigned char *) &hints, PROP_MOTIF_WM_HINTS_ELEMENTS); | |
787 | ||
788 | #endif | |
789 | return true; | |
790 | } |