home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / CToolTipAttachment.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.4 KB  |  175 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. #pragma once
  20.  
  21. #include <LPane.h>
  22. #include <LString.h>
  23. #include "CMouseDispatcher.h"
  24.  
  25. class CToolTipPane;
  26.  
  27. const CommandT msg_HideTooltip = 1000;        // cmd sent to hide the tooltip
  28.  
  29.  
  30. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  31. //    CToolTipAttachment
  32. //    
  33. //    This attachment can be attached to any pane from within Constructor.  Tool
  34. //    Tips require a CMouseDispatcher object be present in order to get time.
  35. //
  36. //    This attachment reads in a resource ID of a PPob which contains the
  37. //    definition of a CToolTipPane (or subclass thereof).
  38. //
  39. //    You should not need to subclass this class unless you want to modify the
  40. //    behaviour of the mouse tracking mechanism.  If you want to change the
  41. //    contents or appearance of the tips, you should subclass the CToolTipPane
  42. //    class (see notes below).
  43. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  44.  
  45. class CToolTipAttachment : public CMouseTrackAttachment
  46. {
  47.     public:
  48.         enum { class_ID = 'TTaT' };
  49.         
  50.         static void            Enable(Boolean inEnableTips);
  51.  
  52.                             CToolTipAttachment(LStream* inStream);    
  53.                             CToolTipAttachment(UInt32 inDelayTicks, ResIDT inPaneResID);    
  54.         virtual                ~CToolTipAttachment();
  55.  
  56.         virtual    void        NoteTipDied(CToolTipPane* inTip);
  57.         
  58.     protected:
  59.     
  60.         virtual void        ExecuteSelf(
  61.                                     MessageT            inMessage,
  62.                                     void*                ioParam);
  63.     
  64.         virtual void        MouseEnter(
  65.                                     Point                inPortPt,
  66.                                     const EventRecord&    inMacEvent);
  67.  
  68.         virtual void        MouseWithin(
  69.                                     Point                inPortPt,
  70.                                     const EventRecord&    inMacEvent);
  71.  
  72.         virtual void        MouseLeave(void);
  73.  
  74.         virtual    void        ShowToolTip(const EventRecord&    inMacEvent);
  75.         virtual    void        HideToolTip(void);
  76.         
  77.         Boolean                IsDelayElapsed(Uint32 inTicks) const;
  78.         Boolean                IsToolTipActive(void) const;
  79.         Boolean                IsTipCancellingEvent(const EventRecord& inMacEvent) const;
  80.         void                ResetTriggerInterval(Uint32 inWithTicks);
  81.  
  82.         virtual void        CalcTipText(
  83.                                     LWindow*                inOwningWindow,
  84.                                     LPane*                    inOwningPane,
  85.                                     const EventRecord&        inMacEvent,
  86.                                     StringPtr                outTipText);
  87.  
  88.         ResIDT                mTipPaneResID;        
  89.         Uint32                mEnterTicks;
  90.         Uint32                mDelayTicks;
  91.  
  92.         static CToolTipPane* sActiveTip;
  93.         static Boolean         sTipsEnabled;
  94. };
  95.  
  96. inline Boolean CToolTipAttachment::IsDelayElapsed(Uint32 inTicks) const
  97.     {    return ((inTicks - mEnterTicks) > mDelayTicks);        }
  98. inline Boolean CToolTipAttachment::IsToolTipActive(void) const
  99.     {    return (sActiveTip != NULL);                        }
  100. inline void CToolTipAttachment::ResetTriggerInterval(Uint32 inWithTicks)
  101.     {    mEnterTicks = inWithTicks;                            }
  102. inline void    CToolTipAttachment::Enable(Boolean inEnableTips)
  103.     {     sTipsEnabled = inEnableTips;                         }
  104.  
  105.  
  106. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  107. //    CToolTipPane
  108. //
  109. //    This is your basic little tip blurb.  If you want to change the appearance
  110. //    or content calculation of a Tool Tip, subclass this class and not the
  111. //    controlling attachment.
  112. //
  113. //    Instances of this class are reanimated when the controlling attachment
  114. //    needs to display one.
  115. //
  116. //    NOTE: Unless you want to see this pane get resized and positioned in its
  117. //    owning window, you better make sure that the visible flag in the resource
  118. //    definition is off.
  119. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  120.  
  121. class CToolTipPane : public LPane
  122. {
  123.     public:
  124.         enum { class_ID = 'TTpn' };
  125.         
  126.                             CToolTipPane(LStream* inStream);
  127.         virtual                ~CToolTipPane();
  128.     
  129.         virtual void        SetParent(CToolTipAttachment* inParent);
  130.                             
  131.         virtual void        CalcFrameWithRespectTo(
  132.                                     LWindow*                inOwningWindow,
  133.                                     LPane*                    inOwningPane,
  134.                                     const EventRecord&        inMacEvent,
  135.                                     Rect&                     outTipFrame);
  136.     
  137.         virtual    void         CalcTipText(
  138.                                     LWindow*                inOwningWindow,
  139.                                     LPane*                    inOwningPane,
  140.                                     const EventRecord&        inMacEvent,
  141.                                     StringPtr                outTipText);
  142.  
  143.         virtual void        SetDescriptor(ConstStringPtr inDescriptor);
  144.  
  145.     protected:
  146.  
  147.         virtual    void        ForceInPortFrame(
  148.                                     LWindow*                inOwningWindow,
  149.                                     Rect&                    ioTipFrame);
  150.  
  151.         virtual    void        DrawSelf(void);
  152.     
  153.         ResIDT                mTipTraitsID;
  154.         TString<Str255>        mTip;
  155.         CToolTipAttachment*    mParent;
  156. };
  157.  
  158.  
  159. class CSharedToolTipAttachment : public CToolTipAttachment
  160. {
  161.     public:
  162.         enum { class_ID = 'STat' };
  163.  
  164.                             CSharedToolTipAttachment(LStream* inStream);
  165.     protected:
  166.         virtual void        CalcTipText(
  167.                                     LWindow*                inOwningWindow,
  168.                                     LPane*                    inOwningPane,
  169.                                     const EventRecord&        inMacEvent,
  170.                                     StringPtr                outTipText);
  171.  
  172.         ResIDT                mStringListID;
  173.         UInt16                mStringIndex;
  174. };
  175.