]> git.saurik.com Git - wxWidgets.git/blame - src/common/toplvcmn.cpp
implemented Alex's <object_ref> symlinks in XRC
[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{
63 // this destructor is required for Darwin
64}
65
7d9f12f3
VS
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
76// ----------------------------------------------------------------------------
82c9f85c
VZ
77// wxTopLevelWindow size management: we exclude the areas taken by
78// menu/status/toolbars from the client area, so the client area is what's
79// really available for the frame contents
7d9f12f3
VS
80// ----------------------------------------------------------------------------
81
82void wxTopLevelWindowBase::DoScreenToClient(int *x, int *y) const
83{
84 wxWindow::DoScreenToClient(x, y);
85
82c9f85c 86 // translate the wxWindow client coords to our client coords
7d9f12f3 87 wxPoint pt(GetClientAreaOrigin());
82c9f85c
VZ
88 if ( x )
89 *x -= pt.x;
90 if ( y )
91 *y -= pt.y;
7d9f12f3
VS
92}
93
94void wxTopLevelWindowBase::DoClientToScreen(int *x, int *y) const
95{
82c9f85c
VZ
96 // our client area origin (0, 0) may be really something like (0, 30) for
97 // wxWindow if we have a toolbar, account for it before translating
98 wxPoint pt(GetClientAreaOrigin());
99 if ( x )
100 *x += pt.x;
101 if ( y )
102 *y += pt.y;
7d9f12f3
VS
103
104 wxWindow::DoClientToScreen(x, y);
105}
106
107
108// ----------------------------------------------------------------------------
109// event handlers
110// ----------------------------------------------------------------------------
111
112// default resizing behaviour - if only ONE subwindow, resize to fill the
113// whole client area
114void wxTopLevelWindowBase::OnSize(wxSizeEvent& WXUNUSED(event))
115{
116 // if we're using constraints - do use them
117#if wxUSE_CONSTRAINTS
118 if ( GetAutoLayout() )
119 {
120 Layout();
121 }
122 else
123#endif // wxUSE_CONSTRAINTS
124 {
125 // do we have _exactly_ one child?
126 wxWindow *child = (wxWindow *)NULL;
127 for ( wxWindowList::Node *node = GetChildren().GetFirst();
128 node;
129 node = node->GetNext() )
130 {
131 wxWindow *win = node->GetData();
132
133 // exclude top level and managed windows (status bar isn't
134 // currently in the children list except under wxMac anyhow, but
135 // it makes no harm to test for it)
136 if ( !win->IsTopLevel() && !IsOneOfBars(win) )
137 {
138 if ( child )
139 {
bdb2ce96
DW
140#ifdef __WXPM__
141 AlterChildPos();
142#endif
7d9f12f3
VS
143 return; // it's our second subwindow - nothing to do
144 }
145
146 child = win;
147 }
148 }
149
150 // do we have any children at all?
151 if ( child )
152 {
153 // exactly one child - set it's size to fill the whole frame
154 int clientW, clientH;
155 DoGetClientSize(&clientW, &clientH);
156
157 // for whatever reasons, wxGTK wants to have a small offset - it
158 // probably looks better with it?
159#ifdef __WXGTK__
160 static const int ofs = 1;
161#else
162 static const int ofs = 0;
163#endif
164
165 child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs);
bdb2ce96 166#ifdef __WXPM__
5150c016 167 UpdateInternalSize(child, clientH);
bdb2ce96 168#endif
7d9f12f3
VS
169 }
170 }
171}
172
173// The default implementation for the close window event.
174void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
175{
176 Destroy();
177}
178
179bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized)
180{
181 wxIconizeEvent event(GetId(), iconized);
182 event.SetEventObject(this);
183
184 return GetEventHandler()->ProcessEvent(event);
185}