home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / CTargetFramer.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  4.2 KB  |  154 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. // Author: John R. McMullen
  20.  
  21.  
  22. #include "CTargetFramer.h"
  23.  
  24. #include "UGraphicGizmos.h"
  25.  
  26. #include <LCommander.h>
  27. #include <LPane.h>
  28.  
  29. static const kSideInsetPixels = 1;
  30. static const kTopAndBottomInsetPixels = 1;
  31.  
  32. //-----------------------------------
  33. CTargetFramer::CTargetFramer()
  34. //-----------------------------------
  35. :    LAttachment(msg_AnyMessage, /* inExecuteHost = */ true)
  36. ,    mPane(nil)
  37. ,    mCommander(nil)
  38. ,    mDrawWithHilite(false)
  39. {
  40.  
  41. } // CTargetFramer::CTargetFramer
  42.  
  43. //-----------------------------------
  44. CTargetFramer::CTargetFramer(LStream* inStream)
  45. //-----------------------------------
  46. :    LAttachment(inStream)
  47. ,    mPane(nil)
  48. ,    mCommander(nil)
  49. {
  50.     SetMessage(msg_AnyMessage);
  51.     SetExecuteHost(true);
  52.     SetOwnerHost(LAttachable::GetDefaultAttachable());
  53. } // CTargetFramer::CTargetFramer
  54.  
  55. //-----------------------------------
  56. CTargetFramer::~CTargetFramer()
  57. //-----------------------------------
  58. {
  59. } // CTargetFramer::~CTargetFramer
  60.  
  61. //-----------------------------------
  62. void CTargetFramer::SetOwnerHost(LAttachable* inAttachable)
  63. //-----------------------------------
  64. {
  65.     mCommander = dynamic_cast<LCommander*>(inAttachable);
  66.     Assert_(mCommander);
  67.     mPane = dynamic_cast<LPane*>(inAttachable);
  68.     Assert_(mPane);
  69.     mDrawWithHilite = mCommander->IsTarget();
  70.     Inherited::SetOwnerHost(inAttachable);
  71. } // CTargetFramer::SetOwnerHost
  72.  
  73. //-----------------------------------
  74. void CTargetFramer::CalcBorderRegion(RgnHandle ioBorderRgn)
  75. //-----------------------------------
  76. {
  77.     // compute the border region
  78.     StRegion frameRgn;
  79.     Rect frameRect;
  80.     mPane->CalcLocalFrameRect(frameRect);
  81.     ::RectRgn(frameRgn, &frameRect);
  82.     ::InsetRect(&frameRect, kSideInsetPixels, kTopAndBottomInsetPixels);
  83.     ::RectRgn(ioBorderRgn, &frameRect);
  84.     ::DiffRgn(frameRgn, ioBorderRgn, ioBorderRgn);
  85. } //  CTargetFramer::CalcBorderRegion
  86.  
  87. //-----------------------------------
  88. void CTargetFramer::InvertBorder()
  89. //-----------------------------------
  90. {
  91.     StRegion borderRgn;
  92.     StColorPenState penState;
  93.     penState.Normalize();
  94.  
  95.     CalcBorderRegion(borderRgn);
  96.  
  97.     // Fiddle with the hilite color so that our inversion does not
  98.     // interfere with the inversion already done by the pane
  99.     RGBColor savedHiliteColor;
  100.     ::LMGetHiliteRGB(&savedHiliteColor);
  101.     RGBColor darkTingeColor, ignoredLightColor;
  102.     UGraphicGizmos::CalcWindowTingeColors(
  103.         mPane->GetMacPort(), ignoredLightColor, darkTingeColor);
  104.     ::HiliteColor(&darkTingeColor);
  105.     UDrawingUtils::SetHiliteModeOn();
  106.     ::InvertRgn(borderRgn);
  107.     ::HiliteColor(&savedHiliteColor);
  108. } //  CTargetFramer::InvertBorder
  109.  
  110. //-----------------------------------
  111. void CTargetFramer::ExecuteSelf(MessageT inMessage, void* ioParam)
  112. //-----------------------------------
  113. {
  114.     switch (inMessage)
  115.     {
  116.         case msg_BecomingTarget:
  117.         case msg_ResigningTarget:
  118.             mPane->FocusDraw();
  119.             // FALL THROUGH!
  120.         case msg_DrawOrPrint:
  121.         case msg_DrawSelfDone:
  122.         {
  123.             switch (inMessage)
  124.             {
  125.                 case msg_BecomingTarget:
  126.                 case msg_ResigningTarget:
  127.                 {
  128.                     mDrawWithHilite = !mDrawWithHilite;
  129.                     InvertBorder();
  130.                     break;
  131.                 }
  132.                 case msg_DrawOrPrint:
  133.                 {
  134.                     // Called before the pane does DrawSelf
  135.                     StRegion borderRgn;
  136.                     CalcBorderRegion(borderRgn);
  137.                     ::EraseRgn(borderRgn);
  138.                     break;
  139.                 }
  140.                 case msg_DrawSelfDone:
  141.                 {
  142.                     // Called after the pane does DrawSelf
  143.                     if (mDrawWithHilite)
  144.                         InvertBorder();
  145.                     break;
  146.                 }
  147.             } // switch
  148.             break;
  149.         }
  150.         default:
  151.             return;
  152.     }
  153. } // CTargetFramer::ExecuteSelf
  154.