home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CPlaceHolderView.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  5.3 KB  |  171 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "CPlaceHolderView.h"
  20.  
  21. /*
  22. Overview:
  23. ---------
  24.     A CPlaceHolderView allows you define a space where another view
  25.     from the same window is moved to when the CPlaceHolderView becomes
  26.     visible. When the CPlaceHolderView is hidden, the view is put back
  27.     where it was.
  28.  
  29.     It is similar to the CIncludeView with the difference that the
  30.     CIncludeView creates the included view from an external 'PPob' 
  31.     while the CPlaceHolderView assumes that the included view is
  32.     already somewhere in the same window.
  33.  
  34. Application:
  35. ------------
  36.     It has been developed for the CSubscribeWindow which contains
  37.     a TabSwitcher where each Tab panel displays the same list which
  38.     can't be disposed when switching panels. The list is originally
  39.     attached to the Window (under Constructor) and each Tab panel
  40.     contains a CPlaceHolderView which refers to the list.
  41.  
  42. Limitation:
  43. -----------
  44.     It does not take care of the Commander chain. If the view that
  45.     you plan to move around with different CPlaceHolderViews is also
  46.     a Commander, you will have to manually link it where it fits
  47.     in the Commander chain .
  48. */
  49.  
  50.  
  51. //------------------------------------------------------------------------------------
  52. //    CPlaceHolderView
  53. //
  54. //------------------------------------------------------------------------------------
  55. CPlaceHolderView::CPlaceHolderView(LStream* inStream)
  56. :    LView(inStream),
  57.     mSaveSuperViewOfInstalledView(nil),
  58.     mInstalledView(nil)
  59. {
  60.     *inStream >> mInstalledViewID;
  61. }
  62.  
  63.  
  64. //------------------------------------------------------------------------------------
  65. //    ~CPlaceHolderView
  66. //
  67. //------------------------------------------------------------------------------------
  68. CPlaceHolderView::~CPlaceHolderView()
  69. {
  70. }
  71.  
  72.  
  73. //------------------------------------------------------------------------------------
  74. //    FinishCreateSelf
  75. //
  76. //------------------------------------------------------------------------------------
  77. void CPlaceHolderView::FinishCreateSelf()
  78. {
  79.     LView::FinishCreateSelf();
  80.     AcquirePane();
  81. }
  82.  
  83.  
  84. //------------------------------------------------------------------------------------
  85. //    ShowSelf
  86. //
  87. //------------------------------------------------------------------------------------
  88. void CPlaceHolderView::ShowSelf()
  89. {
  90.     AcquirePane();
  91. }
  92.  
  93.  
  94. //------------------------------------------------------------------------------------
  95. //    HideSelf
  96. //
  97. //------------------------------------------------------------------------------------
  98. void CPlaceHolderView::HideSelf()
  99. {
  100.     ReturnPane();
  101. }
  102.  
  103.  
  104. //------------------------------------------------------------------------------------
  105. //    AcquirePane
  106. //
  107. //------------------------------------------------------------------------------------
  108. void CPlaceHolderView::AcquirePane()
  109. {
  110.     if (mInstalledViewID == 0)        // no view to install
  111.         return;
  112.  
  113.     if (mInstalledView != nil)        // view already installed
  114.         return;
  115.  
  116.     // Starting from the top of the view hierarchy, we look
  117.     // inside the window for a pane with the specified id
  118.     LWindow *    myWindow = LWindow::FetchWindowObject(GetMacPort());
  119.     mInstalledView = (LView *)myWindow->FindPaneByID(mInstalledViewID);
  120.  
  121.     // We don't want to re-install ourselves, though
  122.     if (mInstalledView == (LView *)this)
  123.         mInstalledView = nil;
  124.  
  125.     // Install the view
  126.     Assert_(mInstalledView != nil);
  127.     if (mInstalledView != nil)
  128.     {
  129.         mSaveSuperViewOfInstalledView = mInstalledView->GetSuperView();
  130.         InstallPane(mInstalledView);
  131.     }
  132. }
  133.  
  134.  
  135. //------------------------------------------------------------------------------------
  136. //    ReturnPane
  137. //
  138. //------------------------------------------------------------------------------------
  139. void CPlaceHolderView::ReturnPane()
  140. {
  141.     // Put back the included view to its original place before I disappear...
  142.     if (mInstalledView)
  143.     {
  144.         // ... but check first if I'm still the owner of the view.
  145.         if (mInstalledView->GetSuperView() == this)
  146.         {
  147.             if (mSaveSuperViewOfInstalledView)
  148.                 mInstalledView->PutInside(mSaveSuperViewOfInstalledView, false);
  149.         }
  150.         mInstalledView = nil;
  151.     }
  152. }
  153.  
  154. //------------------------------------------------------------------------------------
  155. //    InstallPane
  156. //
  157. //------------------------------------------------------------------------------------
  158. void CPlaceHolderView::InstallPane(LPane* inPane)
  159. {
  160.     // Set the Pane's binding to my binding
  161.     SBooleanRect frameBinding;
  162.     GetFrameBinding(frameBinding);
  163.     inPane->SetFrameBinding(frameBinding);
  164.     
  165.     // Associate Pane with its superview: me
  166.     inPane->PutInside(this, false);
  167.  
  168.     // Expand the Pane to my size
  169.     this->ExpandSubPane(inPane, true, true);
  170. }
  171.