Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
231 changes: 227 additions & 4 deletions Source/fmx/WrapFmxControls.pas
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface

uses
Classes, SysUtils, TypInfo, Types,
Fmx.Controls,
FMX.Types, FMX.Controls,
PythonEngine, WrapDelphi, WrapDelphiClasses, WrapFmxTypes;

type
Expand All @@ -31,14 +31,17 @@ TPyDelphiControl = class (TPyDelphiFmxObject)
function CanFocus_Wrapper(args: PPyObject): PPyObject; cdecl;
function SetFocus_Wrapper(args: PPyObject): PPyObject; cdecl;
function ResetFocus_Wrapper(args: PPyObject): PPyObject; cdecl;
function PrepareForPaint_Wrapper(args : PPyObject) : PPyObject; cdecl;
// Property Getters
function Get_Visible(AContext: Pointer): PPyObject; cdecl;
function Get_ControlsCount( AContext : Pointer) : PPyObject; cdecl;
function Get_Controls(AContext: Pointer): PPyObject; cdecl;
function Get_IsFocused( AContext : Pointer) : PPyObject; cdecl;
function Get_ParentControl( AContext : Pointer) : PPyObject; cdecl;
function Get_Position(AContext: Pointer): PPyObject; cdecl;
// Property Setters
function Set_Visible(AValue: PPyObject; AContext: Pointer): integer; cdecl;
function Set_Position(AValue: PPyObject; AContext: Pointer): integer; cdecl;
public
class function DelphiObjectClass : TClass; override;
class procedure RegisterGetSets( PythonType : TPythonType ); override;
Expand All @@ -65,10 +68,34 @@ TControlsAccess = class(TContainerAccess)
property Container : TControl read GetContainer;
end;

implementation
TPyDelphiStyledControl = class(TPyDelphiControl)
private
function GetDelphiObject: TStyledControl;
procedure SetDelphiObject(const Value: TStyledControl);
protected
// Exposed Methods
function ApplyStyleLookup_Wrapper(args : PPyObject) : PPyObject; cdecl;
function NeedStyleLookup_Wrapper(args : PPyObject) : PPyObject; cdecl;
function Inflate_Wrapper(args : PPyObject) : PPyObject; cdecl;
// Property Getters
function Get_DefaultStyleLookupName(AContext: Pointer): PPyObject; cdecl;
function Get_StyleLookup(AContext: Pointer): PPyObject; cdecl;
function Get_AutoTranslate(AContext: Pointer): PPyObject; cdecl;
function Get_AdjustSizeValue(AContext: Pointer): PPyObject; cdecl;
function Get_AdjustType(AContext: Pointer): PPyObject; cdecl;
function Get_StyleState(AContext: Pointer): PPyObject; cdecl;
// Property Setters
function Set_StyleLookup(AValue: PPyObject; AContext: Pointer): integer; cdecl;
function Set_AutoTranslate(AValue: PPyObject; AContext: Pointer): integer; cdecl;
public
class function DelphiObjectClass: TClass; override;
class procedure RegisterGetSets(PythonType: TPythonType); override;
class procedure RegisterMethods(PythonType: TPythonType); override;
// Properties
property DelphiObject: TStyledControl read GetDelphiObject write SetDelphiObject;
end;

uses
FMX.Types;
implementation

type
{ Register the wrappers, the globals and the constants }
Expand Down Expand Up @@ -125,6 +152,18 @@ function TPyDelphiControl.LocalToAbsolute_Wrapper(
end;
end;

function TPyDelphiControl.PrepareForPaint_Wrapper(args: PPyObject): PPyObject;
begin
Adjust(@Self);
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':PrepareForPaint') <> 0 then begin
DelphiObject.PrepareForPaint;
Result := ReturnNone;
end else
Result := nil;
end;
end;

class function TPyDelphiControl.DelphiObjectClass: TClass;
begin
Result := TControl;
Expand Down Expand Up @@ -161,6 +200,12 @@ function TPyDelphiControl.Get_ParentControl(AContext: Pointer): PPyObject;
Result := Wrap(DelphiObject.ParentControl);
end;

function TPyDelphiControl.Get_Position(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := Wrap(DelphiObject.Position);
end;

function TPyDelphiControl.Get_Visible(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Expand All @@ -178,6 +223,8 @@ class procedure TPyDelphiControl.RegisterGetSets(PythonType: TPythonType);
'Returns an iterator over contained controls', nil);
PythonType.AddGetSet('IsFocused', @TPyDelphiControl.Get_IsFocused, nil,
'Determines whether the control has input focus.', nil);
PythonType.AddGetSet('Position', @TPyDelphiControl.Get_Position, @TPyDelphiControl.Set_Position,
'Returns an access to the position of the control inside its parent', nil);
end;

class procedure TPyDelphiControl.RegisterMethods(PythonType: TPythonType);
Expand Down Expand Up @@ -210,6 +257,9 @@ class procedure TPyDelphiControl.RegisterMethods(PythonType: TPythonType);
PythonType.AddMethod('ResetFocus', @TPyDelphiControl.ResetFocus_Wrapper,
'TControl.ResetFocus()'#10 +
'Removes the focus from a control of from any children of the control.');
PythonType.AddMethod('PrepareForPaint', @TPyDelphiControl.PrepareForPaint_Wrapper,
'TControl.PrepareForPaint()'#10 +
'Prepares the current control for painting.');
end;

function TPyDelphiControl.Repaint_Wrapper(args: PPyObject): PPyObject;
Expand Down Expand Up @@ -304,6 +354,21 @@ function TPyDelphiControl.SetFocus_Wrapper(args: PPyObject): PPyObject;
end;
end;

function TPyDelphiControl.Set_Position(AValue: PPyObject;
AContext: Pointer): integer;
var
LValue: TObject;
begin
Adjust(@Self);
if CheckObjAttribute(AValue, 'Position', TPosition, LValue) then
begin
DelphiObject.Position := TPosition(LValue);
Result := 0;
end
else
Result := -1;
end;

function TPyDelphiControl.Set_Visible(AValue: PPyObject;
AContext: Pointer): integer;
var
Expand Down Expand Up @@ -336,6 +401,7 @@ procedure TControlsRegistration.RegisterWrappers(
begin
inherited;
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiControl);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiStyledControl);
end;

{ TControlsAccess }
Expand Down Expand Up @@ -404,6 +470,163 @@ class function TControlsAccess.SupportsIndexOf: Boolean;
Result := True;
end;

{ TPyDelphiStyledControl }

function TPyDelphiStyledControl.ApplyStyleLookup_Wrapper(
args: PPyObject): PPyObject;
begin
Adjust(@Self);
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':ApplyStyleLookup') <> 0 then begin
DelphiObject.ApplyStyleLookup;
Result := ReturnNone;
end else
Result := nil;
end;
end;

class function TPyDelphiStyledControl.DelphiObjectClass: TClass;
begin
Result := TStyledControl;
end;

function TPyDelphiStyledControl.GetDelphiObject: TStyledControl;
begin
Result := TStyledControl(inherited DelphiObject);
end;

function TPyDelphiStyledControl.Get_AdjustSizeValue(
AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := WrapSizeF(PyDelphiWrapper, DelphiObject.AdjustSizeValue);
end;

function TPyDelphiStyledControl.Get_AdjustType(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(Ord(DelphiObject.AdjustType));
end;

function TPyDelphiStyledControl.Get_AutoTranslate(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.VariantAsPyObject(Self.DelphiObject.AutoTranslate);
end;

function TPyDelphiStyledControl.Get_DefaultStyleLookupName(
AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyUnicodeFromString(DelphiObject.DefaultStyleLookupName);
end;

function TPyDelphiStyledControl.Get_StyleLookup(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyUnicodeFromString(DelphiObject.StyleLookup);
end;

function TPyDelphiStyledControl.Get_StyleState(AContext: Pointer): PPyObject;
begin
Adjust(@Self);
Result := GetPythonEngine.PyLong_FromLong(Ord(DelphiObject.StyleState));
end;

function TPyDelphiStyledControl.Inflate_Wrapper(args: PPyObject): PPyObject;
begin
Adjust(@Self);
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':Inflate') <> 0 then begin
DelphiObject.Inflate;
Result := ReturnNone;
end else
Result := nil;
end;
end;

function TPyDelphiStyledControl.NeedStyleLookup_Wrapper(
args: PPyObject): PPyObject;
begin
Adjust(@Self);
with GetPythonEngine do begin
if PyArg_ParseTuple( args, ':NeedStyleLookup') <> 0 then begin
DelphiObject.NeedStyleLookup;
Result := ReturnNone;
end else
Result := nil;
end;
end;

class procedure TPyDelphiStyledControl.RegisterGetSets(PythonType: TPythonType);
begin
inherited;
with PythonType do begin
AddGetSet('DefaultStyleLookupName', @TPyDelphiStyledControl.Get_StyleLookup, nil,
'Returns a string with the name of the default style of this control', nil);
AddGetSet('StyleLookup', @TPyDelphiStyledControl.Get_StyleLookup, @TPyDelphiStyledControl.Set_StyleLookup,
'Specifies the name of the resource object to which the current TStyledControl is linked', nil);
AddGetSet('AutoTranslate', @TPyDelphiStyledControl.Get_AutoTranslate, @TPyDelphiStyledControl.Set_AutoTranslate,
'Specifies whether the control''s text should be translated', nil);
AddGetSet('AdjustSizeValue', @TPyDelphiStyledControl.Get_AdjustSizeValue, nil,
'Updates the width and height of this control according to its current style', nil);
AddGetSet('AdjustType', @TPyDelphiStyledControl.Get_AdjustType, nil,
'Determines if and how the width and height of this control should be '
+ 'modified to take the fixed space dictated by the style of this control', nil);
AddGetSet('StyleState', @TPyDelphiStyledControl.Get_StyleState, nil,
'This property allows you to define the current state of style', nil);
end;
end;

class procedure TPyDelphiStyledControl.RegisterMethods(PythonType: TPythonType);
begin
inherited;
PythonType.AddMethod('ApplyStyleLookup', @TPyDelphiStyledControl.ApplyStyleLookup_Wrapper,
'TStyledControl.ApplyStyleLookup()'#10 +
'Gets and applies the style of a TStyledControl.');
PythonType.AddMethod('NeedStyleLookup', @TPyDelphiStyledControl.NeedStyleLookup_Wrapper,
'TStyledControl.NeedStyleLookup()'#10 +
'Call this procedure to indicate that this control requires to get and apply its style lookup.');
PythonType.AddMethod('Inflate', @TPyDelphiStyledControl.Inflate_Wrapper,
'TStyledControl.Inflate()'#10 +
'Call this procedure to get and apply its style lookup.');
end;

procedure TPyDelphiStyledControl.SetDelphiObject(const Value: TStyledControl);
begin
inherited DelphiObject := Value;
end;

function TPyDelphiStyledControl.Set_AutoTranslate(AValue: PPyObject;
AContext: Pointer): integer;
var
LValue: Boolean;
begin
Adjust(@Self);
if CheckBoolAttribute(AValue, 'AutoTranslate', LValue) then
begin
DelphiObject.AutoTranslate := LValue;
Result := 0;
end
else
Result := -1;
end;

function TPyDelphiStyledControl.Set_StyleLookup(AValue: PPyObject;
AContext: Pointer): integer;
var
LValue: string;
begin
if CheckStrAttribute(AValue, 'StyleLookup', LValue) then
with GetPythonEngine do begin
Adjust(@Self);
DelphiObject.StyleLookup := LValue;
Result := 0;
end
else
Result := -1;
end;

initialization
RegisteredUnits.Add(TControlsRegistration.Create);

Expand Down
Loading