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