// Author: Julian Smart, Vadim Zeitlin
// Created: 01/02/97
// Id: $Id$
-// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
+// Copyright: (c) 1998 Robert Roebling and Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// headers
// ----------------------------------------------------------------------------
-#ifdef __GNUG__
- #pragma implementation "toplevelbase.h"
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/toplevel.h"
#include "wx/dcclient.h"
+ #include "wx/app.h"
#endif // WX_PRECOMP
+#include "wx/display.h"
+
// ----------------------------------------------------------------------------
// event table
// ----------------------------------------------------------------------------
// implementation
// ============================================================================
+IMPLEMENT_ABSTRACT_CLASS(wxTopLevelWindow, wxWindow)
+
// ----------------------------------------------------------------------------
// construction/destruction
// ----------------------------------------------------------------------------
wxTopLevelWindowBase::wxTopLevelWindowBase()
{
+ // Unlike windows, top level windows are created hidden by default.
+ m_isShown = false;
+}
+
+wxTopLevelWindowBase::~wxTopLevelWindowBase()
+{
+ // don't let wxTheApp keep any stale pointers to us
+ if ( wxTheApp && wxTheApp->GetTopWindow() == this )
+ wxTheApp->SetTopWindow(NULL);
+
+ bool shouldExit = IsLastBeforeExit();
+
+ wxTopLevelWindows.DeleteObject(this);
+
+ if ( shouldExit )
+ {
+ // then do it
+ wxTheApp->ExitMainLoop();
+ }
}
bool wxTopLevelWindowBase::Destroy()
if ( !wxPendingDelete.Member(this) )
wxPendingDelete.Append(this);
- return TRUE;
+ if (wxTopLevelWindows.GetCount() > 1)
+ {
+ // Hide it immediately. This should
+ // not be done if this TLW is the
+ // only one left since we then would
+ // risk not to get any idle events
+ // at all anymore during which we
+ // could delete any pending events.
+ Hide();
+ }
+
+ return true;
+}
+
+bool wxTopLevelWindowBase::IsLastBeforeExit() const
+{
+ // we exit the application if there are no more top level windows left
+ // normally but wxApp can prevent this from happening
+ return wxTopLevelWindows.GetCount() == 1 &&
+ wxTopLevelWindows.GetFirst()->GetData() == (wxWindow *)this &&
+ wxTheApp && wxTheApp->GetExitOnFrameDelete();
+}
+
+// ----------------------------------------------------------------------------
+// wxTopLevelWindow geometry
+// ----------------------------------------------------------------------------
+
+void wxTopLevelWindowBase::GetRectForTopLevelChildren(int *x, int *y, int *w, int *h)
+{
+ GetPosition(x,y);
+ GetSize(w,h);
+}
+
+wxSize wxTopLevelWindowBase::GetMaxSize() const
+{
+ wxSize size( GetMaxWidth(), GetMaxHeight() );
+ int w, h;
+
+ wxClientDisplayRect( 0, 0, &w, &h );
+
+ if( size.GetWidth() == wxDefaultCoord )
+ size.SetWidth( w );
+
+ if( size.GetHeight() == wxDefaultCoord )
+ size.SetHeight( h );
+
+ return size;
+}
+
+/* static */
+wxSize wxTopLevelWindowBase::GetDefaultSize()
+{
+ wxSize size = wxGetClientDisplayRect().GetSize();
+
+ // create proportionally bigger windows on small screens
+ if ( size.x >= 1024 )
+ size.x = 400;
+ else if ( size.x >= 800 )
+ size.x = 300;
+ else if ( size.x >= 320 )
+ size.x = 240;
+
+ if ( size.y >= 768 )
+ size.y = 250;
+ else if ( size.y > 200 )
+ {
+ size.y *= 2;
+ size.y /= 3;
+ }
+
+ return size;
+}
+
+void wxTopLevelWindowBase::DoCentre(int dir)
+{
+ wxRect rectCentre;
+ if ( !(dir & wxCENTRE_ON_SCREEN) && GetParent() )
+ {
+ // centre on parent window
+ rectCentre = GetParent()->GetRect();
+ }
+ else
+ {
+ // we were explicitely asked to centre this window on the entire screen
+ // or if we have no parent anyhow and so can't centre on it
+#if wxUSE_DISPLAY
+ const int nDisplay = wxDisplay::GetFromWindow(this);
+ if ( nDisplay != wxNOT_FOUND )
+ {
+ rectCentre = wxDisplay(nDisplay).GetGeometry();
+ }
+ else
+#endif // wxUSE_DISPLAY
+ {
+ wxDisplaySize(&rectCentre.width, &rectCentre.height);
+ }
+ }
+
+ // window may be at -1 if it's centered on a secondary display, for example
+ SetSize(GetRect().CentreIn(rectCentre, dir), wxSIZE_ALLOW_MINUS_ONE);
}
// ----------------------------------------------------------------------------
-// wxTopLevelWindow size management: we exclude the areas taken by menu/status/toolbars
-// from the client area, so the client area is what's really available for the
-// frame contents
+// wxTopLevelWindow size management: we exclude the areas taken by
+// menu/status/toolbars from the client area, so the client area is what's
+// really available for the frame contents
// ----------------------------------------------------------------------------
void wxTopLevelWindowBase::DoScreenToClient(int *x, int *y) const
{
wxWindow::DoScreenToClient(x, y);
- // We may be faking the client origin.
- // So a window that's really at (0, 30) may appear
- // (to wxWin apps) to be at (0, 0).
+ // translate the wxWindow client coords to our client coords
wxPoint pt(GetClientAreaOrigin());
- *x -= pt.x;
- *y -= pt.y;
+ if ( x )
+ *x -= pt.x;
+ if ( y )
+ *y -= pt.y;
}
void wxTopLevelWindowBase::DoClientToScreen(int *x, int *y) const
{
- // We may be faking the client origin.
- // So a window that's really at (0, 30) may appear
- // (to wxWin apps) to be at (0, 0).
- wxPoint pt1(GetClientAreaOrigin());
- *x += pt1.x;
- *y += pt1.y;
+ // our client area origin (0, 0) may be really something like (0, 30) for
+ // wxWindow if we have a toolbar, account for it before translating
+ wxPoint pt(GetClientAreaOrigin());
+ if ( x )
+ *x += pt.x;
+ if ( y )
+ *y += pt.y;
wxWindow::DoClientToScreen(x, y);
}
// default resizing behaviour - if only ONE subwindow, resize to fill the
// whole client area
-void wxTopLevelWindowBase::OnSize(wxSizeEvent& WXUNUSED(event))
+void wxTopLevelWindowBase::DoLayout()
{
- // if we're using constraints - do use them
-#if wxUSE_CONSTRAINTS
+ // if we're using constraints or sizers - do use them
if ( GetAutoLayout() )
{
Layout();
}
else
-#endif // wxUSE_CONSTRAINTS
{
// do we have _exactly_ one child?
wxWindow *child = (wxWindow *)NULL;
- for ( wxWindowList::Node *node = GetChildren().GetFirst();
+ for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
node;
node = node->GetNext() )
{
return GetEventHandler()->ProcessEvent(event);
}
+// do the window-specific processing after processing the update event
+void wxTopLevelWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
+{
+ // call inherited, but skip the wxControl's version, and call directly the
+ // wxWindow's one instead, because the only reason why we are overriding this
+ // function is that we want to use SetTitle() instead of wxControl::SetLabel()
+ wxWindowBase::DoUpdateWindowUI(event);
+
+ // update title
+ if ( event.GetSetText() )
+ {
+ if ( event.GetText() != GetTitle() )
+ SetTitle(event.GetText());
+ }
+}
+
+void wxTopLevelWindowBase::RequestUserAttention(int WXUNUSED(flags))
+{
+ // it's probably better than do nothing, isn't it?
+ Raise();
+}
+