diff options
Diffstat (limited to 'gui/stylemanager.pas')
-rw-r--r-- | gui/stylemanager.pas | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/gui/stylemanager.pas b/gui/stylemanager.pas new file mode 100644 index 00000000..299083d1 --- /dev/null +++ b/gui/stylemanager.pas @@ -0,0 +1,74 @@ +unit stylemanager; + +{$mode objfpc}{$H+} + +interface + +uses + Classes + ,fpGUI + ; + +type + TStyleManager = class(TObject) + private + FDefaultStyle: TStyle; + FUserStyle: TStyle; + function GetDefaultStyle: TStyle; + public + property DefaultStyle: TStyle read GetDefaultStyle; + procedure SetStyle(pNewStyle: TStyle); + end; + + +// lazy mans singleton +function gStyleManager: TStyleManager; + + +implementation +uses + fpGFX + ; + +var + uStyleManager: TStyleManager; + + +{ Creation is deferred to the first request } +function gStyleManager: TStyleManager; +begin + if uStyleManager = nil then + uStyleManager := TStyleManager.Create; + result := uStyleManager; +end; + +{ TStyleManager } + +function TStyleManager.GetDefaultStyle: TStyle; +begin + if Assigned(FUserStyle) then + Result := FUserStyle + else + begin + if not Assigned(FDefaultStyle) then + FDefaultStyle := TDefaultStyle.Create(gApplication); + Result := FDefaultStyle; + end; +end; + +procedure TStyleManager.SetStyle(pNewStyle: TStyle); +begin + if Assigned(FUserStyle) then + FUserStyle.Free; + FUserStyle := pNewStyle; +end; + + +initialization + uStyleManager := nil; + +finalization + uStyleManager.Free; + +end. + |