home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CIncludeView.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  5.9 KB  |  191 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.  
  20. #include "CIncludeView.h"
  21.  
  22. //-----------------------------------
  23. CIncludeView::CIncludeView(LStream* inStream)
  24. //-----------------------------------
  25. :    LPane(inStream)
  26. {
  27.     *inStream >> mInstalledViewID;
  28.  
  29.     if ( mInstalledViewID == 0 ) {    // No view to install.
  30.         //Assert_(mInstalledViewID != 0);
  31.         return;
  32.     }
  33.     
  34.     // We need to create the pane immediately so that it is added to the superview in the order
  35.     // specified in Constructor.
  36.  
  37.     // If the installed view ID is negative, we take the absolute value of it and install
  38.     // the created view directly. Otherwise, we install the first subpane of the created
  39.     // view.
  40.     
  41.     const Boolean installViewDirectly = (mInstalledViewID < 0);
  42.     
  43.     // Store default commander and view, do we need to do this?
  44.     LCommander *defaultCommander = LCommander::GetDefaultCommander();
  45.     LView *defaultView = LPane::GetDefaultView();
  46.  
  47.     //
  48.     // Because of the way that the new stream classes work in CWPro1 PP, we had
  49.     // to make a change to how we read in the included object. Previously, we
  50.     // could just call UReanimator::ReadObjects to do this. However, the new
  51.     // classes change the way things work to use a static counter variable to assign
  52.     // a key for each object in an internal hash table. This would normally be ok, but
  53.     // this class forces a reset of that counter (using ReadObjects() does that) and
  54.     // that messes up all the internal bookkeeping for the reanimator. 
  55.     //
  56.     // To get around that, we have duplicated the code in UReanimator::ReadObjects
  57.     // with the exception of the line that resets the counter. (mcmullen & pinkerton)
  58.     //
  59.     LView *newView = nil;
  60.     {
  61.         StResource objectRes('PPob', installViewDirectly ? 
  62.                                     -mInstalledViewID : mInstalledViewID);
  63.         HLockHi(objectRes.mResourceH);
  64.         
  65.         LDataStream objectStream(*objectRes.mResourceH,
  66.                                         GetHandleSize(objectRes.mResourceH));
  67.         
  68.         // sObjectCount = 0; // THIS IS THE BAD THING WE DON'T WANT TO HAPPEN
  69.         
  70.         Int16    ppobVersion;
  71.         objectStream.ReadBlock(&ppobVersion, sizeof(Int16));
  72.         
  73.         SignalIf_(ppobVersion != 2);
  74.                                         
  75.         newView = (LView *) UReanimator::ObjectsFromStream(&objectStream);
  76.     }
  77.  
  78.     // Restore default commander and view, do we need to do this?
  79.     LCommander::SetDefaultCommander(defaultCommander);
  80.     LPane::SetDefaultView(defaultView);
  81.  
  82.     Assert_(newView != nil);
  83.     if ( newView == nil ) {
  84.         mInstalledViewID = 0;    // So that we don't delete ourselves in FinishCreateSelf()
  85.         return;    // Get outta here!
  86.     }
  87.     
  88.     Try_ {
  89.         
  90.         if ( installViewDirectly ) {
  91.         
  92.             InstallPane(newView);
  93.             
  94.         } else {
  95.             
  96.             // The pane we want should be the lone sibling of the root of the installed view's
  97.             // hierarchy.  Why?  Because constructor will only allow the root of the
  98.             // hierarchy to be an LView or an LWindow, and we want to allow all types of
  99.             // panes.  So here we dig out the real pane that we want to install.
  100.             
  101.             LPane *subPane = nil;
  102.             newView->GetSubPanes().FetchItemAt(1, subPane);
  103.             Assert_(subPane != nil);
  104.             
  105.             if ( subPane != nil ) {
  106.  
  107.                 InstallPane(subPane);
  108.                 //subPane->FinishCreate();
  109.                 // NOT!  Superview will call this, because it's added to the iterator.
  110.             }
  111.             
  112.             delete newView; // old parent of the installed view.  An empty shell, now.
  113.         }
  114.         
  115.     }
  116.     Catch_(inErr) {
  117.         delete newView;    // Make sure we delete the view!
  118.         Throw_(inErr);
  119.     }
  120.     EndCatch_
  121. }
  122.  
  123. //-----------------------------------
  124. CIncludeView::~CIncludeView()
  125. //-----------------------------------
  126. {
  127. }
  128.  
  129. //-----------------------------------
  130. void CIncludeView::InstallPane(LPane* inPane)
  131. // This matches LPane::InitPane.  Unfortunately, this may go out of date
  132. // when InitPane changes.
  133. //-----------------------------------
  134. {
  135.     inPane->SetPaneID(mPaneID);
  136.     mPaneID = 0;    // Set our id to 0 so that we are not confused with the installed pane
  137.  
  138.     inPane->SetUserCon(mUserCon);
  139.     
  140.     if ( mVisible == triState_Off ) {
  141.         inPane->Hide();
  142.     } else {
  143.         inPane->Show();
  144.     }
  145.     
  146.     if ( mEnabled == triState_Off ) {
  147.         inPane->Disable();
  148.     } else {
  149.         inPane->Enable();
  150.     }
  151.  
  152.     SDimension16 frameSize;
  153.     GetFrameSize(frameSize);
  154.     inPane->ResizeFrameTo(frameSize.width, frameSize.height, false);
  155.     SPoint32 location;
  156.     inPane->GetFrameLocation(location);
  157.     inPane->MoveBy(mFrameLocation.h - location.h, mFrameLocation.v - location.v, false);
  158.  
  159.     SBooleanRect frameBinding;
  160.     GetFrameBinding(frameBinding);
  161.     inPane->SetFrameBinding(frameBinding);
  162.     
  163.     // Associate Pane with its SuperView
  164.     LView *theSuperView = mSuperView;
  165.     Assert_(theSuperView);    
  166.     inPane->PutInside(theSuperView, false);
  167.  
  168.     // Negative width and/or height means to expand the
  169.     // Pane to the size of the SuperView
  170.         
  171.     if (theSuperView != nil)
  172.     {
  173.         Boolean    expandHoriz = (mFrameSize.width < 0);
  174.         Boolean    expandVert = (mFrameSize.height < 0);
  175.         if (expandHoriz || expandVert)
  176.             theSuperView->ExpandSubPane(inPane, expandHoriz, expandVert);
  177.     }
  178. } // CIncludeView::InstallPane
  179.  
  180. //-----------------------------------
  181. void CIncludeView::FinishCreateSelf()
  182. //-----------------------------------
  183. {
  184.     inherited::FinishCreateSelf();
  185.  
  186.     if ( mInstalledViewID != 0 ) {
  187.         delete this; // removes this from superview in ~LPane
  188.     }
  189.     
  190. } // CIncludeView::FinishCreateSelf
  191.