src/gui/kernel/qt_cocoa_helpers_mac.mm
changeset 30 5dc02b23752f
parent 23 89e065397ea6
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
    81 #include <qpixmapcache.h>
    81 #include <qpixmapcache.h>
    82 #include <private/qevent_p.h>
    82 #include <private/qevent_p.h>
    83 #include <private/qt_cocoa_helpers_mac_p.h>
    83 #include <private/qt_cocoa_helpers_mac_p.h>
    84 #include <private/qt_mac_p.h>
    84 #include <private/qt_mac_p.h>
    85 #include <private/qapplication_p.h>
    85 #include <private/qapplication_p.h>
       
    86 #include <private/qcocoaapplication_mac_p.h>
    86 #include <private/qcocoawindow_mac_p.h>
    87 #include <private/qcocoawindow_mac_p.h>
    87 #include <private/qcocoaview_mac_p.h>
    88 #include <private/qcocoaview_mac_p.h>
    88 #include <private/qkeymapper_p.h>
    89 #include <private/qkeymapper_p.h>
    89 #include <private/qwidget_p.h>
    90 #include <private/qwidget_p.h>
    90 
    91 
   135     m_duration = 0.250;
   136     m_duration = 0.250;
   136     m_windowsToFade.clear();
   137     m_windowsToFade.clear();
   137 }
   138 }
   138 
   139 
   139 extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); // qapplication.cpp;
   140 extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); // qapplication.cpp;
   140 extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm
       
   141 extern QWidget * mac_mouse_grabber;
   141 extern QWidget * mac_mouse_grabber;
   142 extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
   142 extern QWidget *qt_button_down; //qapplication_mac.cpp
   143 
   143 
   144 void macWindowFade(void * /*OSWindowRef*/ window, float durationSeconds)
   144 void macWindowFade(void * /*OSWindowRef*/ window, float durationSeconds)
   145 {
   145 {
   146 #ifdef QT_MAC_USE_COCOA
   146 #ifdef QT_MAC_USE_COCOA
   147     QMacCocoaAutoReleasePool pool;
   147     QMacCocoaAutoReleasePool pool;
   367 {
   367 {
   368     return tablet_hash();
   368     return tablet_hash();
   369 }
   369 }
   370 
   370 
   371 #ifdef QT_MAC_USE_COCOA
   371 #ifdef QT_MAC_USE_COCOA
       
   372 
       
   373 // Clears the QWidget pointer that each QCocoaView holds.
       
   374 void qt_mac_clearCocoaViewQWidgetPointers(QWidget *widget)
       
   375 {
       
   376     QT_MANGLE_NAMESPACE(QCocoaView) *cocoaView = reinterpret_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(qt_mac_nativeview_for(widget));
       
   377     if (cocoaView && [cocoaView respondsToSelector:@selector(qt_qwidget)]) {
       
   378         [cocoaView qt_clearQWidget];
       
   379     }
       
   380 }
       
   381 
   372 void qt_dispatchTabletProximityEvent(void * /*NSEvent * */ tabletEvent)
   382 void qt_dispatchTabletProximityEvent(void * /*NSEvent * */ tabletEvent)
   373 {
   383 {
   374     NSEvent *proximityEvent = static_cast<NSEvent *>(tabletEvent);
   384     NSEvent *proximityEvent = static_cast<NSEvent *>(tabletEvent);
   375     // simply construct a Carbon proximity record and handle it all in one spot.
   385     // simply construct a Carbon proximity record and handle it all in one spot.
   376     TabletProximityRec carbonProximityRec = { [proximityEvent vendorID],
   386     TabletProximityRec carbonProximityRec = { [proximityEvent vendorID],
   640         text = QCFString::toQString(reinterpret_cast<CFStringRef>(keyChars));
   650         text = QCFString::toQString(reinterpret_cast<CFStringRef>(keyChars));
   641 
   651 
   642     UInt32 macScanCode = 1;
   652     UInt32 macScanCode = 1;
   643     QKeyEventEx ke(cocoaEvent2QtEvent([event type]), qtKey, keyMods, text, [event isARepeat], qMax(1, keyLength),
   653     QKeyEventEx ke(cocoaEvent2QtEvent([event type]), qtKey, keyMods, text, [event isARepeat], qMax(1, keyLength),
   644                    macScanCode, [event keyCode], [event modifierFlags]);
   654                    macScanCode, [event keyCode], [event modifierFlags]);
   645     qt_sendSpontaneousEvent(widgetToGetEvent, &ke);
   655     return qt_sendSpontaneousEvent(widgetToGetEvent, &ke) && ke.isAccepted();
   646     return ke.isAccepted();
   656 }
   647 }
   657 #endif
   648 #endif
   658 
       
   659 Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum)
       
   660 {
       
   661     if (buttonNum == 0)
       
   662         return Qt::LeftButton;
       
   663     if (buttonNum == 1)
       
   664         return Qt::RightButton;
       
   665     if (buttonNum == 2)
       
   666         return Qt::MidButton;
       
   667     if (buttonNum == 3)
       
   668         return Qt::XButton1;
       
   669     if (buttonNum == 4)
       
   670         return Qt::XButton2;
       
   671     return Qt::NoButton;
       
   672 }
   649 
   673 
   650 // Helper to share code between QCocoaWindow and QCocoaView
   674 // Helper to share code between QCocoaWindow and QCocoaView
   651 bool qt_dispatchKeyEvent(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEvent)
   675 bool qt_dispatchKeyEvent(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEvent)
   652 {
   676 {
   653 #ifndef QT_MAC_USE_COCOA
   677 #ifndef QT_MAC_USE_COCOA
   657 #else
   681 #else
   658     NSEvent *event = static_cast<NSEvent *>(keyEvent);
   682     NSEvent *event = static_cast<NSEvent *>(keyEvent);
   659     EventRef key_event = static_cast<EventRef>(const_cast<void *>([event eventRef]));
   683     EventRef key_event = static_cast<EventRef>(const_cast<void *>([event eventRef]));
   660     Q_ASSERT(key_event);
   684     Q_ASSERT(key_event);
   661     if ([event type] == NSKeyDown) {
   685     if ([event type] == NSKeyDown) {
   662         qt_keymapper_private()->updateKeyMap(0, key_event, 0);
   686         NSString *characters = [event characters];
   663     }
   687         unichar value = [characters characterAtIndex:0];
       
   688         qt_keymapper_private()->updateKeyMap(0, key_event, (void *)&value);
       
   689     }
       
   690 
       
   691     // Redirect keys to alien widgets.
       
   692     if (widgetToGetEvent->testAttribute(Qt::WA_NativeWindow) == false) {
       
   693         widgetToGetEvent = qApp->focusWidget();
       
   694     }
       
   695 
   664     if (widgetToGetEvent == 0)
   696     if (widgetToGetEvent == 0)
   665         return false;
   697         return false;
   666 
   698 
   667     if (qt_mac_sendMacEventToWidget(widgetToGetEvent, key_event))
   699     if (qt_mac_sendMacEventToWidget(widgetToGetEvent, key_event))
   668         return true;
   700         return true;
   669 
   701 
   670     if (mustUseCocoaKeyEvent())
   702     if (mustUseCocoaKeyEvent())
   671         return qt_dispatchKeyEventWithCocoa(keyEvent, widgetToGetEvent);
   703         return qt_dispatchKeyEventWithCocoa(keyEvent, widgetToGetEvent);
   672     bool isAccepted;
   704     bool isAccepted;
   673     qt_keymapper_private()->translateKeyEvent(widgetToGetEvent, 0, key_event, &isAccepted, true);
   705     bool consumed = qt_keymapper_private()->translateKeyEvent(widgetToGetEvent, 0, key_event, &isAccepted, true);
   674     return isAccepted;
   706     return consumed && isAccepted;
   675 #endif
   707 #endif
   676 }
   708 }
   677 
   709 
   678 void qt_dispatchModifiersChanged(void * /*NSEvent * */flagsChangedEvent, QWidget *widgetToGetEvent)
   710 void qt_dispatchModifiersChanged(void * /*NSEvent * */flagsChangedEvent, QWidget *widgetToGetEvent)
   679 {
   711 {
   848             button = Qt::RightButton;
   880             button = Qt::RightButton;
   849             leftButtonIsRightButton = false;
   881             leftButtonIsRightButton = false;
   850         }
   882         }
   851     }
   883     }
   852 
   884 
   853     QMouseEvent qme(eventType, qlocalPoint, qglobalPoint, button, button, keyMods);
   885     Qt::MouseButtons buttons = 0;
       
   886     {
       
   887         UInt32 mac_buttons;
       
   888         if (GetEventParameter((EventRef)[event eventRef], kEventParamMouseChord, typeUInt32, 0,
       
   889                               sizeof(mac_buttons), 0, &mac_buttons) == noErr)
       
   890             buttons = qt_mac_get_buttons(mac_buttons);
       
   891     }
       
   892 
       
   893     QMouseEvent qme(eventType, qlocalPoint, qglobalPoint, button, buttons, keyMods);
   854     qt_sendSpontaneousEvent(widgetToGetEvent, &qme);
   894     qt_sendSpontaneousEvent(widgetToGetEvent, &qme);
   855 
   895 
   856     // We don't need to set the implicit grab widget here because we won't
   896     // We don't need to set the implicit grab widget here because we won't
   857     // reach this point if then event type is Press over a Qt widget.
   897     // reach this point if then event type is Press over a Qt widget.
   858     // However we might need to unset it if the event is Release.
   898     // However we might need to unset it if the event is Release.
   913                 return false;
   953                 return false;
   914             widgetToGetMouse =
   954             widgetToGetMouse =
   915                 [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(tmpView) qt_qwidget];
   955                 [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(tmpView) qt_qwidget];
   916         }
   956         }
   917     } else {
   957     } else {
   918         extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
   958         extern QWidget * qt_button_down; //qapplication_mac.cpp
   919         QPoint pos;
   959         QPoint pos;
   920         widgetToGetMouse = QApplicationPrivate::pickMouseReceiver(qwidget, qglobalPoint,
   960         widgetToGetMouse = QApplicationPrivate::pickMouseReceiver(qwidget, qglobalPoint,
   921                                                                   pos, eventType,
   961                                                                   pos, eventType,
   922                                                                   button, qt_button_down, 0);
   962                                                                   button, qt_button_down, 0);
   923         if (widgetToGetMouse)
   963         if (widgetToGetMouse)
   925     }
   965     }
   926     if (!widgetToGetMouse)
   966     if (!widgetToGetMouse)
   927         return false;
   967         return false;
   928 
   968 
   929     NSPoint localPoint = [tmpView convertPoint:windowPoint fromView:nil];
   969     NSPoint localPoint = [tmpView convertPoint:windowPoint fromView:nil];
   930     QPoint qlocalPoint(localPoint.x, localPoint.y);
   970     QPoint qlocalPoint = QPoint(localPoint.x, localPoint.y);
       
   971 
       
   972     // Search for alien child widgets (either on this qwidget or on the popup)
       
   973     if (widgetToGetMouse->testAttribute(Qt::WA_NativeWindow) == false || qt_widget_private(widgetToGetMouse)->hasAlienChildren) {
       
   974         QPoint qScreenPoint = flipPoint(globalPoint).toPoint();
       
   975 #ifdef ALIEN_DEBUG
       
   976         qDebug() << "alien mouse event" << qScreenPoint << possibleAlien;
       
   977 #endif
       
   978         QWidget *possibleAlien =  widgetToGetMouse->childAt(qlocalPoint);
       
   979         if (possibleAlien) {
       
   980             qlocalPoint = possibleAlien->mapFromGlobal(widgetToGetMouse->mapToGlobal(qlocalPoint));
       
   981             widgetToGetMouse = possibleAlien;
       
   982         }
       
   983     }
   931 
   984 
   932     EventRef carbonEvent = static_cast<EventRef>(const_cast<void *>([theEvent eventRef]));
   985     EventRef carbonEvent = static_cast<EventRef>(const_cast<void *>([theEvent eventRef]));
   933     if (qt_mac_sendMacEventToWidget(widgetToGetMouse, carbonEvent))
   986     if (qt_mac_sendMacEventToWidget(widgetToGetMouse, carbonEvent))
   934         return true;
   987         return true;
   935 
   988 
   953         [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->view = theView;
  1006         [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->view = theView;
   954         [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->theEvent = theEvent;
  1007         [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->theEvent = theEvent;
   955 #ifndef QT_NAMESPACE
  1008 #ifndef QT_NAMESPACE
   956         Q_ASSERT(clickCount > 0);
  1009         Q_ASSERT(clickCount > 0);
   957 #endif
  1010 #endif
   958         if (clickCount % 2 == 0)
  1011         if (clickCount % 2 == 0 && buttons == button)
   959             eventType = QEvent::MouseButtonDblClick;
  1012             eventType = QEvent::MouseButtonDblClick;
   960         if (button == Qt::LeftButton && (keyMods & Qt::MetaModifier)) {
  1013         if (button == Qt::LeftButton && (keyMods & Qt::MetaModifier)) {
   961             button = Qt::RightButton;
  1014             button = Qt::RightButton;
   962             [theView qt_setLeftButtonIsRightButton: true];
  1015             [theView qt_setLeftButtonIsRightButton: true];
   963         }
  1016         }
   965     case QEvent::MouseButtonRelease:
  1018     case QEvent::MouseButtonRelease:
   966         if (button == Qt::LeftButton && [theView qt_leftButtonIsRightButton]) {
  1019         if (button == Qt::LeftButton && [theView qt_leftButtonIsRightButton]) {
   967             button = Qt::RightButton;
  1020             button = Qt::RightButton;
   968             [theView qt_setLeftButtonIsRightButton: false];
  1021             [theView qt_setLeftButtonIsRightButton: false];
   969         }
  1022         }
       
  1023         qt_button_down = 0;
   970         break;
  1024         break;
   971     }
  1025     }
   972     [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->localPoint = localPoint;
  1026     [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->localPoint = localPoint;
   973     QMouseEvent qme(eventType, qlocalPoint, qglobalPoint, button, buttons, keyMods);
  1027     QMouseEvent qme(eventType, qlocalPoint, qglobalPoint, button, buttons, keyMods);
   974     qt_sendSpontaneousEvent(widgetToGetMouse, &qme);
  1028 
       
  1029 #ifdef ALIEN_DEBUG
       
  1030     qDebug() << "sending mouse event to" << widgetToGetMouse;
       
  1031 #endif
       
  1032     extern QWidget *qt_button_down;
       
  1033     extern QPointer<QWidget> qt_last_mouse_receiver;
       
  1034 
       
  1035     if (qwidget->testAttribute(Qt::WA_NativeWindow) && qt_widget_private(qwidget)->hasAlienChildren == false)
       
  1036         qt_sendSpontaneousEvent(widgetToGetMouse, &qme);
       
  1037     else
       
  1038         QApplicationPrivate::sendMouseEvent(widgetToGetMouse, &qme, widgetToGetMouse, qwidget, &qt_button_down,
       
  1039                                             qt_last_mouse_receiver);
       
  1040 
   975     if (eventType == QEvent::MouseButtonPress && button == Qt::RightButton) {
  1041     if (eventType == QEvent::MouseButtonPress && button == Qt::RightButton) {
   976         QContextMenuEvent qcme(QContextMenuEvent::Mouse, qlocalPoint, qglobalPoint, keyMods);
  1042         QContextMenuEvent qcme(QContextMenuEvent::Mouse, qlocalPoint, qglobalPoint, keyMods);
   977         qt_sendSpontaneousEvent(widgetToGetMouse, &qcme);
  1043         qt_sendSpontaneousEvent(widgetToGetMouse, &qcme);
   978     }
  1044     }
   979     return true;
  1045     return true;
  1095         [theWindow setContentBorderThickness:metrics.top forEdge:NSMaxYEdge];
  1161         [theWindow setContentBorderThickness:metrics.top forEdge:NSMaxYEdge];
  1096     [theWindow setContentBorderThickness:metrics.bottom forEdge:NSMinYEdge];
  1162     [theWindow setContentBorderThickness:metrics.bottom forEdge:NSMinYEdge];
  1097 #endif
  1163 #endif
  1098 }
  1164 }
  1099 
  1165 
       
  1166 #if QT_MAC_USE_COCOA
       
  1167 void qt_mac_replaceDrawRect(void * /*OSWindowRef */window, QWidgetPrivate *widget)
       
  1168 {
       
  1169     QMacCocoaAutoReleasePool pool;
       
  1170     OSWindowRef theWindow = static_cast<OSWindowRef>(window);
       
  1171     if(!theWindow)
       
  1172         return;
       
  1173     id theClass = [[[theWindow contentView] superview] class];
       
  1174     // What we do here is basically to add a new selector to NSThemeFrame called
       
  1175     // "drawRectOriginal:" which will contain the original implementation of
       
  1176     // "drawRect:". After that we get the new implementation from QCocoaWindow
       
  1177     // and exchange them. The new implementation is called drawRectSpecial.
       
  1178     // We cannot just add the method because it might have been added before and since
       
  1179     // we cannot remove a method once it has been added we need to ask QCocoaWindow if
       
  1180     // we did the swap or not.
       
  1181     if(!widget->drawRectOriginalAdded) {
       
  1182         Method m2 = class_getInstanceMethod(theClass, @selector(drawRect:));
       
  1183         if(!m2) {
       
  1184             // This case is pretty extreme, no drawRect means no drawing!
       
  1185             return;
       
  1186         }
       
  1187         class_addMethod(theClass, @selector(drawRectOriginal:), method_getImplementation(m2), method_getTypeEncoding(m2));
       
  1188         widget->drawRectOriginalAdded = true;
       
  1189     }
       
  1190     if(widget->originalDrawMethod) {
       
  1191         Method m0 = class_getInstanceMethod([theWindow class], @selector(drawRectSpecial:));
       
  1192         if(!m0) {
       
  1193             // Ok, this means the methods were never swapped. Just ignore
       
  1194             return;
       
  1195         }
       
  1196         Method m1 = class_getInstanceMethod(theClass, @selector(drawRect:));
       
  1197         if(!m1) {
       
  1198             // Ok, this means the methods were never swapped. Just ignore
       
  1199             return;
       
  1200         }
       
  1201         // We have the original method here. Proceed and swap the methods.
       
  1202         method_exchangeImplementations(m1, m0);
       
  1203         widget->originalDrawMethod = false;
       
  1204         [window display];
       
  1205     }
       
  1206 }
       
  1207 
       
  1208 void qt_mac_replaceDrawRectOriginal(void * /*OSWindowRef */window, QWidgetPrivate *widget)
       
  1209 {
       
  1210     QMacCocoaAutoReleasePool pool;
       
  1211     OSWindowRef theWindow = static_cast<OSWindowRef>(window);
       
  1212     id theClass = [[[theWindow contentView] superview] class];
       
  1213     // Now we need to revert the methods to their original state.
       
  1214     // We cannot remove the method, so we just keep track of it in QCocoaWindow.
       
  1215     Method m0 = class_getInstanceMethod([theWindow class], @selector(drawRectSpecial:));
       
  1216     if(!m0) {
       
  1217         // Ok, this means the methods were never swapped. Just ignore
       
  1218         return;
       
  1219     }
       
  1220     Method m1 = class_getInstanceMethod(theClass, @selector(drawRect:));
       
  1221     if(!m1) {
       
  1222         // Ok, this means the methods were never swapped. Just ignore
       
  1223         return;
       
  1224     }
       
  1225     method_exchangeImplementations(m1, m0);
       
  1226     widget->originalDrawMethod = true;
       
  1227     [window display];
       
  1228 }
       
  1229 #endif // QT_MAC_USE_COCOA
       
  1230 
  1100 void qt_mac_showBaseLineSeparator(void * /*OSWindowRef */window, bool show)
  1231 void qt_mac_showBaseLineSeparator(void * /*OSWindowRef */window, bool show)
  1101 {
  1232 {
       
  1233     if(!window)
       
  1234         return;
  1102 #if QT_MAC_USE_COCOA
  1235 #if QT_MAC_USE_COCOA
  1103     QMacCocoaAutoReleasePool pool;
  1236     QMacCocoaAutoReleasePool pool;
  1104     OSWindowRef theWindow = static_cast<OSWindowRef>(window);
  1237     OSWindowRef theWindow = static_cast<OSWindowRef>(window);
  1105     NSToolbar *macToolbar = [theWindow toolbar];
  1238     NSToolbar *macToolbar = [theWindow toolbar];
  1106     if (macToolbar)
  1239     [macToolbar setShowsBaselineSeparator:show];
  1107         [macToolbar setShowsBaselineSeparator: show];
  1240 #endif // QT_MAC_USE_COCOA
  1108 #endif
       
  1109 }
  1241 }
  1110 
  1242 
  1111 QStringList qt_mac_NSArrayToQStringList(void *nsarray)
  1243 QStringList qt_mac_NSArrayToQStringList(void *nsarray)
  1112 {
  1244 {
  1113     QStringList result;
  1245     QStringList result;
  1288 void qt_cocoaChangeOverrideCursor(const QCursor &cursor)
  1420 void qt_cocoaChangeOverrideCursor(const QCursor &cursor)
  1289 {
  1421 {
  1290     QMacCocoaAutoReleasePool pool;
  1422     QMacCocoaAutoReleasePool pool;
  1291     [static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(cursor)) set];
  1423     [static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(cursor)) set];
  1292 }
  1424 }
       
  1425 
       
  1426 //  WARNING: If Qt did not create NSApplication (e.g. in case it is
       
  1427 //  used as a plugin), and at the same time, there is no window on
       
  1428 //  screen (or the window that the event is sendt to becomes hidden etc
       
  1429 //  before the event gets delivered), the message will not be performed.
       
  1430 bool qt_cocoaPostMessage(id target, SEL selector)
       
  1431 {
       
  1432     if (!target)
       
  1433         return false;
       
  1434 
       
  1435     NSInteger windowNumber = 0;
       
  1436     if (![NSApp isMemberOfClass:[QNSApplication class]]) {
       
  1437         // INVARIANT: Cocoa is not using our NSApplication subclass. That means
       
  1438         // we don't control the main event handler either. So target the event
       
  1439         // for one of the windows on screen:
       
  1440         NSWindow *nswin = [NSApp mainWindow];
       
  1441         if (!nswin) {
       
  1442             nswin = [NSApp keyWindow];
       
  1443             if (!nswin)
       
  1444                 return false;
       
  1445         }
       
  1446         windowNumber = [nswin windowNumber];
       
  1447     }
       
  1448 
       
  1449     // WARNING: data1 and data2 is truncated to from 64-bit to 32-bit on OS 10.5! 
       
  1450     // That is why we need to split the address in two parts:
       
  1451     QCocoaPostMessageArgs *args = new QCocoaPostMessageArgs(target, selector);
       
  1452     quint32 lower = quintptr(args);
       
  1453     quint32 upper = quintptr(args) >> 32;
       
  1454     NSEvent *e = [NSEvent otherEventWithType:NSApplicationDefined
       
  1455         location:NSZeroPoint modifierFlags:0 timestamp:0 windowNumber:windowNumber
       
  1456         context:nil subtype:QtCocoaEventSubTypePostMessage data1:lower data2:upper];
       
  1457     [NSApp postEvent:e atStart:NO];
       
  1458     return true;
       
  1459 }
  1293 #endif
  1460 #endif
  1294 
  1461 
  1295 QMacCocoaAutoReleasePool::QMacCocoaAutoReleasePool()
  1462 QMacCocoaAutoReleasePool::QMacCocoaAutoReleasePool()
  1296 {
  1463 {
  1297 #ifndef QT_MAC_USE_COCOA
  1464 #ifndef QT_MAC_USE_COCOA
  1303 QMacCocoaAutoReleasePool::~QMacCocoaAutoReleasePool()
  1470 QMacCocoaAutoReleasePool::~QMacCocoaAutoReleasePool()
  1304 {
  1471 {
  1305     [(NSAutoreleasePool*)pool release];
  1472     [(NSAutoreleasePool*)pool release];
  1306 }
  1473 }
  1307 
  1474 
       
  1475 void qt_mac_post_retranslateAppMenu()
       
  1476 {
       
  1477 #ifdef QT_MAC_USE_COCOA
       
  1478     QMacCocoaAutoReleasePool pool;
       
  1479     qt_cocoaPostMessage([NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)], @selector(qtTranslateApplicationMenu));
       
  1480 #endif
       
  1481 }
       
  1482 
       
  1483 #ifdef QT_MAC_USE_COCOA
       
  1484 // This method implements the magic for the drawRectSpecial method.
       
  1485 // We draw a line at the upper edge of the content view in order to
       
  1486 // override the title baseline.
       
  1487 void macDrawRectOnTop(void * /*OSWindowRef */window)
       
  1488 {
       
  1489     OSWindowRef theWindow = static_cast<OSWindowRef>(window);
       
  1490     NSView *contentView = [theWindow contentView];
       
  1491     if(!contentView)
       
  1492         return;
       
  1493     // Get coordinates of the content view
       
  1494     NSRect contentRect = [contentView frame];
       
  1495     // Draw a line on top of the already drawn line.
       
  1496     // We need to check if we are active or not to use the proper color.
       
  1497     if([window isKeyWindow] || [window isMainWindow]) {
       
  1498         [[NSColor colorWithCalibratedRed:1.0 green:1.0 blue:1.0 alpha:1.0] set];
       
  1499     } else {
       
  1500         [[NSColor colorWithCalibratedRed:1.0 green:1.0 blue:1.0 alpha:1.0] set];
       
  1501     }
       
  1502     NSPoint origin = NSMakePoint(0, contentRect.size.height);
       
  1503     NSPoint end = NSMakePoint(contentRect.size.width, contentRect.size.height);
       
  1504     [NSBezierPath strokeLineFromPoint:origin toPoint:end];
       
  1505 }
       
  1506 
       
  1507 // This method will (or at least should) get called only once.
       
  1508 // Its mission is to find out if we are active or not. If we are active
       
  1509 // we assume that we were launched via finder, otherwise we assume
       
  1510 // we were called from the command line. The distinction is important,
       
  1511 // since in the first case we don't need to trigger a paintEvent, while
       
  1512 // in the second case we do.
       
  1513 void macSyncDrawingOnFirstInvocation(void * /*OSWindowRef */window)
       
  1514 {
       
  1515     OSWindowRef theWindow = static_cast<OSWindowRef>(window);
       
  1516     NSApplication *application = [NSApplication sharedApplication];
       
  1517     NSToolbar *toolbar = [window toolbar];
       
  1518     if([application isActive]) {
       
  1519         // Launched from finder
       
  1520         [toolbar setShowsBaselineSeparator:NO];
       
  1521     } else {
       
  1522         // Launched from commandline
       
  1523         [toolbar setVisible:false];
       
  1524         [toolbar setShowsBaselineSeparator:NO];
       
  1525         [toolbar setVisible:true];
       
  1526         [theWindow display];
       
  1527     }
       
  1528 }
       
  1529 #endif // QT_MAC_USE_COCOA
       
  1530 
  1308 QT_END_NAMESPACE
  1531 QT_END_NAMESPACE