long MyGetScrap(Handle hDest, ResType theType)
{
	// returns the length
	// If the handle is not nil, it sizes handle to hold the data and fills in the data 
	#if TARGET_API_MAC_CARBON
		ScrapRef scrapRef;
		ScrapFlavorType flavorType  = theType;
		Size byteCount,numBytesAllocated;
		OSStatus err = GetCurrentScrap (&scrapRef);
		if(err) return 0;
		//
		err = GetScrapFlavorSize(scrapRef,flavorType,&byteCount);
		if(err) return 0;
		if(byteCount == 0) return 0;
		
		if(hDest) { // then the caller wants the data filled in (
			_SetHandleSize(hDest,byteCount);
			numBytesAllocated = _GetHandleSize(hDest); // _MemError();
			if(byteCount != numBytesAllocated){// we had a memory err, the requested space was not allocated
				SysBeep(5);return(0);
			}
			
			_HLock(hDest);
			err = GetScrapFlavorData(scrapRef,flavorType,&byteCount,*hDest);
			_HUnlock(hDest);
			
			if(err) return 0;
		}
		
		return byteCount;
	#else
		long offset; // note: returned value is not used
		return GetScrap(hDest, theType, &offset);
	#endif
}
Beispiel #2
0
bool MCScreenDC::ownsclipboard(void)
{
	// If m_current_scrap is NULL, then we haven't set the clipboard ourselves
	if (m_current_scrap == NULL)
		return false;

	// Fetch the current scrap references
	ScrapRef t_new_scrap;
	if (GetCurrentScrap(&t_new_scrap) != noErr)
		t_new_scrap = NULL;

	// If its changed, then we no longer own the clipboard so reset our
	// internal data
	if (t_new_scrap != m_current_scrap)
	{
		m_current_scrap = NULL;
		if (m_current_scrap_data != NULL)
		{
			delete m_current_scrap_data;
			m_current_scrap_data = NULL;
		}

		return false;
	}

	return true;
}
Beispiel #3
0
void GetScrap(void **handle, uint32 type, int32 offset)
{
#if defined(__LP64__)
	D(bug("GetScrap handle %p, type %08x, offset %d\n", handle, type, offset));
	#warning Carbon scrapbook function are not implemented in 64-bit mode
#else
	D(bug("GetScrap handle %p, type %08x, offset %d\n", handle, type, offset));
	ScrapRef theScrap;

	if (GetCurrentScrap(&theScrap) != noErr) {
		D(bug(" could not open scrap\n"));
		return;
	}

	Size byteCount;
	if (GetScrapFlavorSize(theScrap, type, &byteCount) == noErr) {

		// Allocate space for new scrap in MacOS side
		M68kRegisters r;
		r.d[0] = byteCount;
		Execute68kTrap(0xa71e, &r);				// NewPtrSysClear()
		uint32 scrap_area = r.a[0];

		// Get the native clipboard data
		if (scrap_area) {
			uint8 * const data = Mac2HostAddr(scrap_area);
			if (GetScrapFlavorData(theScrap, type, &byteCount, data) == noErr) {
				SwapScrapData(type, data, byteCount, FALSE);
				// Add new data to clipboard
				static uint8 proc[] = {
					0x59, 0x8f,					// subq.l	#4,sp
					0xa9, 0xfc,					// ZeroScrap()
					0x2f, 0x3c, 0, 0, 0, 0,		// move.l	#length,-(sp)
					0x2f, 0x3c, 0, 0, 0, 0,		// move.l	#type,-(sp)
					0x2f, 0x3c, 0, 0, 0, 0,		// move.l	#outbuf,-(sp)
					0xa9, 0xfe,					// PutScrap()
					0x58, 0x8f,					// addq.l	#4,sp
					M68K_RTS >> 8, M68K_RTS & 0xff
				};
				r.d[0] = sizeof(proc);
				Execute68kTrap(0xa71e, &r);		// NewPtrSysClear()
				uint32 proc_area = r.a[0];

				if (proc_area) {
					Host2Mac_memcpy(proc_area, proc, sizeof(proc));
					WriteMacInt32(proc_area +  6, byteCount);
					WriteMacInt32(proc_area + 12, type);
					WriteMacInt32(proc_area + 18, scrap_area);
					we_put_this_data = true;
					Execute68k(proc_area, &r);

					r.a[0] = proc_area;
					Execute68kTrap(0xa01f, &r);	// DisposePtr
				}
			}

			r.a[0] = scrap_area;
			Execute68kTrap(0xa01f, &r);			// DisposePtr
		}
Beispiel #4
0
short getscrapcount (void) {

	/*
	2002-10-13 AR: Commented out variable declaration for theCount
	to eliminate compiler warning about an unused variable.
	*/
	
	#ifdef MACVERSION
		//Code change by Timothy Paustian Sunday, June 25, 2000 11:05:56 AM
		//Carbon Support
		#if TARGET_API_MAC_CARBON == 1
		
			ScrapRef 	theRef;
			//UInt32	 	theCount;
			static short theShortCount = 1;
			OSStatus	status;
			static ScrapRef lastScrapRef = nil;
			
			status = GetCurrentScrap(&theRef);
			
			if(status != noErr)
				return 0;
			
			assert(theRef != nil);
			
			if (theRef != lastScrapRef)
				theShortCount++;
				
			lastScrapRef = theRef;
			
			return (theShortCount);
			
			//status = GetScrapFlavorCount(theRef, &theCount);
			//if(status != noErr)
			//	return 0;
			
			//restrict the return value to a short size
			//theShortCount = min(theCount, 32000);
			//return theShortCount;
			
		#else
			
			PScrapStuff pscrap;
			
			pscrap = InfoScrap ();
			
			return ((*pscrap).scrapCount);
			
		#endif
		
	#endif

	#ifdef WIN95VERSION
		return (scrapcount);
	#endif
	} /*getscrapcount*/
Beispiel #5
0
ALIST_API void		ALCopy(ALHandle hAL)
{	Boolean			more, first;
	ALDataDescriptor	flavorDesc = {typeNull, nil};
	LongRect			theBounds;
	ALCell			cell;
	ALData			cellData;
	int				index;
	OSErr			err;
	Handle			groupData;
#if defined( TARGET_API_MAC_CARBON ) && ( TARGET_API_MAC_CARBON == 1 )
	ScrapRef			scrapRef;
#endif

	if (hAL == nil || *hAL == nil || (*hAL)->outputFlavorsHook == nil)
		return;

	// Do some initialization.
	first = true;
	groupData = nil;
#if !defined( TARGET_API_MAC_CARBON ) || ( TARGET_API_MAC_CARBON == 0 )
	err = ZeroScrap();
#else
	ClearCurrentScrap( );
	err = GetCurrentScrap( &scrapRef );
#endif

	theBounds = (*hAL)->dataBounds;
	// Check every cell...copy the selected cells to the Scrap.
	for (cell.h = theBounds.left; cell.h < theBounds.right; cell.h++)
		for (cell.v = theBounds.top; cell.v < theBounds.bottom; cell.v++)
			if (_ALCellIsSelected(&cell, hAL)) {
				// The cell is selected...Add it's contents to the group.
				ALGetCell(&cellData, &cell, hAL);

				for (more = true, index = 0; more && err == noErr; index++) {
					err = CallALOutputFlavorsProc(index, &more, false, &flavorDesc, cellData, &cell, hAL, (*hAL)->outputFlavorsHook);
					if (flavorDesc.dataHandle != nil) {
						_ALSetHandleLock(flavorDesc.dataHandle, true);
						if (first)
							// Put the data on the scrap.
							// This will cause ALL of the first selected cell's data to be on the scrap.
#if !defined( TARGET_API_MAC_CARBON ) || ( TARGET_API_MAC_CARBON == 0 )
							err = PutScrap(GetHandleSize(flavorDesc.dataHandle), flavorDesc.descriptorType,
											*flavorDesc.dataHandle);
#else
							err = PutScrapFlavor( scrapRef, flavorDesc.descriptorType, kScrapFlavorMaskNone,
										GetHandleSize( flavorDesc.dataHandle ), *flavorDesc.dataHandle );
#endif
						else
							// If there's more than one selected cell, that data goes into a group structure.
							// Add the data to the group.
							err = local_ALAddDataToGroup(&flavorDesc, &groupData);
						_ALSetHandleLock(flavorDesc.dataHandle, false);
						_ALForgetHandle(&flavorDesc.dataHandle);
					}
Beispiel #6
0
MCPasteboard *MCScreenDC::getclipboard(void)
{
	ScrapRef t_scrap;
	if (GetCurrentScrap(&t_scrap) != noErr)
		return NULL;

	MCPasteboard *t_pasteboard;
	t_pasteboard = new MCMacOSXScrapPasteboard(t_scrap);
	
	return t_pasteboard;
}
Beispiel #7
0
static PyObject *Scrap_GetCurrentScrap(PyObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	OSStatus _err;
	ScrapRef scrap;
	if (!PyArg_ParseTuple(_args, ""))
		return NULL;
	_err = GetCurrentScrap(&scrap);
	if (_err != noErr) return PyMac_Error(_err);
	_res = Py_BuildValue("O&",
	                     ScrapObj_New, scrap);
	return _res;
}
Beispiel #8
0
static void RomInfoCopyToClipboard(void)
{
	OSStatus	err;
	char		text[2048];

	RomInfoBuildInfoText(text);
	
	err = ClearCurrentScrap();
	if (err == noErr)
	{
		ScrapRef	scrap;
		
		err = GetCurrentScrap(&scrap);
		if (err == noErr)
			err = PutScrapFlavor(scrap, kScrapFlavorTypeText, kScrapFlavorMaskNone, strlen(text), text);
	}
}
long MyPutScrap(long length, ResType theType, void *source)
{

	#if TARGET_API_MAC_CARBON
		ScrapRef scrapRef;
		ScrapFlavorType flavorType = theType;
		ScrapFlavorFlags flavorFlags =  kScrapFlavorMaskNone;
		
		OSStatus err = GetCurrentScrap(&scrapRef);
		if(err) return 0;
		
		return PutScrapFlavor(scrapRef,flavorType,flavorFlags,length,source);
	#else
		return PutScrap(length,theType,source);
		
	#endif
}
Beispiel #10
0
/* IPIcon -> clipboard */
OSErr IPIconToClip(const IPIconRec *ipIcon)
{
	OSErr	err;
	IconFamilyHandle	iconFamily;
	IconActionUPP	copyIconDataUPP=NewIconActionUPP(CopyIconData);
	
	#if TARGET_API_MAC_CARBON
	{
		ScrapRef	scrap;
		
		err=ClearCurrentScrap();
		err=GetCurrentScrap(&scrap);
		err=ForEachIconDo(ipIcon->iconSuite,kSelectorMyData,copyIconDataUPP,scrap);
		
		err=IPIconToIconFamily(ipIcon,&iconFamily);
		if (err==noErr)
		{
			err=PutScrapFlavor(scrap,kIconFamilyType,0,GetHandleSize((Handle)iconFamily),*iconFamily);
			DisposeHandle((Handle)iconFamily);
		}
	}
	#else
	{
		long	result;
		
		result=ZeroScrap();
		err=ForEachIconDo(ipIcon->iconSuite,kSelectorMyData,copyIconDataUPP,nil);
		
		if (gSystemVersion >= 0x0850)
		{
			err=IPIconToIconFamily(ipIcon,&iconFamily);
			if (err==noErr)
			{
				result=PutScrap(GetHandleSize((Handle)iconFamily),kIconFamilyType,*iconFamily);
				DisposeHandle((Handle)iconFamily);
			}
		}
	}
	#endif
		
	DisposeIconActionUPP(copyIconDataUPP);
	
	return err;
}
void _HYPlatformGraphicPane::_CopyToClipboard	(void)
{
	_HYGraphicPane* parent = (_HYGraphicPane*)this;
	#ifdef TARGET_API_MAC_CARBON
		ClearCurrentScrap();
	#else
		ZeroScrap();
	#endif
	Rect  bRect;
	
	bRect.left 			= bRect.top = 0;
	bRect.right 		= parent->w;
	bRect.bottom 		= parent->h;

	PicHandle	 pic 	= OpenPicture (&bRect);
	
	GrafPtr      topPort;
	GetPort		 (&topPort);
	
	LockPixels (GetGWorldPixMap(thePane));
	#ifdef OPAQUE_TOOLBOX_STRUCTS 
		CopyBits (GetPortBitMapForCopyBits(thePane),GetPortBitMapForCopyBits(topPort),
				&bRect,&bRect,srcCopy,(RgnHandle)nil);
	#else
		CopyBits ((BitMap*)*GetGWorldPixMap(thePane),
				  (BitMap*)&(topPort->portBits),&bRect,&bRect,
	    		   srcCopy,(RgnHandle)nil);
	#endif
	UnlockPixels (GetGWorldPixMap(thePane));
    			   
	ClosePicture ();
	HLock	((Handle)pic);		
						
	#ifdef TARGET_API_MAC_CARBON
		ScrapRef		 theScrapRef;
		GetCurrentScrap(&theScrapRef);
		PutScrapFlavor(theScrapRef, 'PICT', kScrapFlavorMaskNone,GetHandleSize((Handle)pic),*pic);
	#else
		PutScrap (GetHandleSize((Handle)pic),'PICT',*pic);
	#endif
	KillPicture (pic);	
}		
Beispiel #12
0
boolean putscrap (tyscraptype scraptype, Handle hscrap) {
	
	/*
	return true if something was put on the scrap, false 
	otherwise.

	5.0a16 dmb: handle NULL scrap for delayed rendering

	5.0b13 dmb: report errors (win)
	*/

	boolean fl;

	#ifdef MACVERSION
		//Code change by Timothy Paustian Sunday, June 25, 2000 11:28:22 AM
		//New scrap code. We don't need flavorFlags I think
		#if TARGET_API_MAC_CARBON == 1
		ScrapRef			theScrap;
		OSStatus			status;
	    ScrapFlavorType 	flavorType = (ScrapFlavorType) scraptype;
	    ScrapFlavorFlags 	flavorFlags = kScrapFlavorMaskNone;
		Size				flavorSize = GetHandleSize(hscrap);
		
		status = GetCurrentScrap(&theScrap);
		if(status != noErr)
			return false;
		HLock(hscrap);
		fl = (PutScrapFlavor (theScrap, flavorType, flavorFlags, flavorSize, *hscrap) == noErr);
    	HUnlock(hscrap);
    	return fl;
    	
		#else
		
		HLock (hscrap);
		
		fl = PutScrap (GetHandleSize (hscrap), scraptype, *hscrap) == noErr;
		
		HUnlock (hscrap);

		return (fl);
		#endif
		
	#endif

	#ifdef WIN95VERSION
		long ctbytes;
		long allocctbytes;
		Handle hdata;
		char *pdata;
		UINT wintype;
		
		wintype = shell2winscraptype (scraptype);

		if (wintype == 0) {
	
			oserror (DV_E_CLIPFORMAT);

			return (false);
			}
		
		if (hscrap == NULL)
			hdata = NULL;
		
		else {
			ctbytes = gethandlesize (hscrap);

			allocctbytes = ctbytes;

			if (scraptype == textscraptype)
				++allocctbytes;							//Allow for NULL termination

			hdata = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, allocctbytes);
			pdata = GlobalLock (hdata);
			
			if (pdata == NULL) {

				GlobalFree (hdata);
				
				return (false);
				}

			moveleft (*hscrap, pdata, ctbytes);
			
			if (scraptype == textscraptype)
				*(pdata + ctbytes) = 0;			//NULL terminate TEXT scraps

			//Window handles are not exact size - NULL fill remaining space for safety
			if ((GlobalSize (hdata) - allocctbytes) > 0)
				clearbytes (pdata + allocctbytes, GlobalSize (hdata) - allocctbytes);

			GlobalUnlock (hdata);
			}
		
		SetLastError (0);
		
		fl = (SetClipboardData (wintype, hdata) != NULL);
		
		if (!fl)
			fl = !oserror (GetLastError ());
		
		return (fl);
	#endif
	} /*putscrap*/
Beispiel #13
0
boolean getscrap (tyscraptype scraptype, Handle hscrap) {
	
	/*
	return true if something was loaded from the scrap, false 
	otherwise.
	
	12/26/91 dmb: return true if scraptype exists; generate error alert on real error.

	5.0a16 dmb: need to scan more than last 32 bytes for NUL char
	*/
	
	#ifdef MACVERSION
#if TARGET_API_MAC_CARBON == 1
		ScrapRef			theScrap;
	    ScrapFlavorType 	flavorType = (ScrapFlavorType)scraptype;
	    Size 				byteCount;
	    OSStatus			status;
	    ScrapFlavorFlags	flavorFlags;
		boolean				retVal = true;
		Size				prevCount;

	    status = GetCurrentScrap(&theScrap);
	    if(status != noErr)
			oserror (status);

		status = GetScrapFlavorFlags(theScrap, flavorType, &flavorFlags);
		if(status == noTypeErr)
		{
			retVal = false;
		}
		else if(status < 0)
		{
			retVal = false;
			oserror (status);
		}
		//if we get here and the handles nil, we really don't want the data
		//also if retVal is false, it means the type does not exist
		if(hscrap == nil || !retVal)
			return retVal;

		status = GetScrapFlavorSize(theScrap, flavorType, &byteCount);
		if(status != noErr)
			oserror (status);
		prevCount = byteCount;
		SetHandleSize(hscrap, byteCount);
		if (MemError () != noErr)
			return (false);
		//lock the handle before getting the data
		HLock(hscrap);
	    status = GetScrapFlavorData(theScrap, flavorType, &byteCount, *(hscrap));
	    HUnlock(hscrap);

	    if(status != noErr)
			oserror (status);
		//only return true if we got all the data.
		return (byteCount == prevCount);

		#else //precarbon mac		
		long result;
		long offset;
		
		result = GetScrap (hscrap, scraptype, &offset);
		
		if (result == noTypeErr)
			return (false);
		
		if (result < 0)
			oserror (result);

		return (true); /*there was something on the scrap of the given type*/
		#endif
		
	#endif
	
	#ifdef WIN95VERSION
		Handle hdata;
		long ctbytes;
		char *pdata;
		boolean fl;
		/*long i;*/
		UINT wintype;
		
		wintype = shell2winscraptype (scraptype);
		
		if (wintype == 0)
			return (false);
		
		releasethreadglobals (); //getting clipboard data can send us a WM_RENDERFORMAT msg
		
		hdata = GetClipboardData (wintype);
		
		grabthreadglobals ();
		
		if (hdata == NULL) {
			
			oserror (GetLastError ()); // may be no error
			
			return (false);
			}
		
		ctbytes = GlobalSize (hdata);
		
		pdata = GlobalLock (hdata);
		
		if (pdata == NULL)
			return (false);
		
		if (scraptype == textscraptype) {		//Handle reducing the scrap size to the NULL
			/* i = 0x40;
			 if (i > ctbytes)
				 i = ctbytes;

			 while (i > 0) {
				 if (*(pdata + ctbytes - i) == 0) {
					 ctbytes = ctbytes - i;
					 break;
					 }

				 --i;
				 } /%while%/
			*/

			ctbytes = strlen (pdata); /*7.1b23: call strlen to find the first terminator: removes junk from end*/
			} /*if*/

		fl = sethandlecontents (pdata, ctbytes, hscrap);
		
		GlobalUnlock (hdata);
		
		return (fl);
	#endif
	} /*getscrap*/
Beispiel #14
0
tyscraptype getscraptype (void) {
	
	/*
	return the type of the first object on the scrap.
	*/
	
	#ifdef MACVERSION
		//Code change by Timothy Paustian Sunday, June 25, 2000 11:06:10 AM
		//Carbon support for new Scrap Manager API
		#if TARGET_API_MAC_CARBON == 1
		ScrapRef		scrap;
		UInt32			infoNumber = 1;
    	ScrapFlavorInfo info[1];
    	OSStatus		status;
    	
    	status = GetCurrentScrap(&scrap);
    	if(status != noErr)
			return 0;
		//now get the first item on the list
		status = GetScrapFlavorInfoList(scrap, &infoNumber, info);
		if(status != noErr)
			return 0;
		
		return (tyscraptype)info[1].flavorType;
		#else
		
		PScrapStuff pscrap;
		OSType **htype;
		
		pscrap = InfoScrap ();
		
		htype = (OSType **) (*pscrap).scrapHandle;
		
		if (htype == nil)
			return (0);
		
		return (**htype);
		#endif
		
	#endif

	#ifdef WIN95VERSION
		UINT format = 0;

		while (true) {

			format = EnumClipboardFormats (format);

			if (format == 0)
				return (0);

			if (format == win_textscraptype)
				return (textscraptype);

			if (format == win_pictscraptype)
				return (pictscraptype);

			if (format == win_opscraptype)
				return (opscraptype);

			if (format == win_scriptscraptype)
				return (scriptscraptype);

			if (format == win_wpscraptype)
				return (wpscraptype);

			if (format == win_hashscraptype)
				return (hashscraptype);

			if (format == win_menuscraptype)
				return (menuscraptype);
			}
	#endif
	} /*getscraptype*/
Beispiel #15
0
//
// I_GetClipboardText
//
// by Denis Lukianov - 20 Mar 2006
// Cross-platform clipboard functionality
//
std::string I_GetClipboardText (void)
{
#ifdef X11
	std::string ret;

	Display *dis = XOpenDisplay(NULL);
	int screen = DefaultScreen(dis);

	if(!dis)
	{
		Printf(PRINT_HIGH, "I_GetClipboardText: XOpenDisplay failed");
		return "";
	}

	XLockDisplay(dis);

	Window WindowEvents = XCreateSimpleWindow(dis, RootWindow(dis, screen), 0, 0, 1, 1, 0, BlackPixel(dis, screen), BlackPixel(dis, screen));

	if(XGetSelectionOwner(dis, XA_PRIMARY) != None)
	{
		if(!XConvertSelection(dis, XA_PRIMARY, XA_STRING, XA_PRIMARY, WindowEvents, CurrentTime))
		{
			XDestroyWindow(dis, WindowEvents);
			XUnlockDisplay(dis);
			XCloseDisplay(dis);
			Printf(PRINT_HIGH, "I_GetClipboardText: XConvertSelection failed");
			return "";
		}

		XFlush (dis);

		// Wait for the reply
		for(;;)
		{
			XEvent e;
			XNextEvent(dis, &e);

			if(e.type == SelectionNotify)
				break;
		}

		Atom type;
		int format, result;
		u_long len, bytes_left, temp;
		u_char *data;

		result = XGetWindowProperty(dis, WindowEvents, XA_PRIMARY, 0, 0, False, AnyPropertyType, &type, &format, &len, &bytes_left, &data);
		if(result != Success)
		{
			XDestroyWindow(dis, WindowEvents);
			XUnlockDisplay(dis);
			XCloseDisplay(dis);
			Printf(PRINT_HIGH, "I_GetClipboardText: XGetWindowProperty failed(1)");
			return "";
		}

		if(!bytes_left)
		{
			XDestroyWindow(dis, WindowEvents);
			DPrintf("I_GetClipboardText: Len was: %d", len);
			XUnlockDisplay(dis);
			XCloseDisplay(dis);
			return "";
		}

		result = XGetWindowProperty(dis, WindowEvents, XA_PRIMARY, 0, bytes_left, False, AnyPropertyType, &type, &format, &len, &temp, &data);
		if(result != Success)
		{
			XDestroyWindow(dis, WindowEvents);
			XUnlockDisplay(dis);
			XCloseDisplay(dis);
			Printf(PRINT_HIGH, "I_GetClipboardText: XGetWindowProperty failed(2)");
			return "";
		}

		ret = std::string((const char *)data, len);
		XFree(data);
	}

	XDestroyWindow(dis, WindowEvents);
	XUnlockDisplay(dis);
	XCloseDisplay(dis);

	return ret;
#endif

#if defined _WIN32 && !defined _XBOX
	std::string ret;

	if(!IsClipboardFormatAvailable(CF_TEXT))
		return "";

	if(!OpenClipboard(NULL))
		return "";

	HANDLE hClipboardData = GetClipboardData(CF_TEXT);

	if(!hClipboardData)
	{
		CloseClipboard();
		return "";
	}

	const char *cData = reinterpret_cast<const char *>(GlobalLock(hClipboardData));
	SIZE_T uiSize = static_cast<SIZE_T>(GlobalSize(hClipboardData));

	if(cData && uiSize)
	{
		for(size_t i = 0; i < uiSize; i++)
		{
			if(!cData[i])
			{
				uiSize = i;
				break;
			}
		}

		ret = std::string(cData, uiSize);
	}

	GlobalUnlock(hClipboardData);

	CloseClipboard();

	return ret;
#endif

#ifdef OSX
	ScrapRef scrap;
	Size size;

	int err = GetCurrentScrap(&scrap);

	if(err)
	{
		Printf(PRINT_HIGH, "GetCurrentScrap error: %d", err);
		return "";
	}

	err = GetScrapFlavorSize(scrap, FOUR_CHAR_CODE('TEXT'), &size);

	if(err)
	{
		Printf(PRINT_HIGH, "GetScrapFlavorSize error: %d", err);
		return "";
	}

	char *data = new char[size+1];

	err = GetScrapFlavorData(scrap, FOUR_CHAR_CODE('TEXT'), &size, data);
	data[size] = 0;

	if(err)
	{
		Printf(PRINT_HIGH, "GetScrapFlavorData error: %d", err);
		delete[] data;

		return "";
	}

	std::string ret(data);

	delete[] data;

	return ret;
#endif

	return "";
}
Beispiel #16
0
int
TkSelGetSelection(
    Tcl_Interp *interp,                /* Interpreter to use for reporting
                                 * errors. */
    Tk_Window tkwin,                /* Window on whose behalf to retrieve
                                 * the selection (determines display
                                 * from which to retrieve). */
    Atom selection,                /* Selection to retrieve. */
    Atom target,                /* Desired form in which selection
                                 * is to be returned. */
    Tk_GetSelProc *proc,        /* Procedure to call to process the
                                 * selection, once it has been retrieved. */
    ClientData clientData)        /* Arbitrary value to pass to proc. */
{
    int result;
    int err;
    long length;
    ScrapRef scrapRef;
    char * buf;

    if ((selection == Tk_InternAtom(tkwin, "CLIPBOARD"))
            && (target == XA_STRING)) {
        /* 
         * Get the scrap from the Macintosh global clipboard.
         */
         
        err=GetCurrentScrap(&scrapRef);
        if (err != noErr) {
            Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection),
                " GetCurrentScrap failed.", (char *) NULL);
            return TCL_ERROR;
        }
        
        err=GetScrapFlavorSize(scrapRef,'TEXT',&length);
        if (err != noErr) {
            Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection),
                " GetScrapFlavorSize failed.", (char *) NULL);
            return TCL_ERROR;
        }
        if (length > 0) {
            Tcl_DString encodedText;

            buf = (char *)ckalloc(length+1);
	    buf[length] = 0;
	    err = GetScrapFlavorData(scrapRef, 'TEXT', &length, buf);
            if (err != noErr) {
                    Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection),
                        " GetScrapFlavorData failed.", (char *) NULL);
                    return TCL_ERROR;
            }

            Tcl_ExternalToUtfDString(TkMacOSXCarbonEncoding, buf, length, 
				     &encodedText);
            result = (*proc)(clientData, interp,
                    Tcl_DStringValue(&encodedText));
            Tcl_DStringFree(&encodedText);

            ckfree(buf);
            return result;
        }
    }
    
    Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection),
        " selection doesn't exist or form \"", Tk_GetAtomName(tkwin, target),
        "\" not defined", (char *) NULL);
    return TCL_ERROR;
}
Beispiel #17
0
void
TkSuspendClipboard()
{
    TkClipboardTarget *targetPtr;
    TkClipboardBuffer *cbPtr;
    TkDisplay *dispPtr;
    char *buffer, *p, *endPtr, *buffPtr;
    long length;
    ScrapRef scrapRef;

    dispPtr = TkGetDisplayList();
    if ((dispPtr == NULL) || !dispPtr->clipboardActive) {
        return;
    }

    for (targetPtr = dispPtr->clipTargetPtr; targetPtr != NULL;
            targetPtr = targetPtr->nextPtr) {
        if (targetPtr->type == XA_STRING)
            break;
    }
    if (targetPtr != NULL) {
        Tcl_DString encodedText;

        length = 0;
        for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL;
                cbPtr = cbPtr->nextPtr) {
            length += cbPtr->length;
        }

        buffer = ckalloc(length);
        buffPtr = buffer;
        for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL;
                cbPtr = cbPtr->nextPtr) {
            for (p = cbPtr->buffer, endPtr = p + cbPtr->length;
                    p < endPtr; p++) {
                if (*p == '\n') {
                    *buffPtr++ = '\r';
                } else {
                    *buffPtr++ = *p;
                }
            }
        }

        ClearCurrentScrap();
        GetCurrentScrap(&scrapRef);
        Tcl_UtfToExternalDString(TkMacOSXCarbonEncoding, buffer, length, &encodedText);
        PutScrapFlavor(scrapRef, 'TEXT', 0, Tcl_DStringLength(&encodedText), Tcl_DStringValue(&encodedText) );
        Tcl_DStringFree(&encodedText);
        ckfree(buffer);
    }

    /*
     * The system now owns the scrap.  We tell Tk that it has
     * lost the selection so that it will look for it the next time
     * it needs it.  (Window list NULL if quiting.)
     */

    if (TkGetMainInfoList() != NULL) {
        Tk_ClearSelection((Tk_Window) TkGetMainInfoList()->winPtr, 
                Tk_InternAtom((Tk_Window) TkGetMainInfoList()->winPtr,
                        "CLIPBOARD"));
    }

    return;
}
Beispiel #18
0
/*** ADJUST MENUS ***/
OSStatus AdjustMenus( void )
{
	register		WindowRef theWin;
	short 			windowKind;
	Boolean 		isDA, isObjectWin, selection, scrapExists, undoExists, isGotoWin, isFindWin;
	EditWindowPtr	dWin = NULL;
	Str31			menuStr;
	short 			i;
	long			scrapSize;	// LR: v1.6.5
	Str255			frontWindowName, menuItemTitle;
	Boolean			namesMatch;

	theWin = FrontNonFloatingWindow();
	if( theWin )
	{
		isGotoWin = (g.gotoDlg && theWin == GetDialogWindow( g.gotoDlg ));		//LR: 1.7 - don't get window info on NULL!
		isFindWin = (g.searchDlg && theWin == GetDialogWindow( g.searchDlg ));

		windowKind = GetWindowKind( theWin );
		isDA = ( windowKind < 0 );
		isObjectWin = GetWindowKind( theWin ) == kHexEditWindowTag;
		if( isObjectWin )
		{
			dWin = (EditWindowPtr)GetWRefCon( theWin );	//LR: 1.66 - don't set unless an edit window!
			selection = dWin->endSel > dWin->startSel;
		}
		else
		{
			selection = (isGotoWin || isFindWin);
		}
	}
	else	// LR: v1.6.5 if no window is visible, then nothing is true!
	{
		isGotoWin = isFindWin = isObjectWin = isDA = selection = 0;
	}

	// LR: v1.6.5 - rewrite of scrap check
	if( isObjectWin || isFindWin || isGotoWin )
	{
#if TARGET_API_MAC_CARBON
		ScrapFlavorFlags flavorFlags;
		ScrapRef scrapRef;
		OSErr anErr;

		anErr = GetCurrentScrap( &scrapRef );
		if( !anErr )
			anErr = GetScrapFlavorFlags( scrapRef, kScrapFlavorTypeText, &flavorFlags );	// non-blocking check for scrap data
		if( !anErr )
			anErr = GetScrapFlavorSize( scrapRef, kScrapFlavorTypeText, &scrapSize );		// blocking call to get size
#else
		long offset;

		scrapSize = GetScrap( NULL, 'TEXT', &offset );
#endif
		scrapExists = scrapSize > 0;
	}
	else
		scrapExists = false;

	undoExists = (isObjectWin && gUndo.type != 0 && gUndo.theWin == dWin);	// check for NULL gUndo!
	
// LR: - enable file menu items during search, via Aaron D.
// LR:	_enableMenuItem( fileMenu, FM_New, g.searchDlg == NULL );
// LR:	_enableMenuItem( fileMenu, FM_Open, g.searchDlg == NULL );

// LR: 1.65 moved print names to string for localization
	GetIndString( menuStr, strPrint, (isObjectWin && dWin->startSel < dWin->endSel) ? 2 : 1 );

	SetMenuItemText( fileMenu, FM_Print, menuStr );

//LR 188 -- page setup should always be enabled
//	_enableMenuItem( fileMenu, FM_PageSetup, isObjectWin );	//SEL: 1.7 - enabled for carbon
	_enableMenuItem( fileMenu, FM_Print, isObjectWin );

//	HR/LR 050328 - Enable and check FM_Disassemble menu item
	_enableMenuItem( fileMenu, FM_Disassemble, isObjectWin );
	CheckMenuItem( fileMenu, FM_Disassemble, g.disassemble );

	_enableMenuItem( fileMenu, FM_OtherFork, isObjectWin );
	_enableMenuItem( fileMenu, FM_Close, isDA || isObjectWin || isFindWin || isGotoWin );	// LR: v1.6.5 rewrite via Max Horn
	_enableMenuItem( fileMenu, FM_Save, isObjectWin && dWin->dirtyFlag );
	_enableMenuItem( fileMenu, FM_SaveAs, isObjectWin );
	_enableMenuItem( fileMenu, FM_Revert, isObjectWin && dWin->refNum && dWin->dirtyFlag );

	_enableMenuItem( editMenu, 0, theWin != NULL );
	_enableMenuItem( editMenu, EM_Undo, isDA || undoExists );
	_enableMenuItem( editMenu, EM_Cut,  isDA || (selection && (!gPrefs.overwrite || (gPrefs.overwrite && !gPrefs.nonDestructive))) );
	_enableMenuItem( editMenu, EM_Copy, isDA || selection );
	_enableMenuItem( editMenu, EM_Paste, isDA || (scrapExists && (!gPrefs.overwrite || (gPrefs.overwrite && !gPrefs.nonDestructive))) );
	_enableMenuItem( editMenu, EM_Clear, isDA || selection );

	_enableMenuItem( editMenu, EM_SelectAll, isDA || isObjectWin || isFindWin || isGotoWin );

	_enableMenuItem( findMenu, 0, isObjectWin || isFindWin || isGotoWin );
/* 1.65
	_enableMenuItem( findMenu, SM_Find, isObjectWin );
	_enableMenuItem( findMenu, SM_GotoAddress, isObjectWin );
*/
	_enableMenuItem( findMenu, SM_FindForward, selection || (isObjectWin && dWin->fileSize && g.searchBuffer[0]) );	//LR 1.72 -- only enable w/something to search :)
	_enableMenuItem( findMenu, SM_FindBackward, selection || (isObjectWin && dWin->fileSize && g.searchBuffer[0]) );
	_enableMenuItem( findMenu, SM_Replace, selection || (isObjectWin && dWin->fileSize && g.searchBuffer[0]) );

	_enableMenuItem( optionsMenu, OM_NonDestructive, gPrefs.overwrite );	//LR 1.74 -- only available in overwrite mode

	CheckMenuItem( optionsMenu, OM_HiAscii, gPrefs.asciiMode );
	CheckMenuItem( optionsMenu, OM_DecimalAddr, gPrefs.decimalAddr );
	CheckMenuItem( optionsMenu, OM_Backups, gPrefs.backupFlag );
	CheckMenuItem( optionsMenu, OM_WinSize, gPrefs.constrainSize );
	CheckMenuItem( optionsMenu, OM_Overwrite, gPrefs.overwrite );
	CheckMenuItem( optionsMenu, OM_NonDestructive, !gPrefs.nonDestructive );	//LR 190 -- REVERSE (updated text, not code)
	CheckMenuItem( optionsMenu, OM_MoveOnlyPaging, gPrefs.moveOnlyPaging );	//LR 180 -- optional move only paging
	CheckMenuItem( optionsMenu, OM_Unformatted, !gPrefs.formatCopies );
	CheckMenuItem( optionsMenu, OM_VertBars, gPrefs.vertBars );
 	CheckMenuItem( optionsMenu, OM_OpenOnLaunch, gPrefs.dialogAtLaunch );	//WD_rpw 12-18-04

	// LR: v1.6.5 Lots of re-writing on handling the color scheme menu
#if !TARGET_API_MAC_CARBON
	// no color usage if not displayable!
	if( !g.colorQDFlag )
		gPrefs.useColor = false;
#endif

// LR: v1.6.5	CheckMenuItem( gColorMenu, CM_UseColor, gPrefs.useColor );	// allow turning on even if not usable
// LR: v1.6.5 Try to show status of color in new windows to help "intuitive" nature of menu
	GetIndString( menuStr, strColor, (gPrefs.useColor) ? 2 : 1 );
	SetMenuItemText( colorMenu, CM_UseColor, menuStr );

	//LR 181 -- show the current window color (or default if no windows)
	if( _cmCheckedItem )
		CheckMenuItem( colorMenu, _cmCheckedItem, false );
	_cmCheckedItem = isObjectWin ? dWin->csMenuID : gPrefs.csMenuID;
	CheckMenuItem( colorMenu, _cmCheckedItem, true );

	selection = gPrefs.useColor;	//LR 190 -- && isObjectWin && dWin->csResID > 0;
	i = CountMenuItems( colorMenu );
	do
	{
		_enableMenuItem( colorMenu, i, selection );	// LR: v1.6.5 only enable for color windows
	} while( --i > 2 );
	
	// NS: v1.6.6 checkmark front window in window menu
	if( theWin )
		GetWTitle( theWin, frontWindowName );	//LR: 1.66 - don't use NULL window!
	else
		frontWindowName[0] = 0;

	i = CountMenuItems( windowMenu );
	_enableMenuItem(windowMenu, 0, i != 0);	// dim out Window menu if no windows up.
	while( i )
	{
		GetMenuItemText( windowMenu, i, menuItemTitle );		// if you open more than one file with the same name (or edit the other fork)É
		namesMatch = EqualPStrings( frontWindowName, menuItemTitle );	// Éyou will have multiple items in the menu with the same text, and all will be checkmarked
		CheckMenuItem( windowMenu, i, namesMatch );

		i--;
	}

	return( noErr );
}
Beispiel #19
0
bool MCScreenDC::setclipboard(MCPasteboard *p_pasteboard)
{
	// First we try and clear the current scrap
	if (ClearCurrentScrap() == noErr)
		m_current_scrap = NULL;
	else
		return false;

	// Free current clipboard data if any
	if (m_current_scrap_data != NULL)
	{
		delete m_current_scrap_data;
		m_current_scrap_data = NULL;
	}

	// If the pasteboard is NULL then we are just clearing the clipboard
	if (p_pasteboard == NULL)
		return true;


	bool t_success;
	t_success = true;

	// Fetch the new scrap reference
	ScrapRef t_new_scrap;
	t_new_scrap = NULL;
	if (GetCurrentScrap(&t_new_scrap) != noErr)
		t_success = false;

	// Create the new scrap data object
	MCMacOSXTransferData *t_new_scrap_data;
	t_new_scrap_data = NULL;
	if (t_success)
	{
		t_new_scrap_data = new MCMacOSXTransferData;
		if (t_new_scrap_data == NULL)
			t_success = false;
	}

	// Publish the pasteboard, this will construct a list of flavor
	// types and converters inside the scrap data.
	if (t_success)
		t_success = t_new_scrap_data -> Publish(p_pasteboard);

	// Iterate over each scrap flavor and put the item onto the scrap
	// using the promise callback mechanism.
	if (t_success)
		t_success = t_new_scrap_data -> ForEachFlavor(PublishScrapFlavor, t_new_scrap);

	// Make sure we set the promise keeper callback - this involves
	// creating a UPP if one hasn't already been made
	if (t_success && m_scrap_promise_keeper_upp == NULL)
	{
		m_scrap_promise_keeper_upp = NewScrapPromiseKeeperUPP(SubscribeScrapFlavor);
		if (m_scrap_promise_keeper_upp == NULL)
			t_success = false;
	}

	if (t_success)
		if (SetScrapPromiseKeeper(t_new_scrap, m_scrap_promise_keeper_upp, t_new_scrap_data) != noErr)
			t_success = false;

	// If we succeeded then update internal state
	if (t_success)
	{
		m_current_scrap = t_new_scrap;
		m_current_scrap_data = t_new_scrap_data;
	}
	else
	{
		ClearCurrentScrap();
		delete t_new_scrap_data;
	}

	return t_success;
}