home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / o / opsprd.zip / TSPREAD.PAS < prev    next >
Pascal/Delphi Source File  |  1992-01-10  |  4KB  |  171 lines

  1. {$R-,S-,I-}
  2. {$I OPDEFINE.INC}
  3.  
  4. {$IFDEF UseMouse}
  5.   {$IFDEF UseDrag}
  6.     {$DEFINE UsingDrag}
  7.   {$ELSE}
  8.     {$DEFINE UseDragAnyway} {<--- define this to force use of OPDRAG}
  9.     {$IFDEF UseDragAnyway}
  10.       {$DEFINE UsingDrag}
  11.     {$ENDIF}
  12.   {$ENDIF}
  13. {$ENDIF}
  14.  
  15. program TSpread;
  16.   {-Test SpreadList object}
  17. uses
  18.   OpCrt,
  19.   OpString,
  20.   OpRoot,
  21.   OpCmd,
  22.   {$IFDEF UseMouse}
  23.   OpMouse,
  24.   {$ENDIF}
  25.   OpFrame,
  26.   OpWindow,
  27.   {$IFDEF UsingDrag}
  28.   OpDrag,
  29.   {$ENDIF}
  30.   OpPick,
  31.   OpSpread;
  32.  
  33. const
  34.   SpreadSize = 50;  {SpreadSheet is SpreadSize*SpreadSize}
  35.   ItemWidth = 8;    {Each item is ItemWidth characters}
  36.                     {Last character used for vertical divider}
  37.  
  38. var
  39.   SL : SpreadList;
  40.   {$IFDEF UseDragAnyway}
  41.   PickCommands : DragProcessor;
  42.   {$ENDIF}
  43.   {$IFDEF UsingDrag}
  44.   ZoomHeaderNum : byte;
  45.   HotCode : byte;
  46.   {$ENDIF}
  47.  
  48. {$F+}
  49. procedure SpreadItem(Item : Word;
  50.                      Mode : pkMode;
  51.                      var IType : pkItemType;
  52.                      var IString : String;
  53.                      PickPtr : PickListPtr);
  54. var
  55.   Row : Word;
  56.   Col : Word;
  57. begin
  58.   with SpreadListPtr(PickPtr)^ do begin
  59.     Row := GetItemRow(Item);
  60.     Col := GetItemCol(Item);
  61.     IString := Long2Str(Row)+','+Long2Str(Col);
  62.   end;
  63. end;
  64. {$F-}
  65.  
  66. procedure InitCommands;
  67. begin
  68. {$IFDEF UsingDrag}
  69.   {$IFDEF UseDragAnyway}
  70.   {Initialize the new picklist dragprocessor}
  71.   if not PickCommands.Init(@PickKeySet, PickKeyMax) then
  72.     Halt;
  73.   {$ENDIF}
  74.   {See-through mouse cursor}
  75.   PickCommands.SetScreenMask($FFFF);
  76.   PickCommands.SetMouseCursor($7700, $7700, $7700);
  77. {$ELSE}
  78.   {Enable the mouse}
  79.   PickCommands.cpOptionsOn(cpEnableMouse);
  80.   SoftMouseCursor($0000,
  81.                  (Word(ColorMono(DefaultColorSet.MouseColor,
  82.                                  DefaultColorSet.MouseMono)) shl 8)
  83.                   or $04);
  84. {$ENDIF}
  85. end;
  86.  
  87. procedure InitSpreadSheet;
  88. begin
  89.   SL.InitDeluxe(5, 3, 36, 20,
  90.                 DefaultColorSet,
  91.                 DefWindowOptions or wBordered,
  92.                 ItemWidth, SpreadSize, SpreadSize,
  93.                 SpreadItem, SingleChoice,
  94.                 DefPickOptions);
  95.   if InitStatus <> 0 then begin
  96.     WriteLn('Error initializing SpreadList');
  97.     Halt;
  98.   end;
  99.  
  100. {$IFDEF UseDragAnyway}
  101.   {attach the DragProcessor to the PickList}
  102.   SL.SetCommandProcessor(PickCommands);
  103. {$ENDIF}
  104.  
  105.   SL.EnableDividers(#209, #179, NoFrameChar);
  106.   SL.ResizeWindow(-1, 0);
  107.   SL.wFrame.AddScrollBar(frBB, 0, 0, DefaultColorSet);
  108.   SL.wFrame.AddScrollBar(frRR, 0, 0, DefaultColorSet);
  109.  
  110. {$IFDEF UsingDrag}
  111.   SL.wFrame.AddCustomHeader(#24, frtr, -1, 0,
  112.                            DefaultColorSet.HeaderColor,
  113.                            DefaultColorSet.HeaderMono);
  114.   SL.wFrame.AddHotRegion(frTR, ZoomHotCode, -1, 0, 1, 1);
  115.   ZoomHeaderNum := SL.wFrame.GetLastHeaderIndex;
  116.   SL.wFrame.AddHotBar(frTT, MoveHotCode);
  117.   SL.wFrame.AddCustomHeader(#240, frbr, 0, 0,
  118.                            DefaultColorSet.FrameColor,
  119.                            DefaultColorSet.FrameMono);
  120.   SL.wFrame.AddHotRegion(frBR, ResizeHotCode, 0, 0, 1, 1);
  121.   {limit the sizeability for demo purposes}
  122.   SL.SetSizeLimits(30, 4, ScreenWidth, ScreenHeight);
  123. {$ELSE}
  124.   {scrolling by line is too slow without dragging}
  125.   SL.pkOptionsOn(pkMousePage);
  126. {$ENDIF}
  127.  
  128.   {Surround each element with spaces}
  129.   SL.SetPadSize(1, 1);
  130. end;
  131.  
  132. begin
  133. {$IFDEF UseMouse}
  134. {$IFDEF UsingDrag}
  135.   if not MouseInstalled then begin
  136.     WriteLn('Boring without a mouse');
  137.     Halt;
  138.   end;
  139. {$ENDIF}
  140. {$ENDIF}
  141.  
  142.   {initialize the screen}
  143.   TextChar := #177;
  144.   ClrScr;
  145.  
  146.   {Initialize the command processor}
  147.   InitCommands;
  148.  
  149.   {Initialize the SpreadList object}
  150.   InitSpreadSheet;
  151.  
  152.   {Set the initial highlight to [20, 20]}
  153.   SL.SetInitialChoice(SL.GetItemNum(20, 20));
  154.  
  155.   {Process it}
  156.   repeat
  157.     SL.Process;
  158.     {$IFDEF UsingDrag}
  159.     case SL.GetLastCommand of
  160.       ccMouseDown : if HandleMousePress(SL) = ZoomHotCode then
  161.                       if SL.IsZoomed then
  162.                         SL.ChangeHeader(ZoomHeaderNum, #18)
  163.                       else
  164.                         SL.ChangeHeader(ZoomHeaderNum, #24);
  165.     end;
  166.     {$ENDIF}
  167.   until SL.GetLastCommand in [ccQuit, ccError];
  168.   SL.Erase;
  169.   SL.Done;
  170. end.
  171.