home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CDynamicTooltips.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  3.0 KB  |  84 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. // Implementation for a pair of classes that provided a tooltip that takes its text dynamically
  21. // based on the content of a pane and the mouse location. The CDynamicTooltipPane asks its 
  22. // parent view what string it should display  depending on the current mouse location.
  23. // The CDynamicTootipMixin class is mixed into the parent view to give the the correct 
  24. // interface.
  25. //
  26.  
  27. #include "CDynamicTooltips.h"
  28.  
  29.  
  30. //
  31. // CalcFrameWithRespectTo
  32. //
  33. // Figures out how big the tip needs to be and where it should be located in the port for
  34. // the tip text. We are guaranteed that |mTip| (the string holding the text) has already
  35. // been correctly set.
  36. //
  37. void
  38. CDynamicTooltipPane :: CalcFrameWithRespectTo( LWindow* inOwningWindow, LPane*    inOwningPane,
  39.                                                 const EventRecord& inMacEvent, 
  40.                                                 Rect& outTipFrame)
  41. {
  42.     const short kXPadding = 5;
  43.     const short kYPadding = 3;
  44.     
  45.     StTextState theTextSaver;
  46.     UTextTraits::SetPortTextTraits(mTipTraitsID);
  47.     
  48.     FontInfo theFontInfo;
  49.     ::GetFontInfo(&theFontInfo);
  50.     Int16 theTextHeight    = theFontInfo.ascent + theFontInfo.descent + theFontInfo.leading + (2 * 2);
  51.     Int16 theTextWidth = ::StringWidth(mTip) + (2 * ::CharWidth(char_Space));
  52.  
  53.     Point theLocalPoint = inMacEvent.where;
  54.     GlobalToPortPoint(theLocalPoint);
  55.  
  56.     Rect theWindowFrame;
  57.     inOwningPane->CalcPortFrameRect(theWindowFrame);
  58.  
  59.     outTipFrame.left = theLocalPoint.h + kXPadding;
  60.     outTipFrame.top = theLocalPoint.v + kYPadding;
  61.     outTipFrame.right = outTipFrame.left + theTextWidth + kXPadding; 
  62.     outTipFrame.bottom = outTipFrame.top + theTextHeight + kYPadding;
  63.  
  64.     ForceInPortFrame(inOwningWindow, outTipFrame);
  65.  
  66. } // CDynamicTooltipPane :: CalcFrameWithRespectTo
  67.  
  68.  
  69. //
  70. // CalcTipText
  71. //
  72. // Asks the parent pane (which has the interface provided by the CDynamicTooltipMixin class)
  73. // for the tooltip at the current mouse location
  74. //
  75. void 
  76. CDynamicTooltipPane :: CalcTipText( LWindow* /* inOwningWindow */, LPane* inOwningPane,
  77.                                     const EventRecord& inMacEvent, StringPtr outTipText)
  78. {
  79.     CDynamicTooltipMixin* parent = dynamic_cast<CDynamicTooltipMixin*>(inOwningPane);
  80.     Assert_(parent != NULL);
  81.     parent->FindTooltipForMouseLocation ( inMacEvent, outTipText );
  82.  
  83. } // CDynamicTooltipPane :: CalcTipText
  84.