]>
git.saurik.com Git - wxWidgets.git/blob - src/common/toplvcmn.cpp
fd659ac2b6dc471d135492165aaf4d30632538ce
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"
31 #include "wx/toplevel.h"
32 #include "wx/dcclient.h"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 BEGIN_EVENT_TABLE(wxTopLevelWindowBase
, wxWindow
)
40 EVT_CLOSE(wxTopLevelWindowBase::OnCloseWindow
)
41 EVT_SIZE(wxTopLevelWindowBase::OnSize
)
44 // ============================================================================
46 // ============================================================================
48 // FIXME: some platforms don't have wxTopLevelWindow yet
49 #ifdef wxTopLevelWindowNative
50 IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow
, wxWindow
)
53 // ----------------------------------------------------------------------------
54 // construction/destruction
55 // ----------------------------------------------------------------------------
57 wxTopLevelWindowBase::wxTopLevelWindowBase()
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);
89 bool wxTopLevelWindowBase::IsLastBeforeExit()
91 // we exit the application if there are no more top level windows left
92 // normally but wxApp can prevent this from happening
93 return (wxTopLevelWindows
.GetCount() == 1) &&
94 wxTheApp
&& wxTheApp
->GetExitOnFrameDelete();
97 // ----------------------------------------------------------------------------
98 // wxTopLevelWindow geometry
99 // ----------------------------------------------------------------------------
101 wxSize
wxTopLevelWindowBase::GetMaxSize() const
103 wxSize
size( GetMaxWidth(), GetMaxHeight() );
106 wxClientDisplayRect( 0, 0, &w
, &h
);
108 if( size
.GetWidth() == -1 )
111 if( size
.GetHeight() == -1 )
117 // ----------------------------------------------------------------------------
118 // wxTopLevelWindow size management: we exclude the areas taken by
119 // menu/status/toolbars from the client area, so the client area is what's
120 // really available for the frame contents
121 // ----------------------------------------------------------------------------
123 void wxTopLevelWindowBase::DoScreenToClient(int *x
, int *y
) const
125 wxWindow::DoScreenToClient(x
, y
);
127 // translate the wxWindow client coords to our client coords
128 wxPoint
pt(GetClientAreaOrigin());
135 void wxTopLevelWindowBase::DoClientToScreen(int *x
, int *y
) const
137 // our client area origin (0, 0) may be really something like (0, 30) for
138 // wxWindow if we have a toolbar, account for it before translating
139 wxPoint
pt(GetClientAreaOrigin());
145 wxWindow::DoClientToScreen(x
, y
);
149 // ----------------------------------------------------------------------------
151 // ----------------------------------------------------------------------------
153 // default resizing behaviour - if only ONE subwindow, resize to fill the
155 void wxTopLevelWindowBase::OnSize(wxSizeEvent
& WXUNUSED(event
))
157 // if we're using constraints or sizers - do use them
158 if ( GetAutoLayout() )
164 // do we have _exactly_ one child?
165 wxWindow
*child
= (wxWindow
*)NULL
;
166 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
168 node
= node
->GetNext() )
170 wxWindow
*win
= node
->GetData();
172 // exclude top level and managed windows (status bar isn't
173 // currently in the children list except under wxMac anyhow, but
174 // it makes no harm to test for it)
175 if ( !win
->IsTopLevel() && !IsOneOfBars(win
) )
179 return; // it's our second subwindow - nothing to do
186 // do we have any children at all?
189 // exactly one child - set it's size to fill the whole frame
190 int clientW
, clientH
;
191 DoGetClientSize(&clientW
, &clientH
);
193 // for whatever reasons, wxGTK wants to have a small offset - it
194 // probably looks better with it?
196 static const int ofs
= 1;
198 static const int ofs
= 0;
201 child
->SetSize(ofs
, ofs
, clientW
- 2*ofs
, clientH
- 2*ofs
);
206 // The default implementation for the close window event.
207 void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
212 bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized
)
214 wxIconizeEvent
event(GetId(), iconized
);
215 event
.SetEventObject(this);
217 return GetEventHandler()->ProcessEvent(event
);