]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/toplvcmn.cpp
Compile corrections
[wxWidgets.git] / src / common / toplvcmn.cpp
... / ...
CommitLineData
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
48// FIXME: some platforms don't have wxTopLevelWindow yet
49#ifdef wxTopLevelWindowNative
50 IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow)
51#endif
52
53// ----------------------------------------------------------------------------
54// construction/destruction
55// ----------------------------------------------------------------------------
56
57wxTopLevelWindowBase::wxTopLevelWindowBase()
58{
59}
60
61wxTopLevelWindowBase::~wxTopLevelWindowBase()
62{
63 // this destructor is required for Darwin
64}
65
66bool wxTopLevelWindowBase::Destroy()
67{
68 // delayed destruction: the frame will be deleted during the next idle
69 // loop iteration
70 if ( !wxPendingDelete.Member(this) )
71 wxPendingDelete.Append(this);
72
73 return TRUE;
74}
75
76wxSize wxTopLevelWindowBase::GetMaxSize() const
77{
78 wxSize size( GetMaxWidth(), GetMaxHeight() );
79 int w, h;
80
81 wxClientDisplayRect( 0, 0, &w, &h );
82
83 if( size.GetWidth() == -1 )
84 size.SetWidth( w );
85
86 if( size.GetHeight() == -1 )
87 size.SetHeight( h );
88
89 return size;
90}
91
92// ----------------------------------------------------------------------------
93// wxTopLevelWindow size management: we exclude the areas taken by
94// menu/status/toolbars from the client area, so the client area is what's
95// really available for the frame contents
96// ----------------------------------------------------------------------------
97
98void wxTopLevelWindowBase::DoScreenToClient(int *x, int *y) const
99{
100 wxWindow::DoScreenToClient(x, y);
101
102 // translate the wxWindow client coords to our client coords
103 wxPoint pt(GetClientAreaOrigin());
104 if ( x )
105 *x -= pt.x;
106 if ( y )
107 *y -= pt.y;
108}
109
110void wxTopLevelWindowBase::DoClientToScreen(int *x, int *y) const
111{
112 // our client area origin (0, 0) may be really something like (0, 30) for
113 // wxWindow if we have a toolbar, account for it before translating
114 wxPoint pt(GetClientAreaOrigin());
115 if ( x )
116 *x += pt.x;
117 if ( y )
118 *y += pt.y;
119
120 wxWindow::DoClientToScreen(x, y);
121}
122
123
124// ----------------------------------------------------------------------------
125// event handlers
126// ----------------------------------------------------------------------------
127
128// default resizing behaviour - if only ONE subwindow, resize to fill the
129// whole client area
130void wxTopLevelWindowBase::OnSize(wxSizeEvent& WXUNUSED(event))
131{
132 // if we're using constraints or sizers - do use them
133 if ( GetAutoLayout() )
134 {
135 Layout();
136 }
137 else
138 {
139 // do we have _exactly_ one child?
140 wxWindow *child = (wxWindow *)NULL;
141 for ( wxWindowList::Node *node = GetChildren().GetFirst();
142 node;
143 node = node->GetNext() )
144 {
145 wxWindow *win = node->GetData();
146
147 // exclude top level and managed windows (status bar isn't
148 // currently in the children list except under wxMac anyhow, but
149 // it makes no harm to test for it)
150 if ( !win->IsTopLevel() && !IsOneOfBars(win) )
151 {
152 if ( child )
153 {
154 return; // it's our second subwindow - nothing to do
155 }
156
157 child = win;
158 }
159 }
160
161 // do we have any children at all?
162 if ( child )
163 {
164 // exactly one child - set it's size to fill the whole frame
165 int clientW, clientH;
166 DoGetClientSize(&clientW, &clientH);
167
168 // for whatever reasons, wxGTK wants to have a small offset - it
169 // probably looks better with it?
170#ifdef __WXGTK__
171 static const int ofs = 1;
172#else
173 static const int ofs = 0;
174#endif
175
176 child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs);
177 }
178 }
179}
180
181// The default implementation for the close window event.
182void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
183{
184 Destroy();
185}
186
187bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized)
188{
189 wxIconizeEvent event(GetId(), iconized);
190 event.SetEventObject(this);
191
192 return GetEventHandler()->ProcessEvent(event);
193}
194
195// vi:sts=4:sw=4:et