]> git.saurik.com Git - wxWidgets.git/blob - src/common/toplvcmn.cpp
Compile fix for sound without threads. Not sure
[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 and Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 #include "wx/app.h"
34 #endif // WX_PRECOMP
35
36 // ----------------------------------------------------------------------------
37 // event table
38 // ----------------------------------------------------------------------------
39
40 BEGIN_EVENT_TABLE(wxTopLevelWindowBase, wxWindow)
41 EVT_CLOSE(wxTopLevelWindowBase::OnCloseWindow)
42 EVT_SIZE(wxTopLevelWindowBase::OnSize)
43 END_EVENT_TABLE()
44
45 // ============================================================================
46 // implementation
47 // ============================================================================
48
49 IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow)
50
51 // ----------------------------------------------------------------------------
52 // construction/destruction
53 // ----------------------------------------------------------------------------
54
55 wxTopLevelWindowBase::wxTopLevelWindowBase()
56 {
57 }
58
59 wxTopLevelWindowBase::~wxTopLevelWindowBase()
60 {
61 // don't let wxTheApp keep any stale pointers to us
62 if ( wxTheApp && wxTheApp->GetTopWindow() == this )
63 wxTheApp->SetTopWindow(NULL);
64
65 bool shouldExit = IsLastBeforeExit();
66
67 wxTopLevelWindows.DeleteObject(this);
68
69 if ( shouldExit )
70 {
71 // then do it
72 wxTheApp->ExitMainLoop();
73 }
74 }
75
76 bool wxTopLevelWindowBase::Destroy()
77 {
78 // delayed destruction: the frame will be deleted during the next idle
79 // loop iteration
80 if ( !wxPendingDelete.Member(this) )
81 wxPendingDelete.Append(this);
82
83 // but hide it immediately
84 Hide();
85
86 return TRUE;
87 }
88
89 bool wxTopLevelWindowBase::IsLastBeforeExit() const
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 wxTopLevelWindows.GetFirst()->GetData() == (wxWindow *)this &&
95 wxTheApp && wxTheApp->GetExitOnFrameDelete();
96 }
97
98 // ----------------------------------------------------------------------------
99 // wxTopLevelWindow geometry
100 // ----------------------------------------------------------------------------
101
102 wxSize wxTopLevelWindowBase::GetMaxSize() const
103 {
104 wxSize size( GetMaxWidth(), GetMaxHeight() );
105 int w, h;
106
107 wxClientDisplayRect( 0, 0, &w, &h );
108
109 if( size.GetWidth() == -1 )
110 size.SetWidth( w );
111
112 if( size.GetHeight() == -1 )
113 size.SetHeight( h );
114
115 return size;
116 }
117
118 // ----------------------------------------------------------------------------
119 // wxTopLevelWindow size management: we exclude the areas taken by
120 // menu/status/toolbars from the client area, so the client area is what's
121 // really available for the frame contents
122 // ----------------------------------------------------------------------------
123
124 void wxTopLevelWindowBase::DoScreenToClient(int *x, int *y) const
125 {
126 wxWindow::DoScreenToClient(x, y);
127
128 // translate the wxWindow client coords to our client coords
129 wxPoint pt(GetClientAreaOrigin());
130 if ( x )
131 *x -= pt.x;
132 if ( y )
133 *y -= pt.y;
134 }
135
136 void wxTopLevelWindowBase::DoClientToScreen(int *x, int *y) const
137 {
138 // our client area origin (0, 0) may be really something like (0, 30) for
139 // wxWindow if we have a toolbar, account for it before translating
140 wxPoint pt(GetClientAreaOrigin());
141 if ( x )
142 *x += pt.x;
143 if ( y )
144 *y += pt.y;
145
146 wxWindow::DoClientToScreen(x, y);
147 }
148
149
150 // ----------------------------------------------------------------------------
151 // event handlers
152 // ----------------------------------------------------------------------------
153
154 // default resizing behaviour - if only ONE subwindow, resize to fill the
155 // whole client area
156 void wxTopLevelWindowBase::OnSize(wxSizeEvent& WXUNUSED(event))
157 {
158 // if we're using constraints or sizers - do use them
159 if ( GetAutoLayout() )
160 {
161 Layout();
162 }
163 else
164 {
165 // do we have _exactly_ one child?
166 wxWindow *child = (wxWindow *)NULL;
167 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
168 node;
169 node = node->GetNext() )
170 {
171 wxWindow *win = node->GetData();
172
173 // exclude top level and managed windows (status bar isn't
174 // currently in the children list except under wxMac anyhow, but
175 // it makes no harm to test for it)
176 if ( !win->IsTopLevel() && !IsOneOfBars(win) )
177 {
178 if ( child )
179 {
180 return; // it's our second subwindow - nothing to do
181 }
182
183 child = win;
184 }
185 }
186
187 // do we have any children at all?
188 if ( child )
189 {
190 // exactly one child - set it's size to fill the whole frame
191 int clientW, clientH;
192 DoGetClientSize(&clientW, &clientH);
193
194 // for whatever reasons, wxGTK wants to have a small offset - it
195 // probably looks better with it?
196 #ifdef __WXGTK__
197 static const int ofs = 1;
198 #else
199 static const int ofs = 0;
200 #endif
201
202 child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs);
203 }
204 }
205 }
206
207 // The default implementation for the close window event.
208 void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
209 {
210 Destroy();
211 }
212
213 bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized)
214 {
215 wxIconizeEvent event(GetId(), iconized);
216 event.SetEventObject(this);
217
218 return GetEventHandler()->ProcessEvent(event);
219 }
220
221 // do the window-specific processing after processing the update event
222 void wxTopLevelWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
223 {
224 if ( event.GetSetEnabled() )
225 Enable(event.GetEnabled());
226
227 if ( event.GetSetText() )
228 {
229 if ( event.GetText() != GetTitle() )
230 SetTitle(event.GetText());
231 }
232 }
233
234 // vi:sts=4:sw=4:et