You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

KOLCEOpenDir.inc 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. {$ifdef read_interface}
  2. //[OpenDirectory Object]
  3. { ----------------------------------------------------------------------
  4. TOpenDirDialog
  5. ----------------------------------------------------------------------- }
  6. //[TOpenDirDialog DEFINITION]
  7. TOpenDirDialog = object( TObj )
  8. {* Dialog for open directories, uses SHBrowseForFolder. }
  9. private
  10. FWnd: HWnd;
  11. function GetDialogWnd: HWnd;
  12. function GetTitle: KOLString;
  13. procedure SetTitle(const AValue: KOLString);
  14. protected
  15. FDlg: PObj;
  16. FOptions: TOpenDirOptions;
  17. FCenterOnScreen: Boolean;
  18. FOnSelChanged: TOnODSelChange;
  19. function GetPath: KOLString;
  20. procedure SetInitialPath(const Value: KOLString);
  21. procedure SetCenterOnScreen(const Value: Boolean);
  22. procedure SetOnSelChanged(const Value: TOnODSelChange);
  23. function GetInitialPath: KOLString;
  24. public
  25. destructor Destroy; {-}virtual;{+}{++}(*override;*){--}
  26. {* destructor }
  27. function Execute : Boolean;
  28. {* Call it to select directory by user. Returns True, if operation was
  29. not cancelled by user. }
  30. property Title : KOLString read GetTitle write SetTitle;
  31. {* Title for a dialog. }
  32. property Options : TOpenDirOptions read FOptions write FOptions;
  33. {* Option flags. }
  34. property Path : KOLString read GetPath;
  35. {* Resulting (selected by user) path. }
  36. property InitialPath: KOLString read GetInitialPath write SetInitialPath;
  37. {* Set this property to a path of directory to be selected initially
  38. in a dialog. }
  39. property CenterOnScreen: Boolean read FCenterOnScreen write SetCenterOnScreen;
  40. {* Set it to True to center dialog on screen. }
  41. property OnSelChanged: TOnODSelChange read FOnSelChanged write SetOnSelChanged;
  42. {* This event is called every time, when user selects another directory.
  43. It is possible to enable/disable OK button in dialog and/or change
  44. dialog status text in responce to event. }
  45. property WndOwner: HWnd read FWnd write FWnd;
  46. {* Owner window. If you want to provide your dialog visible over stay-on-top
  47. form, fire it as a child of the form, assigning the handle of form window
  48. to this property first. }
  49. property DialogWnd: HWnd read GetDialogWnd;
  50. {* Handle to the open directory dialog itself, become available on the
  51. first call of callback procedure (i.e. on the first call to OnSelChanged).
  52. }
  53. end;
  54. //[END OF TOpenDirDialog DEFINITION]
  55. {$endif read_interface}
  56. {$ifdef read_implementation}
  57. {$I KOLDirDlgEx.pas}
  58. function NewOpenDirDialog( const Title: KOLString; Options: TOpenDirOptions ):
  59. POpenDirDialog;
  60. begin
  61. New( Result, Create );
  62. Result.FDlg:=NewOpenDirDialogEx;
  63. Result.FOptions := [ odOnlySystemDirs ];
  64. if Options <> [] then
  65. Result.FOptions := Options;
  66. Result.Title := Title;
  67. end;
  68. { TOpenDirDialog }
  69. function TOpenDirDialog.GetTitle: KOLString;
  70. begin
  71. Result:=POpenDirDialogEx(FDlg).Title;
  72. end;
  73. function TOpenDirDialog.GetDialogWnd: HWnd;
  74. begin
  75. Result:=POpenDirDialogEx(FDlg).Form.GetWindowHandle;
  76. end;
  77. procedure TOpenDirDialog.SetTitle(const AValue: KOLString);
  78. begin
  79. POpenDirDialogEx(FDlg).Title:=AValue;
  80. end;
  81. function TOpenDirDialog.GetPath: KOLString;
  82. begin
  83. Result:=ExcludeTrailingPathDelimiter(POpenDirDialogEx(FDlg).Path);
  84. if Result = '' then
  85. Result:='\';
  86. end;
  87. procedure TOpenDirDialog.SetInitialPath(const Value: KOLString);
  88. begin
  89. POpenDirDialogEx(FDlg).InitialPath:=Value;
  90. end;
  91. procedure TOpenDirDialog.SetCenterOnScreen(const Value: Boolean);
  92. begin
  93. end;
  94. procedure TOpenDirDialog.SetOnSelChanged(const Value: TOnODSelChange);
  95. begin
  96. end;
  97. function TOpenDirDialog.GetInitialPath: KOLString;
  98. begin
  99. Result:=POpenDirDialogEx(FDlg).InitialPath;
  100. end;
  101. destructor TOpenDirDialog.Destroy;
  102. begin
  103. POpenDirDialogEx(FDlg).Free;
  104. inherited;
  105. end;
  106. function TOpenDirDialog.Execute: Boolean;
  107. begin
  108. Result:=POpenDirDialogEx(FDlg).Execute;
  109. end;
  110. {$endif read_implementation}