Recent

Author Topic: I added Systemicons to ShellControls who is the maintainer of shellcontrols?  (Read 13531 times)

SunyD

  • Guest
Hi,
I added for TShellListView Windows SystemImages. It don't copies them. It shares systemimage-handle.
You can integate it in to LCL-Shellcontrols. Here is Code:

Unit for handling imagelist and iconindex:
Code: [Select]
unit lfmosfuncwin;

{$mode objfpc}{$H+}

interface

uses Windows, ComCtrls;

procedure SetListViewImgListToSys(AListView :TCustomListView; ALarge: Boolean);

function GetFileSysImageIndex(AFName: string): Integer;

implementation

const
  SHGFI_SMALLICON         = $000000001;
  SHGFI_LARGEICON         = $000000000;
  SHGFI_SYSICONINDEX      = $000004000;
  SHGFI_ICON              = $000000100;
  IsImgLarge: array[Boolean] of Integer = (SHGFI_SMALLICON, SHGFI_LARGEICON);

function GetSysImageListHandle(ALarge: Boolean): HIMAGELIST;
var aFileInfo: TSHFileInfo;
begin
  //don't needed initial zereo: ZeroMemory(@aFileInfo,sizeof(TSHFileInfo));
  Result := SHGetFileInfo('', 0, aFileInfo, SizeOf(aFileInfo), SHGFI_SYSICONINDEX or IsImgLarge[ALarge]);
end;

procedure SetListViewImgListToSys(AListView :TCustomListView; ALarge: Boolean);
begin
  ListView_SetImageList(AListView.Handle,GetSysImageListHandle(ALarge), IsImgLarge[ALarge]); //SHGFI_SMALLICON);
end;

function GetFileSysImageIndex(AFName: string): Integer;
var aFileInfo: TSHFileInfo;
begin
  //don't needed initial zereo: ZeroMemory(@aFileInfo,sizeof(TSHFileInfo));
  SHGetFileInfo(PChar(AFName),0,aFileInfo, SizeOf(aFileInfo), SHGFI_ICON or SHGFI_SYSICONINDEX);
  Result:=aFileInfo.iIcon;
end;

Changes in ShellCtrls.pas
Code: [Select]
type
  TCustomShellListView = class(TCustomListView)
  //...
  protected
    procedure SetParent(NewParent: TWinControl); override;
  //...
  end; 

implementation

{$ifdef windows}
uses Windows, lfmosfuncwin;
{$endif}

//...


procedure TCustomShellListView.SetParent(NewParent: TWinControl);
begin
   inherited SetParent(NewParent);
   SetListViewImgListToSys(self, true);  //large icons
   SetListViewImgListToSys(self, false); //small icons
end;

//.....

procedure TCustomShellListView.PopulateWithRoot();
  //.....
begin
  //.....
  try
    //near line 715 change:
    TCustomShellTreeView.GetFilesInDir(FRoot, FMask, FObjectTypes, Files, fstFoldersFirst); //add  fstFoldersFirst for better sorting

  //...
      //Add near line 735 inLoop after Line:   
     //NewItem.SubItems.Add(ExtractFileExt(CurFileName));
     //this Line
      NewItem.ImageIndex:=GetFileSysImageIndex(CurFilePath);
 //...
end;


// in function:
procedure TCustomShellListView.Resize;
begin 

  //change this:
  //if  Self.Columns.Count < 3 then Exit;
  //to this:
  if (ViewStyle<>vsReport)or(Self.Columns.Count < 3) then Exit;

  //because in List or IconView Columns are to wide. 

  //...
end;


You can do same thing for TShellTreeView. For TShellTreeView you need only Smallimage-List.

I add my sources as attachment you can use it too.

Edit2:
I made modifications for link and shared files icon-overlay. Some other modifications look for modifications for commentlines "soner".

I made modifications only for TShellListView. I think both component must extend, some things are not the best.

Edit3:
I added images for Linux. For Linux it don't use system images, it use built in images. Better than nothing :)

« Last Edit: March 24, 2011, 11:55:39 pm by SunyD »

SunyD

  • Guest
I'm writing platform independent simple filemanager.
Screenshot (very early version):

SunyD

  • Guest
I forgot to say, don't use TShellListView.LargeImages or  TShellListView.SmallImages properties because Windows manages imagelists.

And i forgot also stateimages for link-files. I have to look in my old delphi codes, how i solved this.

Paul Ishenin

  • Sr. Member
  • ****
  • Posts: 274
SunyD, why you redeclare SHGFI_xxx constants which are declared in the FPC windows unit?

SunyD

  • Guest
SunyD, why you redeclare SHGFI_xxx constants which are declared in the FPC windows unit?
Because they are definied in shellapi and i wouldn't include it.
-

I solved overlay-icon issue and made some modifications. Look first posting after line "edit2:".
 

SunyD

  • Guest
I added  builtin  image support. Look first posting.

Here is screenshot under gtk:

fabienwang

  • Sr. Member
  • ****
  • Posts: 449
  • Lazarus is the best
    • My blog
Does the code in the first post will work on Linux ?
if not, how did you do in linux to get the system icons?

Thanks.
I'm using Arch Linux.
Known for: CPickSniff, OpenGrabby
Contributed to: LazPaint

SunyD

  • Guest
Does the code in the first post will work on Linux ?
if not, how did you do in linux to get the system icons?

Thanks.
Sorry i wrote in first post wrong. On linux it don't use system images it use built in images.

If you programming filemanager take care, TLisView is buggy with GTK/QT toolkits.
Icon, list and smallicon styles of TListView don't works if you have more column and you leave some colunms clean texts like:
string:='';

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
how to use it in ShellTreeView, a small example please  :-\

PeterX

  • Sr. Member
  • ****
  • Posts: 404
Was this "Systemicons thing" integrated in Lazarus ?
Does the Shell Control now use the Windows Shell Iconlist ?
usually using latest Lazarus release version with Windows 10

 

TinyPortal © 2005-2018