当前位置: 首页>>代码示例>>C++>>正文


C++ PasteboardGetItemIdentifier函数代码示例

本文整理汇总了C++中PasteboardGetItemIdentifier函数的典型用法代码示例。如果您正苦于以下问题:C++ PasteboardGetItemIdentifier函数的具体用法?C++ PasteboardGetItemIdentifier怎么用?C++ PasteboardGetItemIdentifier使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了PasteboardGetItemIdentifier函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sync

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;
}
开发者ID:Afreeca,项目名称:qt,代码行数:34,代码来源:qclipboard_mac.cpp

示例2: PasteboardGetItemIdentifier

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;
}
开发者ID:ryanchapman,项目名称:synergy-mac-bmp-html-pasteboard,代码行数:26,代码来源:OSXClipboard.cpp

示例3: _applegetsnarf

char*
_applegetsnarf(void)
{
	char *s, *t;
	CFArrayRef flavors;
	CFDataRef data;
	CFIndex nflavor, ndata, j;
	CFStringRef type;
	ItemCount nitem;
	PasteboardItemID id;
	PasteboardSyncFlags flags;
	UInt32 i;

/*	fprint(2, "applegetsnarf\n"); */
	qlock(&clip.lk);
	if(clip.apple == nil){
		if(PasteboardCreate(kPasteboardClipboard, &clip.apple) != noErr){
			fprint(2, "apple pasteboard create failed\n");
			qunlock(&clip.lk);
			return nil;
		}
	}
	flags = PasteboardSynchronize(clip.apple);
	if(flags&kPasteboardClientIsOwner){
		s = strdup(clip.buf);
		qunlock(&clip.lk);
		return s;
	}
	if(PasteboardGetItemCount(clip.apple, &nitem) != noErr){
		fprint(2, "apple pasteboard get item count failed\n");
		qunlock(&clip.lk);
		return nil;
	}
	for(i=1; i<=nitem; i++){
		if(PasteboardGetItemIdentifier(clip.apple, i, &id) != noErr)
			continue;
		if(PasteboardCopyItemFlavors(clip.apple, id, &flavors) != noErr)
			continue;
		nflavor = CFArrayGetCount(flavors);
		for(j=0; j<nflavor; j++){
			type = (CFStringRef)CFArrayGetValueAtIndex(flavors, j);
			if(!UTTypeConformsTo(type, CFSTR("public.utf16-plain-text")))
				continue;
			if(PasteboardCopyItemFlavorData(clip.apple, id, type, &data) != noErr)
				continue;
			ndata = CFDataGetLength(data);
			qunlock(&clip.lk);
			s = smprint("%.*S", ndata/2, (Rune*)CFDataGetBytePtr(data));
			CFRelease(flavors);
			CFRelease(data);
			for(t=s; *t; t++)
				if(*t == '\r')
					*t = '\n';
			return s;
		}
		CFRelease(flavors);
	}
	qunlock(&clip.lk);
	return nil;		
}
开发者ID:00001,项目名称:plan9port,代码行数:60,代码来源:x11-itrans.c

示例4: queryNewPasteboardFormats

/**
 * Inspect the global pasteboard for new content. Check if there is some type
 * that is supported by vbox and return it.
 *
 * @param   pPasteboardRef Reference to the global pasteboard.
 * @param   pfFormats      Pointer for the bit combination of the
 *                         supported types.
 * @param   pbChanged      True if something has changed after the
 *                         last call.
 *
 * @returns IPRT status code. (Always VINF_SUCCESS atm.)
 */
int queryNewPasteboardFormats(PasteboardRef pPasteboard, uint32_t *pfFormats, bool *pfChanged)
{
    Log(("queryNewPasteboardFormats\n"));

    OSStatus err = noErr;
    *pfChanged = true;

    PasteboardSyncFlags syncFlags;
    /* Make sure all is in sync */
    syncFlags = PasteboardSynchronize(pPasteboard);
    /* If nothing changed return */
    if (!(syncFlags & kPasteboardModified))
    {
        *pfChanged = false;
        return VINF_SUCCESS;
    }

    /* Are some items in the pasteboard? */
    ItemCount itemCount;
    err = PasteboardGetItemCount(pPasteboard, &itemCount);
    if (itemCount < 1)
        return VINF_SUCCESS;

    /* The id of the first element in the pasteboard */
    int rc = VINF_SUCCESS;
    PasteboardItemID itemID;
    if (!(err = PasteboardGetItemIdentifier(pPasteboard, 1, &itemID)))
    {
        /* Retrieve all flavors in the pasteboard, maybe there
         * is something we can use. */
        CFArrayRef flavorTypeArray;
        if (!(err = PasteboardCopyItemFlavors(pPasteboard, itemID, &flavorTypeArray)))
        {
            CFIndex flavorCount;
            flavorCount = CFArrayGetCount(flavorTypeArray);
            for (CFIndex flavorIndex = 0; flavorIndex < flavorCount; flavorIndex++)
            {
                CFStringRef flavorType;
                flavorType = static_cast <CFStringRef>(CFArrayGetValueAtIndex(flavorTypeArray,
                                                                               flavorIndex));
                /* Currently only unicode supported */
                if (UTTypeConformsTo(flavorType, kUTTypeUTF8PlainText) ||
                    UTTypeConformsTo(flavorType, kUTTypeUTF16PlainText))
                {
                    Log(("Unicode flavor detected.\n"));
                    *pfFormats |= VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT;
                }
                else if (UTTypeConformsTo(flavorType, kUTTypeBMP))
                {
                    Log(("BMP flavor detected.\n"));
                    *pfFormats |= VBOX_SHARED_CLIPBOARD_FMT_BITMAP;
                }
            }
            CFRelease(flavorTypeArray);
        }
    }

    Log(("queryNewPasteboardFormats: rc = %02X\n", rc));
    return rc;
}
开发者ID:svn2github,项目名称:virtualbox,代码行数:72,代码来源:darwin-pasteboard.cpp

示例5: GetFormatCount

bool wxDataObject::HasDataInPasteboard( void * pb )
{
    PasteboardRef pasteboard = (PasteboardRef) pb;
    size_t formatcount = GetFormatCount() + 1;
    wxDataFormat *array = new wxDataFormat[ formatcount ];
    array[0] = GetPreferredFormat();
    GetAllFormats( &array[1] );
    ItemCount itemCount = 0;
    bool hasData = false;

    // we synchronize here once again, so we don't mind which flags get returned
    PasteboardSynchronize( pasteboard );

    OSStatus err = PasteboardGetItemCount( pasteboard, &itemCount );
    if ( err == noErr )
    {
        for (size_t i = 0; !hasData && i < formatcount; i++)
        {
            // go through the data in our order of preference
            wxDataFormat dataFormat = array[ i ];

            for( UInt32 itemIndex = 1; itemIndex <= itemCount && hasData == false ; itemIndex++ )
            {
                PasteboardItemID    itemID = 0;
                CFArrayRef          flavorTypeArray = NULL;
                CFIndex             flavorCount = 0;

                err = PasteboardGetItemIdentifier( pasteboard, itemIndex, &itemID );
                if ( err != noErr )
                    continue;

                err = PasteboardCopyItemFlavors( pasteboard, itemID, &flavorTypeArray );
                if ( err != noErr )
                    continue;
                    
                flavorCount = CFArrayGetCount( flavorTypeArray );

                for( CFIndex flavorIndex = 0; !hasData && flavorIndex < flavorCount ; flavorIndex++ )
                {
                    CFStringRef             flavorType;
          
                    flavorType = (CFStringRef)CFArrayGetValueAtIndex( flavorTypeArray,
                                                                         flavorIndex );

                    wxDataFormat flavorFormat( (wxDataFormat::NativeFormat) flavorType );
 
                    if ( dataFormat == flavorFormat || 
                        dataFormat.GetType() == wxDF_UNICODETEXT && flavorFormat.GetType() == wxDF_TEXT )
                    {
                        hasData = true;
                    }
                }
                CFRelease( flavorTypeArray );
            }
        }
    }
    return hasData;
}
开发者ID:Bluehorn,项目名称:wxPython,代码行数:58,代码来源:dataobj.cpp

示例6: PasteboardSynchronize

bool wxDataObject::IsFormatInPasteboard( void * pb, const wxDataFormat &dataFormat )
{
    PasteboardRef pasteboard = (PasteboardRef) pb;
    bool hasData = false;
    OSStatus err = noErr;
    ItemCount itemCount;

    // we synchronize here once again, so we don't mind which flags get returned
    PasteboardSynchronize( pasteboard );

    err = PasteboardGetItemCount( pasteboard, &itemCount );
    if ( err == noErr )
    {
        for( UInt32 itemIndex = 1; itemIndex <= itemCount && hasData == false ; itemIndex++ )
        {
            PasteboardItemID    itemID;
            CFArrayRef          flavorTypeArray;
            CFIndex             flavorCount;
     
            err = PasteboardGetItemIdentifier( pasteboard, itemIndex, &itemID );
            if ( err != noErr )
                continue;
     
            err = PasteboardCopyItemFlavors( pasteboard, itemID, &flavorTypeArray );
            if ( err != noErr )
                continue;
     
            flavorCount = CFArrayGetCount( flavorTypeArray );
     
            for( CFIndex flavorIndex = 0; flavorIndex < flavorCount && hasData == false ; flavorIndex++ )
            {
                CFStringRef             flavorType;
     
                flavorType = (CFStringRef)CFArrayGetValueAtIndex( flavorTypeArray,
                                                                     flavorIndex );
                     
                wxDataFormat flavorFormat( (wxDataFormat::NativeFormat) flavorType );
                if ( dataFormat == flavorFormat )
                    hasData = true;
                else if (  dataFormat.GetType() == wxDF_UNICODETEXT && flavorFormat.GetType() == wxDF_TEXT )
                    hasData = true;
            }
            CFRelease (flavorTypeArray);
        }
    }

    return hasData;
}
开发者ID:Bluehorn,项目名称:wxPython,代码行数:48,代码来源:dataobj.cpp

示例7: copy_from_clipboard

std::string copy_from_clipboard(const bool)
{
	OSStatus err = noErr;
	PasteboardRef clipboard;
	PasteboardSyncFlags syncFlags;
	ItemCount count;
	err = PasteboardCreate(kPasteboardClipboard, &clipboard);
	if (err != noErr) return "";
	syncFlags = PasteboardSynchronize(clipboard);
	if (syncFlags&kPasteboardModified) return "";
	err = PasteboardGetItemCount(clipboard, &count);
	if (err != noErr) return "";
	for (UInt32 k = 1; k <= count; k++) {
		PasteboardItemID itemID;
		CFArrayRef flavorTypeArray;
		CFIndex flavorCount;
		err = PasteboardGetItemIdentifier(clipboard, k, &itemID);
		if (err != noErr) return "";
		err = PasteboardCopyItemFlavors(clipboard, itemID, &flavorTypeArray);
		if (err != noErr) return "";
		flavorCount = CFArrayGetCount(flavorTypeArray);
		for (CFIndex j = 0; j < flavorCount; j++) {
			CFStringRef flavorType;
			CFDataRef flavorData;
			CFIndex flavorDataSize;
			flavorType = (CFStringRef)CFArrayGetValueAtIndex(flavorTypeArray, j);
			if (UTTypeConformsTo(flavorType, CFSTR("public.utf8-plain-text"))) {
				err = PasteboardCopyItemFlavorData(clipboard, itemID, flavorType, &flavorData);
				if (err != noErr) {
					CFRelease(flavorTypeArray);
					return "";
				}
				flavorDataSize = CFDataGetLength(flavorData);
				std::string str;
				str.reserve(flavorDataSize);
				str.resize(flavorDataSize);
				CFDataGetBytes(flavorData, CFRangeMake(0, flavorDataSize), (UInt8 *)str.data());
				for (unsigned int i = 0; i < str.size(); ++i) {
					if (str[i] == '\r') str[i] = '\n';
				}
				return str;
			}
		}
	}
	return "";
}
开发者ID:Coffee--,项目名称:wesnoth-old,代码行数:46,代码来源:clipboard.cpp

示例8: QStringList

QStringList
QMacPasteboard::formats() const
{
    if (!paste)
        return QStringList();

    sync();

    QStringList ret;
    ItemCount cnt = 0;
    if(PasteboardGetItemCount(paste, &cnt) || !cnt)
        return ret;

#ifdef DEBUG_PASTEBOARD
    qDebug("PasteBoard: Formats [%d]", (int)cnt);
#endif
    for(uint index = 1; index <= cnt; ++index) {

        PasteboardItemID id;
        if(PasteboardGetItemIdentifier(paste, index, &id) != noErr)
            continue;

        QCFType<CFArrayRef> types;
        if(PasteboardCopyItemFlavors(paste, id, &types ) != noErr)
            continue;

        const int type_count = CFArrayGetCount(types);
        for(int i = 0; i < type_count; ++i) {
            const QString flavor = QCFString::toQString((CFStringRef)CFArrayGetValueAtIndex(types, i));
#ifdef DEBUG_PASTEBOARD
            qDebug(" -%s", qPrintable(QString(flavor)));
#endif
            QString mimeType = QMacPasteboardMime::flavorToMime(mime_type, flavor);
            if(!mimeType.isEmpty() && !ret.contains(mimeType)) {
#ifdef DEBUG_PASTEBOARD
                qDebug("   -<%d> %s [%s]", ret.size(), qPrintable(mimeType), qPrintable(QString(flavor)));
#endif
                ret << mimeType;
            }
        }
    }
    return ret;
}
开发者ID:Afreeca,项目名称:qt,代码行数:43,代码来源:qclipboard_mac.cpp

示例9: PasteboardCreate

string ClipBoard::getText() {  
	
#ifdef TARGET_OSX
	
    OSStatus             err = noErr;  
    ItemCount            itemCount;  
    PasteboardSyncFlags  syncFlags;  
    static PasteboardRef inPasteboard = NULL;  
    PasteboardCreate( kPasteboardClipboard, &inPasteboard );  
    char* data;  
    data = NULL;  
	
    syncFlags = PasteboardSynchronize( inPasteboard );  
    err = badPasteboardSyncErr;  
	
    err = PasteboardGetItemCount( inPasteboard, &itemCount );  
    require_noerr( err, CantGetPasteboardItemCount );  
	
    for( int itemIndex = 1; itemIndex <= itemCount; itemIndex++ ) {  
        PasteboardItemID  itemID;  
        CFDataRef  flavorData;  
		
        err = PasteboardGetItemIdentifier( inPasteboard, itemIndex, &itemID );  
        require_noerr( err, CantGetPasteboardItemIdentifier );  
		
        err = PasteboardCopyItemFlavorData( inPasteboard, itemID, CFSTR("public.utf8-plain-text"), &flavorData );         
        data = (char*)CFDataGetBytePtr(flavorData);  
		
	CantGetPasteboardItemIdentifier:  
        ;  
    }  
	
CantGetPasteboardItemCount:  
    return (string) data;
	
#else

	ofLog(OF_LOG_WARNING, "ofxGLEditor: sorry, copying to the system clipboard is not supported on your OS yet");
	return "";

#endif	
}  
开发者ID:decebel,项目名称:dataAtom_alpha,代码行数:42,代码来源:ClipBoard.cpp

示例10: PasteboardSynchronize

char *TCOD_sys_clipboard_get()
{
	PasteboardSyncFlags syncFlags;
	ItemCount itemCount;
	PasteboardRef clipboard;
	UInt32 itemIndex;
	if (PasteboardCreate(kPasteboardClipboard, &clipboard) != noErr) return NULL;
	syncFlags = PasteboardSynchronize(clipboard);
	if (PasteboardGetItemCount(clipboard, &itemCount) != noErr) return NULL;
	if (itemCount == 0) return NULL;
	for(itemIndex = 1; itemIndex <= itemCount; itemIndex++) {
		PasteboardItemID itemID;
		CFArrayRef flavorTypeArray;
		CFIndex flavorCount;
		CFIndex flavorIndex;
		if (PasteboardGetItemIdentifier(clipboard, itemIndex, &itemID ) != noErr) return NULL;
		if (PasteboardCopyItemFlavors(clipboard, itemID, &flavorTypeArray) != noErr) return NULL;
		flavorCount = CFArrayGetCount(flavorTypeArray);
		for(flavorIndex = 0; flavorIndex < flavorCount; flavorIndex++) {
        CFStringRef flavorType;
        CFDataRef flavorData;
        CFIndex flavorDataSize;
				flavorType = (CFStringRef)CFArrayGetValueAtIndex(flavorTypeArray, flavorIndex);
				if (UTTypeConformsTo(flavorType, CFSTR("public.plain-text"))) {
						if (PasteboardCopyItemFlavorData(clipboard, itemID, flavorType, &flavorData) != noErr) {
							CFRelease(flavorData);
							return NULL;
						}
						flavorDataSize = CFDataGetLength( flavorData );
						flavorDataSize = (flavorDataSize<254) ? flavorDataSize : 254;
						short dataIndex;
	          for(dataIndex = 0; dataIndex <= flavorDataSize; dataIndex++) {
	             clipboardText[dataIndex] = *(CFDataGetBytePtr(flavorData) + dataIndex);
	          }
	          clipboardText[flavorDataSize] = '\0';
	          clipboardText[flavorDataSize+1] = '\n';
						CFRelease (flavorData);
	     }
		}
	}
	return clipboardText;
}
开发者ID:chilamkatana,项目名称:ASCIIWar,代码行数:42,代码来源:sys_c.c

示例11: PasteboardCreate

GHOST_TUns8 *GHOST_SystemCarbon::getClipboard(bool selection) const
{
	PasteboardRef inPasteboard;
	PasteboardItemID itemID;
	CFDataRef flavorData;
	OSStatus err = noErr;
	GHOST_TUns8 *temp_buff;
	CFRange range;
	OSStatus syncFlags;
	
	err = PasteboardCreate(kPasteboardClipboard, &inPasteboard);
	if (err != noErr) { return NULL; }

	syncFlags = PasteboardSynchronize(inPasteboard);
	/* as we always get in a new string, we can safely ignore sync flags if not an error*/
	if (syncFlags < 0) { return NULL; }


	err = PasteboardGetItemIdentifier(inPasteboard, 1, &itemID);
	if (err != noErr) { return NULL; }

	err = PasteboardCopyItemFlavorData(inPasteboard, itemID, CFSTR("public.utf8-plain-text"), &flavorData);
	if (err != noErr) { return NULL; }

	range = CFRangeMake(0, CFDataGetLength(flavorData));
	
	temp_buff = (GHOST_TUns8 *) malloc(range.length + 1);

	CFDataGetBytes(flavorData, range, (UInt8 *)temp_buff);
	
	temp_buff[range.length] = '\0';
	
	if (temp_buff) {
		return temp_buff;
	}
	else {
		return NULL;
	}
}
开发者ID:danielmarg,项目名称:blender-main,代码行数:39,代码来源:GHOST_SystemCarbon.cpp

示例12: start_paste

void start_paste(widget_list *widget)
{
	OSStatus err = noErr;
	PasteboardRef gClipboard;
	PasteboardItemID  itemID;
	CFDataRef        flavorData;
	char*          flavorText;

	err = PasteboardCreate( kPasteboardClipboard, &gClipboard );
	//require_noerr( err, CantCreateClipboard );

  	err = PasteboardGetItemIdentifier( gClipboard, 1, &itemID );
	err = PasteboardCopyItemFlavorData( gClipboard, itemID, CFSTR("com.apple.traditional-mac-plain-text"), &flavorData );

	int flavorDataSize = CFDataGetLength(flavorData);
	flavorText=(char*)malloc(flavorDataSize+1);

	short dataIndex;
	for(dataIndex = 0; dataIndex <= flavorDataSize; dataIndex++ )
	{
		char byte = *(CFDataGetBytePtr( flavorData ) + dataIndex);
		flavorText[dataIndex] = (byte>32) ? byte : ' ';
	}
	flavorText[flavorDataSize] = '\0';
	CFRelease(flavorData);
	if (widget == NULL)
	{
		do_paste (flavorText);
	}
	else
	{
		do_paste_to_text_field(widget, flavorText);
	}

	free(flavorText);
	CFRelease( gClipboard );
}
开发者ID:Sir-Odie,项目名称:Eternal-Lands,代码行数:37,代码来源:paste.c

示例13: PasteboardGetItemCount

oop QuartzWindow::get_scrap_text() {
  // See Pasteboard Manager Programming guide
  PasteboardRef       clipboard;
  PasteboardSyncFlags syncFlags;
  CFDataRef           textData = NULL;
  ItemCount           itemCount;
  
  if ( PasteboardCreate(kPasteboardClipboard, &clipboard) != noErr
  ||  (PasteboardSynchronize(clipboard) & kPasteboardModified)
  ||   PasteboardGetItemCount(clipboard, &itemCount) != noErr  ) 
    return new_string("", 0);
  
  for( UInt32 itemIndex = 1; itemIndex <= itemCount; itemIndex++ ) {
    PasteboardItemID itemID = 0;
    CFArrayRef       flavorTypeArray = NULL;
    CFIndex          flavorCount = 0;

    if (PasteboardGetItemIdentifier(clipboard, itemIndex, &itemID) != noErr)
      continue;
  
    if (PasteboardCopyItemFlavors(clipboard, itemID, &flavorTypeArray) != noErr)
      continue;

    flavorCount = CFArrayGetCount(flavorTypeArray);
     
    for(CFIndex flavorIndex = 0; flavorIndex < flavorCount; flavorIndex++) {
      CFStringRef flavorType;
      CFDataRef   flavorData;
      CFIndex     flavorDataSize;
      char        flavorText[256];
      
      
      flavorType = (CFStringRef)CFArrayGetValueAtIndex( flavorTypeArray,// 6
                                                       flavorIndex );
      
      if (UTTypeConformsTo(flavorType, kUTTypeOldMacText)) {
        
        if (PasteboardCopyItemFlavorData(clipboard, itemID, flavorType, 
                                         &flavorData) != noErr)
          continue;
          
        flavorDataSize = CFDataGetLength(flavorData);

        // allocate new string.
        byteVectorOop r = Memory->byteVectorObj->cloneSize(flavorDataSize, CANFAIL);
        if (r->is_mark()) {
          CFRelease (flavorData);
          CFRelease (flavorTypeArray);
          return new_string("", 0);
        }
        // copy over
        CFDataGetBytes(flavorData, CFRangeMake(0,CFDataGetLength(flavorData)),
                       (UInt8 *)r->bytes());          
        CFRelease(flavorData);
        CFRelease(flavorTypeArray);
        return r;
      } // else try next      
    }
    CFRelease(flavorTypeArray);
  }  
  
}
开发者ID:ardeujho,项目名称:self,代码行数:62,代码来源:quartzWindow.cpp

示例14: GetClipboardData

//******************************************************************************
bool CClipboard::GetString(
//Copies the system clipboard string into sClip
//Returns: true on success, false otherwise.
//
//Params:
	WSTRING& sClip) //(out)
{
#ifdef WIN32
	if (!OpenClipboard(NULL))
		return false;
	HGLOBAL global = GetClipboardData(CF_UNICODETEXT);
	if (global == NULL) {
		CloseClipboard();
		return false;
	}
	LPWSTR data = (LPWSTR)GlobalLock(global);
	sClip = data;
	GlobalUnlock(global);
	CloseClipboard();

	return true;

#elif defined __APPLE__
	PasteboardRef theClipboard;
    	OSStatus err = PasteboardCreate(kPasteboardClipboard, &theClipboard);
	if (err != noErr)
		return false;

	ItemCount itemCount;
	PasteboardSynchronize(theClipboard);
	PasteboardGetItemCount(theClipboard, &itemCount);
	UInt32 itemIndex = 1;

	PasteboardItemID itemID;
	PasteboardGetItemIdentifier(theClipboard, itemIndex, &itemID);

	CFArrayRef flavorTypeArray;
	PasteboardCopyItemFlavors(theClipboard, itemID, &flavorTypeArray);

	CFIndex flavorCount = CFArrayGetCount(flavorTypeArray);

	for (CFIndex flavorIndex = 0; flavorIndex < flavorCount; flavorIndex++)
	{
		CFStringRef flavorType = (CFStringRef)CFArrayGetValueAtIndex(flavorTypeArray, flavorIndex);

		if (UTTypeConformsTo(flavorType, CFSTR("public.utf8-plain-text")))
		{
			CFDataRef flavorData;
			PasteboardCopyItemFlavorData(theClipboard, itemID, flavorType, &flavorData);

			//CFIndex flavorDataSize = CFDataGetLength(flavorData);
 			const string str = (char*)CFDataGetBytePtr(flavorData);
			UTF8ToUCS2(str.c_str(), str.size(), sClip);
			CFRelease(flavorData);
			break;
		}
	}
	CFRelease (flavorTypeArray);

	return true;

#elif defined(__linux__) || defined(__FreeBSD__)
	string u8clip;
	bool bSuccess;
	if ((bSuccess = GetStringUTF8(u8clip)))
		UTF8ToUCS2(u8clip.c_str(), u8clip.length(), sClip);
	return bSuccess;

#elif defined(__native_client__)
	// Do nothing.
	return false;
#else
#error CClipboard::GetString -- Unicode not implemented
#endif
}
开发者ID:binji,项目名称:drod-nacl,代码行数:76,代码来源:Clipboard.cpp

示例15: osx_driver_getclipboard_loop

static void
osx_driver_getclipboard_loop(
	struct ts_display_t *display,
	struct ts_display_t *to)
{
	if (!clip)
		PasteboardCreate(kPasteboardClipboard, &clip);
	if (!clip)
		return;

	ts_clipboard_clear(&display->clipboard);

	CFDataRef cfdata;
	OSStatus err = noErr;
	ItemCount nItems;
	uint32_t i;

	PasteboardSynchronize(clip);
	if ((err = PasteboardGetItemCount(clip, &nItems)) != noErr) {
		V1("apple pasteboard GetItemCount failed\n");
		return;
	}

	for (i = 1; i <= nItems; ++i) {
		PasteboardItemID itemID;
		CFArrayRef flavorTypeArray;
		CFIndex flavorCount;

		if ((err = PasteboardGetItemIdentifier(clip, i, &itemID)) != noErr) {
			V1("can't get pasteboard item identifier\n");
			return;
		}

		if ((err = PasteboardCopyItemFlavors(clip, itemID,
		        &flavorTypeArray)) != noErr) {
			V1("Can't copy pasteboard item flavors\n");
			return;
		}

		flavorCount = CFArrayGetCount(flavorTypeArray);
		CFIndex flavorIndex;
		for (flavorIndex = 0; flavorIndex < flavorCount; ++flavorIndex) {
			CFStringRef flavorType;
			flavorType = (CFStringRef) CFArrayGetValueAtIndex(flavorTypeArray,
			        flavorIndex);
			if (UTTypeConformsTo(flavorType, CFSTR("public.utf8-plain-text"))) {
				if ((err = PasteboardCopyItemFlavorData(clip, itemID,
				        CFSTR("public.utf8-plain-text"), &cfdata)) != noErr) {
					V1("apple pasteboard CopyItem failed\n");
					return;
				}
				CFIndex length = CFDataGetLength(cfdata);
				uint8_t * data = malloc(length + 1);

				CFDataGetBytes(cfdata, CFRangeMake(0, length), data);
				data[length] = 0;
				V1 ("%s DATA %d!! '%s'\n", __func__, (int)length, data);
				ts_clipboard_add(&display->clipboard, "text", data, length);

				CFRelease(cfdata);
			}
		}
		CFRelease(flavorTypeArray);
	}
	if (display->clipboard.flavorCount)
		ts_display_setclipboard(
				to,
				&display->clipboard);
}
开发者ID:buserror,项目名称:touchstream,代码行数:69,代码来源:ts_osx_clipboard.c


注:本文中的PasteboardGetItemIdentifier函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。