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