(Qt): Fixed all mem leaks with SynEdit, Bitmaps by paul, with small fix against his patch from me.

git-svn-id: trunk@11730 -
This commit is contained in:
zeljko 2007-08-03 17:49:21 +00:00
parent 010ccd79e7
commit abbd39ddec
6 changed files with 61 additions and 73 deletions

View File

@ -412,7 +412,7 @@ procedure TEmulatedCaret.UpdateCaret;
var var
R: TRect; R: TRect;
begin begin
if (FWidget <> nil) and not FWidget.InPaint then if (FWidget <> nil) and not (FWidget.Context <> 0) then
begin begin
R.Left := FPos.x; R.Left := FPos.x;
R.Top := FPos.y; R.Top := FPos.y;

View File

@ -26,7 +26,7 @@ constructor TQtWidgetSet.Create;
begin begin
inherited Create; inherited Create;
InitStockItems; InitStockItems;
QtWidgetSet := Self; QtWidgetSet := Self;
end; end;
@ -42,14 +42,16 @@ destructor TQtWidgetSet.Destroy;
begin begin
DestroyGlobalCaret; DestroyGlobalCaret;
Clipboard.Free; Clipboard.Free;
FreeStockItems;
FreeStockItems;
QtWidgetSet := nil; QtWidgetSet := nil;
if SavedDCList<>nil then if SavedDCList<>nil then
SavedDCList.Free; SavedDCList.Free;
QtDefaultContext.Free;
QtScreenContext.Free;
inherited Destroy; inherited Destroy;
end; end;
@ -234,7 +236,7 @@ begin
Painter :=TQtDeviceContext(CanvasHandle).Widget; Painter :=TQtDeviceContext(CanvasHandle).Widget;
Pen := QPainter_pen(Painter); Pen := QPainter_pen(Painter);
QPen_color(Pen, @ASavedColor); QPen_color(Pen, @ASavedColor);
QColor_setRgb(QColorH(@Color),Red(AColor),Green(AColor),Blue(AColor)); QColor_setRgb(QColorH(@Color),Red(AColor),Green(AColor),Blue(AColor));
QPainter_setPen(Painter, @Color); QPainter_setPen(Painter, @Color);
QPainter_drawPoint(Painter, X,Y); QPainter_drawPoint(Painter, X,Y);
QPainter_setPen(Painter, @ASavedColor); QPainter_setPen(Painter, @ASavedColor);

View File

@ -391,6 +391,9 @@ type
procedure DebugRegion(const msg: string; Rgn: QRegionH); procedure DebugRegion(const msg: string; Rgn: QRegionH);
function Clipboard: TQtClipboard; function Clipboard: TQtClipboard;
function QtDefaultContext: TQtDeviceContext;
function QtScreenContext: TQtDeviceContext;
implementation implementation
const const
ClipbBoardTypeToQtClipboard: array[TClipboardType] of QClipboardMode = ClipbBoardTypeToQtClipboard: array[TClipboardType] of QClipboardMode =
@ -402,6 +405,22 @@ const
var var
FClipboard: TQtClipboard = nil; FClipboard: TQtClipboard = nil;
FDefaultContext: TQtDeviceContext = nil;
FScreenContext: TQtDeviceContext = nil;
function QtDefaultContext: TQtDeviceContext;
begin
if FDefaultContext = nil then
FDefaultContext := TQtDeviceContext.Create(nil);
Result := FDefaultContext;
end;
function QtScreenContext: TQtDeviceContext;
begin
if FScreenContext = nil then
FScreenContext := TQtDeviceContext.Create(QApplication_desktop(), True);
Result := FScreenContext;
end;
{ TQtObject } { TQtObject }
@ -709,7 +728,8 @@ end;
procedure TQtFont.setPointSize(p1: Integer); procedure TQtFont.setPointSize(p1: Integer);
begin begin
QFont_setPointSize(Widget, p1); if p1 > 0 then
QFont_setPointSize(Widget, p1);
end; end;
function TQtFont.pixelSize: Integer; function TQtFont.pixelSize: Integer;
@ -719,7 +739,8 @@ end;
procedure TQtFont.setPixelSize(p1: Integer); procedure TQtFont.setPixelSize(p1: Integer);
begin begin
QFont_setPixelSize(Widget, p1); if p1 > 0 then
QFont_setPixelSize(Widget, p1);
end; end;
function TQtFont.weight: Integer; function TQtFont.weight: Integer;
@ -1105,8 +1126,8 @@ begin
if Parent <> nil then if Parent <> nil then
begin begin
vFont := TQtFont.Create(False); vFont := TQtFont.Create(False);
vFont.Owner := Self; vFont.Owner := Self;
vBrush := TQtBrush.Create(False); vBrush := TQtBrush.Create(False);
vBrush.Owner := Self; vBrush.Owner := Self;
@ -1117,8 +1138,8 @@ begin
vRegion := TQtRegion.Create(False); vRegion := TQtRegion.Create(False);
vRegion.Owner := Self; vRegion.Owner := Self;
vBackgroundBrush := TQtBrush.Create(False); vBackgroundBrush := TQtBrush.Create(False);
vBackgroundBrush.Owner := Self; vBackgroundBrush.Owner := Self;
end else end else
begin begin
@ -1150,26 +1171,23 @@ begin
if Parent <> nil then if Parent <> nil then
begin begin
vFont.Widget := nil;
vFont.Widget := nil; vFont.Free;
vFont.Free;
vBrush.Widget := nil; vBrush.Widget := nil;
vBrush.Free; vBrush.Free;
vPen.Widget := nil; vPen.Widget := nil;
vPen.Free; vPen.Free;
vRegion.Widget := nil; vRegion.Widget := nil;
vRegion.Free; vRegion.Free;
vBackgroundBrush.Widget := nil; vBackgroundBrush.Widget := nil;
vBackgroundBrush.Free; vBackgroundBrush.Free;
end; end;
if vImage <> nil then
QImage_destroy(vImage);
if Widget <> nil then if Widget <> nil then
begin
QPainter_destroy(Widget); QPainter_destroy(Widget);
end;
if ParentPixmap <> nil then if ParentPixmap <> nil then
QPixmap_destroy(ParentPixmap); QPixmap_destroy(ParentPixmap);
@ -2189,3 +2207,4 @@ end;
end. end.

View File

@ -53,6 +53,7 @@ type
FPaintData: TPaintData; FPaintData: TPaintData;
FCentralWidget: QWidgetH; FCentralWidget: QWidgetH;
FStopMouseEventsProcessing: Boolean; // widget stop processing of mouse events FStopMouseEventsProcessing: Boolean; // widget stop processing of mouse events
FContext: HDC;
function GetProps(const AnIndex: String): pointer; function GetProps(const AnIndex: String): pointer;
function GetWidget: QWidgetH; function GetWidget: QWidgetH;
@ -70,7 +71,6 @@ type
AVariant: QVariantH; AVariant: QVariantH;
LCLObject: TWinControl; LCLObject: TWinControl;
HasCaret: Boolean; HasCaret: Boolean;
InPaint: Boolean;
public public
constructor Create(const AWinControl: TWinControl; const AParams: TCreateParams); virtual; constructor Create(const AWinControl: TWinControl; const AParams: TCreateParams); virtual;
destructor Destroy; override; destructor Destroy; override;
@ -133,6 +133,7 @@ type
function windowFlags: QtWindowFlags; function windowFlags: QtWindowFlags;
function windowModality: QtWindowModality; function windowModality: QtWindowModality;
property Context: HDC read FContext;
property Props[AnIndex:String]:pointer read GetProps write SetProps; property Props[AnIndex:String]:pointer read GetProps write SetProps;
property PaintData: TPaintData read FPaintData write FPaintData; property PaintData: TPaintData read FPaintData write FPaintData;
property Widget: QWidgetH read GetWidget write SetWidget; property Widget: QWidgetH read GetWidget write SetWidget;
@ -213,7 +214,6 @@ type
{$endif} {$endif}
MenuBar: TQtMenuBar; MenuBar: TQtMenuBar;
ToolBar: TQtToolBar; ToolBar: TQtToolBar;
Canvas: TQtDeviceContext;
destructor Destroy; override; destructor Destroy; override;
function getClientBounds: TRect; override; function getClientBounds: TRect; override;
procedure setTabOrders; procedure setTabOrders;
@ -1579,7 +1579,6 @@ begin
{$ifdef VerboseQt} {$ifdef VerboseQt}
WriteLn('TQtWidget.SlotPaint'); WriteLn('TQtWidget.SlotPaint');
{$endif} {$endif}
InPaint := True;
if (LCLObject is TWinControl) then if (LCLObject is TWinControl) then
begin begin
FillChar(Msg, SizeOf(Msg), #0); FillChar(Msg, SizeOf(Msg), #0);
@ -1598,6 +1597,7 @@ begin
end; end;
Msg.DC := BeginPaint(THandle(Self), AStruct^); Msg.DC := BeginPaint(THandle(Self), AStruct^);
FContext := Msg.DC;
with getClientBounds do with getClientBounds do
SetWindowOrgEx(Msg.DC, -Left, -Top, nil); SetWindowOrgEx(Msg.DC, -Left, -Top, nil);
@ -1611,6 +1611,7 @@ begin
finally finally
Dispose(PaintData.ClipRect); Dispose(PaintData.ClipRect);
Fillchar(FPaintData, SizeOf(FPaintData), 0); Fillchar(FPaintData, SizeOf(FPaintData), 0);
FContext := 0;
EndPaint(THandle(Self), AStruct^); EndPaint(THandle(Self), AStruct^);
Dispose(AStruct); Dispose(AStruct);
end; end;
@ -1618,7 +1619,6 @@ begin
Application.HandleException(nil); Application.HandleException(nil);
end; end;
end; end;
InPaint := False;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------

View File

@ -105,10 +105,6 @@ begin
New(DC.vClipRect); New(DC.vClipRect);
DC.vClipRect^ := Widget.PaintData.ClipRect^; DC.vClipRect^ := Widget.PaintData.ClipRect^;
end; end;
//DC.DebugClipRect('BeginPaint: After');
// TODO: ask what is this good for
if Widget is TQtMainWindow then
TQtMainWindow(Widget).Canvas := DC;
end; end;
Result := PS.hdc; Result := PS.hdc;
@ -498,12 +494,7 @@ begin
{$ifdef VerboseQtWinAPI} {$ifdef VerboseQtWinAPI}
WriteLn('[WinAPI CreateCompatibleDC] DC: ', dbghex(DC)); WriteLn('[WinAPI CreateCompatibleDC] DC: ', dbghex(DC));
{$endif} {$endif}
{TODO: TEST IT Result := HDC(TQtDeviceContext.Create(nil, True));
if (GetQtDefaultDC <> 0)
and (DC = 0) then
DeleteDefaultDC;
}
Result := GetDC(DC);
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -754,21 +745,7 @@ begin
Result := False; Result := False;
if not IsValidDC(hDC) then exit; if not IsValidDC(hDC) then exit;
TQtDeviceContext(hDC).Free;
Painter := TQtDeviceContext(hDC).Widget;
Result := not QPainter_isActive(Painter);
if not Result then
QPainter_end(Painter);
if Result then
begin
{we should never come here ... endPaint() do the job}
{$ifdef VerboseQtWinAPI}
WriteLn('[WinAPI DeleteDC] freeing resources ');
{$endif}
TQtDeviceContext(hDC).Free;
end;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -854,8 +831,7 @@ begin
and QPaintEngine_isActive(APaintEngine) then and QPaintEngine_isActive(APaintEngine) then
begin begin
APainter := QPaintEngine_painter(APaintEngine); APainter := QPaintEngine_painter(APaintEngine);
if APainter <> NiL if APainter <> nil then
then
QPainter_end(APainter); QPainter_end(APainter);
end ; end ;
@ -1492,6 +1468,8 @@ begin
if Str <> nil then if Str <> nil then
begin begin
WideStr := UTF8Decode(Str); WideStr := UTF8Decode(Str);
if WideStr = '' then
WideStr := Str;
QtDC.drawText(X, Y, @WideStr); QtDC.drawText(X, Y, @WideStr);
end; end;
@ -1918,22 +1896,16 @@ begin
Widget := TQtWidget(hWnd); Widget := TQtWidget(hWnd);
if Widget <> nil then if Widget <> nil then
Result := HDC(TQtDeviceContext.Create(Widget.Widget)) begin
Result := Widget.Context;
if Result = 0 then
Result := HDC(QtDefaultContext);
end
else else
begin begin
{ TODO: Test this ! Result := HDC(QtScreenContext);
if GetQtDefaultDC = 0 then
begin
Result := HDC(TQtDeviceContext.Create(nil));
SetQtDefaultDC(Result);
end else
Result := GetQtDefaultDC;
}
Result := HDC(TQtDeviceContext.Create(nil));
end; end;
// if hWnd <> 0 then TQtCustomForm(hWnd).Canvas := TQtDeviceContext(Result);
{$ifdef VerboseQtWinAPI} {$ifdef VerboseQtWinAPI}
WriteLn('Trace:< [WinAPI GetDC] Result: ', dbghex(Result)); WriteLn('Trace:< [WinAPI GetDC] Result: ', dbghex(Result));
{$endif} {$endif}
@ -1948,14 +1920,8 @@ begin
end; end;
function TQtWidgetSet.GetDesignerDC(WindowHandle: HWND): HDC; function TQtWidgetSet.GetDesignerDC(WindowHandle: HWND): HDC;
var
Widget: TQtWidget;
begin begin
Widget := TQtWidget(WindowHandle); Result := GetDC(WindowHandle);
if Widget <> nil then
Result := HDC(TQtDeviceContext.Create(Widget.Widget, False))
else
Result := HDC(TQtDeviceContext.Create(nil, False));
{$ifdef VerboseQtWinAPI_MISSING_IMPLEMENTATION} {$ifdef VerboseQtWinAPI_MISSING_IMPLEMENTATION}
WriteLn('***** [WinAPI TQtWidgetSet.GetDesignerDC] missing implementation '); WriteLn('***** [WinAPI TQtWidgetSet.GetDesignerDC] missing implementation ');
{$endif} {$endif}
@ -3618,7 +3584,7 @@ begin
Result := 0; Result := 0;
if IsValidDC(DC) then TQtDeviceContext(DC).Free; if IsValidDC(DC) then Exit;
Result := 1; Result := 1;
end; end;
@ -3778,7 +3744,7 @@ begin
if RGN <> 0 then if RGN <> 0 then
QPainter_setClipRegion(Painter, TQtRegion(Rgn).Widget) QPainter_setClipRegion(Painter, TQtRegion(Rgn).Widget)
else else
QPainter_setClipping(Painter, False); QPainter_setClipRegion(Painter, nil, QtNoClip);
if QPainter_hasClipping(Painter) then if QPainter_hasClipping(Painter) then
begin begin
ARegion := QRegion_Create; ARegion := QRegion_Create;

View File

@ -195,3 +195,4 @@ function WindowFromPoint(Point: TPoint): HWND; override;
//##apiwiz##eps## // Do not remove, no wizard declaration after this line //##apiwiz##eps## // Do not remove, no wizard declaration after this line