49#if QT_CONFIG(sessionmanager)
57#include <qpa/qwindowsysteminterface.h>
63 NSObject <NSApplicationDelegate> *reflectionDelegate;
67+ (instancetype)sharedDelegate
70 static dispatch_once_t onceToken;
71 dispatch_once(&onceToken, ^{
72 shared = [[
self alloc] init];
93 if (reflectionDelegate) {
94 [[NSApplication sharedApplication] setDelegate:reflectionDelegate];
95 [reflectionDelegate release];
97 [[NSNotificationCenter defaultCenter] removeObserver:self];
102- (NSMenu *)applicationDockMenu:(NSApplication *)sender
107 [
self.dockMenu.delegate menuWillOpen:self.dockMenu];
108 return [[
self.dockMenu retain] autorelease];
112- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
114 if ([reflectionDelegate respondsToSelector:_cmd])
115 return [reflectionDelegate applicationShouldTerminate:sender];
121 qCDebug(lcQpaApplication) <<
"No running event loops, terminating now";
122 return NSTerminateNow;
125#if QT_CONFIG(sessionmanager)
131 qCDebug(lcQpaApplication) <<
"Session management canceled application termination";
132 return NSTerminateCancel;
136 if (!QWindowSystemInterface::handleApplicationTermination<QWindowSystemInterface::SynchronousDelivery>()) {
137 qCDebug(lcQpaApplication) <<
"Application termination canceled";
138 return NSTerminateCancel;
145 qCDebug(lcQpaApplication) <<
"Termination accepted, but returning to runloop for exit through main()";
146 return NSTerminateCancel;
149- (
void)applicationWillFinishLaunching:(NSNotification *)notification
167 NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager];
168 [eventManager setEventHandler:self
169 andSelector:@selector(getUrl:withReplyEvent:)
170 forEventClass:kInternetEventClass
171 andEventID:kAEGetURL];
175- (
void)removeAppleEventHandlers
177 NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager];
178 [eventManager removeEventHandlerForEventClass:kInternetEventClass andEventID:kAEGetURL];
186- (
void)applicationDidFinishLaunching:(NSNotification *)aNotification
196 [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
202- (
void)application:(NSApplication *)sender openFiles:(NSArray *)filenames
214 if (
qApp->arguments().contains(qtFileName))
220 if ([reflectionDelegate respondsToSelector:_cmd])
221 [reflectionDelegate application:sender
openFiles:filenames];
225- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
227 if ([reflectionDelegate respondsToSelector:_cmd])
228 return [reflectionDelegate applicationShouldTerminateAfterLastWindowClosed:sender];
233- (
void)applicationDidBecomeActive:(NSNotification *)notification
236 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:QCocoaWindow::s_applicationActivationObserver];
240 if ([reflectionDelegate respondsToSelector:_cmd])
241 [reflectionDelegate applicationDidBecomeActive:notification];
249 [view convertFromScreen:[NSEvent mouseLocation] toWindowPoint:&windowPoint andScreenPoint:&screenPoint];
251 qCInfo(lcQpaMouse) <<
"Application activated with mouse at" << windowPoint <<
"; sending" <<
QEvent::Enter <<
"to" << windowUnderMouse;
256- (
void)applicationDidResignActive:(NSNotification *)notification
258 if ([reflectionDelegate respondsToSelector:_cmd])
259 [reflectionDelegate applicationDidResignActive:notification];
265 qCInfo(lcQpaMouse) <<
"Application deactivated; sending" <<
QEvent::Leave <<
"to" << windowUnderMouse;
270- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
272 if ([reflectionDelegate respondsToSelector:_cmd])
273 return [reflectionDelegate applicationShouldHandleReopen:theApplication hasVisibleWindows:flag];
287- (
void)setReflectionDelegate:(NSObject <NSApplicationDelegate> *)oldDelegate
289 [oldDelegate retain];
290 [reflectionDelegate release];
291 reflectionDelegate = oldDelegate;
294- (NSMethodSignature *)methodSignatureForSelector:(
SEL)aSelector
296 NSMethodSignature *
result = [
super methodSignatureForSelector:aSelector];
297 if (!
result && reflectionDelegate) {
298 result = [reflectionDelegate methodSignatureForSelector:aSelector];
303- (BOOL)respondsToSelector:(
SEL)aSelector
305 return [
super respondsToSelector:aSelector] || [reflectionDelegate respondsToSelector:aSelector];
308- (
void)forwardInvocation:(NSInvocation *)invocation
310 SEL invocationSelector = [invocation selector];
311 if ([reflectionDelegate respondsToSelector:invocationSelector])
312 [invocation invokeWithTarget:reflectionDelegate];
314 [
self doesNotRecognizeSelector:invocationSelector];
317- (
void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
320 NSString *urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
326 const QString qurlString = QString::fromNSString(urlString);
334@implementation QCocoaApplicationDelegate (Menus)
336- (BOOL)validateMenuItem:(NSMenuItem*)item
338 qCDebug(lcQpaMenus) <<
"Validating" <<
item <<
"for" << self;
340 auto *nativeItem = qt_objc_cast<QCocoaNSMenuItem *>(
item);
344 auto *platformItem = nativeItem.platformMenuItem;
346 return item.hasSubmenu || (
item.enabled && (
item.action !=
@selector(qt_itemFired:)));
349 if (platformItem->menu())
357@implementation QCocoaApplicationDelegate (MenuAPI)
366 auto *nativeItem = qt_objc_cast<QCocoaNSMenuItem *>(
item);
367 Q_ASSERT_X(nativeItem,
qPrintable(__FUNCTION__),
"Triggered menu item is not a QCocoaNSMenuItem.");
368 auto *platformItem = nativeItem.platformMenuItem;
371 if (!platformItem || platformItem->menu())
static QCocoaSessionManager * instance()
static QPointer< QCocoaWindow > s_windowUnderMouse
static id s_applicationActivationObserver
bool isEnabled() const
Returns true if the item is enabled; otherwise, false is returned.
static Qt::KeyboardModifiers modifier_buttons
static QGuiApplicationPrivate * instance()
\inmodule QtCore\reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isValid() const
Returns true if the URL is non-empty and valid; otherwise returns false.
static void handleLeaveEvent(QWindow *window)
static void handleFileOpenEvent(const QString &fileName)
static void handleApplicationStateChanged(Qt::ApplicationState newState, bool forcePropagate=false)
static void handleEnterEvent(QWindow *window, const QPointF &local=QPointF(), const QPointF &global=QPointF())
void openFiles(const std::string &accept, FileSelectMode fileSelectMode, const std::function< void(int fileCount)> &fileDialogClosed, const std::function< char *(uint64_t size, const std::string &name)> &acceptFile, const std::function< void()> &fileDataReady)
QNSView * qnsview_cast(NSView *view)
Returns the view cast to a QNSview if possible.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
#define qCInfo(category,...)
#define qCDebug(category,...)
#define Q_ASSERT_X(cond, x, msg)
#define qPrintable(string)
Q_CORE_EXPORT bool qEnvironmentVariableIsEmpty(const char *varName) noexcept
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
QUrl url("example.com")
[constructor-url-reference]