Parcourir la source

design: started TFresnelForm a descendent of viewport and TFresnelFormMediator

mattias il y a 2 ans
Parent
commit
b62838287a
4 fichiers modifiés avec 613 ajouts et 58 suppressions
  1. 81 12
      design/fresnelregister.pas
  2. 31 29
      src/fresneldom.pas
  3. 1 1
      src/fresnellayouter.pas
  4. 500 16
      src/fresnellclcontrols.pas

+ 81 - 12
design/fresnelregister.pas

@@ -16,11 +16,12 @@ interface
 
 uses
   LCLProc, LCLType, Classes, SysUtils, FormEditingIntf, LCLIntf, Graphics,
-  Controls, ProjectIntf, FresnelDOM, FresnelControls, FresnelLCLControls;
+  Controls, Forms, ProjectIntf, LazLoggerBase, FresnelDOM, FresnelControls,
+  FresnelLCLControls;
 
 type
 
-  { TFresnelFormMediator }
+  { TFresnelFormMediator - mediator for TFresnelForm }
 
   TFresnelFormMediator = class(TDesignerMediator,IFresnelFormDesigner)
   private
@@ -28,6 +29,7 @@ type
   protected
     procedure Notification(AComponent: TComponent; Operation: TOperation);
       override;
+    procedure SetLCLForm(const AValue: TForm); override;
   public
     // needed by the Lazarus form editor
     class function CreateMediator(TheOwner, aForm: TComponent): TDesignerMediator;
@@ -48,8 +50,11 @@ type
     function ParentAcceptsChild(Parent: TComponent;
                 Child: TComponentClass): boolean; override;
   public
-    // needed by Renderer
+    // needed by Fresnel
     procedure InvalidateRect(Sender: TObject; ARect: TRect; Erase: boolean);
+    procedure SetDesignerFormBounds(Sender: TObject; NewBounds: TRect);
+    function GetDesignerClientHeight: integer;
+    function GetDesignerClientWidth: integer;
     property DsgnForm: TFresnelForm read FDsgnForm;
   end;
 
@@ -91,6 +96,14 @@ begin
   end;
 end;
 
+procedure TFresnelFormMediator.SetLCLForm(const AValue: TForm);
+begin
+  if LCLForm=AValue then exit;
+  inherited SetLCLForm(AValue);
+  if FDsgnForm=nil then exit;
+  FDsgnForm.Canvas:=LCLForm.Canvas;
+end;
+
 class function TFresnelFormMediator.CreateMediator(TheOwner, aForm: TComponent
   ): TDesignerMediator;
 var
@@ -99,6 +112,7 @@ begin
   Result:=inherited CreateMediator(TheOwner,aForm);
   Mediator:=TFresnelFormMediator(Result);
   Mediator.FDsgnForm:=aForm as TFresnelForm;
+  Mediator.FDsgnForm.Designer:=Mediator;
   Mediator.FreeNotification(aForm);
 end;
 
@@ -113,25 +127,46 @@ var
   El: TFresnelElement;
   aBorderBox: TFresnelRect;
 begin
-  if AComponent is TFresnelElement then begin
+  if AComponent=FDsgnForm then
+  begin
+    CurBounds:=FDsgnForm.FormBoundsRect;
+  end else if AComponent is TFresnelElement then
+  begin
     El:=TFresnelElement(AComponent);
     aBorderBox:=El.RenderedBorderBox;
     FresnelRectToRect(aBorderBox,CurBounds);
   end else
     inherited GetBounds(AComponent,CurBounds);
+  //debugln(['TFresnelFormMediator.GetBounds ',DbgSName(AComponent),' ',dbgs(CurBounds)]);
 end;
 
 procedure TFresnelFormMediator.SetBounds(AComponent: TComponent;
   NewBounds: TRect);
 begin
-  // bounds are controlled by CSS
-  inherited SetBounds(AComponent, NewBounds);
+  debugln(['TFresnelFormMediator.SetBounds ',DbgSName(AComponent),' ',dbgs(NewBounds)]);
+  if AComponent=FDsgnForm then
+  begin
+    FDsgnForm.FormBoundsRect:=NewBounds;
+    if LCLForm<>nil then
+      debugln(['TFresnelFormMediator.SetBounds lclform=',dbgs(LCLForm.BoundsRect)]);
+  end else if AComponent is TFresnelElement then
+  begin
+    // bounds are controlled by CSS
+  end else begin
+    inherited SetBounds(AComponent, NewBounds);
+  end;
 end;
 
 procedure TFresnelFormMediator.GetClientArea(AComponent: TComponent; out
   CurClientArea: TRect; out ScrollOffset: TPoint);
 begin
-  inherited GetClientArea(AComponent, CurClientArea, ScrollOffset);
+  if AComponent=FDsgnForm then
+  begin
+    CurClientArea:=FDsgnForm.Form.ClientRect;
+    ScrollOffset:=Point(0,0);
+  end else begin
+    inherited GetClientArea(AComponent, CurClientArea, ScrollOffset);
+  end;
 end;
 
 function TFresnelFormMediator.GetComponentOriginOnForm(AComponent: TComponent
@@ -140,7 +175,10 @@ var
   El: TFresnelElement;
   BorderBox: TFresnelRect;
 begin
-  if AComponent is TFresnelElement then
+  if AComponent=FDsgnForm then
+  begin
+    Result:=Point(0,0);
+  end else if AComponent is TFresnelElement then
   begin
     El:=TFresnelElement(AComponent);
     if not El.Rendered then
@@ -154,7 +192,8 @@ end;
 
 procedure TFresnelFormMediator.Paint;
 begin
-  inherited Paint;
+  if FDsgnForm=nil then exit;
+  FDsgnForm.Renderer.Draw(FDsgnForm);
 end;
 
 function TFresnelFormMediator.ComponentIsIcon(AComponent: TComponent): boolean;
@@ -168,7 +207,9 @@ end;
 function TFresnelFormMediator.ComponentIsVisible(AComponent: TComponent
   ): Boolean;
 begin
-  if AComponent is TFresnelElement then
+  if AComponent=FDsgnForm then
+    Result:=true
+  else if AComponent is TFresnelElement then
     Result:=TFresnelElement(AComponent).Rendered
   else
     Result:=true;
@@ -177,12 +218,17 @@ end;
 function TFresnelFormMediator.ComponentAtPos(p: TPoint;
   MinClass: TComponentClass; Flags: TDMCompAtPosFlags): TComponent;
 begin
-  Result:=DsgnForm.Viewport.GetElementAt(p.X,p.Y);
+  if Flags=[] then ;
+  Result:=DsgnForm.GetElementAt(p.X,p.Y);
+  if Result=nil then exit;
+  if (MinClass<>nil) and not Result.InheritsFrom(MinClass) then
+    Result:=nil;
 end;
 
 function TFresnelFormMediator.ParentAcceptsChild(Parent: TComponent;
   Child: TComponentClass): boolean;
 begin
+  debugln(['AAA1 TFresnelFormMediator.ParentAcceptsChild Parent=',DbgSName(Parent),' Child=',DbgSName(Child)]);
   if Child.InheritsFrom(TControl) then
     Result:=false
   else if Child.InheritsFrom(TFresnelViewport) then
@@ -194,6 +240,7 @@ begin
     Result:=Child.InheritsFrom(TFresnelElement);
   end else
     Result:=inherited ParentAcceptsChild(Parent, Child);
+  debugln(['AAA2 TFresnelFormMediator.ParentAcceptsChild Parent=',DbgSName(Parent),' Child=',DbgSName(Child),' Result=',Result]);
 end;
 
 constructor TFresnelFormMediator.Create(AOwner: TComponent);
@@ -215,6 +262,29 @@ begin
   LCLIntf.InvalidateRect(LCLForm.Handle,@ARect,Erase);
 end;
 
+procedure TFresnelFormMediator.SetDesignerFormBounds(Sender: TObject;
+  NewBounds: TRect);
+begin
+  if LCLForm=nil then exit;
+  LCLForm.BoundsRect:=NewBounds;
+end;
+
+function TFresnelFormMediator.GetDesignerClientHeight: integer;
+begin
+  if LCLForm=nil then
+    Result:=FDsgnForm.Form.ClientHeight
+  else
+    Result:=LCLForm.ClientHeight;
+end;
+
+function TFresnelFormMediator.GetDesignerClientWidth: integer;
+begin
+  if LCLForm=nil then
+    Result:=FDsgnForm.Form.ClientWidth
+  else
+    Result:=LCLForm.ClientWidth;
+end;
+
 { TFileDescPascalUnitWithFresnelForm }
 
 constructor TFileDescPascalUnitWithFresnelForm.Create;
@@ -222,7 +292,6 @@ begin
   inherited Create;
   Name:='FresnelForm';
   ResourceClass:=TFresnelForm;
-  UseCreateFormStatements:=true;
 end;
 
 function TFileDescPascalUnitWithFresnelForm.GetInterfaceUsesSection: string;

+ 31 - 29
src/fresneldom.pas

@@ -23,8 +23,9 @@ unit FresnelDOM;
 interface
 
 uses
-  Classes, SysUtils, Math, sortbase, LazLoggerBase, fpCSSResolver,
-  fpCSSTree, fpCSSParser, FPImage;
+  Classes, SysUtils, Math, FPImage, sortbase,
+  fpCSSResolver, fpCSSTree, fpCSSParser,
+  LazLoggerBase;
 
 type
   TFresnelLength = double;
@@ -212,10 +213,6 @@ const
     );
 
 type
-  IFresnelFormDesigner = interface
-    ['{095CB7DD-E291-45B6-892E-F486A38E597C}']
-  end;
-
   TFresnelViewport = class;
   TFresnelElement = class;
 
@@ -378,6 +375,7 @@ type
     function GetViewport: TFresnelViewport; virtual;
     function ElementAttrToAttrId(Attr: TFresnelCSSAttribute): TCSSNumericalID;
     function GetFont: IFresnelFont; virtual;
+    procedure FPOObservedChanged(ASender: TObject; Operation: TFPObservedOperation; Data: Pointer); virtual;
   protected
     procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
     procedure SetParentComponent(Value: TComponent); override;
@@ -390,7 +388,6 @@ type
     function GetRoot: TFresnelElement;
     function GetPath: string; virtual;
     function AcceptChildrenAtDesignTime: boolean; virtual;
-    procedure FPOObservedChanged(ASender: TObject; Operation: TFPObservedOperation; Data: Pointer); virtual;
     procedure DomChanged; virtual;
     property Parent: TFresnelElement read FParent write SetParent;
     property NodeCount: integer read GetNodeCount;
@@ -482,7 +479,7 @@ type
 
   { TFresnelViewport }
 
-  TFresnelViewport = class(TFresnelElement,IFPObserver)
+  TFresnelViewport = class(TFresnelElement)
   private
     FCSSResolver: TCSSResolver;
     FFontEngine: TFresnelFontEngine;
@@ -496,31 +493,31 @@ type
     FHeight: TFresnelLength;
     FWidth: TFresnelLength;
     FMaxPreferredWidth: TFresnelLength;
-    function GetHeight: TFresnelLength;
-    function GetMaxPreferredWidth: TFresnelLength;
-    function GetScrollbarWidth(IsHorizontal: boolean): TFresnelLength;
-    function GetVPLength(l: TFresnelViewportLength): TFresnelLength;
-    function GetWidth: TFresnelLength;
-    procedure SetFontMinSize(const AValue: TFresnelLength);
-    procedure SetHeight(AValue: TFresnelLength);
-    procedure SetMaxPreferredWidth(const AValue: TFresnelLength);
-    procedure SetScrollbarWidth(IsHorizontal: boolean;
-      const AValue: TFresnelLength);
-    procedure SetStylesheet(AValue: TStrings);
-    procedure SetVPLength(l: TFresnelViewportLength;
-      const AValue: TFresnelLength);
-    procedure SetWidth(AValue: TFresnelLength);
   protected
     function GetDPI(IsHorizontal: boolean): TFresnelLength; override;
-    procedure SetDPI(IsHorizontal: boolean; const AValue: TFresnelLength);
+    function GetHeight: TFresnelLength; virtual;
+    function GetMaxPreferredWidth: TFresnelLength; virtual;
+    function GetScrollbarWidth(IsHorizontal: boolean): TFresnelLength; virtual;
+    function GetVPLength(l: TFresnelViewportLength): TFresnelLength; virtual;
+    function GetWidth: TFresnelLength; virtual;
+    procedure FPOObservedChanged(ASender: TObject; {%H-}Operation: TFPObservedOperation; {%H-}Data: Pointer); override;
+    procedure InitCSSResolver(aResolver: TCSSResolver); override;
+    procedure Notification(AComponent: TComponent; Operation: TOperation);
+      override;
     procedure SetCSSElAttribute(Attr: TFresnelCSSAttribute; const AValue: string
       ); override;
+    procedure SetDPI(IsHorizontal: boolean; const AValue: TFresnelLength);
+    procedure SetFontMinSize(const AValue: TFresnelLength); virtual;
+    procedure SetHeight(AValue: TFresnelLength); virtual;
+    procedure SetMaxPreferredWidth(const AValue: TFresnelLength); virtual;
+    procedure SetScrollbarWidth(IsHorizontal: boolean;
+      const AValue: TFresnelLength); virtual;
+    procedure SetStylesheet(AValue: TStrings); virtual;
+    procedure SetVPLength(l: TFresnelViewportLength;
+      const AValue: TFresnelLength); virtual;
+    procedure SetWidth(AValue: TFresnelLength); virtual;
     procedure StylesheetChanged; virtual;
     procedure UpdateStylesheetElements; virtual;
-    procedure FPOObservedChanged(ASender: TObject; {%H-}Operation: TFPObservedOperation; {%H-}Data: Pointer); virtual;
-    procedure InitCSSResolver(aResolver: TCSSResolver); override;
-    procedure Notification(AComponent: TComponent; Operation: TOperation);
-      override;
   public
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
@@ -791,6 +788,7 @@ procedure TFresnelViewport.FPOObservedChanged(ASender: TObject;
 begin
   if ASender=FStylesheet then
     StylesheetChanged;
+  inherited FPOObservedChanged(ASender,Operation,Data);
 end;
 
 procedure TFresnelViewport.InitCSSResolver(aResolver: TCSSResolver);
@@ -927,7 +925,7 @@ end;
 
 procedure TFresnelViewport.DomChanged;
 begin
-  if assigned(OnDomChanged) then
+  if Assigned(OnDomChanged) then
     OnDomChanged(Self);
 end;
 
@@ -2462,7 +2460,9 @@ var
   aStreamRoot: IFresnelStreamRoot;
 begin
   debugln(['TFresnelElement.SetParentComponent Self=',DbgSName(Self),' NewParent=',DbgSName(Value)]);
-  if Value is TFresnelElement then
+  if Value=nil then
+    Parent:=nil
+  else if Value is TFresnelElement then
     Parent:=TFresnelElement(Value)
   else if Supports(Value,IFresnelStreamRoot,aStreamRoot) then
   begin
@@ -2548,6 +2548,8 @@ end;
 procedure TFresnelElement.FPOObservedChanged(ASender: TObject;
   Operation: TFPObservedOperation; Data: Pointer);
 begin
+  if Operation=ooFree then exit;
+  if Data=nil then ;
   if ASender=FCSSClasses then
     DomChanged;
 end;

+ 1 - 1
src/fresnellayouter.pas

@@ -903,7 +903,7 @@ begin
   if El.LayoutNode<>nil then
     Result:=TSimpleFresnelLayoutNode(El.LayoutNode)
   else begin
-    Result:=TSimpleFresnelLayoutNode.Create(El);
+    Result:=TSimpleFresnelLayoutNode.Create(nil);
     El.LayoutNode:=Result;
     Result.Element:=El;
   end;

+ 500 - 16
src/fresnellclcontrols.pas

@@ -98,9 +98,9 @@ type
     property LayoutQueued: boolean read FLayoutQueued write SetLayoutQueued;
   end;
 
-  { TFresnelCustomForm }
+  { TOldFresnelCustomForm }
 
-  TFresnelCustomForm = class(TCustomForm,IFresnelStreamRoot)
+  TOldFresnelCustomForm = class(TCustomForm,IFresnelStreamRoot)
   private
     FFontEngine: TFresnelLCLFontEngine;
     FLayouter: TSimpleFresnelLayouter;
@@ -123,20 +123,157 @@ type
     destructor Destroy; override;
     procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
     property Viewport: TFresnelViewport read FViewport;
-    property Layouter: TSimpleFresnelLayouter read FLayouter;
     property FontEngine: TFresnelLCLFontEngine read FFontEngine;
+    property Layouter: TSimpleFresnelLayouter read FLayouter;
+    property LayoutQueued: boolean read FLayoutQueued write SetLayoutQueued;
     property Renderer: TFresnelLCLRenderer read FRenderer;
     property Stylesheet: TStrings read GetStylesheet write SetStylesheet;
+  end;
+
+  { TOldFresnelForm }
+
+  TOldFresnelForm = class(TOldFresnelCustomForm)
+  published
+    property Stylesheet;
+  end;
+
+  IFresnelFormDesigner = interface
+    ['{095CB7DD-E291-45B6-892E-F486A38E597C}']
+    procedure InvalidateRect(Sender: TObject; ARect: TRect; Erase: boolean);
+    procedure SetDesignerFormBounds(Sender: TObject; NewBounds: TRect);
+    function GetDesignerClientWidth: integer;
+    function GetDesignerClientHeight: integer;
+  end;
+
+  { TCustomFresnelForm }
+
+  TCustomFresnelForm = class(TFresnelViewport)
+  private
+    FCanvas: TCanvas;
+    FClearing: boolean;
+    FDesigner: IFresnelFormDesigner;
+    FFontEngineLCL: TFresnelLCLFontEngine;
+    FForm: TCustomForm;
+    FLayouter: TSimpleFresnelLayouter;
+    FLayoutQueued: boolean;
+    FRenderer: TFresnelLCLRenderer;
+    FVisible: boolean;
+    function GetAllowDropFiles: Boolean;
+    function GetAlphaBlend: Boolean;
+    function GetAlphaBlendValue: Byte;
+    function GetBorderIcons: TBorderIcons;
+    function GetCaption: TCaption;
+    function GetDefaultMonitor: TDefaultMonitor;
+    function GetEffectiveShowInTaskBar: TShowInTaskBar;
+    function GetFormBorderStyle: TFormBorderStyle;
+    function GetFormBoundsRect: TRect;
+    function GetFormHeight: integer;
+    function GetFormLeft: integer;
+    function GetFormState: TFormState;
+    function GetFormStyle: TFormStyle;
+    function GetFormTop: integer;
+    function GetFormWidth: integer;
+    function GetIcon: TIcon;
+    function GetPosition: TPosition;
+    function GetShowInTaskbar: TShowInTaskbar;
+    function GetVisible: boolean;
+    function GetWindowState: TWindowState;
+    function IsIconStored: Boolean;
+    procedure OnFormResize(Sender: TObject);
+    procedure SetAllowDropFiles(const AValue: Boolean);
+    procedure SetAlphaBlend(const AValue: Boolean);
+    procedure SetAlphaBlendValue(const AValue: Byte);
+    procedure SetBorderIcons(const AValue: TBorderIcons);
+    procedure SetCanvas(const AValue: TCanvas);
+    procedure SetCaption(const AValue: TCaption);
+    procedure SetDefaultMonitor(const AValue: TDefaultMonitor);
+    procedure SetFormBorderStyle(const AValue: TFormBorderStyle);
+    procedure SetFormBoundsRect(const AValue: TRect);
+    procedure SetFormHeight(const AValue: integer);
+    procedure SetFormLeft(const AValue: integer);
+    procedure SetFormStyle(const AValue: TFormStyle);
+    procedure SetFormTop(const AValue: integer);
+    procedure SetFormWidth(const AValue: integer);
+    procedure SetIcon(const AValue: TIcon);
+    procedure SetLayoutQueued(const AValue: boolean);
+    procedure SetPosition(const AValue: TPosition);
+    procedure SetShowInTaskBar(const AValue: TShowInTaskbar);
+    procedure SetVisible(const AValue: boolean);
+    procedure SetWindowState(const AValue: TWindowState);
+    function VisibleIsStored: Boolean;
+  protected
+    function GetHeight: TFresnelLength; override;
+    function GetWidth: TFresnelLength; override;
+    procedure FormPaint(Sender: TObject); virtual;
+    procedure Notification(AComponent: TComponent; Operation: TOperation);
+      override;
+    procedure OnQueuedLayout({%H-}Data: PtrInt); virtual;
+    procedure SetName(const NewName: TComponentName); override;
+    procedure SetHeight({%H-}AValue: TFresnelLength); override;
+    procedure SetWidth({%H-}AValue: TFresnelLength); override;
+  public
+    constructor Create(AOwner: TComponent); override;
+    destructor Destroy; override;
+    procedure DomChanged; override;
+    property AllowDropFiles: Boolean read GetAllowDropFiles write SetAllowDropFiles;
+    property AlphaBlend: Boolean read GetAlphaBlend write SetAlphaBlend;
+    property AlphaBlendValue: Byte read GetAlphaBlendValue write SetAlphaBlendValue;
+    property BorderIcons: TBorderIcons read GetBorderIcons write SetBorderIcons
+      default [biSystemMenu, biMinimize, biMaximize];
+    property BorderStyle: TFormBorderStyle
+                      read GetFormBorderStyle write SetFormBorderStyle default bsSizeable;
+    property Canvas: TCanvas read FCanvas write SetCanvas;
+    property Caption: TCaption read GetCaption write SetCaption;
+    property DefaultMonitor: TDefaultMonitor read GetDefaultMonitor
+      write SetDefaultMonitor default dmActiveForm;
+    property Designer: IFresnelFormDesigner read FDesigner write FDesigner;
+    property EffectiveShowInTaskBar: TShowInTaskBar read GetEffectiveShowInTaskBar;
+    property FontEngineLCL: TFresnelLCLFontEngine read FFontEngineLCL;
+    property Form: TCustomForm read FForm;
+    property FormState: TFormState read GetFormState;
+    property FormStyle: TFormStyle read GetFormStyle write SetFormStyle default fsNormal;
+    property Icon: TIcon read GetIcon write SetIcon stored IsIconStored;
+    property Layouter: TSimpleFresnelLayouter read FLayouter;
     property LayoutQueued: boolean read FLayoutQueued write SetLayoutQueued;
+    property Position: TPosition read GetPosition write SetPosition default poDesigned;
+    property Renderer: TFresnelLCLRenderer read FRenderer;
+    property ShowInTaskBar: TShowInTaskbar read GetShowInTaskbar write SetShowInTaskBar
+                                    default stDefault;
+    property Visible: boolean read GetVisible write SetVisible stored VisibleIsStored default false;
+    property WindowState: TWindowState read GetWindowState write SetWindowState
+                                       default wsNormal;
+    property FormBoundsRect: TRect read GetFormBoundsRect write SetFormBoundsRect;
+    property FormLeft: integer read GetFormLeft write SetFormLeft;
+    property FormTop: integer read GetFormTop write SetFormTop;
+    property FormWidth: integer read GetFormWidth write SetFormWidth;
+    property FormHeight: integer read GetFormHeight write SetFormHeight;
   end;
 
   { TFresnelForm }
 
-  TFresnelForm = class(TFresnelCustomForm)
+  TFresnelForm = class(TCustomFresnelForm)
   published
+    property AllowDropFiles;
+    property AlphaBlend;
+    property AlphaBlendValue;
+    property BorderIcons;
+    property BorderStyle;
+    property Caption;
+    property DefaultMonitor;
+    property FormHeight;
+    property FormLeft;
+    property FormStyle;
+    property FormTop;
+    property FormWidth;
+    property Icon;
+    property Position;
+    property ShowInTaskBar;
     property Stylesheet;
+    property Visible;
+    property WindowState;
   end;
 
+
 function CompareFresnelLCLFont(Item1, Item2: Pointer): integer;
 function CompareFresnelFontDescWithLCLFont(Key, Item: Pointer): integer;
 procedure FresnelRectToRect(const Src: TFresnelRect; out Dest: TRect);
@@ -191,6 +328,353 @@ begin
   Dest.Bottom:=ceil(Src.Bottom);
 end;
 
+{ TCustomFresnelForm }
+
+procedure TCustomFresnelForm.DomChanged;
+begin
+  LayoutQueued:=true;
+end;
+
+procedure TCustomFresnelForm.OnQueuedLayout(Data: PtrInt);
+begin
+  ApplyCSS;
+  //Layouter.WriteLayoutTree;
+  Layouter.Apply(Self);
+  if Designer<>nil then
+    Designer.InvalidateRect(Self,Bounds(0,0,ceil(Width),ceil(Height)),false)
+  else
+    Form.Invalidate;
+end;
+
+procedure TCustomFresnelForm.FormPaint(Sender: TObject);
+begin
+  if Designer<>nil then exit;
+  Renderer.Draw(Self);
+end;
+
+procedure TCustomFresnelForm.SetLayoutQueued(const AValue: boolean);
+begin
+  if FLayoutQueued=AValue then Exit;
+  if FClearing then exit;
+  if csDestroyingHandle in Form.ControlState then exit;
+  if csDestroying in ComponentState then exit;
+  FLayoutQueued:=AValue;
+  if FLayoutQueued then
+    Application.QueueAsyncCall(@OnQueuedLayout,0);
+end;
+
+procedure TCustomFresnelForm.SetPosition(const AValue: TPosition);
+begin
+  Form.Position:=AValue;
+end;
+
+procedure TCustomFresnelForm.SetShowInTaskBar(const AValue: TShowInTaskbar);
+begin
+  Form.ShowInTaskBar:=AValue;
+end;
+
+procedure TCustomFresnelForm.SetVisible(const AValue: boolean);
+begin
+  if csDesigning in ComponentState then
+    FVisible:=AValue
+  else
+    Form.Visible:=AValue;
+end;
+
+procedure TCustomFresnelForm.SetWindowState(const AValue: TWindowState);
+begin
+  Form.WindowState:=AValue;
+end;
+
+function TCustomFresnelForm.VisibleIsStored: Boolean;
+begin
+  Result:=Visible;
+end;
+
+function TCustomFresnelForm.GetHeight: TFresnelLength;
+begin
+  if Designer<>nil then
+    Result:=Designer.GetDesignerClientHeight
+  else
+    Result:=Form.ClientHeight;
+end;
+
+function TCustomFresnelForm.GetWidth: TFresnelLength;
+begin
+  if Designer<>nil then
+    Result:=Designer.GetDesignerClientWidth
+  else
+    Result:=Form.ClientWidth;
+end;
+
+function TCustomFresnelForm.GetAllowDropFiles: Boolean;
+begin
+  Result:=Form.AllowDropFiles;
+end;
+
+procedure TCustomFresnelForm.OnFormResize(Sender: TObject);
+begin
+  inherited SetWidth(Form.ClientWidth);
+  inherited SetHeight(Form.ClientHeight);
+end;
+
+function TCustomFresnelForm.GetAlphaBlend: Boolean;
+begin
+  Result:=Form.AlphaBlend;
+end;
+
+function TCustomFresnelForm.GetAlphaBlendValue: Byte;
+begin
+  Result:=Form.AlphaBlendValue;
+end;
+
+function TCustomFresnelForm.GetBorderIcons: TBorderIcons;
+begin
+  Result:=Form.BorderIcons;
+end;
+
+function TCustomFresnelForm.GetCaption: TCaption;
+begin
+  Result:=Form.Caption;
+end;
+
+function TCustomFresnelForm.GetDefaultMonitor: TDefaultMonitor;
+begin
+  Result:=Form.DefaultMonitor;
+end;
+
+function TCustomFresnelForm.GetEffectiveShowInTaskBar: TShowInTaskBar;
+begin
+  Result:=Form.EffectiveShowInTaskBar;
+end;
+
+function TCustomFresnelForm.GetFormBorderStyle: TFormBorderStyle;
+begin
+  Result:=Form.BorderStyle;
+end;
+
+function TCustomFresnelForm.GetFormBoundsRect: TRect;
+begin
+  Result:=Form.BoundsRect;
+end;
+
+function TCustomFresnelForm.GetFormHeight: integer;
+begin
+  Result:=Form.Height;
+end;
+
+function TCustomFresnelForm.GetFormLeft: integer;
+begin
+  Result:=Form.Left;
+end;
+
+function TCustomFresnelForm.GetFormState: TFormState;
+begin
+  Result:=Form.FormState;
+end;
+
+function TCustomFresnelForm.GetFormStyle: TFormStyle;
+begin
+  Result:=Form.FormStyle;
+end;
+
+function TCustomFresnelForm.GetFormTop: integer;
+begin
+  Result:=Form.Top;
+end;
+
+function TCustomFresnelForm.GetFormWidth: integer;
+begin
+  Result:=Form.Width;
+end;
+
+function TCustomFresnelForm.GetIcon: TIcon;
+begin
+  Result:=Form.Icon;
+end;
+
+function TCustomFresnelForm.GetPosition: TPosition;
+begin
+  Result:=Form.Position;
+end;
+
+function TCustomFresnelForm.GetShowInTaskbar: TShowInTaskbar;
+begin
+  Result:=Form.ShowInTaskBar;
+end;
+
+function TCustomFresnelForm.GetVisible: boolean;
+begin
+  if csDesigning in ComponentState then
+    Result:=FVisible
+  else
+    Result:=Form.Visible;
+end;
+
+function TCustomFresnelForm.GetWindowState: TWindowState;
+begin
+  Result:=Form.WindowState;
+end;
+
+function TCustomFresnelForm.IsIconStored: Boolean;
+begin
+  Result:=Icon<>nil;
+end;
+
+procedure TCustomFresnelForm.SetAllowDropFiles(const AValue: Boolean);
+begin
+  Form.AllowDropFiles:=AValue;
+end;
+
+procedure TCustomFresnelForm.SetAlphaBlend(const AValue: Boolean);
+begin
+  Form.AlphaBlend:=AValue;
+end;
+
+procedure TCustomFresnelForm.SetAlphaBlendValue(const AValue: Byte);
+begin
+  Form.AlphaBlendValue:=AValue;
+end;
+
+procedure TCustomFresnelForm.SetBorderIcons(const AValue: TBorderIcons);
+begin
+  Form.BorderIcons:=AValue;
+end;
+
+procedure TCustomFresnelForm.SetCanvas(const AValue: TCanvas);
+begin
+  if FCanvas=AValue then Exit;
+  FCanvas:=AValue;
+  FontEngineLCL.Canvas:=FCanvas;
+  Renderer.Canvas:=FCanvas;
+end;
+
+procedure TCustomFresnelForm.SetCaption(const AValue: TCaption);
+begin
+  Form.Caption:=AValue;
+end;
+
+procedure TCustomFresnelForm.SetDefaultMonitor(const AValue: TDefaultMonitor);
+begin
+  Form.DefaultMonitor:=AValue;
+end;
+
+procedure TCustomFresnelForm.SetFormBorderStyle(const AValue: TFormBorderStyle);
+begin
+  Form.BorderStyle:=AValue;
+end;
+
+procedure TCustomFresnelForm.SetFormBoundsRect(const AValue: TRect);
+begin
+  Form.BoundsRect:=AValue;
+end;
+
+procedure TCustomFresnelForm.SetFormHeight(const AValue: integer);
+begin
+  Form.Height:=AValue;
+  if Designer<>nil then
+    Designer.SetDesignerFormBounds(Self,Form.BoundsRect);
+end;
+
+procedure TCustomFresnelForm.SetFormLeft(const AValue: integer);
+begin
+  Form.Left:=AValue;
+  if Designer<>nil then
+    Designer.SetDesignerFormBounds(Self,Form.BoundsRect);
+end;
+
+procedure TCustomFresnelForm.SetFormStyle(const AValue: TFormStyle);
+begin
+  Form.FormStyle:=AValue;
+end;
+
+procedure TCustomFresnelForm.SetFormTop(const AValue: integer);
+begin
+  Form.Top:=AValue;
+  if Designer<>nil then
+    Designer.SetDesignerFormBounds(Self,Form.BoundsRect);
+end;
+
+procedure TCustomFresnelForm.SetFormWidth(const AValue: integer);
+begin
+  Form.Width:=AValue;
+  if Designer<>nil then
+    Designer.SetDesignerFormBounds(Self,Form.BoundsRect);
+end;
+
+procedure TCustomFresnelForm.SetIcon(const AValue: TIcon);
+begin
+  Form.Icon:=AValue;
+end;
+
+procedure TCustomFresnelForm.Notification(AComponent: TComponent;
+  Operation: TOperation);
+begin
+  inherited Notification(AComponent, Operation);
+  if Operation=opRemove then
+  begin
+    if AComponent=FForm then
+    begin
+      FForm:=nil;
+      FCanvas:=nil;
+    end;
+    if AComponent=FFontEngineLCL then
+      FFontEngineLCL:=nil;
+    if AComponent=FRenderer then
+      FRenderer:=nil;
+  end;
+end;
+
+procedure TCustomFresnelForm.SetName(const NewName: TComponentName);
+begin
+  inherited SetName(NewName);
+  Form.Name:=NewName;
+end;
+
+procedure TCustomFresnelForm.SetHeight(AValue: TFresnelLength);
+begin
+  raise Exception.Create('TCustomFresnelForm.SetHeight is a derived value, set FormHeight instead');
+end;
+
+procedure TCustomFresnelForm.SetWidth(AValue: TFresnelLength);
+begin
+  raise Exception.Create('TCustomFresnelForm.SetWidth is a derived value, set FormWidth instead');
+end;
+
+constructor TCustomFresnelForm.Create(AOwner: TComponent);
+begin
+  inherited Create(AOwner);
+  FForm:=TCustomForm.CreateNew(nil);
+  FForm.Name:=Name;
+  FForm.Visible:=false;
+  FForm.OnResize:=@OnFormResize;
+  FCanvas:=Form.Canvas;
+  Form.OnPaint:=@FormPaint;
+
+  FFontEngineLCL:=TFresnelLCLFontEngine.Create(nil);
+  FontEngine:=FontEngineLCL;
+  FontEngineLCL.Canvas:=Canvas;
+
+  FLayouter:=TSimpleFresnelLayouter.Create(nil);
+  Layouter.Viewport:=Self;
+
+  FRenderer:=TFresnelLCLRenderer.Create(nil);
+  FRenderer.Canvas:=Canvas;
+end;
+
+destructor TCustomFresnelForm.Destroy;
+begin
+  FClearing:=true;
+  FreeAndNil(FRenderer);
+  FreeAndNil(FLayouter);
+  FontEngine:=nil;
+  FreeAndNil(FFontEngineLCL);
+  FCanvas:=nil;
+  FreeAndNil(FForm);
+  Application.RemoveAllHandlersOfObject(Self);
+  inherited Destroy;
+end;
+
 { TFresnelLCLRenderer }
 
 procedure TFresnelLCLRenderer.FillRect(const aColor: TFPColor;
@@ -231,19 +715,19 @@ begin
   inherited Create(AOwner);
 end;
 
-{ TFresnelCustomForm }
+{ TOldFresnelCustomForm }
 
-function TFresnelCustomForm.GetStylesheet: TStrings;
+function TOldFresnelCustomForm.GetStylesheet: TStrings;
 begin
   Result:=Viewport.Stylesheet;
 end;
 
-procedure TFresnelCustomForm.OnDomChanged(Sender: TObject);
+procedure TOldFresnelCustomForm.OnDomChanged(Sender: TObject);
 begin
   LayoutQueued:=true;
 end;
 
-procedure TFresnelCustomForm.OnQueuedLayout(Data: PtrInt);
+procedure TOldFresnelCustomForm.OnQueuedLayout(Data: PtrInt);
 begin
   ViewPort.ApplyCSS;
   //Layouter.WriteLayoutTree;
@@ -251,7 +735,7 @@ begin
   Invalidate;
 end;
 
-procedure TFresnelCustomForm.SetLayoutQueued(const AValue: boolean);
+procedure TOldFresnelCustomForm.SetLayoutQueued(const AValue: boolean);
 begin
   if FLayoutQueued=AValue then Exit;
   if FClearing then exit;
@@ -262,12 +746,12 @@ begin
     Application.QueueAsyncCall(@OnQueuedLayout,0);
 end;
 
-procedure TFresnelCustomForm.SetStylesheet(const AValue: TStrings);
+procedure TOldFresnelCustomForm.SetStylesheet(const AValue: TStrings);
 begin
   Viewport.Stylesheet:=AValue;
 end;
 
-procedure TFresnelCustomForm.Notification(AComponent: TComponent;
+procedure TOldFresnelCustomForm.Notification(AComponent: TComponent;
   Operation: TOperation);
 begin
   inherited Notification(AComponent, Operation);
@@ -288,18 +772,18 @@ begin
   end;
 end;
 
-procedure TFresnelCustomForm.Paint;
+procedure TOldFresnelCustomForm.Paint;
 begin
   inherited Paint;
   Renderer.Draw(Viewport);
 end;
 
-function TFresnelCustomForm.GetViewport: TFresnelViewport;
+function TOldFresnelCustomForm.GetViewport: TFresnelViewport;
 begin
   Result:=FViewport;
 end;
 
-constructor TFresnelCustomForm.Create(AOwner: TComponent);
+constructor TOldFresnelCustomForm.Create(AOwner: TComponent);
 begin
   inherited Create(AOwner);
   FViewport:=TFresnelViewport.Create(nil);
@@ -314,7 +798,7 @@ begin
   FRenderer.Canvas:=Canvas;
 end;
 
-destructor TFresnelCustomForm.Destroy;
+destructor TOldFresnelCustomForm.Destroy;
 begin
   FClearing:=true;
   FreeAndNil(FRenderer);
@@ -325,7 +809,7 @@ begin
   inherited Destroy;
 end;
 
-procedure TFresnelCustomForm.GetChildren(Proc: TGetChildProc; Root: TComponent);
+procedure TOldFresnelCustomForm.GetChildren(Proc: TGetChildProc; Root: TComponent);
 var
   i: Integer;
   OwnedComponent: TComponent;