1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/toplvcmn.cpp
3 // Purpose: common (for all platforms) wxTopLevelWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
7 // Copyright: (c) 1998 Robert Roebling and Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
27 #include "wx/toplevel.h"
28 #include "wx/dcclient.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 BEGIN_EVENT_TABLE(wxTopLevelWindowBase
, wxWindow
)
37 EVT_CLOSE(wxTopLevelWindowBase::OnCloseWindow
)
38 EVT_SIZE(wxTopLevelWindowBase::OnSize
)
41 // ============================================================================
43 // ============================================================================
45 IMPLEMENT_ABSTRACT_CLASS(wxTopLevelWindow
, wxWindow
)
47 // ----------------------------------------------------------------------------
48 // construction/destruction
49 // ----------------------------------------------------------------------------
51 wxTopLevelWindowBase::wxTopLevelWindowBase()
53 // Unlike windows, top level windows are created hidden by default.
57 wxTopLevelWindowBase::~wxTopLevelWindowBase()
59 // don't let wxTheApp keep any stale pointers to us
60 if ( wxTheApp
&& wxTheApp
->GetTopWindow() == this )
61 wxTheApp
->SetTopWindow(NULL
);
63 bool shouldExit
= IsLastBeforeExit();
65 wxTopLevelWindows
.DeleteObject(this);
70 wxTheApp
->ExitMainLoop();
74 bool wxTopLevelWindowBase::Destroy()
76 // delayed destruction: the frame will be deleted during the next idle
78 if ( !wxPendingDelete
.Member(this) )
79 wxPendingDelete
.Append(this);
81 if (wxTopLevelWindows
.GetCount() > 1)
83 // Hide it immediately. This should
84 // not be done if this TLW is the
85 // only one left since we then would
86 // risk not to get any idle events
87 // at all anymore during which we
88 // could delete any pending events.
95 bool wxTopLevelWindowBase::IsLastBeforeExit() const
97 // we exit the application if there are no more top level windows left
98 // normally but wxApp can prevent this from happening
99 return wxTopLevelWindows
.GetCount() == 1 &&
100 wxTopLevelWindows
.GetFirst()->GetData() == (wxWindow
*)this &&
101 wxTheApp
&& wxTheApp
->GetExitOnFrameDelete();
104 // ----------------------------------------------------------------------------
105 // wxTopLevelWindow geometry
106 // ----------------------------------------------------------------------------
108 void wxTopLevelWindowBase::GetRectForTopLevelChildren(int *x
, int *y
, int *w
, int *h
)
114 wxSize
wxTopLevelWindowBase::GetMaxSize() const
116 wxSize
size( GetMaxWidth(), GetMaxHeight() );
119 wxClientDisplayRect( 0, 0, &w
, &h
);
121 if( size
.GetWidth() == wxDefaultCoord
)
124 if( size
.GetHeight() == wxDefaultCoord
)
131 wxSize
wxTopLevelWindowBase::GetDefaultSize()
133 wxSize size
= wxGetClientDisplayRect().GetSize();
135 // create proportionally bigger windows on small screens
136 if ( size
.x
>= 1024 )
138 else if ( size
.x
>= 800 )
140 else if ( size
.x
>= 320 )
145 else if ( size
.y
> 200 )
154 // ----------------------------------------------------------------------------
155 // wxTopLevelWindow size management: we exclude the areas taken by
156 // menu/status/toolbars from the client area, so the client area is what's
157 // really available for the frame contents
158 // ----------------------------------------------------------------------------
160 void wxTopLevelWindowBase::DoScreenToClient(int *x
, int *y
) const
162 wxWindow::DoScreenToClient(x
, y
);
164 // translate the wxWindow client coords to our client coords
165 wxPoint
pt(GetClientAreaOrigin());
172 void wxTopLevelWindowBase::DoClientToScreen(int *x
, int *y
) const
174 // our client area origin (0, 0) may be really something like (0, 30) for
175 // wxWindow if we have a toolbar, account for it before translating
176 wxPoint
pt(GetClientAreaOrigin());
182 wxWindow::DoClientToScreen(x
, y
);
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
190 // default resizing behaviour - if only ONE subwindow, resize to fill the
192 void wxTopLevelWindowBase::DoLayout()
194 // if we're using constraints or sizers - do use them
195 if ( GetAutoLayout() )
201 // do we have _exactly_ one child?
202 wxWindow
*child
= (wxWindow
*)NULL
;
203 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
205 node
= node
->GetNext() )
207 wxWindow
*win
= node
->GetData();
209 // exclude top level and managed windows (status bar isn't
210 // currently in the children list except under wxMac anyhow, but
211 // it makes no harm to test for it)
212 if ( !win
->IsTopLevel() && !IsOneOfBars(win
) )
216 return; // it's our second subwindow - nothing to do
223 // do we have any children at all?
226 // exactly one child - set it's size to fill the whole frame
227 int clientW
, clientH
;
228 DoGetClientSize(&clientW
, &clientH
);
230 // for whatever reasons, wxGTK wants to have a small offset - it
231 // probably looks better with it?
233 static const int ofs
= 1;
235 static const int ofs
= 0;
238 child
->SetSize(ofs
, ofs
, clientW
- 2*ofs
, clientH
- 2*ofs
);
243 // The default implementation for the close window event.
244 void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
249 bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized
)
251 wxIconizeEvent
event(GetId(), iconized
);
252 event
.SetEventObject(this);
254 return GetEventHandler()->ProcessEvent(event
);
257 // do the window-specific processing after processing the update event
258 void wxTopLevelWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
260 if ( event
.GetSetEnabled() )
261 Enable(event
.GetEnabled());
263 if ( event
.GetSetText() )
265 if ( event
.GetText() != GetTitle() )
266 SetTitle(event
.GetText());
270 void wxTopLevelWindowBase::RequestUserAttention(int WXUNUSED(flags
))
272 // it's probably better than do nothing, isn't it?