mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 07:19:31 +02:00
Qt: invalidate only handles of syscolor brushes when style is dynamically changed, otherwise we have segfault, because brush can be in saveddc data.
git-svn-id: trunk@25136 -
This commit is contained in:
parent
e76087acbe
commit
8d37468fe5
@ -141,7 +141,7 @@ type
|
||||
procedure SetQtDefaultDC(Handle: HDC); virtual;
|
||||
procedure InitStockItems;
|
||||
procedure FreeStockItems;
|
||||
procedure FreeSysColorBrushes;
|
||||
procedure FreeSysColorBrushes(const AInvalidateHandlesOnly: Boolean = False);
|
||||
|
||||
property DragImageLock: Boolean read FDragImageLock write FDragImageLock;
|
||||
property OverrideCursor: TObject read FOverrideCursor write SetOverrideCursor;
|
||||
|
@ -289,7 +289,7 @@ begin
|
||||
QEventStyleChange:
|
||||
begin
|
||||
ClearCachedColors;
|
||||
FreeSysColorBrushes;
|
||||
FreeSysColorBrushes(True);
|
||||
end;
|
||||
LCLQt_Destroy:
|
||||
begin
|
||||
@ -607,7 +607,7 @@ begin
|
||||
DeleteAndNilObject(FStockSystemFont);
|
||||
end;
|
||||
|
||||
procedure TQtWidgetSet.FreeSysColorBrushes;
|
||||
procedure TQtWidgetSet.FreeSysColorBrushes(const AInvalidateHandlesOnly: Boolean = False);
|
||||
|
||||
procedure DeleteAndNilObject(var h: HGDIOBJ);
|
||||
begin
|
||||
@ -619,11 +619,24 @@ procedure TQtWidgetSet.FreeSysColorBrushes;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure InvalidateHandleOnly(AIndex: Integer; h: HGDIOBJ);
|
||||
begin
|
||||
if (h <> 0) and (TQtBrush(h).Widget <> nil) then
|
||||
begin
|
||||
QBrush_destroy(TQtBrush(h).Widget);
|
||||
TQtBrush(h).Widget := nil;
|
||||
getSysColorBrush(AIndex);
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
for i := Low(FSysColorBrushes) to High(FSysColorBrushes) do
|
||||
DeleteAndNilObject(FSysColorBrushes[i]);
|
||||
if AInvalidateHandlesOnly then
|
||||
InvalidateHandleOnly(i, FSysColorBrushes[i])
|
||||
else
|
||||
DeleteAndNilObject(FSysColorBrushes[i]);
|
||||
end;
|
||||
|
||||
function TQtWidgetSet.GetQtDefaultDC: HDC;
|
||||
|
@ -1645,7 +1645,7 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
function TQtWidgetSet.FillRect(DC: HDC; const Rect: TRect; Brush: HBRUSH): Boolean;
|
||||
begin
|
||||
result:=false;
|
||||
Result := False;
|
||||
|
||||
{$ifdef VerboseQtWinAPI}
|
||||
DebugLn('[WinAPI FillRect Rect=', dbgs(Rect),' Brush=', dbghex(Brush));
|
||||
@ -1656,9 +1656,8 @@ begin
|
||||
if not IsValidGdiObject(Brush) then
|
||||
exit;
|
||||
|
||||
TQTDeviceContext(DC).fillRect(@Rect, TQtBrush(Brush).Widget);
|
||||
|
||||
result := true;
|
||||
TQtDeviceContext(DC).fillRect(@Rect, TQtBrush(Brush).Widget);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -2917,8 +2916,10 @@ function TQtWidgetSet.GetSysColorBrush(nIndex: Integer): HBrush;
|
||||
QApplication_palette(Handle)
|
||||
else
|
||||
QApplication_palette(Handle, ClassName);
|
||||
|
||||
Result := HBrush(TQtBrush.Create(False));
|
||||
if FSysColorBrushes[nIndex] = 0 then
|
||||
Result := HBrush(TQtBrush.Create(False))
|
||||
else
|
||||
Result := FSysColorBrushes[nIndex];
|
||||
TQtBrush(Result).Widget := QBrush_create(QPalette_brush(Handle, Group, Role));
|
||||
TQtBrush(Result).FShared := True;
|
||||
|
||||
@ -2929,7 +2930,10 @@ function TQtWidgetSet.GetSysColorBrush(nIndex: Integer): HBrush;
|
||||
var
|
||||
Color: TQColor;
|
||||
begin
|
||||
Result := HBrush(TQtBrush.Create(True));
|
||||
if FSysColorBrushes[nIndex] = 0 then
|
||||
Result := HBrush(TQtBrush.Create(True))
|
||||
else
|
||||
Result := FSysColorBrushes[nIndex];
|
||||
Color := QBrush_Color(TQtBrush(Result).Widget)^;
|
||||
ColorRefToTQColor(ColorToRGB(AColor), Color);
|
||||
QBrush_setColor(TQtBrush(Result).Widget, @Color);
|
||||
@ -2943,7 +2947,11 @@ begin
|
||||
Exit;
|
||||
end;
|
||||
|
||||
if FSysColorBrushes[nIndex] = 0 then
|
||||
if (FSysColorBrushes[nIndex] = 0) or
|
||||
(
|
||||
(FSysColorBrushes[nIndex] <> 0) and
|
||||
(TQtBrush(FSysColorBrushes[nIndex]).Widget = nil)
|
||||
) then
|
||||
begin
|
||||
case nIndex of
|
||||
COLOR_SCROLLBAR : Result:=GetBrush(QPaletteActive, QPaletteButton);
|
||||
|
Loading…
Reference in New Issue
Block a user