Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/kernel/qapplication_mac.mm

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    185185static bool qt_mac_collapse_on_dblclick = true;
    186186extern int qt_antialiasing_threshold; // from qapplication.cpp
    187 QPointer<QWidget> qt_button_down;                // widget got last button-down
     187QWidget * qt_button_down;                // widget got last button-down
     188QPointer<QWidget> qt_last_mouse_receiver;
    188189#ifndef QT_MAC_USE_COCOA
    189190static bool qt_button_down_in_content; // whether the button_down was in the content area.
     
    737738static void qt_mac_update_child_gl_widgets(QWidget *widget)
    738739{
    739     if (widget->isWindow())
    740         return;
    741 
    742740    // Update all OpenGL child widgets for the given widget.
    743741    QList<QWidgetPrivate::GlWidgetInfo> &glWidgets = qt_widget_private(widget)->glWidgets;
     
    12211219
    12221220#endif
    1223         if (!app_proc_ae_handlerUPP) {
     1221        if (!app_proc_ae_handlerUPP && !QApplication::testAttribute(Qt::AA_MacPluginApplication)) {
    12241222            app_proc_ae_handlerUPP = AEEventHandlerUPP(QApplicationPrivate::globalAppleEventProcessor);
    1225             for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i)
    1226                 AEInstallEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id,
    1227                         app_proc_ae_handlerUPP, SRefCon(qApp), false);
     1223            for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i) {
     1224                // Install apple event handler, but avoid overwriting an already
     1225                // existing handler (it means a 3rd party application has installed one):
     1226                SRefCon refCon = 0;
     1227                AEEventHandlerUPP current_handler = NULL;
     1228                AEGetEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id, &current_handler, &refCon, false);
     1229                if (!current_handler)
     1230                    AEInstallEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id,
     1231                            app_proc_ae_handlerUPP, SRefCon(qApp), false);
     1232            }
    12281233        }
    12291234
     
    12381243    // Cocoa application delegate
    12391244#ifdef QT_MAC_USE_COCOA
    1240     NSApplication *cocoaApp = [NSApplication sharedApplication];
     1245    NSApplication *cocoaApp = [QNSApplication sharedApplication];
    12411246    QMacCocoaAutoReleasePool pool;
    12421247    NSObject *oldDelegate = [cocoaApp delegate];
     
    12591264        [newDelegate setMenuLoader:qtMenuLoader];
    12601265        [qtMenuLoader release];
    1261 
    1262         NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager];
    1263         [eventManager setEventHandler:newDelegate andSelector:@selector(getUrl:withReplyEvent:)
    1264           forEventClass:kInternetEventClass andEventID:kAEGetURL];
    12651266    }
    12661267#endif
     
    13621363  QApplication cursor stack
    13631364 *****************************************************************************/
     1365#ifdef QT_MAC_USE_COCOA
     1366void QApplicationPrivate::disableUsageOfCursorRects(bool disable)
     1367{
     1368    // In Cocoa there are two competing ways of setting the cursor; either
     1369    // by using cursor rects (see qcocoaview_mac.mm), or by pushing/popping
     1370    // the cursor manually. When we use override cursors, it makes most sense
     1371    // to use the latter. But then we need to tell cocoa to stop using the
     1372    // first approach so it doesn't change the cursor back when hovering over
     1373    // a cursor rect:
     1374    QWidgetList topLevels = qApp->topLevelWidgets();
     1375    for (int i=0; i<topLevels.size(); ++i) {
     1376        if (NSWindow *window = qt_mac_window_for(topLevels.at(i)))
     1377            disable ? [window disableCursorRects] : [window enableCursorRects];
     1378    }
     1379}
     1380
     1381void QApplicationPrivate::updateOverrideCursor()
     1382{
     1383    // Sometimes Cocoa forgets that we have set a Cursor
     1384    // manually. In those cases, remind it again:
     1385    if (QCursor *override = qApp->overrideCursor())
     1386        [static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(*override)) set];
     1387}
     1388#endif
     1389
    13641390void QApplication::setOverrideCursor(const QCursor &cursor)
    13651391{
     
    13681394#ifdef QT_MAC_USE_COCOA
    13691395    QMacCocoaAutoReleasePool pool;
     1396    if (qApp->d_func()->cursor_list.size() == 1)
     1397        qApp->d_func()->disableUsageOfCursorRects(true);
    13701398    [static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(cursor)) push];
    13711399#else
     
    13841412    QMacCocoaAutoReleasePool pool;
    13851413    [NSCursor pop];
     1414    if (qApp->d_func()->cursor_list.isEmpty())
     1415        qApp->d_func()->disableUsageOfCursorRects(false);
    13861416#else
    13871417    if (qApp && qApp->activeWindow()) {
     
    17271757            // As a results of this, and to make sure we dont't receive duplicate events,
    17281758            // we try to detect when this happend by checking the 'compatibilityEvent'.
     1759            // Since delta is delivered as pixels rather than degrees, we need to
     1760            // convert from pixels to degrees in a sensible manner.
     1761            // It looks like 1/4 degrees per pixel behaves most native.
     1762            // (NB: Qt expects the unit for delta to be 8 per degree):
     1763            const int pixelsToDegrees = 2;
    17291764            SInt32 mdelt = 0;
    17301765            GetEventParameter(event, kEventParamMouseWheelSmoothHorizontalDelta, typeSInt32, 0,
    17311766                              sizeof(mdelt), 0, &mdelt);
    1732             wheel_deltaX = mdelt;
     1767            wheel_deltaX = mdelt * pixelsToDegrees;
    17331768            mdelt = 0;
    17341769            GetEventParameter(event, kEventParamMouseWheelSmoothVerticalDelta, typeSInt32, 0,
    17351770                              sizeof(mdelt), 0, &mdelt);
    1736             wheel_deltaY = mdelt;
     1771            wheel_deltaY = mdelt * pixelsToDegrees;
    17371772            GetEventParameter(event, kEventParamEventRef, typeEventRef, 0,
    17381773                              sizeof(compatibilityEvent), 0, &compatibilityEvent);
     
    24092444            if(!handled_event) {
    24102445                if(cmd.commandID == kHICommandQuit) {
    2411                     handled_event = true;
    2412                     HiliteMenu(0);
    2413                     bool handle_quit = true;
    2414                     if(QApplicationPrivate::modalState()) {
    2415                         int visible = 0;
    2416                         const QWidgetList tlws = QApplication::topLevelWidgets();
    2417                         for(int i = 0; i < tlws.size(); ++i) {
    2418                             if(tlws.at(i)->isVisible())
    2419                                 ++visible;
     2446                    // Quitting the application is not Qt's responsibility if
     2447                    // used in a plugin or just embedded into a native application.
     2448                    // In that case, let the event pass down to the native apps event handler.
     2449                    if (!QApplication::testAttribute(Qt::AA_MacPluginApplication)) {
     2450                        handled_event = true;
     2451                        HiliteMenu(0);
     2452                        bool handle_quit = true;
     2453                        if(QApplicationPrivate::modalState()) {
     2454                            int visible = 0;
     2455                            const QWidgetList tlws = QApplication::topLevelWidgets();
     2456                            for(int i = 0; i < tlws.size(); ++i) {
     2457                                if(tlws.at(i)->isVisible())
     2458                                    ++visible;
     2459                            }
     2460                            handle_quit = (visible <= 1);
    24202461                        }
    2421                         handle_quit = (visible <= 1);
    2422                     }
    2423                     if(handle_quit) {
    2424                         QCloseEvent ev;
    2425                         QApplication::sendSpontaneousEvent(app, &ev);
    2426                         if(ev.isAccepted())
    2427                             app->quit();
    2428                     } else {
    2429                         QApplication::beep();
     2462                        if(handle_quit) {
     2463                            QCloseEvent ev;
     2464                            QApplication::sendSpontaneousEvent(app, &ev);
     2465                            if(ev.isAccepted())
     2466                                app->quit();
     2467                        } else {
     2468                            QApplication::beep();
     2469                        }
    24302470                    }
    24312471                } else if(cmd.commandID == kHICommandSelectWindow) {
     
    24572497#endif
    24582498}
     2499
     2500#ifdef QT_MAC_USE_COCOA
     2501void QApplicationPrivate::qt_initAfterNSAppStarted()
     2502{
     2503    setupAppleEvents();
     2504    updateOverrideCursor();
     2505}
     2506
     2507void QApplicationPrivate::setupAppleEvents()
     2508{
     2509    // This function is called from the event dispatcher when NSApplication has
     2510    // finished initialization, which appears to be just after [NSApplication run] has
     2511    // started to execute. By setting up our apple events handlers this late, we override
     2512    // the ones set up by NSApplication.
     2513
     2514    // If Qt is used as a plugin, we let the 3rd party application handle events
     2515    // like quit and open file events. Otherwise, if we install our own handlers, we
     2516    // easily end up breaking functionallity the 3rd party application depend on:
     2517    if (QApplication::testAttribute(Qt::AA_MacPluginApplication))
     2518        return;
     2519
     2520    QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) *newDelegate = [QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate];
     2521    NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager];
     2522    [eventManager setEventHandler:newDelegate andSelector:@selector(appleEventQuit:withReplyEvent:)
     2523     forEventClass:kCoreEventClass andEventID:kAEQuitApplication];
     2524    [eventManager setEventHandler:newDelegate andSelector:@selector(getUrl:withReplyEvent:)
     2525      forEventClass:kInternetEventClass andEventID:kAEGetURL];
     2526}
     2527#endif
    24592528
    24602529// In Carbon this is your one stop for apple events.
     
    30093078
    30103079    QMenuBar::macUpdateMenuBar();
    3011 
     3080    QApplicationPrivate::updateOverrideCursor();
    30123081#else
    30133082    Q_UNUSED(widget);
Note: See TracChangeset for help on using the changeset viewer.