Skip to content

Commit fede80a

Browse files
committed
Improved focus behavior for TEsImageControl, TEsVirtualImageControl and TEsPaintBox. Improved keyboard support for TEsPaintBox.
1 parent 99a2fcd commit fede80a

File tree

5 files changed

+195
-8
lines changed

5 files changed

+195
-8
lines changed

Samples/Image/ImagesTest.dproj

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<PropertyGroup>
33
<ProjectGuid>{2BB64C94-AACA-40C4-B562-C34CC63010C6}</ProjectGuid>
4-
<ProjectVersion>19.5</ProjectVersion>
4+
<ProjectVersion>20.1</ProjectVersion>
55
<FrameworkType>VCL</FrameworkType>
66
<MainSource>ImagesTest.dpr</MainSource>
77
<Base>True</Base>
@@ -220,6 +220,16 @@
220220
<Operation>1</Operation>
221221
</Platform>
222222
</DeployClass>
223+
<DeployClass Name="AndroidSplashImageDefV21">
224+
<Platform Name="Android">
225+
<RemoteDir>res\drawable-anydpi-v21</RemoteDir>
226+
<Operation>1</Operation>
227+
</Platform>
228+
<Platform Name="Android64">
229+
<RemoteDir>res\drawable-anydpi-v21</RemoteDir>
230+
<Operation>1</Operation>
231+
</Platform>
232+
</DeployClass>
223233
<DeployClass Name="AndroidSplashStyles">
224234
<Platform Name="Android">
225235
<RemoteDir>res\values</RemoteDir>
@@ -240,6 +250,66 @@
240250
<Operation>1</Operation>
241251
</Platform>
242252
</DeployClass>
253+
<DeployClass Name="AndroidSplashStylesV31">
254+
<Platform Name="Android">
255+
<RemoteDir>res\values-v31</RemoteDir>
256+
<Operation>1</Operation>
257+
</Platform>
258+
<Platform Name="Android64">
259+
<RemoteDir>res\values-v31</RemoteDir>
260+
<Operation>1</Operation>
261+
</Platform>
262+
</DeployClass>
263+
<DeployClass Name="Android_AdaptiveIcon">
264+
<Platform Name="Android">
265+
<RemoteDir>res\drawable-anydpi-v26</RemoteDir>
266+
<Operation>1</Operation>
267+
</Platform>
268+
<Platform Name="Android64">
269+
<RemoteDir>res\drawable-anydpi-v26</RemoteDir>
270+
<Operation>1</Operation>
271+
</Platform>
272+
</DeployClass>
273+
<DeployClass Name="Android_AdaptiveIconBackground">
274+
<Platform Name="Android">
275+
<RemoteDir>res\drawable</RemoteDir>
276+
<Operation>1</Operation>
277+
</Platform>
278+
<Platform Name="Android64">
279+
<RemoteDir>res\drawable</RemoteDir>
280+
<Operation>1</Operation>
281+
</Platform>
282+
</DeployClass>
283+
<DeployClass Name="Android_AdaptiveIconForeground">
284+
<Platform Name="Android">
285+
<RemoteDir>res\drawable</RemoteDir>
286+
<Operation>1</Operation>
287+
</Platform>
288+
<Platform Name="Android64">
289+
<RemoteDir>res\drawable</RemoteDir>
290+
<Operation>1</Operation>
291+
</Platform>
292+
</DeployClass>
293+
<DeployClass Name="Android_AdaptiveIconMonochrome">
294+
<Platform Name="Android">
295+
<RemoteDir>res\drawable</RemoteDir>
296+
<Operation>1</Operation>
297+
</Platform>
298+
<Platform Name="Android64">
299+
<RemoteDir>res\drawable</RemoteDir>
300+
<Operation>1</Operation>
301+
</Platform>
302+
</DeployClass>
303+
<DeployClass Name="Android_AdaptiveIconV33">
304+
<Platform Name="Android">
305+
<RemoteDir>res\drawable-anydpi-v33</RemoteDir>
306+
<Operation>1</Operation>
307+
</Platform>
308+
<Platform Name="Android64">
309+
<RemoteDir>res\drawable-anydpi-v33</RemoteDir>
310+
<Operation>1</Operation>
311+
</Platform>
312+
</DeployClass>
243313
<DeployClass Name="Android_Colors">
244314
<Platform Name="Android">
245315
<RemoteDir>res\values</RemoteDir>
@@ -250,6 +320,16 @@
250320
<Operation>1</Operation>
251321
</Platform>
252322
</DeployClass>
323+
<DeployClass Name="Android_ColorsDark">
324+
<Platform Name="Android">
325+
<RemoteDir>res\values-night-v21</RemoteDir>
326+
<Operation>1</Operation>
327+
</Platform>
328+
<Platform Name="Android64">
329+
<RemoteDir>res\values-night-v21</RemoteDir>
330+
<Operation>1</Operation>
331+
</Platform>
332+
</DeployClass>
253333
<DeployClass Name="Android_DefaultAppIcon">
254334
<Platform Name="Android">
255335
<RemoteDir>res\drawable</RemoteDir>
@@ -420,6 +500,56 @@
420500
<Operation>1</Operation>
421501
</Platform>
422502
</DeployClass>
503+
<DeployClass Name="Android_VectorizedNotificationIcon">
504+
<Platform Name="Android">
505+
<RemoteDir>res\drawable-anydpi-v24</RemoteDir>
506+
<Operation>1</Operation>
507+
</Platform>
508+
<Platform Name="Android64">
509+
<RemoteDir>res\drawable-anydpi-v24</RemoteDir>
510+
<Operation>1</Operation>
511+
</Platform>
512+
</DeployClass>
513+
<DeployClass Name="Android_VectorizedSplash">
514+
<Platform Name="Android">
515+
<RemoteDir>res\drawable</RemoteDir>
516+
<Operation>1</Operation>
517+
</Platform>
518+
<Platform Name="Android64">
519+
<RemoteDir>res\drawable</RemoteDir>
520+
<Operation>1</Operation>
521+
</Platform>
522+
</DeployClass>
523+
<DeployClass Name="Android_VectorizedSplashDark">
524+
<Platform Name="Android">
525+
<RemoteDir>res\drawable-night-anydpi-v21</RemoteDir>
526+
<Operation>1</Operation>
527+
</Platform>
528+
<Platform Name="Android64">
529+
<RemoteDir>res\drawable-night-anydpi-v21</RemoteDir>
530+
<Operation>1</Operation>
531+
</Platform>
532+
</DeployClass>
533+
<DeployClass Name="Android_VectorizedSplashV31">
534+
<Platform Name="Android">
535+
<RemoteDir>res\drawable-anydpi-v31</RemoteDir>
536+
<Operation>1</Operation>
537+
</Platform>
538+
<Platform Name="Android64">
539+
<RemoteDir>res\drawable-anydpi-v31</RemoteDir>
540+
<Operation>1</Operation>
541+
</Platform>
542+
</DeployClass>
543+
<DeployClass Name="Android_VectorizedSplashV31Dark">
544+
<Platform Name="Android">
545+
<RemoteDir>res\drawable-night-anydpi-v31</RemoteDir>
546+
<Operation>1</Operation>
547+
</Platform>
548+
<Platform Name="Android64">
549+
<RemoteDir>res\drawable-night-anydpi-v31</RemoteDir>
550+
<Operation>1</Operation>
551+
</Platform>
552+
</DeployClass>
423553
<DeployClass Name="DebugSymbols">
424554
<Platform Name="iOSSimulator">
425555
<Operation>1</Operation>

Samples/Image/ImagesTest.res

41.5 KB
Binary file not shown.

Samples/Image/Main.dfm

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ object MainForm: TMainForm
1111
Font.Height = -11
1212
Font.Name = 'Tahoma'
1313
Font.Style = []
14-
OldCreateOrder = False
15-
PixelsPerInch = 96
1614
TextHeight = 13
1715
object Image3: TImage
1816
Left = 336
@@ -2952,9 +2950,11 @@ object MainForm: TMainForm
29522950
Top = 0
29532951
Width = 770
29542952
Height = 605
2955-
ActivePage = TabSheet1
2953+
ActivePage = TabSheet4
29562954
Align = alClient
29572955
TabOrder = 0
2956+
ExplicitWidth = 764
2957+
ExplicitHeight = 586
29582958
object TabSheet1: TTabSheet
29592959
Caption = 'Smothing'
29602960
object Shape2: TShape
@@ -11434,15 +11434,18 @@ object MainForm: TMainForm
1143411434
object Label21: TLabel
1143511435
Left = 8
1143611436
Top = 5
11437-
Width = 151
11437+
Width = 320
1143811438
Height = 13
11439-
Caption = 'Focus support: (press TAB key)'
11439+
Caption =
11440+
'Focus support: Press TAB key for Focus, and SPACE key for "Click' +
11441+
'"'
1144011442
end
1144111443
object EsImageControl14: TEsImageControl
1144211444
Left = 8
1144311445
Top = 24
1144411446
Width = 209
1144511447
Height = 73
11448+
AllowFocus = True
1144611449
Picture.Data = {
1144711450
0954506E67496D61676589504E470D0A1A0A0000000D49484452000000A60000
1144811451
0038080600000077E483440000000473424954080808087C0864880000000970
@@ -11879,6 +11882,7 @@ object MainForm: TMainForm
1187911882
Top = 24
1188011883
Width = 209
1188111884
Height = 73
11885+
AllowFocus = True
1188211886
Picture.Data = {
1188311887
0954506E67496D61676589504E470D0A1A0A0000000D49484452000000A60000
1188411888
0038080600000077E483440000000473424954080808087C0864880000000970
@@ -12116,6 +12120,7 @@ object MainForm: TMainForm
1211612120
Top = 24
1211712121
Width = 209
1211812122
Height = 73
12123+
AllowFocus = True
1211912124
Picture.Data = {
1212012125
0954506E67496D61676589504E470D0A1A0A0000000D49484452000000A60000
1212112126
0038080600000077E483440000000473424954080808087C0864880000000970

Source/ES.Images.pas

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ TEsImageControl = class(TEsBaseLayout)
292292
FFrameWidth: TFrameWidth;
293293
FFrameColor: TColor;
294294
FFrameStyle: TFrameStyle;
295+
FAllowFocus: Boolean;
295296
function GetCanvas: TCanvas;
296297
function GetImageIndex: TImageIndex;
297298
function GetImages: TCustomImageList;
@@ -326,19 +327,22 @@ TEsImageControl = class(TEsBaseLayout)
326327
procedure CalcContentMargins(var Margins: TContentMargins); override;
327328
procedure ImageProxyChange(Sender: TObject);
328329
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
330+
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
329331
procedure Loaded; override;
330332
procedure Paint; override;
331333
procedure PaintWindow(DC: HDC); override;
332334
public
333335
constructor Create(AOwner: TComponent); override;
334336
destructor Destroy; override;
337+
function CanFocus: Boolean; override;
335338
procedure BeginDraw;
336339
procedure EndDraw;
337340
procedure RecreateBitmap;
338341
property Canvas: TCanvas read GetCanvas;
339342
published
340343
property Align;
341344
property AlignWithMargins;
345+
property AllowFocus: Boolean read FAllowFocus write FAllowFocus default False;
342346
property Anchors;
343347
property AutoSize;
344348
property BorderWidth;
@@ -393,6 +397,9 @@ TEsImageControl = class(TEsBaseLayout)
393397
property OnEndDrag;
394398
property OnEnter;
395399
property OnExit;
400+
property OnKeyDown;
401+
property OnKeyPress;
402+
property OnKeyUp;
396403
property OnGesture;
397404
property OnMouseActivate;
398405
property OnMouseDown;
@@ -555,6 +562,7 @@ TEsCustomVirtualImageControl = class(TEsBaseLayout)
555562
FFrameWidth: TFrameWidth;
556563
FFrameColor: TColor;
557564
FFrameStyle: TFrameStyle;
565+
FAllowFocus: Boolean;
558566
function GetImageCollection: TCustomImageCollection;
559567
function GetImageHeight: Integer;
560568
function GetImageIndex: TImageIndex;
@@ -583,10 +591,12 @@ TEsCustomVirtualImageControl = class(TEsBaseLayout)
583591
procedure ChangeScale(M, D: Integer; isDpiChange: Boolean); override;
584592
procedure ImageProxyChange(Sender: TObject);
585593
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
594+
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
586595
procedure Paint; override;
587596
public
588597
constructor Create(AOwner: TComponent); override;
589598
destructor Destroy; override;
599+
function CanFocus: Boolean; override;
590600
property FrameColor: TColor read FFrameColor write SetFrameColor default clBtnShadow;
591601
property FrameStyle: TFrameStyle read FFrameStyle write SetFrameStyle default TExFrameStyle.None;
592602
property FrameWidth: TFrameWidth read FFrameWidth write SetFrameWidth default 1;
@@ -608,11 +618,13 @@ TEsCustomVirtualImageControl = class(TEsBaseLayout)
608618
property Opacity: Byte read GetOpacity write SetOpacity default 255;
609619
/// <summary> Image location </summary>
610620
property Stretch: TImageStretch read GetStretch write SetStretch default TImageStretch.Fit;
621+
property AllowFocus: Boolean read FAllowFocus write FAllowFocus default False;
611622
end;
612623

613624
TEsVirtualImageControl = class(TEsCustomVirtualImageControl)
614625
property Align;
615626
property AlignWithMargins;
627+
property AllowFocus;
616628
property Anchors;
617629
property BorderWidth;
618630
property Color default clBtnFace;
@@ -662,6 +674,9 @@ TEsVirtualImageControl = class(TEsCustomVirtualImageControl)
662674
property OnEndDrag;
663675
property OnEnter;
664676
property OnExit;
677+
property OnKeyDown;
678+
property OnKeyPress;
679+
property OnKeyUp;
665680
property OnGesture;
666681
property OnMouseActivate;
667682
property OnMouseDown;
@@ -1491,6 +1506,11 @@ function TEsImageControl.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;
14911506
NewHeight := ImageProxy.ImageHeight + ContentMargins.Height;
14921507
end;
14931508

1509+
function TEsImageControl.CanFocus: Boolean;
1510+
begin
1511+
Result := AllowFocus and Inherited;
1512+
end;
1513+
14941514
function TEsImageControl.GetOpacity: Byte;
14951515
begin
14961516
Result := ImageProxy.Opacity;
@@ -1592,10 +1612,20 @@ function TEsImageControl.IsImageNameStored: Boolean;
15921612
procedure TEsImageControl.KeyUp(var Key: Word; Shift: TShiftState);
15931613
begin
15941614
inherited;
1595-
if (Key = VK_SPACE) or (Key = VK_RETURN) then
1615+
if (Key = VK_SPACE) {or (Key = VK_RETURN)} then
15961616
Click;
15971617
end;
15981618

1619+
procedure TEsImageControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
1620+
begin
1621+
inherited;
1622+
1623+
if (Button = mbLeft) and Enabled and AllowFocus then
1624+
begin
1625+
Winapi.Windows.SetFocus(Handle);
1626+
end;
1627+
end;
1628+
15991629
procedure TEsImageControl.Loaded;
16001630
begin
16011631
inherited;
@@ -2287,6 +2317,11 @@ procedure TEsCustomVirtualImageControl.CalcContentMargins(
22872317
end;
22882318
end;
22892319

2320+
function TEsCustomVirtualImageControl.CanFocus: Boolean;
2321+
begin
2322+
Result := AllowFocus and Inherited;
2323+
end;
2324+
22902325
{$IFDEF VER310UP}
22912326
procedure TEsCustomVirtualImageControl.ChangeScale(M, D: Integer; isDpiChange: Boolean);
22922327
begin
@@ -2356,10 +2391,20 @@ function TEsCustomVirtualImageControl.IsImageNameStored: Boolean;
23562391
procedure TEsCustomVirtualImageControl.KeyUp(var Key: Word; Shift: TShiftState);
23572392
begin
23582393
inherited;
2359-
if (Key = VK_SPACE) or (Key = VK_RETURN) then
2394+
if (Key = VK_SPACE) {or (Key = VK_RETURN)} then
23602395
Click;
23612396
end;
23622397

2398+
procedure TEsCustomVirtualImageControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
2399+
begin
2400+
inherited;
2401+
2402+
if (Button = mbLeft) and Enabled and AllowFocus then
2403+
begin
2404+
Winapi.Windows.SetFocus(Handle);
2405+
end;
2406+
end;
2407+
23632408
procedure TEsCustomVirtualImageControl.Paint;
23642409
begin
23652410
if (csDesigning in ComponentState) and IsDrawHelper and

0 commit comments

Comments
 (0)