home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CSwatchBrokerView.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  5.9 KB  |  221 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. //    CSwatchBrokerView.cp
  21. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  22.  
  23. #include "CSwatchBrokerView.h"
  24. #include "CBevelView.h"
  25.  
  26.  
  27. CBrokeredView::CBrokeredView(LStream* inStream)
  28.     :    LView(inStream)
  29. {
  30. }
  31.  
  32. void CBrokeredView::GetPendingFrameSize(SDimension16& outSize) const
  33. {
  34.     outSize = mPendingSize;
  35. }
  36.  
  37. void CBrokeredView::GetPendingFrameLocation(SPoint32& outLocation) const
  38. {
  39.     outLocation = mPendingLocation;
  40. }
  41.  
  42. void CBrokeredView::ResizeFrameBy(
  43.     Int16                 inWidthDelta,
  44.     Int16                 inHeightDelta,
  45.     Boolean             inRefresh)
  46. {
  47.     if (inRefresh)
  48.         {
  49.         GetFrameSize(mPendingSize);
  50.         mPendingSize.width += inWidthDelta;
  51.         mPendingSize.height += inHeightDelta;
  52.         BroadcastMessage(msg_BrokeredViewAboutToChangeSize, this);
  53.         }
  54.         
  55.     LView::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
  56.     
  57.     if (!inRefresh)
  58.         BroadcastMessage(msg_BrokeredViewChangeSize, this);
  59. }
  60.  
  61. void CBrokeredView::MoveBy(
  62.     Int32                inHorizDelta,
  63.     Int32                 inVertDelta,
  64.     Boolean             inRefresh)
  65. {
  66.     if (inRefresh)
  67.         {
  68.         GetFrameLocation(mPendingLocation);
  69.         mPendingLocation.h += inHorizDelta;
  70.         mPendingLocation.v += inVertDelta;
  71.         BroadcastMessage(msg_BrokeredViewAboutToMove, this);
  72.         }
  73.         
  74.     LView::MoveBy(inHorizDelta, inVertDelta, inRefresh);
  75.     
  76.     if (!inRefresh)
  77.         BroadcastMessage(msg_BrokeredViewMoved, this);
  78. }
  79.  
  80. CSwatchBrokerView::CSwatchBrokerView(LStream* inStream)
  81.     :    LView(inStream)
  82. {
  83.     *inStream >> mDynamicPaneID;
  84.     *inStream >> mBalancePaneID;
  85.     SetRefreshAllWhenResized(false);
  86. }
  87.  
  88.  
  89. void CSwatchBrokerView::FinishCreateSelf(void)
  90. {
  91.     LView::FinishCreateSelf();
  92.  
  93.     mBalancePane = FindPaneByID(mBalancePaneID);
  94.     Assert_(mBalancePane != NULL);
  95.     
  96.     mDynamicPane = dynamic_cast<CBrokeredView*>(FindPaneByID(mDynamicPaneID));
  97.     if (mDynamicPane)
  98.     {
  99.         mDynamicPane->AddListener(this);
  100.  
  101.         // We need to "prime to pump".  The dynamic view may have resized itself
  102.         // in it's FinishCreateSelf(), at which point we were not listening.
  103.         SDimension16 theSize;
  104.         mDynamicPane->GetFrameSize(theSize);
  105.         AdaptToBrokeredViewResize(mDynamicPane, theSize, true);
  106.     }
  107. }
  108.  
  109.  
  110. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  111.  
  112. // on adapt to super frame size we ignore broadcasts from the subs
  113. // so that we dont recalculate too often.  we really want to know when
  114. // a sub changes height so we can reposition and resize the others.
  115.  
  116. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  117.  
  118. void CSwatchBrokerView::AdaptToSuperFrameSize(
  119.     Int32                inSurrWidthDelta,
  120.     Int32                inSurrHeightDelta,
  121.     Boolean                inRefresh)
  122. {
  123.     StopListening();
  124.     LView::AdaptToSuperFrameSize(inSurrWidthDelta, inSurrHeightDelta, inRefresh);
  125.     StartListening();
  126. }
  127.  
  128.  
  129. void CSwatchBrokerView::ListenToMessage(
  130.     MessageT            inMessage,
  131.     void*                ioParam)
  132. {
  133.     CBrokeredView* theView = (CBrokeredView*)ioParam;
  134.  
  135.     switch (inMessage)
  136.         {
  137.         case msg_BrokeredViewAboutToChangeSize:
  138.             {
  139.             SDimension16 thePendingSize;
  140.             theView->GetPendingFrameSize(thePendingSize);
  141.             AdaptToBrokeredViewResize(theView, thePendingSize, true);
  142.             }
  143.             break;
  144.             
  145.         case msg_BrokeredViewChangeSize:
  146.             {
  147.             SDimension16 theNewSize;
  148.             theView->GetFrameSize(theNewSize);
  149.             AdaptToBrokeredViewResize(theView, theNewSize, false);
  150.             }
  151.             break;
  152.             
  153.         case msg_BrokeredViewAboutToMove:
  154.             {
  155.             SPoint32 thePendingLocation;
  156.             theView->GetPendingFrameLocation(thePendingLocation);
  157.             AdaptToBrokeredViewMove(theView, thePendingLocation, true);
  158.             }
  159.             break;
  160.         
  161.         case msg_BrokeredViewMoved:
  162.             {
  163.             SPoint32 theNewLocation;
  164.             theView->GetFrameLocation(theNewLocation);
  165.             AdaptToBrokeredViewMove(theView, theNewLocation, false);
  166.             }
  167.             break;
  168.         }
  169.  
  170. }
  171.  
  172. // this whole thing needs to be way more robust.  multiple brokered views,
  173. // top to bottom ordering, etc.
  174.  
  175. void CSwatchBrokerView::AdaptToBrokeredViewResize(
  176.     CBrokeredView*        inView,
  177.     const SDimension16    inNewSize,
  178.     Boolean                inRefresh)
  179. {
  180.     SDimension16 theBrokerSize;
  181.     GetFrameSize(theBrokerSize);
  182.  
  183.     SDimension16 theBalanceSize;
  184.     mBalancePane->GetFrameSize(theBalanceSize);
  185.     
  186.     SPoint32 theBalanceLocation;
  187.     mBalancePane->GetFrameLocation(theBalanceLocation);
  188.     
  189.     SPoint32 theNewLocation;
  190.     inView->GetFrameLocation(theNewLocation);
  191.     
  192.     Int32 theBalanceHeight= (theBrokerSize.height - inNewSize.height) - theBalanceSize.height;
  193.     
  194.     mBalancePane->ResizeFrameBy(0, theBalanceHeight, false);
  195.     
  196.     // Need to determine if the balance pane is above or below the dynamic pane
  197.     SPoint32 dynamicPaneLocation, balancePaneLocation;
  198.     mDynamicPane->GetFrameLocation( dynamicPaneLocation );
  199.     mBalancePane->GetFrameLocation( balancePaneLocation );
  200.     if( balancePaneLocation.v >= dynamicPaneLocation.v)
  201.         mBalancePane->MoveBy(0, -theBalanceHeight, false);
  202.     
  203.     // if we're in an enclosing CBevelView, we need to notify it that
  204.     // it's subpanes have changed so that it can recalculate the
  205.     // bevel region.
  206.     
  207.     CBevelView::SubPanesChanged(this, inRefresh);
  208.     
  209.     if (inRefresh)
  210.         Refresh();
  211. }
  212.  
  213. void CSwatchBrokerView::AdaptToBrokeredViewMove(
  214.     CBrokeredView*        inView,
  215.     const SPoint32&        inNewLocation,
  216.     Boolean                inRefresh)
  217. {
  218.  
  219. }
  220.     
  221.