]>
git.saurik.com Git - wxWidgets.git/blob - src/common/toplvcmn.cpp
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, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
20 #pragma implementation "toplevelbase.h"
23 // For compilers that support precompilation, includes "wx.h".
24 #include "wx/wxprec.h"
32 #include "wx/toplevel.h"
33 #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 // FIXME: some platforms don't have wxTopLevelWindow yet
50 #ifdef wxTopLevelWindowNative
51 IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow
, wxWindow
)
54 // ----------------------------------------------------------------------------
55 // construction/destruction
56 // ----------------------------------------------------------------------------
58 wxTopLevelWindowBase::wxTopLevelWindowBase()
62 wxTopLevelWindowBase::~wxTopLevelWindowBase()
64 // don't let wxTheApp keep any stale pointers to us
65 if ( wxTheApp
&& wxTheApp
->GetTopWindow() == this )
66 wxTheApp
->SetTopWindow(NULL
);
68 bool shouldExit
= IsLastBeforeExit();
70 wxTopLevelWindows
.DeleteObject(this);
75 wxTheApp
->ExitMainLoop();
79 bool wxTopLevelWindowBase::Destroy()
81 // delayed destruction: the frame will be deleted during the next idle
83 if ( !wxPendingDelete
.Member(this) )
84 wxPendingDelete
.Append(this);
90 bool wxTopLevelWindowBase::IsLastBeforeExit()
92 // we exit the application if there are no more top level windows left
93 // normally but wxApp can prevent this from happening
94 return (wxTopLevelWindows
.GetCount() == 1) &&
95 wxTheApp
&& wxTheApp
->GetExitOnFrameDelete();
98 // ----------------------------------------------------------------------------
99 // wxTopLevelWindow geometry
100 // ----------------------------------------------------------------------------
102 wxSize
wxTopLevelWindowBase::GetMaxSize() const
104 wxSize
size( GetMaxWidth(), GetMaxHeight() );
107 wxClientDisplayRect( 0, 0, &w
, &h
);
109 if( size
.GetWidth() == -1 )
112 if( size
.GetHeight() == -1 )
118 // ----------------------------------------------------------------------------
119 // wxTopLevelWindow size management: we exclude the areas taken by
120 // menu/status/toolbars from the client area, so the client area is what's
121 // really available for the frame contents
122 // ----------------------------------------------------------------------------
124 void wxTopLevelWindowBase::DoScreenToClient(int *x
, int *y
) const
126 wxWindow::DoScreenToClient(x
, y
);
128 // translate the wxWindow client coords to our client coords
129 wxPoint
pt(GetClientAreaOrigin());
136 void wxTopLevelWindowBase::DoClientToScreen(int *x
, int *y
) const
138 // our client area origin (0, 0) may be really something like (0, 30) for
139 // wxWindow if we have a toolbar, account for it before translating
140 wxPoint
pt(GetClientAreaOrigin());
146 wxWindow::DoClientToScreen(x
, y
);
150 // ----------------------------------------------------------------------------
152 // ----------------------------------------------------------------------------
154 // default resizing behaviour - if only ONE subwindow, resize to fill the
156 void wxTopLevelWindowBase::OnSize(wxSizeEvent
& WXUNUSED(event
))
158 // if we're using constraints or sizers - do use them
159 if ( GetAutoLayout() )
165 // do we have _exactly_ one child?
166 wxWindow
*child
= (wxWindow
*)NULL
;
167 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
169 node
= node
->GetNext() )
171 wxWindow
*win
= node
->GetData();
173 // exclude top level and managed windows (status bar isn't
174 // currently in the children list except under wxMac anyhow, but
175 // it makes no harm to test for it)
176 if ( !win
->IsTopLevel() && !IsOneOfBars(win
) )
180 return; // it's our second subwindow - nothing to do
187 // do we have any children at all?
190 // exactly one child - set it's size to fill the whole frame
191 int clientW
, clientH
;
192 DoGetClientSize(&clientW
, &clientH
);
194 // for whatever reasons, wxGTK wants to have a small offset - it
195 // probably looks better with it?
197 static const int ofs
= 1;
199 static const int ofs
= 0;
202 child
->SetSize(ofs
, ofs
, clientW
- 2*ofs
, clientH
- 2*ofs
);
207 // The default implementation for the close window event.
208 void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
213 bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized
)
215 wxIconizeEvent
event(GetId(), iconized
);
216 event
.SetEventObject(this);
218 return GetEventHandler()->ProcessEvent(event
);