{******************************************************}
{                                                      }
{   ToolTip unit version 1                             }
{   for Turbo Pascal for Windows and Borland Pascal    }
{   Requires Windows 3.1, ToolBar and ObjectWindows    }
{   Copyright (c) 1994 by Antony Lewis                 }
{                                                      }
{******************************************************}


{This unit contains a Toolbar object descended from the toolbar object supplied with
Turbo Pascal. It pops up a little tip window when the cursor is held over a tool button
for a specified time. This is a very useful tool to help people use your program, as the
function of toolbar icons is often far from obvious.

The toolbar object  loads itself from a custom resource type like the normal toolbar. Here,
however the type is HelpToolBarData which can be edited using Resource Workshop. In
addition to the data supplied in ToolBarData resourced, it also as the tip text associated
with each button.

The format of HelpToolBarData is much like the ToolBarData type, except the nul-terminated
string after the command value for each button. For example

(You cannot have the comments in an actual resource statement)

MyHelpToolbar  HELPTOOLBARDATA
BEGIN
    4             (Total number of buttons and spacers in resource     )
    tbHelp        (bitmap id (here a pascal identifier)                )
    cmHelp        (menu command id of button                           )
    "Help\0"      (Nul-terminated tip text for button                  )
    0             (inserts a space between buttons. You wont need a    )
    8             (tip text for a space                                )
    tbOpen        (Start definition of next button                     )
    cmOpen
    "Open\0"
    tbSave
    cmSave
    "Save\0"
  END

A program could create a toolbar from this resource with, for example

 MyHelpToolBar := New(PHelpToolbar, Init(@Self, 'MyToolbar', tbHorizontal, 500));

The last parameter is the delay time, in milliseconds, before displaying the hint.

For a demonstration of the ToolTip unit compile the DEMO.PAS program supplied. The
resource file for this program is the DEMO.RC script. The ToolTip unit assumes the
use of ObjectWindows in the normal way. If you are not using the standard ObjectWindows
method of dealing with messages you may have some problems with this unit.


The ToolTip unit is distributed as shareware. If you wish to continue using the program
after 30 days evaluation you must register. Registering gives you the right to unlimited
distribution of your program(s) using the ToolTip unit.

To register please send 30 US Dollars or 20 Pounds Sterling to

   Antony Lewis, 16 Townley Rd, London SE22 8SR, UK

giving your name. If you wish to have the full source code for the unit there is an
additional charge of 15 US Dollars or 10 Pounds Sterling, including P&P of the source code on disk,
making a total fee of 45 US Dollars or 30 Pounds.}

{Here follows the declaration parts of the source code}
{$X+}
unit ToolTip;
interface
uses Toolbar, WinProcs, WinTypes, OWindows, ODialogs, Objects;

Type PHelpToolButton=^THelpToolButton;
     THelpToolButton=Object(TToolButton)
     StartTime:Longint;       {Time mouse moves over button}
     Delay:Word;              {Time over button before showin help}
     HelpText:PChar;          {Pointer to text to display}
     HasHelped:Boolean;       {Doesn't display tip once button is used}
     GlobalMousePos:TPoint;   {Position of the mouse in screen co-ordinates when mouse
                               is over button}
     IsStillOver:Boolean;
     constructor Init(AParent: PWindowsObject; X, Y: Integer;ACommand:
                       Word;BitmapName: PChar;ADelay:Word);
       {As for TToolButton, except the additional ADelay parameter. This should be the
        delay time in milliseconds before displayng the help window}
     destructor Done;virtual;
     procedure EndMouseOver;virtual;
       {Closes the HelpTipWindow if it exists. Sets IsStillOver to False}
     procedure DoMessages;virtual;
       {Processes messaged while mouse is over button.
        Traps WM_LButtonUp, WM_NCMouseMove, and WM_MouseMove before processing}
     procedure CheckTiming;virtual;
       {Calls ShowHelp if Delay time has elapsed}
     function GetHelpTipWindow:PWindow;virtual;
       {By default returns a TTipWindow, with a static control in. GetHelpTipWindow
        calculates width of HelpText and returns TTipWIndow of the appropriate width
        and height. Override this to display a different descendant of TTipWindow. Return
        Nil to not display a tip}
     procedure ShowHelp;virtual;
       {Calls makes window returned by GetHelpTipWindow and shows it. Override to,
        for example, display text on the status line giving more detailed help}
     procedure BeginMouseOver(MousePos:TPoint);virtual;
       {Called when mouse moves over button}
     procedure Read(var S: TStream); virtual;
       {Reads HelpText and Delay}
     procedure Write(var S: TStream); virtual;
       {Writes HelpText and Delay}
end;

Type PHelpToolBar=^THelpToolBar;
     THelpToolBar=Object(TToolBar)
     StillOver:Boolean;
     Selected:PHelpToolButton;   {If mouse is over button, points to selected button}
     DelayTime:Word;             {Delay time which all the buttons are set to by default}
     NoHelp:Boolean;             {If tips are diabled}
     HelpTipWindow:PWindow;      {Pointer to the tip window. Nil when not tip showing}
     constructor Init(AParent: PWindowsObject; AName: PChar; Orient: Word;ADelay:Word);
       {As for TToolBar except the ADelay parameter which the help delay for all the buttons}
     constructor Load(var S: TStream);
       {Loads DelayTime and NoHelp, and initialises variables}
     procedure Store(var S: TStream); virtual;
       {Store DelayTime and NoHelp}
     procedure WMMouseMove(var Msg: TMessage);virtual wm_First + wm_MouseMove;
       {Detects when mouse is moved over button and starts timing. Sets GlobalMousePoint
       to the screen-coordinate of the mouse}
     function CreateTool(Num: Integer; Origin: TPoint;Command: Word;
                BitmapName: PChar): PTool;virtual;
       {Overriden TToolBar methos to create THelpToolButtons}
     procedure ReadResource;virtual;
       {Reads a HELPTOOLBARDATA resource. Sets up the buttons HelpText field from the
       resource. See above for details of the HELPTOOLBARDATA resource type}
     procedure DisableHelp;virtual;    {Enables pop-up help tips}
     procedure EnableHelp;virtual;     {Disables them}
end;

{New help tip windows can be descended from the TTipWindow type,
which is basically the same as TWindow except how the Attr field is set up.}
Type PTipWindow=^TTipWindow;
     TTipWindow=object(TWindow)
     constructor init(AParent:PToolbar;MousePos:TPoint;Orient,Width,Height:Word);
     {Sets up the Attr field appropriately depending on the
      orientation of the toolbar and the mouse position.
      Checks if the window rect is on screen, and if not sets the
      Attr field so that it is.
      Override to set the window to pop-up in a different position.
      Sets Attr.Style:=ws_border or ws_popup or ws_disabled}
end;


const
  RHelpToolbar: TStreamRec = (
    ObjType: 12302;
    VmtLink: Ofs(TypeOf(THelpToolbar)^);
    Load:    @THelpToolbar.Load;
    Store:   @THelpToolbar.Store);


implementation
uses Win31, Strings;

{You can obtain the full source code by paying an additional registration fee
 of 15 US Dollars or 10 Pounds Sterling. See Above}


end.