diff --git a/lcl/interfaces/cocoa/cocoawinapi.inc b/lcl/interfaces/cocoa/cocoawinapi.inc index 1d6747eaf9..1ef905e9f6 100644 --- a/lcl/interfaces/cocoa/cocoawinapi.inc +++ b/lcl/interfaces/cocoa/cocoawinapi.inc @@ -1056,6 +1056,19 @@ begin {$ENDIF} end; +function TCocoaWidgetSet.GetFocus: HWND; +var + Obj: NSObject; +begin + Result := HWND(NSApp.keyWindow); + if Result <> 0 then + begin + Obj := NSWindow(Result).firstResponder; + if Assigned(Obj) and Obj.isKindOfClass(NSView) then + Result := HWND(Obj); + end; +end; + function TCocoaWidgetSet.GetForegroundWindow: HWND; //var // App: NSRunningApplication; @@ -1236,6 +1249,29 @@ begin Result := True; end; +function TCocoaWidgetSet.SetFocus(Handle: HWND): HWND; +var + Obj: NSObject; +begin + if Handle <> 0 then + begin + if Result = Handle then + Exit; + Obj := NSObject(Handle); + if Obj.isKindOfClass(NSWindow) then + begin + NSWindow(Obj).makeKeyWindow; + NSWindow(Obj).makeFirstResponder(nil); + end + else + if Obj.isKindOfClass(NSView) then + begin + NSView(Obj).window.makeKeyWindow; + NSView(Obj).window.makeFirstResponder(NSView(Obj)); + end; + end; +end; + function TCocoaWidgetSet.SetForegroundWindow(HWnd: HWND): boolean; var Obj: NSObject; diff --git a/lcl/interfaces/cocoa/cocoawinapih.inc b/lcl/interfaces/cocoa/cocoawinapih.inc index 4ff2ac5b35..e2f19c2cd2 100644 --- a/lcl/interfaces/cocoa/cocoawinapih.inc +++ b/lcl/interfaces/cocoa/cocoawinapih.inc @@ -103,8 +103,8 @@ function GetDC(hWnd: HWND): HDC; override; {function GetDCOriginRelativeToWindow(PaintDC: HDC; WindowHandle: HWND; var OriginDiff: TPoint): boolean; override; function GetDeviceCaps(DC: HDC; Index: Integer): Integer; override; function GetDeviceSize(DC: HDC; var P: TPoint): Boolean; Override; -function GetDIBits(DC: HDC; Bitmap: HBitmap; StartScan, NumScans: UINT; Bits: Pointer; var BitInfo: BitmapInfo; Usage: UINT): Integer; Override; -function GetFocus: HWND; override;} +function GetDIBits(DC: HDC; Bitmap: HBitmap; StartScan, NumScans: UINT; Bits: Pointer; var BitInfo: BitmapInfo; Usage: UINT): Integer; Override;} +function GetFocus: HWND; override; function GetForegroundWindow: HWND; override; {function GetKeyState(nVirtKey: Integer): Smallint; override;} function GetMonitorInfo(hMonitor: HMONITOR; lpmi: PMonitorInfo): Boolean; override; @@ -172,7 +172,7 @@ function SetCaretPosEx(Handle: HWnd; X, Y: Integer): Boolean; override; function SetCaretRespondToFocus(handle: HWND; ShowHideOnFocus: boolean): Boolean; override;} function SetCursor(ACursor: HCURSOR): HCURSOR; override; function SetCursorPos(X, Y: Integer): Boolean; override; -{function SetFocus(hWnd: HWND): HWND; override;} +function SetFocus(Handle: HWND): HWND; override; function SetForegroundWindow(HWnd: HWND): boolean; override; function SetProp(Handle: hwnd; Str: PChar; Data: Pointer) : Boolean; override; function SetROP2(DC: HDC; Mode: Integer): Integer; override;