home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / OPBONUS.ZIP / WFIELD.LZH / WFIELD2.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-04-04  |  8.4 KB  |  305 lines

  1. {$V-}
  2.  
  3. (*
  4.  
  5.    WFIELD2
  6.    -------
  7.    This program is an example of a directory list (DirList) embedded within a
  8.    data entry screen. The effect is somewhat like that of a "dialog box."
  9.    Points worth noting:
  10.  
  11.      1) The pre-edit routine prevents the directory list from being activated
  12.         when there are no files to be selected. That can't happen in this
  13.         program, because the diShowDrives option is used, but it could happen
  14.         if diShowDrives were not in use.
  15.  
  16.      2) The post-edit routine manages the interaction between the two fields
  17.         that make up the entry screen. When a file is selected with the
  18.         DirList, it loads the filename into the variable associated with the
  19.         string field. If the user presses <Enter> (ccSelect) on the string
  20.         field, it checks to see if the string entered is a real or potential
  21.         filename. If so, it tells the entry screen to exit. If not, it checks
  22.         to see if the user modified the field; if he did, the mask for the
  23.         DirList is set to match what was entered.
  24.  
  25.      3) By deactivating the efAllowEscape option before calling AddWindowField,
  26.         we tell OPENTRY to treat the ccQuit command (<Esc>) as equivalent
  27.         to ccNextField when it is issued within the DirList.
  28.  
  29.      4) By activating the sefSwitchCommands option before calling
  30.         AddWindowField, we tell OPENTRY to make the DirList use the same
  31.         CommandProcessor as the EntryScreen. This allows commands such as
  32.         ccTab, which normally have no meaning in a DirList, to produce the
  33.         same effects that they have when issued within the EntryScreen itself.
  34.  
  35.      5) Notice how the wAltFrame option lets us "highlight" the DirList when
  36.         it becomes active: the active frame has special headers; the inactive
  37.         frame does not.
  38.  
  39.      6) The wNoCoversBuffer option is used for the DirList field to limit
  40.         memory usage.
  41.  
  42. *)
  43.  
  44. program WFIELD2;
  45.  
  46. {$I OPDEFINE.INC}
  47.  
  48. uses
  49.   Dos,
  50.   OpInline,
  51.   OpString,
  52.   OpDos,
  53.   OpRoot,
  54.   OpCrt,
  55.   {$IFDEF UseMouse}
  56.   OpMouse,
  57.   {$ENDIF}
  58.   OpAbsFld,
  59.   OpCmd,
  60.   OpField,
  61.   OpFrame,
  62.   OpWindow,
  63.   OpPick,
  64.   OpDir,
  65.   OpSelect,
  66.   OpEntry;
  67.  
  68.   {$IFDEF UseMouse}
  69. const
  70.   MouseChar  : Char = #04;
  71.   {$ENDIF}
  72.  
  73. {Color set used by entry screen}
  74. const
  75.   EsColors : ColorSet = (
  76.     TextColor       : $1E;      TextMono        : $0F;
  77.     CtrlColor       : $1E;      CtrlMono        : $0F;
  78.     FrameColor      : $1F;      FrameMono       : $0F;
  79.     HeaderColor     : $3F;      HeaderMono      : $70;
  80.     ShadowColor     : $0B;      ShadowMono      : $0F;
  81.     HighlightColor  : $4F;      HighlightMono   : $70;
  82.     PromptColor     : $1B;      PromptMono      : $07;
  83.     SelPromptColor  : $1F;      SelPromptMono   : $0F;
  84.     ProPromptColor  : $1B;      ProPromptMono   : $07;
  85.     FieldColor      : $1E;      FieldMono       : $0F;
  86.     SelFieldColor   : $3E;      SelFieldMono    : $70;
  87.     ProFieldColor   : $17;      ProFieldMono    : $07;
  88.     ScrollBarColor  : $1B;      ScrollBarMono   : $07;
  89.     SliderColor     : $1B;      SliderMono      : $0F;
  90.     HotSpotColor    : $30;      HotSpotMono     : $70;
  91.     BlockColor      : $3E;      BlockMono       : $0F;
  92.     MarkerColor     : $3F;      MarkerMono      : $70;
  93.     DelimColor      : $1E;      DelimMono       : $0F;
  94.     SelDelimColor   : $31;      SelDelimMono    : $0F;
  95.     ProDelimColor   : $1E;      ProDelimMono    : $0F;
  96.     SelItemColor    : $3E;      SelItemMono     : $70;
  97.     ProItemColor    : $17;      ProItemMono     : $07;
  98.     HighItemColor   : $1F;      HighItemMono    : $0F;
  99.     AltItemColor    : $1F;      AltItemMono     : $0F;
  100.     AltSelItemColor : $3F;      AltSelItemMono  : $70;
  101.     FlexAHelpColor  : $1F;      FlexAHelpMono   : $0F;
  102.     FlexBHelpColor  : $1F;      FlexBHelpMono   : $0F;
  103.     FlexCHelpColor  : $1B;      FlexCHelpMono   : $70;
  104.     UnselXrefColor  : $1E;      UnselXrefMono   : $08;
  105.     SelXrefColor    : $3F;      SelXrefMono     : $70;
  106.     MouseColor      : $4F;      MouseMono       : $70
  107.   );
  108.  
  109. {Entry field constants}
  110. const
  111.   idPathMask             = 0;
  112.   idDirWin               = 1;
  113.  
  114. type
  115.   UserRecord =
  116.     record
  117.       PathMask             : string[64];
  118.     end;
  119. var
  120.   ES      : EntryScreen;
  121.   UR      : UserRecord;
  122.   Status  : Word;
  123.   DL      : DirList;
  124.   AllDone : Boolean;
  125.  
  126. {$F+}
  127. procedure PreEdit(ESP : EntryScreenPtr);
  128.   {-Called just before a field is edited}
  129. begin
  130.   with ESP^ do
  131.     if GetCurrentID = idDirWin then
  132.       if DL.GetMatchingFileCount = 0 then
  133.         SetNextField(idPathMask);
  134. end;
  135.  
  136. procedure PostEdit(ESP : EntryScreenPtr);
  137.   {-Called just after a field has been edited}
  138.  
  139.   function AcceptFile(var S : string) : Boolean;
  140.   begin
  141.     S := FExpand(S);
  142.     if (S[Length(S)] = '\') or IsDirectory(S) then begin
  143.       S := AddBackSlash(S)+'*.*';
  144.       AcceptFile := False;
  145.     end
  146.     else if ExistFile(S) then
  147.       AcceptFile := True
  148.     else
  149.       AcceptFile := (S <> '') and (Pos('*', S) = 0) and (Pos('?', S) = 0);
  150.   end;
  151.  
  152. begin
  153.   with ESP^ do
  154.     case GetCurrentID of
  155.       idPathMask :
  156.         if (GetLastCommand = ccSelect) and AcceptFile(UR.PathMask) then
  157.           SetLastCommand(ccDone)
  158.         else if CurrentFieldModified then begin
  159.           DL.SetMask(FExpand(UR.PathMask), 0);
  160.           DL.PreLoadDirList;
  161.           Draw;
  162.         end;
  163.       idDirWin :
  164.         if GetLastCommand = ccSelect then begin
  165.           UR.PathMask := DL.GetSelectedPath;
  166.           DrawField(idPathMask);
  167.         end;
  168.     end;
  169. end;
  170. {$F-}
  171.  
  172. function InitEntryScreen : Word;
  173.   {-Initialize entry screen generated by MAKESCRN}
  174. const
  175.   WinOptions = wBordered+wClear+wUserContents;
  176. begin
  177.   with ES do begin
  178.     if not InitCustom(20, 6, 57, 18, EsColors, WinOptions) then begin
  179.       InitEntryScreen := InitStatus;
  180.       Exit;
  181.     end;
  182.  
  183.     wFrame.AddShadow(shBR, shOverWrite);
  184.  
  185.     SetWrapMode(WrapAtEdges);
  186.  
  187.     SetPreEditProc(PreEdit);
  188.     SetPostEditProc(PostEdit);
  189.  
  190.     esFieldOptionsOn(efClearFirstChar);
  191.  
  192.   {idPathMask:}
  193.     AddSimpleStringField(
  194.       'File:', 1, 3,
  195.       'X', 1, 9, 28, 64,
  196.       1, UR.PathMask);
  197.  
  198.   {idDirWin}
  199.     esFieldOptionsOff(efAllowEscape);
  200.     esSecFieldOptionsOn(sefSwitchCommands);
  201.     AddWindowField(
  202.       '', 2, 3,
  203.       2, 3,
  204.       2, DL);
  205.  
  206.     InitEntryScreen := RawError;
  207.   end;
  208. end;
  209.  
  210. function InitDirList : Word;
  211.   {-Initialize directory list}
  212. const
  213.   WinOptions = wBordered+wAltFrame+wClear+wUserContents+wNoCoversBuffer;
  214. begin
  215.   with DL do begin
  216.     if not InitCustom(
  217.       23, 8, 54, 17, EsColors, WinOptions,
  218.       20000, PickSnaking, SingleFile) then begin
  219.         InitDirList := InitStatus;
  220.         Exit;
  221.       end;
  222.  
  223.     AddMaskHeader(True, 1, Width, heTC);
  224.  
  225.     AddMoreHeader(' || ', heBR, #27, #26, '', 2, 3, 0);
  226.  
  227.     aFrame.SetFrameAttr($1B, $07);
  228.  
  229.     SetPadSize(1, 0);
  230.     SetSortOrder(SortDirName);
  231.  
  232.     diOptionsOn(diShowDrives);
  233.     SetMask('*.*', Directory);
  234.     PreLoadDirList;
  235.  
  236.     InitDirList := RawError;
  237.   end;
  238. end;
  239.  
  240. begin
  241.   ClrScr;
  242.  
  243.   DefWindowFrame := SglWindowFrame;
  244.  
  245.   {initialize user record}
  246.   UR.PathMask := '*.*';
  247.  
  248.   {initialize directory list}
  249.   Status := InitDirList;
  250.   if Status <> 0 then begin
  251.     WriteLn('Error initializing DirList: ', Status);
  252.     Halt(1);
  253.   end;
  254.  
  255.   {initialize entry screen}
  256.   Status := InitEntryScreen;
  257.   if Status <> 0 then begin
  258.     WriteLn('Error initializing entry screen: ', Status);
  259.     Halt(1);
  260.   end;
  261.  
  262.   {$IFDEF UseMouse}
  263.   if MouseInstalled then
  264.     with EsColors do begin
  265.       {activate mouse cursor}
  266.       SoftMouseCursor($0000, (ColorMono(MouseColor, MouseMono) shl 8)+
  267.                              Byte(MouseChar));
  268.       ShowMouse;
  269.  
  270.       {enable mouse support}
  271.       EntryCommands.cpOptionsOn(cpEnableMouse);
  272.       PickCommands.cpOptionsOn(cpEnableMouse);
  273.     end;
  274.   {$ENDIF}
  275.  
  276.   AllDone := False;
  277.   repeat
  278.     ES.Process;
  279.     case ES.GetLastCommand of
  280.       ccDone :
  281.         AllDone := True;
  282.       ccError, ccQuit :
  283.         begin
  284.           AllDone := True;
  285.           UR.PathMask := '';
  286.         end;
  287.     end;
  288.   until AllDone;
  289.  
  290.   {$IFDEF UseMouse}
  291.   HideMouse;
  292.   {$ENDIF}
  293.  
  294.   ES.Erase;
  295.  
  296.   {show exit command and selection}
  297.   ClrScr;
  298.   WriteLn('Exit command = ', ES.GetLastCommand);
  299.   if UR.PathMask <> '' then
  300.     WriteLn('Selection    = ', UR.PathMask);
  301.  
  302.   {dispose of the parent *and* its children}
  303.   ES.Done;
  304. end.
  305.