]> git.saurik.com Git - wxWidgets.git/blame - src/common/toplvcmn.cpp
Corrected size of staticbox borders when running OS X Panther or higher.
[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
7d9f12f3
VS
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
14f355c2 19#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
7d9f12f3
VS
20 #pragma implementation "toplevelbase.h"
21#endif
22
23// For compilers that support precompilation, includes "wx.h".
24#include "wx/wxprec.h"
25
26#ifdef __BORLANDC__
27 #pragma hdrstop
28#endif
29
30#ifndef WX_PRECOMP
31 #include "wx/toplevel.h"
32 #include "wx/dcclient.h"
5f1d3069 33 #include "wx/app.h"
7d9f12f3
VS
34#endif // WX_PRECOMP
35
36// ----------------------------------------------------------------------------
37// event table
38// ----------------------------------------------------------------------------
39
40BEGIN_EVENT_TABLE(wxTopLevelWindowBase, wxWindow)
41 EVT_CLOSE(wxTopLevelWindowBase::OnCloseWindow)
42 EVT_SIZE(wxTopLevelWindowBase::OnSize)
43END_EVENT_TABLE()
44
45// ============================================================================
46// implementation
47// ============================================================================
48
ddbfcced 49IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow)
82c9f85c 50
7d9f12f3
VS
51// ----------------------------------------------------------------------------
52// construction/destruction
53// ----------------------------------------------------------------------------
54
55wxTopLevelWindowBase::wxTopLevelWindowBase()
56{
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);
68
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
cafcf62a
VZ
83 // but hide it immediately
84 Hide();
85
7d9f12f3
VS
86 return TRUE;
87}
88
5c363878 89bool wxTopLevelWindowBase::IsLastBeforeExit() const
1cbee0b4
VZ
90{
91 // we exit the application if there are no more top level windows left
92 // normally but wxApp can prevent this from happening
5c363878
VZ
93 return wxTopLevelWindows.GetCount() == 1 &&
94 wxTopLevelWindows.GetFirst()->GetData() == (wxWindow *)this &&
1cbee0b4
VZ
95 wxTheApp && wxTheApp->GetExitOnFrameDelete();
96}
97
98// ----------------------------------------------------------------------------
99// wxTopLevelWindow geometry
100// ----------------------------------------------------------------------------
101
34c3ffca
RL
102wxSize wxTopLevelWindowBase::GetMaxSize() const
103{
104 wxSize size( GetMaxWidth(), GetMaxHeight() );
105 int w, h;
106
107 wxClientDisplayRect( 0, 0, &w, &h );
108
109 if( size.GetWidth() == -1 )
110 size.SetWidth( w );
111
112 if( size.GetHeight() == -1 )
113 size.SetHeight( h );
114
115 return size;
116}
117
7d9f12f3 118// ----------------------------------------------------------------------------
82c9f85c
VZ
119// wxTopLevelWindow size management: we exclude the areas taken by
120// menu/status/toolbars from the client area, so the client area is what's
121// really available for the frame contents
7d9f12f3
VS
122// ----------------------------------------------------------------------------
123
124void wxTopLevelWindowBase::DoScreenToClient(int *x, int *y) const
125{
126 wxWindow::DoScreenToClient(x, y);
127
82c9f85c 128 // translate the wxWindow client coords to our client coords
7d9f12f3 129 wxPoint pt(GetClientAreaOrigin());
82c9f85c
VZ
130 if ( x )
131 *x -= pt.x;
132 if ( y )
133 *y -= pt.y;
7d9f12f3
VS
134}
135
136void wxTopLevelWindowBase::DoClientToScreen(int *x, int *y) const
137{
82c9f85c
VZ
138 // our client area origin (0, 0) may be really something like (0, 30) for
139 // wxWindow if we have a toolbar, account for it before translating
140 wxPoint pt(GetClientAreaOrigin());
141 if ( x )
142 *x += pt.x;
143 if ( y )
144 *y += pt.y;
7d9f12f3
VS
145
146 wxWindow::DoClientToScreen(x, y);
147}
148
149
150// ----------------------------------------------------------------------------
151// event handlers
152// ----------------------------------------------------------------------------
153
154// default resizing behaviour - if only ONE subwindow, resize to fill the
155// whole client area
156void wxTopLevelWindowBase::OnSize(wxSizeEvent& WXUNUSED(event))
157{
bc55104d 158 // if we're using constraints or sizers - do use them
7d9f12f3
VS
159 if ( GetAutoLayout() )
160 {
161 Layout();
162 }
163 else
7d9f12f3
VS
164 {
165 // do we have _exactly_ one child?
166 wxWindow *child = (wxWindow *)NULL;
222ed1d6 167 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
7d9f12f3
VS
168 node;
169 node = node->GetNext() )
170 {
171 wxWindow *win = node->GetData();
172
173 // exclude top level and managed windows (status bar isn't
174 // currently in the children list except under wxMac anyhow, but
175 // it makes no harm to test for it)
176 if ( !win->IsTopLevel() && !IsOneOfBars(win) )
177 {
178 if ( child )
179 {
180 return; // it's our second subwindow - nothing to do
181 }
182
183 child = win;
184 }
185 }
186
187 // do we have any children at all?
188 if ( child )
189 {
190 // exactly one child - set it's size to fill the whole frame
191 int clientW, clientH;
192 DoGetClientSize(&clientW, &clientH);
193
194 // for whatever reasons, wxGTK wants to have a small offset - it
195 // probably looks better with it?
196#ifdef __WXGTK__
197 static const int ofs = 1;
198#else
199 static const int ofs = 0;
200#endif
201
45e0dc94 202 child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs);
7d9f12f3
VS
203 }
204 }
205}
206
207// The default implementation for the close window event.
208void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
209{
210 Destroy();
211}
212
213bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized)
214{
215 wxIconizeEvent event(GetId(), iconized);
216 event.SetEventObject(this);
217
218 return GetEventHandler()->ProcessEvent(event);
219}
34c3ffca 220
e39af974
JS
221// do the window-specific processing after processing the update event
222void wxTopLevelWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
223{
224 if ( event.GetSetEnabled() )
225 Enable(event.GetEnabled());
226
227 if ( event.GetSetText() )
228 {
229 if ( event.GetText() != GetTitle() )
230 SetTitle(event.GetText());
231 }
232}
233
34c3ffca 234// vi:sts=4:sw=4:et