Changeset 324 for trunk/src/gui/kernel/qclipboard_pm.cpp
- Timestamp:
- Nov 18, 2009, 1:49:31 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gui/kernel/qclipboard_pm.cpp
r323 r324 52 52 #include "qevent.h" 53 53 #include "qmime.h" 54 #include "qdnd_p.h" 55 54 56 #include "qt_os2.h" 55 #include " qdnd_p.h"57 #include "private/qpmobjectwindow_pm_p.h" 56 58 57 59 #define QCLIPBOARD_DEBUG 58 60 61 #ifdef QCLIPBOARD_DEBUG 62 #include "qdebug.h" 63 #endif 64 59 65 QT_BEGIN_NAMESPACE 60 66 … … 64 70 { 65 71 public: 66 QClipboardWatcher() {}72 QClipboardWatcher() : isDirty(true) {} 67 73 68 74 bool hasFormat_sys(const QString &mimetype) const; 69 75 QStringList formats_sys() const; 70 76 QVariant retrieveData_sys(const QString &mimetype, QVariant::Type preferredType) const; 77 78 private: 79 80 void peekData() const; 81 82 mutable QList<ULONG> formats; 83 mutable QList<QPMMime::Match> matches; 84 mutable bool isDirty; 71 85 }; 72 86 87 void QClipboardWatcher::peekData() const 88 { 89 if (!isDirty) 90 return; 91 92 if (!WinOpenClipbrd(NULLHANDLE)) { 93 #ifndef QT_NO_DEBUG 94 qWarning("QClipboardWatcher: WinOpenClipbrd failed with 0x%lX", 95 WinGetLastError(NULLHANDLE)); 96 #endif 97 return; 98 } 99 100 formats.clear(); 101 ULONG cf = 0; 102 while ((cf = WinEnumClipbrdFmts(NULLHANDLE, cf))) 103 formats << cf; 104 105 WinCloseClipbrd(NULLHANDLE); 106 107 matches = QPMMime::allConvertersFromFormats(formats); 108 isDirty = false; 109 } 110 73 111 bool QClipboardWatcher::hasFormat_sys(const QString &mime) const 74 112 { 75 bool ok = false; 76 if (WinOpenClipbrd(NULLHANDLE)) { 77 ULONG cf = 0; 78 while ((cf = WinEnumClipbrdFmts(NULLHANDLE, cf))) { 79 if (QPMMime::converterToMime(mime, cf)) { 80 ok = true; 81 break; 82 } 83 } 84 WinCloseClipbrd(NULLHANDLE); 85 } 86 #ifndef QT_NO_DEBUG 87 else 88 qWarning("QClipboardWatcher: WinOpenClipbrd failed with %lX", 89 WinGetLastError(NULLHANDLE)); 90 #endif 91 return ok; 113 peekData(); 114 if (isDirty) 115 return false; // peekData() failed 116 117 foreach (QPMMime::Match match, matches) 118 if (match.mime == mime) 119 return true; 120 121 return false; 92 122 } 93 123 … … 95 125 { 96 126 QStringList fmts; 97 if (WinOpenClipbrd(NULLHANDLE)) { 98 QVector<ULONG> cfs; 99 ULONG cf = 0; 100 while ((cf = WinEnumClipbrdFmts(NULLHANDLE, cf))) 101 cfs << cf; 102 fmts = QPMMime::allMimesForFormats(cfs); 103 WinCloseClipbrd(NULLHANDLE); 104 } 105 #ifndef QT_NO_DEBUG 106 else 107 qWarning("QClipboardWatcher: WinOpenClipbrd failed with %lX", 108 WinGetLastError(NULLHANDLE)); 109 #endif 127 128 peekData(); 129 if (isDirty) 130 return fmts; // peekData() failed 131 132 foreach (QPMMime::Match match, matches) 133 fmts << match.mime; 134 110 135 return fmts; 111 136 } … … 116 141 QVariant result; 117 142 118 if (WinOpenClipbrd(NULLHANDLE)) { 119 ULONG cf = 0; 120 while ((cf = WinEnumClipbrdFmts(NULLHANDLE, cf))) { 121 QPMMime *converter = QPMMime::converterToMime(mime, cf); 122 if (converter) { 123 ULONG flags; 124 if (WinQueryClipbrdFmtInfo(NULLHANDLE, cf, &flags)) { 125 ULONG data = WinQueryClipbrdData(NULLHANDLE, cf); 126 if (data) { 127 result = converter->convertToMime(mime, type, cf, flags, data); 128 } 129 } 130 break; 143 peekData(); 144 if (isDirty) 145 return result; // peekData() failed 146 147 foreach (QPMMime::Match match, matches) { 148 if (match.mime == mime) { 149 ULONG flags; 150 if (WinQueryClipbrdFmtInfo(NULLHANDLE, match.format, &flags)) { 151 ULONG data = WinQueryClipbrdData(NULLHANDLE, match.format); 152 result = match.converter->convertFromFormat(match.format, flags, 153 data, match.mime, type); 131 154 } 155 return result; 132 156 } 133 WinCloseClipbrd(NULLHANDLE); 134 } 135 #ifndef QT_NO_DEBUG 136 else 137 qWarning("QClipboardWatcher: WinOpenClipbrd failed with %lX", 138 WinGetLastError(NULLHANDLE)); 139 #endif 157 } 158 140 159 return result; 141 160 } … … 143 162 //////////////////////////////////////////////////////////////////////////////// 144 163 145 class QClipboardData 164 class QClipboardData : public QPMObjectWindow 146 165 { 147 166 public: … … 149 168 ~QClipboardData(); 150 169 151 // @todo ... 170 void setSource(QMimeData *s) 171 { 172 if (s == src) 173 return; 174 delete src; 175 src = s; 176 } 177 178 QMimeData *source() 179 { 180 return src; 181 } 182 183 bool setClipboard(QPMMime *converter, ULONG format, bool isDelayed); 184 185 MRESULT message(ULONG msg, MPARAM mp1, MPARAM mp2); 152 186 153 187 private: 188 QMimeData *src; 154 189 }; 155 190 156 QClipboardData::QClipboardData() 191 QClipboardData::QClipboardData() : src(0) 157 192 { 158 193 } … … 160 195 QClipboardData::~QClipboardData() 161 196 { 197 delete src; 198 } 199 200 bool QClipboardData::setClipboard(QPMMime *converter, ULONG format, 201 bool isDelayed) 202 { 203 Q_ASSERT(src); 204 if (!src) 205 return false; 206 207 bool ok; 208 ULONG flags = 0, data = 0; 209 210 if (isDelayed) { 211 // setup delayed rendering of clipboard data 212 ok = converter->convertFromMimeData(src, format, flags, 0); 213 if (ok) { 214 WinSetClipbrdOwner(NULLHANDLE, hwnd()); 215 WinSetClipbrdData(NULLHANDLE, 0, format, flags); 216 } 217 } else { 218 // render now 219 ok = converter->convertFromMimeData(src, format, flags, &data); 220 if (ok) 221 WinSetClipbrdData(NULLHANDLE, data, format, flags); 222 } 223 #ifdef QCLIPBOARD_DEBUG 224 qDebug("QClipboardData::setClipboard: convert to CF 0x%lX, flags 0x%lX," 225 "data 0x%lX, ok %d", format, flags, data, ok); 226 #endif 227 228 return ok; 229 } 230 231 MRESULT QClipboardData::message(ULONG msg, MPARAM mp1, MPARAM mp2) 232 { 233 return 0; 162 234 } 163 235 … … 168 240 if (ptrClipboardData == 0) { 169 241 ptrClipboardData = new QClipboardData; 170 // @todo ...171 242 } 172 243 return ptrClipboardData; … … 181 252 //////////////////////////////////////////////////////////////////////////////// 182 253 254 static bool ignore_WM_DESTROYCLIPBOARD = FALSE; 255 183 256 QClipboard::~QClipboard() 184 257 { … … 188 261 void QClipboard::setMimeData(QMimeData *src, Mode mode) 189 262 { 190 if (mode != Clipboard) 263 if (mode != Clipboard) { 264 delete src; 191 265 return; 266 } 192 267 193 268 if (!WinOpenClipbrd(NULLHANDLE)) { 194 269 #ifndef QT_NO_DEBUG 195 qWarning("QClipboard: WinOpenClipbrd failed with%lX",270 qWarning("QClipboard::setMimeData: WinOpenClipbrd failed with 0x%lX", 196 271 WinGetLastError(NULLHANDLE)); 197 272 #endif 273 delete src; 198 274 return; 199 275 } 200 276 201 // @todo 202 // QClipboardData *d = clipboardData(); 203 // d->setSource(src); 277 QClipboardData *d = clipboardData(); 278 d->setSource(src); 279 280 ignore_WM_DESTROYCLIPBOARD = TRUE; 281 BOOL ok = WinEmptyClipbrd(NULLHANDLE); 282 ignore_WM_DESTROYCLIPBOARD = FALSE; 283 #ifndef QT_NO_DEBUG 284 if (!ok) 285 qWarning("QClipboard::setMimeData: WinEmptyClipbrd failed with 0x%lX", 286 WinGetLastError(NULLHANDLE)); 287 #else 288 Q_UNUSED(ok); 289 #endif 290 291 if (!src) 292 return; // nothing to do 293 294 bool runsEventLoop = QCoreApplication::instance() && 295 QCoreApplication::instance()->d_func()->in_exec; 296 297 QStringList formats = src->formats(); 298 foreach(QString mime, formats) { 299 #ifdef QCLIPBOARD_DEBUG 300 qDebug() << "QClipboard::setMimeData: src mime" << mime; 301 #endif 302 QList<QPMMime::Match> matches = QPMMime::allConvertersFromMimeData(src); 303 foreach(QPMMime::Match match, matches) { 304 d->setClipboard(match.converter, match.format, !runsEventLoop); 305 } 306 } 204 307 205 308 WinCloseClipbrd(NULLHANDLE);
Note:
See TracChangeset
for help on using the changeset viewer.