IDEIntf: Fix scaling of action names listbox in ActionList component editor

(cherry picked from commit 0f2d6ec40d)
This commit is contained in:
wp_xyz 2024-12-30 12:06:31 +01:00
parent f3c47a1f6a
commit dc4fd8af5c
2 changed files with 58 additions and 34 deletions

View File

@ -9,14 +9,14 @@ object ActionListEditor: TActionListEditor
ClientHeight = 315 ClientHeight = 315
ClientWidth = 404 ClientWidth = 404
KeyPreview = True KeyPreview = True
Position = poScreenCenter
LCLVersion = '4.99.0.0'
OnClose = ActionListEditorClose OnClose = ActionListEditorClose
OnCreate = FormCreate OnCreate = FormCreate
OnHide = FormHide OnHide = FormHide
OnKeyDown = ActionListEditorKeyDown OnKeyDown = ActionListEditorKeyDown
OnKeyPress = ActionListEditorKeyPress OnKeyPress = ActionListEditorKeyPress
OnShow = FormShow OnShow = FormShow
Position = poScreenCenter
LCLVersion = '2.3.0.0'
object PanelDescr: TPanel object PanelDescr: TPanel
Left = 0 Left = 0
Height = 26 Height = 26
@ -52,22 +52,6 @@ object ActionListEditor: TActionListEditor
AutoSnap = False AutoSnap = False
OnCanResize = SplitterCanResize OnCanResize = SplitterCanResize
end end
object lstActionName: TListBox
Left = 157
Height = 261
Top = 54
Width = 247
Align = alClient
ItemHeight = 0
OnClick = lstActionNameClick
OnDblClick = lstActionNameDblClick
OnDrawItem = lstActionNameDrawItem
OnKeyDown = lstActionNameKeyDown
OnMouseDown = lstActionNameMouseDown
PopupMenu = PopMenuActions
Style = lbOwnerDrawFixed
TabOrder = 1
end
object lstCategory: TListBox object lstCategory: TListBox
Left = 0 Left = 0
Height = 261 Height = 261
@ -75,10 +59,10 @@ object ActionListEditor: TActionListEditor
Width = 152 Width = 152
Align = alLeft Align = alLeft
ItemHeight = 0 ItemHeight = 0
PopupMenu = PopMenuActions
TabOrder = 1
OnClick = lstCategoryClick OnClick = lstCategoryClick
OnMouseDown = lstActionNameMouseDown OnMouseDown = lstActionNameMouseDown
PopupMenu = PopMenuActions
TabOrder = 2
end end
object ToolBar1: TToolBar object ToolBar1: TToolBar
Left = 0 Left = 0
@ -93,7 +77,7 @@ object ActionListEditor: TActionListEditor
EdgeOuter = esNone EdgeOuter = esNone
ParentShowHint = False ParentShowHint = False
ShowHint = True ShowHint = True
TabOrder = 4 TabOrder = 3
object btnAdd: TToolButton object btnAdd: TToolButton
Left = 1 Left = 1
Top = 0 Top = 0
@ -114,12 +98,12 @@ object ActionListEditor: TActionListEditor
Style = tbsDivider Style = tbsDivider
end end
object btnUp: TToolButton object btnUp: TToolButton
Left = 70 Left = 68
Top = 0 Top = 0
Action = ActMoveUp Action = ActMoveUp
end end
object btnDown: TToolButton object btnDown: TToolButton
Left = 96 Left = 94
Top = 0 Top = 0
Action = ActMoveDown Action = ActMoveDown
end end
@ -129,31 +113,31 @@ object ActionListEditor: TActionListEditor
Top = 260 Top = 260
object ActDelete: TAction object ActDelete: TAction
Category = 'AddDelete' Category = 'AddDelete'
ShortCut = 46
OnExecute = ActDeleteExecute OnExecute = ActDeleteExecute
OnUpdate = ActDeleteUpdate OnUpdate = ActDeleteUpdate
ShortCut = 46
end end
object ActNew: TAction object ActNew: TAction
Category = 'AddDelete' Category = 'AddDelete'
OnExecute = ActNewExecute
ShortCut = 45 ShortCut = 45
OnExecute = ActNewExecute
end end
object ActNewStd: TAction object ActNewStd: TAction
Category = 'AddDelete' Category = 'AddDelete'
OnExecute = ActNewStdExecute
ShortCut = 16429 ShortCut = 16429
OnExecute = ActNewStdExecute
end end
object ActMoveUp: TAction object ActMoveUp: TAction
Category = 'MoveUpDown' Category = 'MoveUpDown'
ShortCut = 16422
OnExecute = ActMoveUpDownExecute OnExecute = ActMoveUpDownExecute
OnUpdate = ActMoveUpUpdate OnUpdate = ActMoveUpUpdate
ShortCut = 16422
end end
object ActMoveDown: TAction object ActMoveDown: TAction
Category = 'MoveUpDown' Category = 'MoveUpDown'
ShortCut = 16424
OnExecute = ActMoveUpDownExecute OnExecute = ActMoveUpDownExecute
OnUpdate = ActMoveDownUpdate OnUpdate = ActMoveDownUpdate
ShortCut = 16424
end end
object ActPanelDescr: TAction object ActPanelDescr: TAction
Category = 'Panels' Category = 'Panels'

View File

@ -88,7 +88,6 @@ type
lblCategory: TLabel; lblCategory: TLabel;
lblName: TLabel; lblName: TLabel;
lstCategory: TListBox; lstCategory: TListBox;
lstActionName: TListBox;
MenuItem1: TMenuItem; MenuItem1: TMenuItem;
MenuItem2: TMenuItem; MenuItem2: TMenuItem;
mItemActListPanelDescr: TMenuItem; mItemActListPanelDescr: TMenuItem;
@ -151,6 +150,7 @@ type
FActionList: TActionList; FActionList: TActionList;
FCompDesigner: TComponentEditorDesigner; FCompDesigner: TComponentEditorDesigner;
FCompEditor: TActionListComponentEditor; FCompEditor: TActionListComponentEditor;
lstActionName: TListbox;
procedure AddCategoryActions(aCategory: String); procedure AddCategoryActions(aCategory: String);
function CategoryIndexOf(Category: String): Integer; function CategoryIndexOf(Category: String): Integer;
function IsValidCategory(Category: String): Boolean; function IsValidCategory(Category: String): Boolean;
@ -263,7 +263,28 @@ implementation
var var
EditorForms : TList = nil; EditorForms : TList = nil;
type
TImgListbox = class(TListbox)
private
FImages: TCustomImageList;
public
function CalculateStandardItemHeight: Integer; override;
property Images: TCustomImageList read FImages write FImages;
end;
function TImgListbox.CalculateStandardItemHeight: Integer;
var
hImg: Integer;
begin
Result := inherited;
if Assigned(FImages) and (Style <> lbOwnerDrawVariable) then
begin
hImg := FImages.HeightForPPI[0, Font.PixelsPerInch] + 4;
if hImg > Result then Result := hImg;
end;
end;
procedure InitFormsList; procedure InitFormsList;
begin begin
EditorForms:=TList.Create; EditorForms:=TList.Create;
@ -412,6 +433,20 @@ end;
procedure TActionListEditor.FormCreate(Sender: TObject); procedure TActionListEditor.FormCreate(Sender: TObject);
begin begin
lstActionName := TImgListbox.Create(self);
with TImgListbox(lstActionName) do
begin
Parent := self;
Align := alClient;
PopupMenu := PopMenuActions;
Style := lbOwnerDrawFixed;
OnClick := @lstActionNameClick;
OnDblClick := @lstActionNameDblClick;
OnDrawItem := @lstActionNameDrawItem;
OnKeyDown := @lstActionNameKeyDown;
OnMouseDown := @lstActionNameMouseDown;
end;
ToolBar1.Images := IDEImages.Images_16; ToolBar1.Images := IDEImages.Images_16;
btnAdd.ImageIndex := IDEImages.GetImageIndex('laz_add'); btnAdd.ImageIndex := IDEImages.GetImageIndex('laz_add');
btnDelete.ImageIndex := IDEImages.GetImageIndex('laz_delete'); btnDelete.ImageIndex := IDEImages.GetImageIndex('laz_delete');
@ -762,6 +797,8 @@ var
ACanvas: TCanvas; ACanvas: TCanvas;
R: TRect; R: TRect;
dh: Integer; dh: Integer;
hImg: Integer;
ppi: Integer;
Imgs: TCustomImageList; Imgs: TCustomImageList;
AAction: TCustomAction; AAction: TCustomAction;
S: String; S: String;
@ -788,11 +825,15 @@ begin
AAction := TCustomAction(lb.Items.Objects[Index]); AAction := TCustomAction(lb.Items.Objects[Index]);
R.Right := R.Left + dh; R.Right := R.Left + dh;
if AAction.ImageIndex <> -1 then if AAction.ImageIndex <> -1 then
Imgs.Draw(ACanvas, R.Left, R.Top + (dh-Imgs.Height) div 2, AAction.ImageIndex); begin
ppi := lb.Font.PixelsPerInch;
hImg := Imgs.HeightForPPI[0, ppi];
Imgs.DrawForPPI(ACanvas, R.Left, R.Top + (dh-hImg) div 2, AAction.ImageIndex, 0, ppi, lb.GetCanvasScaleFactor);
end;
Inc(R.Left, dh + 2); Inc(R.Left, dh + 2);
end; end;
S := lb.Items[Index]; S := lb.Items[Index];
ACanvas.TextOut(R.Left, R.Top + (dh-Canvas.TextHeight(S)) div 2, S); ACanvas.TextOut(R.Left, R.Top + (dh-ACanvas.TextHeight(S)) div 2, S);
if odFocused in State then if odFocused in State then
ACanvas.DrawFocusRect(ARect); ACanvas.DrawFocusRect(ARect);
end; end;
@ -908,8 +949,7 @@ begin
if FActionList<>nil then if FActionList<>nil then
begin begin
FreeNotification(FActionList); FreeNotification(FActionList);
if FActionList.Images<>nil then (lstActionName as TImgListbox).Images := FActionList.Images;
lstActionName.ItemHeight := FActionList.Images.Height + Scale96ToFont(4);
end; end;
FillCategories; FillCategories;
//FillActionByCategory(-1); //FillActionByCategory(-1);