Changeset 334 for trunk/src/gui/kernel/qclipboard_pm.cpp
- Timestamp:
- Nov 20, 2009, 7:39:03 PM (16 years ago)
- File:
-
- 1 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 bool peekData(bool leaveOpen = false) 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 false; 98 } 99 100 QList<ULONG> newFormats; 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() const; 178 188 void putAllMimeToClipboard(bool isDelayed); 179 189 void flushClipboard(); 190 191 const QMimeData *mimeData() const; 180 192 181 193 static QClipboardData *instance() … … 202 214 QList<QPMMime::Match> matches; 203 215 HWND prevClipboardViewer; 216 217 QClipboardWatcher watcher; 204 218 205 219 bool ignore_WM_DESTROYCLIPBOARD; … … 265 279 } 266 280 267 bool QClipboardData::ownsClipboard() 281 bool QClipboardData::ownsClipboard() const 268 282 { 269 283 return src && hwnd() == WinQueryClipbrdOwner(NULLHANDLE); … … 346 360 setSource(0); 347 361 } 362 } 363 364 const QMimeData *QClipboardData::mimeData() const 365 { 366 // short cut for local copy / paste 367 if (ownsClipboard() && src) 368 return src; 369 return &watcher; 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
Note:
See TracChangeset
for help on using the changeset viewer.