home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / OPHPCK.ZIP / HPTEST.PAS next >
Encoding:
Pascal/Delphi Source File  |  1990-10-10  |  10.3 KB  |  303 lines

  1. (*
  2.  This program demonstrates the OPHPICK unit, which provides an HPickList
  3.  object derived from the PickList. HPickList manages a single column of pick
  4.  items and remaps the ccLeft and ccRight (left and right arrow) commands so
  5.  that individual items in the list will scroll horizontally (all at the same
  6.  time). This is useful when the length of each item string exceeds the width
  7.  of the pick window. HPickList supports all features of the PickList object,
  8.  including multiple choice lists, flexwriting, scroll bars, mouse support,
  9.  item searching, protected items, and so on, with the single exception that it
  10.  does not allow lists with more than one column of items.
  11.  
  12.  To work with HPickList, you must write a specialized user string procedure,
  13.  demonstrated by the example below. The procedure is much like the one
  14.  normally used with a PickList, but it is passed an additional parameter,
  15.  HScroll, which indicates the amount of horizontal scrolling. If HScroll is 0,
  16.  no scrolling has occurred and each item is displayed starting with its first
  17.  character. If HScroll is 1, the first column of each string does not appear,
  18.  and so on. It is the string procedure's responsibility to copy the desired
  19.  section of the overall string based on the value of HScroll. Note that if
  20.  flexwriting is activated, the string procedure must take special steps to
  21.  ensure that the flex characters are inserted correctly when HScroll is
  22.  non-zero. The example below also illustrates this when you define the
  23.  DemoFlex conditional.
  24.  
  25.  Also note that when the string procedure is called with Mode=pkSearch, you'll
  26.  probably want to return the unscrolled version of the string regardless of
  27.  the value of HScroll. The example also shows how to do this. The
  28.  GetLastChoiceString method of PickList calls the string procedure in pkSearch
  29.  mode, so GetLastChoiceString will return the full string regardless of
  30.  scrolling only if you make the kind of check shown below.
  31.  
  32.  An HPickList is initialized by calling one of its constructors -- Init,
  33.  InitCustom, InitAbstract, InitDeluxe, or InitAbstractDeluxe. The "abstract"
  34.  constructors should be used only when an object derived from HPickList has
  35.  overridden the HItemString method of HPickList. The other constructors are
  36.  used to specify a user-written string procedure, just like the constructors
  37.  for a PickList. The InitDeluxe constructor provides the most versatile
  38.  control over instantiation of an HPickList:
  39.  
  40.     constructor InitDeluxe(X1, Y1, X2, Y2 : Byte;
  41.                            var Colors : ColorSet;
  42.                            Options : LongInt;
  43.                            MaxItemWidth : Word;
  44.                            NumItems : Word;
  45.                            StringProc : hpStringProc;
  46.                            CommandHandler : pkGenlProc;
  47.                            PickOptions : Word);
  48.  
  49.  With two exceptions, the InitDeluxe parameters are used exactly like those
  50.  for a PickList. MaxItemWidth specifies the maximum string string from which
  51.  the string procedure is returning subsections. This length controls the
  52.  amount of horizontal scrolling that the HPickList will allow: just enough to
  53.  allow the rightmost edge of the longest string to appear within the window.
  54.  HPickList automatically deals with the situation that occurs when
  55.  MaxItemWidth is less than the window width; in this case, no horizontal
  56.  scrolling will be necessary.
  57.  
  58.  The other difference is that the HPickList string procedure is of type
  59.  hpStringProc:
  60.  
  61.     hpStringProc =
  62.       procedure (Item : Word;
  63.                  Mode : pkMode;
  64.                  HScroll : Word;
  65.                  var IType : pkItemType;
  66.                  var IString : String;
  67.                  HPickPtr : HPickListPtr);
  68.  
  69.  This procedure type is almost identical to the PickList's string procedure.
  70.  As usual, the string procedure must be global and compiled under the FAR
  71.  model. The HScroll parameter specifies the amount of horizontal scrolling
  72.  currently active. Alternatively, the application may derive a new object
  73.  based on HPickList and override the HItemString virtual method.
  74.  
  75.  InitDeluxe and the other HPickList constructors will fail only if the
  76.  PickList constructor they call fails.
  77.  
  78.  A left selection string (specified by calling SetSelectMarker) always appears
  79.  at the left edge of the window regardless of scrolling, but the right
  80.  selection string appears only when the rightmost edge of the item string
  81.  scrolls into view. The example illustrates this effect when you define
  82.  DemoMulti below.
  83.  
  84.  OPHPICK provides stream support with the Load and Store methods and the
  85.  HPickListStream registration procedure. Note that its stream constants are
  86.  stored in OPHPICK rather than in OPROOT. Activate the DemoStreams define
  87.  below to see the streams support.
  88.  
  89.  OPHPICK also provides access methods for reading the current amount of
  90.  horizontal scrolling (GetCurrentCol) and for reading and changing the
  91.  specified maximum item width (GetMaxWidth and SetMaxWidth).
  92.  
  93.  OPHPICK works by overriding PickList's ItemString virtual method and by
  94.  taking over several of the PickList's "primitive move action procedures." See
  95.  the OPHPICK source code for more information.
  96.  
  97.  Written by TurboPower Software, 10/10/90.
  98. *)
  99.  
  100. {$R-,S-,F-}
  101.  
  102. {$I OPDEFINE.INC}
  103.  
  104. {.$DEFINE DemoFlex}           {Activate to demonstrate flexwriting}
  105. {.$DEFINE DemoMulti}          {Activate to demonstrate multiple choice}
  106. {.$DEFINE DemoStreams}        {Activate to demonstrate streams}
  107.  
  108. program HpTest;
  109.   {-Test OpHpick unit}
  110.  
  111. uses
  112.   opInline,
  113.   opString,
  114.   opRoot,
  115.   opCrt,
  116.   {$IFDEF UseMouse}
  117.   opMouse,
  118.   {$ENDIF}
  119.   opFrame,
  120.   opWindow,
  121.   opCmd,
  122.   {$IFDEF UseDrag}
  123.   opDrag,
  124.   {$ENDIF}
  125.   opPick,
  126.   opHpick;
  127.  
  128. const
  129.   NumItems = 200;
  130.   MaxItemWidth = 57;
  131.   ItemAttr : FlexAttrs = ($07, $0F, $01, $70);
  132.  
  133. var
  134.   P : HPickList;
  135.   MAttr : Word;
  136.   {$IFDEF DemoStreams}
  137.   S : BufIdStream;
  138.   Status : Word;
  139.   {$ENDIF}
  140.  
  141. {$F+}
  142. procedure SProc(Item : Word; Mode : pkMode; HScroll : Word;
  143.                 var IType : pkItemType; var IString : String;
  144.                 HPickPtr : HPickListPtr);
  145. var
  146.   NumStr : string[8];
  147. begin
  148.   {Exit quickly if just checking mode}
  149.   if Mode = pkGetType then
  150.     Exit;
  151.  
  152.   {Use a simple item string for the example program}
  153.   Str(Item:3, NumStr);
  154.   IString := NumStr+'. ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  155.  
  156.   {Return the unscrolled string if searching}
  157.   if Mode = pkSearch then
  158.     Exit;
  159.  
  160.   {Take a substring based on the amount of scrolling specified}
  161.   IString := Copy(IString, HScroll+1, 255);
  162.  
  163.   {$IFDEF DemoFlex}
  164.   {Insert flex characters carefully!}
  165.   if Mode = pkDisplay then
  166.     if HScroll < 4 then begin
  167.       Insert(^A, IString, 5-HScroll);
  168.       Insert(^A, IString, 1);
  169.     end;
  170.   {$ENDIF}
  171. end;
  172. {$F-}
  173.  
  174. {$IFDEF DemoStreams}
  175. procedure RegisterTypes(var S : IdStream);
  176.   {-Register types for this h-pick list stream}
  177. begin
  178.   S.RegisterHier(HPickListStream);
  179.   {$IFDEF DemoMulti}
  180.   S.RegisterPointer(ptPickMultipleChoice, @MultipleChoice);
  181.   {$ELSE}
  182.   S.RegisterPointer(ptPickSingleChoice, @SingleChoice);
  183.   {$ENDIF}
  184.   S.RegisterPointer(1000, @SProc);
  185. end;
  186. {$ENDIF}
  187.  
  188. begin
  189.   {$IFDEF UseMouse}
  190.   if MouseInstalled then begin
  191.     {Enable mouse support}
  192.     with DefaultColorSet do
  193.       MAttr := (ColorMono(MouseColor, MouseMono) shl 8);
  194.     SoftMouseCursor($0000,  MAttr or $04);
  195.     PickCommands.cpOptionsOn(cpEnableMouse);
  196.  
  197.     {$IFDEF UseDrag}
  198.     PickCommands.SetMouseCursor(MAttr or $04, MAttr or $12, MAttr or $1D);
  199.     {$ENDIF}
  200.     ShowMouse;
  201.   end;
  202.   {$ENDIF}
  203.  
  204.   {$IFDEF DemoStreams}
  205.   if ParamCount = 0 then
  206.   {$ENDIF}
  207.     begin
  208.       if not p.Init(10, 5, 31, 20, MaxItemWidth, NumItems, SProc,
  209.                     {$IFDEF DemoMulti}
  210.                     MultipleChoice
  211.                     {$ELSE}
  212.                     SingleChoice
  213.                     {$ENDIF}
  214.                     ) then begin
  215.         WriteLn('error initializing');
  216.         Halt;
  217.       end;
  218.       p.wOptionsOn(wBordered);
  219.       p.SetSizeLimits(4, 3, ScreenWidth, ScreenHeight);
  220.  
  221.       {$IFDEF DemoMulti}
  222.       p.SetSelectMarker(#16, #17);
  223.       {Add horizontal scrolling space for selection markers}
  224.       p.SetMaxWidth(MaxItemWidth+2);
  225.       {$ENDIF}
  226.  
  227.       {$IFDEF DemoFlex}
  228.       p.SetPickFlex(pkNormal, False, ItemAttr, ItemAttr);
  229.       {$ENDIF}
  230.  
  231.       {$IFDEF UseScrollBars}
  232.       {add scroll bars}
  233.       p.wFrame.AddCustomScrollBar(frBB, 0, MaxLongInt, 1, 1, #178, #176, DefaultColorSet);
  234.       p.wFrame.AddCustomScrollBar(frRR, 0, MaxLongInt, 1, 1, #178, #176, DefaultColorSet);
  235.       {$ENDIF}
  236.  
  237.       {$IFDEF UseDrag}
  238.       {add hot spot for zooming}
  239.       p.wFrame.AddCustomHeader(#24, frTR, -1, 0,
  240.                                DefaultColorSet.HeaderColor,
  241.                                DefaultColorSet.HeaderMono);
  242.       p.wFrame.AddHotRegion(frTR, ZoomHotCode, -1, 0, 1, 1);
  243.  
  244.       {add hot spot for moving}
  245.       p.wFrame.AddHotBar(frTT, MoveHotCode);
  246.  
  247.       {add hot spot for resizing}
  248.       p.wFrame.AddCustomHeader(#240, frBR, 0, 0,
  249.                                DefaultColorSet.FrameColor,
  250.                                DefaultColorSet.FrameMono);
  251.       p.wFrame.AddHotRegion(frBR, ResizeHotCode, 0, 0, 1, 1);
  252.       {$ENDIF}
  253.     end;
  254.  
  255.   {$IFDEF DemoStreams}
  256.   if ParamCount = 0 then begin
  257.     {Create stream file and store the list}
  258.     S.Init('HPTEST.STM', SCreate, 4096);
  259.     RegisterTypes(S);
  260.     S.Put(p);
  261.     Status := S.GetStatus;
  262.     if Status <> 0 then begin
  263.       WriteLn('Store error: ', Status);
  264.       Halt(1);
  265.     end;
  266.     S.Done;
  267.  
  268.     {Dispose of the list}
  269.     P.Done;
  270.   end;
  271.  
  272.   {Reopen stream file and reload list}
  273.   S.Init('HPTEST.STM', SOpen, 4096);
  274.   RegisterTypes(S);
  275.   S.Get(P);
  276.   Status := S.GetStatus;
  277.   if Status <> 0 then begin
  278.     WriteLn('Load error: ', Status);
  279.     WriteLn('InitStatus: ', InitStatus);
  280.     Halt(3);
  281.   end;
  282.   S.Done;
  283.   {$ENDIF}
  284.  
  285.   repeat
  286.     p.Process;
  287.     {$IFDEF UseDrag}
  288.     if p.GetLastCommand = ccMouseDown then
  289.        if HandleMousePress(p) = hsNone then ;
  290.     {$ENDIF}
  291.   until p.GetLastCommand in [ccSelect, ccQuit, ccError];
  292.  
  293.   p.Erase;
  294.  
  295.   HideMouse;
  296.   GoToXy(1, 20);
  297.   WriteLn('last command: ', p.getlastcommand);
  298.   WriteLn('last choice:  ', p.getlastchoice);
  299.   WriteLn('last string:  ', p.getlastchoicestring);
  300.  
  301.   p.Done;
  302. end.
  303.