-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
DW.NativeButton.pas
161 lines (138 loc) · 4.18 KB
/
DW.NativeButton.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
unit DW.NativeButton;
{*******************************************************}
{ }
{ Kastri }
{ }
{ Delphi Worlds Cross-Platform Library }
{ }
{ Copyright 2020-2024 Dave Nottage under MIT license }
{ which is located in the root folder of this library }
{ }
{*******************************************************}
interface
uses
// RTL
System.Classes, System.Types,
// FMX
FMX.Controls.Presentation, FMX.Controls.Model, FMX.StdCtrls, FMX.Types,
// DW
DW.NativeControlModel;
const
MM_SET_TEXT = MM_USER + 1;
type
TCustomNativeButtonModel = class(TNativeControlModel)
private
FText: string;
procedure SetText(const Value: string);
public
property Text: string read FText write SetText;
end;
TCustomNativeButton = class(TPresentedTextControl)
private
function GetModel: TCustomNativeButtonModel; overload;
function GetOnLongPress: TNotifyEvent;
procedure SetOnLongPress(const Value: TNotifyEvent);
protected
function DefineModelClass: TDataModelClass; override;
function RecommendSize(const AWishedSize: TSizeF): TSizeF; override;
procedure SetText(const Value: string); override;
public
constructor Create(AOwner: TComponent); override;
property Model: TCustomNativeButtonModel read GetModel;
property OnLongPress: TNotifyEvent read GetOnLongPress write SetOnLongPress;
end;
TCustomButtonEx = class(FMX.StdCtrls.TCustomButton)
private
FOnLongPress: TNotifyEvent;
public
property OnLongPress: TNotifyEvent read FOnLongPress write FOnLongPress;
end;
{$IF CompilerVersion < 35}
[ComponentPlatformsAttribute(pfidiOS or pidAndroid32Arm or pidAndroid64Arm or pidWin32 or pidWin64)]
{$ELSE}
[ComponentPlatformsAttribute(pfidiOS or pidAndroidArm32 or pidAndroidArm64 or pidWin32 or pidWin64)]
{$ENDIF}
{$IF Defined(IOS) or Defined(ANDROID)}
TNativeButton = class(TCustomNativeButton)
{$ELSE}
TNativeButton = class(TCustomButtonEx)
{$ENDIF}
published
property Action;
property Align default TAlignLayout.None;
property Anchors;
property Enabled;
property Height;
property HitTest;
property Margins;
property Padding;
property Position;
property Size;
property TabOrder;
property TabStop;
property Text;
property Visible default True;
property Width;
property OnClick;
property OnDblClick;
property OnEnter;
property OnExit;
property OnLongPress;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnResized;
end;
procedure Register;
implementation
{$IF Defined(IOS)}
uses
DW.NativeButton.iOS;
{$ENDIF}
{$IF Defined(ANDROID)}
uses
DW.NativeButton.Android;
{$ENDIF}
procedure Register;
begin
RegisterComponents('Kastri FMX', [TNativeButton]);
end;
{ TCustomNativeButtonModel }
procedure TCustomNativeButtonModel.SetText(const Value: string);
begin
FText := Value;
SendMessage<string>(MM_SET_TEXT, FText);
end;
{ TCustomNativeButton }
constructor TCustomNativeButton.Create(AOwner: TComponent);
begin
inherited;
ControlType := TControlType.Platform;
end;
function TCustomNativeButton.DefineModelClass: TDataModelClass;
begin
Result := TCustomNativeButtonModel;
end;
function TCustomNativeButton.GetModel: TCustomNativeButtonModel;
begin
Result := inherited GetModel<TCustomNativeButtonModel>;
end;
function TCustomNativeButton.RecommendSize(const AWishedSize: TSizeF): TSizeF;
begin
Result := AWishedSize;
end;
procedure TCustomNativeButton.SetText(const Value: string);
begin
inherited;
Model.Text := Value;
end;
function TCustomNativeButton.GetOnLongPress: TNotifyEvent;
begin
Result := Model.OnLongPress;
end;
procedure TCustomNativeButton.SetOnLongPress(const Value: TNotifyEvent);
begin
Model.OnLongPress := Value;
end;
end.