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; } ClearCurrentScrap(); } }
long MyZeroScrap(void) { #if TARGET_API_MAC_CARBON ClearCurrentScrap(); return 0; #else return ZeroScrap(); #endif }
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); }
static PyObject *Scrap_ClearCurrentScrap(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; OSStatus _err; if (!PyArg_ParseTuple(_args, "")) return NULL; _err = ClearCurrentScrap(); if (_err != noErr) return PyMac_Error(_err); Py_INCREF(Py_None); _res = Py_None; return _res; }
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*/
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); } }
/* 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); }
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; }
/* YASTControlCarbonEventHandler defines the main entry point for all of the carbon event handlers installed for the YASTControl. */ static pascal OSStatus YASTControlCarbonEventHandler( EventHandlerCallRef myHandler, EventRef event, void* userData) { #pragma unused ( myHandler ) OSStatus err, returnedResult; YASTControlVarsPtr varsp; UInt32 eclass, ekind; /* set up locals */ eclass = GetEventClass(event); ekind = GetEventKind(event); varsp = (YASTControlVarsPtr) userData; returnedResult = eventNotHandledErr; /* dispatch the event by class*/ switch (eclass) { case kEventClassWindow: if ( ekind == kEventWindowCursorChange ) { Point where; UInt32 modifiers; Boolean cursorWasSet; /* get the mouse position */ err = GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(where), NULL, &where); if (err == noErr) { err = GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(modifiers), NULL, &modifiers); if (err == noErr) { SetPort(varsp->fGrafPtr); GlobalToLocal(&where); if (PtInRect(where, &varsp->fRBounds)) { err = HandleControlSetCursor( varsp->fControl, where, modifiers, &cursorWasSet); if (err != noErr) cursorWasSet = false; if ( ! cursorWasSet ) InitCursor(); returnedResult = noErr; } } } } break; case kEventClassMouse: /* handle mouse downs in the control, but only if the control is in focus. */ if ( ekind == kEventMouseDown ) { EventRecord outEvent; if ( varsp->fInFocus ) { if (ConvertEventRefToEventRecord( event, &outEvent)) { TXNClick( varsp->fTXNObject, &outEvent); } returnedResult = noErr; } } break; case kEventClassTextInput: if ( ekind == kEventUnicodeForKeyEvent && varsp->fTabMovesFocus) { UniChar mUnicodeText[8]; UInt32 bytecount, nchars; /* get the character */ err = GetEventParameter(event, kEventParamTextInputSendText, typeUnicodeText, NULL, sizeof(mUnicodeText), &bytecount, (char*) mUnicodeText); if ((err == noErr) && (bytecount >= sizeof(UniChar))) { nchars = ( bytecount / sizeof(UniChar) ); /* if it's not the tab key, forget it... */ if ( mUnicodeText[0] == '\t' ) { EventRef rawKeyEvent; Boolean shiftDown; /* is the shift key held down? */ shiftDown = false; err = GetEventParameter(event, kEventParamTextInputSendKeyboardEvent, typeEventRef, NULL, sizeof(rawKeyEvent), NULL, &rawKeyEvent); if (err == noErr) { UInt32 modifiers; err = GetEventParameter(rawKeyEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(modifiers), NULL, &modifiers); if (err == noErr) { shiftDown = ( (modifiers & shiftKey) != 0 ); } } /* advance the keyboard focus, backwards if shift is down */ if (shiftDown) ReverseKeyboardFocus( varsp->fWindow ); else AdvanceKeyboardFocus( varsp->fWindow ); /* noErr lets the CEM know we handled the event */ returnedResult = noErr; } } } break; case kEventClassControl: switch (ekind) { case kEventControlSetFocusPart: { ControlPartCode thePart; err = GetEventParameter(event, kEventParamControlPart, typeControlPartCode, NULL, sizeof(thePart), NULL, &thePart); if (err == noErr) { switch (thePart) { default: case kControlFocusNoPart: /* turn off focus */ if ( varsp->fInFocus ) { TXNFocus( varsp->fTXNObject, false); varsp->fInFocus = false; } thePart = kControlFocusNoPart; break; case kYASTControlOnlyPart: /* turn on focus */ if ( ! varsp->fInFocus ) { TXNFocus( varsp->fTXNObject, true); varsp->fInFocus = true; } thePart = kYASTControlOnlyPart; break; case kControlFocusPrevPart: /* toggle focus on/off */ case kControlFocusNextPart: varsp->fInFocus = ! varsp->fInFocus; TXNFocus( varsp->fTXNObject, varsp->fInFocus); thePart = (varsp->fInFocus ? kYASTControlOnlyPart : kControlFocusNoPart); break; } SetPort(varsp->fGrafPtr); /* calculate the next highlight state */ SetTextActivation(varsp, varsp->fIsActive && varsp->fInFocus); /* redraw the text fram and focus rectangle to indicate the new focus state */ DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); RedrawFocusOutline(varsp); } /* pass back the foocus part code */ err = SetEventParameter( event, kEventParamControlPart, typeControlPartCode, sizeof(thePart), &thePart); returnedResult = err; } break; case kEventControlHitTest: /* this event does not necessairly mean that a mouse click has occured. Here we are simply testing to see if a particular point is located inside of the control. More complicated controls would return different part codes for different parts of themselves; but, since YASTControls only advertise one part, the hit test here is more or less a boolean test. */ { ControlPartCode thePart; Point where; err = GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(where), NULL, &where); if (err == noErr) { if (PtInRect(where, &varsp->fRTextArea)) { thePart = kYASTControlOnlyPart; } else thePart = 0; err = SetEventParameter( event, kEventParamControlPart, typeControlPartCode, sizeof(thePart), &thePart); } returnedResult = err; } break; case kEventControlClick: /* here we handle focus switching on the control. Actual tracking of mouse down events in the control is performed in the kEventClassMouse mouse down handler above. */ if ( ! varsp->fInFocus ) { SetKeyboardFocus(varsp->fWindow, varsp->fControl, kYASTControlOnlyPart); returnedResult = noErr; } break; case kEventControlBoundsChanged: /* we moved, or switched size - recalculate our rectangles */ { Rect bounds; err = GetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, NULL, sizeof(bounds), NULL, &bounds); if (err == noErr) { YASTControlCalculateBounds(varsp, &bounds); TXNSetFrameBounds( varsp->fTXNObject, varsp->fRTextArea.top, varsp->fRTextArea.left, varsp->fRTextArea.bottom, varsp->fRTextArea.right, varsp->fTXNFrameID); } } break; case kEventControlActivate: case kEventControlDeactivate: { SetPort(varsp->fGrafPtr); varsp->fIsActive = (ekind == kEventControlActivate); SetTextActivation(varsp, varsp->fIsActive && varsp->fInFocus); /* redraw the frame */ DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); RedrawFocusOutline(varsp); returnedResult = noErr; } break; case kEventControlDraw: /* redraw the control */ SetPort(varsp->fGrafPtr); /* update the text region */ TXNDraw(varsp->fTXNObject, NULL); /* restore the drawing environment */ /* draw the text frame and focus frame (if necessary) */ DrawThemeEditTextFrame(&varsp->fRTextOutline, varsp->fIsActive ? kThemeStateActive: kThemeStateInactive); RedrawFocusOutline(varsp); returnedResult = noErr; break; case kEventControlSetCursor: /* cursor adjustment */ { SetPortWindowPort(varsp->fWindow); TXNAdjustCursor( varsp->fTXNObject, varsp->fRTextOutlineRegion); returnedResult = noErr; } break; case kEventControlDispose: /* RemoveEventHandler(varsp->fControlEvents); -- this call has been left out on purpose because it will be called automatically when the control is disposed. */ RemoveEventHandler(varsp->fWindowEvents); TXNDeleteObject(varsp->fTXNObject); DisposeRgn(varsp->fRTextOutlineRegion); free(varsp); /* returnedResult = noErr; -- this has been left out on purpose because we want the dispatching to continue and dispose of the control */ break; case kEventControlSetData: { ResType inTagName; Size inBufferSize; void * inBuffer; err = GetEventParameter( event, kEventParamControlDataTag, typeEnumeration, NULL, sizeof(inTagName), NULL, &inTagName); if (err == noErr) { err = GetEventParameter( event, kEventParamControlDataBuffer, typePtr, NULL, sizeof(inBuffer), NULL, &inBuffer); if (err == noErr) { err = GetEventParameter( event, kEventParamControlDataBufferSize, typeLongInteger, NULL, sizeof(inBufferSize), NULL, &inBufferSize); if (err == noErr) { err = YASTControlSetData(varsp, inTagName, inBuffer, inBufferSize); } } } returnedResult = err; } break; case kEventControlGetData: { ResType inTagName; Size inBufferSize, outBufferSize; void * inBuffer; err = GetEventParameter( event, kEventParamControlDataTag, typeEnumeration, NULL, sizeof(inTagName), NULL, &inTagName); if (err == noErr) { err = GetEventParameter( event, kEventParamControlDataBuffer, typePtr, NULL, sizeof(inBuffer), NULL, &inBuffer); if (err == noErr) { err = GetEventParameter( event, kEventParamControlDataBufferSize, typeLongInteger, NULL, sizeof(inBufferSize), NULL, &inBufferSize); if (err == noErr) { err = YASTControlGetData(varsp, inTagName, inBuffer, inBufferSize, &outBufferSize); if (err == noErr) { err = SetEventParameter( event, kEventParamControlDataBufferSize, typeLongInteger, sizeof(outBufferSize), &outBufferSize); } } } } returnedResult = err; } break; } break; case kEventClassCommand: if ( ekind == kEventProcessCommand ) { HICommand command; err = GetEventParameter( event, kEventParamDirectObject, typeHICommand, NULL, sizeof(command), NULL, &command); if (err == noErr) { switch (command.commandID) { case kHICommandUndo: TXNUndo(varsp->fTXNObject); returnedResult = noErr; break; case kHICommandRedo: TXNRedo(varsp->fTXNObject); returnedResult = noErr; break; case kHICommandCut: ClearCurrentScrap(); err = TXNCut(varsp->fTXNObject); if (err == noErr) err = TXNConvertToPublicScrap(); returnedResult = err; break; case kHICommandCopy: ClearCurrentScrap(); err = TXNCopy(varsp->fTXNObject); if (err == noErr) err = TXNConvertToPublicScrap(); returnedResult = err; break; case kHICommandPaste: err = TXNConvertFromPublicScrap(); if (err == noErr) err = TXNPaste(varsp->fTXNObject); returnedResult = err; break; case kHICommandClear: err = TXNClear(varsp->fTXNObject); returnedResult = err; break; case kHICommandSelectAll: err = TXNSetSelection(varsp->fTXNObject, kTXNStartOffset, kTXNEndOffset); returnedResult = err; break; } } } else if ( ekind == kEventCommandUpdateStatus ) { HICommand command; TXNOffset oStartOffset, oEndOffset; TXNActionKey oActionKey; err = GetEventParameter( event, kEventParamDirectObject, typeHICommand, NULL, sizeof(command), NULL, &command); if ((err == noErr) && ((command.attributes & kHICommandFromMenu) != 0)) { switch (command.commandID) { case kHICommandUndo: if (TXNCanUndo(varsp->fTXNObject, &oActionKey)) { EnableMenuItem(command.menu.menuRef, 0); /* required pre OS 10.2 */ EnableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); } else DisableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); returnedResult = noErr; break; case kHICommandRedo: if (TXNCanRedo(varsp->fTXNObject, &oActionKey)) { EnableMenuItem(command.menu.menuRef, 0); /* required pre OS 10.2 */ EnableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); } else DisableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); returnedResult = noErr; break; case kHICommandCut: case kHICommandCopy: case kHICommandClear: TXNGetSelection(varsp->fTXNObject, &oStartOffset, &oEndOffset); if (oStartOffset != oEndOffset) { EnableMenuItem(command.menu.menuRef, 0); /* required pre OS 10.2 */ EnableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); } else DisableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); returnedResult = noErr; break; case kHICommandPaste: if (TXNIsScrapPastable()) { EnableMenuItem(command.menu.menuRef, 0); /* required pre OS 10.2 */ EnableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); } else DisableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); returnedResult = noErr; break; case kHICommandSelectAll: if(TXNDataSize(varsp->fTXNObject) > 0) { EnableMenuItem(command.menu.menuRef, 0); /* required pre OS 10.2 */ EnableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); } else DisableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); returnedResult = noErr; break; } } } break; } return returnedResult; }
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; }