Skip to content

Commit

Permalink
improve focus support in TEsImageControl and TEsVirtualImageControl
Browse files Browse the repository at this point in the history
  • Loading branch information
errorcalc committed Dec 24, 2023
1 parent fede80a commit e2f95e5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Source/ES.Images.pas
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ TEsImageControl = class(TEsBaseLayout)
procedure SetTransparentGraphic(const Value: Boolean);
procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
procedure CNKeydown(var Message: TWMKeyDown); message CN_KEYDOWN;
{$IFDEF VER340UP}
function GetImageName: TImageName;
function IsImageNameStored: Boolean;
Expand All @@ -326,7 +327,6 @@ TEsImageControl = class(TEsBaseLayout)
function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override;
procedure CalcContentMargins(var Margins: TContentMargins); override;
procedure ImageProxyChange(Sender: TObject);
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure Loaded; override;
procedure Paint; override;
Expand Down Expand Up @@ -586,11 +586,11 @@ TEsCustomVirtualImageControl = class(TEsBaseLayout)
procedure SetFrameWidth(const Value: TFrameWidth);
procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
procedure CNKeydown(var Message: TWMKeyDown); message CN_KEYDOWN;
protected
procedure CalcContentMargins(var Margins: TContentMargins); override;
procedure ChangeScale(M, D: Integer; isDpiChange: Boolean); override;
procedure ImageProxyChange(Sender: TObject);
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure Paint; override;
public
Expand Down Expand Up @@ -1511,6 +1511,8 @@ function TEsImageControl.CanFocus: Boolean;
Result := AllowFocus and Inherited;
end;



function TEsImageControl.GetOpacity: Byte;
begin
Result := ImageProxy.Opacity;
Expand Down Expand Up @@ -1609,10 +1611,11 @@ function TEsImageControl.IsImageNameStored: Boolean;
end;
{$ENDIF}

procedure TEsImageControl.KeyUp(var Key: Word; Shift: TShiftState);
procedure TEsImageControl.CNKeydown(var Message: TWMKeyDown);
begin
inherited;
if (Key = VK_SPACE) {or (Key = VK_RETURN)} then

if (Message.CharCode = VK_SPACE) or (Message.CharCode = VK_RETURN) then
Click;
end;

Expand Down Expand Up @@ -1666,7 +1669,7 @@ procedure TEsImageControl.Paint;
else
DrawFrame(inherited Canvas, nil, ClientRect, FrameStyle, FrameWidth, FrameColor, clBtnHighlight, clBtnShadow);

if Focused then
if IsShowFocusRect(Self) then
begin
(inherited Canvas).Brush.Color := TColor($FF000000);
(inherited Canvas).DrawFocusRect(ContentRect);
Expand Down Expand Up @@ -2388,10 +2391,11 @@ function TEsCustomVirtualImageControl.IsImageNameStored: Boolean;
Result := ImageProxy.ImageName <> '';
end;

procedure TEsCustomVirtualImageControl.KeyUp(var Key: Word; Shift: TShiftState);
procedure TEsCustomVirtualImageControl.CNKeydown(var Message: TWMKeyDown);
begin
inherited;
if (Key = VK_SPACE) {or (Key = VK_RETURN)} then

if (Message.CharCode = VK_SPACE) or (Message.CharCode = VK_RETURN) then
Click;
end;

Expand Down Expand Up @@ -2432,7 +2436,7 @@ procedure TEsCustomVirtualImageControl.Paint;
DrawDesignStretchHint(Canvas, ClientRect, ImageProxy);
end;

if Focused then
if IsShowFocusRect(Self) then
begin
Canvas.Brush.Color := TColor($FF000000);
Canvas.DrawFocusRect(ContentRect);
Expand Down

0 comments on commit e2f95e5

Please sign in to comment.