]>
Commit | Line | Data |
---|---|---|
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$ | |
55d99c7a | 7 | // Copyright: (c) 1998 Robert Roebling and Julian Smart |
7d9f12f3 VS |
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" | |
5f1d3069 | 33 | #include "wx/app.h" |
7d9f12f3 VS |
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 | ||
ddbfcced | 49 | IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow) |
82c9f85c | 50 | |
7d9f12f3 VS |
51 | // ---------------------------------------------------------------------------- |
52 | // construction/destruction | |
53 | // ---------------------------------------------------------------------------- | |
54 | ||
55 | wxTopLevelWindowBase::wxTopLevelWindowBase() | |
56 | { | |
57 | } | |
58 | ||
799ea011 GD |
59 | wxTopLevelWindowBase::~wxTopLevelWindowBase() |
60 | { | |
1cbee0b4 VZ |
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 | } | |
799ea011 GD |
74 | } |
75 | ||
7d9f12f3 VS |
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 | return TRUE; | |
84 | } | |
85 | ||
5c363878 | 86 | bool wxTopLevelWindowBase::IsLastBeforeExit() const |
1cbee0b4 VZ |
87 | { |
88 | // we exit the application if there are no more top level windows left | |
89 | // normally but wxApp can prevent this from happening | |
5c363878 VZ |
90 | return wxTopLevelWindows.GetCount() == 1 && |
91 | wxTopLevelWindows.GetFirst()->GetData() == (wxWindow *)this && | |
1cbee0b4 VZ |
92 | wxTheApp && wxTheApp->GetExitOnFrameDelete(); |
93 | } | |
94 | ||
95 | // ---------------------------------------------------------------------------- | |
96 | // wxTopLevelWindow geometry | |
97 | // ---------------------------------------------------------------------------- | |
98 | ||
34c3ffca RL |
99 | wxSize wxTopLevelWindowBase::GetMaxSize() const |
100 | { | |
101 | wxSize size( GetMaxWidth(), GetMaxHeight() ); | |
102 | int w, h; | |
103 | ||
104 | wxClientDisplayRect( 0, 0, &w, &h ); | |
105 | ||
106 | if( size.GetWidth() == -1 ) | |
107 | size.SetWidth( w ); | |
108 | ||
109 | if( size.GetHeight() == -1 ) | |
110 | size.SetHeight( h ); | |
111 | ||
112 | return size; | |
113 | } | |
114 | ||
7d9f12f3 | 115 | // ---------------------------------------------------------------------------- |
82c9f85c VZ |
116 | // wxTopLevelWindow size management: we exclude the areas taken by |
117 | // menu/status/toolbars from the client area, so the client area is what's | |
118 | // really available for the frame contents | |
7d9f12f3 VS |
119 | // ---------------------------------------------------------------------------- |
120 | ||
121 | void wxTopLevelWindowBase::DoScreenToClient(int *x, int *y) const | |
122 | { | |
123 | wxWindow::DoScreenToClient(x, y); | |
124 | ||
82c9f85c | 125 | // translate the wxWindow client coords to our client coords |
7d9f12f3 | 126 | wxPoint pt(GetClientAreaOrigin()); |
82c9f85c VZ |
127 | if ( x ) |
128 | *x -= pt.x; | |
129 | if ( y ) | |
130 | *y -= pt.y; | |
7d9f12f3 VS |
131 | } |
132 | ||
133 | void wxTopLevelWindowBase::DoClientToScreen(int *x, int *y) const | |
134 | { | |
82c9f85c VZ |
135 | // our client area origin (0, 0) may be really something like (0, 30) for |
136 | // wxWindow if we have a toolbar, account for it before translating | |
137 | wxPoint pt(GetClientAreaOrigin()); | |
138 | if ( x ) | |
139 | *x += pt.x; | |
140 | if ( y ) | |
141 | *y += pt.y; | |
7d9f12f3 VS |
142 | |
143 | wxWindow::DoClientToScreen(x, y); | |
144 | } | |
145 | ||
146 | ||
147 | // ---------------------------------------------------------------------------- | |
148 | // event handlers | |
149 | // ---------------------------------------------------------------------------- | |
150 | ||
151 | // default resizing behaviour - if only ONE subwindow, resize to fill the | |
152 | // whole client area | |
153 | void wxTopLevelWindowBase::OnSize(wxSizeEvent& WXUNUSED(event)) | |
154 | { | |
bc55104d | 155 | // if we're using constraints or sizers - do use them |
7d9f12f3 VS |
156 | if ( GetAutoLayout() ) |
157 | { | |
158 | Layout(); | |
159 | } | |
160 | else | |
7d9f12f3 VS |
161 | { |
162 | // do we have _exactly_ one child? | |
163 | wxWindow *child = (wxWindow *)NULL; | |
222ed1d6 | 164 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
7d9f12f3 VS |
165 | node; |
166 | node = node->GetNext() ) | |
167 | { | |
168 | wxWindow *win = node->GetData(); | |
169 | ||
170 | // exclude top level and managed windows (status bar isn't | |
171 | // currently in the children list except under wxMac anyhow, but | |
172 | // it makes no harm to test for it) | |
173 | if ( !win->IsTopLevel() && !IsOneOfBars(win) ) | |
174 | { | |
175 | if ( child ) | |
176 | { | |
177 | return; // it's our second subwindow - nothing to do | |
178 | } | |
179 | ||
180 | child = win; | |
181 | } | |
182 | } | |
183 | ||
184 | // do we have any children at all? | |
185 | if ( child ) | |
186 | { | |
187 | // exactly one child - set it's size to fill the whole frame | |
188 | int clientW, clientH; | |
189 | DoGetClientSize(&clientW, &clientH); | |
190 | ||
191 | // for whatever reasons, wxGTK wants to have a small offset - it | |
192 | // probably looks better with it? | |
193 | #ifdef __WXGTK__ | |
194 | static const int ofs = 1; | |
195 | #else | |
196 | static const int ofs = 0; | |
197 | #endif | |
198 | ||
45e0dc94 | 199 | child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs); |
7d9f12f3 VS |
200 | } |
201 | } | |
202 | } | |
203 | ||
204 | // The default implementation for the close window event. | |
205 | void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) | |
206 | { | |
207 | Destroy(); | |
208 | } | |
209 | ||
210 | bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized) | |
211 | { | |
212 | wxIconizeEvent event(GetId(), iconized); | |
213 | event.SetEventObject(this); | |
214 | ||
215 | return GetEventHandler()->ProcessEvent(event); | |
216 | } | |
34c3ffca | 217 | |
e39af974 JS |
218 | // do the window-specific processing after processing the update event |
219 | void wxTopLevelWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event) | |
220 | { | |
221 | if ( event.GetSetEnabled() ) | |
222 | Enable(event.GetEnabled()); | |
223 | ||
224 | if ( event.GetSetText() ) | |
225 | { | |
226 | if ( event.GetText() != GetTitle() ) | |
227 | SetTitle(event.GetText()); | |
228 | } | |
229 | } | |
230 | ||
34c3ffca | 231 | // vi:sts=4:sw=4:et |