From cbfa6091d1bb3829fc19aead655c33329436f98b Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 1 Oct 2012 08:17:52 +0000 Subject: [PATCH] cocoa: (de)allocate PaintStruct dinamically, cleanup git-svn-id: trunk@38933 - --- lcl/interfaces/cocoa/cocoawscommon.pas | 31 +++++++++++--------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoawscommon.pas b/lcl/interfaces/cocoa/cocoawscommon.pas index 7b0dd1c081..a031e7b12f 100644 --- a/lcl/interfaces/cocoa/cocoawscommon.pas +++ b/lcl/interfaces/cocoa/cocoawscommon.pas @@ -101,7 +101,6 @@ const // Utility WS functions -function AllocCustomControl(const AWinControl: TWinControl): TCocoaCustomControl; function EmbedInScrollView(AView: NSView): TCocoaScrollView; implementation @@ -111,14 +110,6 @@ uses {$I mackeycodes.inc} -function AllocCustomControl(const AWinControl: TWinControl): TCocoaCustomControl; -begin - if not Assigned(AWinControl) then - Exit(nil); - Result := TCocoaCustomControl(TCocoaCustomControl.alloc).init; - Result.callback := TLCLCommonCallback.Create(Result, AWinControl); -end; - function EmbedInScrollView(AView: NSView): TCocoaScrollView; var r: TRect; @@ -804,22 +795,26 @@ end; procedure TLCLCommonCallback.Draw(ControlContext: NSGraphicsContext; const bounds, dirty: NSRect); var - struct: TPaintStruct; + PS: PPaintStruct; begin // todo: think more about draw call while previous draw still active if Assigned(FContext) then Exit; - FContext := TCocoaContext.Create; + FContext := TCocoaContext.Create(ControlContext); try - FContext.ctx := ControlContext; if FContext.InitDraw(Round(bounds.size.width), Round(bounds.size.height)) then begin - FillChar(struct, SizeOf(TPaintStruct), 0); - struct.hdc := HDC(FContext); - struct.rcPaint := NSRectToRect(dirty); - LCLSendPaintMsg(Target, HDC(FContext), @struct); - if FHasCaret then - DrawCaret; + New(PS); + try + FillChar(PS^, SizeOf(TPaintStruct), 0); + PS^.hdc := HDC(FContext); + PS^.rcPaint := NSRectToRect(dirty); + LCLSendPaintMsg(Target, HDC(FContext), PS); + if FHasCaret then + DrawCaret; + finally + Dispose(PS); + end; end; finally FreeAndNil(FContext);