* Store main objects classname in xib
* Store referencing outlet to main object in the files owner. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2633 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
9c37b28e46
commit
7e3b60e61d
@ -98,6 +98,8 @@ type
|
|||||||
tiOSWriteDomMethod = function (AnObjectDomElement: TDOMElement): TDOMElement of object;
|
tiOSWriteDomMethod = function (AnObjectDomElement: TDOMElement): TDOMElement of object;
|
||||||
TiOSXIBPos = (sLeft, sTop, sWidth, sHeight);
|
TiOSXIBPos = (sLeft, sTop, sWidth, sHeight);
|
||||||
|
|
||||||
|
TiOSXIBConnectionType = (ctOutlet, ctEvent);
|
||||||
|
|
||||||
NSObject = class;
|
NSObject = class;
|
||||||
tiOSFakeComponent = class(TComponent)
|
tiOSFakeComponent = class(TComponent)
|
||||||
private
|
private
|
||||||
@ -118,7 +120,10 @@ type
|
|||||||
function GetXIBObjectRecords: TDOMElement;
|
function GetXIBObjectRecords: TDOMElement;
|
||||||
function GetXIBObjects: TDOMElement;
|
function GetXIBObjects: TDOMElement;
|
||||||
function GetXIBRootObjects: TDOMElement;
|
function GetXIBRootObjects: TDOMElement;
|
||||||
|
function GetXIBFlattenedProperties: TDOMElement;
|
||||||
|
function GetXIBConnectionRecords: TDOMElement;
|
||||||
function GetNextObjectID: integer;
|
function GetNextObjectID: integer;
|
||||||
|
function GetXIBConnection(ASourceRef, ADestinationRef: int64; ConnectionType: TiOSXIBConnectionType; CreateIfNotExists: boolean): TDOMElement;
|
||||||
function FindOrderdObjectByRef(ARef: int64): TDOMElement;
|
function FindOrderdObjectByRef(ARef: int64): TDOMElement;
|
||||||
protected
|
protected
|
||||||
procedure SetXIBObjectElement(const AValue: TDOMElement);
|
procedure SetXIBObjectElement(const AValue: TDOMElement);
|
||||||
@ -249,14 +254,15 @@ type
|
|||||||
private
|
private
|
||||||
FDesigner: IMyWidgetDesigner;
|
FDesigner: IMyWidgetDesigner;
|
||||||
FFilesOwnerClass: string;
|
FFilesOwnerClass: string;
|
||||||
FHiddenObjectOutletName: string;
|
|
||||||
FIsHiddenObject: boolean;
|
FIsHiddenObject: boolean;
|
||||||
FNIBDocument: TXMLDocument;
|
FNIBDocument: TXMLDocument;
|
||||||
FWidth, FHeight: integer;
|
FWidth, FHeight: integer;
|
||||||
FXIBUsesObjectsForArrays: boolean;
|
FXIBUsesObjectsForArrays: boolean;
|
||||||
|
function GetFilesOwnerOutletName: string;
|
||||||
procedure GetXIBSaveParam(Sender: TObject; const ParamName: String; out AValue: String);
|
procedure GetXIBSaveParam(Sender: TObject; const ParamName: String; out AValue: String);
|
||||||
function IsNIBRoot: boolean;
|
function IsNIBRoot: boolean;
|
||||||
function GetFilesOwnerID: string;
|
function GetFilesOwnerID: string;
|
||||||
|
procedure SetFilesOwnerOutletName(AValue: string);
|
||||||
protected
|
protected
|
||||||
function GetFlattenedProperties: string;
|
function GetFlattenedProperties: string;
|
||||||
function GetNSObject: NSObject; override;
|
function GetNSObject: NSObject; override;
|
||||||
@ -283,7 +289,7 @@ type
|
|||||||
published
|
published
|
||||||
property FilesOwnerClass: string read FFilesOwnerClass write FFilesOwnerClass stored IsNIBRoot;
|
property FilesOwnerClass: string read FFilesOwnerClass write FFilesOwnerClass stored IsNIBRoot;
|
||||||
property IsHiddenObject: boolean read FIsHiddenObject write FIsHiddenObject stored IsNIBRoot;
|
property IsHiddenObject: boolean read FIsHiddenObject write FIsHiddenObject stored IsNIBRoot;
|
||||||
property HiddenObjectOutletName: string read FHiddenObjectOutletName write FHiddenObjectOutletName stored IsNIBRoot;
|
property FilesOwnerOutletName: string read GetFilesOwnerOutletName write SetFilesOwnerOutletName;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
UIResponder = class(NSObject);
|
UIResponder = class(NSObject);
|
||||||
@ -1182,11 +1188,18 @@ end;
|
|||||||
|
|
||||||
procedure TNIBObjectWriter.BeginComponent(Component: TComponent;
|
procedure TNIBObjectWriter.BeginComponent(Component: TComponent;
|
||||||
Flags: TFilerFlags; ChildPos: Integer);
|
Flags: TFilerFlags; ChildPos: Integer);
|
||||||
|
var
|
||||||
|
FakeComp: tiOSFakeComponent;
|
||||||
|
AnElement: TDOMElement;
|
||||||
begin
|
begin
|
||||||
if not FIsWritten then
|
if not FIsWritten then
|
||||||
begin
|
begin
|
||||||
if (Component is NSObject) then
|
if (Component is NSObject) then
|
||||||
begin
|
begin
|
||||||
|
FakeComp := tiOSFakeComponent(Component);
|
||||||
|
AnElement := FakeComp.GetXIBFlattenedProperties;
|
||||||
|
AnElement := FakeComp.GetKeyNode(AnElement,'string', inttostr(FakeComp.ObjectID) +'.CustomClassName');
|
||||||
|
AnElement.TextContent:=FakeComp.ClassName;
|
||||||
WriteXML(NSObject(Component).FNIBDocument, FStream);
|
WriteXML(NSObject(Component).FNIBDocument, FStream);
|
||||||
FIsWritten:=true;
|
FIsWritten:=true;
|
||||||
end;
|
end;
|
||||||
@ -1602,6 +1615,20 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function NSObject.GetFilesOwnerOutletName: string;
|
||||||
|
var
|
||||||
|
AnElement: TDOMElement;
|
||||||
|
begin
|
||||||
|
result := '';
|
||||||
|
AnElement := GetXIBConnection(841351856, Ref, ctOutlet, false);
|
||||||
|
if assigned(AnElement) then
|
||||||
|
begin
|
||||||
|
AnElement := FindKeyNode(AnElement, 'string' ,'label');
|
||||||
|
if assigned(AnElement) then
|
||||||
|
result := AnElement.TextContent;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function NSObject.IsNIBRoot: boolean;
|
function NSObject.IsNIBRoot: boolean;
|
||||||
begin
|
begin
|
||||||
result := Parent=Nil;
|
result := Parent=Nil;
|
||||||
@ -1615,6 +1642,18 @@ begin
|
|||||||
Result:='664661524';
|
Result:='664661524';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure NSObject.SetFilesOwnerOutletName(AValue: string);
|
||||||
|
var
|
||||||
|
AnElement: TDOMElement;
|
||||||
|
begin
|
||||||
|
if AValue=GetFilesOwnerOutletName then
|
||||||
|
Exit;
|
||||||
|
|
||||||
|
AnElement := GetXIBConnection(841351856, Ref, ctOutlet, True);
|
||||||
|
AnElement := GetKeyNode(AnElement, 'string' ,'label');
|
||||||
|
AnElement.TextContent := AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
function NSObject.GetNSObject: NSObject;
|
function NSObject.GetNSObject: NSObject;
|
||||||
begin
|
begin
|
||||||
Result:=self;
|
Result:=self;
|
||||||
@ -1809,7 +1848,7 @@ begin
|
|||||||
result := result +
|
result := result +
|
||||||
'<object class="IBConnectionRecord">' + LineEnding +
|
'<object class="IBConnectionRecord">' + LineEnding +
|
||||||
' <object class="IBCocoaTouchOutletConnection" key="connection">' + LineEnding +
|
' <object class="IBCocoaTouchOutletConnection" key="connection">' + LineEnding +
|
||||||
' <string key="label">'+HiddenObjectOutletName+'</string>' + LineEnding +
|
' <string key="label">delegate</string>' + LineEnding +
|
||||||
' <reference key="source" ref="'+GetFilesOwnerID+'"/>' + LineEnding +
|
' <reference key="source" ref="'+GetFilesOwnerID+'"/>' + LineEnding +
|
||||||
' <reference key="destination" ref="664661524"/>' + LineEnding +
|
' <reference key="destination" ref="664661524"/>' + LineEnding +
|
||||||
' </object>' + LineEnding +
|
' </object>' + LineEnding +
|
||||||
@ -1827,7 +1866,6 @@ var
|
|||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
FIsHiddenObject:=true;
|
FIsHiddenObject:=true;
|
||||||
FHiddenObjectOutletName:='delegate';
|
|
||||||
FWidth:=340;
|
FWidth:=340;
|
||||||
FHeight:=500;
|
FHeight:=500;
|
||||||
FTop := 100;
|
FTop := 100;
|
||||||
@ -1890,6 +1928,10 @@ begin
|
|||||||
' </object>' +
|
' </object>' +
|
||||||
' </array>' +
|
' </array>' +
|
||||||
' </object>' +
|
' </object>' +
|
||||||
|
' <dictionary class="NSMutableDictionary" key="flattenedProperties">' +
|
||||||
|
' <string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>' +
|
||||||
|
' <string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>' +
|
||||||
|
' </dictionary>' +
|
||||||
' <dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>' +
|
' <dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>' +
|
||||||
' <nil key="activeLocalization"/>' +
|
' <nil key="activeLocalization"/>' +
|
||||||
' <dictionary class="NSMutableDictionary" key="localizations"/>' +
|
' <dictionary class="NSMutableDictionary" key="localizations"/>' +
|
||||||
@ -1991,6 +2033,7 @@ end;
|
|||||||
procedure NSObject.InitializeDefaults;
|
procedure NSObject.InitializeDefaults;
|
||||||
begin
|
begin
|
||||||
inherited InitializeDefaults;
|
inherited InitializeDefaults;
|
||||||
|
FilesOwnerOutletName:='delegate';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function NSObject.GetIBClassName: string;
|
class function NSObject.GetIBClassName: string;
|
||||||
@ -2010,6 +2053,60 @@ begin
|
|||||||
result := i;
|
result := i;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function tiOSFakeComponent.GetXIBConnection(ASourceRef, ADestinationRef: int64;
|
||||||
|
ConnectionType: TiOSXIBConnectionType; CreateIfNotExists: boolean): TDOMElement;
|
||||||
|
var
|
||||||
|
AnElement: TDOMElement;
|
||||||
|
AnOutletElement: TDOMElement;
|
||||||
|
SourceElement: TDOMElement;
|
||||||
|
DestElement: TDOMElement;
|
||||||
|
begin
|
||||||
|
result := nil;
|
||||||
|
AnElement := GetXIBConnectionRecords.FirstChild as TDOMElement;
|
||||||
|
while assigned(AnElement) do
|
||||||
|
begin
|
||||||
|
if (AnElement.NodeName='object') and (AnElement.AttribStrings['class']='IBConnectionRecord') then
|
||||||
|
begin
|
||||||
|
AnOutletElement := FindKeyNode(AnElement, 'object', 'connection');
|
||||||
|
if assigned(AnOutletElement) then
|
||||||
|
begin
|
||||||
|
SourceElement := FindKeyNode(AnOutletElement, 'reference', 'source');
|
||||||
|
DestElement := FindKeyNode(AnOutletElement, 'reference', 'destination');
|
||||||
|
if assigned(SourceElement) and assigned(DestElement) and
|
||||||
|
(SourceElement.AttribStrings['ref']=IntToStr(ASourceRef)) and
|
||||||
|
(DestElement.AttribStrings['ref']=IntToStr(ADestinationRef)) then
|
||||||
|
begin
|
||||||
|
if ((ConnectionType=ctOutlet) and (AnOutletElement.AttribStrings['class']='IBCocoaTouchOutletConnection')) or
|
||||||
|
((ConnectionType=ctEvent) and (AnOutletElement.AttribStrings['class']='IBCocoaTouchEventConnection')) then
|
||||||
|
begin
|
||||||
|
result := AnOutletElement;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
AnElement := AnElement.NextSibling as TDOMElement;
|
||||||
|
end;
|
||||||
|
if CreateIfNotExists then
|
||||||
|
begin
|
||||||
|
AnElement := AddElement(GetXIBConnectionRecords, 'object');
|
||||||
|
AnElement.AttribStrings['class']:='IBConnectionRecord';
|
||||||
|
AnOutletElement := GetKeyNode(AnElement,'object','connection');
|
||||||
|
if ConnectionType=ctOutlet then
|
||||||
|
AnOutletElement.AttribStrings['class'] := 'IBCocoaTouchOutletConnection'
|
||||||
|
else if ConnectionType=ctEvent then
|
||||||
|
AnOutletElement.AttribStrings['class'] := 'IBCocoaTouchEventConnection';
|
||||||
|
SourceElement := GetKeyNode(AnOutletElement,'reference','source');
|
||||||
|
SourceElement.AttribStrings['ref'] := IntToStr(ASourceRef);
|
||||||
|
DestElement := GetKeyNode(AnOutletElement,'reference','destination');
|
||||||
|
DestElement.AttribStrings['ref'] := IntToStr(ADestinationRef);
|
||||||
|
result := AnOutletElement;
|
||||||
|
|
||||||
|
GetKeyNode(AnElement,'int','connectionID').TextContent:=IntToStr(GConnectionID);
|
||||||
|
inc(GConnectionID);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{ tiOSFakeComponent }
|
{ tiOSFakeComponent }
|
||||||
|
|
||||||
procedure tiOSFakeComponent.SetHeight(const AValue: integer);
|
procedure tiOSFakeComponent.SetHeight(const AValue: integer);
|
||||||
@ -2165,6 +2262,19 @@ begin
|
|||||||
Result := FindKeyNode(DataNode,'object','IBDocument.RootObjects');
|
Result := FindKeyNode(DataNode,'object','IBDocument.RootObjects');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function tiOSFakeComponent.GetXIBFlattenedProperties: TDOMElement;
|
||||||
|
var
|
||||||
|
AnElement: TDOMElement;
|
||||||
|
begin
|
||||||
|
AnElement := GetXIBObjects;
|
||||||
|
result := GetKeyNode(AnElement, 'dictionary', 'flattenedProperties', 'NSMutableDictionary');
|
||||||
|
end;
|
||||||
|
|
||||||
|
function tiOSFakeComponent.GetXIBConnectionRecords: TDOMElement;
|
||||||
|
begin
|
||||||
|
Result := GetKeyNode(GetXIBObjects, 'array', 'connectionRecords', 'NSMutableArray');
|
||||||
|
end;
|
||||||
|
|
||||||
function tiOSFakeComponent.FindOrderdObjectByRef(ARef: int64): TDOMElement;
|
function tiOSFakeComponent.FindOrderdObjectByRef(ARef: int64): TDOMElement;
|
||||||
var
|
var
|
||||||
ANode: TDOMNode;
|
ANode: TDOMNode;
|
||||||
|
Loading…
Reference in New Issue
Block a user