]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/x11/toplevel.cpp
respect minimal wxTLW size in wxUniv
[wxWidgets.git] / src / x11 / toplevel.cpp
... / ...
CommitLineData
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#endif //WX_PRECOMP
39
40#include "wx/x11/private.h"
41#include "X11/Xatom.h"
42#include "X11/Xutil.h"
43
44// Set the window manager decorations according to the
45// given wxWindows style
46#if 0
47static bool SetWMDecorations(Widget w, long style);
48#endif
49static bool MWMIsRunning(Window w);
50
51
52// ----------------------------------------------------------------------------
53// globals
54// ----------------------------------------------------------------------------
55
56// list of all frames and modeless dialogs
57// wxWindowList wxModelessWindows;
58
59// ----------------------------------------------------------------------------
60// wxTopLevelWindowX11 creation
61// ----------------------------------------------------------------------------
62
63void wxTopLevelWindowX11::Init()
64{
65 m_iconized =
66 m_maximizeOnShow = FALSE;
67
68 // unlike (almost?) all other windows, frames are created hidden
69 m_isShown = FALSE;
70
71 // Data to save/restore when calling ShowFullScreen
72 m_fsStyle = 0;
73 m_fsIsMaximized = FALSE;
74 m_fsIsShowing = FALSE;
75}
76
77bool wxTopLevelWindowX11::CreateDialog(const wxString& title,
78 const wxPoint& pos,
79 const wxSize& size)
80{
81 // TODO
82 return FALSE;
83}
84
85bool wxTopLevelWindowX11::CreateFrame(const wxString& title,
86 const wxPoint& pos,
87 const wxSize& size)
88{
89 // TODO
90 return FALSE;
91}
92
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();
103
104 m_windowStyle = style;
105
106 SetName(name);
107
108 m_windowId = id == -1 ? NewControlId() : id;
109
110 wxTopLevelWindows.Append(this);
111
112 Atom wm_delete_window = XInternAtom(wxGlobalDisplay(), "WM_DELETE_WINDOW", False);
113
114 XSetWMProtocols(wxGlobalDisplay(), (Window) GetMainWindow(), &wm_delete_window, 1);
115#if 0
116 SetWMDecorations((Window) GetMainWindow(), style);
117#endif
118
119 SetTitle(title);
120
121 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
122 {
123 return CreateDialog(title, pos, size);
124 }
125 else // !dialog
126 {
127 return CreateFrame(title, pos, size);
128 }
129}
130
131wxTopLevelWindowX11::~wxTopLevelWindowX11()
132{
133 wxTopLevelWindows.DeleteObject(this);
134
135 if ( wxModelessWindows.Find(this) )
136 wxModelessWindows.DeleteObject(this);
137
138 // If this is the last top-level window, exit.
139 if ( wxTheApp && (wxTopLevelWindows.Number() == 0) )
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
151// ----------------------------------------------------------------------------
152// wxTopLevelWindowX11 showing
153// ----------------------------------------------------------------------------
154
155bool wxTopLevelWindowX11::Show(bool show)
156{
157 if ( !wxWindowBase::Show(show) )
158 return FALSE;
159
160 return wxWindowX11::Show(show);
161}
162
163// ----------------------------------------------------------------------------
164// wxTopLevelWindowX11 maximize/minimize
165// ----------------------------------------------------------------------------
166
167void wxTopLevelWindowX11::Maximize(bool maximize)
168{
169 // TODO
170}
171
172bool wxTopLevelWindowX11::IsMaximized() const
173{
174 // TODO
175 return TRUE;
176}
177
178void wxTopLevelWindowX11::Iconize(bool iconize)
179{
180 if (!m_iconized && GetMainWindow())
181 {
182 if (XIconifyWindow(wxGlobalDisplay(),
183 (Window) GetMainWindow(), DefaultScreen(wxGlobalDisplay())) != 0)
184 m_iconized = TRUE;
185 }
186}
187
188bool wxTopLevelWindowX11::IsIconized() const
189{
190 return m_iconized;
191}
192
193void wxTopLevelWindowX11::Restore()
194{
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 }
201}
202
203// ----------------------------------------------------------------------------
204// wxTopLevelWindowX11 fullscreen
205// ----------------------------------------------------------------------------
206
207bool wxTopLevelWindowX11::ShowFullScreen(bool show, long style)
208{
209 if (show)
210 {
211 if (IsFullScreen())
212 return FALSE;
213
214 m_fsIsShowing = TRUE;
215 m_fsStyle = style;
216
217 // TODO
218
219 return TRUE;
220 }
221 else
222 {
223 if (!IsFullScreen())
224 return FALSE;
225
226 m_fsIsShowing = FALSE;
227
228 // TODO
229 return TRUE;
230 }
231}
232
233// ----------------------------------------------------------------------------
234// wxTopLevelWindowX11 misc
235// ----------------------------------------------------------------------------
236
237void wxTopLevelWindowX11::SetIcon(const wxIcon& icon)
238{
239 // this sets m_icon
240 wxTopLevelWindowBase::SetIcon(icon);
241
242 if (icon.Ok() && GetMainWindow())
243 {
244#if 0
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);
259#endif
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
317#if 0
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}
380#endif
381
382static bool MWMIsRunning(Window w)
383{
384 Display *dpy = (Display*)wxGetDisplay();
385 Atom motifWmInfo = XInternAtom(dpy, "_MOTIF_WM_INFO", False);
386
387 unsigned long length, bytesafter;
388 unsigned char value[20];
389 unsigned char *ptr = &value[0];
390 int ret, format;
391 Atom type;
392
393 type = format = length = 0;
394 value[0] = 0;
395
396 ret = XGetWindowProperty(wxGlobalDisplay(), w, motifWmInfo,
397 0L, 2, False, motifWmInfo,
398 &type, &format, &length, &bytesafter, &ptr);
399
400 return (ret == Success);
401}
402