| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781 |
- {
- Copyright (C) 2025 Mattias Gaertner [email protected]
- *****************************************************************************
- This file is part of the Fresnel project.
- See the file COPYING.modifiedLGPL.txt, included in this distribution,
- for details about the license.
- *****************************************************************************
- }
- unit Fresnel.Register;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils,
- // lcl
- LCLProc, LCLType, LCLIntf, LazLoggerBase, Graphics, Controls, Forms,
- // IDE intf
- FormEditingIntf, PropEdits, LazIDEIntf, ComponentEditors, IDEOptEditorIntf, ProjectIntf,
- IDECommands, MenuIntf, IDEWindowIntf, PackageIntf, IDEOptionsIntf,
- // codetools
- CodeToolManager, CodeCache, StdCodeTools,
- // fresnel
- Fresnel.DOM, Fresnel.Controls, Fresnel.Forms,
- Fresnel.Renderer, Fresnel.Classes, Fresnel.Events, FCL.Events, Fresnel.LCLApp, Fresnel.LCL,
- Fresnel.DsgnStrConsts, Fresnel.StylePropEdit, Fresnel.DsgnOptsFrame, Fresnel.DsgnOptions,
- Fresnel.DsgnInspector;
- const
- ProjDescNameFresnelApplication = 'Fresnel Application';
- FresnelPkgName = 'Fresnel';
- FresnelLCLPkgName = 'FresnelLCL';
- FresnelBasePkgName = 'FresnelBase';
- FresnelDesignPkgName = 'FresnelDsgn';
- type
- { TFresnelFormMediator - mediator for TFresnelForm }
- TFresnelFormMediator = class(TDesignerMediator,IFresnelFormDesigner)
- private
- FDsgnForm: TFresnelForm;
- FRenderer: TFresnelLCLRenderer;
- protected
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- procedure OnCSSApplied(Event: TAbstractEvent); virtual;
- procedure SetLCLForm(const AValue: TForm); override;
- procedure SetDsgnForm(aFrlForm: TFresnelForm); virtual;
- public
- // needed by the Lazarus form editor
- class function CreateMediator(TheOwner, aForm: TComponent): TDesignerMediator;
- override;
- class function FormClass: TComponentClass; override;
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- function ComponentAtPos(p: TPoint; MinClass: TComponentClass;
- Flags: TDMCompAtPosFlags): TComponent; override;
- function ComponentIsIcon(AComponent: TComponent): boolean; override;
- function ComponentIsVisible(AComponent: TComponent): Boolean; override;
- function GetComponentOriginOnForm(AComponent: TComponent): TPoint; override;
- function ParentAcceptsChild(Parent: TComponent;
- ChildClass: TComponentClass): boolean; override;
- procedure GetBounds(AComponent: TComponent; out CurBounds: TRect); override;
- procedure GetClientArea(AComponent: TComponent; out
- CurClientArea: TRect; out ScrollOffset: TPoint); override;
- procedure InitComponent(AComponent, NewParent: TComponent; NewBounds: TRect); override;
- procedure Paint; override;
- procedure SetBounds(AComponent: TComponent; NewBounds: TRect); override;
- public
- // needed by Fresnel
- procedure InvalidateRect(Sender: TObject; ARect: TRect; Erase: boolean); virtual;
- procedure SetDesignerFormBounds(Sender: TObject; NewBounds: TRect); virtual;
- function GetDesignerClientHeight: integer; virtual;
- function GetDesignerClientWidth: integer; virtual;
- function GetRenderer: TFresnelRenderer; virtual;
- property DsgnForm: TFresnelForm read FDsgnForm;
- property Renderer: TFresnelLCLRenderer read FRenderer;
- end;
- { TFileDescFresnelForm }
- TFileDescFresnelForm = class(TFileDescPascalUnitWithResource)
- public
- constructor Create; override;
- function Init(var NewFilename: string; NewOwner: TObject;
- var NewSource: string; Quiet: boolean): TModalResult; override;
- function Initialized(NewFile: TLazProjectFile): TModalResult; override;
- function GetInterfaceUsesSection: string; override;
- function GetLocalizedName: string; override;
- function GetLocalizedDescription: string; override;
- end;
- { TProjDescFresnelApplication }
- TProjDescFresnelApplication = class(TProjectDescriptor)
- public
- constructor Create; override;
- function GetLocalizedName: string; override;
- function GetLocalizedDescription: string; override;
- function InitProject(AProject: TLazProject): TModalResult; override;
- function CreateStartFiles({%H-}AProject: TLazProject): TModalResult; override;
- end;
- { TFresnelStylePropertyEditor }
- TFresnelStylePropertyEditor = class(TStringPropertyEditor)
- public
- function GetAttributes: TPropertyAttributes; override;
- procedure Edit; override;
- end;
- { TFresnelStyleSheetPropertyEditor }
- TFresnelStyleSheetPropertyEditor = class(TClassPropertyEditor)
- public
- procedure Edit; override;
- function GetAttributes: TPropertyAttributes; override;
- end;
- { TFresnelComponentRequirements }
- TFresnelComponentRequirements = class(TComponentRequirements)
- public
- procedure RequiredPkgs(Pkgs: TStrings); override;
- end;
- var
- FileDescFresnelForm: TFileDescFresnelForm;
- ProjDescFresnelApplication: TProjDescFresnelApplication;
- var
- FresnelOptionsFrameID: integer = 1000;
- procedure Register;
- implementation
- {$R fresneldsgnimg.res}
- procedure Register;
- var
- Key: TIDEShortCut;
- Cat: TIDECommandCategory;
- begin
- FresnelOptions:=TFresnelDsgnOptions.Create(nil);
- // register mediator for designer forms
- FormEditingHook.RegisterDesignerMediator(TFresnelFormMediator);
- FormEditingHook.SetDesignerBaseClassCanAppCreateForm(TFresnelForm,true);
- // register elements
- RegisterComponents('Fresnel',[TDiv,TSpan,TLabel,TButton,TImage,TBody]);
- RegisterComponentRequirements([TDiv,TSpan,TLabel,TButton,TImage,TBody],TFresnelComponentRequirements);
- // register fresnel form as new file type
- FileDescFresnelForm:=TFileDescFresnelForm.Create;
- RegisterProjectFileDescriptor(FileDescFresnelForm,FileDescGroupName);
- // register fresnel application as new project type
- ProjDescFresnelApplication:=TProjDescFresnelApplication.Create;
- RegisterProjectDescriptor(ProjDescFresnelApplication);
- // register property editors
- RegisterPropertyEditor(TypeInfo(String), TFresnelElement, 'Style', TFresnelStylePropertyEditor);
- RegisterPropertyEditor(TypeInfo(String), TFresnelForm, 'Style', THiddenPropertyEditor);
- RegisterPropertyEditor(TypeInfo(TStrings), TFresnelForm, 'Stylesheet', TFresnelStyleSheetPropertyEditor);
- // register IDE options frame
- FresnelOptionsFrameID:=RegisterIDEOptionsEditor(GroupEnvironment,TFresnelOptionsFrame,
- FresnelOptionsFrameID)^.Index;
- // register shortcut for view CSS Inspector
- Key:=IDEShortCut(VK_UNKNOWN,[],VK_UNKNOWN,[]);
- Cat:=IDECommandList.FindCategoryByName(CommandCategoryViewName);
- ViewCSSInspectorCmd:=RegisterIDECommand(Cat, 'View Fresnel CSS Inspector',
- frsFresnelCSSInspector, Key,nil,@ViewCSSInspector);
- // add a menu item in the view menu
- ViewCSSInspectorMenuCmd:=RegisterIDEMenuCommand(itmViewMainWindows, 'ViewFresnelCSSInspector',
- frsFresnelCSSInspector, nil, nil, ViewCSSInspectorCmd{, 'menu_view_fresnel_css_inspector'});
- // register window creator
- IDEWindowCreators.Add(CSSInspectorWindowName,@CreateCSSInspectorWindow,nil,'250','400','','');
- end;
- { TFresnelFormMediator }
- procedure TFresnelFormMediator.OnCSSApplied(Event: TAbstractEvent);
- begin
- if Event=nil then ;
- end;
- procedure TFresnelFormMediator.Notification(AComponent: TComponent;
- Operation: TOperation);
- begin
- inherited Notification(AComponent, Operation);
- if Operation=opRemove then
- begin
- if FDsgnForm=AComponent then
- begin
- FDsgnForm.Designer:=nil;
- FDsgnForm:=nil;
- end;
- if FRenderer=AComponent then
- begin
- FRenderer.Canvas:=nil;
- FRenderer:=nil;
- end;
- end;
- end;
- procedure TFresnelFormMediator.SetLCLForm(const AValue: TForm);
- begin
- if LCLForm=AValue then exit;
- inherited SetLCLForm(AValue);
- if FDsgnForm<>nil then
- begin
- if FRenderer<>nil then
- FRenderer.Canvas:=LCLForm.Canvas;
- TFresnelLCLFontEngine(FDsgnForm.FontEngine).Canvas:=LCLForm.Canvas;
- end else begin
- if FRenderer<>nil then
- FRenderer.Canvas:=nil;
- TFresnelLCLFontEngine(FDsgnForm.FontEngine).Canvas:=nil;
- end;
- end;
- procedure TFresnelFormMediator.SetDsgnForm(aFrlForm: TFresnelForm);
- begin
- if FDsgnForm=aFrlForm then exit;
- if DsgnForm<>nil then
- begin
- DsgnForm.Designer:=nil;
- DsgnForm.EventDispatcher.UnRegisterHandler(@OnCSSApplied,evtViewportCSSApplied);
- end;
- FDsgnForm:=aFrlForm;
- if DsgnForm<>nil then
- DsgnForm.AddEventListener(evtViewportCSSApplied,@OnCSSApplied);
- end;
- class function TFresnelFormMediator.CreateMediator(TheOwner, aForm: TComponent
- ): TDesignerMediator;
- var
- Mediator: TFresnelFormMediator;
- aFresnelForm: TFresnelForm;
- begin
- Result:=inherited CreateMediator(TheOwner,aForm);
- Mediator:=TFresnelFormMediator(Result);
- aFresnelForm:=aForm as TFresnelForm;
- Mediator.SetDsgnForm(aFresnelForm);
- aFresnelForm.Designer:=Mediator;
- Mediator.FreeNotification(aForm);
- aFresnelForm.FontEngine:=TFresnelLCLFontEngine.Create(Mediator);
- end;
- class function TFresnelFormMediator.FormClass: TComponentClass;
- begin
- Result:=TFresnelForm;
- end;
- procedure TFresnelFormMediator.GetBounds(AComponent: TComponent; out
- CurBounds: TRect);
- var
- El: TFresnelElement;
- aBox: TFresnelRect;
- begin
- if AComponent=FDsgnForm then
- begin
- CurBounds:=FDsgnForm.FormBounds.GetRect;
- end else if AComponent is TFresnelElement then
- begin
- // return borderbox
- El:=TFresnelElement(AComponent);
- aBox:=El.UsedBorderBox;
- FresnelRectToRect(aBox,CurBounds);
- end else
- inherited GetBounds(AComponent,CurBounds);
- //debugln(['TFresnelFormMediator.GetBounds ',DbgSName(AComponent),' ',dbgs(CurBounds)]);
- end;
- procedure TFresnelFormMediator.SetBounds(AComponent: TComponent;
- NewBounds: TRect);
- var
- El: TFresnelElement;
- OldStyle: String;
- NewBorderBox: TFresnelRect;
- NewLeft, NewTop, NewWidth, NewHeight: TFresnelLength;
- begin
- //debugln(['TFresnelFormMediator.SetBounds ',DbgSName(AComponent),' ',dbgs(NewBounds)]);
- if AComponent=FDsgnForm then
- begin
- FDsgnForm.WSResize(TFresnelRect.Create(NewBounds),NewBounds.Width,NewBounds.Height);
- end else if AComponent is TFresnelElement then
- begin
- // an element (bounds are controlled by CSS)
- El:=TFresnelElement(AComponent);
- if El.ComputedPosition in [CSSRegistry.kwAbsolute,CSSRegistry.kwFixed] then
- begin
- // NewBounds is borderbox
- with El.LayoutNode do begin
- NewBorderBox.SetRect(NewBounds); // integer to float
- NewLeft:=NewBorderBox.Left-MarginLeft;
- NewTop:=NewBorderBox.Top-MarginTop;
- NewWidth:=NewBorderBox.Width;
- NewHeight:=NewBorderBox.Height;
- // todo: if parent position is static, use the nearest parent with non static
- // todo: right and bottom aligned
- OldStyle:=El.Style;
- case El.ComputedBoxSizing of
- CSSRegistry.kwBorderBox:
- begin
- end;
- CSSRegistry.kwPaddingBox:
- begin
- NewWidth:=NewWidth-BorderLeft-BorderRight;
- NewHeight:=NewHeight-BorderTop-BorderBottom;
- end;
- CSSRegistry.kwContentBox:
- begin
- NewWidth:=NewWidth-BorderLeft-BorderRight-PaddingLeft-PaddingRight;
- NewHeight:=NewHeight-BorderTop-BorderBottom-PaddingTop-PaddingBottom;
- end;
- end;
- end;
- if El.GetStyleAttr('left')<>'' then
- El.SetStyleAttr('left',FloatToCSSPx(NewLeft));
- if El.GetStyleAttr('top')<>'' then
- El.SetStyleAttr('top',FloatToCSSPx(NewTop));
- if El.GetStyleAttr('width')<>'' then
- El.SetStyleAttr('width',FloatToCSSPx(NewWidth));
- if El.GetStyleAttr('height')<>'' then
- El.SetStyleAttr('height',FloatToCSSPx(NewHeight));
- debugln(['TFresnelFormMediator.SetBounds AComponent=',DbgSName(AComponent),' OldStyle=[',OldStyle,'] OldBorderBox=',FloatToCSSStr(El.UsedBorderBox.Left),',',FloatToCSSStr(El.UsedBorderBox.Top),' w=',FloatToCSSStr(El.UsedBorderBox.Width),',h=',FloatToCSSStr(El.UsedBorderBox.Height),' box-sizing=',CSSRegistry.Keywords[El.ComputedBoxSizing],' NewLeft,Top=',FloatToCSSStr(NewLeft),',',FloatToCSSStr(NewTop),' NewWH=',FloatToCSSStr(NewWidth),'x',FloatToCSSStr(NewHeight)]);
- El.Viewport.ApplyCSS;
- end;
- end else begin
- inherited SetBounds(AComponent, NewBounds);
- end;
- end;
- procedure TFresnelFormMediator.GetClientArea(AComponent: TComponent; out
- CurClientArea: TRect; out ScrollOffset: TPoint);
- var
- El: TFresnelElement;
- Box, BorderBox: TFresnelRect;
- begin
- if AComponent=FDsgnForm then
- begin
- CurClientArea:=Rect(0,0,round(FDsgnForm.Width),round(FDsgnForm.Height));
- ScrollOffset:=Point(0,0);
- end else if AComponent is TFresnelElement then begin
- // return clientbox inside the borderbox
- El:=TFresnelElement(AComponent);
- BorderBox:=El.UsedBorderBox;
- Box:=El.UsedClientBox;
- Box.Offset(-BorderBox.Left,-BorderBox.Top);
- FresnelRectToRect(Box,CurClientArea);
- ScrollOffset.X:=round(El.ScrollLeft);
- ScrollOffset.Y:=round(El.ScrollTop);
- end else
- inherited;
- end;
- procedure TFresnelFormMediator.InitComponent(AComponent, NewParent: TComponent; NewBounds: TRect);
- var
- El: TFresnelElement;
- BorderBox: TFresnelRect;
- begin
- if AComponent is TFresnelElement then
- begin
- // set parentcomponent, needed for streaming
- TFresnelFormMediator(AComponent).SetParentComponent(NewParent);
- El:=TFresnelElement(AComponent);
- debugln(['TFresnelFormMediator.InitComponent AComponent=',DbgSName(AComponent),' NewParent=',DbgSName(NewParent),' Bounds=',dbgs(NewBounds)]);
- if FresnelOptions.PositionAbsolute then
- begin
- // todo: if parent position is static, use the nearest parent with non static
- BorderBox.SetRect(NewBounds);
- // todo: compute margins via resolver
- El.SetStyleAttr('position','absolute');
- El.SetStyleAttr('box-sizing','border-box');
- El.SetStyleAttr('left',FloatToCSSPx(BorderBox.Left));
- El.SetStyleAttr('top',FloatToCSSPx(BorderBox.Top));
- if not (El is TReplacedElement) then
- begin
- if (BorderBox.Width<=0) and (El.NodeCount=0) then
- BorderBox.Width:=50;
- if (BorderBox.Height<=0) and (El.NodeCount=0) then
- BorderBox.Height:=50;
- if BorderBox.Width>0 then
- El.SetStyleAttr('width',FloatToCSSPx(BorderBox.Width));
- if BorderBox.Height>0 then
- El.SetStyleAttr('height',FloatToCSSPx(BorderBox.Height));
- end;
- end;
- end else
- inherited;
- end;
- function TFresnelFormMediator.GetComponentOriginOnForm(AComponent: TComponent
- ): TPoint;
- var
- El: TFresnelElement;
- BorderBox: TFresnelRect;
- begin
- 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
- exit(Point(0,0));
- BorderBox:=El.GetBorderBoxOnViewport;
- Result.X:=round(BorderBox.Left);
- Result.Y:=round(BorderBox.Top);
- end else
- Result:=inherited GetComponentOriginOnForm(AComponent);
- end;
- procedure TFresnelFormMediator.Paint;
- begin
- //debugln(['TFresnelFormMediator.Paint FDsgnForm=',DbgSName(FDsgnForm)]);
- if FDsgnForm=nil then exit;
- //debugln(['TFresnelFormMediator.Paint FDsgnForm=',DbgSName(FDsgnForm),' Renderer=',DbgSName(FDsgnForm.Renderer)]);
- FDsgnForm.Renderer.Draw(FDsgnForm);
- end;
- function TFresnelFormMediator.ComponentIsIcon(AComponent: TComponent): boolean;
- begin
- if AComponent is TFresnelElement then
- Result:=false
- else
- Result:=inherited ComponentIsIcon(AComponent);
- end;
- function TFresnelFormMediator.ComponentIsVisible(AComponent: TComponent
- ): Boolean;
- begin
- if AComponent=FDsgnForm then
- Result:=true
- else if AComponent is TFresnelElement then
- Result:=TFresnelElement(AComponent).Rendered
- else
- Result:=true;
- end;
- function TFresnelFormMediator.ComponentAtPos(p: TPoint;
- MinClass: TComponentClass; Flags: TDMCompAtPosFlags): TComponent;
- var
- ElArr: TFresnelElementArray;
- El: TFresnelElement;
- i: Integer;
- begin
- if Flags=[] then ;
- // skip sub elements aka return only elements owned by the lookup root,
- // which are streamed
- ElArr:=DsgnForm.GetElementsAt(p.X,p.Y);
- for i:=0 to length(ElArr)-1 do
- begin
- El:=ElArr[i];
- if (El=DsgnForm) or (El.Owner=DsgnForm) then
- begin
- if (MinClass=nil) or El.InheritsFrom(MinClass) then
- exit(El);
- end;
- end;
- Result:=nil;
- end;
- function TFresnelFormMediator.ParentAcceptsChild(Parent: TComponent;
- ChildClass: TComponentClass): boolean;
- begin
- //debugln(['TFresnelFormMediator.ParentAcceptsChild START Parent=',DbgSName(Parent),' Child=',DbgSName(ChildClass)]);
- if ChildClass.InheritsFrom(TControl) then
- Result:=false
- else if ChildClass.InheritsFrom(TFresnelViewport) then
- Result:=false
- else if Parent is TFresnelElement then
- begin
- if Parent is TReplacedElement then
- exit(false);
- Result:=ChildClass.InheritsFrom(TFresnelElement);
- end else
- Result:=inherited ParentAcceptsChild(Parent, ChildClass);
- //debugln(['TFresnelFormMediator.ParentAcceptsChild END Parent=',DbgSName(Parent),' Child=',DbgSName(ChildClass),' Result=',Result]);
- end;
- constructor TFresnelFormMediator.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- end;
- destructor TFresnelFormMediator.Destroy;
- begin
- SetDsgnForm(nil);
- inherited Destroy;
- end;
- procedure TFresnelFormMediator.InvalidateRect(Sender: TObject; ARect: TRect;
- Erase: boolean);
- begin
- //debugln(['TFresnelFormMediator.InvalidateRect ',DbgSName(FDsgnForm),' ',dbgs(ARect)]);
- if (LCLForm=nil) or (not LCLForm.HandleAllocated) then exit;
- 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:=round(FDsgnForm.Height)
- else
- Result:=LCLForm.ClientHeight;
- end;
- function TFresnelFormMediator.GetDesignerClientWidth: integer;
- begin
- if LCLForm=nil then
- Result:=round(FDsgnForm.Width)
- else
- Result:=LCLForm.ClientWidth;
- end;
- function TFresnelFormMediator.GetRenderer: TFresnelRenderer;
- begin
- if FRenderer=nil then
- begin
- FRenderer:=TFresnelLCLRenderer.Create(Self);
- Renderer.Canvas:=LCLForm.Canvas;
- end;
- Result:=FRenderer;
- end;
- { TFileDescFresnelForm }
- constructor TFileDescFresnelForm.Create;
- begin
- inherited Create;
- Name:='FresnelForm';
- ResourceClass:=TFresnelForm;
- UseCreateFormStatements:=true;
- end;
- function TFileDescFresnelForm.Init(var NewFilename: string; NewOwner: TObject;
- var NewSource: string; Quiet: boolean): TModalResult;
- var
- DependencyOwner, aOwner: TObject;
- begin
- Result:=inherited Init(NewFilename, NewOwner, NewSource, Quiet);
- // if project uses the LCL, add dependency FresnelLCL else Fresnel
- RequiredPackages:=FresnelPkgName+';'+FresnelDesignPkgName;
- aOwner:=NewOwner;
- if aOwner=nil then
- aOwner:=LazarusIDE.ActiveProject;
- if aOwner<>nil then
- begin
- if PackageEditingInterface.IsOwnerDependingOnPkg(aOwner,'LCL',DependencyOwner) then
- RequiredPackages:=FresnelLCLPkgName+';'+FresnelDesignPkgName;
- end;
- end;
- function TFileDescFresnelForm.Initialized(NewFile: TLazProjectFile
- ): TModalResult;
- var
- aProject: TLazProject;
- MainFilename: String;
- Code: TCodeBuffer;
- DependencyOwner: TObject;
- NamePos, InPos: integer;
- begin
- Result:=inherited Initialized(NewFile);
- aProject:=LazarusIDE.ActiveProject;
- if aProject=nil then begin
- debugln(['Warning: TFileDescFresnelForm.Initialized: not adding uses Fresnel, because ActiveProject=nil']);
- exit;
- end;
- if aProject.MainFile=nil then begin
- debugln(['Warning: TFileDescFresnelForm.Initialized: not adding uses Fresnel, because ActiveProject.MainFile=nil']);
- exit;
- end;
- if PackageEditingInterface.IsOwnerDependingOnPkg(aProject,'LCL',DependencyOwner) then
- begin
- // a lcl app -> add Fresnel behind 'interfaces'
- MainFilename:=aProject.MainFile.Filename;
- Code:=CodeToolBoss.LoadFile(MainFilename,true,false);
- if not CodeToolBoss.AddUnitToMainUsesSectionIfNeeded(Code,'Fresnel','',[aufLast]) then
- begin
- if CodeToolBoss.FindUnitInAllUsesSections(Code,'Fresnel',NamePos,InPos) then
- begin
- debugln(['Warning: TFileDescFresnelForm.Initialized: failed adding uses Fresnel to "',MainFilename,'"']);
- exit;
- end;
- end;
- end;
- end;
- function TFileDescFresnelForm.GetInterfaceUsesSection: string;
- begin
- Result:='Classes, SysUtils, Fresnel.Classes, Fresnel.Forms, Fresnel.DOM, Fresnel.Controls';
- end;
- function TFileDescFresnelForm.GetLocalizedName: string;
- begin
- Result:='Fresnel Form';
- end;
- function TFileDescFresnelForm.GetLocalizedDescription: string;
- begin
- Result:='Create a new Fresnel form';
- end;
- { TProjDescFresnelApplication }
- constructor TProjDescFresnelApplication.Create;
- begin
- inherited Create;
- Name:=ProjDescNameFresnelApplication;
- Flags:=Flags+[pfUseDefaultCompilerOptions];
- end;
- function TProjDescFresnelApplication.GetLocalizedName: string;
- begin
- Result:=frsFresnelApplication;
- end;
- function TProjDescFresnelApplication.GetLocalizedDescription: string;
- begin
- Result:=frsFresnelApplicationDesc;
- end;
- function TProjDescFresnelApplication.InitProject(AProject: TLazProject
- ): TModalResult;
- var
- NewSource: String;
- MainFile: TLazProjectFile;
- begin
- Result:=inherited InitProject(AProject);
- MainFile:=AProject.CreateProjectFile('project1.lpr');
- MainFile.IsPartOfProject:=true;
- AProject.AddFile(MainFile,false);
- AProject.MainFileID:=0;
- AProject.UseAppBundle:=true;
- AProject.UseManifest:=true;
- AProject.Scaled:=true;
- // ToDo: AProject.ProjResources.XPManifest.DpiAware := xmdaTrue;
- AProject.LoadDefaultIcon;
- // create program source
- NewSource:='program Project1;'+LineEnding
- +LineEnding
- +'{$mode objfpc}{$H+}'+LineEnding
- +LineEnding
- +'uses'+LineEnding
- +' {$IFDEF UNIX}'+LineEnding
- +' cthreads,'+LineEnding
- +' {$ENDIF}'+LineEnding
- +' {$IFDEF HASAMIGA}'+LineEnding
- +' athreads,'+LineEnding
- +' {$ENDIF}'+LineEnding
- +' Fresnel, // this includes the Fresnel widgetset'+LineEnding
- +' Fresnel.Forms'+LineEnding
- +' { you can add units after this };'+LineEnding
- +LineEnding
- +'begin'+LineEnding
- +' Application.Initialize;'+LineEnding
- +' Application.Run;'+LineEnding
- +'end.'+LineEnding
- +LineEnding;
- AProject.MainFile.SetSourceText(NewSource,true);
- // add Fresnel package dependency
- AProject.AddPackageDependency('Fresnel');
- AProject.LazCompilerOptions.Win32GraphicApp:=true;
- AProject.LazCompilerOptions.UnitOutputDirectory:='lib'+PathDelim+'$(TargetCPU)-$(TargetOS)';
- AProject.LazCompilerOptions.TargetFilename:='project1';
- end;
- function TProjDescFresnelApplication.CreateStartFiles(AProject: TLazProject
- ): TModalResult;
- begin
- Result:=LazarusIDE.DoNewEditorFile(FileDescFresnelForm,'','',
- [nfIsPartOfProject,nfOpenInEditor,nfCreateDefaultSrc]);
- end;
- { TFresnelStylePropertyEditor }
- function TFresnelStylePropertyEditor.GetAttributes: TPropertyAttributes;
- begin
- Result := [paMultiSelect, paDialog, paRevertable];
- end;
- procedure TFresnelStylePropertyEditor.Edit;
- var
- TheDialog : TStylePropEditDialog;
- begin
- TheDialog := TStylePropEditDialog.Create(nil);
- try
- TheDialog.Caption := 'CSS Inline Style Editor';
- TheDialog.Editor := Self;
- TheDialog.ShowModal;
- finally
- TheDialog.Free;
- end;
- end;
- { TFresnelStyleSheetPropertyEditor }
- procedure TFresnelStyleSheetPropertyEditor.Edit;
- var
- TheDialog : TStylePropEditDialog;
- begin
- TheDialog := TStylePropEditDialog.Create(nil);
- try
- TheDialog.Caption := 'CSS Stylesheet Editor';
- TheDialog.Editor := Self;
- TheDialog.ShowModal;
- finally
- TheDialog.Free;
- end;
- end;
- function TFresnelStyleSheetPropertyEditor.GetAttributes: TPropertyAttributes;
- begin
- Result := [paMultiSelect, paDialog, paRevertable, paReadOnly];
- end;
- { TFresnelComponentRequirements }
- procedure TFresnelComponentRequirements.RequiredPkgs(Pkgs: TStrings);
- procedure RemoveFresnelBase;
- var
- i: Integer;
- begin
- i:=Pkgs.IndexOf('FresnelBase');
- if i<0 then exit;
- Pkgs.Delete(i);
- end;
- var
- aProject: TLazProject;
- DependencyOwner: TObject;
- begin
- // the Fresnel components are part of package FresnelBase, but the project
- // actually needs a Fresnel backend.
- // if project is using the LCL then use FresnelLCL else Fresnel
- aProject:=LazarusIDE.ActiveProject;
- if aProject<>nil then
- begin
- RemoveFresnelBase;
- if PackageEditingInterface.IsOwnerDependingOnPkg(aProject,'LCL',DependencyOwner) then
- begin
- Pkgs.Add('FresnelLCL');
- end else begin
- Pkgs.Add('Fresnel');
- end;
- end;
- end;
- end.
|