]> git.saurik.com Git - wxWidgets.git/blame - src/x11/toplevel.cpp
respect minimal wxTLW size in wxUniv
[wxWidgets.git] / src / x11 / toplevel.cpp
CommitLineData
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"
38#endif //WX_PRECOMP
83df96d6 39
1b0fb34b 40#include "wx/x11/private.h"
b513212d
JS
41#include "X11/Xatom.h"
42#include "X11/Xutil.h"
43
44// Set the window manager decorations according to the
45// given wxWindows style
68e42278 46#if 0
b513212d 47static bool SetWMDecorations(Widget w, long style);
68e42278 48#endif
b513212d
JS
49static bool MWMIsRunning(Window w);
50
83df96d6
JS
51
52// ----------------------------------------------------------------------------
53// globals
54// ----------------------------------------------------------------------------
55
1b0fb34b
JS
56// list of all frames and modeless dialogs
57// wxWindowList wxModelessWindows;
83df96d6
JS
58
59// ----------------------------------------------------------------------------
1b0fb34b 60// wxTopLevelWindowX11 creation
83df96d6
JS
61// ----------------------------------------------------------------------------
62
1b0fb34b
JS
63void wxTopLevelWindowX11::Init()
64{
65 m_iconized =
66 m_maximizeOnShow = FALSE;
83df96d6 67
1b0fb34b
JS
68 // unlike (almost?) all other windows, frames are created hidden
69 m_isShown = FALSE;
83df96d6 70
1b0fb34b
JS
71 // Data to save/restore when calling ShowFullScreen
72 m_fsStyle = 0;
73 m_fsIsMaximized = FALSE;
74 m_fsIsShowing = FALSE;
75}
83df96d6 76
1b0fb34b
JS
77bool wxTopLevelWindowX11::CreateDialog(const wxString& title,
78 const wxPoint& pos,
79 const wxSize& size)
83df96d6 80{
1b0fb34b
JS
81 // TODO
82 return FALSE;
83df96d6
JS
83}
84
1b0fb34b
JS
85bool wxTopLevelWindowX11::CreateFrame(const wxString& title,
86 const wxPoint& pos,
87 const wxSize& size)
83df96d6 88{
1b0fb34b
JS
89 // TODO
90 return FALSE;
91}
83df96d6 92
1b0fb34b
JS
93bool wxTopLevelWindowX11::Create(wxWindow *parent,
94 wxWindowID id,
95 const wxString& title,
96 const wxPoint& pos,
97 const wxSize& size,
98 long style,
99 const wxString& name)
100{
101 // init our fields
102 Init();
83df96d6
JS
103
104 m_windowStyle = style;
105
1b0fb34b 106 SetName(name);
83df96d6 107
1b0fb34b 108 m_windowId = id == -1 ? NewControlId() : id;
83df96d6 109
1b0fb34b 110 wxTopLevelWindows.Append(this);
b513212d
JS
111
112 Atom wm_delete_window = XInternAtom(wxGlobalDisplay(), "WM_DELETE_WINDOW", False);
113
114 XSetWMProtocols(wxGlobalDisplay(), (Window) GetMainWindow(), &wm_delete_window, 1);
68e42278 115#if 0
b513212d 116 SetWMDecorations((Window) GetMainWindow(), style);
68e42278 117#endif
83df96d6 118
b513212d 119 SetTitle(title);
83df96d6 120
1b0fb34b 121 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
83df96d6 122 {
1b0fb34b 123 return CreateDialog(title, pos, size);
83df96d6 124 }
1b0fb34b 125 else // !dialog
83df96d6 126 {
1b0fb34b 127 return CreateFrame(title, pos, size);
83df96d6 128 }
83df96d6
JS
129}
130
1b0fb34b 131wxTopLevelWindowX11::~wxTopLevelWindowX11()
83df96d6 132{
83df96d6 133 wxTopLevelWindows.DeleteObject(this);
83df96d6 134
1b0fb34b
JS
135 if ( wxModelessWindows.Find(this) )
136 wxModelessWindows.DeleteObject(this);
83df96d6 137
1b0fb34b
JS
138 // If this is the last top-level window, exit.
139 if ( wxTheApp && (wxTopLevelWindows.Number() == 0) )
83df96d6
JS
140 {
141 wxTheApp->SetTopWindow(NULL);
142
143 if (wxTheApp->GetExitOnFrameDelete())
144 {
145 // Signal to the app that we're going to close
146 wxTheApp->ExitMainLoop();
147 }
148 }
149}
150
1b0fb34b
JS
151// ----------------------------------------------------------------------------
152// wxTopLevelWindowX11 showing
153// ----------------------------------------------------------------------------
83df96d6 154
1b0fb34b 155bool wxTopLevelWindowX11::Show(bool show)
83df96d6 156{
1b0fb34b
JS
157 if ( !wxWindowBase::Show(show) )
158 return FALSE;
83df96d6 159
b513212d 160 return wxWindowX11::Show(show);
83df96d6
JS
161}
162
1b0fb34b
JS
163// ----------------------------------------------------------------------------
164// wxTopLevelWindowX11 maximize/minimize
165// ----------------------------------------------------------------------------
83df96d6 166
1b0fb34b 167void wxTopLevelWindowX11::Maximize(bool maximize)
83df96d6 168{
1b0fb34b 169 // TODO
83df96d6
JS
170}
171
1b0fb34b 172bool wxTopLevelWindowX11::IsMaximized() const
83df96d6 173{
1b0fb34b
JS
174 // TODO
175 return TRUE;
83df96d6
JS
176}
177
1b0fb34b 178void wxTopLevelWindowX11::Iconize(bool iconize)
83df96d6 179{
b513212d
JS
180 if (!m_iconized && GetMainWindow())
181 {
182 if (XIconifyWindow(wxGlobalDisplay(),
183 (Window) GetMainWindow(), DefaultScreen(wxGlobalDisplay())) != 0)
184 m_iconized = TRUE;
185 }
83df96d6
JS
186}
187
1b0fb34b 188bool wxTopLevelWindowX11::IsIconized() const
83df96d6 189{
1b0fb34b 190 return m_iconized;
83df96d6
JS
191}
192
1b0fb34b 193void wxTopLevelWindowX11::Restore()
83df96d6 194{
b513212d
JS
195 // This is the way to deiconify the window, according to the X FAQ
196 if (m_iconized && GetMainWindow())
197 {
198 XMapWindow(wxGlobalDisplay(), (Window) GetMainWindow());
199 m_iconized = FALSE;
200 }
83df96d6
JS
201}
202
1b0fb34b
JS
203// ----------------------------------------------------------------------------
204// wxTopLevelWindowX11 fullscreen
205// ----------------------------------------------------------------------------
83df96d6 206
1b0fb34b 207bool wxTopLevelWindowX11::ShowFullScreen(bool show, long style)
83df96d6 208{
1b0fb34b 209 if (show)
83df96d6 210 {
1b0fb34b
JS
211 if (IsFullScreen())
212 return FALSE;
83df96d6 213
1b0fb34b
JS
214 m_fsIsShowing = TRUE;
215 m_fsStyle = style;
83df96d6 216
1b0fb34b 217 // TODO
83df96d6 218
1b0fb34b 219 return TRUE;
83df96d6 220 }
1b0fb34b 221 else
83df96d6 222 {
1b0fb34b
JS
223 if (!IsFullScreen())
224 return FALSE;
83df96d6 225
1b0fb34b 226 m_fsIsShowing = FALSE;
83df96d6 227
1b0fb34b
JS
228 // TODO
229 return TRUE;
83df96d6
JS
230 }
231}
232
1b0fb34b
JS
233// ----------------------------------------------------------------------------
234// wxTopLevelWindowX11 misc
235// ----------------------------------------------------------------------------
83df96d6 236
1b0fb34b 237void wxTopLevelWindowX11::SetIcon(const wxIcon& icon)
83df96d6 238{
1b0fb34b
JS
239 // this sets m_icon
240 wxTopLevelWindowBase::SetIcon(icon);
83df96d6 241
b513212d
JS
242 if (icon.Ok() && GetMainWindow())
243 {
68e42278 244#if 0
b513212d
JS
245 XWMHints *wmHints = XAllocWMHints();
246 wmHints.icon_pixmap = (Pixmap) icon.GetPixmap();
247
248 wmHints.flags = IconPixmapHint;
249
250 if (icon.GetMask())
251 {
252 wmHints.flags |= IconMaskHint;
253 wmHints.icon_mask = (Pixmap) icon.GetMask()->GetPixmap();
254 }
255
256 XSetWMHints(wxGlobalDisplay(), (Window) GetMainWindow(),
257 wmHints);
258 XFree(wmHints);
68e42278 259#endif
b513212d
JS
260 }
261}
262
263void wxTopLevelWindowX11::SetTitle(const wxString& title)
264{
265 m_title = title;
266 if (GetMainWindow())
267 {
268 XStoreName(wxGlobalDisplay(), (Window) GetMainWindow(),
269 (const char*) title);
270 XSetIconName(wxGlobalDisplay(), (Window) GetMainWindow(),
271 (const char*) title);
272#if 0
273 XTextProperty textProperty;
274 textProperty.value = (unsigned char*) title;
275 textProperty.encoding = XA_STRING;
276 textProperty.format = 8;
277 textProperty.nitems = 1;
278
279 XSetTextProperty(wxGlobalDisplay(), (Window) GetMainWindow(),
280 & textProperty, WM_NAME);
281#endif
282 }
283}
284
285wxString wxTopLevelWindowX11::GetTitle() const
286{
287 return m_title;
288}
289
290#ifndef MWM_DECOR_BORDER
291/* bit definitions for MwmHints.flags */
292#define MWM_HINTS_FUNCTIONS (1L << 0)
293#define MWM_HINTS_DECORATIONS (1L << 1)
294#define MWM_HINTS_INPUT_MODE (1L << 2)
295#define MWM_HINTS_STATUS (1L << 3)
296
297#define MWM_DECOR_ALL (1L << 0)
298#define MWM_DECOR_BORDER (1L << 1)
299#define MWM_DECOR_RESIZEH (1L << 2)
300#define MWM_DECOR_TITLE (1L << 3)
301#define MWM_DECOR_MENU (1L << 4)
302#define MWM_DECOR_MINIMIZE (1L << 5)
303#define MWM_DECOR_MAXIMIZE (1L << 6)
304#endif
305
306struct MwmHints {
307 long flags;
308 long functions;
309 long decorations;
310 long input_mode;
311};
312
313#define PROP_MOTIF_WM_HINTS_ELEMENTS 5
314
315// Set the window manager decorations according to the
316// given wxWindows style
68e42278 317#if 0
b513212d
JS
318static bool SetWMDecorations(Widget w, long style)
319{
320 if (!MWMIsRunning(w))
321 return FALSE;
322
323 Atom mwm_wm_hints = XInternAtom(wxGlobalDisplay(),"_MOTIF_WM_HINTS", False);
324 MwmHints hints;
325 hints.flags = 0;
326 hints.decorations = 0;
327
328 if (style & wxRESIZE_BORDER)
329 {
330 hints.flags |= MWM_HINTS_DECORATIONS;
331 hints.decorations |= MWM_DECOR_RESIZEH;
332 }
333
334 if (style & wxSYSTEM_MENU)
335 {
336 hints.flags |= MWM_HINTS_DECORATIONS;
337 hints.decorations |= MWM_DECOR_MENU;
338 }
339
340 if ((style & wxCAPTION) ||
341 (style & wxTINY_CAPTION_HORIZ) ||
342 (style & wxTINY_CAPTION_VERT))
343 {
344 hints.flags |= MWM_HINTS_DECORATIONS;
345 hints.decorations |= MWM_DECOR_TITLE;
346 }
347
348 if (style & wxTHICK_FRAME)
349 {
350 hints.flags |= MWM_HINTS_DECORATIONS;
351 hints.decorations |= MWM_DECOR_BORDER;
352 }
353
354 if (style & wxTHICK_FRAME)
355 {
356 hints.flags |= MWM_HINTS_DECORATIONS;
357 hints.decorations |= MWM_DECOR_BORDER;
358 }
359
360 if (style & wxMINIMIZE_BOX)
361 {
362 hints.flags |= MWM_HINTS_DECORATIONS;
363 hints.decorations |= MWM_DECOR_MINIMIZE;
364 }
365
366 if (style & wxMAXIMIZE_BOX)
367 {
368 hints.flags |= MWM_HINTS_DECORATIONS;
369 hints.decorations |= MWM_DECOR_MAXIMIZE;
370 }
371
372 XChangeProperty(wxGlobalDisplay(),
373 w,
374 mwm_wm_hints, mem_wm_hints,
375 32, PropModeReplace,
376 (unsigned char *) &hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
377
378 return TRUE;
379}
68e42278 380#endif
b513212d
JS
381
382static bool MWMIsRunning(Window w)
383{
68e42278 384 Display *dpy = (Display*)wxGetDisplay();
b513212d
JS
385 Atom motifWmInfo = XInternAtom(dpy, "_MOTIF_WM_INFO", False);
386
387 unsigned long length, bytesafter;
388 unsigned char value[20];
68e42278
RR
389 unsigned char *ptr = &value[0];
390 int ret, format;
391 Atom type;
b513212d
JS
392
393 type = format = length = 0;
68e42278 394 value[0] = 0;
b513212d
JS
395
396 ret = XGetWindowProperty(wxGlobalDisplay(), w, motifWmInfo,
397 0L, 2, False, motifWmInfo,
68e42278 398 &type, &format, &length, &bytesafter, &ptr);
b513212d
JS
399
400 return (ret == Success);
83df96d6 401}
b513212d 402