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:
zeljko 2010-05-02 15:25:31 +00:00
parent e76087acbe
commit 8d37468fe5
3 changed files with 33 additions and 12 deletions

View File

@ -141,7 +141,7 @@ type
procedure SetQtDefaultDC(Handle: HDC); virtual; procedure SetQtDefaultDC(Handle: HDC); virtual;
procedure InitStockItems; procedure InitStockItems;
procedure FreeStockItems; procedure FreeStockItems;
procedure FreeSysColorBrushes; procedure FreeSysColorBrushes(const AInvalidateHandlesOnly: Boolean = False);
property DragImageLock: Boolean read FDragImageLock write FDragImageLock; property DragImageLock: Boolean read FDragImageLock write FDragImageLock;
property OverrideCursor: TObject read FOverrideCursor write SetOverrideCursor; property OverrideCursor: TObject read FOverrideCursor write SetOverrideCursor;

View File

@ -289,7 +289,7 @@ begin
QEventStyleChange: QEventStyleChange:
begin begin
ClearCachedColors; ClearCachedColors;
FreeSysColorBrushes; FreeSysColorBrushes(True);
end; end;
LCLQt_Destroy: LCLQt_Destroy:
begin begin
@ -607,7 +607,7 @@ begin
DeleteAndNilObject(FStockSystemFont); DeleteAndNilObject(FStockSystemFont);
end; end;
procedure TQtWidgetSet.FreeSysColorBrushes; procedure TQtWidgetSet.FreeSysColorBrushes(const AInvalidateHandlesOnly: Boolean = False);
procedure DeleteAndNilObject(var h: HGDIOBJ); procedure DeleteAndNilObject(var h: HGDIOBJ);
begin begin
@ -619,10 +619,23 @@ procedure TQtWidgetSet.FreeSysColorBrushes;
end; end;
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 var
i: integer; i: integer;
begin begin
for i := Low(FSysColorBrushes) to High(FSysColorBrushes) do for i := Low(FSysColorBrushes) to High(FSysColorBrushes) do
if AInvalidateHandlesOnly then
InvalidateHandleOnly(i, FSysColorBrushes[i])
else
DeleteAndNilObject(FSysColorBrushes[i]); DeleteAndNilObject(FSysColorBrushes[i]);
end; end;

View File

@ -1645,7 +1645,7 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TQtWidgetSet.FillRect(DC: HDC; const Rect: TRect; Brush: HBRUSH): Boolean; function TQtWidgetSet.FillRect(DC: HDC; const Rect: TRect; Brush: HBRUSH): Boolean;
begin begin
result:=false; Result := False;
{$ifdef VerboseQtWinAPI} {$ifdef VerboseQtWinAPI}
DebugLn('[WinAPI FillRect Rect=', dbgs(Rect),' Brush=', dbghex(Brush)); DebugLn('[WinAPI FillRect Rect=', dbgs(Rect),' Brush=', dbghex(Brush));
@ -1656,9 +1656,8 @@ begin
if not IsValidGdiObject(Brush) then if not IsValidGdiObject(Brush) then
exit; exit;
TQTDeviceContext(DC).fillRect(@Rect, TQtBrush(Brush).Widget); TQtDeviceContext(DC).fillRect(@Rect, TQtBrush(Brush).Widget);
Result := True;
result := true;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -2917,8 +2916,10 @@ function TQtWidgetSet.GetSysColorBrush(nIndex: Integer): HBrush;
QApplication_palette(Handle) QApplication_palette(Handle)
else else
QApplication_palette(Handle, ClassName); QApplication_palette(Handle, ClassName);
if FSysColorBrushes[nIndex] = 0 then
Result := HBrush(TQtBrush.Create(False)); Result := HBrush(TQtBrush.Create(False))
else
Result := FSysColorBrushes[nIndex];
TQtBrush(Result).Widget := QBrush_create(QPalette_brush(Handle, Group, Role)); TQtBrush(Result).Widget := QBrush_create(QPalette_brush(Handle, Group, Role));
TQtBrush(Result).FShared := True; TQtBrush(Result).FShared := True;
@ -2929,7 +2930,10 @@ function TQtWidgetSet.GetSysColorBrush(nIndex: Integer): HBrush;
var var
Color: TQColor; Color: TQColor;
begin 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)^; Color := QBrush_Color(TQtBrush(Result).Widget)^;
ColorRefToTQColor(ColorToRGB(AColor), Color); ColorRefToTQColor(ColorToRGB(AColor), Color);
QBrush_setColor(TQtBrush(Result).Widget, @Color); QBrush_setColor(TQtBrush(Result).Widget, @Color);
@ -2943,7 +2947,11 @@ begin
Exit; Exit;
end; end;
if FSysColorBrushes[nIndex] = 0 then if (FSysColorBrushes[nIndex] = 0) or
(
(FSysColorBrushes[nIndex] <> 0) and
(TQtBrush(FSysColorBrushes[nIndex]).Widget = nil)
) then
begin begin
case nIndex of case nIndex of
COLOR_SCROLLBAR : Result:=GetBrush(QPaletteActive, QPaletteButton); COLOR_SCROLLBAR : Result:=GetBrush(QPaletteActive, QPaletteButton);