diff options
author | Graeme Geldenhuys <graemeg@users.sourceforge.net> | 2007-03-07 15:53:00 +0000 |
---|---|---|
committer | Graeme Geldenhuys <graemeg@users.sourceforge.net> | 2007-03-07 15:53:00 +0000 |
commit | 6615b82afe97f92af4d1c0f7fb2e6b82b44c7ace (patch) | |
tree | 4408ca138fce1f5c9b7c8809c0c47f64b1d8841a /gui | |
parent | e6714f4d892945103ef0e0339f101f958b40baf4 (diff) | |
download | fpGUI-6615b82afe97f92af4d1c0f7fb2e6b82b44c7ace.tar.xz |
* Extending the StyleManager to behave like a class factory. All Style classes will register with the factory and the factory will create the styles as needed.
Diffstat (limited to 'gui')
-rw-r--r-- | gui/defimpl/defstyle.inc | 2 | ||||
-rw-r--r-- | gui/scrollbar.inc | 2 | ||||
-rw-r--r-- | gui/style.inc | 2 | ||||
-rw-r--r-- | gui/stylemanager.pas | 111 | ||||
-rw-r--r-- | gui/widget.inc | 2 |
5 files changed, 109 insertions, 10 deletions
diff --git a/gui/defimpl/defstyle.inc b/gui/defimpl/defstyle.inc index dd137f86..6b76c4c5 100644 --- a/gui/defimpl/defstyle.inc +++ b/gui/defimpl/defstyle.inc @@ -3,7 +3,7 @@ Default Style class declarations - Copyright (C) 2000 - 2006 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, diff --git a/gui/scrollbar.inc b/gui/scrollbar.inc index b2bfda1f..41369e5d 100644 --- a/gui/scrollbar.inc +++ b/gui/scrollbar.inc @@ -3,7 +3,7 @@ ScrollBar class declarations - Copyright (C) 2000 - 2006 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, diff --git a/gui/style.inc b/gui/style.inc index ef32d399..1af0272e 100644 --- a/gui/style.inc +++ b/gui/style.inc @@ -3,7 +3,7 @@ Style class declarations - Copyright (C) 2000 - 2006 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, diff --git a/gui/stylemanager.pas b/gui/stylemanager.pas index dce91366..5cfe4013 100644 --- a/gui/stylemanager.pas +++ b/gui/stylemanager.pas @@ -3,7 +3,7 @@ Style Manager as a Singleton - Copyright (C) 2000 - 2006 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, @@ -22,30 +22,60 @@ interface uses Classes + ,Contnrs ,fpGUI ; type + + // A class reference for the TStyle descendants + TStyleClass = class of TStyle; + + + // A class to hold the TStyle class mappings. The factory maintains + // a list of these and uses the StyleClass property to create the objects. + TStyleClassMapping = class(TObject) + private + FsMappingName : string; + FStyleClass : TStyleClass; + public + constructor Create(const AMappingName: string; AStyleClass: TStyleClass); overload; + property MappingName: string read FsMappingName; + property StyleClass: TStyleClass read FStyleClass; + end; + + + // Style manager and factory class + + { TStyleManager } + TStyleManager = class(TObject) private + FList : TObjectList; FDefaultStyle: TStyle; FUserStyle: TStyle; + FDefaultStyleType: string; function GetDefaultStyle: TStyle; public constructor Create; - destructor Destroy;override; + destructor Destroy; override; property DefaultStyle: TStyle read GetDefaultStyle; procedure SetStyle(pNewStyle: TStyle); + procedure RegisterClass(const AStyleName: string; AStyleClass : TStyleClass); + function CreateInstance(const AStyleName: string): TStyle; overload; + function CreateInstance: TStyle; overload; + procedure AssignStyleTypes(AStrings : TStrings); end; -// lazy mans singleton +// Singleton function gStyleManager: TStyleManager; implementation uses - fpGFX + SysUtils + ,fpGFX ; var @@ -76,12 +106,18 @@ end; constructor TStyleManager.Create; begin - FUserStyle := nil; - FDefaultStyle := nil; + inherited Create; + FList := TObjectList.Create; + FUserStyle := nil; + FDefaultStyle := nil; + FDefaultStyleType := 'auto'; end; destructor TStyleManager.Destroy; begin + FList.Free; + + {$Note These will be removed later} if FUserStyle <> nil then FUserStyle.Free; if FDefaultStyle <> nil then @@ -96,6 +132,69 @@ begin FUserStyle := pNewStyle; end; +// Register a TStyle class for creation by the factory +procedure TStyleManager.RegisterClass(const AStyleName: string; + AStyleClass: TStyleClass); +var + i: integer; +begin + for i := 0 to FList.Count - 1 do + if UpperCase(TStyleClassMapping(FList.Items[i]).MappingName) = + UpperCase(AStyleName) then + Assert(false, + Format('Style class <%s> already registered.', + [AStyleName])); + FList.Add(TStyleClassMapping.Create(AStyleName, AStyleClass)); + + // we will use this later +// FDefaultStyleType := UpperCase(AStyleName); +end; + +// Call the factory to create an instance of TStyle +function TStyleManager.CreateInstance(const AStyleName: string): TStyle; +var + i: integer; +begin + result := nil; + for i := 0 to FList.Count - 1 do + if UpperCase(TStyleClassMapping(FList.Items[i]).MappingName) = + UpperCase(AStyleName) then begin + result := TStyleClassMapping(FList.Items[i]).StyleClass.Create; + Break; //==> + end; + + Assert(result <> nil, + Format('<%s> does not identify a registered style class.', + [AStyleName])); +end; + +function TStyleManager.CreateInstance: TStyle; +begin + result := CreateInstance(FDefaultStyleType); +end; + +// Assing the registered list of TStyle names to a StringList +// This can be used to populate a combobox with the available TStyle +// class types. +procedure TStyleManager.AssignStyleTypes(AStrings: TStrings); +var + i: integer; +begin + AStrings.Clear; + for i := 0 to FList.Count - 1 do + AStrings.Add(TStyleClassMapping(FList.Items[i]).MappingName); +end; + +{ TStyleClassMapping } + +constructor TStyleClassMapping.Create(const AMappingName: string; + AStyleClass: TStyleClass); +begin + inherited Create; + FsMappingName := AMappingName; + FStyleClass := AStyleClass; +end; + initialization uStyleManager := nil; diff --git a/gui/widget.inc b/gui/widget.inc index b00b3f8e..1b1b85d8 100644 --- a/gui/widget.inc +++ b/gui/widget.inc @@ -3,7 +3,7 @@ Basic events and Widget class declarations - Copyright (C) 2000 - 2006 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2007 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, |