(************************************************************************
*    This File is Part of the AHM Triton Tools                          *
*    for Borland Delphi and C++ Builder.                                *
*************************************************************************
* Copyright © 1995-1999 Alexander H. Mehlhorn (AHM) and Tritontools.com *
* All Rights reserved.                                                  *
*                                                                       *
*    For more Information contact us at                                 *
*    E-Mail : support@tritontools.com                                   *
*    URL : http://www.tritontools.com                                   *
*                                                                       *
*    AHM is copyright by Alexander H. Mehlhorn                          *
*    All Parts of this Collection were developed,                       *
*    designed and implemented by AHM                                    *
*                                                                       *
*    Under no Circumstances may you distribute this file                *
*    in this or any other format. This File is supplied                 *
*    as Evaluation of Source only. No Delphi Components may be developed*
*    using extracts or subsets of this code without expressed permission*
*    by AHM.                                                            *
*                                                                       *
*************************************************************************)
unit AHMTExplorerView;

interface

uses SysUtils, Windows, Messages, Classes, Graphics, Controls,
    Forms, Dialogs, StdCtrls, Menus,Registry,AHMStdClass,FileCtrl;
type
  TAHMExplorerView = class(TFileListBox)
  private
    FBitmap: TBitmap;
    FCharCase: TEditCharCase;
    FAboutStr : TAHMAboutSControlStr;
    procedure SetCharCase(ACase: TEditCharCase);
  protected
    procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
  public
    constructor Create(AOwner: TComponent); override;
    procedure Loaded; override;
    destructor Destroy; override;
    function RPos(const SubStr: Char; Str: string): Word;
  published
    property About : TAHMAboutSControlStr read FAboutStr write FAboutStr;
    property CharCase: TEditCharCase read FCharCase write SetCharCase;
    property Align;
    property BorderStyle;
    property Columns;
    property Ctl3D;
    property DragCursor;
    property DragMode;
    property Enabled;
    property Font;
    property IntegralHeight;
    property ItemHeight;
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Visible;
    property OnDragDrop;
    property OnDragOver;
    property OnDrawItem;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnMeasureItem;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnDblClick;
  end;

{$R AHMTExplorerView}
implementation

uses ShellApi;

constructor TAHMExplorerView.Create(AOwner: TComponent);
var IconInfo : TSHFileInfo;
    PathName  : array [0..MAX_PATH] of char;
begin
  GetWindowsDirectory(PathName,MAX_PATH);
  inherited Create(AOwner);
  ItemHeight:=18;
  Style := lbOwnerDrawFixed;
  Columns := 1;
  FCharCase := ecLowerCase;
  FBitmap := TBitmap.Create;
  with TImageList.Create(self) do
  try
    Handle:=SHGetFileInfo(PathName,0,IconInfo,SizeOf(TSHFileInfo),SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
    ShareImages:=True;
    FBitmap.Width:=16;
    FBitmap.Height:=16;
    Draw(FBitmap.Canvas,0,0,IconInfo.iIcon);
  finally
    Free;
  end;
end;

procedure TAHMExplorerView.Loaded;
begin
  inherited Loaded;
end;

destructor TAHMExplorerView.Destroy;
begin
  FBitmap.Free;
  inherited Destroy;
end;

function TAHMExplorerView.RPos(const SubStr: Char; Str: string): Word;
begin
  result :=0;
  repeat
    if Str[Length(Str)] = SubStr then exit else
    begin
      SetLength(Str, Length(Str) - 1);
      Inc(result)
    end
  until Length(Str) = 0;
end;

procedure TAHMExplorerView.DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);
var Info : TSHFileInfo;
begin
  with Canvas do
  begin
    FillRect(Rect);
    begin
//    FillChar(Info,SizeOF(TSHFileInfo),0);
      with TImageList.Create(self) do
      try
        if Pos('[',Items[Index])=0 then
        begin
        Handle:=SHGetFileInfo(PChar(Items.Strings[Index]),0,Info,
        SizeOf(TSHFileInfo),SHGFI_SYSICONINDEX or SHGFI_SMALLICON or SHGFI_OPENICON);
        ShareImages:=True;
        Draw(Canvas,Rect.Left,Rect.Top,Info.iIcon);
        end else Canvas.Draw(Rect.Left,Rect.Top,FBitmap);
      finally
        Free;
      end;
      TextOut(Rect.Left+ 18, Rect.Top, Items[Index]);
    end;
  end
end;

procedure TAHMExplorerView.SetCharCase(ACase: TEditCharCase);
begin
  FCharCase := ACase;
  Update;
end;

end.
