home *** CD-ROM | disk | FTP | other *** search
/ PC World Plus! (NZ) 2001 June / HDC50.iso / Runimage / Delphi50 / Doc / FILECTRL.INT < prev    next >
Text File  |  1999-08-11  |  9KB  |  309 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Borland Delphi Visual Component Library         }
  5. {                                                       }
  6. {       Copyright (c) 1995,99 Inprise Corporation       }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. unit FileCtrl;
  11.  
  12. {$R-,T-,H+,X+}
  13.  
  14. interface
  15.  
  16. uses Windows, Messages, SysUtils, Classes, Controls, Graphics, Forms,
  17.   Menus, StdCtrls, Buttons;
  18.  
  19. type
  20.   TFileAttr = (ftReadOnly, ftHidden, ftSystem, ftVolumeID, ftDirectory,
  21.     ftArchive, ftNormal);
  22.   TFileType = set of TFileAttr;
  23.  
  24.   TDriveType = (dtUnknown, dtNoDrive, dtFloppy, dtFixed, dtNetwork, dtCDROM,
  25.     dtRAM);
  26.  
  27.   TDirectoryListBox = class;
  28.   TFilterComboBox = class;
  29.   TDriveComboBox = class;
  30.  
  31. { TFileListBox }
  32.  
  33.   TFileListBox = class(TCustomListBox)
  34.   protected
  35.     FDirectory: string;
  36.     FMask: string;
  37.     FFileType: TFileType;
  38.     FFileEdit: TEdit;
  39.     FDirList: TDirectoryListBox;
  40.     FFilterCombo: TFilterComboBox;
  41.     ExeBMP, DirBMP, UnknownBMP: TBitmap;
  42.     FOnChange: TNotifyEvent;
  43.     FLastSel: Integer;
  44.     FShowGlyphs: Boolean;
  45.     procedure CreateWnd; override;
  46.     procedure ReadBitmaps; virtual;
  47.     procedure Click; override;
  48.     procedure Change; virtual;
  49.     procedure ReadFileNames; virtual;
  50.     procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);  override;
  51.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  52.     function GetFilePath: string; virtual;
  53.   public
  54.     constructor Create(AOwner: TComponent); override;
  55.     destructor Destroy; override;
  56.     procedure Update; reintroduce;
  57.     procedure ApplyFilePath (const EditText: string); virtual;
  58.     property Drive: char;
  59.     property Directory: string;
  60.     property FileName: string;
  61.   published
  62.     property Align;
  63.     property Anchors;
  64.     property Color;
  65.     property Constraints;
  66.     property Ctl3D;
  67.     property DragCursor;
  68.     property DragMode;
  69.     property Enabled;
  70.     property ExtendedSelect;
  71.     property FileEdit: TEdit;
  72.     property FileType: TFileType default [ftNormal];
  73.     property Font;
  74.     property ImeMode;
  75.     property ImeName;
  76.     property IntegralHeight;
  77.     property ItemHeight;
  78.     property Mask: string;
  79.     property MultiSelect;
  80.     property ParentColor;
  81.     property ParentCtl3D;
  82.     property ParentFont;
  83.     property ParentShowHint;
  84.     property PopupMenu;
  85.     property ShowGlyphs: Boolean default False;
  86.     property ShowHint;
  87.     property TabOrder;
  88.     property TabStop;
  89.     property Visible;
  90.     property OnChange: TNotifyEvent;
  91.     property OnClick;
  92.     property OnContextPopup;
  93.     property OnDblClick;
  94.     property OnDragDrop;
  95.     property OnDragOver;
  96.     property OnEndDrag;
  97.     property OnEnter;
  98.     property OnExit;
  99.     property OnKeyDown;
  100.     property OnKeyPress;
  101.     property OnKeyUp;
  102.     property OnMouseDown;
  103.     property OnMouseMove;
  104.     property OnMouseUp;
  105.     property OnStartDrag;
  106.   end;
  107.  
  108. { TDirectoryListBox }
  109.  
  110.   TDirectoryListBox = class(TCustomListBox)
  111.   protected
  112.     ClosedBMP, OpenedBMP, CurrentBMP: TBitmap;
  113.     FDirectory: string;
  114.     FOnChange: TNotifyEvent;
  115.     procedure Change; virtual;
  116.     procedure DblClick; override;
  117.     procedure ReadBitmaps; virtual;
  118.     procedure CreateWnd; override;
  119.     procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
  120.     function  ReadDirectoryNames(const ParentDirectory: string;
  121.       DirectoryList: TStringList): Integer;
  122.     procedure BuildList; virtual;
  123.     procedure KeyPress(var Key: Char); override;
  124.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  125.   public
  126.     constructor Create(AOwner: TComponent); override;
  127.     destructor Destroy; override;
  128.     function  DisplayCase(const S: String): String;
  129.     function  FileCompareText(const A, B: String): Integer;
  130.     function GetItemPath(Index: Integer): string;
  131.     procedure OpenCurrent;
  132.     procedure Update; reintroduce;
  133.     property Drive: Char;
  134.     property Directory: string;
  135.     property PreserveCase: Boolean;
  136.     property CaseSensitive: Boolean;
  137.   published
  138.     property Align;
  139.     property Anchors;
  140.     property Color;
  141.     property Columns;
  142.     property Constraints;
  143.     property Ctl3D;
  144.     property DirLabel: TLabel;
  145.     property DragCursor;
  146.     property DragMode;
  147.     property Enabled;
  148.     property FileList: TFileListBox;
  149.     property Font;
  150.     property ImeMode;
  151.     property ImeName;
  152.     property IntegralHeight;
  153.     property ItemHeight;
  154.     property ParentColor;
  155.     property ParentCtl3D;
  156.     property ParentFont;
  157.     property ParentShowHint;
  158.     property PopupMenu;
  159.     property ShowHint;
  160.     property TabOrder;
  161.     property TabStop;
  162.     property Visible;
  163.     property OnChange: TNotifyEvent;
  164.     property OnClick;
  165.     property OnContextPopup;
  166.     property OnDblClick;
  167.     property OnDragDrop;
  168.     property OnDragOver;
  169.     property OnEndDrag;
  170.     property OnEnter;
  171.     property OnExit;
  172.     property OnKeyDown;
  173.     property OnKeyPress;
  174.     property OnKeyUp;
  175.     property OnMouseDown;
  176.     property OnMouseMove;
  177.     property OnMouseUp;
  178.     property OnStartDrag;
  179.   end;
  180.  
  181. { TDriveComboBox }
  182.  
  183.   TTextCase = (tcLowerCase, tcUpperCase);
  184.  
  185.   TDriveComboBox = class(TCustomComboBox)
  186.   protected
  187.     FloppyBMP, FixedBMP, NetworkBMP, CDROMBMP, RAMBMP: TBitmap;
  188.     procedure CreateWnd; override;
  189.     procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
  190.     procedure Click; override;
  191.     procedure BuildList; virtual;
  192.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  193.   public
  194.     constructor Create(AOwner: TComponent); override;
  195.     destructor Destroy; override;
  196.     property Text;
  197.     property Drive: Char;
  198.   published
  199.     property Anchors;
  200.     property Color;
  201.     property Constraints;
  202.     property Ctl3D;
  203.     property DirList: TDirectoryListBox;
  204.     property DragMode;
  205.     property DragCursor;
  206.     property Enabled;
  207.     property Font;
  208.     property ImeMode;
  209.     property ImeName;
  210.     property ParentColor;
  211.     property ParentCtl3D;
  212.     property ParentFont;
  213.     property ParentShowHint;
  214.     property PopupMenu;
  215.     property ShowHint;
  216.     property TabOrder;
  217.     property TabStop;
  218.     property TextCase: TTextCase default tcLowerCase;
  219.     property Visible;
  220.     property OnChange;
  221.     property OnClick;
  222.     property OnContextPopup;
  223.     property OnDblClick;
  224.     property OnDragDrop;
  225.     property OnDragOver;
  226.     property OnDropDown;
  227.     property OnEndDrag;
  228.     property OnEnter;
  229.     property OnExit;
  230.     property OnKeyDown;
  231.     property OnKeyPress;
  232.     property OnKeyUp;
  233.     property OnStartDrag;
  234.   end;
  235.  
  236. { TFilterComboBox }
  237.  
  238.   TFilterComboBox = class(TCustomComboBox)
  239.   protected
  240.     procedure Change; override;
  241.     procedure CreateWnd; override;
  242.     procedure Click; override;
  243.     procedure BuildList;
  244.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  245.   public
  246.     constructor Create(AOwner: TComponent); override;
  247.     destructor Destroy; override;
  248.     property Mask: string;
  249.     property Text;
  250.   published
  251.     property Anchors;
  252.     property Color;
  253.     property Constraints;
  254.     property Ctl3D;
  255.     property DragMode;
  256.     property DragCursor;
  257.     property Enabled;
  258.     property FileList: TFileListBox;
  259.     property Filter: string;
  260.     property Font;
  261.     property ImeName;
  262.     property ImeMode;
  263.     property ParentColor;
  264.     property ParentCtl3D;
  265.     property ParentFont;
  266.     property ParentShowHint;
  267.     property PopupMenu;
  268.     property ShowHint;
  269.     property TabOrder;
  270.     property TabStop;
  271.     property Visible;
  272.     property OnChange;
  273.     property OnClick;
  274.     property OnContextPopup;
  275.     property OnDblClick;
  276.     property OnDragDrop;
  277.     property OnDragOver;
  278.     property OnDropDown;
  279.     property OnEndDrag;
  280.     property OnEnter;
  281.     property OnExit;
  282.     property OnKeyDown;
  283.     property OnKeyPress;
  284.     property OnKeyUp;
  285.     property OnStartDrag;
  286.   end;
  287.  
  288. procedure ProcessPath (const EditText: string; var Drive: Char;
  289.   var DirPart: string; var FilePart: string);
  290.  
  291. function MinimizeName(const Filename: TFileName; Canvas: TCanvas;
  292.   MaxLen: Integer): TFileName;
  293.  
  294. const
  295.   WNTYPE_DRIVE = 1;  { from WINNET.H, WFW 3.1 SDK }
  296.  
  297. type
  298.   TSelectDirOpt = (sdAllowCreate, sdPerformCreate, sdPrompt);
  299.   TSelectDirOpts = set of TSelectDirOpt;
  300.  
  301. function SelectDirectory(var Directory: string;
  302.   Options: TSelectDirOpts; HelpCtx: Longint): Boolean; overload;
  303. function SelectDirectory(const Caption: string; const Root: WideString;
  304.   out Directory: string): Boolean; overload;
  305. function DirectoryExists(const Name: string): Boolean;
  306. function ForceDirectories(Dir: string): Boolean;
  307.  
  308. implementation
  309.