home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2233.zip / wxOS2-2_3_3.zip / wxWindows-2.3.3 / src / common / toplvcmn.cpp < prev    next >
C/C++ Source or Header  |  2002-08-17  |  7KB  |  222 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name:        common/toplvcmn.cpp
  3. // Purpose:     common (for all platforms) wxTopLevelWindow functions
  4. // Author:      Julian Smart, Vadim Zeitlin
  5. // Created:     01/02/97
  6. // Id:          $Id: toplvcmn.cpp,v 1.16 2002/08/17 12:11:03 RR Exp $
  7. // Copyright:   (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
  8. // Licence:     wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10.  
  11. // ============================================================================
  12. // declarations
  13. // ============================================================================
  14.  
  15. // ----------------------------------------------------------------------------
  16. // headers
  17. // ----------------------------------------------------------------------------
  18.  
  19. #ifdef __GNUG__
  20.     #pragma implementation "toplevelbase.h"
  21. #endif
  22.  
  23. // For compilers that support precompilation, includes "wx.h".
  24. #include "wx/wxprec.h"
  25.  
  26. #ifdef __BORLANDC__
  27.     #pragma hdrstop
  28. #endif
  29.  
  30. #ifndef WX_PRECOMP
  31.     #include "wx/toplevel.h"
  32.     #include "wx/dcclient.h"
  33.     #include "wx/app.h"
  34. #endif // WX_PRECOMP
  35.  
  36. // ----------------------------------------------------------------------------
  37. // event table
  38. // ----------------------------------------------------------------------------
  39.  
  40. BEGIN_EVENT_TABLE(wxTopLevelWindowBase, wxWindow)
  41.     EVT_CLOSE(wxTopLevelWindowBase::OnCloseWindow)
  42.     EVT_SIZE(wxTopLevelWindowBase::OnSize)
  43. END_EVENT_TABLE()
  44.  
  45. // ============================================================================
  46. // implementation
  47. // ============================================================================
  48.  
  49. // FIXME: some platforms don't have wxTopLevelWindow yet
  50. #ifdef wxTopLevelWindowNative
  51.     IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow)
  52. #endif
  53.  
  54. // ----------------------------------------------------------------------------
  55. // construction/destruction
  56. // ----------------------------------------------------------------------------
  57.  
  58. wxTopLevelWindowBase::wxTopLevelWindowBase()
  59. {
  60. }
  61.  
  62. wxTopLevelWindowBase::~wxTopLevelWindowBase()
  63. {
  64.     // don't let wxTheApp keep any stale pointers to us
  65.     if ( wxTheApp && wxTheApp->GetTopWindow() == this )
  66.         wxTheApp->SetTopWindow(NULL);
  67.  
  68.     bool shouldExit = IsLastBeforeExit();
  69.  
  70.     wxTopLevelWindows.DeleteObject(this);
  71.  
  72.     if ( shouldExit )
  73.     {
  74.         // then do it
  75.         wxTheApp->ExitMainLoop();
  76.     }
  77. }
  78.  
  79. bool wxTopLevelWindowBase::Destroy()
  80. {
  81.     // delayed destruction: the frame will be deleted during the next idle
  82.     // loop iteration
  83.     if ( !wxPendingDelete.Member(this) )
  84.         wxPendingDelete.Append(this);
  85.  
  86.     return TRUE;
  87. }
  88.  
  89. bool wxTopLevelWindowBase::IsLastBeforeExit() const
  90. {
  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.             wxTopLevelWindows.GetFirst()->GetData() == (wxWindow *)this &&
  95.             wxTheApp && wxTheApp->GetExitOnFrameDelete();
  96. }
  97.  
  98. // ----------------------------------------------------------------------------
  99. // wxTopLevelWindow geometry
  100. // ----------------------------------------------------------------------------
  101.  
  102. wxSize wxTopLevelWindowBase::GetMaxSize() const
  103. {
  104.     wxSize  size( GetMaxWidth(), GetMaxHeight() );
  105.     int     w, h;
  106.  
  107.     wxClientDisplayRect( 0, 0, &w, &h );
  108.  
  109.     if( size.GetWidth() == -1 )
  110.         size.SetWidth( w );
  111.  
  112.     if( size.GetHeight() == -1 )
  113.         size.SetHeight( h );
  114.  
  115.     return size;
  116. }
  117.  
  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. // ----------------------------------------------------------------------------
  123.  
  124. void wxTopLevelWindowBase::DoScreenToClient(int *x, int *y) const
  125. {
  126.     wxWindow::DoScreenToClient(x, y);
  127.  
  128.     // translate the wxWindow client coords to our client coords
  129.     wxPoint pt(GetClientAreaOrigin());
  130.     if ( x )
  131.         *x -= pt.x;
  132.     if ( y )
  133.         *y -= pt.y;
  134. }
  135.  
  136. void wxTopLevelWindowBase::DoClientToScreen(int *x, int *y) const
  137. {
  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());
  141.     if ( x )
  142.         *x += pt.x;
  143.     if ( y )
  144.         *y += pt.y;
  145.  
  146.     wxWindow::DoClientToScreen(x, y);
  147. }
  148.  
  149.  
  150. // ----------------------------------------------------------------------------
  151. // event handlers
  152. // ----------------------------------------------------------------------------
  153.  
  154. // default resizing behaviour - if only ONE subwindow, resize to fill the
  155. // whole client area
  156. void wxTopLevelWindowBase::OnSize(wxSizeEvent& WXUNUSED(event))
  157. {
  158.     // if we're using constraints or sizers - do use them
  159.     if ( GetAutoLayout() )
  160.     {
  161.         Layout();
  162.     }
  163.     else
  164.     {
  165.         // do we have _exactly_ one child?
  166.         wxWindow *child = (wxWindow *)NULL;
  167.         for ( wxWindowList::Node *node = GetChildren().GetFirst();
  168.               node;
  169.               node = node->GetNext() )
  170.         {
  171.             wxWindow *win = node->GetData();
  172.  
  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) )
  177.             {
  178.                 if ( child )
  179.                 {
  180.                     return;     // it's our second subwindow - nothing to do
  181.                 }
  182.  
  183.                 child = win;
  184.             }
  185.         }
  186.  
  187.         // do we have any children at all?
  188.         if ( child )
  189.         {
  190.             // exactly one child - set it's size to fill the whole frame
  191.             int clientW, clientH;
  192.             DoGetClientSize(&clientW, &clientH);
  193.  
  194.             // for whatever reasons, wxGTK wants to have a small offset - it
  195.             // probably looks better with it?
  196. #ifdef __WXGTK__
  197.             static const int ofs = 1;
  198. #else
  199.             static const int ofs = 0;
  200. #endif
  201.  
  202.             child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs);
  203.         }
  204.     }
  205. }
  206.  
  207. // The default implementation for the close window event.
  208. void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
  209. {
  210.     Destroy();
  211. }
  212.  
  213. bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized)
  214. {
  215.     wxIconizeEvent event(GetId(), iconized);
  216.     event.SetEventObject(this);
  217.  
  218.     return GetEventHandler()->ProcessEvent(event);
  219. }
  220.  
  221. // vi:sts=4:sw=4:et
  222.