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