From 8a85601fbb8e7a7b717ccca07ec84407d554593d Mon Sep 17 00:00:00 2001 From: "pinkerton%netscape.com" Date: Tue, 25 Aug 1998 00:03:19 +0000 Subject: [PATCH] Landing code from 4.5. Allows tooltips to stay around between areas that want them, instead of hiding each time. git-svn-id: svn://10.0.0.236/trunk@8419 18797224-902f-48f8-a5cc-f745e15eee43 --- .../mac/UserInterface/CToolTipAttachment.cp | 106 ++++++++++++------ .../mac/UserInterface/CToolTipAttachment.h | 20 ++-- 2 files changed, 84 insertions(+), 42 deletions(-) diff --git a/mozilla/lib/mac/UserInterface/CToolTipAttachment.cp b/mozilla/lib/mac/UserInterface/CToolTipAttachment.cp index 701b8b356b7..1f49ce00d81 100644 --- a/mozilla/lib/mac/UserInterface/CToolTipAttachment.cp +++ b/mozilla/lib/mac/UserInterface/CToolTipAttachment.cp @@ -38,6 +38,7 @@ CToolTipPane* CToolTipAttachment::sActiveTip = NULL; // dispatch and reset the interval there if necessary. const UInt32 ToolTipsTicks_Indefinite = 0xFFFFFFFF; +const UInt32 ToolTipsTicks_AutoRemoveAfter = 3600; // ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ // ₯ CToolTipAttachment @@ -114,7 +115,11 @@ void CToolTipAttachment::ExecuteSelf( else if ( inMessage == msg_HideTooltip ) HideToolTip(); else + { + if (sActiveTip && inMessage == msg_MouseWithin) + ((SMouseTrackParms*)ioParam)->paneOfAttachment = sActiveTip; CMouseTrackAttachment::ExecuteSelf(inMessage, ioParam); + } } // ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ @@ -127,7 +132,7 @@ void CToolTipAttachment::MouseEnter( Point /* inPortPt */, const EventRecord& /* inMacEvent */) { - if (!mOwningPane || !mOwningPane->IsActive() || !mOwningPane->IsEnabled()) + if (!EnsureOwningPane()) return; ResetTriggerInterval(::LMGetTicks()); @@ -141,10 +146,10 @@ void CToolTipAttachment::MouseEnter( // ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ void CToolTipAttachment::MouseWithin( - Point /* inPortPt */, + Point inPortPt, const EventRecord& inMacEvent) { - if (!mOwningPane || !mOwningPane->IsActive() || !mOwningPane->IsEnabled()) + if (!EnsureOwningPane()) return; if (!sTipsEnabled) @@ -160,8 +165,17 @@ void CToolTipAttachment::MouseWithin( // If the tip is active and the corresponding event is one that should // cancel the tip, kill it. - else if (IsToolTipActive() && IsTipCancellingEvent(inMacEvent)) - HideToolTip(); + else if (IsToolTipActive()) + { + if (IsTipCancelingEvent(inMacEvent) + || ::LMGetTicks() - mEnterTicks > ToolTipsTicks_AutoRemoveAfter) + HideToolTip(); + else if (sActiveTip->WantsToCancel(inPortPt)) + { + HideToolTip(); + ShowToolTip(inMacEvent); // in the new location + } + } // If the tip is not active and the trigger interval has elapsed // then we need to show the new tip. @@ -173,23 +187,25 @@ void CToolTipAttachment::MouseWithin( // ₯ MouseLeave // ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ -void CToolTipAttachment::MouseLeave(void) +void CToolTipAttachment::MouseLeave() { - if (!mOwningPane || !mOwningPane->IsActive() || !mOwningPane->IsEnabled()) + if (!EnsureOwningPane()) return; HideToolTip(); } // ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ -// ₯ IsTipCancellingEvent +// ₯ IsTipCancelingEvent // ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ -Boolean CToolTipAttachment::IsTipCancellingEvent(const EventRecord& inMacEvent) const +Boolean CToolTipAttachment::IsTipCancelingEvent(const EventRecord& inMacEvent) const { - Boolean bShouldCancel = ((inMacEvent.what != nullEvent) && - (inMacEvent.what != updateEvt) && - ((inMacEvent.what != osEvt) || ((inMacEvent.message & osEvtMessageMask) != (mouseMovedMessage << 24)))); + Boolean bShouldCancel = (inMacEvent.what != nullEvent && + inMacEvent.what != updateEvt && + (inMacEvent.what != osEvt + || (inMacEvent.message & osEvtMessageMask) + != (mouseMovedMessage << 24))); return bShouldCancel; } @@ -199,11 +215,10 @@ Boolean CToolTipAttachment::IsTipCancellingEvent(const EventRecord& inMacEvent) void CToolTipAttachment::CalcTipText( LWindow* inOwningWindow, - LPane* inOwningPane, const EventRecord& inMacEvent, StringPtr outTipText) { - sActiveTip->CalcTipText(inOwningWindow, inOwningPane, inMacEvent, outTipText); + sActiveTip->CalcTipText(inOwningWindow, inMacEvent, outTipText); } // ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ @@ -227,6 +242,7 @@ void CToolTipAttachment::ShowToolTip(const EventRecord& inMacEvent) sActiveTip = dynamic_cast(UReanimator::CreateView(mTipPaneResID, theWindow, theWindow)); ThrowIfNULL_(sActiveTip); sActiveTip->SetParent(this); + sActiveTip->SetOwningPane(mOwningPane); // Calculate the tip text first because the size and positioning rely on it. // The practice of having the tip pane calculate the text and then have that @@ -236,18 +252,30 @@ void CToolTipAttachment::ShowToolTip(const EventRecord& inMacEvent) // // If no text is returned, abort instead of showing an empty tooltip Str255 theTipText; - this->CalcTipText(theWindow, mOwningPane, inMacEvent, theTipText); - if ( !theTipText[0] ) - throw (0); - sActiveTip->SetDescriptor(theTipText); - + this->CalcTipText(theWindow, inMacEvent, theTipText); Rect theTipPortFrame; - theWindow->FocusDraw(); - sActiveTip->CalcFrameWithRespectTo(theWindow, mOwningPane, inMacEvent, theTipPortFrame); - - sActiveTip->ResizeFrameTo(RectWidth(theTipPortFrame), RectHeight(theTipPortFrame), false); - sActiveTip->PlaceInSuperFrameAt(theTipPortFrame.left, theTipPortFrame.top, false); - sActiveTip->Show(); + if ( theTipText[0] ) + { + sActiveTip->SetDescriptor(theTipText); + + theWindow->FocusDraw(); + sActiveTip->CalcFrameWithRespectTo(theWindow, inMacEvent, theTipPortFrame); + // Returning a zero-width rectangle is another way that the tip pane can + // say "don't show me". + if (RectWidth(theTipPortFrame) == 0) + theTipText[0] = 0; + } + if ( theTipText[0] ) + { + sActiveTip->ResizeFrameTo(RectWidth(theTipPortFrame), RectHeight(theTipPortFrame), false); + sActiveTip->PlaceInSuperFrameAt(theTipPortFrame.left, theTipPortFrame.top, false); + sActiveTip->Show(); + } + else + { + delete sActiveTip; + sActiveTip = NULL; + } } catch(...) { @@ -260,7 +288,7 @@ void CToolTipAttachment::ShowToolTip(const EventRecord& inMacEvent) // ₯ HideToolTip // ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ -void CToolTipAttachment::HideToolTip(void) +void CToolTipAttachment::HideToolTip() { // calc the tip's port rect if (IsToolTipActive()) @@ -283,9 +311,10 @@ void CToolTipAttachment::HideToolTip(void) CToolTipPane::CToolTipPane(LStream* inStream) : LPane(inStream) + , mOwningPane(nil) + , mParent(nil) { *inStream >> mTipTraitsID; - mParent = NULL; } // ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ @@ -307,13 +336,21 @@ void CToolTipPane::SetParent(CToolTipAttachment* inParent) mParent = inParent; } +// ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ +// ₯ SetOwningPane +// ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ + +void CToolTipPane::SetOwningPane(LPane* inOwningPane) +{ + mOwningPane = inOwningPane; +} + // ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ // ₯ CalcFrameWithRespectTo // ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ void CToolTipPane::CalcFrameWithRespectTo( LWindow* inOwningWindow, - LPane* inOwningPane, const EventRecord& /* inMacEvent */, Rect& outPortFrame) { @@ -328,7 +365,7 @@ void CToolTipPane::CalcFrameWithRespectTo( inOwningWindow->FocusDraw(); Rect theOwningPortFrame; - inOwningPane->CalcPortFrameRect(theOwningPortFrame); + mOwningPane->CalcPortFrameRect(theOwningPortFrame); outPortFrame.left = ((theOwningPortFrame.left + theOwningPortFrame.right) >> 1) - (theTextWidth >> 1); outPortFrame.top = theOwningPortFrame.bottom + 3; @@ -349,11 +386,10 @@ void CToolTipPane::CalcFrameWithRespectTo( void CToolTipPane::CalcTipText( LWindow* /* inOwningWindow */, - LPane* inOwningPane, const EventRecord& /* inMacEvent */, StringPtr outTipText) { - inOwningPane->GetDescriptor(outTipText); + mOwningPane->GetDescriptor(outTipText); } // ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ @@ -409,7 +445,7 @@ void CToolTipPane::SetDescriptor(ConstStringPtr inDescriptor) // override this method. // ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ -void CToolTipPane::DrawSelf(void) +void CToolTipPane::DrawSelf() { StColorPenState thePenSaver; thePenSaver.Normalize(); @@ -443,6 +479,11 @@ void CToolTipPane::DrawSelf(void) UGraphicGizmos::CenterStringInRect(mTip, theFrame); } +Boolean CToolTipPane::WantsToCancel(Point inMouseLocal) +{ + return false; +} + // ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ // ₯ CSharedToolTipAttachment // @@ -460,7 +501,6 @@ CSharedToolTipAttachment::CSharedToolTipAttachment(LStream* inStream) void CSharedToolTipAttachment::CalcTipText( LWindow* /* inOwningWindow */, - LPane* /* inOwningPane */, const EventRecord& /* inMacEvent */, StringPtr outTipText) { diff --git a/mozilla/lib/mac/UserInterface/CToolTipAttachment.h b/mozilla/lib/mac/UserInterface/CToolTipAttachment.h index 4266381bbad..0ee6a65a4e1 100644 --- a/mozilla/lib/mac/UserInterface/CToolTipAttachment.h +++ b/mozilla/lib/mac/UserInterface/CToolTipAttachment.h @@ -19,8 +19,9 @@ #pragma once #include -#include #include "CMouseDispatcher.h" +#include "PascalString.h" + class CToolTipPane; @@ -76,12 +77,11 @@ class CToolTipAttachment : public CMouseTrackAttachment Boolean IsDelayElapsed(Uint32 inTicks) const; Boolean IsToolTipActive(void) const; - Boolean IsTipCancellingEvent(const EventRecord& inMacEvent) const; + Boolean IsTipCancelingEvent(const EventRecord& inMacEvent) const; void ResetTriggerInterval(Uint32 inWithTicks); virtual void CalcTipText( LWindow* inOwningWindow, - LPane* inOwningPane, const EventRecord& inMacEvent, StringPtr outTipText); @@ -126,21 +126,23 @@ class CToolTipPane : public LPane CToolTipPane(LStream* inStream); virtual ~CToolTipPane(); - virtual void SetParent(CToolTipAttachment* inParent); + virtual void SetParent(CToolTipAttachment* inParent); + + virtual void SetOwningPane(LPane* inOwningPane); virtual void CalcFrameWithRespectTo( LWindow* inOwningWindow, - LPane* inOwningPane, const EventRecord& inMacEvent, Rect& outTipFrame); virtual void CalcTipText( LWindow* inOwningWindow, - LPane* inOwningPane, const EventRecord& inMacEvent, StringPtr outTipText); - virtual void SetDescriptor(ConstStringPtr inDescriptor); + virtual void SetDescriptor(ConstStringPtr inDescriptor); + + virtual Boolean WantsToCancel(Point inMouseLocal); protected: @@ -151,8 +153,9 @@ class CToolTipPane : public LPane virtual void DrawSelf(void); ResIDT mTipTraitsID; - TString mTip; + CStr255 mTip; // I hate that this needs to be a CStr255 CToolTipAttachment* mParent; + LPane* mOwningPane; }; @@ -165,7 +168,6 @@ class CSharedToolTipAttachment : public CToolTipAttachment protected: virtual void CalcTipText( LWindow* inOwningWindow, - LPane* inOwningPane, const EventRecord& inMacEvent, StringPtr outTipText);