Qt: avoid crash inside q_DrawXXX() functions when palette paremeter is nil and painter parent is nil. fixes #14673

git-svn-id: trunk@21876 -
This commit is contained in:
zeljko 2009-09-26 07:40:18 +00:00
parent b680c53595
commit 771b53b7e8

View File

@ -1943,21 +1943,46 @@ end;
procedure TQtDeviceContext.qDrawShadeRect(x, y, w, h: integer; Palette: QPaletteH = nil; Sunken: Boolean = False; procedure TQtDeviceContext.qDrawShadeRect(x, y, w, h: integer; Palette: QPaletteH = nil; Sunken: Boolean = False;
lineWidth: Integer = 1; midLineWidth: Integer = 0; FillBrush: QBrushH = nil); lineWidth: Integer = 1; midLineWidth: Integer = 0; FillBrush: QBrushH = nil);
var
AppPalette: QPaletteH;
begin begin
AppPalette := nil;
if Palette = nil then if Palette = nil then
begin
if Parent = nil then
begin
AppPalette := QPalette_create();
QApplication_palette(AppPalette);
Palette := AppPalette;
end else
Palette := QWidget_palette(Parent); Palette := QWidget_palette(Parent);
end;
q_DrawShadeRect(Widget, x, y, w, h, Palette, Sunken, lineWidth, midLineWidth, FillBrush); q_DrawShadeRect(Widget, x, y, w, h, Palette, Sunken, lineWidth, midLineWidth, FillBrush);
if AppPalette <> nil then
begin
QPalette_destroy(AppPalette);
Palette := nil;
end;
end; end;
procedure TQtDeviceContext.qDrawWinPanel(x, y, w, h: integer; procedure TQtDeviceContext.qDrawWinPanel(x, y, w, h: integer;
Palette: QPaletteH; Sunken: Boolean; lineWidth: Integer; FillBrush: QBrushH); Palette: QPaletteH; Sunken: Boolean; lineWidth: Integer; FillBrush: QBrushH);
var var
i: integer; i: integer;
AppPalette: QPaletteH;
begin begin
AppPalette := nil;
if Palette = nil then if Palette = nil then
begin
if Parent = nil then
begin
AppPalette := QPalette_create();
QApplication_palette(AppPalette);
Palette := AppPalette;
end else
Palette := QWidget_palette(Parent); Palette := QWidget_palette(Parent);
end;
// since q_DrawWinPanel doesnot supports lineWidth we should do it ourself // since q_DrawWinPanel doesnot supports lineWidth we should do it ourself
for i := 1 to lineWidth - 2 do for i := 1 to lineWidth - 2 do
begin begin
q_DrawWinPanel(Widget, x, y, w, h, Palette, Sunken); q_DrawWinPanel(Widget, x, y, w, h, Palette, Sunken);
@ -1975,6 +2000,11 @@ begin
else else
q_DrawShadePanel(Widget, x, y, w, h, Palette, Sunken, 1, FillBrush); q_DrawShadePanel(Widget, x, y, w, h, Palette, Sunken, 1, FillBrush);
end; end;
if AppPalette <> nil then
begin
QPalette_destroy(AppPalette);
Palette := nil;
end;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------