src/gui/kernel/qcocoaview_mac.mm
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
child 30 5dc02b23752f
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
   347         QApplication::sendEvent(qwidget, &qDMEvent);
   347         QApplication::sendEvent(qwidget, &qDMEvent);
   348         if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction) {
   348         if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction) {
   349             // since we accepted the drag enter event, the widget expects
   349             // since we accepted the drag enter event, the widget expects
   350             // future drage move events.
   350             // future drage move events.
   351             // ### check if we need to treat this like the drag enter event.
   351             // ### check if we need to treat this like the drag enter event.
   352             nsActions = QT_PREPEND_NAMESPACE(qt_mac_mapDropAction)(qDEEvent.dropAction());
   352             nsActions = NSDragOperationNone;
       
   353             // Save as ignored in the answer rect.
       
   354             qDMEvent.setDropAction(Qt::IgnoreAction);
   353         } else {
   355         } else {
   354             nsActions = QT_PREPEND_NAMESPACE(qt_mac_mapDropAction)(qDMEvent.dropAction());
   356             nsActions = QT_PREPEND_NAMESPACE(qt_mac_mapDropAction)(qDMEvent.dropAction());
   355         }
   357         }
   356         QT_PREPEND_NAMESPACE(qt_mac_copy_answer_rect)(qDMEvent);
   358         QT_PREPEND_NAMESPACE(qt_mac_copy_answer_rect)(qDMEvent);
   357         return nsActions;
   359         return nsActions;
   358     }
   360     }
   359  }
   361  }
   360 
       
   361 - (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender
   362 - (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender
   362 {
   363 {
   363     NSPoint windowPoint = [sender draggingLocation];
   364     NSPoint windowPoint = [sender draggingLocation];
   364     if (qwidget->testAttribute(Qt::WA_TransparentForMouseEvents)) {
   365     if (qwidget->testAttribute(Qt::WA_TransparentForMouseEvents)) {
   365         // pass the drag move event to the view underneath.
   366         // pass the drag move event to the view underneath.
   400         mimeData = QDragManager::self()->dragPrivate()->data;
   401         mimeData = QDragManager::self()->dragPrivate()->data;
   401     QDragMoveEvent qDMEvent(posDrag, qtAllowed, mimeData, QApplication::mouseButtons(), modifiers);
   402     QDragMoveEvent qDMEvent(posDrag, qtAllowed, mimeData, QApplication::mouseButtons(), modifiers);
   402     qDMEvent.setDropAction(QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec).lastAction);
   403     qDMEvent.setDropAction(QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec).lastAction);
   403     qDMEvent.accept();
   404     qDMEvent.accept();
   404     QApplication::sendEvent(qwidget, &qDMEvent);
   405     QApplication::sendEvent(qwidget, &qDMEvent);
   405     qt_mac_copy_answer_rect(qDMEvent);
       
   406 
   406 
   407     NSDragOperation operation = qt_mac_mapDropAction(qDMEvent.dropAction());
   407     NSDragOperation operation = qt_mac_mapDropAction(qDMEvent.dropAction());
   408     if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction) {
   408     if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction) {
   409         // ignore this event (we will still receive further notifications)
   409         // ignore this event (we will still receive further notifications)
   410         operation = NSDragOperationNone;
   410         operation = NSDragOperationNone;
   411     }
   411         // Save as ignored in the answer rect.
       
   412         qDMEvent.setDropAction(Qt::IgnoreAction);
       
   413     }
       
   414     qt_mac_copy_answer_rect(qDMEvent);
   412     return operation;
   415     return operation;
   413 }
   416 }
   414 
   417 
   415 - (void)draggingExited:(id < NSDraggingInfo >)sender
   418 - (void)draggingExited:(id < NSDraggingInfo >)sender
   416 {
   419 {
   503             [self setNeedsDisplayInRect:rects[count]];
   506             [self setNeedsDisplayInRect:rects[count]];
   504         }
   507         }
   505     } else {
   508     } else {
   506         [self setNeedsDisplay:YES];
   509         [self setNeedsDisplay:YES];
   507     }
   510     }
       
   511 
       
   512     // Make sure the opengl context is updated on resize.
       
   513     if (qwidgetprivate->isGLWidget) {
       
   514         qwidgetprivate->needWindowChange = true;
       
   515         QEvent event(QEvent::MacGLWindowChange);
       
   516         qApp->sendEvent(qwidget, &event);
       
   517     }
   508 }
   518 }
   509 
   519 
   510 - (void)drawRect:(NSRect)aRect
   520 - (void)drawRect:(NSRect)aRect
   511 {
   521 {
   512     if (QApplicationPrivate::graphicsSystem() != 0) {
   522     if (QApplicationPrivate::graphicsSystem() != 0) {
   513         if (QWidgetBackingStore *bs = qwidgetprivate->maybeBackingStore())
   523         if (QWidgetBackingStore *bs = qwidgetprivate->maybeBackingStore()) {
   514             bs->markDirty(qwidget->rect(), qwidget);
   524             // Drawing is handled on the window level
   515         qwidgetprivate->syncBackingStore(qwidget->rect());
   525             // See qcocoasharedwindowmethods_mac_p.
   516         return;
   526             return;
       
   527         }
   517     }
   528     }
   518     CGContextRef cg = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
   529     CGContextRef cg = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
   519     qwidgetprivate->hd = cg;
   530     qwidgetprivate->hd = cg;
   520     CGContextSaveGState(cg);
   531     CGContextSaveGState(cg);
   521 
   532 
   632     [ta release];
   643     [ta release];
   633 }
   644 }
   634 
   645 
   635 - (void)mouseEntered:(NSEvent *)event
   646 - (void)mouseEntered:(NSEvent *)event
   636 {
   647 {
       
   648     if (qwidgetprivate->data.in_destructor)
       
   649         return;
   637     QEvent enterEvent(QEvent::Enter);
   650     QEvent enterEvent(QEvent::Enter);
   638     NSPoint windowPoint = [event locationInWindow];
   651     NSPoint windowPoint = [event locationInWindow];
   639     NSPoint globalPoint = [[event window] convertBaseToScreen:windowPoint];
   652     NSPoint globalPoint = [[event window] convertBaseToScreen:windowPoint];
   640     NSPoint viewPoint = [self convertPoint:windowPoint fromView:nil];
   653     NSPoint viewPoint = [self convertPoint:windowPoint fromView:nil];
   641     if (!qAppInstance()->activeModalWidget() || QApplicationPrivate::tryModalHelper(qwidget, 0)) {
   654     if (!qAppInstance()->activeModalWidget() || QApplicationPrivate::tryModalHelper(qwidget, 0)) {
   813         deltaX = qBound(-120, int([theEvent deltaX] * 10000), 120);
   826         deltaX = qBound(-120, int([theEvent deltaX] * 10000), 120);
   814         deltaY = qBound(-120, int([theEvent deltaY] * 10000), 120);
   827         deltaY = qBound(-120, int([theEvent deltaY] * 10000), 120);
   815         deltaZ = qBound(-120, int([theEvent deltaZ] * 10000), 120);
   828         deltaZ = qBound(-120, int([theEvent deltaZ] * 10000), 120);
   816     }
   829     }
   817 
   830 
       
   831 #ifndef QT_NO_WHEELEVENT
   818     if (deltaX != 0) {
   832     if (deltaX != 0) {
   819         QWheelEvent qwe(qlocal, qglobal, deltaX, buttons, keyMods, Qt::Horizontal);
   833         QWheelEvent qwe(qlocal, qglobal, deltaX, buttons, keyMods, Qt::Horizontal);
   820         qt_sendSpontaneousEvent(widgetToGetMouse, &qwe);
   834         qt_sendSpontaneousEvent(widgetToGetMouse, &qwe);
   821         wheelOK = qwe.isAccepted();
   835         wheelOK = qwe.isAccepted();
   822         if (!wheelOK && QApplicationPrivate::focus_widget
   836         if (!wheelOK && QApplicationPrivate::focus_widget
   853                              deltaZ, buttons, keyMods, (Qt::Orientation)3);
   867                              deltaZ, buttons, keyMods, (Qt::Orientation)3);
   854             qt_sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2);
   868             qt_sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2);
   855             wheelOK = qwe2.isAccepted();
   869             wheelOK = qwe2.isAccepted();
   856         }
   870         }
   857     }
   871     }
       
   872 #endif //QT_NO_WHEELEVENT
       
   873 
   858     if (!wheelOK) {
   874     if (!wheelOK) {
   859         return [super scrollWheel:theEvent];
   875         return [super scrollWheel:theEvent];
   860     }
   876     }
   861 }
   877 }
   862 
   878 
  1389     QAccessible::updateAccessibility(this, 0, QAccessible::DragDropStart);
  1405     QAccessible::updateAccessibility(this, 0, QAccessible::DragDropStart);
  1390 #endif
  1406 #endif
  1391 
  1407 
  1392     // setup the data
  1408     // setup the data
  1393     QMacPasteboard dragBoard((CFStringRef) NSDragPboard, QMacPasteboardMime::MIME_DND);
  1409     QMacPasteboard dragBoard((CFStringRef) NSDragPboard, QMacPasteboardMime::MIME_DND);
  1394     dragPrivate()->data->setData(QLatin1String("application/x-qt-mime-type-name"), QByteArray());
  1410     dragPrivate()->data->setData(QLatin1String("application/x-qt-mime-type-name"), QByteArray("dummy"));
  1395     dragBoard.setMimeData(dragPrivate()->data);
  1411     dragBoard.setMimeData(dragPrivate()->data);
  1396 
  1412 
  1397     // create the image
  1413     // create the image
  1398     QPoint hotspot;
  1414     QPoint hotspot;
  1399     QPixmap pix = dragPrivate()->pixmap;
  1415     QPixmap pix = dragPrivate()->pixmap;