Merge pull request #5880

8b60808 [QT] some mac specifiy cleanup (memory handling, unnecessary code) (Jonas Schnelli)
89e70e9 [QT] fix OSX dock icon window reopening (Jonas Schnelli)
This commit is contained in:
Wladimir J. van der Laan 2015-03-16 13:54:07 +01:00
commit 226f880498
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
3 changed files with 32 additions and 42 deletions

View File

@ -237,7 +237,7 @@ BitcoinGUI::~BitcoinGUI()
trayIcon->hide();
#ifdef Q_OS_MAC
delete appMenuBar;
MacDockIconHandler::instance()->setMainWindow(NULL);
MacDockIconHandler::cleanup();
#endif
delete rpcConsole;

View File

@ -14,12 +14,6 @@ class QMenu;
class QWidget;
QT_END_NAMESPACE
#ifdef __OBJC__
@class DockIconClickEventHandler;
#else
class DockIconClickEventHandler;
#endif
/** Macintosh-specific dock icon handler.
*/
class MacDockIconHandler : public QObject
@ -33,7 +27,7 @@ public:
void setIcon(const QIcon &icon);
void setMainWindow(QMainWindow *window);
static MacDockIconHandler *instance();
static void cleanup();
void handleDockIconClickEvent();
signals:
@ -42,7 +36,6 @@ signals:
private:
MacDockIconHandler();
DockIconClickEventHandler *m_dockIconClickEventHandler;
QWidget *m_dummyWidget;
QMenu *m_dockMenu;
QMainWindow *mainWindow;

View File

@ -11,52 +11,46 @@
#undef slots
#include <Cocoa/Cocoa.h>
#include <objc/objc.h>
#include <objc/message.h>
#if QT_VERSION < 0x050000
extern void qt_mac_set_dock_menu(QMenu *);
#endif
@interface DockIconClickEventHandler : NSObject
{
MacDockIconHandler* dockIconHandler;
static MacDockIconHandler *s_instance = NULL;
bool dockClickHandler(id self,SEL _cmd,...) {
Q_UNUSED(self)
Q_UNUSED(_cmd)
s_instance->handleDockIconClickEvent();
// Return NO (false) to suppress the default OS X actions
return false;
}
@end
void setupDockClickHandler() {
Class cls = objc_getClass("NSApplication");
id appInst = objc_msgSend((id)cls, sel_registerName("sharedApplication"));
@implementation DockIconClickEventHandler
- (id)initWithDockIconHandler:(MacDockIconHandler *)aDockIconHandler
{
self = [super init];
if (self) {
dockIconHandler = aDockIconHandler;
[[NSAppleEventManager sharedAppleEventManager]
setEventHandler:self
andSelector:@selector(handleDockClickEvent:withReplyEvent:)
forEventClass:kCoreEventClass
andEventID:kAEReopenApplication];
}
return self;
}
- (void)handleDockClickEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent
{
Q_UNUSED(event)
Q_UNUSED(replyEvent)
if (dockIconHandler) {
dockIconHandler->handleDockIconClickEvent();
if (appInst != NULL) {
id delegate = objc_msgSend(appInst, sel_registerName("delegate"));
Class delClass = (Class)objc_msgSend(delegate, sel_registerName("class"));
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
if (class_getInstanceMethod(delClass, shouldHandle))
class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:");
else
class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler,"B@:");
}
}
@end
MacDockIconHandler::MacDockIconHandler() : QObject()
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
this->m_dockIconClickEventHandler = [[DockIconClickEventHandler alloc] initWithDockIconHandler:this];
setupDockClickHandler();
this->m_dummyWidget = new QWidget();
this->m_dockMenu = new QMenu(this->m_dummyWidget);
this->setMainWindow(NULL);
@ -74,7 +68,6 @@ void MacDockIconHandler::setMainWindow(QMainWindow *window) {
MacDockIconHandler::~MacDockIconHandler()
{
[this->m_dockIconClickEventHandler release];
delete this->m_dummyWidget;
this->setMainWindow(NULL);
}
@ -119,12 +112,16 @@ void MacDockIconHandler::setIcon(const QIcon &icon)
MacDockIconHandler *MacDockIconHandler::instance()
{
static MacDockIconHandler *s_instance = NULL;
if (!s_instance)
s_instance = new MacDockIconHandler();
return s_instance;
}
void MacDockIconHandler::cleanup()
{
delete s_instance;
}
void MacDockIconHandler::handleDockIconClickEvent()
{
if (this->mainWindow)