home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Snippets / PNL Libraries / MyStandardFile.p < prev    next >
Encoding:
Text File  |  1997-03-06  |  6.7 KB  |  255 lines  |  [TEXT/CWIE]

  1. unit MyStandardFile;
  2.  
  3. interface
  4.  
  5.     uses
  6.         StandardFile;
  7.  
  8.     type
  9.         MySFReply = record
  10.                 Rgood: boolean;
  11.                 Rfolder: boolean;
  12.                 RfType: OSType;
  13.                 RvRefNum: integer;
  14.                 RdirID: longint;
  15.                 RfName: Str63;
  16.             end;
  17.  
  18.     function MFSPt: Point;
  19.     procedure GetFile (ffilter: Ptr; numTypes: integer; typeList: SFTypeList; var reply: MySFReply);
  20.     procedure GetFile1 (t: OSType; var reply: MySFReply);
  21. {    procedure GetFolder (ffilter: Ptr; numTypes: integer; typeList: SFTypeList; id: integer; var reply: MySFReply);}
  22. { NOTE: GetFolder must be passed a Dialog ID with Button 11 being a folder button }
  23. { NOTE: reply.copy should be interpreted as reply.folder }
  24.     procedure PutFile (str, origName: Str255; var reply: MySFreply);
  25.     procedure PutFolder (str, origName: Str255; id: integer; var reply: MySFreply);
  26. { NOTE: PutFolder must be passed a Dialog ID with Button 9 being a folder button }
  27. { NOTE: reply.copy should be interpreted as reply.folder }
  28.     procedure SetSFFile (wdrn: integer; dirID: longint);
  29.     procedure SegmentStandardFile;
  30.  
  31. implementation
  32.  
  33.     uses
  34.         MyTypes, MyUtils, MySystemGlobals, MyFileSystemUtils, MyButtons;
  35.  
  36.  {$S StandardFile}
  37.     procedure SegmentStandardFile;
  38.     begin
  39.     end;
  40.  
  41.     procedure SetSFFile (wdrn: integer; dirID: longint);
  42.         var
  43.             oe: OSErr;
  44.             vrn: integer;
  45.             procID: longint;
  46.     begin
  47.         if dirID = 0 then begin
  48.             oe := GetWDInfo(wdrn, vrn, dirID, procID);
  49.         end else begin
  50.             vrn := wdrn;
  51.         end;
  52.         integerP(SFSaveDiskA)^ := -vrn;
  53.         longintP(CurDirStoreA)^ := dirID;
  54.     end;
  55.  
  56.     function MFSPt: Point;
  57.         var
  58.             pt: Point;
  59.     begin
  60.         pt.v := 40;
  61.         pt.h := 40;
  62.         MFSPt := pt;
  63.     end;
  64.  
  65.     procedure SetStdReply (var reply: MySFReply; stdReply: StandardFileReply);
  66.     begin
  67.         with reply do begin
  68.             Rgood := stdReply.sfGood;
  69.             Rfolder := ord(stdReply.sfIsFolder) <> 0;        { Argghhh!  Bloody Apple and there C booleans! }
  70.             RfType := stdReply.sfType;
  71.             RvRefNum := stdReply.sfFile.vRefNum;
  72.             RdirID := stdReply.sfFile.parID;
  73.             RfName := stdReply.sfFile.name;
  74.         end;
  75.     end;
  76.  
  77.     procedure SetOldReply (var reply: MySFReply; oldReply: SFReply);
  78.         var
  79.             junk: OSErr;
  80.     begin
  81.         with reply do begin
  82.             Rgood := oldReply.good;
  83.             Rfolder := oldReply.copy;
  84.             RfType := oldReply.fType;
  85.             junk := GetDirID(oldReply.vRefNum, RvRefNum, RdirID);
  86.             RfName := oldReply.fName;
  87.         end;
  88.     end;
  89.  
  90.     procedure GetFile (ffilter: Ptr; numTypes: integer; typeList: SFTypeList; var reply: MySFReply);
  91.         var
  92.             stdReply: StandardFileReply;
  93.             oldReply: SFReply;
  94.     begin
  95.         with reply do
  96.             if has_NewStandardFile then begin
  97.                 StandardGetFile(ffilter, numTypes, @typeList, stdReply);
  98.                 SetStdReply(reply, stdReply);
  99.             end
  100.             else begin
  101.                 SFGetFile(MFSPt, '', ffilter, numTypes, @typeList, nil, oldReply);
  102.                 oldReply.copy := false;
  103.                 SetOldReply(reply, oldReply);
  104.             end;
  105.     end;
  106.  
  107.     procedure GetFile1 (t: OSType; var reply: MySFReply);
  108.         var
  109.             typeList: SFTypeList;
  110.     begin
  111.         if t = OSType(noType) then begin
  112.             GetFile(nil, -1, typeList, reply);
  113.         end else begin
  114.             typeList[0] := t;
  115.             GetFile(nil, 1, typeList, reply);
  116.         end;
  117.     end;
  118.  
  119.     procedure PutFile (str, origName: Str255; var reply: MySFreply);
  120.         var
  121.             stdReply: StandardFileReply;
  122.             oldReply: SFReply;
  123.     begin
  124.         with reply do
  125.             if has_NewStandardFile then begin
  126.                 StandardPutFile(str, origName, stdReply);
  127.                 SetStdReply(reply, stdReply);
  128.             end
  129.             else begin
  130.                 SFPutFile(MFSPt, str, origName, nil, oldReply);
  131.                 oldReply.copy := false;
  132.                 SetOldReply(reply, oldReply);
  133.             end;
  134.     end;
  135.  
  136.     var
  137.         oldReply: SFReply;
  138.         newReply: StandardFileReply;
  139. { item1 is ThisFolder }
  140.         item1: integer;
  141.         button1: boolean;
  142.         active1: boolean;
  143.  
  144.     procedure SetButtons (dlg: DialogPtr);
  145.         var
  146.             new1: boolean;
  147.     begin
  148.         if has_NewStandardFile then begin
  149.             new1 := newReply.sfFile.parID <> 1; { everywhere except  desktop???? }
  150.         end
  151.         else begin
  152.             new1 := true;
  153.         end;
  154.         SetButton(dlg, item1, active1, new1);
  155.     end;
  156.  
  157.     function ButtonModalFilter (dlg: DialogPtr; var er: EventRecord; var item: integer): boolean;
  158.     begin
  159. {$unused(item)}
  160.         SetButtons(dlg);
  161.         if (er.what = updateEvt) and (dlg = DialogPtr(er.message)) then begin
  162.             UpdateButton(dlg, item1, active1);
  163.         end;
  164.         ButtonModalFilter := false;
  165.     end;
  166.  
  167.     function ButtonModalFilterSys7 (dlg: DialogPtr; var er: EventRecord; var item: integer; data: Ptr): boolean;
  168.     begin
  169. {$unused(data)}
  170.         ButtonModalFilterSys7 := ButtonModalFilter(dlg, er, item);
  171.     end;
  172.  
  173.     function ButtonHook (item: integer; dlg: DialogPtr): integer;
  174.     begin
  175.         if not has_NewStandardFile or (GetWRefCon(dlg) = longint(sfMainDialogRefCon)) then begin
  176.             if item = sfHookFirstCall then begin
  177.                 button1 := false;
  178.                 InitButton(dlg, item1, active1, active1);
  179.                 SetButtons(dlg);
  180.             end;
  181.             if active1 then begin
  182.                 if item <> sfHookLastCall then begin
  183.                     button1 := item = item1;
  184.                     if button1 then begin
  185.                         item := sfItemOpenButton;
  186.                     end;
  187.                 end;
  188.             end;
  189.         end;
  190.         ButtonHook := item;
  191.     end;
  192.  
  193.     function ButtonHookSys7 (item: integer; dlg: DialogPtr; data: Ptr): integer;
  194.     begin
  195. {$unused(data)}
  196.         ButtonHookSys7 := ButtonHook(item, dlg);
  197.     end;
  198.  
  199.     procedure PutFolder (str, origName: Str255; id: integer; var reply: MySFreply);
  200.     begin
  201.         if has_NewStandardFile then begin
  202.             item1 := 13;
  203.             active1 := true;
  204.             CustomPutFile(str, origName, newReply, id + 1, MFSPt, @ButtonHookSys7, @ButtonModalFilterSys7, nil, nil, nil); {@ButtonModalFilterSys7}
  205.             SetStdReply(reply, newReply);
  206.             reply.Rfolder := button1;
  207.         end
  208.         else begin
  209.             item1 := 9;
  210.             active1 := true;
  211.             SFPPutFile(MFSPt, str, origName, @ButtonHook, oldReply, id, nil);
  212.             oldReply.copy := button1;
  213.             SetOldReply(reply, oldReply);
  214.         end;
  215.     end;
  216.  
  217. (*
  218.     function CallFileFilterSys7 (pb: CInfoPBPtr; addr: Ptr): boolean;
  219.     inline
  220.         $205F, $4E90;
  221.  
  222.     function FileFilterSys7 (pb: CInfoPBPtr; addr: Ptr): boolean;
  223.     begin
  224.         if (BAND(pb^.ioFlAttrib, $0010) = 0) and (addr <> nil) then begin
  225.             FileFilterSys7 := CallFileFilterSys7(pb, addr);
  226.         end else begin
  227.             FileFilterSys7 := false;
  228.         end;
  229.     end;
  230.  
  231.     procedure GetFolder (ffilter: Ptr; numTypes: integer; typeList: SFTypeList; id: integer; var reply: MySFReply);
  232.     begin
  233.         if has_NewStandardFile then begin
  234.             item1 := 10;
  235.             active1 := true;
  236.             CustomGetFile(@FileFilterSys7, numTypes, @typeList, newReply, id + 1, MFSpt, @ButtonHookSys7, @ButtonModalFilterSys7, nil, nil, ffilter);
  237.             SetStdReply(reply, newReply);
  238.             reply.Rfolder := button1;
  239.         end
  240.         else begin
  241.             item1 := 11;
  242.             active1 := true;
  243.             SFPGetFile(MFSPt, '', ffilter, numTypes, @typeList, @ButtonHook, oldReply, id, nil);
  244.             oldReply.copy := button1;
  245.             SetOldReply(reply, oldReply);
  246.         end;
  247.     end;
  248. *)
  249.  
  250. end.
  251.     function Button11Hook (item: integer; dlg: DialogPtr): integer;
  252. { NOTE: Button11Hook sets Button11 when it converts Button 11 to Button 1 (Open) }
  253.     function Button9Hook (item: integer; dlg: DialogPtr): integer;
  254. { NOTE: Button9Hook sets Button9 when it converts Button 9 to Button 1 (Save) }
  255.