7 #include <QImageWriter> 13 #include <Cocoa/Cocoa.h> 14 #include <objc/objc.h> 15 #include <objc/message.h> 17 #if QT_VERSION < 0x050000 34 Class cls = objc_getClass(
"NSApplication");
35 id appInst = objc_msgSend((
id)cls, sel_registerName(
"sharedApplication"));
37 if (appInst != NULL) {
38 id delegate = objc_msgSend(appInst, sel_registerName(
"delegate"));
39 Class delClass = (Class)objc_msgSend(delegate, sel_registerName(
"class"));
40 SEL shouldHandle = sel_registerName(
"applicationShouldHandleReopen:hasVisibleWindows:");
41 if (class_getInstanceMethod(delClass, shouldHandle))
44 class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler,
"B@:");
51 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
57 #if QT_VERSION < 0x050000 59 #elif QT_VERSION >= 0x050200 82 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
85 image = [[NSImage imageNamed:
@"NSApplicationIcon"] retain];
88 QSize
size = icon.actualSize(QSize(128, 128));
89 QPixmap pixmap = icon.pixmap(size);
92 QBuffer notificationBuffer;
93 if (!pixmap.isNull() && notificationBuffer.open(QIODevice::ReadWrite)) {
94 QImageWriter writer(¬ificationBuffer,
"PNG");
95 if (writer.write(pixmap.toImage())) {
96 NSData* macImgData = [NSData dataWithBytes:notificationBuffer.buffer().data()
97 length:notificationBuffer.buffer().size()];
98 image = [[NSImage alloc] initWithData:macImgData];
104 image = [[NSImage imageNamed:
@"NSApplicationIcon"] retain];
108 [NSApp setApplicationIconImage:image];
void setupDockClickHandler()
void qt_mac_set_dock_menu(QMenu *)
Macintosh-specific dock icon handler.
void handleDockIconClickEvent()
void setIcon(const QIcon &icon)
static MacDockIconHandler * instance()
void setMainWindow(QMainWindow *window)
bool dockClickHandler(id self, SEL _cmd,...)
uint8_t const size_t const size