Changeset 334
- Timestamp:
- Nov 20, 2009, 7:39:03 PM (16 years ago)
- Location:
- trunk/src/gui/kernel
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gui/kernel/qclipboard_pm.cpp
r331 r334 74 74 { 75 75 public: 76 QClipboardWatcher() : isDirty(true){}76 QClipboardWatcher() {} 77 77 78 78 bool hasFormat_sys(const QString &mimetype) const; … … 82 82 private: 83 83 84 void peekData() const;84 ) const; 85 85 86 86 mutable QList<ULONG> formats; 87 87 mutable QList<QPMMime::Match> matches; 88 mutable bool isDirty;89 88 }; 90 89 91 void QClipboardWatcher::peekData() const 92 { 93 if (!isDirty) 94 return; 95 90 bool QClipboardWatcher::peekData(bool leaveOpen) const 91 { 96 92 if (!WinOpenClipbrd(NULLHANDLE)) { 97 93 #ifndef QT_NO_DEBUG … … 99 95 "failed with 0x%lX", WinGetLastError(NULLHANDLE)); 100 96 #endif 101 return ;102 } 103 104 formats.clear();97 return; 98 } 99 100 ; 105 101 ULONG cf = 0; 106 102 while ((cf = WinEnumClipbrdFmts(NULLHANDLE, cf))) 107 formats << cf; 108 109 WinCloseClipbrd(NULLHANDLE); 110 103 newFormats << cf; 104 105 if (!leaveOpen) 106 WinCloseClipbrd(NULLHANDLE); 107 108 // optimization: we don't want to call the potentially expensive 109 // allConvertersFromFormats() unlesss we really got a different set 110 if (newFormats == formats) 111 return true; 112 113 formats = newFormats; 111 114 matches = QPMMime::allConvertersFromFormats(formats); 112 isDirty = false; 115 116 #ifdef QCLIPBOARD_DEBUG 117 foreach(QPMMime::Match match, matches) 118 DEBUG(("QClipboardWatcher::peekData: converter %p mime \"%ls\" " 119 "format 0x%lX priority %d", match.converter, match.mime.utf16(), 120 match.format, match.priority)); 121 #endif 122 123 return true; 113 124 } 114 125 115 126 bool QClipboardWatcher::hasFormat_sys(const QString &mime) const 116 127 { 117 peekData(); 118 if (isDirty) 119 return false; // peekData() failed 128 if (!peekData()) 129 return false; 120 130 121 131 foreach (QPMMime::Match match, matches) … … 130 140 QStringList fmts; 131 141 132 peekData(); 133 if (isDirty) 134 return fmts; // peekData() failed 142 if (!peekData()) 143 return fmts; 135 144 136 145 foreach (QPMMime::Match match, matches) … … 145 154 QVariant result; 146 155 147 peekData(); 148 if (isDirty) 149 return result; // peekData() failed 156 if (!peekData(true /*leaveOpen*/)) 157 return result; 150 158 151 159 foreach (QPMMime::Match match, matches) { … … 157 165 data, match.mime, type); 158 166 } 159 return result; 160 } 161 } 167 break; 168 } 169 } 170 171 WinCloseClipbrd(NULLHANDLE); 162 172 163 173 return result; … … 175 185 176 186 void setAsClipboardViewer(); 177 bool ownsClipboard() ;187 bool ownsClipboard(); 178 188 void putAllMimeToClipboard(bool isDelayed); 179 189 void flushClipboard(); 190 191 180 192 181 193 static QClipboardData *instance() … … 202 214 QList<QPMMime::Match> matches; 203 215 HWND prevClipboardViewer; 216 217 204 218 205 219 bool ignore_WM_DESTROYCLIPBOARD; … … 265 279 } 266 280 267 bool QClipboardData::ownsClipboard() 281 bool QClipboardData::ownsClipboard() 268 282 { 269 283 return src && hwnd() == WinQueryClipbrdOwner(NULLHANDLE); … … 346 360 setSource(0); 347 361 } 362 363 364 365 366 367 368 369 348 370 } 349 371 … … 481 503 const QMimeData *QClipboard::mimeData(Mode mode) const 482 504 { 483 // @todo implement 484 return 0; 505 if (mode != Clipboard) 506 return 0; 507 508 return QClipboardData::instance()->mimeData(); 485 509 } 486 510 -
trunk/src/gui/kernel/qmime.h
r332 r334 127 127 ULONG &flags, ULONG *data) const = 0; 128 128 129 130 129 131 // for converting to Qt 130 virtual Q StringListmimesForFormats(const QList<ULONG> &formats) const = 0;132 virtual Q mimesForFormats(const QList<ULONG> &formats) const = 0; 131 133 virtual QVariant convertFromFormat(ULONG format, ULONG flags, ULONG data, 132 134 const QString &mimeType, … … 145 147 struct Match 146 148 { 147 Match(QPMMime *c, const QString f, int p) :148 converter(c), mime(f), format( 0), priority(p) {}149 Match(QPMMime *c, const QString f, int p) : 150 converter(c), mime(f), format(), priority(p) {} 149 151 150 152 Match(QPMMime *c, ULONG f, int p) : … … 153 155 QPMMime *converter; 154 156 QString mime; // used by allConvertersFromFormats() 155 ULONG format; // used by allConvertersFrom MimeData()157 ULONG format; // used by allConvertersFromMimeData() 156 158 int priority; 157 159 }; -
trunk/src/gui/kernel/qmime_pm.cpp
r332 r334 246 246 247 247 /*! 248 \fn Q StringListQPMMime::mimesForFormats(const QList<ULONG> &formats) const248 \fn Q QPMMime::mimesForFormats(const QList<ULONG> &formats) const 249 249 250 250 Returns a list of mime types that will be created form the specified \a list 251 251 of \a formats, in order of precedence (the most suitable mime type comes 252 252 first), or an empty list if neither of the \a formats is supported by this 253 converter. 253 converter. Note that each pair in the returned list consists of the mime 254 type name and the corresponding format identifier. 254 255 255 256 All subclasses must reimplement this pure virtual function. … … 276 277 QList<QPMMime*> mimes = theMimeList()->mimes(); 277 278 for (int i = mimes.size()-1; i >= 0; --i) { 278 Q StringListfmts = mimes[i]->mimesForFormats(formats);279 Q fmts = mimes[i]->mimesForFormats(formats); 279 280 int priority = 0; 280 foreach ( QStringfmt, fmts) {281 foreach ( fmt, fmts) { 281 282 ++priority; 282 283 QList<Match>::iterator it = matches.begin(); 283 284 for (; it != matches.end(); ++it) { 284 285 Match &match = *it; 285 if (match.mime == fmt ) {286 if (match.mime == fmt) { 286 287 // replace if priority is higher, ignore otherwise 287 288 if (priority < match.priority) { 288 289 match.converter = mimes[i]; 290 289 291 match.priority = priority; 290 292 } … … 293 295 } 294 296 if (it == matches.end()) { 295 matches += Match(mimes[i], fmt , priority);297 matches += Match(mimes[i], fmt, priority); 296 298 } 297 299 } … … 344 346 ULONG &flags, ULONG *data) const; 345 347 346 Q StringListmimesForFormats(const QList<ULONG> &formats) const;348 Q mimesForFormats(const QList<ULONG> &formats) const; 347 349 QVariant convertFromFormat(ULONG format, ULONG flags, ULONG data, 348 350 const QString &mimeType, … … 388 390 int maxsize = str.size()+str.size()/40+3; 389 391 r.fill('\0', maxsize); 390 char *o = r.data();391 const char *d = str.data();392 charo = r.data(); 393 const chard = str.data(); 392 394 const int s = str.size(); 393 395 bool cr = false; … … 454 456 } 455 457 456 Q StringListQPMMimeText::mimesForFormats(const QList<ULONG> &formats) const457 { 458 Q StringListmimes;458 Q QPMMimeText::mimesForFormats(const QList<ULONG> &formats) const 459 { 460 Q mimes; 459 461 foreach(ULONG cf, formats) { 460 if (cf == CF_TEXT || cf == CF_TextUnicode){ 461 mimes << QLatin1String("text/plain"); 462 break; 463 } 462 // prefer unicode over local8Bit 463 if (cf == CF_TextUnicode) 464 mimes.prepend(qMakePair(QString(QLatin1String("text/plain")), cf)); 465 if (cf == CF_TEXT) 466 mimes.append(qMakePair(QString(QLatin1String("text/plain")), cf)); 464 467 } 465 468 return mimes; … … 470 473 QVariant::Type preferredType) const 471 474 { 472 return QVariant(); 475 QVariant ret; 476 477 // @todo why is it startsWith? the rest of the mime specification (encoding, 478 // etc) isn't taken into account... Anyway, copied the logic from Windows. 479 if (!mimeType.startsWith("text/plain")) 480 return ret; 481 if (!(flags & CFI_POINTER) || !data) 482 return ret; 483 484 QString str; 485 486 if (format == CF_TEXT) { 487 const char *d = (const char *)data; 488 QByteArray r(""); 489 if (*d) { 490 const int s = qstrlen(d); 491 r.fill('\0', s); 492 char *o = r.data(); 493 int j = 0; 494 for (int i = 0; i < s; i++) { 495 char c = d[i]; 496 if (c != '\r') 497 o[j++] = c; 498 } 499 } 500 str = QString::fromLocal8Bit(r); 501 } else if (format == CF_TextUnicode) { 502 str = QString::fromUtf16((const unsigned short *)data); 503 str.replace(QLatin1String("\r\n"), QLatin1String("\n")); 504 } 505 506 if (preferredType == QVariant::String) 507 ret = str; 508 else 509 ret = str.toUtf8(); 510 511 return ret; 473 512 } 474 513
Note:
See TracChangeset
for help on using the changeset viewer.