home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / CPatternButtonPopupText.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  6.8 KB  |  206 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 "CPatternButtonPopupText.h"
  20. #include "UGraphicGizmos.h"
  21. #include "UGraphicsUtilities.h"
  22. #include "UGAAppearance.h"
  23. #include "UGAColorRamp.h"
  24. #include "CSharedPatternWorld.h"
  25. #include "CTargetedUpdateMenuRegistry.h"
  26.  
  27. // This class overrides CPatternButtonPopup to provide a popup menu which
  28. // changes the descriptor based on the menu selection
  29. // assumes left-justified text in DrawButtonTitle()
  30.  
  31. // ---------------------------------------------------------------------------
  32. //        Ñ CPatternButtonPopupText
  33. // ---------------------------------------------------------------------------
  34. // Stream-based ctor
  35.  
  36. CPatternButtonPopupText::CPatternButtonPopupText(LStream* inStream)
  37.                             :    CPatternButtonPopup(inStream)
  38. {
  39. }
  40.  
  41.  
  42. // ---------------------------------------------------------------------------
  43. //        Ñ HandleNewValue
  44. // ---------------------------------------------------------------------------
  45. //    Hook for handling value changes. Called by SetValue.
  46. //    Note that the setting of the new value is done by CPatternButtonPopup::SetValue.
  47. //  Therefore, GetValue() will still return the old value here, so the old value is
  48. //    still available in this method.
  49.  
  50. Boolean
  51. CPatternButtonPopupText::HandleNewValue(Int32 inNewValue)
  52. {
  53.     Str255    str;
  54.     MenuHandle menuh;
  55.     menuh = GetMenu()->GetMacMenuH();
  56.     ::GetMenuItemText ( menuh, inNewValue, str );
  57.     
  58.     SetDescriptor( str );
  59.     return false;
  60. }
  61.  
  62.  
  63. // taken from LGAPopup.cp and then modified
  64. const Int16 gsPopup_ArrowHeight            =     5;        //    Actual height of the arrow
  65. const Int16 gsPopup_ArrowWidth            =     9;        //    Actual width of the arrow at widest
  66. const Int16 gsPopup_ArrowButtonWidth     =     22;        //    Width used in drawing the arrow only
  67. const Int16 gsPopup_ArrowButtonHeight    =     16;        //    Height used for drawing arrow only
  68.  
  69. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  70. //    Ñ    DrawButtonContent
  71. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  72. // copied from CPatternButton::DrawButtonContent()
  73. // comment out check for "IsMouseInFrame()" and always draw the bevel rect
  74.     
  75. void
  76. CPatternButtonPopupText::DrawButtonContent(void)
  77. {
  78.     CGrafPtr thePort;
  79.     ::GetPort(&(GrafPtr)thePort);
  80.     
  81.     Rect theFrame = mCachedButtonFrame;
  82.     Point theAlignment;
  83.     
  84.     CalcOrientationPoint(theAlignment);
  85.     mPatternWorld->Fill(thePort, theFrame, theAlignment);
  86.  
  87.     ::InsetRect(&theFrame, 2, 2);
  88.  
  89.     if (IsActive() && IsEnabled())
  90.         {
  91.         // Ñ Setup a device loop so that we can handle drawing at the correct bit depth
  92.         StDeviceLoop    theLoop ( mCachedButtonFrame );
  93.         Int16            depth;
  94.             
  95.         if (IsTrackInside() || (!IsBehaviourButton() && (mValue == Button_On)))
  96.             {
  97.             while ( theLoop.NextDepth ( depth )) 
  98.                 if ( depth >= 4 )        // don't do anything for black and white
  99.                     {
  100.                     Rect frame = mCachedButtonFrame;
  101.                     ::InsetRect(&frame, 1, 1);
  102.                     UGraphicGizmos::LowerRoundRectColorVolume(frame, 4, 4, UGAAppearance::sGASevenGrayLevels);
  103.                     }
  104.  
  105.             UGAAppearance::DrawGAPopupPressedBevelTint(mCachedButtonFrame);
  106.             }
  107.         else if (IsMouseInFrame())
  108.             {
  109.             UGAAppearance::DrawGAPopupBevelTint(mCachedButtonFrame);
  110.             
  111.             while ( theLoop.NextDepth ( depth )) 
  112.                 if ( depth >= 4 )        // don't do anything for black and white
  113.                     UGraphicGizmos::LowerColorVolume(theFrame, UGAAppearance::sGAHiliteContentTint);
  114.             }
  115.         else // ! (IsMouseInFrame())
  116.             {
  117.             // draw round rect frame
  118.             UGraphicGizmos::BevelTintRoundRect(mCachedButtonFrame, 8, 8, UGAAppearance::sGASevenGrayLevels, false);
  119.             // draw seperator between text and arrow
  120.             UGraphicGizmos::BevelTintLine(mCachedButtonFrame.right - gsPopup_ArrowButtonWidth,
  121.                                           mCachedButtonFrame.top + 1,
  122.                                           mCachedButtonFrame.right - gsPopup_ArrowButtonWidth,
  123.                                           mCachedButtonFrame.bottom - 2,
  124.                                           UGAAppearance::sGAFiveGrayLevels,
  125.                                           false);
  126.                         
  127.             while ( theLoop.NextDepth ( depth )) 
  128.                 if ( depth >= 4 )        // don't do anything for black and white
  129.                     UGraphicGizmos::LowerColorVolume(theFrame, UGAAppearance::sGAHiliteContentTint);
  130.             }
  131.         }
  132. }
  133.  
  134. void
  135. CPatternButtonPopupText::DrawButtonTitle(void)
  136. {
  137.     StColorPenState thePenSaver;
  138.     thePenSaver.Normalize();
  139.  
  140. // only if we're tracking; checking for "Button_On" is bad as mValue is current menuSelection
  141.     if (IsTrackInside())
  142.         ::RGBForeColor(&UGAColorRamp::GetWhiteColor());
  143.  
  144.     UGraphicGizmos::PlaceStringInRect(mTitle, mCachedTitleFrame, teFlushLeft, teCenter);
  145.     
  146.     DrawPopupArrow();
  147. }
  148.  
  149. void
  150. CPatternButtonPopupText::DrawPopupArrow()
  151. {
  152.     Rect theFrame;
  153.     
  154.     CalcLocalFrameRect(theFrame);
  155.     
  156.     Int16 width = theFrame.right - theFrame.left;
  157.     Int16 height = theFrame.bottom - theFrame.top;
  158.     theFrame.top += ((height - gsPopup_ArrowHeight) / 2);
  159.     theFrame.left = theFrame.right - gsPopup_ArrowWidth - 7;
  160.     theFrame.right = theFrame.left + gsPopup_ArrowWidth - 1;
  161.     theFrame.bottom = theFrame.top + gsPopup_ArrowHeight - 1;
  162.  
  163.     // check if we have moved past the right edge of the button
  164.     // if so, adjust it back to the right edge of the button
  165.     if ( theFrame.right > mCachedButtonFrame.right - 4 )
  166.     {
  167.         theFrame.right = mCachedButtonFrame.right - 4;
  168.         theFrame.left = theFrame.right - gsPopup_ArrowWidth - 1;
  169.     }
  170.  
  171.     UGraphicGizmos::DrawPopupArrow(
  172.                                     theFrame,
  173.                                     IsEnabled(),
  174.                                     IsActive(),
  175.                                     IsTrackInside());
  176. }
  177.  
  178.  
  179. #pragma mark -
  180.  
  181. // always call ProcessCommandStatus for popup menus which can change values
  182. void
  183. CPatternButtonPopupText::HandleEnablingPolicy()
  184. {
  185.     LCommander* theTarget        = LCommander::GetTarget();
  186.     MessageT    buttonCommand    = GetValueMessage();
  187.     Boolean     enabled            = false;
  188.     Boolean        usesMark        = false;
  189.     Str255        outName;
  190.     Char16        outMark;
  191.     
  192.     if (!CTargetedUpdateMenuRegistry::UseRegistryToUpdateMenus() ||
  193.             CTargetedUpdateMenuRegistry::CommandInRegistry(buttonCommand))
  194.     {
  195.         if (!IsActive() || !IsVisible())
  196.             return;
  197.             
  198.         if (!theTarget)
  199.             return;
  200.         
  201.         CPatternButtonPopup::HandleEnablingPolicy();
  202.         
  203.         if (buttonCommand)
  204.             theTarget->ProcessCommandStatus(buttonCommand, enabled, usesMark, outMark, outName);
  205.     }
  206. }