macOS: Add qnswindow_cast helper function

Change-Id: If4394e4fbee271c926c0c1c32de1f9783319d994
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit ba2d109c5f091cf5307a15b096da56f50ad44412)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2023-03-14 14:08:42 +01:00 committed by Qt Cherry-pick Bot
parent 88dd567930
commit 1d84c2d479
3 changed files with 12 additions and 3 deletions

View File

@ -36,6 +36,8 @@ QT_FORWARD_DECLARE_CLASS(QCocoaWindow)
typedef NSWindow<QNSWindowProtocol> QCocoaNSWindow;
QCocoaNSWindow *qnswindow_cast(NSWindow *window);
#else
class QCocoaNSWindow;
#endif // __OBJC__

View File

@ -58,6 +58,15 @@ static bool isMouseEvent(NSEvent *ev)
}
@end
NSWindow<QNSWindowProtocol> *qnswindow_cast(NSWindow *window)
{
if ([window conformsToProtocol:@protocol(QNSWindowProtocol)])
return static_cast<QCocoaNSWindow *>(window);
else
return nil;
}
@implementation QNSWindow
#define QNSWINDOW_PROTOCOL_IMPLMENTATION 1
#include "qnswindow.mm"

View File

@ -23,9 +23,7 @@ static inline bool isWhiteSpace(const QString &s)
static QCocoaWindow *toPlatformWindow(NSWindow *window)
{
if ([window conformsToProtocol:@protocol(QNSWindowProtocol)])
return static_cast<QCocoaNSWindow *>(window).platformWindow;
return nullptr;
return qnswindow_cast(window).platformWindow;
}
@implementation QNSWindowDelegate