Qt: fix segfault when creating QRegion with negative width or height.Fixed implementation of GetRgnBox, so it doesn't ask for QRegion_boundingRect() if returned region type is ERROR or NULLREGION.

git-svn-id: trunk@22881 -
This commit is contained in:
zeljko 2009-11-30 20:43:38 +00:00
parent 41403c5fbd
commit 06a978b8e3
2 changed files with 17 additions and 7 deletions

View File

@ -1631,7 +1631,7 @@ begin
{$endif}
// Creates the widget
if CreateHandle then Widget := QRegion_create;
if CreateHandle then Widget := QRegion_create();
end;
{------------------------------------------------------------------------------
@ -1641,6 +1641,8 @@ end;
------------------------------------------------------------------------------}
constructor TQtRegion.Create(CreateHandle: Boolean; X1,Y1,X2,Y2:Integer;
Const RegionType: QRegionRegionType = QRegionRectangle);
var
W, H: Integer;
begin
{$ifdef VerboseQt}
WriteLn('TQtRegion.Create CreateHandle: ', dbgs(CreateHandle));
@ -1649,7 +1651,16 @@ begin
// Creates the widget
// Note that QRegion_create expects a width and a height,
// and not a X2, Y2 bottom-right point
if CreateHandle then Widget := QRegion_create(X1,Y1,X2-X1,Y2-Y1, RegionType);
if CreateHandle then
begin
W := X2 - X1;
H := Y2 - Y1;
if W < 0 then
W := 0;
if H < 0 then
H := 0;
Widget := QRegion_create(X1, Y1, W, H, RegionType);
end;
end;
constructor TQtRegion.Create(CreateHandle: Boolean; Poly: QPolygonH;

View File

@ -2581,20 +2581,19 @@ var
R: TRect;
begin
{$ifdef VerboseQtWinAPI}
WriteLn('[WinAPI TQtWidgetSet.GetRgnBox] possible wrong implementation !');
writeln('Trace:> [WinAPI GetRgnBox] Handle: ' + dbghex(RGN));
{$endif}
Result := SIMPLEREGION;
If lpRect <> nil then
if lpRect <> nil then
lpRect^ := Rect(0,0,0,0);
If Not IsValidGDIObject(RGN) then
if not IsValidGDIObject(RGN) then
Result := ERROR
else
begin
Result := TQtRegion(RGN).GetRegionType;
If lpRect <> nil then
if not (Result in [ERROR, NULLREGION]) and (lpRect <> nil) then
begin
QRegion_boundingRect(TQtRegion(RGN).Widget, @R);
with lpRect^ do
begin
Left := R.Left;