From 7c2dbbb1e0e307dfd003a37af9b1908455ae7512 Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Fri, 2 Dec 2011 08:17:54 +0000 Subject: [PATCH] customdrawn: Postpones the palette creation time to avoid a circle between the LCL-CustomDrawn and the Drawer, each reading the palette from one another git-svn-id: trunk@33902 - --- lcl/customdrawn_common.pas | 10 ++++++++++ lcl/customdrawncontrols.pas | 4 ++++ lcl/customdrawndrawers.pas | 33 +++++++++++++++------------------ 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/lcl/customdrawn_common.pas b/lcl/customdrawn_common.pas index 648f877202..4afa6e9aa1 100644 --- a/lcl/customdrawn_common.pas +++ b/lcl/customdrawn_common.pas @@ -22,6 +22,7 @@ type TCDDrawerCommon = class(TCDDrawer) public + function PalDefaultUsesNativePalette: Boolean; override; procedure LoadFallbackPaletteColors; override; // General function GetMeasures(AMeasureID: Integer): Integer; override; @@ -129,6 +130,15 @@ const { TCDDrawerCommon } +function TCDDrawerCommon.PalDefaultUsesNativePalette: Boolean; +begin + {$ifdef MSWindows} + Result := True; + {$else} + Result := False; + {$endif} +end; + procedure TCDDrawerCommon.LoadFallbackPaletteColors; begin Palette.BtnFace := WIN2000_BTNFACE; diff --git a/lcl/customdrawncontrols.pas b/lcl/customdrawncontrols.pas index ab7a1840ac..19ebd53f10 100644 --- a/lcl/customdrawncontrols.pas +++ b/lcl/customdrawncontrols.pas @@ -723,10 +723,14 @@ begin end; procedure TCDControl.PrepareCurrentDrawer; +var + OldDrawer: TCDDrawer; begin + OldDrawer := FDrawer; FDrawer := GetDrawer(FDrawStyle); if FDrawer = nil then FDrawer := GetDrawer(dsCommon); // avoid exceptions in the object inspector if an invalid drawer is selected if FDrawer = nil then raise Exception.Create('No registered drawers were found'); + if OldDrawer <> FDrawer then FDrawer.LoadPalette(); end; procedure TCDControl.SetDrawStyle(const AValue: TCDDrawStyle); diff --git a/lcl/customdrawndrawers.pas b/lcl/customdrawndrawers.pas index a41e661542..dcd5d6144d 100644 --- a/lcl/customdrawndrawers.pas +++ b/lcl/customdrawndrawers.pas @@ -251,15 +251,17 @@ type public Palette: TCDColorPalette; FallbackPalette: TCDColorPalette; + PaletteKind: TCDPaletteKind; constructor Create; virtual; destructor Destroy; override; procedure CreateResources; virtual; procedure LoadResources; virtual; procedure FreeResources; virtual; procedure ScaleRasterImage(ARasterImage: TRasterImage; ASourceDPI, ADestDPI: Word); - procedure SetPaletteKind(APaletteKind: TCDPaletteKind); + procedure LoadPalette; procedure LoadNativePaletteColors; procedure LoadFallbackPaletteColors; virtual; + function PalDefaultUsesNativePalette: Boolean; virtual; function GetDrawStyle: TCDDrawStyle; virtual; // GetControlDefaultColor is used by customdrawncontrols to resolve clDefault function GetControlDefaultColor(AControlId: TCDControlID): TColor; @@ -471,11 +473,13 @@ constructor TCDDrawer.Create; begin inherited Create; + // We never load the system palette at creation because we might get created + // before the Widgetset is constructed Palette := TCDColorPalette.Create; - SetPaletteKind(palFallback); + LoadFallbackPaletteColors(); FallbackPalette := TCDColorPalette.Create; FallbackPalette.Assign(Palette); - SetPaletteKind(palDefault); + PaletteKind := palDefault; CreateResources; LoadResources; @@ -515,24 +519,12 @@ begin ARasterImage.Height := lNewHeight; end; -procedure TCDDrawer.SetPaletteKind(APaletteKind: TCDPaletteKind); -var - lIsOnNativeSystem: Boolean = False; - lStyle: TCDDrawStyle; +procedure TCDDrawer.LoadPalette; begin - case APaletteKind of + case PaletteKind of palDefault: begin - lStyle := GetDrawStyle(); - case lStyle of - dsWinCE: lIsOnNativeSystem := {$ifdef WinCE}True{$else}False{$endif}; - dsCommon, dsWin2000, dsWinXP: - lIsOnNativeSystem := {$ifdef MSWindows}True{$else}False{$endif}; - else - lIsOnNativeSystem := False; - end; - - if lIsOnNativeSystem then LoadNativePaletteColors() + if PalDefaultUsesNativePalette() then LoadNativePaletteColors() else LoadFallbackPaletteColors(); end; palNative: LoadNativePaletteColors(); @@ -582,6 +574,11 @@ begin end; +function TCDDrawer.PalDefaultUsesNativePalette: Boolean; +begin + Result := False; +end; + function TCDDrawer.GetDrawStyle: TCDDrawStyle; begin Result := dsCommon;