lcl: use GetSysColorBrush if solid brush needs to be created with system color

win32: call Windows.GetSysColorBrush for lclintf.GetSysColorBrush

git-svn-id: trunk@25128 -
This commit is contained in:
paul 2010-05-02 09:25:41 +00:00
parent dec729b223
commit 9e2134c1a2
8 changed files with 34 additions and 4 deletions

View File

@ -1787,6 +1787,7 @@ function StringToColor(const S: shortstring): TColor;
procedure GetColorValues(Proc: TGetColorStringProc);
function InvertColor(AColor: TColor): TColor;
function DecColor(AColor: TColor; AQuantity: Byte): TColor;
function IsSysColor(AColor: TColor): Boolean;
function Blue(rgb: TColor): BYTE; // does not work on system color
function Green(rgb: TColor): BYTE; // does not work on system color
@ -2464,6 +2465,11 @@ begin
Result := RGBToColor(R, G, B);
end;
function IsSysColor(AColor: TColor): Boolean;
begin
Result := (Cardinal(AColor) and Cardinal(SYS_COLOR_BASE)) <> 0;
end;
{$I graphicsobject.inc}
{$I graphic.inc}

View File

@ -234,7 +234,10 @@ begin
end else
begin
if LogBrush.lbStyle <> BS_PATTERN then
FReference._lclHandle := TLCLHandle(CreateBrushIndirect(LogBrush))
if (LogBrush.lbStyle = BS_SOLID) and IsSysColor(LogBrush.lbColor) then
FReference._lclHandle := GetSysColorBrush(SysColorToSysColorIndex(LogBrush.lbColor))
else
FReference._lclHandle := TLCLHandle(CreateBrushIndirect(LogBrush))
else
FReference._lclHandle := TLCLHandle(CreatePatternBrush(LogBrush.lbHatch));
BrushResourceCache.AddResource(FReference.Handle, @LogBrush);

View File

@ -184,10 +184,7 @@ const
var
OldHandle: HBRUSH;
begin
//DebugLn('[TCanvas.CreateBrush] ',Classname,' Self=',DbgS(Self)
// ,' Brush=',DbgS(Brush));
OldHandle := SelectObject(FHandle, HGDIOBJ(Brush.Reference.Handle));
//debugln('TCanvas.CreateBrush ',ClassName,' Self=',DbgS(Self),' OldHandle=',DbgS(OldHandle),8),' NewHandle=',DbgS(Brush.Handle),' FSavedBrushHandle=',DbgS(Cardinal(FSavedBrushHandle));
if (OldHandle <> HBRUSH(Brush.Reference.Handle)) and (FSavedBrushHandle=0) then
FSavedBrushHandle := OldHandle;
Include(FState, csBrushValid);

View File

@ -1048,6 +1048,16 @@ begin
Result := 0;
end;
function TWidgetSet.GetSysColorBrush(nIndex: Integer): HBrush;
var
LogBrush: TLogBrush;
begin
LogBrush.lbColor := GetSysColor(nIndex);
LogBrush.lbStyle := 0; // BS_CLEAR
LogBrush.lbHatch := 0;
Result := CreateBrushIndirect(LogBrush);
end;
function TWidgetSet.GetSystemMetrics(nIndex: Integer): Integer;
begin
Result := 0;

View File

@ -466,6 +466,11 @@ begin
Result := WidgetSet.GetSysColor(nIndex);
end;
function GetSysColorBrush(nIndex: Integer): HBrush;
begin
Result := WidgetSet.GetSysColorBrush(nIndex);
end;
function GetSystemMetrics(nIndex: Integer): Integer;
begin
Result := WidgetSet.GetSystemMetrics(nIndex);

View File

@ -144,6 +144,7 @@ function GetScrollInfo(Handle: HWND; SBStyle: Integer; var ScrollInfo: TScrollIn
//function GetScrollRange --> independent
function GetStockObject(Value: Integer): THandle; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
function GetSysColor(nIndex: Integer): DWORD; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
function GetSysColorBrush(nIndex: Integer): HBrush; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
function GetSystemPaletteEntries(DC: HDC; StartIndex, NumEntries: UINT;
var PaletteEntries): UINT; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}
function GetSystemMetrics(nIndex: Integer): Integer; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF}

View File

@ -1981,6 +1981,13 @@ begin
Result := Windows.GetSysColor(nIndex);
end;
function TWin32WidgetSet.GetSysColorBrush(nIndex: Integer): HBrush;
begin
if NIndex = COLOR_FORM then
NIndex := COLOR_BTNFACE;
Result := Windows.GetSysColorBrush(nIndex);
end;
{------------------------------------------------------------------------------
Method: GetSystemMetrics
Params: NIndex - system metric to retrieve

View File

@ -119,6 +119,7 @@ function GetRGNBox(Rgn: HRGN; lpRect : PRect) : Longint; override;
function GetScrollInfo(Handle: HWND; BarFlag: Integer; Var ScrollInfo: TScrollInfo): Boolean; override;
function GetStockObject(Value: Integer): THandle; override;
function GetSysColor(NIndex: Integer): DWORD; override;
function GetSysColorBrush(nIndex: Integer): HBrush; override;
function GetSystemMetrics(NIndex: Integer): Integer; override;
function GetTextColor(DC: HDC): TColorRef; override;
function GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; Var Size: TSize): Boolean; override;