• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PasteboardCreate函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: clipboard_push_text

void clipboard_push_text(char * text)
{
#ifdef MACOSX
	PasteboardRef newclipboard;

	if (PasteboardCreate(kPasteboardClipboard, &newclipboard)!=noErr) return;
	if (PasteboardClear(newclipboard)!=noErr) return;
	PasteboardSynchronize(newclipboard);

	CFDataRef data = CFDataCreate(kCFAllocatorDefault, text, strlen(text));
	PasteboardPutItemFlavor(newclipboard, (PasteboardItemID)1, CFSTR("com.apple.traditional-mac-plain-text"), data, 0);
#elif defined WIN32
	if (OpenClipboard(NULL))
	{
		HGLOBAL cbuffer;
		char * glbuffer;

		EmptyClipboard();

		cbuffer = GlobalAlloc(GMEM_DDESHARE, strlen(text)+1);
		glbuffer = (char*)GlobalLock(cbuffer);

		strcpy(glbuffer, text);

		GlobalUnlock(cbuffer);
		SetClipboardData(CF_TEXT, cbuffer);
		CloseClipboard();
	}
#else
	printf("Not implemented: put text on clipboard \"%s\"\n", text);
#endif
}
开发者ID:321boom,项目名称:The-Powder-Toy,代码行数:32,代码来源:misc.c


示例2: RomInfoCopyToClipboard

static void RomInfoCopyToClipboard (void)
{
	OSStatus			err;
	PasteboardRef		clipboard;
	PasteboardSyncFlags	sync;
	CFDataRef			cfdata;
	char				text[1024];

	RomInfoBuildInfoText(text);

	err = PasteboardCreate(kPasteboardClipboard, &clipboard);
	if (err == noErr)
	{
		err = PasteboardClear(clipboard);
		if (err == noErr)
		{
			sync = PasteboardSynchronize(clipboard);
			if (!(sync & kPasteboardModified) && (sync & kPasteboardClientIsOwner))
			{
				cfdata = CFDataCreate(kCFAllocatorDefault, (UInt8 *) text, (CFIndex) strlen(text));
				if (cfdata)
				{
					err = PasteboardPutItemFlavor(clipboard, (PasteboardItemID) 1, CFSTR("com.apple.traditional-mac-plain-text"), cfdata, 0);
					CFRelease(cfdata);
				}
			}
		}

		CFRelease(clipboard);
	}
}
开发者ID:OV2,项目名称:snes9x-libsnes,代码行数:31,代码来源:mac-dialog.cpp


示例3: PasteboardCreate

void GHOST_SystemCarbon::putClipboard(GHOST_TInt8 *buffer, bool selection) const
{
	if (selection) {return; } // for copying the selection, used on X11

	PasteboardRef inPasteboard;
	CFDataRef textData = NULL;
	OSStatus err = noErr; /*For error checking*/
	OSStatus syncFlags;
	
	err = PasteboardCreate(kPasteboardClipboard, &inPasteboard);
	if (err != noErr) { return; }
	
	syncFlags = PasteboardSynchronize(inPasteboard);
	/* as we always put in a new string, we can safely ignore sync flags */
	if (syncFlags < 0) { return; }
	
	err = PasteboardClear(inPasteboard);
	if (err != noErr) { return; }
	
	textData = CFDataCreate(kCFAllocatorDefault, (UInt8 *)buffer, strlen(buffer));
	
	if (textData) {
		err = PasteboardPutItemFlavor(inPasteboard, (PasteboardItemID)1, CFSTR("public.utf8-plain-text"), textData, 0);
		if (err != noErr) {
			if (textData) { CFRelease(textData); }
			return;
		}
	}
	
	if (textData) {
		CFRelease(textData);
	}
}
开发者ID:danielmarg,项目名称:blender-main,代码行数:33,代码来源:GHOST_SystemCarbon.cpp


示例4: PasteboardCreate

bool ClipBoard::setText(const string text) {  
	
#ifdef TARGET_OSX

    OSStatus                err = noErr;  
    static PasteboardRef    pasteboard = NULL;  
    PasteboardCreate( kPasteboardClipboard, &pasteboard );  
	
    err = PasteboardClear( pasteboard );  
    require_noerr( err, PasteboardClear_FAILED );  
	
    CFDataRef  data;  
	
    data = CFDataCreate(kCFAllocatorDefault, (UInt8*) text.c_str(), strlen(text.c_str())+1);  
    err = PasteboardPutItemFlavor( pasteboard, (PasteboardItemID)1, kUTTypeUTF8PlainText, data, 0);   
    require_noerr( err, PasteboardPutItemFlavor_FAILED );  
	
	return true;
	
PasteboardPutItemFlavor_FAILED: 
	ofLog(OF_LOG_ERROR, "ofxGLEditor: pasting from the pasteboard failed");
	return false;
	
PasteboardClear_FAILED:
	ofLog(OF_LOG_ERROR, "ofxGLEditor: clearing the cliboard failed");
    return false;
	
#else
	
	ofLog(OF_LOG_WARNING, "ofxGLEditor: sorry, pasting from the system clipboard is not supported on your OS yet");
	return true;

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


示例5: _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


示例6: copy_to_clipboard

void copy_to_clipboard(const std::string& text, const bool)
{
	std::string new_str;
	new_str.reserve(text.size());
	for (unsigned int i = 0; i < text.size(); ++i)
	{
		if (text[i] == '\n')
		{
			new_str.push_back('\r');
		} else {
			new_str.push_back(text[i]);
		}
	}
	OSStatus err = noErr;
	PasteboardRef clipboard;
	PasteboardSyncFlags syncFlags;
	CFDataRef textData = NULL;
	err = PasteboardCreate(kPasteboardClipboard, &clipboard);
	if (err != noErr) return;
	err = PasteboardClear(clipboard);
	if (err != noErr) return;
	syncFlags = PasteboardSynchronize(clipboard);
	if ((syncFlags&kPasteboardModified) && !(syncFlags&kPasteboardClientIsOwner)) return;
	textData = CFDataCreate(kCFAllocatorDefault, (const UInt8 *)new_str.c_str(), text.size());
	PasteboardPutItemFlavor(clipboard, (PasteboardItemID)1, CFSTR("public.utf8-plain-text"), textData, 0);
}
开发者ID:Coffee--,项目名称:wesnoth-old,代码行数:26,代码来源:clipboard.cpp


示例7: m_time

COSXClipboard::COSXClipboard() :
	m_time(0),
	m_pboard(NULL)
{
	m_converters.push_back(new COSXClipboardHTMLConverter);
	m_converters.push_back(new COSXClipboardBMPConverter);
	m_converters.push_back(new COSXClipboardUTF16Converter);
	m_converters.push_back(new COSXClipboardTextConverter);



	OSStatus createErr = PasteboardCreate(kPasteboardClipboard, &m_pboard);
	if (createErr != noErr) {
		LOG((CLOG_DEBUG "failed to create clipboard reference: error %i", createErr));
		LOG((CLOG_ERR "unable to connect to pasteboard, clipboard sharing disabled", createErr));
		m_pboard = NULL;
		return;

	}

	OSStatus syncErr = PasteboardSynchronize(m_pboard);
	if (syncErr != noErr) {
		LOG((CLOG_DEBUG "failed to syncronize clipboard: error %i", syncErr));
	}
}
开发者ID:BogdanLivadariu,项目名称:synergy,代码行数:25,代码来源:OSXClipboard.cpp


示例8: Picture_copyToClipboard

void Picture_copyToClipboard (Picture me) {
	/*
	 * Find the clipboard and clear it.
	 */
	PasteboardRef clipboard = nullptr;
	PasteboardCreate (kPasteboardClipboard, & clipboard);
	PasteboardClear (clipboard);
	/*
	 * Add a PDF flavour to the clipboard.
	 */
	static CGDataConsumerCallbacks callbacks = { appendBytes, nullptr };
	CFDataRef data = CFDataCreateMutable (kCFAllocatorDefault, 0);
	CGDataConsumerRef consumer = CGDataConsumerCreate ((void *) data, & callbacks);
	int resolution = 600;
	CGRect rect = CGRectMake (0, 0, (my selx2 - my selx1) * resolution, (my sely1 - my sely2) * resolution);
	CGContextRef context = CGPDFContextCreate (consumer, & rect, nullptr);
	//my selx1 * RES, (12 - my sely2) * RES, my selx2 * RES, (12 - my sely1) * RES)
	{// scope
		autoGraphics graphics = Graphics_create_pdf (context, resolution, my selx1, my selx2, my sely1, my sely2);
		Graphics_play (my graphics.get(), graphics.get());
	}
	PasteboardPutItemFlavor (clipboard, (PasteboardItemID) 1, kUTTypePDF, data, kPasteboardFlavorNoFlags);
	CFRelease (data);
	/*
	 * Forget the clipboard.
	 */
	CFRelease (clipboard);
}
开发者ID:DsRQuicke,项目名称:praat,代码行数:28,代码来源:Picture.cpp


示例9: shoes_init

shoes_code
shoes_init(SHOES_INIT_ARGS)
{
#ifdef SHOES_GTK
  gtk_init(NULL, NULL);
#endif
#ifdef SHOES_WIN32
  INITCOMMONCONTROLSEX InitCtrlEx;
  InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
  InitCtrlEx.dwICC = ICC_PROGRESS_CLASS;
  InitCommonControlsEx(&InitCtrlEx);
#else
  signal(SIGINT,  shoes_sigint);
  signal(SIGQUIT, shoes_sigint);
#endif
  ruby_init();
  shoes_ruby_init();
  shoes_world = shoes_world_alloc();
#ifdef SHOES_QUARTZ
  shoes_app_quartz_install();
  shoes_slot_quartz_register();
  if (PasteboardCreate(kPasteboardClipboard, &shoes_world->os.clip) != noErr) {
    INFO("Apple Pasteboard create failed.\n");
  }
#endif
#ifdef SHOES_WIN32
  shoes_world->os.instance = inst;
  shoes_world->os.style = style;
  shoes_classex_init();
#endif
  return SHOES_OK;
}
开发者ID:danorine,项目名称:shoes,代码行数:32,代码来源:world.c


示例10: initPasteboard

/**
 * Initialize the global pasteboard and return a reference to it.
 *
 * @param pPasteboardRef Reference to the global pasteboard.
 *
 * @returns IPRT status code.
 */
int initPasteboard(PasteboardRef *pPasteboardRef)
{
    int rc = VINF_SUCCESS;

    if (PasteboardCreate(kPasteboardClipboard, pPasteboardRef))
        rc = VERR_NOT_SUPPORTED;

    return rc;
}
开发者ID:svn2github,项目名称:virtualbox,代码行数:16,代码来源:darwin-pasteboard.cpp


示例11: EmptyClipboard

//******************************************************************************
bool CClipboard::SetString(
//Copies the given string into the system clipboard
//Returns: true on success, false otherwise.
//
//Params:
	const WSTRING& sClip)  //(in)
{
#ifdef WIN32
	if (!OpenClipboard(NULL))
		return false;
	EmptyClipboard();

	HGLOBAL global = GlobalAlloc(GMEM_ZEROINIT, (sClip.size()+1)*sizeof(WCHAR));

	if (global == NULL) {
		CloseClipboard();
		return false;
	}

	LPWSTR data = (LPWSTR)GlobalLock(global);

	WCScpy(data, sClip.c_str());

	GlobalUnlock(global);
	SetClipboardData(CF_UNICODETEXT, global);
	CloseClipboard();

	return true;
#elif defined(__APPLE__)
	PasteboardRef theClipboard;
    	OSStatus err = PasteboardCreate(kPasteboardClipboard, &theClipboard);
	if (err != noErr)
		return false;
	PasteboardClear(theClipboard);
	PasteboardSynchronize(theClipboard);
	BYTE *pbOutStr = NULL;
	if (to_utf8(sClip.c_str(), pbOutStr)) {
		CFDataRef data = CFDataCreate(kCFAllocatorDefault, (UInt8*)pbOutStr, sClip.size() + 1);
		PasteboardPutItemFlavor(theClipboard, (PasteboardItemID)1, CFSTR("public.utf8-plain-text"), data, 0);
	}
	delete[] pbOutStr;
	return true;
#elif defined(__linux__) || defined(__FreeBSD__)
	bool bSuccess = false;
	BYTE *pbOutStr = NULL;
	if (to_utf8(sClip.c_str(), pbOutStr))
		bSuccess = SetStringUTF8((const char*)pbOutStr);
	delete[] pbOutStr;
	return bSuccess;

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


示例12: EmptyClipboard

void g2LabelEdit::CopyBuffer()
{
    // Win32 implementation
    #ifdef _WIN32
    
        // Attempt to open clipboard
        if(!OpenClipboard(GetForegroundWindow()))
            return;
        
        // Empty current clipboard
        EmptyClipboard();
        
        // Allocate a system resource (a memory buffer for the text)
        HGLOBAL TextHandle = GlobalAlloc(GMEM_MOVEABLE, (strlen(TextBuffer) + 1) * sizeof(char));
        if(TextHandle == NULL)
            return;
        
        LPTSTR StringLock = (LPTSTR)GlobalLock(TextHandle);
        if(StringLock == NULL)
            return;
        strcpy(StringLock, TextBuffer);
        GlobalUnlock(TextHandle);
        
        // Copy to the clipboard
        SetClipboardData(CF_TEXT, TextHandle);
        
        // Close clipboard
        CloseClipboard();
    
    // OSX implementation
    #elif __APPLE__
    
        // Allocate or get a reference to the application's active clipboard
        PasteboardRef ClipboardHandle;
        if(PasteboardCreate(kPasteboardClipboard, &ClipboardHandle) != noErr)
            return;
        
        // Clear current clipboard
        if(PasteboardClear(ClipboardHandle) != noErr)
            return;
        
        // Explicitly update (after cleaning is important)
        PasteboardSynchronize(ClipboardHandle);
        
        // Create a system-wide buffer to give to the clipboard
        CFDataRef DataBuffer = CFDataCreate(kCFAllocatorDefault, (const UInt8*)TextBuffer, CFIndex((strlen(TextBuffer) + 1) * sizeof(char)));
        if(DataBuffer == NULL)
            return;
        
        // Paste into clipboard
        PasteboardPutItemFlavor(ClipboardHandle, (PasteboardItemID)1, CFSTR("public.utf8-plain-text"), DataBuffer, kPasteboardFlavorNoFlags);
    
    // Not a feature in Linux...
    #endif
}
开发者ID:RahulRachuri,项目名称:volume-visualization,代码行数:55,代码来源:g2LabelEdit.cpp


示例13: PasteboardCreate

wxClipboard::wxClipboard()
{
    m_open = false;
    m_data = NULL ;
    PasteboardRef clipboard = 0;
    OSStatus err = PasteboardCreate( kPasteboardClipboard, &clipboard );
    if (err != noErr)
    {
        wxLogSysError( wxT("Failed to create the clipboard.") );
    }
    m_pasteboard.reset(clipboard);
}
开发者ID:CyberIntelMafia,项目名称:clamav-devel,代码行数:12,代码来源:clipbrd.cpp


示例14: uchar

QMacPasteboard::QMacPasteboard(CFStringRef name, uchar mt)
{
    mac_mime_source = false;
    mime_type = mt ? mt : uchar(QMacPasteboardMime::MIME_ALL);
    paste = 0;
    OSStatus err = PasteboardCreate(name, &paste);
    if(err == noErr) {
        PasteboardSetPromiseKeeper(paste, promiseKeeper, this);
    } else {
        qDebug("PasteBoard: Error creating pasteboard: %s [%d]", QCFString::toQString(name).toLatin1().constData(), (int)err);
    }
}
开发者ID:Afreeca,项目名称:qt,代码行数:12,代码来源:qclipboard_mac.cpp


示例15: QuartzBitmap_Output

void QuartzBitmap_Output(QuartzDesc_t dev, QuartzBitmapDevice *qbd)
{
    if(qbd->path && qbd->uti) {
        /* On 10.4+ we can employ the CGImageDestination API to create a
           variety of different bitmap formats */
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
	char buf[PATH_MAX+1];
	snprintf(buf, PATH_MAX, qbd->path, qbd->page); buf[PATH_MAX] = '\0';
        CFStringRef pathString = CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8*) buf, strlen(buf), kCFStringEncodingUTF8, FALSE);
        CFURLRef path;
        if(CFStringFind(pathString, CFSTR("://"), 0).location != kCFNotFound) {
            CFStringRef pathEscaped = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, pathString, NULL, NULL, kCFStringEncodingUTF8);
            path = CFURLCreateWithString(kCFAllocatorDefault, pathEscaped, NULL);
            CFRelease(pathEscaped);
        } else {
            path = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8*) buf, strlen(buf), FALSE);
        }
        CFRelease(pathString);

        CFStringRef scheme = CFURLCopyScheme(path);
       	CFStringRef type  = CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8*) qbd->uti, strlen(qbd->uti), kCFStringEncodingUTF8, FALSE);
    	CGImageRef image = CGBitmapContextCreateImage(qbd->bitmap);
        if(CFStringCompare(scheme,CFSTR("file"), 0) == 0) { /* file output */
            CGImageDestinationRef dest = CGImageDestinationCreateWithURL(path, type, 1, NULL);
	    if(dest) {
		CGImageDestinationAddImage(dest, image, NULL);
		CGImageDestinationFinalize(dest);
		CFRelease(dest);
	    } else 
		error(_("QuartzBitmap_Output - unable to open file '%s'"), buf);
        } else if(CFStringCompare(scheme, CFSTR("clipboard"), 0) == 0) { /* clipboard output */
            CFMutableDataRef      data = CFDataCreateMutable(kCFAllocatorDefault, 0);
            CGImageDestinationRef dest = CGImageDestinationCreateWithData(data, type, 1, NULL);
            CGImageDestinationAddImage(dest, image, NULL);
            CGImageDestinationFinalize(dest);
            CFRelease(dest);
            PasteboardRef pb = NULL;
            if(PasteboardCreate(kPasteboardClipboard, &pb) == noErr) {
                PasteboardClear(pb);
                PasteboardSynchronize(pb);
                PasteboardPutItemFlavor(pb, (PasteboardItemID) 1, type, data, 0);
            }
            CFRelease(data);
        } else
            warning(_("not a supported scheme, no image data written"));
        CFRelease(scheme);
       	CFRelease(type);
        CFRelease(path);
        CFRelease(image);
#endif
    }
}
开发者ID:Bgods,项目名称:r-source,代码行数:52,代码来源:qdBitmap.c


示例16: CFDataCreate

int QuartzWindow::put_scrap_text(const char* s, int len) {
  // See Pasteboard Manager Programming guide
  PasteboardRef clipboard;
  OSStatus      err;
  CFDataRef     textData = CFDataCreate(kCFAllocatorDefault, 
                                        (const UInt8*)s, len);
  if (textData == NULL) return -1;
  if ((err = PasteboardCreate(kPasteboardClipboard, &clipboard)) != noErr) return err;
  if ((err = PasteboardClear(clipboard)) != noErr) return err;

  return PasteboardPutItemFlavor(clipboard, (PasteboardItemID)s, 
                                 kUTTypeOldMacText, textData, 
                                 kPasteboardFlavorNoFlags);
  
}
开发者ID:ardeujho,项目名称:self,代码行数:15,代码来源:quartzWindow.cpp


示例17: _appleputsnarf

void
_appleputsnarf(char *s)
{
	CFDataRef cfdata;
	PasteboardSyncFlags flags;

/*	fprint(2, "appleputsnarf\n"); */

	if(strlen(s) >= SnarfSize)
		return;
	qlock(&clip.lk);
	strcpy(clip.buf, s);
	runesnprint(clip.rbuf, nelem(clip.rbuf), "%s", s);
	if(clip.apple == nil){
		if(PasteboardCreate(kPasteboardClipboard, &clip.apple) != noErr){
			fprint(2, "apple pasteboard create failed\n");
			qunlock(&clip.lk);
			return;
		}
	}
	if(PasteboardClear(clip.apple) != noErr){
		fprint(2, "apple pasteboard clear failed\n");
		qunlock(&clip.lk);
		return;
	}
	flags = PasteboardSynchronize(clip.apple);
	if((flags&kPasteboardModified) || !(flags&kPasteboardClientIsOwner)){
		fprint(2, "apple pasteboard cannot assert ownership\n");
		qunlock(&clip.lk);
		return;
	}
	cfdata = CFDataCreate(kCFAllocatorDefault, 
		(uchar*)clip.rbuf, runestrlen(clip.rbuf)*2);
	if(cfdata == nil){
		fprint(2, "apple pasteboard cfdatacreate failed\n");
		qunlock(&clip.lk);
		return;
	}
	if(PasteboardPutItemFlavor(clip.apple, (PasteboardItemID)1,
		CFSTR("public.utf16-plain-text"), cfdata, 0) != noErr){
		fprint(2, "apple pasteboard putitem failed\n");
		CFRelease(cfdata);
		qunlock(&clip.lk);
		return;
	}
	/* CFRelease(cfdata); ??? */
	qunlock(&clip.lk);
}
开发者ID:00001,项目名称:plan9port,代码行数:48,代码来源:x11-itrans.c


示例18: 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


示例19: copy_to_clipboard

void copy_to_clipboard(const char* text)
{
	OSStatus err = noErr;
	PasteboardRef gClipboard;
	CFDataRef textData;

	err = PasteboardCreate( kPasteboardClipboard, &gClipboard );
	err = PasteboardClear( gClipboard );

	// allocate data based on the size of the selection
	textData = CFDataCreate( kCFAllocatorSystemDefault, (UInt8*)text, strlen(text));

	// add text data to the pasteboard
	err = PasteboardPutItemFlavor( gClipboard, (PasteboardItemID)1,
		CFSTR("com.apple.traditional-mac-plain-text"), textData, 0 );
	CFRelease(textData);
	CFRelease( gClipboard );
}
开发者ID:Sir-Odie,项目名称:Eternal-Lands,代码行数:18,代码来源:paste.c


示例20: osx_driver_setclipboard_loop

void
osx_driver_setclipboard_loop(
		struct ts_display_t *d,
		ts_clipboard_p clipboard)
{
	if (!clip)
		PasteboardCreate(kPasteboardClipboard, &clip);

	if (!clipboard->flavorCount)
		return;

	for (int i = 0; i < clipboard->flavorCount; i++) {
		if (!strcmp(clipboard->flavor[i].name, "text")) {
			V1("%s adding %d bytes of %s\n", __func__,
					(int)clipboard->flavor[i].size, clipboard->flavor[i].name);
			if (PasteboardClear(clip) != noErr) {
				V1("apple pasteboard clear failed");
				return;
			}
			PasteboardSyncFlags flags = PasteboardSynchronize(clip);
			if ((flags & kPasteboardModified) || !(flags & kPasteboardClientIsOwner)) {
				V1("apple pasteboard cannot assert ownership");
				return;
			}
			CFDataRef cfdata = CFDataCreate(kCFAllocatorDefault,
					(uint8_t*)clipboard->flavor[i].data,
					clipboard->flavor[i].size);

			if (cfdata == nil) {
				V1("apple pasteboard cfdatacreate failed");
				return;
			}
			if (PasteboardPutItemFlavor(clip, (PasteboardItemID) 1,
			        CFSTR("public.utf8-plain-text"), cfdata, 0) != noErr) {
				V1("apple pasteboard putitem failed");
				CFRelease(cfdata);
			}
			CFRelease(cfdata);
			return;
		}
	}
}
开发者ID:buserror,项目名称:touchstream,代码行数:42,代码来源:ts_osx_clipboard.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PasteboardGetItemIdentifier函数代码示例发布时间:2022-05-30
下一篇:
C++ Paste函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap