* Register components on different pages

* When a control on a view is unknown, show a UIxcodePlaceholder component
 * Redraw after changing the title of a UISegmentedControl
 * Removed commented code


git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2874 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
loesje_
2013-12-29 12:58:57 +00:00
parent f76acb185e
commit de918f9d48
2 changed files with 91 additions and 51 deletions

View File

@@ -37,7 +37,8 @@ unit iOS_Views;
interface interface
uses uses
Classes, SysUtils, Math, types, DOM, XMLWrite, XMLRead, Graphics, strutils; Classes, SysUtils, Math, types, DOM, XMLWrite, XMLRead, Graphics, strutils,
ComponentReg;
type type
TXIBProperties = ( TXIBProperties = (
@@ -213,7 +214,7 @@ type
procedure SetName(const NewName: TComponentName); override; procedure SetName(const NewName: TComponentName); override;
// iOS // iOS
procedure AddConnectionRecord(AnObjectDomElement: TDOMElement; AConnectionType, ALabel, AEventType: string); procedure AddConnectionRecord(AnObjectDomElement: TDOMElement; AConnectionType, ALabel, AEventType: string);
class function GetIBClassName: string; virtual; function GetIBClassName: string; virtual;
function GetDesigner: IMyWidgetDesigner; virtual; function GetDesigner: IMyWidgetDesigner; virtual;
function GetHeight: integer; virtual; function GetHeight: integer; virtual;
function GetLeft: integer; virtual; function GetLeft: integer; virtual;
@@ -287,6 +288,19 @@ type
property Height: integer read GetHeight write SetHeight; property Height: integer read GetHeight write SetHeight;
end; end;
{ UIxcodePlaceholder }
UIxcodePlaceholder = class(tiOSFakeComponent)
private
function GetXcodeClassName: string;
procedure SetXcodeClassName(AValue: string);
public
procedure paint(ACanvas: TCanvas); override;
function GetIBClassName: string; override;
published
property XcodeClassName: string read GetXcodeClassName write SetXcodeClassName;
end;
{ UIView } { UIView }
UIView = class(tiOSFakeComponent) UIView = class(tiOSFakeComponent)
@@ -305,7 +319,7 @@ type
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
procedure InitializeDefaults; override; procedure InitializeDefaults; override;
procedure paint(ACanvas: TCanvas); override; procedure paint(ACanvas: TCanvas); override;
class function GetIBClassName: string; override; function GetIBClassName: string; override;
property NSSuperview: UIView index bvSuperview read GetXIBObject write SetXIBObject; property NSSuperview: UIView index bvSuperview read GetXIBObject write SetXIBObject;
property NSNextResponder: UIView index bvNextResponder read GetXIBObject write SetXIBObject; property NSNextResponder: UIView index bvNextResponder read GetXIBObject write SetXIBObject;
property Flags: Int64 index bvFlags read GetXIBInt64 write SetXIBInt64; property Flags: Int64 index bvFlags read GetXIBInt64 write SetXIBInt64;
@@ -345,7 +359,7 @@ type
destructor Destroy; override; destructor Destroy; override;
function GetDesigner: IMyWidgetDesigner; override; function GetDesigner: IMyWidgetDesigner; override;
procedure InitializeDefaults; override; procedure InitializeDefaults; override;
class function GetIBClassName: string; override; function GetIBClassName: string; override;
property Designer: IMyWidgetDesigner read FDesigner write FDesigner; property Designer: IMyWidgetDesigner read FDesigner write FDesigner;
property NIBDocument: TXMLDocument read FNIBDocument; property NIBDocument: TXMLDocument read FNIBDocument;
property XIBUsesObjectsForArrays: boolean read FXIBUsesObjectsForArrays; property XIBUsesObjectsForArrays: boolean read FXIBUsesObjectsForArrays;
@@ -372,7 +386,7 @@ type
procedure InitializeDefaults; override; procedure InitializeDefaults; override;
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
procedure paint(ACanvas: TCanvas); override; procedure paint(ACanvas: TCanvas); override;
class function GetIBClassName: string; override; function GetIBClassName: string; override;
published published
property StatusBar: TiOSFakeStatusBarStyle read GetStatusBar write SetStatusBar; property StatusBar: TiOSFakeStatusBarStyle read GetStatusBar write SetStatusBar;
property ResizesToFullScreen: boolean index bvFullScreen read GetXIBBoolean write SetXIBBoolean; property ResizesToFullScreen: boolean index bvFullScreen read GetXIBBoolean write SetXIBBoolean;
@@ -388,7 +402,7 @@ type
procedure SetBounds(NewLeft, NewTop, NewWidth, NewHeight: integer); override; procedure SetBounds(NewLeft, NewTop, NewWidth, NewHeight: integer); override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
class function GetIBClassName: string; override; function GetIBClassName: string; override;
end; end;
{ UINavigationBar } { UINavigationBar }
@@ -399,7 +413,7 @@ type
procedure paint(ACanvas: TCanvas); override; procedure paint(ACanvas: TCanvas); override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
class function GetIBClassName: string; override; function GetIBClassName: string; override;
end; end;
{ UINavigationItem } { UINavigationItem }
@@ -410,7 +424,7 @@ type
procedure SetBounds(NewLeft, NewTop, NewWidth, NewHeight: integer); override; procedure SetBounds(NewLeft, NewTop, NewWidth, NewHeight: integer); override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
class function GetIBClassName: string; override; function GetIBClassName: string; override;
end; end;
{ UISegmentedControl } { UISegmentedControl }
@@ -427,7 +441,7 @@ type
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
procedure paint(ACanvas: TCanvas); override; procedure paint(ACanvas: TCanvas); override;
class function GetIBClassName: string; override; function GetIBClassName: string; override;
property SegmentCount: integer index bvSegments read GetXIBInteger; property SegmentCount: integer index bvSegments read GetXIBInteger;
published published
property Segments: TCollection read GetSegments; property Segments: TCollection read GetSegments;
@@ -456,7 +470,7 @@ type
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
procedure InitializeDefaultChildren; override; procedure InitializeDefaultChildren; override;
class function GetIBClassName: string; override; function GetIBClassName: string; override;
published published
end; end;
@@ -480,7 +494,7 @@ type
public public
procedure InitializeDefaults; override; procedure InitializeDefaults; override;
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
class function GetIBClassName: string; override; function GetIBClassName: string; override;
procedure paint(ACanvas: TCanvas); override; procedure paint(ACanvas: TCanvas); override;
property NSNextKeyView: UIView read FNSNextKeyView write FNSNextKeyView; property NSNextKeyView: UIView read FNSNextKeyView write FNSNextKeyView;
@@ -504,7 +518,7 @@ type
procedure SetTextAlignment(AValue: TiOSFakeAlignment); procedure SetTextAlignment(AValue: TiOSFakeAlignment);
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
class function GetIBClassName: string; override; function GetIBClassName: string; override;
procedure paint(ACanvas: TCanvas); override; procedure paint(ACanvas: TCanvas); override;
published published
property Lines: integer index bvLines read GetXIBInteger write SetXIBInteger; property Lines: integer index bvLines read GetXIBInteger write SetXIBInteger;
@@ -525,7 +539,7 @@ type
procedure SetTextAlignment(AValue: TiOSFakeAlignment); procedure SetTextAlignment(AValue: TiOSFakeAlignment);
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
class function GetIBClassName: string; override; function GetIBClassName: string; override;
procedure paint(ACanvas: TCanvas); override; procedure paint(ACanvas: TCanvas); override;
published published
property Placeholder: string index bvPlaceHolder read GetXIBString write SetXIBString; property Placeholder: string index bvPlaceHolder read GetXIBString write SetXIBString;
@@ -547,7 +561,7 @@ type
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
procedure InitializeDefaults; override; procedure InitializeDefaults; override;
procedure paint(ACanvas: TCanvas); override; procedure paint(ACanvas: TCanvas); override;
class function GetIBClassName: string; override; function GetIBClassName: string; override;
published published
property RowHeight: double index bvRowHeight read GetXIBFloat write SetXIBFloat; property RowHeight: double index bvRowHeight read GetXIBFloat write SetXIBFloat;
property SectionHeaderHeight: double index bvSectionHeaderHeigh read GetXIBFloat write SetXIBFloat; property SectionHeaderHeight: double index bvSectionHeaderHeigh read GetXIBFloat write SetXIBFloat;
@@ -571,7 +585,7 @@ type
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
procedure InitializeDefaults; override; procedure InitializeDefaults; override;
class function GetIBClassName: string; override; function GetIBClassName: string; override;
published published
property Caption; property Caption;
property Placeholder: string index bvPlaceHolder read GetXIBString write SetXIBString; property Placeholder: string index bvPlaceHolder read GetXIBString write SetXIBString;
@@ -588,7 +602,7 @@ type
procedure SetProgressViewStyle(AValue: TiOSFakeProgressViewStyle); procedure SetProgressViewStyle(AValue: TiOSFakeProgressViewStyle);
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
class function GetIBClassName: string; override; function GetIBClassName: string; override;
published published
property progressViewStyle: TiOSFakeProgressViewStyle read GetProgressViewStyle write SetProgressViewStyle; property progressViewStyle: TiOSFakeProgressViewStyle read GetProgressViewStyle write SetProgressViewStyle;
property progress: double index bvProgress read GetXIBFloat write SetXIBFloat; property progress: double index bvProgress read GetXIBFloat write SetXIBFloat;
@@ -737,6 +751,41 @@ begin
end; end;
end; end;
{ UIxcodePlaceholder }
function UIxcodePlaceholder.GetXcodeClassName: string;
begin
result := XIBObjectElement.AttribStrings['class'];
end;
procedure UIxcodePlaceholder.SetXcodeClassName(AValue: string);
begin
if AValue<>GetXcodeClassName then
begin
if assigned(GetClass(AValue)) then
raise exception.create('Invalid class name for placeholder: class does exist.');
XIBObjectElement.AttribStrings['class'] := AValue;
end;
end;
procedure UIxcodePlaceholder.paint(ACanvas: TCanvas);
begin
with ACanvas do
begin
Brush.Color:=clInactiveBorder;
Pen.Color:=clGradientInactiveCaption;
Brush.Style:=bsBDiagonal;
pen.Style:=psSolid;
// Background
Rectangle(0,0,self.Width,self.Height);
end;
end;
function UIxcodePlaceholder.GetIBClassName: string;
begin
Result:=GetXcodeClassName;
end;
{ TiOSSegmentedControlSegment } { TiOSSegmentedControlSegment }
function TiOSSegmentedControlSegment.GetTitle: string; function TiOSSegmentedControlSegment.GetTitle: string;
@@ -771,6 +820,7 @@ begin
ANode := FindKeyNode(FSegmentedControl.XIBObjectElement, 'array', 'IBSegmentTitles'); ANode := FindKeyNode(FSegmentedControl.XIBObjectElement, 'array', 'IBSegmentTitles');
ANode := ANode.ChildNodes.Item[ID]; ANode := ANode.ChildNodes.Item[ID];
ANode.TextContent := AValue; ANode.TextContent := AValue;
FSegmentedControl.Invalidate;
end; end;
{ UISegmentedControl } { UISegmentedControl }
@@ -792,24 +842,6 @@ begin
ASegment.FSegmentedControl := self; ASegment.FSegmentedControl := self;
end; end;
FCreatingSegments:=false;; FCreatingSegments:=false;;
{ if Assigned(XIBObjectElement) then
begin
ANode := FindKeyNode(XIBObjectElement, 'array', 'IBSegmentTitles');
if assigned(ANode) then
begin
ANode := ANode.FirstChild;
//i := 0;
while assigned(ANode) do
begin
ASegment := (FSegments.Add as TiOSSegmentedControlSegment);
//ASegment.Title:=ANode.TextContent;
ASegment.FSegmentedControl := self;
ANode := ANode.NextSibling;
//inc(i);
end;
end
end}
end; end;
result := FSegments; result := FSegments;
end; end;
@@ -916,7 +948,7 @@ begin
end; end;
end; end;
class function UISegmentedControl.GetIBClassName: string; function UISegmentedControl.GetIBClassName: string;
begin begin
Result:='IBUISegmentedControl'; Result:='IBUISegmentedControl';
end; end;
@@ -1259,7 +1291,11 @@ begin
CompName:=ObjectNode.TextContent; CompName:=ObjectNode.TextContent;
if copy(CompClassName,1,2)='IB' then if copy(CompClassName,1,2)='IB' then
begin
CompClassName:=copy(CompClassName,3,250); CompClassName:=copy(CompClassName,3,250);
if not assigned(IDEComponentPalette.FindComponent(CompClassName)) then
CompClassName := 'UIxcodePlaceholder';
end;
FReadChilds := False; FReadChilds := False;
if ReadState=rsHasRootChilds then if ReadState=rsHasRootChilds then
ReadState:=rsRootObjectProp ReadState:=rsRootObjectProp
@@ -1615,7 +1651,7 @@ begin
trackTintColor := clDefault; trackTintColor := clDefault;
end; end;
class function UIProgressView.GetIBClassName: string; function UIProgressView.GetIBClassName: string;
begin begin
Result:='IBUIProgressView'; Result:='IBUIProgressView';
end; end;
@@ -1641,7 +1677,7 @@ begin
Height:=44; Height:=44;
end; end;
class function UINavigationItem.GetIBClassName: string; function UINavigationItem.GetIBClassName: string;
begin begin
Result:='IBUINavigationItem'; Result:='IBUINavigationItem';
end; end;
@@ -1703,7 +1739,7 @@ begin
FAcceptChildsAtDesignTime:=true; FAcceptChildsAtDesignTime:=true;
end; end;
class function UIViewController.GetIBClassName: string; function UIViewController.GetIBClassName: string;
begin begin
Result:='IBUIViewController'; Result:='IBUIViewController';
end; end;
@@ -1736,7 +1772,7 @@ begin
FAcceptChildsAtDesignTime:=false; FAcceptChildsAtDesignTime:=false;
end; end;
class function UINavigationBar.GetIBClassName: string; function UINavigationBar.GetIBClassName: string;
begin begin
Result:='IBUINavigationBar'; Result:='IBUINavigationBar';
end; end;
@@ -1812,7 +1848,7 @@ begin
end end
end; end;
class function UINavigationController.GetIBClassName: string; function UINavigationController.GetIBClassName: string;
begin begin
Result:='IBUINavigationController'; Result:='IBUINavigationController';
end; end;
@@ -1936,7 +1972,7 @@ begin
end; end;
end; end;
class function UIWindow.GetIBClassName: string; function UIWindow.GetIBClassName: string;
begin begin
Result:='IBUIWindow'; Result:='IBUIWindow';
end; end;
@@ -2182,7 +2218,7 @@ begin
FilesOwnerOutletName:='delegate'; FilesOwnerOutletName:='delegate';
end; end;
class function NSObject.GetIBClassName: string; function NSObject.GetIBClassName: string;
begin begin
Result:='IBUICustomObject'; Result:='IBUICustomObject';
end; end;
@@ -3044,7 +3080,7 @@ begin
AddIBInt(IBConnectionElement,'IBEventType',StrToInt64Def(AEventType,1)); AddIBInt(IBConnectionElement,'IBEventType',StrToInt64Def(AEventType,1));
end; end;
class function tiOSFakeComponent.GetIBClassName: string; function tiOSFakeComponent.GetIBClassName: string;
begin begin
result := ''; result := '';
end; end;
@@ -3370,7 +3406,7 @@ begin
Opaque:=true; Opaque:=true;
end; end;
class function UISearchBar.GetIBClassName: string; function UISearchBar.GetIBClassName: string;
begin begin
Result:='IBUISearchBar'; Result:='IBUISearchBar';
end; end;
@@ -3449,7 +3485,7 @@ begin
end; end;
end; end;
class function UITableView.GetIBClassName: string; function UITableView.GetIBClassName: string;
begin begin
Result:='IBUITableView'; Result:='IBUITableView';
end; end;
@@ -3481,7 +3517,7 @@ begin
FAcceptChildsAtDesignTime:=false; FAcceptChildsAtDesignTime:=false;
end; end;
class function UITextField.GetIBClassName: string; function UITextField.GetIBClassName: string;
begin begin
Result:='IBUITextField'; Result:='IBUITextField';
end; end;
@@ -3669,7 +3705,7 @@ begin
FAcceptChildsAtDesignTime:=false; FAcceptChildsAtDesignTime:=false;
end; end;
class function UILabel.GetIBClassName: string; function UILabel.GetIBClassName: string;
begin begin
result := 'IBUILabel'; result := 'IBUILabel';
end; end;
@@ -3919,7 +3955,7 @@ begin
end; end;
end; end;
class function UIView.GetIBClassName: string; function UIView.GetIBClassName: string;
begin begin
result := 'IBUIView'; result := 'IBUIView';
end; end;
@@ -3962,7 +3998,7 @@ begin
FAcceptChildsAtDesignTime:=false; FAcceptChildsAtDesignTime:=false;
end; end;
class function UIButton.GetIBClassName: string; function UIButton.GetIBClassName: string;
begin begin
result := 'IBUIButton'; result := 'IBUIButton';
end; end;
@@ -3971,7 +4007,7 @@ procedure UIButton.paint(ACanvas: TCanvas);
var var
ARadius: integer; ARadius: integer;
begin begin
inherited; Inherited;
with ACanvas do with ACanvas do
begin begin
brush.Color:=clWhite; brush.Color:=clWhite;

View File

@@ -155,7 +155,10 @@ procedure Register;
begin begin
FormEditingHook.RegisterDesignerMediator(TNSObjectDesignerMediator); FormEditingHook.RegisterDesignerMediator(TNSObjectDesignerMediator);
FormEditingHook.RegisterDesignerMediator(TUIResponderDesignerMediator); FormEditingHook.RegisterDesignerMediator(TUIResponderDesignerMediator);
RegisterComponents('iOS',[UIWindow,UINavigationController,UIButton,UILabel,UITextField,UITableView,UISearchBar,UIView,UIViewController, UIProgressView, UISegmentedControl]); RegisterComponents('iOS-Windows && Bars',[UIWindow, UISearchBar, UIView, UIxcodePlaceholder]);
RegisterComponents('iOS-Data Views',[UITableView, UITextField]);
RegisterComponents('iOS-Controls',[UIButton, UILabel, UIProgressView, UISegmentedControl]);
RegisterComponents('iOS-Objects & Controllers',[UINavigationController, UIViewController]);
GiOSEventHandlers := TiOSEventHandlers.Create; GiOSEventHandlers := TiOSEventHandlers.Create;
@@ -179,6 +182,7 @@ begin
SetFakeUnitname(UIViewController); SetFakeUnitname(UIViewController);
SetFakeUnitname(UIProgressView); SetFakeUnitname(UIProgressView);
SetFakeUnitname(UISegmentedControl); SetFakeUnitname(UISegmentedControl);
SetFakeUnitname(UIxcodePlaceholder);
end; end;
{ TiOSEventHandlers } { TiOSEventHandlers }