2007-12-09 12:02:11 +00:00
|
|
|
unit CmpSwDialog;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
ActnList,
|
|
|
|
Classes,
|
|
|
|
ComCtrls,
|
|
|
|
Controls,
|
|
|
|
ExtCtrls,
|
2007-12-10 20:29:57 +00:00
|
|
|
Graphics,
|
2007-12-09 12:02:11 +00:00
|
|
|
ImgList,
|
2007-12-10 16:13:05 +00:00
|
|
|
IniFiles,
|
2007-12-09 12:02:11 +00:00
|
|
|
Menus,
|
|
|
|
StdCtrls,
|
2007-12-10 20:29:57 +00:00
|
|
|
Windows,
|
2007-12-09 12:02:11 +00:00
|
|
|
|
|
|
|
BaseSwDialog,
|
2007-12-10 20:29:57 +00:00
|
|
|
BaseSwObjects,
|
|
|
|
CmpSwFilters;
|
2007-12-09 12:02:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
2007-12-10 20:29:57 +00:00
|
|
|
procedure ResizeBitmap(const ABitmap: Graphics.TBitmap; const AWidth, AHeight: Integer);
|
2007-12-10 16:13:05 +00:00
|
|
|
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)
|
2007-12-10 20:29:57 +00:00
|
|
|
private
|
|
|
|
FClassFilteredList: TBaseSwItemList;
|
|
|
|
FClassFilter: TCmpSwComponentClassFilter;
|
2007-12-09 12:02:11 +00:00
|
|
|
protected
|
2007-12-10 20:29:57 +00:00
|
|
|
function InternalExecute(): TBaseSwItemList; override;
|
|
|
|
|
2007-12-09 12:02:11 +00:00
|
|
|
function CreateStyleVisitor(): TBaseSwStyleVisitor; override;
|
2007-12-10 20:29:57 +00:00
|
|
|
function GetBaseItemList(): TBaseSwItemList; override;
|
|
|
|
|
|
|
|
procedure DrawItemText(ACanvas: TCanvas; AItem: TBaseSwItem; ARect: TRect); override;
|
|
|
|
|
|
|
|
procedure UpdateClassFilter();
|
2007-12-09 12:02:11 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
2007-12-10 16:13:05 +00:00
|
|
|
uses
|
|
|
|
SysUtils,
|
|
|
|
ToolsAPI,
|
|
|
|
|
|
|
|
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
|
2007-12-10 20:29:57 +00:00
|
|
|
ImageIndex := -1;
|
2007-12-10 16:13:05 +00:00
|
|
|
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
|
2007-12-10 20:29:57 +00:00
|
|
|
Result := packageServices.PackageNames[packageIndex];
|
|
|
|
|
|
|
|
{ Delphi 7 doesn't add the .bpl extension, BDS 2006 does, let's just
|
|
|
|
take the safe route and check }
|
|
|
|
if not SameText(ExtractFileExt(Result), '.bpl') then
|
|
|
|
Result := Result + '.bpl';
|
|
|
|
|
2007-12-10 16:13:05 +00:00
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TCmpSwStyleVisitor.LoadComponentImage(const APackageName, AClassName: String): Integer;
|
|
|
|
var
|
|
|
|
packageHandle: THandle;
|
|
|
|
bitmapHandle: THandle;
|
2007-12-10 20:29:57 +00:00
|
|
|
bitmap: Graphics.TBitmap;
|
2007-12-10 16:13:05 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
packageHandle := LoadLibrary(PChar(APackageName));
|
|
|
|
|
|
|
|
if packageHandle <> 0 then
|
|
|
|
try
|
2007-12-10 20:29:57 +00:00
|
|
|
{ BDS includes 16x16 versions of the component bitmaps, try those first }
|
|
|
|
bitmapHandle := LoadBitmap(packageHandle, PChar(AClassName + '16'));
|
|
|
|
if bitmapHandle = 0 then
|
|
|
|
bitmapHandle := LoadBitmap(packageHandle, PChar(AClassName));
|
|
|
|
|
2007-12-10 16:13:05 +00:00
|
|
|
if bitmapHandle <> 0 then
|
|
|
|
begin
|
2007-12-10 20:29:57 +00:00
|
|
|
bitmap := Graphics.TBitmap.Create();
|
|
|
|
try
|
|
|
|
bitmap.Handle := bitmapHandle;
|
|
|
|
|
|
|
|
if (bitmap.Width <> FImageList.Width) or
|
|
|
|
(bitmap.Height <> FImageList.Height) then
|
|
|
|
begin
|
|
|
|
ResizeBitmap(bitmap, FImageList.Width, FImageList.Height);
|
|
|
|
end;
|
|
|
|
|
|
|
|
Result := FImageList.AddMasked(bitmap, bitmap.TransparentColor);
|
|
|
|
finally
|
|
|
|
FreeAndNil(bitmap);
|
|
|
|
end;
|
2007-12-10 16:13:05 +00:00
|
|
|
end;
|
|
|
|
finally
|
|
|
|
FreeLibrary(packageHandle);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Result = -1 then
|
|
|
|
Result := -2;
|
|
|
|
|
|
|
|
FImageMap.Add(AClassName, Result);
|
2007-12-09 12:02:11 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-12-10 20:29:57 +00:00
|
|
|
procedure TCmpSwStyleVisitor.ResizeBitmap(const ABitmap: Graphics.TBitmap;
|
|
|
|
const AWidth, AHeight: Integer);
|
|
|
|
var
|
|
|
|
tempBitmap: Graphics.TBitmap;
|
|
|
|
|
|
|
|
begin
|
|
|
|
tempBitmap := Graphics.TBitmap.Create();
|
|
|
|
try
|
|
|
|
tempBitmap.PixelFormat := pf24bit;
|
|
|
|
tempBitmap.Width := AWidth;
|
|
|
|
tempBitmap.Height := AHeight;
|
|
|
|
|
|
|
|
tempBitmap.Canvas.CopyRect(Rect(0, 0, AWidth, AHeight), ABitmap.Canvas,
|
|
|
|
Rect(0, 0, ABitmap.Width, ABitmap.Height));
|
|
|
|
|
|
|
|
ABitmap.Assign(tempBitmap);
|
|
|
|
finally
|
|
|
|
FreeAndNil(tempBitmap);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-12-09 12:02:11 +00:00
|
|
|
{ TfrmCmpSwDialog }
|
2007-12-10 20:29:57 +00:00
|
|
|
function TfrmCmpSwDialog.InternalExecute(): TBaseSwItemList;
|
|
|
|
begin
|
|
|
|
FClassFilteredList := TBaseSwItemList.Create();
|
|
|
|
FClassFilter := TCmpSwComponentClassFilter.Create();
|
|
|
|
try
|
|
|
|
UpdateClassFilter();
|
|
|
|
Result := inherited InternalExecute();
|
|
|
|
finally
|
|
|
|
FreeAndNil(FClassFilter);
|
|
|
|
FreeAndNil(FClassFilteredList);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-12-09 12:02:11 +00:00
|
|
|
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;
|
|
|
|
|
2007-12-10 20:29:57 +00:00
|
|
|
|
|
|
|
procedure TfrmCmpSwDialog.DrawItemText(ACanvas: TCanvas; AItem: TBaseSwItem; ARect: TRect);
|
|
|
|
var
|
|
|
|
text: String;
|
|
|
|
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
ACanvas.Font.Color := clGrayText;
|
|
|
|
text := (AItem as TCmpSwComponent).ComponentClass;
|
|
|
|
|
|
|
|
DrawText(ACanvas.Handle, PChar(text), Length(text), ARect, DT_SINGLELINE or
|
|
|
|
DT_RIGHT or DT_VCENTER);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TfrmCmpSwDialog.UpdateClassFilter();
|
|
|
|
begin
|
|
|
|
// FClassFilteredList.Clone(ItemList);
|
|
|
|
// FClassFilter.FilterList(FClassFilteredList);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TfrmCmpSwDialog.GetBaseItemList(): TBaseSwItemList;
|
|
|
|
begin
|
|
|
|
// Result := FClassFilteredList;
|
|
|
|
Result := inherited GetBaseItemList;
|
|
|
|
end;
|
|
|
|
|
2007-12-09 12:02:11 +00:00
|
|
|
end.
|