diff --git a/lcl/graphics.pp b/lcl/graphics.pp index ad29658a11..889269ce5d 100644 --- a/lcl/graphics.pp +++ b/lcl/graphics.pp @@ -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} diff --git a/lcl/include/brush.inc b/lcl/include/brush.inc index 25f1f22c1e..be4582dc54 100644 --- a/lcl/include/brush.inc +++ b/lcl/include/brush.inc @@ -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); diff --git a/lcl/include/canvas.inc b/lcl/include/canvas.inc index 4c8ff854ca..a442874fba 100644 --- a/lcl/include/canvas.inc +++ b/lcl/include/canvas.inc @@ -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); diff --git a/lcl/include/intfbasewinapi.inc b/lcl/include/intfbasewinapi.inc index 1b2deda57b..3a5f296414 100644 --- a/lcl/include/intfbasewinapi.inc +++ b/lcl/include/intfbasewinapi.inc @@ -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; diff --git a/lcl/include/winapi.inc b/lcl/include/winapi.inc index 3e4df82fbd..c78f0af8cc 100644 --- a/lcl/include/winapi.inc +++ b/lcl/include/winapi.inc @@ -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); diff --git a/lcl/include/winapih.inc b/lcl/include/winapih.inc index 7393a61150..1b952de4df 100644 --- a/lcl/include/winapih.inc +++ b/lcl/include/winapih.inc @@ -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} diff --git a/lcl/interfaces/win32/win32winapi.inc b/lcl/interfaces/win32/win32winapi.inc index f821bcd1ac..a1fbcc9fce 100644 --- a/lcl/interfaces/win32/win32winapi.inc +++ b/lcl/interfaces/win32/win32winapi.inc @@ -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 diff --git a/lcl/interfaces/win32/win32winapih.inc b/lcl/interfaces/win32/win32winapih.inc index bfe4f3b775..018f9fef8a 100644 --- a/lcl/interfaces/win32/win32winapih.inc +++ b/lcl/interfaces/win32/win32winapih.inc @@ -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;