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