mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-28 16:00:59 +02:00
Fix memory leaks on hint windows and popup menu
git-svn-id: trunk@43598 -
This commit is contained in:
parent
ea591448aa
commit
cd6227e4c9
@ -175,8 +175,9 @@ type
|
||||
|
||||
TCocoaMenuItem = objcclass(NSMenuItem)
|
||||
public
|
||||
callback: IMenuItemCallback;
|
||||
menuItemCallback: IMenuItemCallback;
|
||||
procedure lclItemSelected(sender: id); message 'lclItemSelected:';
|
||||
function lclGetCallback: IMenuItemCallback; override;
|
||||
end;
|
||||
|
||||
{ TCocoaButton }
|
||||
@ -1934,7 +1935,12 @@ end;
|
||||
|
||||
procedure TCocoaMenuItem.lclItemSelected(sender:id);
|
||||
begin
|
||||
callback.ItemSelected;
|
||||
menuItemCallback.ItemSelected;
|
||||
end;
|
||||
|
||||
function TCocoaMenuItem.lclGetCallback: IMenuItemCallback;
|
||||
begin
|
||||
result:=menuItemCallback;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -131,6 +131,7 @@ type
|
||||
public
|
||||
published
|
||||
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
||||
class procedure DestroyHandle(const AWinControl: TWinControl); override;
|
||||
end;
|
||||
|
||||
{ TCocoaWSScreen }
|
||||
@ -210,6 +211,33 @@ begin
|
||||
Result := TLCLIntfHandle(cnt);
|
||||
end;
|
||||
|
||||
|
||||
class procedure TCocoaWSHintWindow.DestroyHandle(const AWinControl: TWinControl);
|
||||
var
|
||||
cnt: TCocoaWindowContent;
|
||||
Callback: ICommonCallback;
|
||||
CallbackObject: TObject;
|
||||
begin
|
||||
if not AWinControl.HandleAllocated then
|
||||
Exit;
|
||||
|
||||
cnt:= TCocoaWindowContent(AWinControl.Handle);
|
||||
cnt.removeFromSuperview;
|
||||
|
||||
cnt.ownwin.close;
|
||||
|
||||
Callback := cnt.lclGetCallback;
|
||||
if Assigned(Callback) then
|
||||
begin
|
||||
CallbackObject := Callback.GetCallbackObject;
|
||||
Callback := nil;
|
||||
cnt.lclClearCallback;
|
||||
CallbackObject.Free;
|
||||
end;
|
||||
|
||||
cnt.release;
|
||||
end;
|
||||
|
||||
{ TLCLWindowCallback }
|
||||
|
||||
function TLCLWindowCallback.CanActivate: Boolean;
|
||||
|
@ -170,7 +170,7 @@ begin
|
||||
objcselector('lclItemSelected:'), NSString.alloc.init);
|
||||
ns.release;
|
||||
item.setTarget(item);
|
||||
TCocoaMenuItem(item).callback:=TLCLMenuItemCallback.Create(item, AMenuItem);
|
||||
TCocoaMenuItem(item).menuItemCallback:=TLCLMenuItemCallback.Create(item, AMenuItem);
|
||||
item.setEnabled(AMenuItem.Enabled);
|
||||
end;
|
||||
|
||||
@ -184,8 +184,23 @@ end;
|
||||
Destroys menu item in Cocoa interface
|
||||
------------------------------------------------------------------------------}
|
||||
class procedure TCocoaWSMenuItem.DestroyHandle(const AMenuItem: TMenuItem);
|
||||
var
|
||||
callback: IMenuItemCallback;
|
||||
callbackObject: TObject;
|
||||
item : TCocoaMenuItem;
|
||||
begin
|
||||
|
||||
if AMenuItem.Caption <> '-' then
|
||||
begin
|
||||
item:=TCocoaMenuItem(AMenuItem.Handle);
|
||||
callback := item.lclGetCallback;
|
||||
if Assigned(callback) then
|
||||
begin
|
||||
callbackObject := callback.GetCallbackObject;
|
||||
callback := nil;
|
||||
item.lclClearCallback;
|
||||
callbackObject.Free;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user