]> git.saurik.com Git - wxWidgets.git/blame - src/common/toplvcmn.cpp
What did I change here?
[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$
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19#ifdef __GNUG__
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"
33#endif // WX_PRECOMP
34
35// ----------------------------------------------------------------------------
36// event table
37// ----------------------------------------------------------------------------
38
39BEGIN_EVENT_TABLE(wxTopLevelWindowBase, wxWindow)
40 EVT_CLOSE(wxTopLevelWindowBase::OnCloseWindow)
41 EVT_SIZE(wxTopLevelWindowBase::OnSize)
42END_EVENT_TABLE()
43
44// ============================================================================
45// implementation
46// ============================================================================
47
f427e0d6
VZ
48// FIXME: some platforms don't have wxTopLevelWindow yet
49#ifdef wxTopLevelWindowNative
50 IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow)
51#endif
82c9f85c 52
7d9f12f3
VS
53// ----------------------------------------------------------------------------
54// construction/destruction
55// ----------------------------------------------------------------------------
56
57wxTopLevelWindowBase::wxTopLevelWindowBase()
58{
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);
70
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
85 return TRUE;
86}
87
1cbee0b4
VZ
88/* static */
89bool wxTopLevelWindowBase::IsLastBeforeExit()
90{
91 // we exit the application if there are no more top level windows left
92 // normally but wxApp can prevent this from happening
93 return (wxTopLevelWindows.GetCount() == 1) &&
94 wxTheApp && wxTheApp->GetExitOnFrameDelete();
95}
96
97// ----------------------------------------------------------------------------
98// wxTopLevelWindow geometry
99// ----------------------------------------------------------------------------
100
34c3ffca
RL
101wxSize wxTopLevelWindowBase::GetMaxSize() const
102{
103 wxSize size( GetMaxWidth(), GetMaxHeight() );
104 int w, h;
105
106 wxClientDisplayRect( 0, 0, &w, &h );
107
108 if( size.GetWidth() == -1 )
109 size.SetWidth( w );
110
111 if( size.GetHeight() == -1 )
112 size.SetHeight( h );
113
114 return size;
115}
116
7d9f12f3 117// ----------------------------------------------------------------------------
82c9f85c
VZ
118// wxTopLevelWindow size management: we exclude the areas taken by
119// menu/status/toolbars from the client area, so the client area is what's
120// really available for the frame contents
7d9f12f3
VS
121// ----------------------------------------------------------------------------
122
123void wxTopLevelWindowBase::DoScreenToClient(int *x, int *y) const
124{
125 wxWindow::DoScreenToClient(x, y);
126
82c9f85c 127 // translate the wxWindow client coords to our client coords
7d9f12f3 128 wxPoint pt(GetClientAreaOrigin());
82c9f85c
VZ
129 if ( x )
130 *x -= pt.x;
131 if ( y )
132 *y -= pt.y;
7d9f12f3
VS
133}
134
135void wxTopLevelWindowBase::DoClientToScreen(int *x, int *y) const
136{
82c9f85c
VZ
137 // our client area origin (0, 0) may be really something like (0, 30) for
138 // wxWindow if we have a toolbar, account for it before translating
139 wxPoint pt(GetClientAreaOrigin());
140 if ( x )
141 *x += pt.x;
142 if ( y )
143 *y += pt.y;
7d9f12f3
VS
144
145 wxWindow::DoClientToScreen(x, y);
146}
147
148
149// ----------------------------------------------------------------------------
150// event handlers
151// ----------------------------------------------------------------------------
152
153// default resizing behaviour - if only ONE subwindow, resize to fill the
154// whole client area
155void wxTopLevelWindowBase::OnSize(wxSizeEvent& WXUNUSED(event))
156{
bc55104d 157 // if we're using constraints or sizers - do use them
7d9f12f3
VS
158 if ( GetAutoLayout() )
159 {
160 Layout();
161 }
162 else
7d9f12f3
VS
163 {
164 // do we have _exactly_ one child?
165 wxWindow *child = (wxWindow *)NULL;
166 for ( wxWindowList::Node *node = GetChildren().GetFirst();
167 node;
168 node = node->GetNext() )
169 {
170 wxWindow *win = node->GetData();
171
172 // exclude top level and managed windows (status bar isn't
173 // currently in the children list except under wxMac anyhow, but
174 // it makes no harm to test for it)
175 if ( !win->IsTopLevel() && !IsOneOfBars(win) )
176 {
177 if ( child )
178 {
179 return; // it's our second subwindow - nothing to do
180 }
181
182 child = win;
183 }
184 }
185
186 // do we have any children at all?
187 if ( child )
188 {
189 // exactly one child - set it's size to fill the whole frame
190 int clientW, clientH;
191 DoGetClientSize(&clientW, &clientH);
192
193 // for whatever reasons, wxGTK wants to have a small offset - it
194 // probably looks better with it?
195#ifdef __WXGTK__
196 static const int ofs = 1;
197#else
198 static const int ofs = 0;
199#endif
200
45e0dc94 201 child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs);
7d9f12f3
VS
202 }
203 }
204}
205
206// The default implementation for the close window event.
207void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
208{
209 Destroy();
210}
211
212bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized)
213{
214 wxIconizeEvent event(GetId(), iconized);
215 event.SetEventObject(this);
216
217 return GetEventHandler()->ProcessEvent(event);
218}
34c3ffca
RL
219
220// vi:sts=4:sw=4:et