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 if (wxTopLevelWindows
.GetCount() > 1)
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.
97 bool wxTopLevelWindowBase::IsLastBeforeExit() const
99 // we exit the application if there are no more top level windows left
100 // normally but wxApp can prevent this from happening
101 return wxTopLevelWindows
.GetCount() == 1 &&
102 wxTopLevelWindows
.GetFirst()->GetData() == (wxWindow
*)this &&
103 wxTheApp
&& wxTheApp
->GetExitOnFrameDelete();
106 // ----------------------------------------------------------------------------
107 // wxTopLevelWindow geometry
108 // ----------------------------------------------------------------------------
110 wxSize
wxTopLevelWindowBase::GetMaxSize() const
112 wxSize
size( GetMaxWidth(), GetMaxHeight() );
115 wxClientDisplayRect( 0, 0, &w
, &h
);
117 if( size
.GetWidth() == -1 )
120 if( size
.GetHeight() == -1 )
126 // ----------------------------------------------------------------------------
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
130 // ----------------------------------------------------------------------------
132 void wxTopLevelWindowBase::DoScreenToClient(int *x
, int *y
) const
134 wxWindow::DoScreenToClient(x
, y
);
136 // translate the wxWindow client coords to our client coords
137 wxPoint
pt(GetClientAreaOrigin());
144 void wxTopLevelWindowBase::DoClientToScreen(int *x
, int *y
) const
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());
154 wxWindow::DoClientToScreen(x
, y
);
158 // ----------------------------------------------------------------------------
160 // ----------------------------------------------------------------------------
162 // default resizing behaviour - if only ONE subwindow, resize to fill the
164 void wxTopLevelWindowBase::OnSize(wxSizeEvent
& WXUNUSED(event
))
166 // if we're using constraints or sizers - do use them
167 if ( GetAutoLayout() )
173 // do we have _exactly_ one child?
174 wxWindow
*child
= (wxWindow
*)NULL
;
175 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
177 node
= node
->GetNext() )
179 wxWindow
*win
= node
->GetData();
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
) )
188 return; // it's our second subwindow - nothing to do
195 // do we have any children at all?
198 // exactly one child - set it's size to fill the whole frame
199 int clientW
, clientH
;
200 DoGetClientSize(&clientW
, &clientH
);
202 // for whatever reasons, wxGTK wants to have a small offset - it
203 // probably looks better with it?
205 static const int ofs
= 1;
207 static const int ofs
= 0;
210 child
->SetSize(ofs
, ofs
, clientW
- 2*ofs
, clientH
- 2*ofs
);
215 // The default implementation for the close window event.
216 void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
221 bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized
)
223 wxIconizeEvent
event(GetId(), iconized
);
224 event
.SetEventObject(this);
226 return GetEventHandler()->ProcessEvent(event
);
229 // do the window-specific processing after processing the update event
230 void wxTopLevelWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
232 if ( event
.GetSetEnabled() )
233 Enable(event
.GetEnabled());
235 if ( event
.GetSetText() )
237 if ( event
.GetText() != GetTitle() )
238 SetTitle(event
.GetText());