Changeset 846 for trunk/src/gui/kernel/qapplication_mac.mm
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/kernel/qapplication_mac.mm
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 185 185 static bool qt_mac_collapse_on_dblclick = true; 186 186 extern int qt_antialiasing_threshold; // from qapplication.cpp 187 QPointer<QWidget> qt_button_down; // widget got last button-down 187 QWidget * qt_button_down; // widget got last button-down 188 QPointer<QWidget> qt_last_mouse_receiver; 188 189 #ifndef QT_MAC_USE_COCOA 189 190 static bool qt_button_down_in_content; // whether the button_down was in the content area. … … 737 738 static void qt_mac_update_child_gl_widgets(QWidget *widget) 738 739 { 739 if (widget->isWindow())740 return;741 742 740 // Update all OpenGL child widgets for the given widget. 743 741 QList<QWidgetPrivate::GlWidgetInfo> &glWidgets = qt_widget_private(widget)->glWidgets; … … 1221 1219 1222 1220 #endif 1223 if (!app_proc_ae_handlerUPP ) {1221 if (!app_proc_ae_handlerUPP && !QApplication::testAttribute(Qt::AA_MacPluginApplication)) { 1224 1222 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, ¤t_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 } 1228 1233 } 1229 1234 … … 1238 1243 // Cocoa application delegate 1239 1244 #ifdef QT_MAC_USE_COCOA 1240 NSApplication *cocoaApp = [ NSApplication sharedApplication];1245 NSApplication *cocoaApp = [QNSApplication sharedApplication]; 1241 1246 QMacCocoaAutoReleasePool pool; 1242 1247 NSObject *oldDelegate = [cocoaApp delegate]; … … 1259 1264 [newDelegate setMenuLoader:qtMenuLoader]; 1260 1265 [qtMenuLoader release]; 1261 1262 NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager];1263 [eventManager setEventHandler:newDelegate andSelector:@selector(getUrl:withReplyEvent:)1264 forEventClass:kInternetEventClass andEventID:kAEGetURL];1265 1266 } 1266 1267 #endif … … 1362 1363 QApplication cursor stack 1363 1364 *****************************************************************************/ 1365 #ifdef QT_MAC_USE_COCOA 1366 void 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 1381 void 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 1364 1390 void QApplication::setOverrideCursor(const QCursor &cursor) 1365 1391 { … … 1368 1394 #ifdef QT_MAC_USE_COCOA 1369 1395 QMacCocoaAutoReleasePool pool; 1396 if (qApp->d_func()->cursor_list.size() == 1) 1397 qApp->d_func()->disableUsageOfCursorRects(true); 1370 1398 [static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(cursor)) push]; 1371 1399 #else … … 1384 1412 QMacCocoaAutoReleasePool pool; 1385 1413 [NSCursor pop]; 1414 if (qApp->d_func()->cursor_list.isEmpty()) 1415 qApp->d_func()->disableUsageOfCursorRects(false); 1386 1416 #else 1387 1417 if (qApp && qApp->activeWindow()) { … … 1727 1757 // As a results of this, and to make sure we dont't receive duplicate events, 1728 1758 // 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; 1729 1764 SInt32 mdelt = 0; 1730 1765 GetEventParameter(event, kEventParamMouseWheelSmoothHorizontalDelta, typeSInt32, 0, 1731 1766 sizeof(mdelt), 0, &mdelt); 1732 wheel_deltaX = mdelt ;1767 wheel_deltaX = mdelt * pixelsToDegrees; 1733 1768 mdelt = 0; 1734 1769 GetEventParameter(event, kEventParamMouseWheelSmoothVerticalDelta, typeSInt32, 0, 1735 1770 sizeof(mdelt), 0, &mdelt); 1736 wheel_deltaY = mdelt ;1771 wheel_deltaY = mdelt * pixelsToDegrees; 1737 1772 GetEventParameter(event, kEventParamEventRef, typeEventRef, 0, 1738 1773 sizeof(compatibilityEvent), 0, &compatibilityEvent); … … 2409 2444 if(!handled_event) { 2410 2445 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); 2420 2461 } 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 } 2430 2470 } 2431 2471 } else if(cmd.commandID == kHICommandSelectWindow) { … … 2457 2497 #endif 2458 2498 } 2499 2500 #ifdef QT_MAC_USE_COCOA 2501 void QApplicationPrivate::qt_initAfterNSAppStarted() 2502 { 2503 setupAppleEvents(); 2504 updateOverrideCursor(); 2505 } 2506 2507 void 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 2459 2528 2460 2529 // In Carbon this is your one stop for apple events. … … 3009 3078 3010 3079 QMenuBar::macUpdateMenuBar(); 3011 3080 QApplicationPrivate::updateOverrideCursor(); 3012 3081 #else 3013 3082 Q_UNUSED(widget);
Note:
See TracChangeset
for help on using the changeset viewer.