Changeset 331 for trunk/src/gui/kernel
- Timestamp:
- Nov 20, 2009, 2:50:32 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gui/kernel/qclipboard_pm.cpp
r327 r331 58 58 #include "private/qpmobjectwindow_pm_p.h" 59 59 60 #define QCLIPBOARD_DEBUG60 #define QCLIPBOARD_DEBUG 61 61 62 62 #ifdef QCLIPBOARD_DEBUG 63 #include "qdebug.h" 63 # include "qdebug.h" 64 # define DEBUG(a) qDebug a 65 #else 66 # define DEBUG(a) do {} while(0) 64 67 #endif 65 68 … … 173 176 void setAsClipboardViewer(); 174 177 bool ownsClipboard(); 175 void renderAllFormats(bool isDelayed); 178 void putAllMimeToClipboard(bool isDelayed); 179 void flushClipboard(); 176 180 177 181 static QClipboardData *instance() … … 191 195 192 196 private: 193 bool openClipboard();194 void closeClipboard();195 197 bool setClipboard(QPMMime *converter, ULONG format, bool isDelayed); 196 void renderFormat(ULONG format);197 198 198 199 MRESULT message(ULONG msg, MPARAM mp1, MPARAM mp2); … … 218 219 QClipboardData::~QClipboardData() 219 220 { 220 renderAllFormats(false);221 221 setSource(0); 222 222 … … 237 237 if (src) 238 238 matches = QPMMime::allConvertersFromMimeData(src); 239 240 241 242 243 244 245 246 247 239 248 } 240 249 241 250 void QClipboardData::setAsClipboardViewer() 242 251 { 252 253 243 254 HWND clipboardViewer = WinQueryClipbrdViewer(NULLHANDLE); 244 255 if (hwnd() != clipboardViewer) { … … 259 270 } 260 271 261 bool QClipboardData::openClipboard()262 {263 if (!WinOpenClipbrd(NULLHANDLE)) {264 #ifndef QT_NO_DEBUG265 qWarning("QClipboardData::openClipboard: WinOpenClipbrd "266 "failed with 0x%lX", WinGetLastError(NULLHANDLE));267 #endif268 return false;269 }270 return true;271 }272 273 void QClipboardData::closeClipboard()274 {275 WinCloseClipbrd(NULLHANDLE);276 }277 278 272 bool QClipboardData::setClipboard(QPMMime *converter, ULONG format, 279 273 bool isDelayed) … … 283 277 return false; 284 278 285 bool ok ;279 bool ok; 286 280 ULONG flags = 0, data = 0; 287 281 … … 291 285 if (ok) { 292 286 WinSetClipbrdOwner(NULLHANDLE, hwnd()); 293 WinSetClipbrdData(NULLHANDLE, 0, format, flags);287 WinSetClipbrdData(NULLHANDLE, 0, format, flags); 294 288 } 295 289 } else { … … 297 291 ok = converter->convertFromMimeData(src, format, flags, &data); 298 292 if (ok) 299 WinSetClipbrdData(NULLHANDLE, data, format, flags); 300 } 301 #ifdef QCLIPBOARD_DEBUG 302 qDebug("QClipboardData::setClipboard: convert to CF 0x%lX, flags 0x%lX," 303 "data 0x%lX, delayed %d, ok %d", format, flags, data, isDelayed, ok); 304 #endif 305 306 return ok; 307 } 308 309 void QClipboardData::renderFormat(ULONG format) 310 { 311 #ifdef QCLIPBOARD_DEBUG 312 qDebug("QClipboardData::renderFormat: CF 0x%lX", format); 313 #endif 314 315 if (!src) 293 ok2 = WinSetClipbrdData(NULLHANDLE, data, format, flags); 294 } 295 DEBUG(("QClipboardData::setClipboard: convert to CF 0x%lX flags 0x%lX " 296 "data 0x%lX delayed %d ok %d", format, flags, data, isDelayed, ok)); 297 #ifndef QT_NO_DEBUG 298 if (!ok2) { 299 qWarning("QClipboardData::setClipboard: WinSetClipbrdData " 300 "failed with 0x%lX", WinGetLastError(NULLHANDLE)); 301 } 302 #endif 303 304 return ok && ok2; 305 } 306 307 void QClipboardData::putAllMimeToClipboard(bool isDelayed) 308 { 309 DEBUG(() << "QClipboardData::putAllMimeToClipboard: isDelayed" << isDelayed); 310 311 if (!WinOpenClipbrd(NULLHANDLE)) { 312 #ifndef QT_NO_DEBUG 313 qWarning("QClipboardData::putAllMimeToClipboard: WinOpenClipbrd " 314 "failed with 0x%lX", WinGetLastError(NULLHANDLE)); 315 #endif 316 316 return; 317 318 if (!openClipboard()) 319 return; 320 321 foreach(QPMMime::Match match, matches) { 322 if (match.format == format) { 323 setClipboard(match.converter, match.format, false); 324 break; 325 } 326 } 327 328 closeClipboard(); 329 } 330 331 void QClipboardData::renderAllFormats(bool isDelayed) 332 { 333 #ifdef QCLIPBOARD_DEBUG 334 qDebug() << "QClipboardData::renderAllFormats: isDelayed" << isDelayed; 335 #endif 336 337 if (!openClipboard()) 338 return; 317 } 339 318 340 319 // delete the clipboard contents before we render everything to make sure … … 345 324 if (!ok) { 346 325 #ifndef QT_NO_DEBUG 347 qWarning("QClipboardData:: renderAllFormats: WinEmptyClipbrd "326 qWarning("QClipboardData::: WinEmptyClipbrd " 348 327 "failed with 0x%lX", WinGetLastError(NULLHANDLE)); 349 328 #endif 329 350 330 return; 351 331 } 352 332 353 333 if (src) { 354 #ifdef QCLIPBOARD_DEBUG355 qDebug() << "QClipboardData::renderAllFormats: mimes" << src->formats();356 #endif357 334 foreach(QPMMime::Match match, matches) 358 335 setClipboard(match.converter, match.format, isDelayed); 359 336 } 360 337 361 closeClipboard(); 338 WinCloseClipbrd(NULLHANDLE); 339 } 340 341 void QClipboardData::flushClipboard() 342 { 343 if (ownsClipboard()) { 344 putAllMimeToClipboard(false); 345 // make sure we won't be doing this again if asked in WM_RENDERALLFMTS 346 setSource(0); 347 } 362 348 } 363 349 364 350 MRESULT QClipboardData::message(ULONG msg, MPARAM mp1, MPARAM mp2) 365 351 { 366 #ifdef QCLIPBOARD_DEBUG 367 qDebug("QClipboardData::message: msg %08lX, mp1 %p, mp2 %p", 368 msg, mp1, mp2); 369 #endif 352 DEBUG(("QClipboardData::message: msg %08lX, mp1 %p, mp2 %p", 353 msg, mp1, mp2)); 370 354 371 355 switch (msg) { 372 356 373 357 case WM_DRAWCLIPBOARD: { 358 359 374 360 // ask QClipboard to emit changed() signals 375 361 QClipboardEvent e(reinterpret_cast<QEventPrivate *>(1)); … … 391 377 prevClipboardViewer = NULLHANDLE; 392 378 } 393 break; 394 } 395 396 case WM_DESTROYCLIPBOARD: 379 } 380 break; 381 382 case WM_DESTROYCLIPBOARD: { 383 DEBUG(("QClipboardData::message: WM_DESTROYCLIPBOARD:")); 397 384 if (!ignore_WM_DESTROYCLIPBOARD) 398 385 setSource(0); 399 break; 400 401 case WM_RENDERFMT: 402 renderFormat((ULONG)mp1); 403 break; 404 405 case WM_RENDERALLFMTS: 406 renderAllFormats(false); 407 break; 386 } 387 break; 388 389 case WM_RENDERFMT: { 390 DEBUG(("QClipboardData::message: WM_RENDERFMT: CF 0x%lX", (ULONG)mp1)); 391 if (src) { 392 foreach(QPMMime::Match match, matches) { 393 if (match.format == (ULONG)mp1) { 394 setClipboard(match.converter, match.format, false); 395 break; 396 } 397 } 398 } 399 } 400 break; 401 402 case WM_RENDERALLFMTS: { 403 DEBUG(("QClipboardData::message: WM_RENDERALLFMTS:")); 404 if (src) { 405 foreach(QPMMime::Match match, matches) 406 setClipboard(match.converter, match.format, false); 407 } 408 } 409 break; 408 410 409 411 default: … … 411 413 } 412 414 413 return (MRESULT)TRUE; 415 DEBUG(("QClipboardData::message: END")); 416 return FALSE; 414 417 } 415 418 … … 423 426 void QClipboard::setMimeData(QMimeData *src, Mode mode) 424 427 { 425 #ifdef QCLIPBOARD_DEBUG 426 qDebug() << "QClipboard::setMimeData: src" << src << "mode" << mode; 427 #endif 428 DEBUG(() << "QClipboard::setMimeData: src" << src << "mode" << mode); 428 429 429 430 if (mode != Clipboard) { … … 441 442 bool runsEventLoop = d_func()->threadData->loopLevel != 0; 442 443 443 d-> renderAllFormats(runsEventLoop);444 d->(runsEventLoop); 444 445 } 445 446 … … 456 457 if (!((QClipboardEvent*)e)->data()) { 457 458 // this is sent by QApplication to render all formats at app shut down 458 QClipboardData::instance()-> renderAllFormats(false);459 QClipboardData::instance()->); 459 460 } else { 460 461 // this is sent by QClipboardData to notify about clipboard data change
Note:
See TracChangeset
for help on using the changeset viewer.