* Store object-names in .xib

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2622 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
loesje_
2013-01-14 20:24:22 +00:00
parent 706c667f9f
commit 0b6368ae7b
2 changed files with 156 additions and 65 deletions

View File

@ -121,6 +121,7 @@ type
function GetNextObjectID: integer; function GetNextObjectID: integer;
function FindOrderdObjectByRef(ARef: int64): TDOMElement; function FindOrderdObjectByRef(ARef: int64): TDOMElement;
protected protected
procedure SetXIBObjectElement(const AValue: TDOMElement);
procedure AddChild(const AValue: tiOSFakeComponent); virtual; procedure AddChild(const AValue: tiOSFakeComponent); virtual;
procedure RemoveChild(const AValue: tiOSFakeComponent); virtual; procedure RemoveChild(const AValue: tiOSFakeComponent); virtual;
procedure SetParentComponent(Value: TComponent); override; procedure SetParentComponent(Value: TComponent); override;
@ -133,6 +134,8 @@ type
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override; procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
procedure InternalInvalidateRect(ARect: TRect; Erase: boolean); virtual; procedure InternalInvalidateRect(ARect: TRect; Erase: boolean); virtual;
function StoreSizeAsFrameSize: boolean; virtual; function StoreSizeAsFrameSize: boolean; virtual;
procedure SetName(const NewName: TComponentName); override;
// iOS // iOS
procedure AddConnectionRecord(AnObjectDomElement: TDOMElement; AConnectionType, ALabel, AEventType: string); procedure AddConnectionRecord(AnObjectDomElement: TDOMElement; AConnectionType, ALabel, AEventType: string);
procedure WriteToDomElement(AnObjectDomElement: TDOMElement); virtual; procedure WriteToDomElement(AnObjectDomElement: TDOMElement); virtual;
@ -556,11 +559,11 @@ type
FRefStack: array of int64; FRefStack: array of int64;
private private
FXIBUsesObjectsForArrays: boolean; FXIBUsesObjectsForArrays: boolean;
function GetConnectionRef(AnIBConnectionRecord: TDOMElement; key: string): int64; //function GetConnectionRef(AnIBConnectionRecord: TDOMElement; key: string): int64;
function GetObjectFromRef(ARef: int64): TDOMElement; function GetObjectFromRef(ARef: int64): TDOMElement;
function GetConnectionLabel(AnIBConnectionRecord: TDOMElement): string; function GetConnectionLabel(AnIBConnectionRecord: TDOMElement): string;
function GetNextChild(ACurrentNode: TDOMNode; ParentRef: int64): TDOMElement; function GetNextChild(ACurrentNode: TDOMNode; ParentRef: int64): TDOMElement;
function FindOrderdObjectByRef(ARef: int64): TDOMElement; function FindOrderedObjectByRef(ARef: int64): TDOMElement;
function FindFirstChild: TDOMElement; function FindFirstChild: TDOMElement;
function FindNextChild(ARef: int64): TDOMElement; function FindNextChild(ARef: int64): TDOMElement;
function FindNextOrderedObject: TDOMElement; function FindNextOrderedObject: TDOMElement;
@ -593,6 +596,12 @@ type
property XIBUsesObjectsForArrays: boolean read FXIBUsesObjectsForArrays; property XIBUsesObjectsForArrays: boolean read FXIBUsesObjectsForArrays;
end; end;
procedure ObtainBaseObjectInfoFromXIB(AStream: TStream; out AXMLDocument: TXMLDocument;
out ARootObjects, AConnectionRecords, AOrderedObjects, AMainOrderedObject: TDOMElement;
out AFilesOwnerID: int64;
out AXIBUsesObjectsForArrays: boolean);
function FindKeyNode(AParentNode: TDOMNode; NodeName, Key: string): TDOMElement;
implementation implementation
@ -640,7 +649,7 @@ end;
{ TXIBObjectReader } { TXIBObjectReader }
function TXIBObjectReader.GetConnectionRef(AnIBConnectionRecord: TDOMElement; key: string): int64; function GetConnectionRef(AnIBConnectionRecord: TDOMElement; key: string): int64;
var var
ATempNode: TDOMElement; ATempNode: TDOMElement;
AReferenceNode: TDOMElement; AReferenceNode: TDOMElement;
@ -711,13 +720,13 @@ begin
end; end;
end; end;
function TXIBObjectReader.FindOrderdObjectByRef(ARef: int64): TDOMElement; function FindOrderdObjectByRefA(AnOrderedObjects: TDOMElement; ARef: int64): TDOMElement;
var var
ANode: TDOMNode; ANode: TDOMNode;
ARefNode: TDOMElement; ARefNode: TDOMElement;
begin begin
result := nil; result := nil;
ANode := FOrderedObjects.FirstChild; ANode := AnOrderedObjects.FirstChild;
while assigned(ANode) do while assigned(ANode) do
begin begin
if (ANode.NodeName='object') and (ANode is TDOMElement) and (TDOMElement(ANode).AttribStrings['class']='IBObjectRecord') then if (ANode.NodeName='object') and (ANode is TDOMElement) and (TDOMElement(ANode).AttribStrings['class']='IBObjectRecord') then
@ -733,6 +742,11 @@ begin
end; end;
end; end;
function TXIBObjectReader.FindOrderedObjectByRef(ARef: int64): TDOMElement;
begin
result := FindOrderdObjectByRefA(FOrderedObjects, ARef);
end;
function TXIBObjectReader.FindFirstChild: TDOMElement; function TXIBObjectReader.FindFirstChild: TDOMElement;
var var
ANode: TDOMNode; ANode: TDOMNode;
@ -764,6 +778,8 @@ begin
result := nil; result := nil;
pass := false; pass := false;
ANode := FindKeyNode(FCurrentOrderedObject,'object','children'); ANode := FindKeyNode(FCurrentOrderedObject,'object','children');
if not assigned(ANode) then
ANode := FindKeyNode(FCurrentOrderedObject,'array','children');
if assigned(ANode) then if assigned(ANode) then
begin begin
ANode := ANode.FirstChild as TDOMElement; ANode := ANode.FirstChild as TDOMElement;
@ -841,7 +857,10 @@ begin
FStream := AStream; FStream := AStream;
end; end;
procedure TXIBObjectReader.BeginRootComponent; procedure ObtainBaseObjectInfoFromXIB(AStream: TStream; out AXMLDocument: TXMLDocument;
out ARootObjects, AConnectionRecords, AOrderedObjects, AMainOrderedObject: TDOMElement;
out AFilesOwnerID: int64;
out AXIBUsesObjectsForArrays: boolean);
var var
ArchiveNode, DataNode: TDOMNode; ArchiveNode, DataNode: TDOMNode;
Objects: TDOMNode; Objects: TDOMNode;
@ -850,19 +869,22 @@ var
MainObjectRef: int64; MainObjectRef: int64;
begin begin
ReadXMLFile(FXMLDocument, FStream); ReadXMLFile(AXMLDocument, AStream);
ArchiveNode := FXMLDocument.FirstChild; ArchiveNode := AXMLDocument.FirstChild;
assert(ArchiveNode.NodeName='archive'); assert(ArchiveNode.NodeName='archive');
DataNode := ArchiveNode.FindNode('data'); DataNode := ArchiveNode.FindNode('data');
FRootObjects := FindKeyNode(DataNode,'array','IBDocument.RootObjects'); ARootObjects := FindKeyNode(DataNode,'array','IBDocument.RootObjects');
if not assigned(FRootObjects) then if not assigned(ARootObjects) then
// Older XCode versions this: // Older XCode versions this:
begin begin
FRootObjects := FindKeyNode(DataNode,'object','IBDocument.RootObjects'); ARootObjects := FindKeyNode(DataNode,'object','IBDocument.RootObjects');
FXIBUsesObjectsForArrays:=true; AXIBUsesObjectsForArrays:=true;
end; end
ANode := FRootObjects.FirstChild; else
AXIBUsesObjectsForArrays:=False;
ANode := ARootObjects.FirstChild;
while assigned(ANode) do while assigned(ANode) do
begin begin
if (ANode.NodeName='object') and (ANode is TDOMElement) and (TDOMElement(ANode).AttribStrings['class']='IBProxyObject') then if (ANode.NodeName='object') and (ANode is TDOMElement) and (TDOMElement(ANode).AttribStrings['class']='IBProxyObject') then
@ -870,7 +892,7 @@ begin
ATempNode := FindKeyNode(ANode, 'string', 'IBProxiedObjectIdentifier'); ATempNode := FindKeyNode(ANode, 'string', 'IBProxiedObjectIdentifier');
if ATempNode.TextContent='IBFilesOwner' then if ATempNode.TextContent='IBFilesOwner' then
begin begin
FFilesOwnerID:=StrToInt(TDOMElement(ANode).AttribStrings['id']); AFilesOwnerID:=StrToInt(TDOMElement(ANode).AttribStrings['id']);
break; break;
end; end;
end; end;
@ -878,24 +900,24 @@ begin
end; end;
Objects := FindKeyNode(DataNode,'object','IBDocument.Objects'); Objects := FindKeyNode(DataNode,'object','IBDocument.Objects');
FConnectionRecords := FindKeyNode(Objects,'array','connectionRecords') as TDOMElement; AConnectionRecords := FindKeyNode(Objects,'array','connectionRecords') as TDOMElement;
if not assigned(FConnectionRecords) then if not assigned(AConnectionRecords) then
// Interface builder v3.1 and below uses 'object' instead of 'array' // Interface builder v3.1 and below uses 'object' instead of 'array'
FConnectionRecords := FindKeyNode(Objects,'object','connectionRecords') as TDOMElement; AConnectionRecords := FindKeyNode(Objects,'object','connectionRecords') as TDOMElement;
ANode := FindKeyNode(Objects,'object','objectRecords'); ANode := FindKeyNode(Objects,'object','objectRecords');
FOrderedObjects := FindKeyNode(ANode,'array','orderedObjects'); AOrderedObjects := FindKeyNode(ANode,'array','orderedObjects');
if not assigned(FOrderedObjects) then if not assigned(AOrderedObjects) then
// Interface builder v3.1 and below uses 'object' instead of 'array' // Interface builder v3.1 and below uses 'object' instead of 'array'
FOrderedObjects := FindKeyNode(ANode,'object','orderedObjects'); AOrderedObjects := FindKeyNode(ANode,'object','orderedObjects');
MainObjectRef:=0; MainObjectRef:=0;
ANode := FConnectionRecords.FirstChild; ANode := AConnectionRecords.FirstChild;
while assigned(ANode) do while assigned(ANode) do
begin begin
if (ANode.NodeName='object') and (ANode is TDOMElement) and (TDOMElement(ANode).AttribStrings['class']='IBConnectionRecord') then if (ANode.NodeName='object') and (ANode is TDOMElement) and (TDOMElement(ANode).AttribStrings['class']='IBConnectionRecord') then
begin begin
//FCurrentConnectionNode := TDOMElement(ANode); //FCurrentConnectionNode := TDOMElement(ANode);
if GetConnectionRef(TDOMElement(ANode),'source')=FFilesOwnerID then if GetConnectionRef(TDOMElement(ANode),'source')=AFilesOwnerID then
begin begin
MainObjectRef:=GetConnectionRef(TDOMElement(ANode),'destination'); MainObjectRef:=GetConnectionRef(TDOMElement(ANode),'destination');
break; break;
@ -905,10 +927,10 @@ begin
end; end;
if MainObjectRef<>0 then if MainObjectRef<>0 then
FMainOrderedObject := FindOrderdObjectByRef(MainObjectRef) AMainOrderedObject := FindOrderdObjectByRefA(AOrderedObjects, MainObjectRef)
else else
begin begin
ANode := FOrderedObjects.FirstChild; ANode := AOrderedObjects.FirstChild;
while assigned(ANode) do while assigned(ANode) do
begin begin
if (ANode.NodeName='object') and (ANode is TDOMElement) and (TDOMElement(ANode).AttribStrings['class']='IBObjectRecord') then if (ANode.NodeName='object') and (ANode is TDOMElement) and (TDOMElement(ANode).AttribStrings['class']='IBObjectRecord') then
@ -916,7 +938,7 @@ begin
ATempNode := FindKeyNode(ANode,'int','objectID'); ATempNode := FindKeyNode(ANode,'int','objectID');
if StrToIntDef(ATempNode.TextContent,0)>0 then if StrToIntDef(ATempNode.TextContent,0)>0 then
begin begin
FMainOrderedObject := ANode as TDOMElement; AMainOrderedObject := ANode as TDOMElement;
break; break;
end; end;
end; end;
@ -924,7 +946,14 @@ begin
end; end;
end; end;
end;
procedure TXIBObjectReader.BeginRootComponent;
begin
ObtainBaseObjectInfoFromXIB(FStream, FXMLDocument, FRootObjects, FConnectionRecords, FOrderedObjects, FMainOrderedObject, FFilesOwnerID, FXIBUsesObjectsForArrays);
FCurrentOrderedObject := FMainOrderedObject; FCurrentOrderedObject := FMainOrderedObject;
ReadState := rsMainProp; ReadState := rsMainProp;
end; end;
@ -938,6 +967,11 @@ begin
ObjectNode := GetObjectFromRef(Ref); ObjectNode := GetObjectFromRef(Ref);
CompClassName:=ObjectNode.AttribStrings['class']; CompClassName:=ObjectNode.AttribStrings['class'];
ObjectNode := FindKeyNode(FCurrentOrderedObject,'string','objectName');
if assigned(ObjectNode) then
CompName:=ObjectNode.TextContent;
if copy(CompClassName,1,2)='IB' then if copy(CompClassName,1,2)='IB' then
CompClassName:=copy(CompClassName,3,250); CompClassName:=copy(CompClassName,3,250);
FReadChilds := False; FReadChilds := False;
@ -987,7 +1021,7 @@ begin
CurrentChildRef := FindFirstChild; CurrentChildRef := FindFirstChild;
if assigned(CurrentChildRef) then if assigned(CurrentChildRef) then
begin begin
FCurrentOrderedObject := FindOrderdObjectByRef(StrToInt(CurrentChildRef.AttribStrings['ref'])); FCurrentOrderedObject := FindOrderedObjectByRef(StrToInt(CurrentChildRef.AttribStrings['ref']));
SetLength(FRefStack,length(FRefStack)+1); SetLength(FRefStack,length(FRefStack)+1);
FRefStack[high(FRefStack)]:=GetRefFromOrderedObject(FCurrentOrderedObject); FRefStack[high(FRefStack)]:=GetRefFromOrderedObject(FCurrentOrderedObject);
end end
@ -1001,7 +1035,7 @@ begin
CurrentChildRef := FindFirstChild; CurrentChildRef := FindFirstChild;
if assigned(CurrentChildRef) then if assigned(CurrentChildRef) then
begin begin
FCurrentOrderedObject := FindOrderdObjectByRef(StrToInt(CurrentChildRef.AttribStrings['ref'])); FCurrentOrderedObject := FindOrderedObjectByRef(StrToInt(CurrentChildRef.AttribStrings['ref']));
SetLength(FRefStack,length(FRefStack)+1); SetLength(FRefStack,length(FRefStack)+1);
FRefStack[high(FRefStack)]:=GetRefFromOrderedObject(FCurrentOrderedObject); FRefStack[high(FRefStack)]:=GetRefFromOrderedObject(FCurrentOrderedObject);
end end
@ -1017,14 +1051,14 @@ begin
begin begin
ref := FRefStack[high(FRefStack)]; ref := FRefStack[high(FRefStack)];
setlength(FRefStack, high(FRefStack)); setlength(FRefStack, high(FRefStack));
FCurrentOrderedObject := FindOrderdObjectByRef(ref); FCurrentOrderedObject := FindOrderedObjectByRef(ref);
ANode := FindKeyNode(FCurrentOrderedObject,'reference','parent'); ANode := FindKeyNode(FCurrentOrderedObject,'reference','parent');
FCurrentOrderedObject := FindOrderdObjectByRef(StrToInt(ANode.AttribStrings['ref'])); FCurrentOrderedObject := FindOrderedObjectByRef(StrToInt(ANode.AttribStrings['ref']));
CurrentChildRef := FindNextChild(ref); CurrentChildRef := FindNextChild(ref);
if assigned(CurrentChildRef) then if assigned(CurrentChildRef) then
begin begin
FCurrentOrderedObject := FindOrderdObjectByRef(StrToInt(CurrentChildRef.AttribStrings['ref'])); FCurrentOrderedObject := FindOrderedObjectByRef(StrToInt(CurrentChildRef.AttribStrings['ref']));
SetLength(FRefStack,length(FRefStack)+1); SetLength(FRefStack,length(FRefStack)+1);
FRefStack[high(FRefStack)]:=GetRefFromOrderedObject(FCurrentOrderedObject); FRefStack[high(FRefStack)]:=GetRefFromOrderedObject(FCurrentOrderedObject);
end end
@ -1035,7 +1069,7 @@ begin
begin begin
ref := FRefStack[high(FRefStack)]; ref := FRefStack[high(FRefStack)];
setlength(FRefStack, high(FRefStack)); setlength(FRefStack, high(FRefStack));
FCurrentOrderedObject := FindOrderdObjectByRef(ref); FCurrentOrderedObject := FindOrderedObjectByRef(ref);
FCurrentOrderedObject := FindNextOrderedObject; FCurrentOrderedObject := FindNextOrderedObject;
if assigned(FCurrentOrderedObject) then if assigned(FCurrentOrderedObject) then
begin begin
@ -2078,9 +2112,9 @@ var
AFrameNode: TDOMNode; AFrameNode: TDOMNode;
begin begin
result := 0; result := 0;
if assigned(FXIBObjectElement) then if assigned(XIBObjectElement) then
begin begin
AFrameNode := FindKeyNode(FXIBObjectElement,'string','NSFrame'); AFrameNode := FindKeyNode(XIBObjectElement,'string','NSFrame');
if assigned(AFrameNode) then if assigned(AFrameNode) then
begin begin
state := sLeft; state := sLeft;
@ -2088,7 +2122,7 @@ begin
end end
else if APosition in [sWidth, sHeight] then else if APosition in [sWidth, sHeight] then
begin begin
AFrameNode := FindKeyNode(FXIBObjectElement,'string','NSFrameSize'); AFrameNode := FindKeyNode(XIBObjectElement,'string','NSFrameSize');
if assigned(AFrameNode) then if assigned(AFrameNode) then
begin begin
state := sWidth; state := sWidth;
@ -2100,8 +2134,8 @@ end;
function tiOSFakeComponent.GetRef: integer; function tiOSFakeComponent.GetRef: integer;
begin begin
if assigned(FXIBObjectElement) then if assigned(XIBObjectElement) then
result := StrToInt(FXIBObjectElement.AttribStrings['id']) result := StrToIntDef(XIBObjectElement.AttribStrings['id'],0)
else else
result := 0; result := 0;
end; end;
@ -2167,6 +2201,26 @@ begin
end; end;
end; end;
procedure tiOSFakeComponent.SetXIBObjectElement(const AValue: TDOMElement);
var
AnElement: TDOMElement;
ARef: integer;
begin
FXIBObjectElement := AValue;
if csLoading in ComponentState then
Exit;
if (Name<>'') then
begin
ARef := Ref;
if ARef<>0 then
begin
AnElement := FindOrderdObjectByRef(ARef);
AnElement := GetKeyNode(AnElement,'string','objectName');
AnElement.TextContent:=Name;
end;
end;
end;
procedure tiOSFakeComponent.AddChild(const AValue: tiOSFakeComponent); procedure tiOSFakeComponent.AddChild(const AValue: tiOSFakeComponent);
var var
AComp: UIView; AComp: UIView;
@ -2192,10 +2246,12 @@ var
begin begin
if not (csLoading in ComponentState) {and assigned(FXIBObjectElement)} then if not (csLoading in ComponentState) {and assigned(FXIBObjectElement)} then
begin begin
AValue.FXIBObjectElement := GetXIBDocument.CreateElement('object'); AValue.SetXIBObjectElement(GetXIBDocument.CreateElement('object'));
ARef := random(999999999); ARef := random(999999999);
AValue.FXIBObjectElement.AttribStrings['class'] := AValue.GetIBClassName; while assigned(AValue.FindOrderdObjectByRef(ARef)) do
AValue.FXIBObjectElement.AttribStrings['id'] := IntToStr(ARef); ARef := random(999999999);
AValue.XIBObjectElement.AttribStrings['class'] := AValue.GetIBClassName;
AValue.XIBObjectElement.AttribStrings['id'] := IntToStr(ARef);
if GetNSObject.XIBUsesObjectsForArrays then if GetNSObject.XIBUsesObjectsForArrays then
s := 'object' s := 'object'
@ -2207,14 +2263,16 @@ begin
if IsRootObject then if IsRootObject then
ANode := GetXIBRootObjects ANode := GetXIBRootObjects
else else
ANode := GetKeyNode(FXIBObjectElement,s,'NSSubviews','NSMutableArray'); ANode := GetKeyNode(XIBObjectElement,s,'NSSubviews','NSMutableArray');
ANode.AppendChild(AValue.FXIBObjectElement); ANode.AppendChild(AValue.XIBObjectElement);
AOrderedObjects := GetXIBOrderedObjects; AOrderedObjects := GetXIBOrderedObjects;
ANode := AddElement(AOrderedObjects,'object'); ANode := AddElement(AOrderedObjects,'object');
ANode.AttribStrings['class'] := 'IBObjectRecord'; ANode.AttribStrings['class'] := 'IBObjectRecord';
AddIBInt(ANode,'objectID',GetNextObjectID); AddIBInt(ANode,'objectID',GetNextObjectID);
if AValue.Name<>'' then
AddIBString(ANode, 'objectName', AValue.Name);
AddIBReference(ANode, 'object', IntToStr(ARef)); AddIBReference(ANode, 'object', IntToStr(ARef));
if IsRootObject then if IsRootObject then
AddIBReference(ANode, 'parent', '0') AddIBReference(ANode, 'parent', '0')
@ -2301,9 +2359,9 @@ var
begin begin
result := clDefault; result := clDefault;
if Assigned(FXIBObjectElement) then if Assigned(XIBObjectElement) then
begin begin
AnElement := FindKeyNode(FXIBObjectElement, 'object', XIBPropertiesStrings[index].APropertyName); AnElement := FindKeyNode(XIBObjectElement, 'object', XIBPropertiesStrings[index].APropertyName);
if assigned(AnElement) then if assigned(AnElement) then
begin begin
AnElement := FindKeyNode(AnElement, 'bytes', 'NSRGB'); AnElement := FindKeyNode(AnElement, 'bytes', 'NSRGB');
@ -2340,12 +2398,12 @@ begin
if GetXIBColor(index)=AValue then if GetXIBColor(index)=AValue then
Exit; Exit;
if Assigned(FXIBObjectElement) then if Assigned(XIBObjectElement) then
begin begin
if (AValue = clDefault) then if (AValue = clDefault) then
begin begin
// Value is set to default, remove node // Value is set to default, remove node
AnElement := FindKeyNode(FXIBObjectElement, 'object', XIBPropertiesStrings[index].APropertyName); AnElement := FindKeyNode(XIBObjectElement, 'object', XIBPropertiesStrings[index].APropertyName);
if assigned(AnElement) then if assigned(AnElement) then
AnElement.ParentNode.RemoveChild(AnElement); AnElement.ParentNode.RemoveChild(AnElement);
end end
@ -2360,7 +2418,7 @@ begin
fr := b / $ff; fr := b / $ff;
s := FloatToStr(fr)+' '+FloatToStr(fg)+' '+FloatToStr(fb); s := FloatToStr(fr)+' '+FloatToStr(fg)+' '+FloatToStr(fb);
AnElement := FindKeyNode(FXIBObjectElement, 'object', XIBPropertiesStrings[index].APropertyName); AnElement := FindKeyNode(XIBObjectElement, 'object', XIBPropertiesStrings[index].APropertyName);
if assigned(AnElement) then if assigned(AnElement) then
begin begin
AnElement := FindKeyNode(AnElement,'bytes','NSRGB'); AnElement := FindKeyNode(AnElement,'bytes','NSRGB');
@ -2368,7 +2426,7 @@ begin
end end
else else
begin begin
AnElement := GetKeyNode(FXIBObjectElement, 'object', XIBPropertiesStrings[index].APropertyName); AnElement := GetKeyNode(XIBObjectElement, 'object', XIBPropertiesStrings[index].APropertyName);
AnElement.AttribStrings['class'] := 'NSColor'; AnElement.AttribStrings['class'] := 'NSColor';
AddIBInt(AnElement,'NSColorSpace',1); AddIBInt(AnElement,'NSColorSpace',1);
AddIBBytes(AnElement,'NSRGB',s); AddIBBytes(AnElement,'NSRGB',s);
@ -2395,7 +2453,7 @@ procedure tiOSFakeComponent.DefineProperties(Filer: TFiler);
begin begin
inherited DefineProperties(Filer); inherited DefineProperties(Filer);
if filer is TXIBReader then if filer is TXIBReader then
FXIBObjectElement := TXIBObjectReader(TReader(Filer).Driver).FCurrentObject; SetXIBObjectElement(TXIBObjectReader(TReader(Filer).Driver).FCurrentObject);
end; end;
function tiOSFakeComponent.GetKeyNode(AParentNode: TDOMNode; NodeName, Key: string; AClass: string): TDOMElement; function tiOSFakeComponent.GetKeyNode(AParentNode: TDOMNode; NodeName, Key: string; AClass: string): TDOMElement;
@ -2474,6 +2532,19 @@ begin
result := False; result := False;
end; end;
procedure tiOSFakeComponent.SetName(const NewName: TComponentName);
var
AnElement: TDOMElement;
begin
inherited SetName(NewName);
if not (csLoading in ComponentState) and assigned(XIBObjectElement) then
begin
AnElement := FindOrderdObjectByRef(Ref);
AnElement := GetKeyNode(AnElement, 'string','objectName');
AnElement.TextContent := NewName;
end;
end;
procedure tiOSFakeComponent.AddConnectionRecord(AnObjectDomElement: TDOMElement; AConnectionType, ALabel, AEventType: string); procedure tiOSFakeComponent.AddConnectionRecord(AnObjectDomElement: TDOMElement; AConnectionType, ALabel, AEventType: string);
var var
IBConnectionRecordElement : TDOMElement; IBConnectionRecordElement : TDOMElement;
@ -2619,18 +2690,18 @@ begin
exit; exit;
Invalidate; Invalidate;
if assigned(FXIBObjectElement) then if assigned(XIBObjectElement) then
begin begin
if StoreSizeAsFrameSize then if StoreSizeAsFrameSize then
begin begin
AFrameNode := GetKeyNode(FXIBObjectElement,'string','NSFrameSize'); AFrameNode := GetKeyNode(XIBObjectElement,'string','NSFrameSize');
s := Format('{%d, %d}',[NewWidth, NewHeight]); s := Format('{%d, %d}',[NewWidth, NewHeight]);
FLeft:=NewLeft; FLeft:=NewLeft;
FTop:=NewTop; FTop:=NewTop;
end end
else else
begin begin
AFrameNode := GetKeyNode(FXIBObjectElement,'string','NSFrame'); AFrameNode := GetKeyNode(XIBObjectElement,'string','NSFrame');
s := Format('{{%d, %d}, {%D, %d}}',[NewLeft, NewTop, NewWidth, NewHeight]); s := Format('{{%d, %d}, {%D, %d}}',[NewLeft, NewTop, NewWidth, NewHeight]);
end; end;
AFrameNode.TextContent:=s; AFrameNode.TextContent:=s;
@ -3032,7 +3103,7 @@ var
s: string; s: string;
ANode: TDOMElement; ANode: TDOMElement;
begin begin
ANode := FindKeyNode(FXIBObjectElement, 'reference', 'NSSuperview'); ANode := FindKeyNode(XIBObjectElement, 'reference', 'NSSuperview');
if assigned(ANode) then if assigned(ANode) then
begin begin
s := ANode.AttribStrings['ref']; s := ANode.AttribStrings['ref'];
@ -3054,16 +3125,16 @@ procedure UIView.SetNSSuperView(AValue: UIView);
var var
ANode: TDOMElement; ANode: TDOMElement;
begin begin
if not assigned(FXIBObjectElement) then if not assigned(XIBObjectElement) then
raise exception.create('NoObjectElement'); raise exception.create('NoObjectElement');
if assigned(AValue) then if assigned(AValue) then
begin begin
ANode := GetKeyNode(FXIBObjectElement, 'reference', 'NSSuperview'); ANode := GetKeyNode(XIBObjectElement, 'reference', 'NSSuperview');
ANode.AttribStrings['ref'] := IntToStr(AValue.Ref); ANode.AttribStrings['ref'] := IntToStr(AValue.Ref);
end end
else else
begin begin
ANode := FindKeyNode(FXIBObjectElement, 'reference', 'NSSuperview'); ANode := FindKeyNode(XIBObjectElement, 'reference', 'NSSuperview');
if assigned(ANode) then if assigned(ANode) then
ANode.ParentNode.RemoveChild(ANode); ANode.ParentNode.RemoveChild(ANode);
end; end;
@ -3076,18 +3147,18 @@ var
begin begin
if GetXIBString(index, ANodeName)=AValue then if GetXIBString(index, ANodeName)=AValue then
Exit; Exit;
if Assigned(FXIBObjectElement) then if Assigned(XIBObjectElement) then
begin begin
if (AValue = XIBPropertiesStrings[index].ADefaultValue) then if (AValue = XIBPropertiesStrings[index].ADefaultValue) then
begin begin
// Value is set to default, remove node // Value is set to default, remove node
ANode := FindKeyNode(FXIBObjectElement, ANodeName, XIBPropertiesStrings[index].APropertyName); ANode := FindKeyNode(XIBObjectElement, ANodeName, XIBPropertiesStrings[index].APropertyName);
if assigned(ANode) then if assigned(ANode) then
ANode.ParentNode.RemoveChild(ANode); ANode.ParentNode.RemoveChild(ANode);
end end
else else
begin begin
ANode := GetKeyNode(FXIBObjectElement, ANodeName, XIBPropertiesStrings[index].APropertyName); ANode := GetKeyNode(XIBObjectElement, ANodeName, XIBPropertiesStrings[index].APropertyName);
ANode.TextContent:=AValue; ANode.TextContent:=AValue;
end; end;
Invalidate; Invalidate;
@ -3163,9 +3234,9 @@ function tiOSFakeComponent.GetXIBString(index: TXIBProperties; ANodeName: string
var var
ANode: TDOMNode; ANode: TDOMNode;
begin begin
if Assigned(FXIBObjectElement) then if Assigned(XIBObjectElement) then
begin begin
ANode := FindKeyNode(FXIBObjectElement, ANodeName, XIBPropertiesStrings[index].APropertyName); ANode := FindKeyNode(XIBObjectElement, ANodeName, XIBPropertiesStrings[index].APropertyName);
if not assigned(ANode) then if not assigned(ANode) then
result := XIBPropertiesStrings[index].ADefaultValue result := XIBPropertiesStrings[index].ADefaultValue
else else

View File

@ -45,7 +45,6 @@ var
nx,ny,nt: integer; nx,ny,nt: integer;
r,p: integer; r,p: integer;
begin begin
// CodeToolBoss.find;
r := FindNextCompilerDirectiveWithName((source as TCodeBuffer).Source, -1, 'FakeResource', False, p); r := FindNextCompilerDirectiveWithName((source as TCodeBuffer).Source, -1, 'FakeResource', False, p);
result := (r > -1) result := (r > -1)
end; end;
@ -76,7 +75,7 @@ end;
class function TXIBResourcefileFormat.GetClassNameFromStream(s: TStream; out class function TXIBResourcefileFormat.GetClassNameFromStream(s: TStream; out
IsInherited: Boolean): shortstring; IsInherited: Boolean): shortstring;
begin begin
result := 'TSObject1'; result := 'TAppDelegate_iPhone';
end; end;
class function TXIBResourcefileFormat.CreateReader(s: TStream; class function TXIBResourcefileFormat.CreateReader(s: TStream;
@ -94,11 +93,32 @@ end;
class function TXIBResourcefileFormat.QuickCheckResourceBuffer(PascalBuffer, class function TXIBResourcefileFormat.QuickCheckResourceBuffer(PascalBuffer,
LFMBuffer: TObject; out LFMType, LFMComponentName, LFMClassName: string; out LFMBuffer: TObject; out LFMType, LFMComponentName, LFMClassName: string; out
LCLVersion: string; out MissingClasses: TStrings): TModalResult; LCLVersion: string; out MissingClasses: TStrings): TModalResult;
var
ms: TStream;
XMLDocument: TXMLDocument;
RO, CR, OO, MO : TDOMElement;
i: int64;
b: boolean;
AnElement: TDOMElement;
begin begin
ms := TStringStream.Create((LFMBuffer as TCodeBuffer).Source);
try
ObtainBaseObjectInfoFromXIB(ms, XMLDocument, RO, CR, OO, MO,i, b);
try
AnElement := FindKeyNode(MO,'string','objectName');
if assigned(AnElement) then
LFMComponentName:=AnElement.TextContent;
finally
XMLDocument.Free;
end;
finally
ms.Free;
end;
LCLVersion:='1.1'; LCLVersion:='1.1';
LFMType:='unknown'; LFMType:='unknown';
LFMClassName:='TSObject1'; LFMClassName:='TAppDelegate_iPhone';
LFMComponentName:='SObject1';
end; end;
end. end.