cocoa: (de)allocate PaintStruct dinamically, cleanup

git-svn-id: trunk@38933 -
This commit is contained in:
paul 2012-10-01 08:17:52 +00:00
parent d07bc91aef
commit cbfa6091d1

View File

@ -101,7 +101,6 @@ const
// Utility WS functions // Utility WS functions
function AllocCustomControl(const AWinControl: TWinControl): TCocoaCustomControl;
function EmbedInScrollView(AView: NSView): TCocoaScrollView; function EmbedInScrollView(AView: NSView): TCocoaScrollView;
implementation implementation
@ -111,14 +110,6 @@ uses
{$I mackeycodes.inc} {$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; function EmbedInScrollView(AView: NSView): TCocoaScrollView;
var var
r: TRect; r: TRect;
@ -804,22 +795,26 @@ end;
procedure TLCLCommonCallback.Draw(ControlContext: NSGraphicsContext; procedure TLCLCommonCallback.Draw(ControlContext: NSGraphicsContext;
const bounds, dirty: NSRect); const bounds, dirty: NSRect);
var var
struct: TPaintStruct; PS: PPaintStruct;
begin begin
// todo: think more about draw call while previous draw still active // todo: think more about draw call while previous draw still active
if Assigned(FContext) then if Assigned(FContext) then
Exit; Exit;
FContext := TCocoaContext.Create; FContext := TCocoaContext.Create(ControlContext);
try try
FContext.ctx := ControlContext;
if FContext.InitDraw(Round(bounds.size.width), Round(bounds.size.height)) then if FContext.InitDraw(Round(bounds.size.width), Round(bounds.size.height)) then
begin begin
FillChar(struct, SizeOf(TPaintStruct), 0); New(PS);
struct.hdc := HDC(FContext); try
struct.rcPaint := NSRectToRect(dirty); FillChar(PS^, SizeOf(TPaintStruct), 0);
LCLSendPaintMsg(Target, HDC(FContext), @struct); PS^.hdc := HDC(FContext);
if FHasCaret then PS^.rcPaint := NSRectToRect(dirty);
DrawCaret; LCLSendPaintMsg(Target, HDC(FContext), PS);
if FHasCaret then
DrawCaret;
finally
Dispose(PS);
end;
end; end;
finally finally
FreeAndNil(FContext); FreeAndNil(FContext);