2013-12-16 18:54:02 -03:00
|
|
|
// Copyright (c) 2011-2013 The Bitcoin Core developers
|
2014-12-13 01:09:33 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-12-16 18:54:02 -03:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2011-10-07 08:21:45 -03:00
|
|
|
#include "macdockiconhandler.h"
|
|
|
|
|
2012-09-22 06:29:55 -03:00
|
|
|
#include <QMenu>
|
2013-12-16 18:54:02 -03:00
|
|
|
#include <QWidget>
|
2011-10-07 08:21:45 -03:00
|
|
|
|
|
|
|
#undef slots
|
|
|
|
#include <Cocoa/Cocoa.h>
|
2015-03-11 20:08:22 -03:00
|
|
|
#include <objc/objc.h>
|
|
|
|
#include <objc/message.h>
|
2011-10-07 08:21:45 -03:00
|
|
|
|
2017-08-16 12:26:07 -03:00
|
|
|
static MacDockIconHandler *s_instance = nullptr;
|
2011-10-07 08:21:45 -03:00
|
|
|
|
2015-03-11 20:08:22 -03:00
|
|
|
bool dockClickHandler(id self,SEL _cmd,...) {
|
|
|
|
Q_UNUSED(self)
|
|
|
|
Q_UNUSED(_cmd)
|
2018-07-24 11:59:49 -04:00
|
|
|
|
2015-03-11 20:08:22 -03:00
|
|
|
s_instance->handleDockIconClickEvent();
|
2018-07-24 11:59:49 -04:00
|
|
|
|
2015-03-11 20:08:22 -03:00
|
|
|
// Return NO (false) to suppress the default OS X actions
|
|
|
|
return false;
|
2011-10-07 08:21:45 -03:00
|
|
|
}
|
|
|
|
|
2015-03-11 20:08:22 -03:00
|
|
|
void setupDockClickHandler() {
|
|
|
|
Class cls = objc_getClass("NSApplication");
|
|
|
|
id appInst = objc_msgSend((id)cls, sel_registerName("sharedApplication"));
|
2018-07-24 11:59:49 -04:00
|
|
|
|
2017-08-16 12:26:07 -03:00
|
|
|
if (appInst != nullptr) {
|
2015-03-11 20:08:22 -03:00
|
|
|
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@:");
|
2013-04-14 17:11:55 -03:00
|
|
|
}
|
2011-10-07 08:21:45 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MacDockIconHandler::MacDockIconHandler() : QObject()
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
2015-03-11 20:08:22 -03:00
|
|
|
setupDockClickHandler();
|
2011-10-07 08:21:45 -03:00
|
|
|
this->m_dummyWidget = new QWidget();
|
|
|
|
this->m_dockMenu = new QMenu(this->m_dummyWidget);
|
2017-08-16 12:26:07 -03:00
|
|
|
this->setMainWindow(nullptr);
|
2018-06-13 10:02:39 -04:00
|
|
|
#if QT_VERSION >= 0x050200
|
2014-05-29 15:30:46 -04:00
|
|
|
this->m_dockMenu->setAsDockMenu();
|
2013-11-26 21:10:41 -03:00
|
|
|
#endif
|
2011-10-07 08:21:45 -03:00
|
|
|
[pool release];
|
|
|
|
}
|
|
|
|
|
2013-04-14 17:11:55 -03:00
|
|
|
void MacDockIconHandler::setMainWindow(QMainWindow *window) {
|
|
|
|
this->mainWindow = window;
|
|
|
|
}
|
|
|
|
|
2011-10-07 08:21:45 -03:00
|
|
|
MacDockIconHandler::~MacDockIconHandler()
|
|
|
|
{
|
|
|
|
delete this->m_dummyWidget;
|
2017-08-16 12:26:07 -03:00
|
|
|
this->setMainWindow(nullptr);
|
2011-10-07 08:21:45 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
QMenu *MacDockIconHandler::dockMenu()
|
|
|
|
{
|
|
|
|
return this->m_dockMenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
MacDockIconHandler *MacDockIconHandler::instance()
|
|
|
|
{
|
|
|
|
if (!s_instance)
|
|
|
|
s_instance = new MacDockIconHandler();
|
|
|
|
return s_instance;
|
|
|
|
}
|
|
|
|
|
2015-03-13 11:40:53 -03:00
|
|
|
void MacDockIconHandler::cleanup()
|
|
|
|
{
|
|
|
|
delete s_instance;
|
|
|
|
}
|
|
|
|
|
2011-10-07 08:21:45 -03:00
|
|
|
void MacDockIconHandler::handleDockIconClickEvent()
|
|
|
|
{
|
2013-06-04 23:44:53 -04:00
|
|
|
if (this->mainWindow)
|
|
|
|
{
|
|
|
|
this->mainWindow->activateWindow();
|
|
|
|
this->mainWindow->show();
|
|
|
|
}
|
2013-04-14 17:11:55 -03:00
|
|
|
|
2015-07-15 10:09:31 -03:00
|
|
|
Q_EMIT this->dockIconClicked();
|
2011-10-07 08:21:45 -03:00
|
|
|
}
|