Browse Source

* Implemented TContainerStylesheets

git-svn-id: trunk@16896 -
joost 14 years ago
parent
commit
8bbc335b88
2 changed files with 62 additions and 0 deletions
  1. 43 0
      packages/fcl-web/src/base/fphtml.pp
  2. 19 0
      packages/fcl-web/src/base/webpage.pp

+ 43 - 0
packages/fcl-web/src/base/fphtml.pp

@@ -63,6 +63,28 @@ type
     property WebController: TWebController read GetWebController;
   end;
 
+  { TContainerStylesheet }
+
+  TContainerStylesheet = class(TCollectionItem)
+  private
+    Fhref: string;
+    Fmedia: string;
+  published
+    property href: string read Fhref write Fhref;
+    property media: string read Fmedia write Fmedia;
+  end;
+
+  { TContainerStylesheets }
+
+  TContainerStylesheets = class(TCollection)
+  private
+    function GetItem(Index: integer): TContainerStylesheet;
+    procedure SetItem(Index: integer; const AValue: TContainerStylesheet);
+  public
+    function Add: TContainerStylesheet;
+    property Items[Index: integer]: TContainerStylesheet read GetItem write SetItem;
+  end;
+
   { TWebController }
 
   TWebController = class(TComponent)
@@ -77,12 +99,14 @@ type
   protected
     function GetScriptFileReferences: TStringList; virtual; abstract;
     function GetCurrentJavaScriptStack: TJavaScriptStack; virtual;
+    function GetStyleSheetReferences: TContainerStylesheets; virtual; abstract;
     function GetScripts: TFPObjectList; virtual; abstract;
     function GetRequest: TRequest;
   public
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
     procedure AddScriptFileReference(AScriptFile: String); virtual; abstract;
+    procedure AddStylesheetReference(Ahref, Amedia: String); virtual; abstract;
     function CreateNewJavascriptStack: TJavaScriptStack; virtual; abstract;
     function InitializeJavaScriptStack: TJavaScriptStack;
     procedure FreeJavascriptStack; virtual;
@@ -100,6 +124,7 @@ type
     function AddrelativeLinkPrefix(AnURL: string): string;
     procedure FreeScript(var AScript: TStringList); virtual; abstract;
     property ScriptFileReferences: TStringList read GetScriptFileReferences;
+    property StyleSheetReferences: TContainerStylesheets read GetStyleSheetReferences;
     property Scripts: TFPObjectList read GetScripts;
     property CurrentJavaScriptStack: TJavaScriptStack read GetCurrentJavaScriptStack;
     property MessageBoxHandler: TMessageBoxHandler read FMessageBoxHandler write FMessageBoxHandler;
@@ -455,6 +480,24 @@ resourcestring
   SErrRequestNotHandled = 'Web request was not handled by actions.';
   SErrNoContentProduced = 'The content producer "%s" didn''t produce any content.';
 
+{ TcontainerStylesheets }
+
+function TcontainerStylesheets.GetItem(Index: integer): TContainerStylesheet;
+begin
+  result := TContainerStylesheet(Inherited GetItem(Index));
+end;
+
+procedure TcontainerStylesheets.SetItem(Index: integer; const AValue: TContainerStylesheet);
+begin
+  inherited SetItem(Index, AValue);
+end;
+
+function TcontainerStylesheets.Add: TContainerStylesheet;
+begin
+  result := inherited Add as TContainerStylesheet;
+end;
+
+
 { TJavaScriptStack }
 
 function TJavaScriptStack.GetWebController: TWebController;

+ 19 - 0
packages/fcl-web/src/base/webpage.pp

@@ -37,9 +37,11 @@ type
   private
     FScriptFileReferences: TStringList;
     FScripts: TFPObjectList;
+    FStyleSheetReferences: TContainerStylesheets;
   protected
     function GetScriptFileReferences: TStringList; override;
     function GetScripts: TFPObjectList; override;
+    function GetStyleSheetReferences: TContainerStylesheets; override;
   public
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
@@ -47,6 +49,7 @@ type
     function GetUrl(ParamNames, ParamValues, KeepParams: array of string; Action: string = ''): string; override;
     procedure BindJavascriptCallstackToElement(AComponent: TComponent; AnElement: THtmlCustomElement; AnEvent: string); override;
     procedure AddScriptFileReference(AScriptFile: String); override;
+    procedure AddStylesheetReference(Ahref, Amedia: String); override;
     function DefaultMessageBoxHandler(Sender: TObject; AText: String; Buttons: TWebButtons; ALoaded: string = ''): string; override;
     function CreateNewScript: TStringList; override;
     procedure FreeScript(var AScript: TStringList); override;
@@ -364,6 +367,11 @@ begin
   Result:=FScripts;
 end;
 
+function TStandardWebController.GetStyleSheetReferences: TContainerStylesheets;
+begin
+  Result:=FStyleSheetReferences;
+end;
+
 function TStandardWebController.CreateNewScript: TStringList;
 begin
   Result:=TStringList.Create;
@@ -407,6 +415,7 @@ end;
 constructor TStandardWebController.Create(AOwner: TComponent);
 begin
   inherited Create(AOwner);
+  FStyleSheetReferences := TContainerStylesheets.Create(TContainerStylesheet);
   FScriptFileReferences := TStringList.Create;
   // For some reason the Duplicates property does not work when sorted is true,
   // But we don't want a sorted list so do a manual check in AddScriptFileReference
@@ -418,6 +427,7 @@ destructor TStandardWebController.Destroy;
 begin
   FScriptFileReferences.Free;
   FScripts.Free;
+  FStyleSheetReferences.Free;
   inherited Destroy;
 end;
 
@@ -523,5 +533,14 @@ begin
     FScriptFileReferences.Add(AScriptFile);
 end;
 
+procedure TStandardWebController.AddStylesheetReference(Ahref, Amedia: String);
+begin
+  with FStyleSheetReferences.Add do
+    begin
+    href:=Ahref;
+    media:=Amedia;
+    end;
+end;
+
 end.