home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CToolbarPopup.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  3.9 KB  |  177 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 "CToolbarPopup.h"
  20.  
  21. // this class overrides LGAPopup in order to draw popup menus in the editor and compose
  22. // windows in a dimmed state when the application is switched out.
  23.  
  24. CToolbarPopup::CToolbarPopup( LStream *inStream ) : LGAPopup( inStream )
  25. {
  26. }
  27.  
  28.  
  29. CToolbarPopup::~CToolbarPopup()
  30. {
  31. }
  32.  
  33.  
  34. void CToolbarPopup::DrawSelf()
  35. {
  36.  
  37.     StColorPenState::Normalize ();
  38.     
  39.     // Ñ Get the control drawn in its various states
  40.     if ( IsEnabled () && IsActive () )
  41.     {
  42.         if ( IsHilited ())
  43.             DrawPopupHilited ();
  44.         else
  45.             DrawPopupNormal ();
  46.     }
  47.     else
  48.         DrawPopupDimmed ();
  49.  
  50.     // Ñ Get the arrow drawn
  51.     DrawPopupArrow ();
  52.     
  53.     // Ñ Draw the popup Label
  54.     if ( !IsArrowOnly ())
  55.         DrawPopupLabel ();
  56.  
  57.     // Ñ Get the title for the popup drawn
  58.     if ( !IsArrowOnly ())
  59.         DrawPopupTitle ();
  60.     
  61. }    //    LGAPopup::DrawSelf
  62.  
  63.  
  64. void CToolbarPopup::ActivateSelf()
  65. {
  66.     // Ñ Get things redrawn so that we can see the state change
  67.     Draw ( nil );
  68. }
  69.  
  70.  
  71. void CToolbarPopup::DeactivateSelf()
  72. {
  73.     // Ñ Get things redrawn so that we can see the state change
  74.     Draw ( nil );
  75. }
  76.  
  77.  
  78. #pragma mark -
  79.  
  80.  
  81. CIconToolbarPopup::CIconToolbarPopup( LStream *inStream ) : CGAIconPopup( inStream )
  82. {
  83. }
  84.  
  85.  
  86. CIconToolbarPopup::~CIconToolbarPopup()
  87. {
  88. }
  89.  
  90.  
  91. void CIconToolbarPopup::DrawSelf()
  92. {
  93.     StColorPenState::Normalize ();
  94.     
  95.     // Ñ Get the control drawn in its various states
  96.     if ( IsEnabled() && IsActive())
  97.     {
  98.         if ( IsHilited())
  99.             DrawPopupHilited();
  100.         else
  101.             DrawPopupNormal();
  102.     }
  103.     else
  104.         DrawPopupDimmed();
  105.  
  106.     // Ñ Get the arrow drawn
  107.     DrawPopupArrow();
  108.     
  109.     // Ñ Draw the popup Label
  110.     if ( !IsArrowOnly())
  111.         DrawPopupLabel();
  112.  
  113.     // Ñ Get the title for the popup drawn
  114.     if ( !IsArrowOnly())
  115.         DrawPopupTitle();
  116.     
  117. }
  118.     
  119.  
  120. // override since we don't want to use the constants but the actual size of the icon
  121. void CIconToolbarPopup::DrawPopupTitle(void)
  122. {
  123.     LGAPopup::DrawPopupTitle();
  124.     
  125.     Int16 iconID = GetTitleIconID();
  126.     
  127.     if ( iconID != 0 ) {
  128.     
  129.         CIconHandle theIconH = ::GetCIcon(iconID);
  130.         
  131.         if ( theIconH != nil ) {
  132.             Rect iconRect;
  133.             LGAPopup::CalcTitleRect(iconRect);
  134.             
  135.             Rect trueSize = (**theIconH).iconPMap.bounds;
  136.             if ( EmptyRect( &trueSize ) )
  137.                 trueSize = (**theIconH).iconBMap.bounds;
  138.             
  139.             // if we still don't have a good rect, bail out--nothing to draw
  140.             if ( EmptyRect( &trueSize ) )
  141.                 return;
  142.             
  143.             iconRect.right = iconRect.left + (trueSize.right - trueSize.left);
  144.             iconRect.top = iconRect.top + ((iconRect.bottom - iconRect.top - (trueSize.bottom - trueSize.top)) / 2);
  145.             iconRect.bottom = iconRect.top + trueSize.bottom - trueSize.top;
  146.             
  147.             Int16 transform = ttNone;
  148.             
  149.             if ( IsEnabled() ) {
  150.                 if ( IsHilited() ) {
  151.                     transform = ttSelected;
  152.                 }
  153.             } else {
  154.                 transform = ttDisabled;
  155.             }
  156.         
  157.             ::PlotCIconHandle(&iconRect, ttNone, transform, theIconH);
  158.             
  159.             ::DisposeCIcon(theIconH);
  160.         }
  161.     }
  162. }
  163.  
  164.  
  165. void CIconToolbarPopup::ActivateSelf()
  166. {
  167.     // Ñ Get things redrawn so that we can see the state change
  168.     Draw ( nil );
  169. }
  170.  
  171. void CIconToolbarPopup::DeactivateSelf()
  172. {
  173.     // Ñ Get things redrawn so that we can see the state change
  174.     Draw ( nil );
  175. }
  176.  
  177.