about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/qt-5/5.15/qtbase.patch.d/macos-sdk-10.12/0004-Revert-QCocoaDrag-avoid-using-the-deprecated-API-if-.patch
blob: ee9b80ca6ed4d9358429cee15aeb593ce06d3d7c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
From d5c155a9f3ff38e28ac073f6df43175724ebc290 Mon Sep 17 00:00:00 2001
From: Dmitry Kalinkin <dmitry.kalinkin@gmail.com>
Date: Mon, 7 Dec 2020 12:32:34 -0500
Subject: [PATCH 4/6] Revert "QCocoaDrag - avoid using the deprecated API if
 possible"

This reverts commit 8481a9fc974a1f1dd44a9f82decb18fe2290689f.
---
 src/plugins/platforms/cocoa/qcocoadrag.h      |  6 --
 src/plugins/platforms/cocoa/qcocoadrag.mm     | 90 -------------------
 .../platforms/cocoa/qnsview_dragging.mm       |  9 +-
 3 files changed, 1 insertion(+), 104 deletions(-)

diff --git a/src/plugins/platforms/cocoa/qcocoadrag.h b/src/plugins/platforms/cocoa/qcocoadrag.h
index 975741c270..5a5b985c6e 100644
--- a/src/plugins/platforms/cocoa/qcocoadrag.h
+++ b/src/plugins/platforms/cocoa/qcocoadrag.h
@@ -48,8 +48,6 @@
 #include <QtGui/private/qdnd_p.h>
 #include <QtGui/private/qinternalmimedata_p.h>
 
-#include <QtCore/qeventloop.h>
-
 QT_BEGIN_NAMESPACE
 
 class QCocoaDrag : public QPlatformDrag
@@ -71,15 +69,11 @@ public:
     void setLastMouseEvent(NSEvent *event, NSView *view);
 
     void setAcceptedAction(Qt::DropAction act);
-    void exitDragLoop();
 private:
     QDrag *m_drag;
     NSEvent *m_lastEvent;
     NSView *m_lastView;
     Qt::DropAction m_executed_drop_action;
-    QEventLoop internalDragLoop;
-
-    bool maybeDragMultipleItems();
 
     QPixmap dragPixmap(QDrag *drag, QPoint &hotSpot) const;
 };
diff --git a/src/plugins/platforms/cocoa/qcocoadrag.mm b/src/plugins/platforms/cocoa/qcocoadrag.mm
index ab6863a432..b4a16ab912 100644
--- a/src/plugins/platforms/cocoa/qcocoadrag.mm
+++ b/src/plugins/platforms/cocoa/qcocoadrag.mm
@@ -44,9 +44,6 @@
 #include <QtWidgets/qwidget.h>
 #endif
 #include <QtGui/private/qcoregraphics_p.h>
-#include <QtCore/qsysinfo.h>
-
-#include <vector>
 
 QT_BEGIN_NAMESPACE
 
@@ -131,9 +128,6 @@ Qt::DropAction QCocoaDrag::drag(QDrag *o)
     m_drag = o;
     m_executed_drop_action = Qt::IgnoreAction;
 
-    if (maybeDragMultipleItems())
-        return m_executed_drop_action;
-
     QPoint hotSpot = m_drag->hotSpot();
     QPixmap pm = dragPixmap(m_drag, hotSpot);
     NSImage *dragImage = [NSImage imageFromQImage:pm.toImage()];
@@ -164,95 +158,11 @@ Qt::DropAction QCocoaDrag::drag(QDrag *o)
     return m_executed_drop_action;
 }
 
-bool QCocoaDrag::maybeDragMultipleItems()
-{
-    Q_ASSERT(m_drag && m_drag->mimeData());
-    Q_ASSERT(m_executed_drop_action == Qt::IgnoreAction);
-
-    if (QOperatingSystemVersion::current() < QOperatingSystemVersion::MacOSMojave) {
-        // -dragImage: stopped working in 10.14 first.
-        return false;
-    }
-
-    const QMacAutoReleasePool pool;
-
-    NSWindow *theWindow = [m_lastEvent window];
-    Q_ASSERT(theWindow);
-
-    if (![theWindow.contentView respondsToSelector:@selector(draggingSession:sourceOperationMaskForDraggingContext:)])
-        return false;
-
-    auto *sourceView = static_cast<NSView<NSDraggingSource>*>(theWindow.contentView);
-
-    const auto &qtUrls = m_drag->mimeData()->urls();
-    NSPasteboard *dragBoard = [NSPasteboard pasteboardWithName:NSPasteboardNameDrag];
-
-    if (int(dragBoard.pasteboardItems.count) == 1 && qtUrls.size() <= 1) {
-        // Good old -dragImage: works perfectly for this ...
-        return false;
-    }
-
-    std::vector<NSPasteboardItem *> nonUrls;
-    for (NSPasteboardItem *item in dragBoard.pasteboardItems) {
-        bool isUrl = false;
-        for (NSPasteboardType type in item.types) {
-            using NSStringRef = NSString *;
-            if ([type isEqualToString:NSStringRef(kUTTypeFileURL)]) {
-                isUrl = true;
-                break;
-            }
-        }
-
-        if (!isUrl)
-            nonUrls.push_back(item);
-    }
-
-    QPoint hotSpot = m_drag->hotSpot();
-    const auto pixmap = dragPixmap(m_drag, hotSpot);
-    NSImage *dragImage = [NSImage imageFromQImage:pixmap.toImage()];
-    Q_ASSERT(dragImage);
-
-    NSMutableArray<NSDraggingItem *> *dragItems = [[[NSMutableArray alloc] init] autorelease];
-    const NSPoint itemLocation = m_drag->hotSpot().toCGPoint();
-    // 0. We start from URLs, which can be actually in a list (thus technically
-    // only ONE item in the pasteboard. The fact it's only one does not help, we are
-    // still getting an exception because of the number of items/images mismatch ...
-    for (const auto &qtUrl : qtUrls) {
-        NSURL *nsUrl = qtUrl.toNSURL();
-        auto *newItem = [[[NSDraggingItem alloc] initWithPasteboardWriter:nsUrl] autorelease];
-        const NSRect itemFrame = NSMakeRect(itemLocation.x, itemLocation.y,
-                                            dragImage.size.width,
-                                            dragImage.size.height);
-        [newItem setDraggingFrame:itemFrame contents:dragImage];
-        [dragItems addObject:newItem];
-    }
-    // 1. Repeat for non-url items, if any:
-    for (auto *pbItem : nonUrls) {
-        auto *newItem = [[[NSDraggingItem alloc] initWithPasteboardWriter:pbItem] autorelease];
-        const NSRect itemFrame = NSMakeRect(itemLocation.x, itemLocation.y,
-                                            dragImage.size.width,
-                                            dragImage.size.height);
-        [newItem setDraggingFrame:itemFrame contents:dragImage];
-        [dragItems addObject:newItem];
-    }
-
-    [sourceView beginDraggingSessionWithItems:dragItems event:m_lastEvent source:sourceView];
-    internalDragLoop.exec();
-    return true;
-}
-
 void QCocoaDrag::setAcceptedAction(Qt::DropAction act)
 {
     m_executed_drop_action = act;
 }
 
-void QCocoaDrag::exitDragLoop()
-{
-    if (internalDragLoop.isRunning())
-        internalDragLoop.exit();
-}
-
-
 QPixmap QCocoaDrag::dragPixmap(QDrag *drag, QPoint &hotSpot) const
 {
     const QMimeData* data = drag->mimeData();
diff --git a/src/plugins/platforms/cocoa/qnsview_dragging.mm b/src/plugins/platforms/cocoa/qnsview_dragging.mm
index 978d73f7d9..463e3c5579 100644
--- a/src/plugins/platforms/cocoa/qnsview_dragging.mm
+++ b/src/plugins/platforms/cocoa/qnsview_dragging.mm
@@ -232,10 +232,6 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin
     if (!target)
         return;
 
-    auto *nativeDrag = QCocoaIntegration::instance()->drag();
-    Q_ASSERT(nativeDrag);
-    nativeDrag->exitDragLoop();
-
     QPoint windowPoint = QPointF::fromCGPoint([self convertPoint:sender.draggingLocation fromView:nil]).toPoint();
 
     qCDebug(lcQpaMouse) << QEvent::DragLeave << self << "at" << windowPoint;
@@ -294,12 +294,7 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin
     if (!target)
         return;
 
-    QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();
-    Q_ASSERT(nativeDrag);
-    nativeDrag->exitDragLoop();
-    // for internal drag'n'drop, don't override the action the drop event accepted
-    if (!nativeDrag->currentDrag())
-        nativeDrag->setAcceptedAction(qt_mac_mapNSDragOperation(operation));
+    QCocoaIntegration::instance()->drag();
 
     // Qt starts drag-and-drop on a mouse button press event. Cococa in
     // this case won't send the matching release event, so we have to
-- 
2.21.0