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_DYNAMIC_CLASS(wxTopLevelWindow
, wxWindow
)
51 // ----------------------------------------------------------------------------
52 // construction/destruction
53 // ----------------------------------------------------------------------------
55 wxTopLevelWindowBase::wxTopLevelWindowBase()
59 wxTopLevelWindowBase::~wxTopLevelWindowBase()
61 // don't let wxTheApp keep any stale pointers to us
62 if ( wxTheApp
&& wxTheApp
->GetTopWindow() == this )
63 wxTheApp
->SetTopWindow(NULL
);
65 bool shouldExit
= IsLastBeforeExit();
67 wxTopLevelWindows
.DeleteObject(this);
72 wxTheApp
->ExitMainLoop();
76 bool wxTopLevelWindowBase::Destroy()
78 // delayed destruction: the frame will be deleted during the next idle
80 if ( !wxPendingDelete
.Member(this) )
81 wxPendingDelete
.Append(this);
83 // but hide it immediately
86 // also remove it from the list of parents children so that the loop in
87 // wxWindowBase::DestroyChildren() eventually terminates
90 m_parent
->RemoveChild(this);
92 // don't do it again in our dtor
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 wxSize
wxTopLevelWindowBase::GetMaxSize() const
114 wxSize
size( GetMaxWidth(), GetMaxHeight() );
117 wxClientDisplayRect( 0, 0, &w
, &h
);
119 if( size
.GetWidth() == -1 )
122 if( size
.GetHeight() == -1 )
128 // ----------------------------------------------------------------------------
129 // wxTopLevelWindow size management: we exclude the areas taken by
130 // menu/status/toolbars from the client area, so the client area is what's
131 // really available for the frame contents
132 // ----------------------------------------------------------------------------
134 void wxTopLevelWindowBase::DoScreenToClient(int *x
, int *y
) const
136 wxWindow::DoScreenToClient(x
, y
);
138 // translate the wxWindow client coords to our client coords
139 wxPoint
pt(GetClientAreaOrigin());
146 void wxTopLevelWindowBase::DoClientToScreen(int *x
, int *y
) const
148 // our client area origin (0, 0) may be really something like (0, 30) for
149 // wxWindow if we have a toolbar, account for it before translating
150 wxPoint
pt(GetClientAreaOrigin());
156 wxWindow::DoClientToScreen(x
, y
);
160 // ----------------------------------------------------------------------------
162 // ----------------------------------------------------------------------------
164 // default resizing behaviour - if only ONE subwindow, resize to fill the
166 void wxTopLevelWindowBase::OnSize(wxSizeEvent
& WXUNUSED(event
))
168 // if we're using constraints or sizers - do use them
169 if ( GetAutoLayout() )
175 // do we have _exactly_ one child?
176 wxWindow
*child
= (wxWindow
*)NULL
;
177 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
179 node
= node
->GetNext() )
181 wxWindow
*win
= node
->GetData();
183 // exclude top level and managed windows (status bar isn't
184 // currently in the children list except under wxMac anyhow, but
185 // it makes no harm to test for it)
186 if ( !win
->IsTopLevel() && !IsOneOfBars(win
) )
190 return; // it's our second subwindow - nothing to do
197 // do we have any children at all?
200 // exactly one child - set it's size to fill the whole frame
201 int clientW
, clientH
;
202 DoGetClientSize(&clientW
, &clientH
);
204 // for whatever reasons, wxGTK wants to have a small offset - it
205 // probably looks better with it?
207 static const int ofs
= 1;
209 static const int ofs
= 0;
212 child
->SetSize(ofs
, ofs
, clientW
- 2*ofs
, clientH
- 2*ofs
);
217 // The default implementation for the close window event.
218 void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
223 bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized
)
225 wxIconizeEvent
event(GetId(), iconized
);
226 event
.SetEventObject(this);
228 return GetEventHandler()->ProcessEvent(event
);
231 // do the window-specific processing after processing the update event
232 void wxTopLevelWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
234 if ( event
.GetSetEnabled() )
235 Enable(event
.GetEnabled());
237 if ( event
.GetSetText() )
239 if ( event
.GetText() != GetTitle() )
240 SetTitle(event
.GetText());