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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
20 #pragma implementation "toplevelbase.h"
23 // For compilers that support precompilation, includes "wx.h".
24 #include "wx/wxprec.h"
31 #include "wx/toplevel.h"
32 #include "wx/dcclient.h"
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
40 BEGIN_EVENT_TABLE(wxTopLevelWindowBase
, wxWindow
)
41 EVT_CLOSE(wxTopLevelWindowBase::OnCloseWindow
)
42 EVT_SIZE(wxTopLevelWindowBase::OnSize
)
45 // ============================================================================
47 // ============================================================================
49 IMPLEMENT_ABSTRACT_CLASS(wxTopLevelWindow
, wxWindow
)
51 // ----------------------------------------------------------------------------
52 // construction/destruction
53 // ----------------------------------------------------------------------------
55 wxTopLevelWindowBase::wxTopLevelWindowBase()
57 // Unlike windows, top level windows are created hidden by default.
61 wxTopLevelWindowBase::~wxTopLevelWindowBase()
63 // don't let wxTheApp keep any stale pointers to us
64 if ( wxTheApp
&& wxTheApp
->GetTopWindow() == this )
65 wxTheApp
->SetTopWindow(NULL
);
67 bool shouldExit
= IsLastBeforeExit();
69 wxTopLevelWindows
.DeleteObject(this);
74 wxTheApp
->ExitMainLoop();
78 bool wxTopLevelWindowBase::Destroy()
80 // delayed destruction: the frame will be deleted during the next idle
82 if ( !wxPendingDelete
.Member(this) )
83 wxPendingDelete
.Append(this);
85 if (wxTopLevelWindows
.GetCount() > 1)
87 // Hide it immediately. This should
88 // not be done if this TLW is the
89 // only one left since we then would
90 // risk not to get any idle events
91 // at all anymore during which we
92 // could delete any pending events.
99 bool wxTopLevelWindowBase::IsLastBeforeExit() const
101 // we exit the application if there are no more top level windows left
102 // normally but wxApp can prevent this from happening
103 return wxTopLevelWindows
.GetCount() == 1 &&
104 wxTopLevelWindows
.GetFirst()->GetData() == (wxWindow
*)this &&
105 wxTheApp
&& wxTheApp
->GetExitOnFrameDelete();
108 // ----------------------------------------------------------------------------
109 // wxTopLevelWindow geometry
110 // ----------------------------------------------------------------------------
112 void wxTopLevelWindowBase::GetRectForTopLevelChildren(int *x
, int *y
, int *w
, int *h
)
118 wxSize
wxTopLevelWindowBase::GetMaxSize() const
120 wxSize
size( GetMaxWidth(), GetMaxHeight() );
123 wxClientDisplayRect( 0, 0, &w
, &h
);
125 if( size
.GetWidth() == wxDefaultCoord
)
128 if( size
.GetHeight() == wxDefaultCoord
)
135 wxSize
wxTopLevelWindowBase::GetDefaultSize()
137 wxSize size
= wxGetClientDisplayRect().GetSize();
139 // create proportionally bigger windows on small screens
140 if ( size
.x
>= 1024 )
142 else if ( size
.x
>= 800 )
144 else if ( size
.x
>= 320 )
149 else if ( size
.y
> 200 )
158 // ----------------------------------------------------------------------------
159 // wxTopLevelWindow size management: we exclude the areas taken by
160 // menu/status/toolbars from the client area, so the client area is what's
161 // really available for the frame contents
162 // ----------------------------------------------------------------------------
164 void wxTopLevelWindowBase::DoScreenToClient(int *x
, int *y
) const
166 wxWindow::DoScreenToClient(x
, y
);
168 // translate the wxWindow client coords to our client coords
169 wxPoint
pt(GetClientAreaOrigin());
176 void wxTopLevelWindowBase::DoClientToScreen(int *x
, int *y
) const
178 // our client area origin (0, 0) may be really something like (0, 30) for
179 // wxWindow if we have a toolbar, account for it before translating
180 wxPoint
pt(GetClientAreaOrigin());
186 wxWindow::DoClientToScreen(x
, y
);
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
194 // default resizing behaviour - if only ONE subwindow, resize to fill the
196 void wxTopLevelWindowBase::DoLayout()
198 // if we're using constraints or sizers - do use them
199 if ( GetAutoLayout() )
205 // do we have _exactly_ one child?
206 wxWindow
*child
= (wxWindow
*)NULL
;
207 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
209 node
= node
->GetNext() )
211 wxWindow
*win
= node
->GetData();
213 // exclude top level and managed windows (status bar isn't
214 // currently in the children list except under wxMac anyhow, but
215 // it makes no harm to test for it)
216 if ( !win
->IsTopLevel() && !IsOneOfBars(win
) )
220 return; // it's our second subwindow - nothing to do
227 // do we have any children at all?
230 // exactly one child - set it's size to fill the whole frame
231 int clientW
, clientH
;
232 DoGetClientSize(&clientW
, &clientH
);
234 // for whatever reasons, wxGTK wants to have a small offset - it
235 // probably looks better with it?
237 static const int ofs
= 1;
239 static const int ofs
= 0;
242 child
->SetSize(ofs
, ofs
, clientW
- 2*ofs
, clientH
- 2*ofs
);
247 // The default implementation for the close window event.
248 void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
253 bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized
)
255 wxIconizeEvent
event(GetId(), iconized
);
256 event
.SetEventObject(this);
258 return GetEventHandler()->ProcessEvent(event
);
261 // do the window-specific processing after processing the update event
262 void wxTopLevelWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
264 if ( event
.GetSetEnabled() )
265 Enable(event
.GetEnabled());
267 if ( event
.GetSetText() )
269 if ( event
.GetText() != GetTitle() )
270 SetTitle(event
.GetText());
274 void wxTopLevelWindowBase::RequestUserAttention(int WXUNUSED(flags
))
276 // it's probably better than do nothing, isn't it?