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