Gtk2: fixed memleaks in FillRgn

git-svn-id: trunk@41033 -
This commit is contained in:
zeljko 2013-05-05 09:04:16 +00:00
parent 0631e9d7d1
commit d5114580c9

View File

@ -3929,26 +3929,25 @@ var
CRect : TGDKRectangle; CRect : TGDKRectangle;
hasClipping: Boolean; hasClipping: Boolean;
begin begin
//todo: sanity checks for valid handle etc.
Result := IsValidDC(DC) and IsValidGDIObject(hbr) and IsValidGDIObject(RegionHnd); Result := IsValidDC(DC) and IsValidGDIObject(hbr) and IsValidGDIObject(RegionHnd);
if not Result then Exit; if not Result then Exit;
GtkDC := SaveDC(DC); GtkDC := SaveDC(DC);
DevCtx.ClipRegion := {%H-}PGdiObject(CreateRegionCopy(RegionHnd)); if (DevCtx.ClipRegion <> nil) and (DevCtx.ClipRegion^.GDIRegionObject <> nil) then
OldRgn:= DevCtx.ClipRegion^.GDIRegionObject; OldRgn := gdk_region_copy(DevCtx.ClipRegion^.GDIRegionObject)
else
hasClipping := Assigned(OldRgn); //todo: Check a better way OldRgn := nil;
hasClipping := Assigned(OldRgn);
try try
if hasClipping then if SelectClipRGN(DC, RegionHnd) <> ERROR then
if SelectClipRGN(DC, RegionHnd) <> ERROR then begin
begin gdk_region_get_clipbox({%H-}PGDIObject(RegionHnd)^.GDIRegionObject, @CRect);
gdk_region_get_clipbox({%H-}PGDIObject(RegionHnd)^.GDIRegionObject, @CRect); ARect := RectFromGdkRect(CRect);
ARect := RectFromGdkRect(CRect); DevCtx.FillRect(ARect, hbr, True);
DevCtx.FillRect(ARect, hbr, True); // revert clip (whatever it is - null or valid region)
if hasClipping then SelectClipRGN(DC, {%H-}HRGN(OldRgn));
SelectClipRGN(DC, {%H-}HRGN(OldRgn)); Result := True;
Result := True; end;
end;
finally finally
if hasClipping then if hasClipping then
gdk_region_destroy(OldRgn); gdk_region_destroy(OldRgn);
@ -7669,22 +7668,22 @@ begin
if not IsValidDC(DC) then Exit(ERROR); if not IsValidDC(DC) then Exit(ERROR);
// clear old clipregion // clear old clipregion
if Assigned(DevCtx.ClipRegion) if Assigned(DevCtx.ClipRegion) then
then begin begin
OldClipRegion := DevCtx.ClipRegion; OldClipRegion := DevCtx.ClipRegion;
DevCtx.ClipRegion := nil;// decrease DCCount DevCtx.ClipRegion := nil;// decrease DCCount
if OldClipRegion = DevCtx.OwnedGDIObjects[gdiRegion] if OldClipRegion = DevCtx.OwnedGDIObjects[gdiRegion] then
then DeleteObject(HGDIOBJ({%H-}PtrUInt(OldClipRegion))); DeleteObject(HGDIOBJ({%H-}PtrUInt(OldClipRegion)));
end; end;
if RGN = 0 if RGN = 0 then
then begin begin
DevCtx.SelectRegion; DevCtx.SelectRegion;
Exit(NULLREGION); Exit(NULLREGION);
end; end;
if IsValidGDIObject(RGN) if IsValidGDIObject(RGN) then
then begin begin
DevCtx.ClipRegion := {%H-}PGdiObject(CreateRegionCopy(RGN)); DevCtx.ClipRegion := {%H-}PGdiObject(CreateRegionCopy(RGN));
DevCtx.OwnedGDIObjects[gdiRegion] := DevCtx.ClipRegion; DevCtx.OwnedGDIObjects[gdiRegion] := DevCtx.ClipRegion;
RegObj := DevCtx.ClipRegion^.GDIRegionObject; RegObj := DevCtx.ClipRegion^.GDIRegionObject;