43 #ifndef QT_NO_DRAGANDDROP 54 #ifndef QT_NO_ACCESSIBILITY 58 #include <private/qapplication_p.h> 59 #include <private/qwidget_p.h> 60 #include <private/qdnd_p.h> 61 #include <private/qt_mac_p.h> 79 #ifndef QT_MAC_USE_COCOA 97 #ifndef QT_MAC_USE_COCOA 116 #ifdef DEBUG_DRAG_EVENTS 117 # define MAP_MAC_ENUM(x) x, #x 119 # define MAP_MAC_ENUM(x) x 125 #ifdef DEBUG_DRAG_EVENTS 129 #ifndef QT_MAC_USE_COCOA 139 DragActions ret = kDragActionNothing;
140 for(
int i = 0; dnd_action_symbols[i].
qt_code; ++i) {
141 if(qActions & dnd_action_symbols[i].
qt_code)
142 ret |= dnd_action_symbols[i].
mac_code;
148 #ifdef DEBUG_DRAG_EVENTS 149 qDebug(
"Converting DND ActionList: 0x%lx", macActions);
152 for(
int i = 0; dnd_action_symbols[i].
qt_code; ++i) {
153 #ifdef DEBUG_DRAG_EVENTS 154 qDebug(
" %d) [%s] : %s", i, dnd_action_symbols[i].qt_desc,
155 (macActions & dnd_action_symbols[i].
mac_code) ?
"true" :
"false");
157 if(macActions & dnd_action_symbols[i].mac_code)
169 if(qtActions & preferred_actions[i]) {
170 ret = preferred_actions[i];
174 #ifdef DEBUG_DRAG_EVENTS 175 for(
int i = 0; dnd_action_symbols[i].
qt_code; ++i) {
176 if(dnd_action_symbols[i].
qt_code == ret) {
177 qDebug(
"Got default action: %s [0x%lx]", dnd_action_symbols[i].qt_desc, macActions);
186 GetDragModifiers(dragRef, &modifiers, 0, 0);
191 DragActions macAllowed = kDragActionNothing;
192 GetDragDropAction(dragRef, &macAllowed);
196 if(!(qtAllowed & qtAction))
202 DragActions currentActions;
203 GetDragDropAction(dragRef, ¤tActions);
204 if(currentActions != macAction) {
205 SetDragDropAction(dragRef, macAction);
209 #endif // !QT_MAC_USE_COCOA 216 #ifndef QT_MAC_USE_COCOA 219 qDebug(
"DnD: Cannot get PasteBoard!");
226 #endif // !QT_MAC_USE_COCOA 231 #ifndef QT_MAC_USE_COCOA 234 qDebug(
"DnD: Cannot get PasteBoard!");
242 #endif // !QT_MAC_USE_COCOA 247 #ifndef QT_MAC_USE_COCOA 250 qDebug(
"DnD: Cannot get PasteBoard!");
275 beingCancelled =
true;
278 #ifndef QT_NO_ACCESSIBILITY 298 #ifndef QT_MAC_USE_COCOA 299 DragActions currentAction = kDragActionNothing;
300 OSStatus err = GetDragDropAction(dragRef, ¤tAction);
301 if (err == noErr && currentAction != kDragActionNothing) {
321 qt_mac_dnd_answer_rec.
rect =
event.answerRect();
322 qt_mac_dnd_answer_rec.
buttons =
event.mouseButtons();
323 qt_mac_dnd_answer_rec.
modifiers =
event.keyboardModifiers();
324 qt_mac_dnd_answer_rec.
lastAction =
event.dropAction();
339 bool QWidgetPrivate::qt_mac_dnd_event(
uint kind, DragRef dragRef)
341 #ifndef QT_MAC_USE_COCOA 344 if (kind != kEventControlDragLeave)
348 GetDragMouse(dragRef, &mouse, 0L);
349 if(!mouse.h && !mouse.v)
350 GetGlobalMouse(&mouse);
354 if(
modal->isWindow()) {
363 DragActions allowed = kDragActionNothing;
364 GetDragAllowableActions(dragRef, &allowed);
374 bool interrestedInDrag =
true;
377 if (kind == kEventControlDragWithin) {
381 qt_mac_dnd_answer_rec.
clear();
393 interrestedInDrag =
false;
398 }
else if (kind == kEventControlDragEnter) {
399 qt_mac_dnd_answer_rec.
clear();
407 if (!qDEEvent.isAccepted())
419 qDMEvent.setDropAction(qDEEvent.dropAction());
422 interrestedInDrag =
false;
428 }
else if(kind == kEventControlDragLeave) {
431 }
else if(kind == kEventControlDragReceive) {
432 QDropEvent de(q->mapFromGlobal(
QPoint(mouse.h, mouse.v)), qtAllowed, dropdata,
437 if(!de.isAccepted()) {
438 interrestedInDrag =
false;
439 SetDragDropAction(dragRef, kDragActionNothing);
447 #ifdef DEBUG_DRAG_EVENTS 449 const char *desc = 0;
451 case kEventControlDragWithin: desc =
"DragMove";
break;
452 case kEventControlDragEnter: desc =
"DragEnter";
break;
453 case kEventControlDragLeave: desc =
"DragLeave";
break;
454 case kEventControlDragReceive: desc =
"DragDrop";
break;
458 qDebug(
"Sending <%s>(%d, %d) event to %p(%s::%s) [%d] (%p)",
459 desc, pos.x(), pos.y(), q, q->metaObject()->className(),
460 q->objectName().toLocal8Bit().constData(), ret, dragRef);
466 bool found_cursor =
false;
467 if(kind == kEventControlDragWithin || kind == kEventControlDragEnter) {
468 ThemeCursor cursor = kThemeNotAllowedCursor;
470 if (interrestedInDrag) {
471 DragActions action = kDragActionNothing;
472 GetDragDropAction(dragRef, &action);
475 cursor = kThemeNotAllowedCursor;
478 cursor = kThemeArrowCursor;
481 cursor = kThemeCopyArrowCursor;
484 cursor = kThemeAliasArrowCursor;
487 cursor = kThemeNotAllowedCursor;
491 SetThemeCursor(cursor);
497 if(
qApp &&
qApp->overrideCursor()) {
498 cursor = *
qApp->overrideCursor();
502 cursor = p->cursor();
518 if (kind == kEventControlDragReceive)
519 return interrestedInDrag;
526 #endif // !QT_MAC_USE_COCOA 529 #ifndef QT_MAC_USE_COCOA 534 qWarning(
"Qt: Internal error: WH0A, unexpected condition reached");
541 if(!(GetCurrentEventButtonState() & kEventMouseButtonPrimary))
545 dragPrivate()->source->removeEventFilter(
this);
547 beingCancelled =
false;
551 dragPrivate()->
target = 0;
553 #ifndef QT_NO_ACCESSIBILITY 564 if((result = NewDragWithPasteboard(dragBoard.
pasteBoard(), &dragRef)))
568 SetDragAllowableActions(dragRef,
571 SetDragAllowableActions(dragRef,
577 QPixmap pix = dragPrivate()->pixmap;
579 if(dragPrivate()->data->hasText() || dragPrivate()->data->hasUrls()) {
581 QString s = dragPrivate()->
data->hasText() ? dragPrivate()->data->text()
582 : dragPrivate()->data->urls().first().toString();
590 const int width = fm.
width(s);
591 const int height = fm.
height();
592 if(width > 0 && height > 0) {
610 hotspot = dragPrivate()->hotspot;
614 EventRecord fakeEvent;
615 GetGlobalMouse(&(fakeEvent.where));
616 fakeEvent.message = 0;
617 fakeEvent.what = mouseDown;
618 fakeEvent.when = EventTimeToTicks(GetCurrentEventTime());
619 fakeEvent.modifiers = GetCurrentKeyModifiers();
620 if(GetCurrentEventButtonState() & 2)
621 fakeEvent.modifiers |= controlKey;
625 boundsPoint.h = fakeEvent.where.h - hotspot.
x();
626 boundsPoint.v = fakeEvent.where.v - hotspot.
y();
628 SetRect(&boundsRect, boundsPoint.h, boundsPoint.v, boundsPoint.h + pix.
width(), boundsPoint.v + pix.
height());
631 QRegion dragRegion(boundsPoint.h, boundsPoint.v, pix.
width(), pix.
height()), pixRegion;
633 HIPoint hipoint = { -hotspot.
x(), -hotspot.
y() };
635 SetDragImageWithCGImage(dragRef, img, &hipoint, 0);
639 SetDragItemBounds(dragRef, (ItemReference)1 , &boundsRect);
647 if(result == noErr) {
652 PasteboardCopyPasteLocation(dragBoard.
pasteBoard(), &pasteLocation);
662 bool atleastOne =
false;
664 for (
int i = 0; i < urls.
size(); ++i){
665 QUrl fromUrl = urls.
at(i);
677 DisposeDrag(dragRef);
684 DragActions ret = kDragActionNothing;
685 GetDragDropAction(dragRef, &ret);
686 DisposeDrag(dragRef);
691 DisposeDrag(dragRef);
703 NSString* pasteboardName = (NSString*)pasteboard;
704 [pasteboardName retain];
711 [pasteboardName release];
719 qDebug(
"DnD: Cannot get PasteBoard!");
731 qDebug(
"DnD: Cannot get PasteBoard!");
744 qDebug(
"DnD: Cannot get PasteBoard!");
752 #endif // QT_NO_DRAGANDDROP The QVariant class acts like a union for the most common Qt data types.
The QPainter class performs low-level painting on widgets and other paint devices.
void setPointSize(int)
Sets the point size to pointSize.
const struct __CFString * CFStringRef
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object's accessibility information.
static DragActions qt_mac_dnd_map_qt_actions(Qt::DropActions qActions)
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
bool rename(const QString &newName)
Renames the file currently specified by fileName() to newName.
bool hasFormat_sys(const QString &mimeType) const
bool qt_mac_mouse_inside_answer_rect(QPoint mouse)
QStringList formats_sys() const
The QCursor class provides a mouse cursor with an arbitrary shape.
The QFontMetrics class provides font metrics information.
#define QT_END_NAMESPACE
This macro expands to.
The QDrag class provides support for MIME-based drag and drop data transfer.
int width() const
Returns the width of the pixmap.
void setMimeData(QMimeData *data)
Sets the data to be sent to the given MIME data.
static mac_enum_mapper dnd_action_symbols[]
PasteboardRef OSPasteboardRef
Qt::DropAction defaultAction(Qt::DropActions possibleActions, Qt::KeyboardModifiers modifiers) const
uint qGlobalPostedEventsCount()
int length() const
Returns the number of characters in this string.
static const int default_pm_hotx
void qt_mac_set_cursor(const QCursor *)
static QString toQString(CFStringRef cfstr)
void accept()
Calls QDropEvent::accept().
static Qt::DropActions qt_mac_dnd_map_mac_actions(DragActions macActions)
struct CGImage * CGImageRef
QByteArray data(const QString &mimetype) const
Returns the data stored in the object in the format described by the MIME type specified by mimeType...
static const char *const default_pm[]
void cancel(bool deleteSource=true)
The QUrl class provides a convenient interface for working with URLs.
The QString class provides a Unicode character string.
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
static const int default_pm_hoty
void emitActionChanged(Qt::DropAction newAction)
The QObject class is the base class of all Qt objects.
Qt::KeyboardModifiers modifiers
The QChar class provides a 16-bit Unicode character.
QChar * data()
Returns a pointer to the data stored in the QString.
QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const
OSPasteboardRef pasteBoard() const
QCocoaDropData(CFStringRef pasteboard)
QString path() const
Returns the path of the URL.
Qt::DropAction drag(QDrag *)
int ascent() const
Returns the ascent of the font.
Q_CORE_EXPORT void qDebug(const char *,...)
static Qt::DropAction qt_mac_dnd_map_mac_default_action(DragActions macActions)
static QWidget * activeModalWidget()
Returns the active modal widget.
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position...
#define QT_BEGIN_NAMESPACE
This macro expands to.
CFStringRef dropPasteboard
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
static bool qt_mac_set_existing_drop_action(const DragRef &dragRef, QDropEvent &event)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QRect answerRect() const
Returns the rectangle in the widget where the drop will occur if accepted.
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
QVariant retrieveData(const QString &format, QVariant::Type) const
QStringList formats() const
Returns a list of formats supported by the object.
static Qt::DropActions possible_actions
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
Type
This enum type defines the types of variable that a QVariant can contain.
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static void sendPostedEvents()
The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leav...
The QRegion class specifies a clip region for a painter.
QList< QUrl > urls() const
Returns a list of URLs contained within the MIME data object.
The QMimeData class provides a container for data that records information about its MIME type...
struct OpaqueRgnHandle * RgnHandle
bool hasFormat(const QString &format) const
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
void qt_mac_copy_answer_rect(const QDragMoveEvent &event)
static QDragManager * self()
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const
QStringList formats() const
QMacDndAnswerRecord qt_mac_dnd_answer_rec
The QDropEvent class provides an event which is sent when a drag and drop action is completed...
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
static void qt_mac_dnd_update_action(DragReference dragRef)
The QTimerEvent class contains parameters that describe a timer event.
The QFont class specifies a font used for drawing text.
QMimeData * mimeData() const
Returns the MIME data that is encapsulated by the drag object.
Qt::DropAction executed_action
static DragReference qt_mac_current_dragRef
The QDragEnterEvent class provides an event which is sent to a widget when a drag and drop action ent...
The QPoint class defines a point in the plane using integer precision.
int size() const
Returns the number of items in the list.
void setPen(const QColor &color)
Sets the painter's pen to have style Qt::SolidLine, width 0 and the specified color.
void setMimeData(QMimeData *mime)
bool copy(const QString &newName)
Copies the file currently specified by fileName() to a file called newName.
int y() const
Returns the y coordinate of this point.
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
The QPixmap class is an off-screen image representation that can be used as a paint device...
QStringList formats_sys() const
int height() const
Returns the height of the pixmap.
RgnHandle qt_mac_get_rgn()
Qt::DropAction lastAction
void setFont(const QFont &f)
Sets the painter's font to the given font.
static Qt::MouseButtons mouseButtons()
Returns the current state of the buttons on the mouse.
void qt_mac_send_modifiers_changed(quint32, QObject *)
int x() const
Returns the x coordinate of this point.
void move(const QPoint &)
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
int height() const
Returns the height of the font.
The QFileInfo class provides system-independent file information.
The QEvent class is the base class of all event classes.
static QUrl toUrl(Register *reg, int type, QDeclarativeContextData *context, bool *ok=0)
bool eventFilter(QObject *, QEvent *)
Filters events if this object has been installed as an event filter for the watched object...
QDragPrivate * dragPrivate() const
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
static QString fileName(const QString &fileUrl)
void deleteLater()
Schedules this object for deletion.
static void flush()
Flushes the platform specific event queues.
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
bool hasFormat_sys(const QString &mimeType) const
void qt_mac_dispose_rgn(RgnHandle)
void timerEvent(QTimerEvent *)
This event handler can be reimplemented in a subclass to receive timer events for the object...
QWidget * target() const
Returns the target of the drag and drop operation.