CustomPathComboBox.pas 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. unit CustomPathComboBox;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  5. StdCtrls, IEComboBox, ComCtrls;
  6. type
  7. TCustomPathComboBox = class(TIECustomComboBox)
  8. private
  9. FDirView: TCustomListView;
  10. FLastItem: Integer;
  11. FShowFullPath: Boolean;
  12. protected
  13. FPath: string;
  14. procedure DoCloseUp(Canceled: Boolean); override;
  15. procedure DropDown; override;
  16. procedure SetPath(Value: string); virtual; abstract;
  17. function GetPath: string; virtual;
  18. procedure Change; override;
  19. procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  20. procedure PathChanged; virtual;
  21. procedure SetShowFullPath(Value: Boolean);
  22. function GetItemTextEx(Index: Integer; ForList: Boolean): string; override;
  23. property Style default csOwnerDrawFixed;
  24. property Items stored False;
  25. property ItemHeight stored False;
  26. property MaxLength stored False;
  27. property Sorted stored False;
  28. property Text stored False;
  29. public
  30. constructor Create(AOwner: TComponent); override;
  31. property DirView: TCustomListView read FDirView write FDirView;
  32. property Path: string read GetPath write SetPath;
  33. property ShowFullPath: Boolean read FShowFullPath write SetShowFullPath default False;
  34. published
  35. end;
  36. implementation
  37. uses
  38. CustomDirView;
  39. constructor TCustomPathComboBox.Create(AOwner: TComponent);
  40. begin
  41. inherited;
  42. Style := csOwnerDrawFixed;
  43. FDirView := nil;
  44. FShowFullPath := False;
  45. end; { Create }
  46. procedure TCustomPathComboBox.Change;
  47. begin
  48. inherited;
  49. if (not DroppedDown) and (ItemIndex <> FLastItem) then PathChanged;
  50. end; { Change }
  51. procedure TCustomPathComboBox.Notification(AComponent: TComponent; Operation: TOperation);
  52. begin
  53. inherited;
  54. if (Operation = opRemove) and (AComponent = FDirView) then
  55. FDirView := nil;
  56. end; { Notification }
  57. procedure TCustomPathComboBox.DoCloseUp(Canceled: Boolean);
  58. begin
  59. if (FLastItem <> ItemIndex) then
  60. begin
  61. if Canceled then ItemIndex := FLastItem
  62. else PathChanged;
  63. end;
  64. inherited;
  65. end; { DoCloseUp }
  66. function TCustomPathComboBox.GetPath: string;
  67. begin
  68. Result := FPath;
  69. end;
  70. procedure TCustomPathComboBox.PathChanged;
  71. begin
  72. // TUnixPathComboBox doesn't call this inherited method
  73. if Assigned(FDirView) and (TCustomDirView(FDirView).Path <> Path) then
  74. TCustomDirView(FDirView).Path := Path;
  75. FLastItem := ItemIndex;
  76. end; { PathChanged }
  77. procedure TCustomPathComboBox.DropDown;
  78. begin
  79. FLastItem := ItemIndex;
  80. inherited;
  81. end; { DropDown }
  82. procedure TCustomPathComboBox.SetShowFullPath(Value: Boolean);
  83. begin
  84. if ShowFullPath <> Value then
  85. begin
  86. FShowFullPath := Value;
  87. Invalidate;
  88. end;
  89. end;
  90. function TCustomPathComboBox.GetItemTextEx(Index: Integer; ForList: Boolean): string;
  91. begin
  92. if ShowFullPath and not ForList then Result := Path
  93. else Result := inherited GetItemTextEx(Index, ForList);
  94. end;
  95. end.