home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / PASCAL / TOOLTIP / TOOLTIP.TXT < prev   
Encoding:
Text File  |  1994-10-10  |  7.6 KB  |  164 lines

  1. {******************************************************}
  2. {                                                      }
  3. {   ToolTip unit version 1                             }
  4. {   for Turbo Pascal for Windows and Borland Pascal    }
  5. {   Requires Windows 3.1, ToolBar and ObjectWindows    }
  6. {   Copyright (c) 1994 by Antony Lewis                 }
  7. {                                                      }
  8. {******************************************************}
  9.  
  10.  
  11. {This unit contains a Toolbar object descended from the toolbar object supplied with
  12. Turbo Pascal. It pops up a little tip window when the cursor is held over a tool button
  13. for a specified time. This is a very useful tool to help people use your program, as the
  14. function of toolbar icons is often far from obvious.
  15.  
  16. The toolbar object  loads itself from a custom resource type like the normal toolbar. Here,
  17. however the type is HelpToolBarData which can be edited using Resource Workshop. In
  18. addition to the data supplied in ToolBarData resourced, it also as the tip text associated
  19. with each button.
  20.  
  21. The format of HelpToolBarData is much like the ToolBarData type, except the nul-terminated
  22. string after the command value for each button. For example
  23.  
  24. (You cannot have the comments in an actual resource statement)
  25.  
  26. MyHelpToolbar  HELPTOOLBARDATA
  27. BEGIN
  28.     4             (Total number of buttons and spacers in resource     )
  29.     tbHelp        (bitmap id (here a pascal identifier)                )
  30.     cmHelp        (menu command id of button                           )
  31.     "Help\0"      (Nul-terminated tip text for button                  )
  32.     0             (inserts a space between buttons. You wont need a    )
  33.     8             (tip text for a space                                )
  34.     tbOpen        (Start definition of next button                     )
  35.     cmOpen
  36.     "Open\0"
  37.     tbSave
  38.     cmSave
  39.     "Save\0"
  40.   END
  41.  
  42. A program could create a toolbar from this resource with, for example
  43.  
  44.  MyHelpToolBar := New(PHelpToolbar, Init(@Self, 'MyToolbar', tbHorizontal, 500));
  45.  
  46. The last parameter is the delay time, in milliseconds, before displaying the hint.
  47.  
  48. For a demonstration of the ToolTip unit compile the DEMO.PAS program supplied. The
  49. resource file for this program is the DEMO.RC script. The ToolTip unit assumes the
  50. use of ObjectWindows in the normal way. If you are not using the standard ObjectWindows
  51. method of dealing with messages you may have some problems with this unit.
  52.  
  53.  
  54. The ToolTip unit is distributed as shareware. If you wish to continue using the program
  55. after 30 days evaluation you must register. Registering gives you the right to unlimited
  56. distribution of your program(s) using the ToolTip unit.
  57.  
  58. To register please send 30 US Dollars or 20 Pounds Sterling to
  59.  
  60.    Antony Lewis, 16 Townley Rd, London SE22 8SR, UK
  61.  
  62. giving your name. If you wish to have the full source code for the unit there is an
  63. additional charge of 15 US Dollars or 10 Pounds Sterling, including P&P of the source code on disk,
  64. making a total fee of 45 US Dollars or 30 Pounds.}
  65.  
  66. {Here follows the declaration parts of the source code}
  67. {$X+}
  68. unit ToolTip;
  69. interface
  70. uses Toolbar, WinProcs, WinTypes, OWindows, ODialogs, Objects;
  71.  
  72. Type PHelpToolButton=^THelpToolButton;
  73.      THelpToolButton=Object(TToolButton)
  74.      StartTime:Longint;       {Time mouse moves over button}
  75.      Delay:Word;              {Time over button before showin help}
  76.      HelpText:PChar;          {Pointer to text to display}
  77.      HasHelped:Boolean;       {Doesn't display tip once button is used}
  78.      GlobalMousePos:TPoint;   {Position of the mouse in screen co-ordinates when mouse
  79.                                is over button}
  80.      IsStillOver:Boolean;
  81.      constructor Init(AParent: PWindowsObject; X, Y: Integer;ACommand:
  82.                        Word;BitmapName: PChar;ADelay:Word);
  83.        {As for TToolButton, except the additional ADelay parameter. This should be the
  84.         delay time in milliseconds before displayng the help window}
  85.      destructor Done;virtual;
  86.      procedure EndMouseOver;virtual;
  87.        {Closes the HelpTipWindow if it exists. Sets IsStillOver to False}
  88.      procedure DoMessages;virtual;
  89.        {Processes messaged while mouse is over button.
  90.         Traps WM_LButtonUp, WM_NCMouseMove, and WM_MouseMove before processing}
  91.      procedure CheckTiming;virtual;
  92.        {Calls ShowHelp if Delay time has elapsed}
  93.      function GetHelpTipWindow:PWindow;virtual;
  94.        {By default returns a TTipWindow, with a static control in. GetHelpTipWindow
  95.         calculates width of HelpText and returns TTipWIndow of the appropriate width
  96.         and height. Override this to display a different descendant of TTipWindow. Return
  97.         Nil to not display a tip}
  98.      procedure ShowHelp;virtual;
  99.        {Calls makes window returned by GetHelpTipWindow and shows it. Override to,
  100.         for example, display text on the status line giving more detailed help}
  101.      procedure BeginMouseOver(MousePos:TPoint);virtual;
  102.        {Called when mouse moves over button}
  103.      procedure Read(var S: TStream); virtual;
  104.        {Reads HelpText and Delay}
  105.      procedure Write(var S: TStream); virtual;
  106.        {Writes HelpText and Delay}
  107. end;
  108.  
  109. Type PHelpToolBar=^THelpToolBar;
  110.      THelpToolBar=Object(TToolBar)
  111.      StillOver:Boolean;
  112.      Selected:PHelpToolButton;   {If mouse is over button, points to selected button}
  113.      DelayTime:Word;             {Delay time which all the buttons are set to by default}
  114.      NoHelp:Boolean;             {If tips are diabled}
  115.      HelpTipWindow:PWindow;      {Pointer to the tip window. Nil when not tip showing}
  116.      constructor Init(AParent: PWindowsObject; AName: PChar; Orient: Word;ADelay:Word);
  117.        {As for TToolBar except the ADelay parameter which the help delay for all the buttons}
  118.      constructor Load(var S: TStream);
  119.        {Loads DelayTime and NoHelp, and initialises variables}
  120.      procedure Store(var S: TStream); virtual;
  121.        {Store DelayTime and NoHelp}
  122.      procedure WMMouseMove(var Msg: TMessage);virtual wm_First + wm_MouseMove;
  123.        {Detects when mouse is moved over button and starts timing. Sets GlobalMousePoint
  124.        to the screen-coordinate of the mouse}
  125.      function CreateTool(Num: Integer; Origin: TPoint;Command: Word;
  126.                 BitmapName: PChar): PTool;virtual;
  127.        {Overriden TToolBar methos to create THelpToolButtons}
  128.      procedure ReadResource;virtual;
  129.        {Reads a HELPTOOLBARDATA resource. Sets up the buttons HelpText field from the
  130.        resource. See above for details of the HELPTOOLBARDATA resource type}
  131.      procedure DisableHelp;virtual;    {Enables pop-up help tips}
  132.      procedure EnableHelp;virtual;     {Disables them}
  133. end;
  134.  
  135. {New help tip windows can be descended from the TTipWindow type,
  136. which is basically the same as TWindow except how the Attr field is set up.}
  137. Type PTipWindow=^TTipWindow;
  138.      TTipWindow=object(TWindow)
  139.      constructor init(AParent:PToolbar;MousePos:TPoint;Orient,Width,Height:Word);
  140.      {Sets up the Attr field appropriately depending on the
  141.       orientation of the toolbar and the mouse position.
  142.       Checks if the window rect is on screen, and if not sets the
  143.       Attr field so that it is.
  144.       Override to set the window to pop-up in a different position.
  145.       Sets Attr.Style:=ws_border or ws_popup or ws_disabled}
  146. end;
  147.  
  148.  
  149. const
  150.   RHelpToolbar: TStreamRec = (
  151.     ObjType: 12302;
  152.     VmtLink: Ofs(TypeOf(THelpToolbar)^);
  153.     Load:    @THelpToolbar.Load;
  154.     Store:   @THelpToolbar.Store);
  155.  
  156.  
  157. implementation
  158. uses Win31, Strings;
  159.  
  160. {You can obtain the full source code by paying an additional registration fee
  161.  of 15 US Dollars or 10 Pounds Sterling. See Above}
  162.  
  163.  
  164. end.