bool COSXClipboard::has(EFormat format) const { if (m_pboard == NULL) return false; PasteboardItemID item; PasteboardGetItemIdentifier(m_pboard, (CFIndex) 1, &item); for (ConverterList::const_iterator index = m_converters.begin(); index != m_converters.end(); ++index) { IOSXClipboardConverter* converter = *index; if (converter->getFormat() == format) { PasteboardFlavorFlags flags; CFStringRef type = converter->getOSXFormat(); OSStatus res; if ((res = PasteboardGetItemFlavorFlags(m_pboard, item, type, &flags)) == noErr) { return true; } } } return false; }
bool QMacPasteboard::hasFlavor(QString c_flavor) const { if (!paste) return false; sync(); ItemCount cnt = 0; if(PasteboardGetItemCount(paste, &cnt) || !cnt) return false; #ifdef DEBUG_PASTEBOARD qDebug("PasteBoard: hasFlavor [%s]", qPrintable(c_flavor)); #endif for(uint index = 1; index <= cnt; ++index) { PasteboardItemID id; if(PasteboardGetItemIdentifier(paste, index, &id) != noErr) return false; PasteboardFlavorFlags flags; if(PasteboardGetItemFlavorFlags(paste, id, QCFString(c_flavor), &flags) == noErr) { #ifdef DEBUG_PASTEBOARD qDebug(" - Found!"); #endif return true; } } #ifdef DEBUG_PASTEBOARD qDebug(" - NotFound!"); #endif return false; }
CString COSXClipboard::get(EFormat format) const { CFStringRef type; PasteboardItemID item; CString result; if (m_pboard == NULL) return result; PasteboardGetItemIdentifier(m_pboard, (CFIndex) 1, &item); // find the converter for the first clipboard format we can handle IOSXClipboardConverter* converter = NULL; for (ConverterList::const_iterator index = m_converters.begin(); index != m_converters.end(); ++index) { converter = *index; PasteboardFlavorFlags flags; type = converter->getOSXFormat(); if (converter->getFormat() == format && PasteboardGetItemFlavorFlags(m_pboard, item, type, &flags) == noErr) { break; } converter = NULL; } // if no converter then we don't recognize any formats if (converter == NULL) { LOG((CLOG_DEBUG "Unable to find converter for data")); return result; } // get the clipboard data. CFDataRef buffer = NULL; try { OSStatus err = PasteboardCopyItemFlavorData(m_pboard, item, type, &buffer); if (err != noErr) { throw err; } result = CString((char *) CFDataGetBytePtr(buffer), CFDataGetLength(buffer)); } catch (OSStatus err) { LOG((CLOG_DEBUG "exception thrown in COSXClipboard::get MacError (%d)", err)); } catch (...) { LOG((CLOG_DEBUG "unknown exception in COSXClipboard::get")); RETHROW_XTHREAD } if (buffer != NULL) CFRelease(buffer); return converter->toIClipboard(result); }