Cocoa: remove circle references between CocoaInt and CocoaWSCommon

This commit is contained in:
rich2014 2024-11-10 11:59:31 +08:00
parent e16acf9623
commit 1c81206a45
5 changed files with 32 additions and 20 deletions

View File

@ -82,6 +82,8 @@ type
procedure InputClientInsertText(const utf8: string);
function HandleFrame: NSView;
// properties
property HasCaret: Boolean read GetHasCaret write SetHasCaret;
property IsOpaque: Boolean read GetIsOpaque write SetIsOpaque;

View File

@ -278,7 +278,7 @@ implementation
uses
dl,dynlibs,
CocoaWSCommon, CocoaCaret, CocoaThemes;
CocoaCaret, CocoaThemes;
const
// Lack of documentation, provisional definition

View File

@ -1517,21 +1517,18 @@ end;
function TCocoaWidgetSet.IsWindow(handle: HWND): boolean;
var
cbi : ICommonCallback;
obj : TObject;
cb: ICommonCallback;
begin
if handle <> 0 then
begin
cbi := NSObject(handle).lclGetCallback;
Result := Assigned(cbi);
if not Result then Exit;
Result:= False;
obj := cbi.GetCallbackObject;
Result := (obj is TLCLCommonCallback)
and (HWND(TLCLCommonCallback(obj).HandleFrame)=handle);
end
else
Result := False;
if handle = 0 then
Exit;
cb:= NSObject(handle).lclGetCallback;
if NOT Assigned(cb) then
Exit;
Result:= ( HWND(cb.HandleFrame) = handle );
end;
function TCocoaWidgetSet.WindowFromPoint(Point: TPoint): HWND;

View File

@ -45,6 +45,7 @@ type
_isCocoaOnlyState: Boolean;
_UTF8Character : array [0..7] of TUTF8Char;
_UTF8Charcount : Integer;
_handleFrame: NSView; // HWND and "frame" (rectangle) of the a control
private
procedure send_UTF8KeyPress();
procedure send_CN_CHAR_Message();
@ -60,7 +61,6 @@ type
procedure KeyEvPrepare(Event: NSEvent); virtual;
public
Owner: NSObject;
HandleFrame: NSView; // HWND and "frame" (rectangle) of the a control
BlockCocoaUpDown: Boolean;
BlockCocoaKeyBeep: Boolean;
BlockCocoaMouseMove: Boolean;
@ -113,6 +113,9 @@ type
procedure InputClientInsertText(const utf8: string);
function HandleFrame: NSView;
procedure SetHandleFrame( AHandleFrame: NSView );
property HasCaret: Boolean read GetHasCaret write SetHasCaret;
property Target: TWinControl read FTarget;
property IsOpaque: Boolean read GetIsOpaque write SetIsOpaque;
@ -398,9 +401,9 @@ begin
inherited Create;
Owner := AOwner;
if Assigned(AHandleFrame) then
HandleFrame := AHandleFrame
_handleFrame := AHandleFrame
else if Owner.isKindOfClass(NSView) then
HandleFrame := NSView(AOwner);
_handleFrame := NSView(AOwner);
FTarget := ATarget;
FContext := nil;
FHasCaret := False;
@ -476,7 +479,7 @@ begin
ContextMenuHandled := false;
FillChar(MsgContext, SizeOf(MsgContext), #0);
MsgContext.Msg := LM_CONTEXTMENU;
MsgContext.hWnd := HWND(HandleFrame);
MsgContext.hWnd := HWND(_handleFrame);
MousePos := Event.locationInWindow;
ScreenMousePos(MousePos);
MsgContext.XPos := Round(MousePos.X);
@ -1557,6 +1560,16 @@ begin
end;
function TLCLCommonCallback.HandleFrame: NSView;
begin
Result:= _handleFrame;
end;
procedure TLCLCommonCallback.SetHandleFrame(AHandleFrame: NSView);
begin
_handleFrame:= AHandleFrame;
end;
function TLCLCommonCallback.GetIsOpaque: Boolean;
begin
Result:= FIsOpaque;
@ -2035,7 +2048,7 @@ begin
hs := EmbedInManualScrollHost(sl);
hs.callback := ctrl.callback;
lcl.HandleFrame:=hs;
lcl.SetHandleFrame(hs);
ScrollViewSetBorderStyle(hs, TCustomControl(AWinControl).BorderStyle );

View File

@ -2565,7 +2565,7 @@ begin
Result := 0;
Exit;
end;
cb.HandleFrame := scroll;
cb.SetHandleFrame(scroll);
scroll.callback := list.callback;
scroll.setHasVerticalScroller(true);
scroll.setHasHorizontalScroller(true);