]> git.saurik.com Git - wxWidgets.git/blame - src/common/toplvcmn.cpp
really show the window after creation (calling Show(TRUE) doesn't do it any more)
[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{
c7e61a5e
DE
57 // Unlike windows, top level windows are created hidden by default.
58 m_isShown = false;
7d9f12f3
VS
59}
60
799ea011
GD
61wxTopLevelWindowBase::~wxTopLevelWindowBase()
62{
1cbee0b4
VZ
63 // don't let wxTheApp keep any stale pointers to us
64 if ( wxTheApp && wxTheApp->GetTopWindow() == this )
65 wxTheApp->SetTopWindow(NULL);
66
67 bool shouldExit = IsLastBeforeExit();
68
69 wxTopLevelWindows.DeleteObject(this);
b3bd912d 70
1cbee0b4
VZ
71 if ( shouldExit )
72 {
73 // then do it
74 wxTheApp->ExitMainLoop();
75 }
799ea011
GD
76}
77
7d9f12f3
VS
78bool wxTopLevelWindowBase::Destroy()
79{
80 // delayed destruction: the frame will be deleted during the next idle
81 // loop iteration
82 if ( !wxPendingDelete.Member(this) )
83 wxPendingDelete.Append(this);
84
b3bd912d
RR
85 if (wxTopLevelWindows.GetCount() > 1)
86 {
87 // Hide it immediately. This should
88 // not be done if this TLW is the
89 // only one left since we then would
90 // risk not to get any idle events
91 // at all anymore during which we
92 // could delete any pending events.
93 Hide();
94 }
cafcf62a 95
7d9f12f3
VS
96 return TRUE;
97}
98
5c363878 99bool wxTopLevelWindowBase::IsLastBeforeExit() const
1cbee0b4
VZ
100{
101 // we exit the application if there are no more top level windows left
102 // normally but wxApp can prevent this from happening
5c363878
VZ
103 return wxTopLevelWindows.GetCount() == 1 &&
104 wxTopLevelWindows.GetFirst()->GetData() == (wxWindow *)this &&
1cbee0b4
VZ
105 wxTheApp && wxTheApp->GetExitOnFrameDelete();
106}
107
108// ----------------------------------------------------------------------------
109// wxTopLevelWindow geometry
110// ----------------------------------------------------------------------------
111
34c3ffca
RL
112wxSize wxTopLevelWindowBase::GetMaxSize() const
113{
114 wxSize size( GetMaxWidth(), GetMaxHeight() );
115 int w, h;
116
117 wxClientDisplayRect( 0, 0, &w, &h );
118
119 if( size.GetWidth() == -1 )
120 size.SetWidth( w );
121
122 if( size.GetHeight() == -1 )
123 size.SetHeight( h );
124
125 return size;
126}
127
7d9f12f3 128// ----------------------------------------------------------------------------
82c9f85c
VZ
129// wxTopLevelWindow size management: we exclude the areas taken by
130// menu/status/toolbars from the client area, so the client area is what's
131// really available for the frame contents
7d9f12f3
VS
132// ----------------------------------------------------------------------------
133
134void wxTopLevelWindowBase::DoScreenToClient(int *x, int *y) const
135{
136 wxWindow::DoScreenToClient(x, y);
137
82c9f85c 138 // translate the wxWindow client coords to our client coords
7d9f12f3 139 wxPoint pt(GetClientAreaOrigin());
82c9f85c
VZ
140 if ( x )
141 *x -= pt.x;
142 if ( y )
143 *y -= pt.y;
7d9f12f3
VS
144}
145
146void wxTopLevelWindowBase::DoClientToScreen(int *x, int *y) const
147{
82c9f85c
VZ
148 // our client area origin (0, 0) may be really something like (0, 30) for
149 // wxWindow if we have a toolbar, account for it before translating
150 wxPoint pt(GetClientAreaOrigin());
151 if ( x )
152 *x += pt.x;
153 if ( y )
154 *y += pt.y;
7d9f12f3
VS
155
156 wxWindow::DoClientToScreen(x, y);
157}
158
159
160// ----------------------------------------------------------------------------
161// event handlers
162// ----------------------------------------------------------------------------
163
164// default resizing behaviour - if only ONE subwindow, resize to fill the
165// whole client area
166void wxTopLevelWindowBase::OnSize(wxSizeEvent& WXUNUSED(event))
167{
bc55104d 168 // if we're using constraints or sizers - do use them
7d9f12f3
VS
169 if ( GetAutoLayout() )
170 {
171 Layout();
172 }
173 else
7d9f12f3
VS
174 {
175 // do we have _exactly_ one child?
176 wxWindow *child = (wxWindow *)NULL;
222ed1d6 177 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
7d9f12f3
VS
178 node;
179 node = node->GetNext() )
180 {
181 wxWindow *win = node->GetData();
182
183 // exclude top level and managed windows (status bar isn't
184 // currently in the children list except under wxMac anyhow, but
185 // it makes no harm to test for it)
186 if ( !win->IsTopLevel() && !IsOneOfBars(win) )
187 {
188 if ( child )
189 {
190 return; // it's our second subwindow - nothing to do
191 }
192
193 child = win;
194 }
195 }
196
197 // do we have any children at all?
198 if ( child )
199 {
200 // exactly one child - set it's size to fill the whole frame
201 int clientW, clientH;
202 DoGetClientSize(&clientW, &clientH);
203
204 // for whatever reasons, wxGTK wants to have a small offset - it
205 // probably looks better with it?
206#ifdef __WXGTK__
207 static const int ofs = 1;
208#else
209 static const int ofs = 0;
210#endif
211
45e0dc94 212 child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs);
7d9f12f3
VS
213 }
214 }
215}
216
217// The default implementation for the close window event.
218void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
219{
220 Destroy();
221}
222
223bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized)
224{
225 wxIconizeEvent event(GetId(), iconized);
226 event.SetEventObject(this);
227
228 return GetEventHandler()->ProcessEvent(event);
229}
34c3ffca 230
e39af974
JS
231// do the window-specific processing after processing the update event
232void wxTopLevelWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
233{
234 if ( event.GetSetEnabled() )
235 Enable(event.GetEnabled());
236
237 if ( event.GetSetText() )
238 {
239 if ( event.GetText() != GetTitle() )
240 SetTitle(event.GetText());
241 }
242}
243
34c3ffca 244// vi:sts=4:sw=4:et