mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-31 04:52:35 +02:00
Cocoa: Rework TCocoaWidgetSet.WindowFromPoint so that it works with libraries
git-svn-id: trunk@43817 -
This commit is contained in:
parent
99ba895921
commit
4c5854aba3
@ -84,6 +84,7 @@ type
|
||||
function lclGetPropStorage: TStringList; message 'lclGetPropStorage';
|
||||
function lclGetTarget: TObject; message 'lclGetTarget';
|
||||
function lclDeliverMessage(Msg: Cardinal; WParam: WParam; LParam: LParam): LResult; message 'lclDeliverMessage:::';
|
||||
function lclIsHandle: Boolean; message 'lclIsHandle';
|
||||
end;
|
||||
|
||||
{ LCLViewExtension }
|
||||
@ -176,6 +177,7 @@ type
|
||||
TCocoaMenu = objcclass(NSMenu)
|
||||
public
|
||||
procedure lclItemSelected(sender: id); message 'lclItemSelected:';
|
||||
function lclIsHandle: Boolean; override;
|
||||
end;
|
||||
|
||||
{ TCocoaMenuItem }
|
||||
@ -185,6 +187,7 @@ type
|
||||
menuItemCallback: IMenuItemCallback;
|
||||
procedure lclItemSelected(sender: id); message 'lclItemSelected:';
|
||||
function lclGetCallback: IMenuItemCallback; override;
|
||||
function lclIsHandle: Boolean; override;
|
||||
end;
|
||||
|
||||
{ TCocoaButton }
|
||||
@ -215,6 +218,8 @@ type
|
||||
procedure mouseExited(event: NSEvent); override;
|
||||
procedure mouseMoved(event: NSEvent); override;
|
||||
procedure resetCursorRects; override;
|
||||
function lclIsHandle: Boolean; override;
|
||||
|
||||
end;
|
||||
|
||||
{ TCocoaTextField }
|
||||
@ -227,6 +232,7 @@ type
|
||||
function lclGetCallback: ICommonCallback; override;
|
||||
procedure lclClearCallback; override;
|
||||
procedure resetCursorRects; override;
|
||||
function lclIsHandle: Boolean; override;
|
||||
end;
|
||||
|
||||
{ TCocoaSecureTextField }
|
||||
@ -238,6 +244,7 @@ type
|
||||
function becomeFirstResponder: Boolean; override;
|
||||
function resignFirstResponder: Boolean; override;
|
||||
procedure resetCursorRects; override;
|
||||
function lclIsHandle: Boolean; override;
|
||||
end;
|
||||
|
||||
|
||||
@ -252,6 +259,7 @@ type
|
||||
function lclGetCallback: ICommonCallback; override;
|
||||
procedure lclClearCallback; override;
|
||||
procedure resetCursorRects; override;
|
||||
function lclIsHandle: Boolean; override;
|
||||
end;
|
||||
|
||||
{ TCocoaPanel }
|
||||
@ -284,6 +292,7 @@ type
|
||||
procedure mouseExited(event: NSEvent); override;
|
||||
procedure mouseMoved(event: NSEvent); override;
|
||||
procedure sendEvent(event: NSEvent); override;
|
||||
function lclIsHandle: Boolean; override;
|
||||
end;
|
||||
|
||||
|
||||
@ -315,6 +324,7 @@ type
|
||||
procedure mouseExited(event: NSEvent); override;
|
||||
procedure mouseMoved(event: NSEvent); override;
|
||||
procedure sendEvent(event: NSEvent); override;
|
||||
function lclIsHandle: Boolean; override;
|
||||
end;
|
||||
|
||||
{ TCocoaCustomControl }
|
||||
@ -345,6 +355,7 @@ type
|
||||
procedure flagsChanged(event: NSEvent); override;
|
||||
// other
|
||||
procedure resetCursorRects; override;
|
||||
function lclIsHandle: Boolean; override;
|
||||
end;
|
||||
|
||||
{ TCocoaWindowContent }
|
||||
@ -360,6 +371,7 @@ type
|
||||
procedure viewWillMoveToWindow(newWindow: NSWindow); override;
|
||||
procedure dealloc; override;
|
||||
procedure setHidden(aisHidden: Boolean); override;
|
||||
function lclIsHandle: Boolean; override;
|
||||
end;
|
||||
|
||||
{ TCocoaScrollView }
|
||||
@ -373,6 +385,7 @@ type
|
||||
function lclGetCallback: ICommonCallback; override;
|
||||
procedure lclClearCallback; override;
|
||||
procedure resetCursorRects; override;
|
||||
function lclIsHandle: Boolean; override;
|
||||
end;
|
||||
|
||||
|
||||
@ -417,6 +430,7 @@ type
|
||||
procedure comboBoxWillDismiss(notification: NSNotification); message 'comboBoxWillDismiss:';
|
||||
procedure comboBoxSelectionDidChange(notification: NSNotification); message 'comboBoxSelectionDidChange:';
|
||||
procedure comboBoxSelectionIsChanging(notification: NSNotification); message 'comboBoxSelectionIsChanging:';
|
||||
function lclIsHandle: Boolean; override;
|
||||
end;
|
||||
|
||||
{ TCocoaScrollBar }
|
||||
@ -430,6 +444,7 @@ type
|
||||
function lclGetCallback: ICommonCallback; override;
|
||||
procedure lclClearCallback; override;
|
||||
procedure resetCursorRects; override;
|
||||
function lclIsHandle: Boolean; override;
|
||||
end;
|
||||
|
||||
TCocoaListView = objcclass;
|
||||
@ -485,6 +500,7 @@ type
|
||||
// key
|
||||
procedure keyDown(event: NSEvent); override;
|
||||
procedure keyUp(event: NSEvent); override;
|
||||
function lclIsHandle: Boolean; override;
|
||||
|
||||
end;
|
||||
|
||||
@ -499,6 +515,7 @@ type
|
||||
function lclGetCallback: ICommonCallback; override;
|
||||
procedure lclClearCallback; override;
|
||||
procedure resetCursorRects; override;
|
||||
function lclIsHandle: Boolean; override;
|
||||
end;
|
||||
|
||||
procedure SetViewDefaults(AView: NSView);
|
||||
@ -519,6 +536,11 @@ end;
|
||||
|
||||
{ TCocoaWindowContent }
|
||||
|
||||
function TCocoaWindowContent.lclIsHandle: Boolean;
|
||||
begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
function TCocoaWindowContent.lclOwnWindow: NSWindow;
|
||||
begin
|
||||
if not isembedded then
|
||||
@ -590,6 +612,11 @@ end;
|
||||
|
||||
{ TCocoaPanel }
|
||||
|
||||
function TCocoaPanel.lclIsHandle: Boolean;
|
||||
begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
function TCocoaPanel.windowShouldClose(sender: id): LongBool;
|
||||
var
|
||||
canClose: Boolean;
|
||||
@ -758,6 +785,11 @@ end;
|
||||
|
||||
{ TCocoaWindow }
|
||||
|
||||
function TCocoaWindow.lclIsHandle: Boolean;
|
||||
begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
function TCocoaWindow.windowShouldClose(sender: id): LongBool;
|
||||
var
|
||||
canClose: Boolean;
|
||||
@ -928,6 +960,11 @@ end;
|
||||
|
||||
{ TCocoaScrollView }
|
||||
|
||||
function TCocoaScrollView.lclIsHandle: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TCocoaScrollView.acceptsFirstResponder: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
@ -965,6 +1002,11 @@ end;
|
||||
|
||||
{ TCocoaScrollBar }
|
||||
|
||||
function TCocoaScrollBar.lclIsHandle: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TCocoaScrollBar.acceptsFirstResponder: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
@ -1002,6 +1044,11 @@ end;
|
||||
|
||||
{ TCocoaGroupBox }
|
||||
|
||||
function TCocoaGroupBox.lclIsHandle: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TCocoaGroupBox.acceptsFirstResponder: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
@ -1039,6 +1086,11 @@ end;
|
||||
|
||||
{ TCocoaButton }
|
||||
|
||||
function TCocoaButton.lclIsHandle: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TCocoaButton.actionButtonClick(sender: NSObject);
|
||||
begin
|
||||
// this is the action handler of button
|
||||
@ -1167,6 +1219,11 @@ end;
|
||||
|
||||
{ TCocoaTextField }
|
||||
|
||||
function TCocoaTextField.lclIsHandle: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TCocoaTextField.acceptsFirstResponder: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
@ -1205,6 +1262,11 @@ end;
|
||||
|
||||
{ TCocoaTextView }
|
||||
|
||||
function TCocoaTextView.lclIsHandle: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TCocoaTextView.acceptsFirstResponder: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
@ -1240,6 +1302,11 @@ end;
|
||||
|
||||
{ TCocoaSecureTextField }
|
||||
|
||||
function TCocoaSecureTextField.lclIsHandle: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TCocoaSecureTextField.acceptsFirstResponder: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
@ -1265,6 +1332,11 @@ end;
|
||||
|
||||
{ TCocoaCustomControl }
|
||||
|
||||
function TCocoaCustomControl.lclIsHandle: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TCocoaCustomControl.acceptsFirstResponder: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
@ -1494,6 +1566,11 @@ begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function LCLObjectExtension.lclIsHandle: Boolean;
|
||||
begin
|
||||
result:=false;
|
||||
end;
|
||||
|
||||
{ LCLControlExtension }
|
||||
|
||||
function RectToViewCoord(view: NSView; const r: TRect): NSRect;
|
||||
@ -1665,6 +1742,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
{ LCLWindowExtension }
|
||||
|
||||
function LCLWindowExtension.lclIsVisible: Boolean;
|
||||
@ -1809,6 +1887,11 @@ end;
|
||||
|
||||
{ TCocoaListView }
|
||||
|
||||
function TCocoaListView.lclIsHandle: Boolean;
|
||||
begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
function TCocoaListView.acceptsFirstResponder: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
@ -1977,6 +2060,11 @@ end;
|
||||
|
||||
{ TCocoaComboBox }
|
||||
|
||||
function TCocoaComboBox.lclIsHandle: Boolean;
|
||||
begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
function TCocoaComboBox.acceptsFirstResponder: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
@ -2057,6 +2145,11 @@ end;
|
||||
|
||||
{ TCocoaMenu }
|
||||
|
||||
function TCocoaMenu.lclIsHandle: Boolean;
|
||||
begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
procedure TCocoaMenu.lclItemSelected(sender:id);
|
||||
begin
|
||||
|
||||
@ -2064,6 +2157,11 @@ end;
|
||||
|
||||
{ TCocoaMenuITem }
|
||||
|
||||
function TCocoaMenuItem.lclIsHandle: Boolean;
|
||||
begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
procedure TCocoaMenuItem.lclItemSelected(sender:id);
|
||||
begin
|
||||
menuItemCallback.ItemSelected;
|
||||
|
@ -988,13 +988,10 @@ begin
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.IsWindow(handle: HWND): boolean;
|
||||
var
|
||||
Obj: NSObject;
|
||||
begin
|
||||
if handle <> 0 then
|
||||
begin
|
||||
Obj := NSObject(handle);
|
||||
Result := Obj.isKindOfClass(NSWindow);
|
||||
Result := NSObject(handle).lclIsHandle;
|
||||
end
|
||||
else
|
||||
Result := False;
|
||||
@ -1002,42 +999,67 @@ end;
|
||||
|
||||
function TCocoaWidgetSet.WindowFromPoint(Point: TPoint): HWND;
|
||||
var
|
||||
r: TRect;
|
||||
winrect: TRect;
|
||||
windows: NSArray;
|
||||
subviews: NSArray;
|
||||
contentView: NSView;
|
||||
i, n: integer;
|
||||
obj: NSObject;
|
||||
win: integer;
|
||||
window: NSWindow;
|
||||
|
||||
function ViewFromPoint(view:NSView): HWND;
|
||||
var rect: TRect;
|
||||
p:TPoint;
|
||||
begin
|
||||
Result:=0;
|
||||
if not assigned(view) then
|
||||
exit;
|
||||
if view.lclIsHandle then
|
||||
begin
|
||||
p:=Point;
|
||||
view.lclScreenToLocal(p.X,p.Y);
|
||||
rect:=view.lclClientFrame;
|
||||
if PtInRect(rect, p) then
|
||||
Result:=HWND(view);
|
||||
//debugln('Point:'+DbgS(p)+' Rect:'+DbgS(rect)+' Result:'+dbgS(Result));
|
||||
end
|
||||
//else
|
||||
// debugln('No lcl');
|
||||
end;
|
||||
|
||||
|
||||
function RecurseSubviews(view:NSView):HWND;
|
||||
var sv:integer;
|
||||
begin
|
||||
// first check views subview if there is a embedded view
|
||||
Result:=0;
|
||||
sv:=0;
|
||||
while (Result=0) and (sv<view.subviews.count) do
|
||||
begin
|
||||
Result:=RecurseSubviews(view.subviews.objectAtIndex(sv));
|
||||
inc(sv)
|
||||
end;
|
||||
if Result=0 then
|
||||
Result:=ViewFromPoint(view);
|
||||
end;
|
||||
|
||||
begin
|
||||
Result := 0;
|
||||
if not assigned(NSApp) then
|
||||
Exit;
|
||||
|
||||
windows := NSApp.windows;
|
||||
|
||||
for i := 0 to windows.count - 1 do
|
||||
for win := 0 to windows.count - 1 do
|
||||
begin
|
||||
obj:=windows.objectAtIndex(i);
|
||||
if obj.isKindOfClass(NSWindow) then
|
||||
begin
|
||||
r := NSWindow(obj).lclFrame;
|
||||
if PtInRect(r, Point) then
|
||||
begin
|
||||
//debugln('Point:'+DbgS(point)+' Rect:'+DbgS(r));
|
||||
//todo: Find NSViews
|
||||
{ contentView:=NSWindow(obj).contentView;
|
||||
if assigned(contentView) then
|
||||
begin
|
||||
|
||||
end; }
|
||||
|
||||
Result := HWND(obj);
|
||||
Exit;
|
||||
window:=windows.objectAtIndex(win);
|
||||
winrect := window.lclFrame;
|
||||
if PtInRect(winrect, Point) then
|
||||
begin
|
||||
Result:=RecurseSubviews(window.contentView);
|
||||
if Result<>0 then
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function TCocoaWidgetSet.GetRgnBox(RGN: HRGN; lpRect: PRect): Longint;
|
||||
begin
|
||||
Result := ERROR;
|
||||
|
Loading…
Reference in New Issue
Block a user