lcl, win32: handle clDefault font color in controls

git-svn-id: trunk@28308 -
This commit is contained in:
paul 2010-11-18 02:50:43 +00:00
parent a5f3523e6f
commit 6380ade6ac
9 changed files with 52 additions and 24 deletions

View File

@ -477,12 +477,12 @@ procedure SetDefaultFont(AFont: TFont; Layout: TCalculatorLayout);
begin
with AFont do
begin
Color:=clWindowText;
Name:='MS Sans Serif';
Size:=8;
Style:=[fsBold];
end;
begin
Color := clWindowText;
Name := 'MS Sans Serif';
Size := 8;
Style := [fsBold];
end;
end;
function CreateCalculatorForm(AOwner: TComponent; ALayout : TCalculatorLayout; AHelpContext: THelpContext): TCalculatorForm;
@ -492,11 +492,11 @@ begin
try
HelpContext:=AHelpContext;
if Screen.PixelsPerInch <> 96 then
begin { scale to screen res }
begin { scale to screen res }
SetDefaultFont(Font, ALayout);
Left:=(Screen.Width div 2) - (Width div 2);
Top:=(Screen.Height div 2) - (Height div 2);
end;
end;
except
Free;
raise;

View File

@ -516,6 +516,7 @@ type
procedure SetCharSet(const AValue: TFontCharSet);
procedure SetColor(const NewColor: TColor; const NewFPColor: TFPColor); virtual;
procedure SetColor(Value: TColor);
function GetColor: TColor;
procedure SetFlags(Index: integer; AValue: boolean); override;
procedure SetFPColor(const AValue: TFPColor); override;
procedure SetHeight(Avalue: Integer);
@ -544,7 +545,7 @@ type
property Reference: TWSFontReference read GetReference;
published
property CharSet: TFontCharSet read GetCharSet write SetCharSet default DEFAULT_CHARSET;
property Color: TColor read FColor write SetColor default clWindowText;
property Color: TColor read FColor write SetColor default {$ifdef UseCLDefault}clDefault{$else}clWindowText{$endif};
property Height: Integer read GetHeight write SetHeight stored IsHeightStored;
property Name: string read GetName write SetName stored IsNameStored;
property Orientation: Integer read GetOrientation write SetOrientation default 0;

View File

@ -259,10 +259,10 @@ begin
// The TFont will call DeleteObject itself, so we never need to call it.
OldHandle := SelectObject(FHandle, HGDIOBJ(Font.Reference.Handle));
//DebugLn(['TCanvas.CreateFont OldHandle=',dbghex(OldHandle),' Font.Handle=',dbghex(Font.Handle)]);
if (OldHandle <> HFONT(Font.Reference.Handle)) and (FSavedFontHandle=0) then
if (OldHandle <> HFONT(Font.Reference.Handle)) and (FSavedFontHandle = 0) then
FSavedFontHandle := OldHandle;
Include(FState, csFontValid);
SetTextColor(FHandle, Font.Color);
SetTextColor(FHandle, Font.GetColor);
end;
{------------------------------------------------------------------------------
@ -1203,7 +1203,8 @@ begin
SetBkMode(DC, TRANSPARENT);
if Style.SystemFont then
SetTextColor(DC, Font.Color);
SetTextColor(DC, Font.GetColor);
//debugln('TCanvas.TextRect DRAW Text="',Text,'" ',dbgs(fRect));
DrawText(DC, pChar(Text), Length(Text), fRect, Options);

View File

@ -600,7 +600,7 @@ end;
constructor TFont.Create;
begin
inherited Create;
FColor := clWindowText;
FColor := {$ifdef UseCLDefault}clDefault{$else}clWindowText{$endif};
FPixelsPerInch := ScreenInfo.PixelsPerInchY;
FPitch := DefFontData.Pitch;
FCharSet := DefFontData.CharSet;
@ -743,7 +743,7 @@ end;
function TFont.IsDefault: boolean;
begin
Result:=(CharSet=DEFAULT_CHARSET)
and (Color=clWindowText)
and (Color={$ifdef UseCLDefault}clDefault{$else}clWindowText{$endif})
and (Height=0)
and (not IsNameStored)
and (Pitch=fpDefault)
@ -767,7 +767,7 @@ begin
Pitch := DefFontData.Pitch;
Quality := DefFontData.Quality;
Style := DefFontData.Style;
Color := clWindowText;
Color := {$ifdef UseCLDefault}clDefault{$else}clWindowText{$endif};
finally
EndUpdate;
end;
@ -896,6 +896,13 @@ begin
SetColor(Value, TColorToFPColor(Value));
end;
function TFont.GetColor: TColor;
begin
Result := Color;
if (Result = clDefault) and Assigned(Canvas) and (Canvas is TCanvas) then
Result := TCanvas(Canvas).GetDefaultColor(dctFont);
end;
{------------------------------------------------------------------------------
Function: TFont.GetName
Params: none

View File

@ -731,7 +731,7 @@ begin
if not WidgetSet.InitStockFont(FSystemFont, sfSystem) then
begin
FSystemFont.FontData := DefFontData;
FSystemFont.Color := clWindowText;
FSystemFont.Color := {$ifdef UseCLDefault}clDefault{$else}clWindowText{$endif};
end;
Result := FSystemFont;
end;
@ -755,7 +755,7 @@ begin
if not WidgetSet.InitStockFont(FIconFont, sfIcon) then
begin
FIconFont.FontData := DefFontData;
FIconFont.Color := clWindowText;
FIconFont.Color := {$ifdef UseCLDefault}clDefault{$else}clWindowText{$endif};
end;
Result := FIconFont;
end;

View File

@ -1364,7 +1364,10 @@ begin
begin
if ChildWinControl <> nil then
begin
Windows.SetTextColor(WindowDC, Windows.COLORREF(ColorToRGB(ChildWinControl.Font.Color)));
WindowColor := ChildWinControl.Font.Color;
if WindowColor = clDefault then
WindowColor := ChildWinControl.GetDefaultColor(dctFont);
Windows.SetTextColor(WindowDC, Windows.COLORREF(ColorToRGB(WindowColor)));
WindowColor := ChildWinControl.Brush.Color;
if WindowColor = clDefault then
WindowColor := ChildWinControl.GetDefaultColor(dctBrush);

View File

@ -187,6 +187,7 @@ var
Options: TDTTOpts;
Details: TThemedElementDetails;
ShowAccel: Boolean;
Color: TColor;
begin
glyphWidth := srcWidth;
glyphHeight := srcHeight;
@ -215,7 +216,10 @@ var
else
begin
Windows.FillRect(TmpDC, BitmapRect, GetSysColorBrush(COLOR_BTNFACE));
SetTextColor(TmpDC, ColorToRGB(BitBtn.Font.Color));
Color := BitBtn.Font.Color;
if Color = clDefault then
Color := BitBtn.GetDefaultColor(dctFont);
SetTextColor(TmpDC, ColorToRGB(Color));
end;
if AState <> bsDisabled then
@ -297,7 +301,10 @@ var
if AState <> bsDisabled then
begin
// change color to requested or it will be black
Options.crText := ThemeServices.ColorToRGB(BitBtn.Font.Color, @Details);
Color := BitBtn.Font.Color;
if Color = clDefault then
Color := BitBtn.GetDefaultColor(dctFont);
Options.crText := ThemeServices.ColorToRGB(Color, @Details);
Options.crShadow := Options.crText;
Options.dwFlags := Options.dwFlags or DTT_TEXTCOLOR;
end;

View File

@ -217,7 +217,12 @@ class procedure TWin32WSCustomCheckListBox.DefaultWndHandler(
if Selected then
OldColor := Windows.SetTextColor(Data^._HDC, Windows.GetSysColor(COLOR_HIGHLIGHTTEXT))
else
OldColor := Windows.SetTextColor(Data^._HDC, ColorToRGB(CheckListBox.Font.Color));
begin
OldColor := CheckListBox.Font.Color;
if OldColor = clDefault then
OldColor := CheckListBox.GetDefaultColor(dctFont);
OldColor := Windows.SetTextColor(Data^._HDC, ColorToRGB(OldColor));
end;
{$ifdef WindowsUnicodeSupport}
if UnicodeEnabledOS then
begin

View File

@ -1004,13 +1004,17 @@ begin
// TODO ???
end;
class procedure TWin32WSCustomListView.SetFont(const AWinControl: TWinControl;
const AFont: TFont);
class procedure TWin32WSCustomListView.SetFont(const AWinControl: TWinControl; const AFont: TFont);
var
Color: TColor;
begin
// call inherited SetFont; need to do it this way,
// because the compile time ancestor class is TWSCustomListView
TWSWinControlClass(ClassParent).SetFont(AWinControl, AFont);
Windows.SendMessage(AWinControl.Handle, LVM_SETTEXTCOLOR, 0, ColorToRGB(AFont.Color));
Color := AFont.Color;
if Color = clDefault then
Color := AWinControl.GetDefaultColor(dctFont);
Windows.SendMessage(AWinControl.Handle, LVM_SETTEXTCOLOR, 0, ColorToRGB(Color));
end;
class procedure TWin32WSCustomListView.SetHotTrackStyles(const ALV: TCustomListView; const AValue: TListHotTrackStyles);