2007-12-09 12:02:11 +00:00
|
|
|
unit CmpSwDialog;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
ActnList,
|
|
|
|
Classes,
|
|
|
|
ComCtrls,
|
|
|
|
Controls,
|
|
|
|
ExtCtrls,
|
|
|
|
ImgList,
|
2007-12-10 16:13:05 +00:00
|
|
|
IniFiles,
|
2007-12-09 12:02:11 +00:00
|
|
|
Menus,
|
|
|
|
StdCtrls,
|
|
|
|
|
|
|
|
BaseSwDialog,
|
|
|
|
BaseSwObjects;
|
|
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
TCmpSwStyleVisitor = class(TBaseSwStyleVisitor)
|
2007-12-10 16:13:05 +00:00
|
|
|
private
|
|
|
|
FImageList: TImageList;
|
|
|
|
FImageMap: TStringHash;
|
2007-12-09 12:02:11 +00:00
|
|
|
protected
|
|
|
|
procedure VisitItem(const AItem: TBaseSwItem); override;
|
2007-12-10 16:13:05 +00:00
|
|
|
|
|
|
|
function GetComponentPackage(const AClassName: String): String;
|
|
|
|
function LoadComponentImage(const APackageName, AClassName: String): Integer;
|
|
|
|
public
|
|
|
|
constructor Create(AImageList: TImageList);
|
|
|
|
destructor Destroy(); override;
|
2007-12-09 12:02:11 +00:00
|
|
|
end;
|
|
|
|
|
2007-12-10 16:13:05 +00:00
|
|
|
|
2007-12-09 12:02:11 +00:00
|
|
|
TfrmCmpSwDialog = class(TfrmBaseSwDialog)
|
|
|
|
protected
|
|
|
|
function CreateStyleVisitor(): TBaseSwStyleVisitor; override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
2007-12-10 16:13:05 +00:00
|
|
|
uses
|
|
|
|
CommCtrl,
|
|
|
|
SysUtils,
|
|
|
|
ToolsAPI,
|
|
|
|
Windows,
|
|
|
|
|
|
|
|
CmpSwObjects;
|
2007-12-09 12:02:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
|
|
|
|
{ TCmpSwStyleVisitor }
|
2007-12-10 16:13:05 +00:00
|
|
|
constructor TCmpSwStyleVisitor.Create(AImageList: TImageList);
|
|
|
|
begin
|
|
|
|
inherited Create();
|
|
|
|
|
|
|
|
FImageList := AImageList;
|
|
|
|
FImageMap := TStringHash.Create();
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
destructor TCmpSwStyleVisitor.Destroy();
|
|
|
|
begin
|
|
|
|
FreeAndNil(FImageMap);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-12-09 12:02:11 +00:00
|
|
|
procedure TCmpSwStyleVisitor.VisitItem(const AItem: TBaseSwItem);
|
2007-12-10 16:13:05 +00:00
|
|
|
var
|
|
|
|
component: TCmpSwComponent;
|
|
|
|
package: String;
|
|
|
|
|
2007-12-09 12:02:11 +00:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
2007-12-10 16:13:05 +00:00
|
|
|
component := (AItem as TCmpSwComponent);
|
|
|
|
ImageIndex := FImageMap.ValueOf(component.ComponentClass);
|
|
|
|
|
|
|
|
if ImageIndex = -1 then
|
|
|
|
begin
|
|
|
|
package := GetComponentPackage(component.ComponentClass);
|
|
|
|
if Length(package) > 0 then
|
|
|
|
ImageIndex := LoadComponentImage(package, component.ComponentClass);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if ImageIndex = -2 then
|
|
|
|
ImageIndex := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TCmpSwStyleVisitor.GetComponentPackage(const AClassName: String): String;
|
|
|
|
var
|
|
|
|
packageServices: IOTAPackageServices;
|
|
|
|
packageIndex: Integer;
|
|
|
|
componentIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
packageServices := (BorlandIDEServices as IOTAPackageServices);
|
|
|
|
|
|
|
|
for packageIndex := Pred(packageServices.PackageCount) downto 0 do
|
|
|
|
begin
|
|
|
|
for componentIndex := Pred(packageServices.ComponentCount[packageIndex]) downto 0 do
|
|
|
|
begin
|
|
|
|
if SameText(packageServices.ComponentNames[packageIndex, componentIndex],
|
|
|
|
AClassName) then
|
|
|
|
begin
|
|
|
|
Result := packageServices.PackageNames[packageIndex] + '.bpl';
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TCmpSwStyleVisitor.LoadComponentImage(const APackageName, AClassName: String): Integer;
|
|
|
|
var
|
|
|
|
packageHandle: THandle;
|
|
|
|
bitmapHandle: THandle;
|
|
|
|
bitmap: TBitmap;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
packageHandle := LoadLibrary(PChar(APackageName));
|
|
|
|
|
|
|
|
if packageHandle <> 0 then
|
|
|
|
try
|
|
|
|
bitmapHandle := LoadBitmap(packageHandle, PChar(AClassName));
|
|
|
|
if bitmapHandle <> 0 then
|
|
|
|
begin
|
|
|
|
bitmap ;=
|
|
|
|
// #ToDo1 (MvR) 10-12-2007: proper transparency
|
|
|
|
Result := ImageList_AddMasked(FImageList.Handle, bitmapHandle,
|
|
|
|
GetTransparentColor(bitmapHandle));
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
FreeLibrary(packageHandle);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Result = -1 then
|
|
|
|
Result := -2;
|
|
|
|
|
|
|
|
FImageMap.Add(AClassName, Result);
|
2007-12-09 12:02:11 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TfrmCmpSwDialog }
|
|
|
|
function TfrmCmpSwDialog.CreateStyleVisitor(): TBaseSwStyleVisitor;
|
|
|
|
begin
|
2007-12-10 16:13:05 +00:00
|
|
|
Result := TCmpSwStyleVisitor.Create(ilsTypes);
|
2007-12-09 12:02:11 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|