diff --git a/Lib/D7/UnitSwitcherD7.bpl b/Lib/D7/UnitSwitcherD7.bpl index 6c75a88..a701239 100644 Binary files a/Lib/D7/UnitSwitcherD7.bpl and b/Lib/D7/UnitSwitcherD7.bpl differ diff --git a/Packages/D7/UnitSwitcher.dpk b/Packages/D7/UnitSwitcher.dpk index 64cd323..40ffae4 100644 --- a/Packages/D7/UnitSwitcher.dpk +++ b/Packages/D7/UnitSwitcher.dpk @@ -47,6 +47,8 @@ contains UnSwReg in '..\..\Source\UnSwReg.pas', BaseSwObjects in '..\..\Source\BaseSwObjects.pas', BaseSwFilters in '..\..\Source\BaseSwFilters.pas', - BaseSwDialog in '..\..\Source\BaseSwDialog.pas' {frmBaseSwDialog}; + BaseSwDialog in '..\..\Source\BaseSwDialog.pas' {frmBaseSwDialog}, + CmpSwObjects in '..\..\Source\CmpSwObjects.pas', + CmpSwDialog in '..\..\Source\CmpSwDialog.pas' {frmCmpSwDialog}; end. diff --git a/Source/BaseSwDialog.dfm b/Source/BaseSwDialog.dfm index 8fb3bc3..28087b6 100644 --- a/Source/BaseSwDialog.dfm +++ b/Source/BaseSwDialog.dfm @@ -1,10 +1,10 @@ object frmBaseSwDialog: TfrmBaseSwDialog Left = 284 Top = 120 + Width = 320 + Height = 425 BorderIcons = [biSystemMenu] Caption = 'UnitSwitcher' - ClientHeight = 398 - ClientWidth = 312 Color = clBtnFace Constraints.MinHeight = 240 Constraints.MinWidth = 290 diff --git a/Source/CmpSwDialog.dfm b/Source/CmpSwDialog.dfm index ff6598a..f000a87 100644 --- a/Source/CmpSwDialog.dfm +++ b/Source/CmpSwDialog.dfm @@ -4,148 +4,11 @@ inherited frmCmpSwDialog: TfrmCmpSwDialog TextHeight = 13 inherited pnlMain: TPanel inherited lstItems: TListBox - ExplicitTop = 47 + ItemHeight = 30 end end inherited ilsTypes: TImageList - Bitmap = { - 494C010101000200040010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600 - 0000000000003600000028000000400000001000000001002000000000000010 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 00000000000000000000000000000000000000000000000000002C7C2C001274 - 1200729872000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000005990 - AC0010719F000673A6005A8FB40066A0660018801800007E000000870000078F - 0C00006E00004F8D4F0000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 00000000000000000000000000000000000000000000639AB2000679AC000082 - B5000091C3000D84B3000064AD0000811000008F000001970100049E080019AC - 270000720000006E00004E874E00000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 00000000000000000000000000000000000000000000218EB500009BCE0000A0 - D40000AADD001B90BA000064AD00059417000CA8150012AB260018B1320030C7 - 52000072000000720000317E3100000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 000000000000000000000000000000000000000000001A97C50000AFE30000B3 - E60009C3F400249BC200006BB200129C370020BB3D0025BE4A0028C2560044DE - 7500007E0000007E0000257C2500000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000012A3D30000C2F80000C9 - FD000DE5FF0029A0C7000070B60014A24F0032DB6C003FDB760052EB88006AFF - A300078F0C00007E0000187B1800000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 000000000000000000000000000000000000000000000BBFE10001F9FF0027FF - FF0036FFFF0029E2FF00007ABA00476A2B00819542005FFF980055FF920051F0 - 7E0053EE7D0020BB3D000D7B0D00000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000026B9CD0012DCFD0000D6 - FF003D979C009B591C00CB460000CC510000BA410000A8270000767223002CC5 - 43001AB42D0036B03E0067A46900000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 00000000000000000000000000000000000000000000000000000000000048A2 - C700C3660700DC680000D56D0000D9720000BE611800A9410000AA3300009E39 - 1100000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000DC680000E0790000E0790000E67F0000CB702400A9410000A9410000B341 - 0B00000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000E7800000EC860000EC860000F38B0000D47F3000B44E0000AE480000B344 - 0400000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000F38B0000FD940000FD940000FF9B0000DE8D3B00B84D0000B44E0000A941 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000FFB65400FFC77600FFCA8600FFCF9500F6BB7F00D47F2E00BF5C0800B44E - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000C0936B00C9936200CE8B4F00CF813900CB7B3600C57B3B00C07E4C00B77A - 5300000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 0000000000000000000000000000000000000000000000000000000000000000 - 000000000000000000000000000000000000424D3E000000000000003E000000 - 2800000040000000100000000100010000000000800000000000000000000000 - 000000000000000000000000FFFFFF00FFFF000000000000FFC7000000000000 - E003000000000000800100000000000080010000000000008001000000000000 - 800100000000000080010000000000008001000000000000E00F000000000000 - F00F000000000000F00F000000000000F00F000000000000F00F000000000000 - F00F000000000000FFFF00000000000000000000000000000000000000000000 - 000000000000} + Height = 24 + Width = 24 end end diff --git a/Source/CmpSwDialog.pas b/Source/CmpSwDialog.pas index f1bbb04..e97601d 100644 --- a/Source/CmpSwDialog.pas +++ b/Source/CmpSwDialog.pas @@ -8,6 +8,7 @@ uses Controls, ExtCtrls, ImgList, + IniFiles, Menus, StdCtrls, @@ -17,11 +18,20 @@ uses type TCmpSwStyleVisitor = class(TBaseSwStyleVisitor) + private + FImageList: TImageList; + FImageMap: TStringHash; protected procedure VisitItem(const AItem: TBaseSwItem); override; + + function GetComponentPackage(const AClassName: String): String; + function LoadComponentImage(const APackageName, AClassName: String): Integer; + public + constructor Create(AImageList: TImageList); + destructor Destroy(); override; end; - + TfrmCmpSwDialog = class(TfrmBaseSwDialog) protected function CreateStyleVisitor(): TBaseSwStyleVisitor; override; @@ -29,24 +39,119 @@ type implementation +uses + CommCtrl, + SysUtils, + ToolsAPI, + Windows, + + CmpSwObjects; {$R *.dfm} { TCmpSwStyleVisitor } +constructor TCmpSwStyleVisitor.Create(AImageList: TImageList); +begin + inherited Create(); + + FImageList := AImageList; + FImageMap := TStringHash.Create(); +end; + + +destructor TCmpSwStyleVisitor.Destroy(); +begin + FreeAndNil(FImageMap); + + inherited; +end; + + procedure TCmpSwStyleVisitor.VisitItem(const AItem: TBaseSwItem); +var + component: TCmpSwComponent; + package: String; + begin inherited; - ImageIndex := 0; + 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); end; { TfrmCmpSwDialog } function TfrmCmpSwDialog.CreateStyleVisitor(): TBaseSwStyleVisitor; begin - Result := TCmpSwStyleVisitor.Create(); + Result := TCmpSwStyleVisitor.Create(ilsTypes); end; end. diff --git a/Source/CmpSwObjects.pas b/Source/CmpSwObjects.pas index d56be05..00e79e1 100644 --- a/Source/CmpSwObjects.pas +++ b/Source/CmpSwObjects.pas @@ -10,16 +10,18 @@ uses type TCmpSwComponent = class(TBaseSwItem) private - FComponent: IOTAComponent; - FName: String; + FComponent: IOTAComponent; + FComponentClass: String; + FName: String; protected function GetName(): String; override; public constructor Create(AComponent: IOTAComponent); - - procedure Activate(const AClearSelection: Boolean); - class function TryCreate(AComponent: IOTAComponent): TCmpSwComponent; + + procedure Activate(const AClearSelection: Boolean); + + property ComponentClass: String read FComponentClass; end; @@ -41,8 +43,9 @@ constructor TCmpSwComponent.Create(AComponent: IOTAComponent); begin inherited Create(); - FComponent := AComponent; + FComponent := AComponent; FComponent.GetPropValueByName('Name', FName); + FComponentClass := FComponent.GetComponentType(); end; diff --git a/Source/UnSwDialog.dfm b/Source/UnSwDialog.dfm index fefc1c7..158b77e 100644 --- a/Source/UnSwDialog.dfm +++ b/Source/UnSwDialog.dfm @@ -1,14 +1,10 @@ inherited frmUnSwDialog: TfrmUnSwDialog - ExplicitHeight = 425 PixelsPerInch = 96 TextHeight = 13 inherited pnlMain: TPanel Height = 307 - ExplicitHeight = 307 inherited lstItems: TListBox Height = 254 - ExplicitTop = 47 - ExplicitHeight = 254 end end inherited pnlButtons: TPanel @@ -73,7 +69,7 @@ inherited frmUnSwDialog: TfrmUnSwDialog end inherited ilsTypes: TImageList Bitmap = { - 494C010106000900040010001000FFFFFFFFFF00FFFFFFFFFFFFFFFF424D3600 + 494C010106000900040010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600 0000000000003600000028000000400000003000000001002000000000000030 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 @@ -473,7 +469,8 @@ inherited frmUnSwDialog: TfrmUnSwDialog E000E0000000AC0FE000E0000000BF3FE000E0000000FFFFE000600000001000 E000200000001000E00000000000B000E00020000000F000E00060000000F000 E000E0000000F000E000E0000000F000E000E0000000F000E001E0010000F000 - E003E003FFFFF000E007E007FFFFF000} + E003E003FFFFF000E007E007FFFFF00000000000000000000000000000000000 + 000000000000} end inherited alMain: TActionList object actSortByName: TAction