Skip to content

Commit

Permalink
Improved focus behavior for TEsImageControl, TEsVirtualImageControl a…
Browse files Browse the repository at this point in the history
…nd TEsPaintBox. Improved keyboard support for TEsPaintBox.
  • Loading branch information
errorcalc committed Dec 23, 2023
1 parent 99a2fcd commit fede80a
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 8 deletions.
132 changes: 131 additions & 1 deletion Samples/Image/ImagesTest.dproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{2BB64C94-AACA-40C4-B562-C34CC63010C6}</ProjectGuid>
<ProjectVersion>19.5</ProjectVersion>
<ProjectVersion>20.1</ProjectVersion>
<FrameworkType>VCL</FrameworkType>
<MainSource>ImagesTest.dpr</MainSource>
<Base>True</Base>
Expand Down Expand Up @@ -220,6 +220,16 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidSplashImageDefV21">
<Platform Name="Android">
<RemoteDir>res\drawable-anydpi-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-anydpi-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidSplashStyles">
<Platform Name="Android">
<RemoteDir>res\values</RemoteDir>
Expand All @@ -240,6 +250,66 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidSplashStylesV31">
<Platform Name="Android">
<RemoteDir>res\values-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\values-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_AdaptiveIcon">
<Platform Name="Android">
<RemoteDir>res\drawable-anydpi-v26</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-anydpi-v26</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_AdaptiveIconBackground">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_AdaptiveIconForeground">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_AdaptiveIconMonochrome">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_AdaptiveIconV33">
<Platform Name="Android">
<RemoteDir>res\drawable-anydpi-v33</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-anydpi-v33</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_Colors">
<Platform Name="Android">
<RemoteDir>res\values</RemoteDir>
Expand All @@ -250,6 +320,16 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_ColorsDark">
<Platform Name="Android">
<RemoteDir>res\values-night-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\values-night-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_DefaultAppIcon">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
Expand Down Expand Up @@ -420,6 +500,56 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_VectorizedNotificationIcon">
<Platform Name="Android">
<RemoteDir>res\drawable-anydpi-v24</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-anydpi-v24</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_VectorizedSplash">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_VectorizedSplashDark">
<Platform Name="Android">
<RemoteDir>res\drawable-night-anydpi-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-night-anydpi-v21</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_VectorizedSplashV31">
<Platform Name="Android">
<RemoteDir>res\drawable-anydpi-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-anydpi-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_VectorizedSplashV31Dark">
<Platform Name="Android">
<RemoteDir>res\drawable-night-anydpi-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Android64">
<RemoteDir>res\drawable-night-anydpi-v31</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="DebugSymbols">
<Platform Name="iOSSimulator">
<Operation>1</Operation>
Expand Down
Binary file modified Samples/Image/ImagesTest.res
Binary file not shown.
15 changes: 10 additions & 5 deletions Samples/Image/Main.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ object MainForm: TMainForm
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Image3: TImage
Left = 336
Expand Down Expand Up @@ -2952,9 +2950,11 @@ object MainForm: TMainForm
Top = 0
Width = 770
Height = 605
ActivePage = TabSheet1
ActivePage = TabSheet4
Align = alClient
TabOrder = 0
ExplicitWidth = 764
ExplicitHeight = 586
object TabSheet1: TTabSheet
Caption = 'Smothing'
object Shape2: TShape
Expand Down Expand Up @@ -11434,15 +11434,18 @@ object MainForm: TMainForm
object Label21: TLabel
Left = 8
Top = 5
Width = 151
Width = 320
Height = 13
Caption = 'Focus support: (press TAB key)'
Caption =
'Focus support: Press TAB key for Focus, and SPACE key for "Click' +
'"'
end
object EsImageControl14: TEsImageControl
Left = 8
Top = 24
Width = 209
Height = 73
AllowFocus = True
Picture.Data = {
0954506E67496D61676589504E470D0A1A0A0000000D49484452000000A60000
0038080600000077E483440000000473424954080808087C0864880000000970
Expand Down Expand Up @@ -11879,6 +11882,7 @@ object MainForm: TMainForm
Top = 24
Width = 209
Height = 73
AllowFocus = True
Picture.Data = {
0954506E67496D61676589504E470D0A1A0A0000000D49484452000000A60000
0038080600000077E483440000000473424954080808087C0864880000000970
Expand Down Expand Up @@ -12116,6 +12120,7 @@ object MainForm: TMainForm
Top = 24
Width = 209
Height = 73
AllowFocus = True
Picture.Data = {
0954506E67496D61676589504E470D0A1A0A0000000D49484452000000A60000
0038080600000077E483440000000473424954080808087C0864880000000970
Expand Down
49 changes: 47 additions & 2 deletions Source/ES.Images.pas
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ TEsImageControl = class(TEsBaseLayout)
FFrameWidth: TFrameWidth;
FFrameColor: TColor;
FFrameStyle: TFrameStyle;
FAllowFocus: Boolean;
function GetCanvas: TCanvas;
function GetImageIndex: TImageIndex;
function GetImages: TCustomImageList;
Expand Down Expand Up @@ -326,19 +327,22 @@ TEsImageControl = class(TEsBaseLayout)
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;
procedure PaintWindow(DC: HDC); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function CanFocus: Boolean; override;
procedure BeginDraw;
procedure EndDraw;
procedure RecreateBitmap;
property Canvas: TCanvas read GetCanvas;
published
property Align;
property AlignWithMargins;
property AllowFocus: Boolean read FAllowFocus write FAllowFocus default False;
property Anchors;
property AutoSize;
property BorderWidth;
Expand Down Expand Up @@ -393,6 +397,9 @@ TEsImageControl = class(TEsBaseLayout)
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnGesture;
property OnMouseActivate;
property OnMouseDown;
Expand Down Expand Up @@ -555,6 +562,7 @@ TEsCustomVirtualImageControl = class(TEsBaseLayout)
FFrameWidth: TFrameWidth;
FFrameColor: TColor;
FFrameStyle: TFrameStyle;
FAllowFocus: Boolean;
function GetImageCollection: TCustomImageCollection;
function GetImageHeight: Integer;
function GetImageIndex: TImageIndex;
Expand Down Expand Up @@ -583,10 +591,12 @@ TEsCustomVirtualImageControl = class(TEsBaseLayout)
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
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function CanFocus: Boolean; override;
property FrameColor: TColor read FFrameColor write SetFrameColor default clBtnShadow;
property FrameStyle: TFrameStyle read FFrameStyle write SetFrameStyle default TExFrameStyle.None;
property FrameWidth: TFrameWidth read FFrameWidth write SetFrameWidth default 1;
Expand All @@ -608,11 +618,13 @@ TEsCustomVirtualImageControl = class(TEsBaseLayout)
property Opacity: Byte read GetOpacity write SetOpacity default 255;
/// <summary> Image location </summary>
property Stretch: TImageStretch read GetStretch write SetStretch default TImageStretch.Fit;
property AllowFocus: Boolean read FAllowFocus write FAllowFocus default False;
end;

TEsVirtualImageControl = class(TEsCustomVirtualImageControl)
property Align;
property AlignWithMargins;
property AllowFocus;
property Anchors;
property BorderWidth;
property Color default clBtnFace;
Expand Down Expand Up @@ -662,6 +674,9 @@ TEsVirtualImageControl = class(TEsCustomVirtualImageControl)
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnGesture;
property OnMouseActivate;
property OnMouseDown;
Expand Down Expand Up @@ -1491,6 +1506,11 @@ function TEsImageControl.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;
NewHeight := ImageProxy.ImageHeight + ContentMargins.Height;
end;

function TEsImageControl.CanFocus: Boolean;
begin
Result := AllowFocus and Inherited;
end;

function TEsImageControl.GetOpacity: Byte;
begin
Result := ImageProxy.Opacity;
Expand Down Expand Up @@ -1592,10 +1612,20 @@ function TEsImageControl.IsImageNameStored: Boolean;
procedure TEsImageControl.KeyUp(var Key: Word; Shift: TShiftState);
begin
inherited;
if (Key = VK_SPACE) or (Key = VK_RETURN) then
if (Key = VK_SPACE) {or (Key = VK_RETURN)} then
Click;
end;

procedure TEsImageControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited;

if (Button = mbLeft) and Enabled and AllowFocus then
begin
Winapi.Windows.SetFocus(Handle);
end;
end;

procedure TEsImageControl.Loaded;
begin
inherited;
Expand Down Expand Up @@ -2287,6 +2317,11 @@ procedure TEsCustomVirtualImageControl.CalcContentMargins(
end;
end;

function TEsCustomVirtualImageControl.CanFocus: Boolean;
begin
Result := AllowFocus and Inherited;
end;

{$IFDEF VER310UP}
procedure TEsCustomVirtualImageControl.ChangeScale(M, D: Integer; isDpiChange: Boolean);
begin
Expand Down Expand Up @@ -2356,10 +2391,20 @@ function TEsCustomVirtualImageControl.IsImageNameStored: Boolean;
procedure TEsCustomVirtualImageControl.KeyUp(var Key: Word; Shift: TShiftState);
begin
inherited;
if (Key = VK_SPACE) or (Key = VK_RETURN) then
if (Key = VK_SPACE) {or (Key = VK_RETURN)} then
Click;
end;

procedure TEsCustomVirtualImageControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited;

if (Button = mbLeft) and Enabled and AllowFocus then
begin
Winapi.Windows.SetFocus(Handle);
end;
end;

procedure TEsCustomVirtualImageControl.Paint;
begin
if (csDesigning in ComponentState) and IsDrawHelper and
Expand Down
Loading

0 comments on commit fede80a

Please sign in to comment.