Merge pull request #7253 from briankendall/fix_objc_errors

Fixed mac specific compiler errors and cleaned up Objective C code. Closes #7252
This commit is contained in:
sledgehammer999 2017-08-15 21:06:09 +03:00 committed by GitHub
commit e5ea3bd707
8 changed files with 142 additions and 54 deletions

View file

@ -31,8 +31,6 @@
#include "mainwindow.h"
#ifdef Q_OS_MAC
#include <objc/objc.h>
#include <objc/message.h>
#include <QtMacExtras>
#include <QtMac>
#endif
@ -107,6 +105,10 @@
#include "hidabletabwidget.h"
#include "ui_mainwindow.h"
#ifdef Q_OS_MAC
#include "macutilities.h"
#endif
#ifdef Q_OS_MAC
void qt_mac_set_dock_menu(QMenu *menu);
#endif
@ -1294,29 +1296,9 @@ static bool dockClickHandler(id self, SEL cmd, ...)
}
void MainWindow::setupDockClickHandler()
{
Class cls = objc_getClass("NSApplication");
objc_object *appInst = objc_msgSend(reinterpret_cast<objc_object *>(cls), sel_registerName("sharedApplication"));
if (!appInst)
return;
{
dockMainWindowHandle = this;
objc_object* delegate = objc_msgSend(appInst, sel_registerName("delegate"));
Class delClass = reinterpret_cast<Class>(objc_msgSend(delegate, sel_registerName("class")));
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
if (class_getInstanceMethod(delClass, shouldHandle)) {
if (class_replaceMethod(delClass, shouldHandle, reinterpret_cast<IMP>(dockClickHandler), "B@:"))
qDebug("Registered dock click handler (replaced original method)");
else
qWarning("Failed to replace method for dock click handler");
}
else {
if (class_addMethod(delClass, shouldHandle, reinterpret_cast<IMP>(dockClickHandler), "B@:"))
qDebug("Registered dock click handler");
else
qWarning("Failed to register dock click handler");
}
overrideDockClickHandler(dockClickHandler);
}
#endif