Beispiel #1
0
void
XSetSelectionOwner(
    Display* display,	/* X Display. */
    Atom selection,	/* What selection to own. */
    Window owner,	/* Window to be the owner. */
    Time time)		/* The current time? */
{
    Tk_Window tkwin;
    TkDisplay *dispPtr;

    /*
     * This is a gross hack because the Tk_InternAtom interface is broken.
     * It expects a Tk_Window, even though it only needs a Tk_Display.
     */

    tkwin = (Tk_Window) TkGetMainInfoList()->winPtr;

    if (selection == Tk_InternAtom(tkwin, "CLIPBOARD")) {

	/*
	 * Only claim and empty the clipboard if we aren't already the
	 * owner of the clipboard.
	 */

	dispPtr = TkGetMainInfoList()->winPtr->dispPtr;
	if (dispPtr->clipboardActive) {
	    return;
	}
	ZeroScrap();
    }
}
Beispiel #2
0
void
TkSuspendClipboard()
{
    TkClipboardTarget *targetPtr;
    TkClipboardBuffer *cbPtr;
    TkDisplay *dispPtr;
    char *buffer, *p, *endPtr, *buffPtr;
    long length;

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

    for (targetPtr = dispPtr->clipTargetPtr; targetPtr != NULL;
	    targetPtr = targetPtr->nextPtr) {
	if (targetPtr->type == XA_STRING)
	    break;
    }
    if (targetPtr != NULL) {
	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;
		}
	    }
	}

	ZeroScrap();
	PutScrap(length, 'TEXT', buffer);
	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 (tkMainWindowList != NULL) {
	Tk_ClearSelection((Tk_Window) tkMainWindowList->winPtr, 
		Tk_InternAtom((Tk_Window) tkMainWindowList->winPtr,
			"CLIPBOARD"));
    }

    return;
}
long MyZeroScrap(void)
{
	#if TARGET_API_MAC_CARBON
		ClearCurrentScrap();
		return 0;
	#else
		return ZeroScrap();
	#endif
}
Beispiel #4
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 #5
0
boolean resetscrap (void) {
	//Code change by Timothy Paustian Sunday, June 25, 2000 11:05:43 AM
	//Carbon Support
	#ifdef MACVERSION
		#if TARGET_API_MAC_CARBON == 1
		return (ClearCurrentScrap() == noErr);
		#else
		return (ZeroScrap () == noErr);
		#endif
	#endif

	#ifdef WIN95VERSION
		return (EmptyClipboard());
	#endif
	} /*resetscrap*/
Beispiel #6
0
P3(PUBLIC pascal trap, LONGINT, PutScrap, LONGINT, len, ResType, rest, Ptr, p)
{
    OSErr retval;
    LONGINT l, swappedlen;
    INTEGER f;

    LONGINT *lp;

    if (Cx(ScrapState) < 0) {
        retval = ZeroScrap();
	if (retval != noErr)
/*-->*/	    return(retval);
    }
#if defined(X) || defined(NEXTSTEP) || defined (SDL)
    PutScrapX(rest, len, (char *) p, CW (ScrapCount));
#endif /* defined(X) */
    if (Cx(ScrapState) == 0) {
        retval = FSOpen(MR(ScrapName), CW (BootDrive), &f);
        if (retval != noErr)
/*-->*/     return(retval);
        SetFPos(f, fsFromStart, (LONGINT)Cx(ScrapSize));
        l = 4;
	rest = CL(rest);
        FSWriteAll(f, &l, (Ptr) &rest);
        l = 4;
	swappedlen = CL(len);
        FSWriteAll(f, &l, (Ptr) &swappedlen);
        l = len = (len + 1) & -2L;
        FSWriteAll(f, &len, p);
        FSClose(f);
    } else {
        SetHandleSize(MR(ScrapHandle), (Size)Cx(ScrapSize) + 8);
	if (MemErr != noErr)
/*-->*/	    return CW(MemErr);
	/* alignment stuff */
        lp = (LONGINT *)((char *)STARH(MR(ScrapHandle)) + Cx(ScrapSize));
        *lp++ = CL(rest);
        *lp++ = CL(len);
        len = (len + 1) & -2L;
        PtrAndHand(p, MR(ScrapHandle), (Size)len);
    }
    ScrapSize = CL(CL(ScrapSize) + 8 + len);
    return noErr;
}
Beispiel #7
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 #9
0
void DoCopy(void)
{
    Handle stackListCtl = (Handle)GetCtlHandleFromID(gCalcWinPtr, abCalcStackList);
    LERecHndl leHandle;
    CtlRecHndl entryBox = GetCtlHandleFromID(gCalcWinPtr, abCalcEntryBox);

    int numStackItems = abCalcStackNumItems();
    int numDisplayed = numStackItems;
    int selectedStackItem;

    if (gSelectedStackItem == -1) {
        HLock((Handle)entryBox);
        leHandle = (LERecHndl)(*entryBox)->ctlData;
        HUnlock((Handle)entryBox);

        LECopy(leHandle);
        LEToScrap();
        return;
    }

    if (numDisplayed < MIN_STACK_ITEMS)
        numDisplayed = MIN_STACK_ITEMS;

    selectedStackItem = numDisplayed - gSelectedStackItem;

    if (gBuffer == NULL) {
        gBuffer = malloc(AB_CALC_EXPR_STRING_MAX);
    }

    if ((selectedStackItem >= 0) &&
            (selectedStackItem < numStackItems) &&
            (abCalcStackExprStringAt(selectedStackItem, gBuffer, FALSE) != NULL)) {
        ZeroScrap();
        PutScrap(strlen(gBuffer), textScrap, gBuffer);
    }

    SetPort(gCalcWinPtr);
    ResetMember2(stackListCtl);
    DrawMember2(gSelectedStackItem, stackListCtl);
    gSelectedStackItem = -1;
}
Beispiel #10
0
P0(PUBLIC pascal trap, PScrapStuff, InfoScrap)
{
    if (Cx(ScrapState) < 0)
        ZeroScrap();
    return((PScrapStuff)&ScrapSize);
}
Beispiel #11
0
P3(PUBLIC pascal trap, LONGINT, GetScrap, Handle, h, ResType, rest,
								LONGINT *, off)
{
    OSErr retval;
    LONGINT l = 0, incr, s, ltoread, restlen[2];
    unsigned char *p;
    int found;
    INTEGER f;
    Handle temph;

#if !defined (LETGCCWAIL)
    s = 0;
#endif /* LETGCCWAIL */
    if (h)
	temph = 0;
    else {
	temph = NewHandle((Size) 0);
	h = temph;
    }
    
#if defined(X) || defined(NEXTSTEP) || defined (SDL)
    s = GetScrapX(rest, (char **) h);
    if (s >= 0) {
        *off = 0;	/* ack... could mess people up */
/*-->*/ RETURN(s);
    }
#endif /* defined(X) */
    if (Cx(ScrapState) < 0) {
        retval = ZeroScrap();
	if (retval != noErr)
/*-->*/	    RETURN(retval);
    }
    if (ScrapState == 0) {
        retval = FSOpen(MR(ScrapName), CW (BootDrive), &f);
        if (retval != noErr)
/*-->*/     RETURN(retval);
        found = FALSE;
        while (l < Cx(ScrapSize)  && !found) {
            ltoread = 8;
            FSReadAll(f, &ltoread, (Ptr) restlen);
	    s = CL(restlen[1]);
            if (rest == CL(restlen[0]))
                found = TRUE;
            else {
                incr = (8 + s + 1) & ~1L;
                l += incr;
                SetFPos(f, fsFromMark, incr);
            }
        }
        if (l >= Cx(ScrapSize)) {
            FSClose(f);
/*-->*/     RETURN(noTypeErr);
        }
        ReallocHandle(h, s);
	if (MemErr != noErr)
/*-->*/	    RETURN(CW(MemErr));
        HLock(h);
        ltoread = s;
        FSReadAll(f, &ltoread, STARH(h));
        HUnlock(h);
        FSClose(f);
    } else {
        HLock(MR(ScrapHandle));
        p = MR(*(unsigned char **)MR(ScrapHandle));
#if 1 || !defined(QUADALIGN)
        while (l < Cx(ScrapSize) && rest != CL(*(LONGINT *)p))
	  {
	    s = CL (*((LONGINT *) p + 1));
            incr = (8 + s + 1) & ~1L;
            l += incr;
            p += incr;
	  }
        if (l >= Cx(ScrapSize))
	  {
	    HUnlock(MR(ScrapHandle));
/*-->*/     RETURN(noTypeErr);
	  }
	s = CL (*((LONGINT *)p + 1));
#else /* QUADALIGN */
        while (l < Cx(ScrapSize) && rest != SNAGLONG(p)) {
            incr = 8 + ((s = SNAGLONG(p + sizeof(LONGINT))) + 1) & -2L;
            l += incr;
            p += incr;
        }
        if (l >= Cx(ScrapSize))
	  {
	    HUnlock(MR(ScrapHandle));
/*-->*/     RETURN(noTypeErr);
	  }
	s = *((LONGINT *)p + 1);
#endif /* QUADALIGN */
        PtrToXHand((Ptr) (p+8), h, s);
        HUnlock(MR(ScrapHandle));
    }
    *off = CL(l+8);
    RETURN(s);
}
static pascal Boolean MyFilter(DialogPtr dlog, EventRecord *evt, short *itemHit)
	{
		Boolean ans=FALSE,doHilite=FALSE; WindowPtr w;
		short type,ch; Handle hndl; Rect box;
		static long then; static Point clickPt;

		w = (WindowPtr)(evt->message);
		switch(evt->what) {
			case updateEvt:
				if (w == dlog) {
					/* Update our dialog contents */
					DoDialogUpdate(dlog);
					ans = TRUE; *itemHit = 0;
					}
				 else {
					/*
					 *	Call your main event loop DoUpdate(w) routine here if you
					 *	don't want unsightly holes in background windows caused
					 *	by nested alerts, balloon help, or screen savers (see
					 *	Tech Note #304).
					 */
					}
				break;
			case activateEvt:
				if (w == dlog) {
					DoDialogActivate(dlog,(evt->modifiers & activeFlag)!=0);
					*itemHit = 0;
					}
				 else {
					/*
					 *	Call your main event loop DoActivate(w) routine here if
					 *	you want to deactivate the former frontmost window, in order
					 *	to unhighlight any selection, scroll bars, etc.
					 */
					}
				break;
			case mouseDown:
			case mouseUp:
				where = evt->where;		/* Make info available to DoDialog() */
				GlobalToLocal(&where);
				modifiers = evt->modifiers;
				ans = CheckUserItems(where,itemHit);
				break;
			case keyDown:
				if ((ch=(unsigned char)evt->message)=='\r' || ch==ENTERkey) {
					*itemHit = OK_ITEM /* Default Item Number here */;
					doHilite = ans = TRUE;
					}
				 else if (evt->modifiers & cmdKey) {
					ch = (unsigned char)evt->message;
					switch(ch) {
						case 'x':
						case 'X':
							if (TextSelected(dlog))
								{ SystemEdit(3); ZeroScrap(); DialogCut(dlog); TEToScrap(); }
							 else {
								/* Cut from anything else cuttable, like a list */
								}
							break;
						case 'c':
						case 'C':
							if (TextSelected(dlog))
								{ SystemEdit(3); ZeroScrap(); DialogCopy(dlog); TEToScrap(); }
							 else {
								/* Copy from anything else copyable, like a list */
								}
							break;
						case 'v':
						case 'V':
							if (CanPaste(1,'TEXT'))
								{ TEFromScrap(); DialogPaste(dlog); }
							 else {
							 	/* Deal with any other pasteable scraps here */
								}
							break;
						case 'a':
						case 'A':
							if (((DialogPeek)dlog)->editField >= 0) {
								/* Dialog has text edit item: select all */
								SelectDialogItemText(dlog,((DialogPeek)dlog)->editField+1,0,32767);
								}
							 else {
								}
							*itemHit = 0;
							break;
						case '.':
							*itemHit = CANCEL_ITEM;
							doHilite = TRUE;
							break;
						}
					ans = TRUE;		/* Other cmd-chars ignored */
					}
				break;
			}
		if (doHilite) {
			GetDialogItem(dlog,*itemHit,&type,&hndl,&box);
			/* Reality check */
			if (type == (btnCtrl+ctrlItem)) {
				long soon = TickCount() + 7;		/* Or whatever feels right */
				HiliteControl((ControlHandle)hndl,1);
				while (TickCount() < soon) ;		/* Leave hilited for a bit */
				}
			}
		return(ans);
	}
Beispiel #13
0
/* an edit menu handler for TextEdit
 */
short NATEmenup(na_win *winp, WORD menuid, WORD itemno)
{
	MenuHandle	mh = NAmenuh(mEdit);
	TEHandle	hTE = teinfo->hTE;
	TEPtr		pte;
	short		status = NA_NOTPROCESSED;
	
	switch (menuid) {
		case 0:
			pte = *hTE;
			if (pte->selStart != pte->selEnd) {
				EnableItem(mh, iCopy);
				if (!(winp->flags & NATE_READONLY)) {
					EnableItem(mh, iCut);
					EnableItem(mh, iClear);
				}
			} else {
				DisableItem(mh, iCopy);
				if (!(winp->flags & NATE_READONLY)) {
					DisableItem(mh, iCut);
					DisableItem(mh, iClear);
				}
			}
			EnableItem(mh, iSelAll);
			if (!(winp->flags & NATE_READONLY)) {
				EnableItem(mh, iPaste);
			}
			break;

		case mEdit:
			switch (itemno) {
				case iCut:
					TECut(hTE);
					goto DOSCRAP;
					
				case iCopy:
					TECopy(hTE);
				DOSCRAP:
					ZeroScrap();
					TEToScrap();
					goto EDITDONE;
					
				case iPaste:
					TEFromScrap();
					TEPaste(hTE);
					goto EDITDONE;
					
				case iClear:
					TEDelete(hTE);
					goto EDITDONE;
				
				case iSelAll:
					TESetSelect(0, 32767, hTE);
					TESelView(hTE);
				EDITDONE:
					status = NA_PROCESSED;
					NATEsetscroll(winp, false, (Rect*) NULL, (Rect*) NULL);
					break;
			}
		default:
			DisableItem(mh, iSelAll);
			break;
	}
	
	return (status);
}