This commit is contained in:
pinkerton%netscape.com 1998-10-06 03:57:25 +00:00
Родитель 351524239e
Коммит cb23214345
2 изменённых файлов: 0 добавлений и 190 удалений

Просмотреть файл

@ -1,83 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
//
// Implementation for a pair of classes that provided a tooltip that takes its text dynamically
// based on the content of a pane and the mouse location. The CDynamicTooltipPane asks its
// parent view what string it should display depending on the current mouse location.
// The CDynamicTootipMixin class is mixed into the parent view to give the the correct
// interface.
//
#include "CDynamicTooltips.h"
//
// CalcFrameWithRespectTo
//
// Figures out how big the tip needs to be and where it should be located in the port for
// the tip text. We are guaranteed that |mTip| (the string holding the text) has already
// been correctly set.
//
void
CDynamicTooltipPane :: CalcFrameWithRespectTo( LWindow* inOwningWindow, LPane* inOwningPane,
const EventRecord& inMacEvent,
Rect& outTipFrame)
{
const short kXPadding = 5;
const short kYPadding = 3;
StTextState theTextSaver;
UTextTraits::SetPortTextTraits(mTipTraitsID);
FontInfo theFontInfo;
::GetFontInfo(&theFontInfo);
Int16 theTextHeight = theFontInfo.ascent + theFontInfo.descent + theFontInfo.leading + (2 * 2);
Int16 theTextWidth = ::StringWidth(mTip) + (2 * ::CharWidth(char_Space));
Point theLocalPoint = inMacEvent.where;
GlobalToPortPoint(theLocalPoint);
Rect theWindowFrame;
inOwningPane->CalcPortFrameRect(theWindowFrame);
outTipFrame.left = theLocalPoint.h + kXPadding;
outTipFrame.top = theLocalPoint.v + kYPadding;
outTipFrame.right = outTipFrame.left + theTextWidth + kXPadding;
outTipFrame.bottom = outTipFrame.top + theTextHeight + kYPadding;
ForceInPortFrame(inOwningWindow, outTipFrame);
} // CDynamicTooltipPane :: CalcFrameWithRespectTo
//
// CalcTipText
//
// Asks the parent pane (which has the interface provided by the CDynamicTooltipMixin class)
// for the tooltip at the current mouse location
//
void
CDynamicTooltipPane :: CalcTipText( LWindow* /* inOwningWindow */, LPane* inOwningPane,
const EventRecord& inMacEvent, StringPtr outTipText)
{
CDynamicTooltipMixin* parent = dynamic_cast<CDynamicTooltipMixin*>(inOwningPane);
Assert_(parent != NULL);
parent->FindTooltipForMouseLocation ( inMacEvent, outTipText );
} // CDynamicTooltipPane :: CalcTipText

Просмотреть файл

@ -1,107 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
//
// Interface for a pair of classes that provided a tooltip that takes its text dynamically
// based on the content of a pane and the mouse location. The CDynamicTooltipPane asks its
// parent view what string it should display depending on the current mouse location.
// The CDynamicTootipMixin class is mixed into the parent view to give the the correct
// interface.
//
#pragma once
#include "CTooltipAttachment.h"
//
// class CDynamicTooltipPane
//
// Handles querying the parent view to get the appropriate text based on the mouse location.
// Works with the CDynamicTooltipMixin class, which the parent view MUST mixin for this
// to work.
//
// To use this class instead of the normal tooltip pane, include the PPob id of an
// instantiation of this class (located in Tooltips.cnst) in the appropriate
// CTooltipAttachment's properties where it asks for the mTipPaneResID.
//
// NOTE: This will not _crash_ when the parent is not a CDynamicTooltipMixin, but will
// assert so you know you're using it incorrectly.
//
class CDynamicTooltipPane : public CToolTipPane
{
public:
enum { class_ID = 'DyTT' } ;
CDynamicTooltipPane ( LStream* inStream ) : CToolTipPane(inStream) { };
virtual ~CDynamicTooltipPane ( ) { } ;
virtual void CalcFrameWithRespectTo(
LWindow* inOwningWindow,
LPane* inOwningPane,
const EventRecord& inMacEvent,
Rect& outTipFrame);
virtual void CalcTipText(
LWindow* inOwningWindow,
LPane* inOwningPane,
const EventRecord& inMacEvent,
StringPtr outTipText);
}; // CDynamicTooltipPane
//
// class CDynamicTooltipMixin
//
// Mix into your view/pane and override the appropriate methods to return the correct
// information to the query for dynamic tooltip text from the CDynamicTooltipPane.
// All methods are pure virtual so you must override them if you intend to use this class.
//
// There is no data in this class, as it only presents an interface.
//
// As a side note, in addition to implementing the FindTooltipforMouseLocation()
// method, you will probably want to override MouseWithin() and track when the
// mouse enters/leaves a "hot" area that gets a tooltip. This is quite important
// if you want to hide the tooltip when the mouse moves away from that spot. The
// code to do this in MouseWithin() would look something like:
//
// if ( newArea != oldArea ) {
// ... update your own roll-over feedback as necessary ...
// ExecuteAttachments ( msg_HideTooltip, nil );
// }
//
// The CTooltipAttachment responds to this message by hiding the tooltip, thereby
// resetting it for the next "hot spot" the user may move the cursor to within
// the pane.
//
class CDynamicTooltipMixin
{
public:
virtual void FindTooltipForMouseLocation ( const EventRecord& inMacEvent,
StringPtr outTip ) = 0;
private:
// make these private so you can't instantiate one of these standalone
CDynamicTooltipMixin ( ) { } ;
~CDynamicTooltipMixin ( ) { } ;
}; // CDynamicTooltipMixin