home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vp11demo.zip / rtlsrc.rar / tv / STDDLG.PAS < prev    next >
Pascal/Delphi Source File  |  1996-10-08  |  10KB  |  303 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Turbo Pascal Version 7.0                        }
  5. {       Turbo Vision Unit                               }
  6. {                                                       }
  7. {       Copyright (c) 1992 Borland International        }
  8. {                                                       }
  9. {*******************************************************}
  10. {$PureInt+}
  11. unit StdDlg;
  12.  
  13. {$V-,X+,I-,S-,Cdecl-}
  14.  
  15. interface
  16.  
  17. uses Objects, Drivers, Views, Dialogs, Os2Def, Os2Base, Dos, Use32;
  18.  
  19. const
  20.  
  21. { Commands }
  22.  
  23.   cmFileOpen    = 800;   { Returned from TFileDialog when Open pressed }
  24.   cmFileReplace = 801;   { Returned from TFileDialog when Replace pressed }
  25.   cmFileClear   = 802;   { Returned from TFileDialog when Clear pressed }
  26.   cmFileInit    = 803;   { Used by TFileDialog internally }
  27.   cmChangeDir   = 804;   { Used by TChDirDialog internally }
  28.   cmRevert      = 805;   { Used by TChDirDialog internally }
  29.  
  30. { Messages }
  31.  
  32.   cmFileFocused = 806;    { A new file was focused in the TFileList }
  33.   cmFileDoubleClicked     { A file was selected in the TFileList }
  34.                 = 807;
  35.  
  36. type
  37.  
  38.   { TSearchRec }
  39.  
  40.   {  Record used to store directory information by TFileDialog }
  41.  
  42.   TSearchRec = record
  43.     Attr: Byte;
  44.     Time: Longint;
  45.     Size: Longint;
  46.     Name: String;
  47.   end;
  48.  
  49. type
  50.  
  51.   { TFileInputLine is a special input line that is used by      }
  52.   { TFileDialog that will update its contents in response to a  }
  53.   { cmFileFocused command from a TFileList.                     }
  54.  
  55.   PFileInputLine = ^TFileInputLine;
  56.   TFileInputLine = object(TInputLine)
  57.     constructor Init(var Bounds: TRect; AMaxLen: Integer);
  58.     procedure HandleEvent(var Event: TEvent); virtual;
  59.   end;
  60.  
  61.   { TFileCollection is a collection of TSearchRec's.            }
  62.  
  63.   PFileCollection = ^TFileCollection;
  64.   TFileCollection = object(TSortedCollection)
  65.     function Compare(Key1, Key2: Pointer): Integer; virtual;
  66.     procedure FreeItem(Item: Pointer); virtual;
  67.     function GetItem(var S: TStream): Pointer; virtual;
  68.     procedure PutItem(var S: TStream; Item: Pointer); virtual;
  69.   end;
  70.  
  71.   { TSortedListBox is a TListBox that assumes it has a          }
  72.   { TStoredCollection instead of just a TCollection.  It will   }
  73.   { perform an incremental search on the contents.              }
  74.  
  75.   PSortedListBox = ^TSortedListBox;
  76.   TSortedListBox = object(TListBox)
  77.     SearchPos: Word;
  78.     ShiftState: Byte;
  79.     constructor Init(var Bounds: TRect; ANumCols: Word;
  80.       AScrollBar: PScrollBar);
  81.     procedure HandleEvent(var Event: TEvent); virtual;
  82.     function GetKey(var S: String): Pointer; virtual;
  83.     procedure NewList(AList: PCollection); virtual;
  84.   end;
  85.  
  86.   { TFileList is a TSortedList box that assumes it contains     }
  87.   { a TFileCollection as its collection.  It also communicates  }
  88.   { through broadcast messages to TFileInput and TInfoPane      }
  89.   { what file is currently selected.                            }
  90.  
  91.   PFileList = ^TFileList;
  92.   TFileList = object(TSortedListBox)
  93.     constructor Init(var Bounds: TRect; AScrollBar: PScrollBar);
  94.     destructor Done; virtual;
  95.     function DataSize: Word; virtual;
  96.     procedure FocusItem(Item: Integer); virtual;
  97.     procedure GetData(var Rec); virtual;
  98.     function GetText(Item: Integer; MaxLen: Integer): String; virtual;
  99.     function GetKey(var S: String): Pointer; virtual;
  100.     procedure HandleEvent(var Event: TEvent); virtual;
  101.     procedure ReadDirectory(AWildCard: PathStr); virtual;
  102.     procedure SetData(var Rec); virtual;
  103.   end;
  104.  
  105.   { TFileInfoPane is a TView that displays the information      }
  106.   { about the currently selected file in the TFileList          }
  107.   { of a TFileDialog.                                           }
  108.  
  109.   PFileInfoPane = ^TFileInfoPane;
  110.   TFileInfoPane = object(TView)
  111.     S: TSearchRec;
  112.     constructor Init(var Bounds: TRect);
  113.     procedure Draw; virtual;
  114.     function GetPalette: PPalette; virtual;
  115.     procedure HandleEvent(var Event: TEvent); virtual;
  116.   end;
  117.  
  118.   { TFileDialog is a standard file name input dialog            }
  119.  
  120.   TWildStr = PathStr;
  121.  
  122. const
  123.   fdOkButton      = $0001;      { Put an OK button in the dialog }
  124.   fdOpenButton    = $0002;      { Put an Open button in the dialog }
  125.   fdReplaceButton = $0004;      { Put a Replace button in the dialog }
  126.   fdClearButton   = $0008;      { Put a Clear button in the dialog }
  127.   fdHelpButton    = $0010;      { Put a Help button in the dialog }
  128.   fdNoLoadDir     = $0100;      { Do not load the current directory }
  129.                                 { contents into the dialog at Init. }
  130.                                 { This means you intend to change the }
  131.                                 { WildCard by using SetData or store }
  132.                                 { the dialog on a stream. }
  133.  
  134. type
  135.  
  136.   PFileDialog = ^TFileDialog;
  137.   TFileDialog = object(TDialog)
  138.     FileName: PFileInputLine;
  139.     FileList: PFileList;
  140.     WildCard: TWildStr;
  141.     Directory: PString;
  142.     constructor Init(AWildCard: TWildStr; const ATitle,
  143.       InputName: String; AOptions: Word; HistoryId: Byte);
  144.     constructor Load(var S: TStream);
  145.     destructor Done; virtual;
  146.     procedure GetData(var Rec); virtual;
  147.     procedure GetFileName(var S: PathStr);
  148.     procedure HandleEvent(var Event: TEvent); virtual;
  149.     procedure SetData(var Rec); virtual;
  150.     procedure Store(var S: TStream);
  151.     function Valid(Command: Word): Boolean; virtual;
  152.     procedure ReadDirectory;
  153.   end;
  154.  
  155.   { TDirEntry }
  156.  
  157.   PDirEntry = ^TDirEntry;
  158.   TDirEntry = record
  159.     DisplayText: PString;
  160.     Directory: PString;
  161.   end;
  162.  
  163.   { TDirCollection is a collection of TDirEntry's used by       }
  164.   { TDirListBox.                                                }
  165.  
  166.   PDirCollection = ^TDirCollection;
  167.   TDirCollection = object(TCollection)
  168.     function GetItem(var S: TStream): Pointer; virtual;
  169.     procedure FreeItem(Item: Pointer); virtual;
  170.     procedure PutItem(var S: TStream; Item: Pointer); virtual;
  171.   end;
  172.  
  173.   { TDirListBox displays a tree of directories for use in the }
  174.   { TChDirDialog.                                               }
  175.  
  176.   PDirListBox = ^TDirListBox;
  177.   TDirListBox = object(TListBox)
  178.     Dir: DirStr;
  179.     Cur: Word;
  180.     constructor Init(var Bounds: TRect; AScrollBar: PScrollBar);
  181.     destructor Done; virtual;
  182.     function GetText(Item: Integer; MaxLen: Integer): String; virtual;
  183.     procedure HandleEvent(var Event: TEvent); virtual;
  184.     function IsSelected(Item: Integer): Boolean; virtual;
  185.     procedure NewDirectory(var ADir: DirStr);
  186.     procedure SetState(AState: Word; Enable: Boolean); virtual;
  187.   end;
  188.  
  189.   { TChDirDialog is a standard change directory dialog.         }
  190.  
  191. const
  192.   cdNormal     = $0000; { Option to use dialog immediately }
  193.   cdNoLoadDir  = $0001; { Option to init the dialog to store on a stream }
  194.   cdHelpButton = $0002; { Put a help button in the dialog }
  195.  
  196. type
  197.  
  198.   PChDirDialog = ^TChDirDialog;
  199.   TChDirDialog = object(TDialog)
  200.     DirInput: PInputLine;
  201.     DirList: PDirListBox;
  202.     OkButton: PButton;
  203.     ChDirButton: PButton;
  204.     constructor Init(AOptions: Word; HistoryId: Word);
  205.     constructor Load(var S: TStream);
  206.     function DataSize: Word; virtual;
  207.     procedure GetData(var Rec); virtual;
  208.     procedure HandleEvent(var Event: TEvent); virtual;
  209.     procedure SetData(var Rec); virtual;
  210.     procedure Store(var S: TStream);
  211.     function Valid(Command: Word): Boolean; virtual;
  212.     procedure SetUpDialog;
  213.   end;
  214.  
  215. const
  216.  
  217.   CInfoPane = #30;
  218.  
  219.   { TStream registration records }
  220.  
  221. const
  222.   RFileInputLine: TStreamRec = (
  223.      ObjType: 60;
  224.      VmtLink: Ofs(TypeOf(TFileInputLine)^);
  225.      Load:    @TFileInputLine.Load;
  226.      Store:   @TFileInputLine.Store
  227.   );
  228.  
  229. const
  230.   RFileCollection: TStreamRec = (
  231.      ObjType: 61;
  232.      VmtLink: Ofs(TypeOf(TFileCollection)^);
  233.      Load:    @TFileCollection.Load;
  234.      Store:   @TFileCollection.Store
  235.   );
  236.  
  237. const
  238.   RFileList: TStreamRec = (
  239.      ObjType: 62;
  240.      VmtLink: Ofs(TypeOf(TFileList)^);
  241.      Load:    @TFileList.Load;
  242.      Store:   @TFileList.Store
  243.   );
  244.  
  245. const
  246.   RFileInfoPane: TStreamRec = (
  247.      ObjType: 63;
  248.      VmtLink: Ofs(TypeOf(TFileInfoPane)^);
  249.      Load:    @TFileInfoPane.Load;
  250.      Store:   @TFileInfoPane.Store
  251.   );
  252.  
  253. const
  254.   RFileDialog: TStreamRec = (
  255.      ObjType: 64;
  256.      VmtLink: Ofs(TypeOf(TFileDialog)^);
  257.      Load:    @TFileDialog.Load;
  258.      Store:   @TFileDialog.Store
  259.   );
  260.  
  261. const
  262.   RDirCollection: TStreamRec = (
  263.      ObjType: 65;
  264.      VmtLink: Ofs(TypeOf(TDirCollection)^);
  265.      Load:    @TDirCollection.Load;
  266.      Store:   @TDirCollection.Store
  267.   );
  268.  
  269. const
  270.   RDirListBox: TStreamRec = (
  271.      ObjType: 66;
  272.      VmtLink: Ofs(TypeOf(TDirListBox)^);
  273.      Load:    @TDirListBox.Load;
  274.      Store:   @TDirListBox.Store
  275.   );
  276.  
  277. const
  278.   RChDirDialog: TStreamRec = (
  279.      ObjType: 67;
  280.      VmtLink: Ofs(TypeOf(TChDirDialog)^);
  281.      Load:    @TChDirDialog.Load;
  282.      Store:   @TChDirDialog.Store
  283.   );
  284.  
  285. const
  286.   RSortedListBox: TStreamRec = (
  287.      ObjType: 68;
  288.      VmtLink: Ofs(TypeOf(TSortedListBox)^);
  289.      Load:    @TSortedListBox.Load;
  290.      Store:   @TSortedListBox.Store
  291.   );
  292.  
  293. procedure RegisterStdDlg;
  294. function PathValid(var Path: PathStr): Boolean; { !!! made public }
  295. function IsWild(const S: String): Boolean;      { !!! made public }
  296. function IsDir(const S: String): Boolean;       { !!! made public }
  297.  
  298. implementation
  299.  
  300. uses App, Memory, HistList, MsgBox;
  301.  
  302. end.
  303.