]> git.saurik.com Git - wxWidgets.git/blame - src/common/toplvcmn.cpp
support for unicode font names
[wxWidgets.git] / src / common / toplvcmn.cpp
CommitLineData
7d9f12f3
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: common/toplvcmn.cpp
3// Purpose: common (for all platforms) wxTopLevelWindow functions
4// Author: Julian Smart, Vadim Zeitlin
5// Created: 01/02/97
6// Id: $Id$
55d99c7a 7// Copyright: (c) 1998 Robert Roebling and Julian Smart
65571936 8// Licence: wxWindows licence
7d9f12f3
VS
9/////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
7d9f12f3
VS
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#ifndef WX_PRECOMP
27 #include "wx/toplevel.h"
28 #include "wx/dcclient.h"
5f1d3069 29 #include "wx/app.h"
7d9f12f3
VS
30#endif // WX_PRECOMP
31
1f464296
VZ
32#include "wx/display.h"
33
7d9f12f3
VS
34// ----------------------------------------------------------------------------
35// event table
36// ----------------------------------------------------------------------------
37
38BEGIN_EVENT_TABLE(wxTopLevelWindowBase, wxWindow)
39 EVT_CLOSE(wxTopLevelWindowBase::OnCloseWindow)
40 EVT_SIZE(wxTopLevelWindowBase::OnSize)
41END_EVENT_TABLE()
42
43// ============================================================================
44// implementation
45// ============================================================================
46
f58585c0 47IMPLEMENT_ABSTRACT_CLASS(wxTopLevelWindow, wxWindow)
82c9f85c 48
7d9f12f3
VS
49// ----------------------------------------------------------------------------
50// construction/destruction
51// ----------------------------------------------------------------------------
52
53wxTopLevelWindowBase::wxTopLevelWindowBase()
54{
c7e61a5e
DE
55 // Unlike windows, top level windows are created hidden by default.
56 m_isShown = false;
7d9f12f3
VS
57}
58
799ea011
GD
59wxTopLevelWindowBase::~wxTopLevelWindowBase()
60{
1cbee0b4
VZ
61 // don't let wxTheApp keep any stale pointers to us
62 if ( wxTheApp && wxTheApp->GetTopWindow() == this )
63 wxTheApp->SetTopWindow(NULL);
64
65 bool shouldExit = IsLastBeforeExit();
66
67 wxTopLevelWindows.DeleteObject(this);
cb719f2e 68
1cbee0b4
VZ
69 if ( shouldExit )
70 {
71 // then do it
72 wxTheApp->ExitMainLoop();
73 }
799ea011
GD
74}
75
7d9f12f3
VS
76bool wxTopLevelWindowBase::Destroy()
77{
78 // delayed destruction: the frame will be deleted during the next idle
79 // loop iteration
80 if ( !wxPendingDelete.Member(this) )
81 wxPendingDelete.Append(this);
82
b3bd912d
RR
83 if (wxTopLevelWindows.GetCount() > 1)
84 {
85 // Hide it immediately. This should
86 // not be done if this TLW is the
87 // only one left since we then would
88 // risk not to get any idle events
cb719f2e 89 // at all anymore during which we
b3bd912d
RR
90 // could delete any pending events.
91 Hide();
92 }
cafcf62a 93
cb719f2e 94 return true;
7d9f12f3
VS
95}
96
5c363878 97bool wxTopLevelWindowBase::IsLastBeforeExit() const
1cbee0b4
VZ
98{
99 // we exit the application if there are no more top level windows left
100 // normally but wxApp can prevent this from happening
5c363878
VZ
101 return wxTopLevelWindows.GetCount() == 1 &&
102 wxTopLevelWindows.GetFirst()->GetData() == (wxWindow *)this &&
1cbee0b4
VZ
103 wxTheApp && wxTheApp->GetExitOnFrameDelete();
104}
105
106// ----------------------------------------------------------------------------
107// wxTopLevelWindow geometry
108// ----------------------------------------------------------------------------
109
0bba37f5
DE
110void wxTopLevelWindowBase::GetRectForTopLevelChildren(int *x, int *y, int *w, int *h)
111{
112 GetPosition(x,y);
113 GetSize(w,h);
114}
115
34c3ffca
RL
116wxSize wxTopLevelWindowBase::GetMaxSize() const
117{
118 wxSize size( GetMaxWidth(), GetMaxHeight() );
119 int w, h;
120
121 wxClientDisplayRect( 0, 0, &w, &h );
122
cb719f2e 123 if( size.GetWidth() == wxDefaultCoord )
34c3ffca
RL
124 size.SetWidth( w );
125
cb719f2e 126 if( size.GetHeight() == wxDefaultCoord )
34c3ffca
RL
127 size.SetHeight( h );
128
129 return size;
130}
131
0c089c08
VZ
132/* static */
133wxSize wxTopLevelWindowBase::GetDefaultSize()
134{
135 wxSize size = wxGetClientDisplayRect().GetSize();
136
137 // create proportionally bigger windows on small screens
138 if ( size.x >= 1024 )
139 size.x = 400;
140 else if ( size.x >= 800 )
141 size.x = 300;
142 else if ( size.x >= 320 )
143 size.x = 240;
144
145 if ( size.y >= 768 )
146 size.y = 250;
147 else if ( size.y > 200 )
148 {
149 size.y *= 2;
150 size.y /= 3;
151 }
152
153 return size;
154}
155
1f464296
VZ
156void wxTopLevelWindowBase::DoCentre(int dir)
157{
158 wxRect rectCentre;
159 if ( !(dir & wxCENTRE_ON_SCREEN) && GetParent() )
160 {
161 // centre on parent window
162 rectCentre = GetParent()->GetRect();
163 }
164 else
165 {
166 // we were explicitely asked to centre this window on the entire screen
167 // or if we have no parent anyhow and so can't centre on it
168#if wxUSE_DISPLAY
169 const int nDisplay = wxDisplay::GetFromWindow(this);
170 if ( nDisplay != wxNOT_FOUND )
171 {
172 rectCentre = wxDisplay(nDisplay).GetGeometry();
173 }
174 else
175#endif // wxUSE_DISPLAY
176 {
177 wxDisplaySize(&rectCentre.width, &rectCentre.height);
178 }
179 }
180
181 // window may be at -1 if it's centered on a secondary display, for example
182 SetSize(GetRect().CentreIn(rectCentre, dir), wxSIZE_ALLOW_MINUS_ONE);
183}
184
7d9f12f3 185// ----------------------------------------------------------------------------
82c9f85c
VZ
186// wxTopLevelWindow size management: we exclude the areas taken by
187// menu/status/toolbars from the client area, so the client area is what's
188// really available for the frame contents
7d9f12f3
VS
189// ----------------------------------------------------------------------------
190
191void wxTopLevelWindowBase::DoScreenToClient(int *x, int *y) const
192{
193 wxWindow::DoScreenToClient(x, y);
194
82c9f85c 195 // translate the wxWindow client coords to our client coords
7d9f12f3 196 wxPoint pt(GetClientAreaOrigin());
82c9f85c
VZ
197 if ( x )
198 *x -= pt.x;
199 if ( y )
200 *y -= pt.y;
7d9f12f3
VS
201}
202
203void wxTopLevelWindowBase::DoClientToScreen(int *x, int *y) const
204{
82c9f85c
VZ
205 // our client area origin (0, 0) may be really something like (0, 30) for
206 // wxWindow if we have a toolbar, account for it before translating
207 wxPoint pt(GetClientAreaOrigin());
208 if ( x )
209 *x += pt.x;
210 if ( y )
211 *y += pt.y;
7d9f12f3
VS
212
213 wxWindow::DoClientToScreen(x, y);
214}
215
216
217// ----------------------------------------------------------------------------
218// event handlers
219// ----------------------------------------------------------------------------
220
221// default resizing behaviour - if only ONE subwindow, resize to fill the
222// whole client area
5e62d4a5 223void wxTopLevelWindowBase::DoLayout()
7d9f12f3 224{
bc55104d 225 // if we're using constraints or sizers - do use them
7d9f12f3
VS
226 if ( GetAutoLayout() )
227 {
228 Layout();
229 }
230 else
7d9f12f3
VS
231 {
232 // do we have _exactly_ one child?
233 wxWindow *child = (wxWindow *)NULL;
222ed1d6 234 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
7d9f12f3
VS
235 node;
236 node = node->GetNext() )
237 {
238 wxWindow *win = node->GetData();
239
240 // exclude top level and managed windows (status bar isn't
241 // currently in the children list except under wxMac anyhow, but
242 // it makes no harm to test for it)
243 if ( !win->IsTopLevel() && !IsOneOfBars(win) )
244 {
245 if ( child )
246 {
247 return; // it's our second subwindow - nothing to do
248 }
249
250 child = win;
251 }
252 }
253
254 // do we have any children at all?
255 if ( child )
256 {
257 // exactly one child - set it's size to fill the whole frame
258 int clientW, clientH;
259 DoGetClientSize(&clientW, &clientH);
260
261 // for whatever reasons, wxGTK wants to have a small offset - it
262 // probably looks better with it?
263#ifdef __WXGTK__
264 static const int ofs = 1;
265#else
266 static const int ofs = 0;
267#endif
268
45e0dc94 269 child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs);
7d9f12f3
VS
270 }
271 }
272}
273
274// The default implementation for the close window event.
275void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
276{
277 Destroy();
278}
279
280bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized)
281{
282 wxIconizeEvent event(GetId(), iconized);
283 event.SetEventObject(this);
284
285 return GetEventHandler()->ProcessEvent(event);
286}
34c3ffca 287
e39af974
JS
288// do the window-specific processing after processing the update event
289void wxTopLevelWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
290{
a3a4105d
VZ
291 // call inherited, but skip the wxControl's version, and call directly the
292 // wxWindow's one instead, because the only reason why we are overriding this
293 // function is that we want to use SetTitle() instead of wxControl::SetLabel()
294 wxWindowBase::DoUpdateWindowUI(event);
cb719f2e 295
a3a4105d 296 // update title
e39af974
JS
297 if ( event.GetSetText() )
298 {
299 if ( event.GetText() != GetTitle() )
300 SetTitle(event.GetText());
301 }
302}
303
447fd332 304void wxTopLevelWindowBase::RequestUserAttention(int WXUNUSED(flags))
9b59c95b
VZ
305{
306 // it's probably better than do nothing, isn't it?
307 Raise();
308}
309