spktoolbar: Support shortcuts in TSpkPopupMenu items.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8728 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-02-22 13:44:18 +00:00
parent b97dbe66dd
commit 4e512b8b93

View File

@ -5,7 +5,8 @@ unit SpkPopup;
interface
uses
LCLIntf, LCLType, Types, SysUtils, Classes, Controls, Graphics, Menus, StdCtrls,
LCLIntf, LCLType, LCLProc,
Types, SysUtils, Classes, Controls, Graphics, Menus, StdCtrls,
spkt_Const, SpkGUITools, SpkMath, SpkGraphTools, spkt_Appearance;
type
@ -47,11 +48,12 @@ var
P: T2DIntPoint;
R, Rgutter, Rcheck: T2DIntRect;
Radius: Integer;
x, y, wGutter, hText: Integer;
x, y, wGutter, hText, wText: Integer;
iconSize: TSize;
checkboxSize: TSize;
isHot: Boolean;
te: TThemedElementDetails;
shortCutText: String;
begin
if FAppearance = nil then
exit;
@ -68,7 +70,7 @@ begin
ARect.Left,
ARect.Top,
ARect.Right,
ARect.Bottom
ARect.Bottom - 1
);
isHot := AState * [odSelected, odHotLight] <>[];
if not menuItem.Enabled then isHot := false;
@ -132,7 +134,7 @@ begin
ARect.Left,
ARect.Top,
ARect.Left + wGutter,
ARect.Bottom// - 1
ARect.Bottom - 1
);
FrameColor := FAppearance.Popup.CheckedFrameColor;
ColorFrom := FAppearance.Popup.CheckedGradientFromColor;
@ -206,7 +208,7 @@ begin
x := wGutter;
inc(x, DropdownMenuMargin*2);
if (menuItem.Caption = '-') or (menuItem.Caption = '|') then
if menuItem.IsLine then
begin
if FAppearance.Popup.Style <> psGutter then
x := DropDownMenuMargin;
@ -215,7 +217,16 @@ begin
end else
begin
y := (ARect.Top + ARect.Bottom - hText) div 2;
TGUITools.DrawText(ACanvas, x, y, menuItem.Caption, TextColor);
if menuItem.ShortCut <> 0 then
begin
shortCutText := ShortCutToText(menuItem.ShortCut);
wText := ACanvas.TextWidth(shortCutText);
TGUITools.DrawText(ACanvas, ARect.Right - wText - DropdownMenuMargin, y, shortcutText, TextColor);
end else
wText := 0;
R.Right := ARect.Right - wText; // ClipRect
TGUITools.DrawText(ACanvas, x, y, menuItem.Caption, TextColor, R);
end;
end;
end;