mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 02:59:15 +02:00
(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:
parent
010ccd79e7
commit
abbd39ddec
@ -412,7 +412,7 @@ procedure TEmulatedCaret.UpdateCaret;
|
||||
var
|
||||
R: TRect;
|
||||
begin
|
||||
if (FWidget <> nil) and not FWidget.InPaint then
|
||||
if (FWidget <> nil) and not (FWidget.Context <> 0) then
|
||||
begin
|
||||
R.Left := FPos.x;
|
||||
R.Top := FPos.y;
|
||||
|
@ -26,7 +26,7 @@ constructor TQtWidgetSet.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
|
||||
InitStockItems;
|
||||
InitStockItems;
|
||||
|
||||
QtWidgetSet := Self;
|
||||
end;
|
||||
@ -42,14 +42,16 @@ destructor TQtWidgetSet.Destroy;
|
||||
begin
|
||||
DestroyGlobalCaret;
|
||||
Clipboard.Free;
|
||||
|
||||
FreeStockItems;
|
||||
FreeStockItems;
|
||||
|
||||
QtWidgetSet := nil;
|
||||
|
||||
if SavedDCList<>nil then
|
||||
SavedDCList.Free;
|
||||
|
||||
QtDefaultContext.Free;
|
||||
QtScreenContext.Free;
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
@ -234,7 +236,7 @@ begin
|
||||
Painter :=TQtDeviceContext(CanvasHandle).Widget;
|
||||
Pen := QPainter_pen(Painter);
|
||||
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_drawPoint(Painter, X,Y);
|
||||
QPainter_setPen(Painter, @ASavedColor);
|
||||
|
@ -391,6 +391,9 @@ type
|
||||
procedure DebugRegion(const msg: string; Rgn: QRegionH);
|
||||
function Clipboard: TQtClipboard;
|
||||
|
||||
function QtDefaultContext: TQtDeviceContext;
|
||||
function QtScreenContext: TQtDeviceContext;
|
||||
|
||||
implementation
|
||||
const
|
||||
ClipbBoardTypeToQtClipboard: array[TClipboardType] of QClipboardMode =
|
||||
@ -402,6 +405,22 @@ const
|
||||
|
||||
var
|
||||
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 }
|
||||
|
||||
@ -709,7 +728,8 @@ end;
|
||||
|
||||
procedure TQtFont.setPointSize(p1: Integer);
|
||||
begin
|
||||
QFont_setPointSize(Widget, p1);
|
||||
if p1 > 0 then
|
||||
QFont_setPointSize(Widget, p1);
|
||||
end;
|
||||
|
||||
function TQtFont.pixelSize: Integer;
|
||||
@ -719,7 +739,8 @@ end;
|
||||
|
||||
procedure TQtFont.setPixelSize(p1: Integer);
|
||||
begin
|
||||
QFont_setPixelSize(Widget, p1);
|
||||
if p1 > 0 then
|
||||
QFont_setPixelSize(Widget, p1);
|
||||
end;
|
||||
|
||||
function TQtFont.weight: Integer;
|
||||
@ -1105,8 +1126,8 @@ begin
|
||||
|
||||
if Parent <> nil then
|
||||
begin
|
||||
vFont := TQtFont.Create(False);
|
||||
vFont.Owner := Self;
|
||||
vFont := TQtFont.Create(False);
|
||||
vFont.Owner := Self;
|
||||
|
||||
vBrush := TQtBrush.Create(False);
|
||||
vBrush.Owner := Self;
|
||||
@ -1117,8 +1138,8 @@ begin
|
||||
vRegion := TQtRegion.Create(False);
|
||||
vRegion.Owner := Self;
|
||||
|
||||
vBackgroundBrush := TQtBrush.Create(False);
|
||||
vBackgroundBrush.Owner := Self;
|
||||
vBackgroundBrush := TQtBrush.Create(False);
|
||||
vBackgroundBrush.Owner := Self;
|
||||
|
||||
end else
|
||||
begin
|
||||
@ -1150,26 +1171,23 @@ begin
|
||||
|
||||
|
||||
if Parent <> nil then
|
||||
begin
|
||||
|
||||
vFont.Widget := nil;
|
||||
vFont.Free;
|
||||
begin
|
||||
vFont.Widget := nil;
|
||||
vFont.Free;
|
||||
vBrush.Widget := nil;
|
||||
vBrush.Free;
|
||||
vPen.Widget := nil;
|
||||
vPen.Free;
|
||||
vRegion.Widget := nil;
|
||||
vRegion.Free;
|
||||
vBackgroundBrush.Widget := nil;
|
||||
vBackgroundBrush.Free;
|
||||
|
||||
vBackgroundBrush.Widget := nil;
|
||||
vBackgroundBrush.Free;
|
||||
end;
|
||||
|
||||
if vImage <> nil then
|
||||
QImage_destroy(vImage);
|
||||
|
||||
if Widget <> nil then
|
||||
begin
|
||||
QPainter_destroy(Widget);
|
||||
end;
|
||||
|
||||
if ParentPixmap <> nil then
|
||||
QPixmap_destroy(ParentPixmap);
|
||||
@ -2189,3 +2207,4 @@ end;
|
||||
|
||||
end.
|
||||
|
||||
|
||||
|
@ -53,6 +53,7 @@ type
|
||||
FPaintData: TPaintData;
|
||||
FCentralWidget: QWidgetH;
|
||||
FStopMouseEventsProcessing: Boolean; // widget stop processing of mouse events
|
||||
FContext: HDC;
|
||||
|
||||
function GetProps(const AnIndex: String): pointer;
|
||||
function GetWidget: QWidgetH;
|
||||
@ -70,7 +71,6 @@ type
|
||||
AVariant: QVariantH;
|
||||
LCLObject: TWinControl;
|
||||
HasCaret: Boolean;
|
||||
InPaint: Boolean;
|
||||
public
|
||||
constructor Create(const AWinControl: TWinControl; const AParams: TCreateParams); virtual;
|
||||
destructor Destroy; override;
|
||||
@ -133,6 +133,7 @@ type
|
||||
function windowFlags: QtWindowFlags;
|
||||
function windowModality: QtWindowModality;
|
||||
|
||||
property Context: HDC read FContext;
|
||||
property Props[AnIndex:String]:pointer read GetProps write SetProps;
|
||||
property PaintData: TPaintData read FPaintData write FPaintData;
|
||||
property Widget: QWidgetH read GetWidget write SetWidget;
|
||||
@ -213,7 +214,6 @@ type
|
||||
{$endif}
|
||||
MenuBar: TQtMenuBar;
|
||||
ToolBar: TQtToolBar;
|
||||
Canvas: TQtDeviceContext;
|
||||
destructor Destroy; override;
|
||||
function getClientBounds: TRect; override;
|
||||
procedure setTabOrders;
|
||||
@ -1579,7 +1579,6 @@ begin
|
||||
{$ifdef VerboseQt}
|
||||
WriteLn('TQtWidget.SlotPaint');
|
||||
{$endif}
|
||||
InPaint := True;
|
||||
if (LCLObject is TWinControl) then
|
||||
begin
|
||||
FillChar(Msg, SizeOf(Msg), #0);
|
||||
@ -1598,6 +1597,7 @@ begin
|
||||
end;
|
||||
|
||||
Msg.DC := BeginPaint(THandle(Self), AStruct^);
|
||||
FContext := Msg.DC;
|
||||
with getClientBounds do
|
||||
SetWindowOrgEx(Msg.DC, -Left, -Top, nil);
|
||||
|
||||
@ -1611,6 +1611,7 @@ begin
|
||||
finally
|
||||
Dispose(PaintData.ClipRect);
|
||||
Fillchar(FPaintData, SizeOf(FPaintData), 0);
|
||||
FContext := 0;
|
||||
EndPaint(THandle(Self), AStruct^);
|
||||
Dispose(AStruct);
|
||||
end;
|
||||
@ -1618,7 +1619,6 @@ begin
|
||||
Application.HandleException(nil);
|
||||
end;
|
||||
end;
|
||||
InPaint := False;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
@ -105,10 +105,6 @@ begin
|
||||
New(DC.vClipRect);
|
||||
DC.vClipRect^ := Widget.PaintData.ClipRect^;
|
||||
end;
|
||||
//DC.DebugClipRect('BeginPaint: After');
|
||||
// TODO: ask what is this good for
|
||||
if Widget is TQtMainWindow then
|
||||
TQtMainWindow(Widget).Canvas := DC;
|
||||
end;
|
||||
|
||||
Result := PS.hdc;
|
||||
@ -498,12 +494,7 @@ begin
|
||||
{$ifdef VerboseQtWinAPI}
|
||||
WriteLn('[WinAPI CreateCompatibleDC] DC: ', dbghex(DC));
|
||||
{$endif}
|
||||
{TODO: TEST IT
|
||||
if (GetQtDefaultDC <> 0)
|
||||
and (DC = 0) then
|
||||
DeleteDefaultDC;
|
||||
}
|
||||
Result := GetDC(DC);
|
||||
Result := HDC(TQtDeviceContext.Create(nil, True));
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -754,21 +745,7 @@ begin
|
||||
Result := False;
|
||||
if not IsValidDC(hDC) then exit;
|
||||
|
||||
|
||||
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;
|
||||
TQtDeviceContext(hDC).Free;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -854,8 +831,7 @@ begin
|
||||
and QPaintEngine_isActive(APaintEngine) then
|
||||
begin
|
||||
APainter := QPaintEngine_painter(APaintEngine);
|
||||
if APainter <> NiL
|
||||
then
|
||||
if APainter <> nil then
|
||||
QPainter_end(APainter);
|
||||
end ;
|
||||
|
||||
@ -1492,6 +1468,8 @@ begin
|
||||
if Str <> nil then
|
||||
begin
|
||||
WideStr := UTF8Decode(Str);
|
||||
if WideStr = '' then
|
||||
WideStr := Str;
|
||||
|
||||
QtDC.drawText(X, Y, @WideStr);
|
||||
end;
|
||||
@ -1918,22 +1896,16 @@ begin
|
||||
Widget := TQtWidget(hWnd);
|
||||
|
||||
if Widget <> nil then
|
||||
Result := HDC(TQtDeviceContext.Create(Widget.Widget))
|
||||
begin
|
||||
Result := Widget.Context;
|
||||
if Result = 0 then
|
||||
Result := HDC(QtDefaultContext);
|
||||
end
|
||||
else
|
||||
begin
|
||||
{ TODO: Test this !
|
||||
if GetQtDefaultDC = 0 then
|
||||
begin
|
||||
Result := HDC(TQtDeviceContext.Create(nil));
|
||||
SetQtDefaultDC(Result);
|
||||
end else
|
||||
Result := GetQtDefaultDC;
|
||||
}
|
||||
Result := HDC(TQtDeviceContext.Create(nil));
|
||||
Result := HDC(QtScreenContext);
|
||||
end;
|
||||
|
||||
// if hWnd <> 0 then TQtCustomForm(hWnd).Canvas := TQtDeviceContext(Result);
|
||||
|
||||
{$ifdef VerboseQtWinAPI}
|
||||
WriteLn('Trace:< [WinAPI GetDC] Result: ', dbghex(Result));
|
||||
{$endif}
|
||||
@ -1948,14 +1920,8 @@ begin
|
||||
end;
|
||||
|
||||
function TQtWidgetSet.GetDesignerDC(WindowHandle: HWND): HDC;
|
||||
var
|
||||
Widget: TQtWidget;
|
||||
begin
|
||||
Widget := TQtWidget(WindowHandle);
|
||||
if Widget <> nil then
|
||||
Result := HDC(TQtDeviceContext.Create(Widget.Widget, False))
|
||||
else
|
||||
Result := HDC(TQtDeviceContext.Create(nil, False));
|
||||
Result := GetDC(WindowHandle);
|
||||
{$ifdef VerboseQtWinAPI_MISSING_IMPLEMENTATION}
|
||||
WriteLn('***** [WinAPI TQtWidgetSet.GetDesignerDC] missing implementation ');
|
||||
{$endif}
|
||||
@ -3618,7 +3584,7 @@ begin
|
||||
|
||||
Result := 0;
|
||||
|
||||
if IsValidDC(DC) then TQtDeviceContext(DC).Free;
|
||||
if IsValidDC(DC) then Exit;
|
||||
|
||||
Result := 1;
|
||||
end;
|
||||
@ -3778,7 +3744,7 @@ begin
|
||||
if RGN <> 0 then
|
||||
QPainter_setClipRegion(Painter, TQtRegion(Rgn).Widget)
|
||||
else
|
||||
QPainter_setClipping(Painter, False);
|
||||
QPainter_setClipRegion(Painter, nil, QtNoClip);
|
||||
if QPainter_hasClipping(Painter) then
|
||||
begin
|
||||
ARegion := QRegion_Create;
|
||||
|
@ -195,3 +195,4 @@ function WindowFromPoint(Point: TPoint): HWND; override;
|
||||
//##apiwiz##eps## // Do not remove, no wizard declaration after this line
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user