Copy data to the clipboard
int32_t PhClipboardWrite(unsigned short ig, uint32_t n, PhClipboardHdr const clip[]);
ph
This function copies the clipboard data in clip to the Photon clipboard. Each clip is saved based on the input group ig, data type clip.type, and ID of the user. This ensures that one user can't access clipboard data saved by another user. Clipboard data is also encrypted, and can only be accessed through the clipboard API function PhClipboardRead().
Multiple representations of the data may be placed on the clipboard. For example, you may want to save text and format data for the text. The number of different types is specified with the n parameter. Each type has a header structure in the clip array. For more information, see PhClipboardHdr.
This callback copies selected text from a PtText widget named text, and saves it on the clipboard:
int copy_to_clip( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo ) { char *selstring; int start, end, len, ig; PhClipboardHdr clip[1]; ig=PhInputGroup(cbinfo->event); len = PtTextGetSelection(ABW_text, &start, &end); if(start!=-1 && len > 1) { char *text = NULL; PtGetResource( ABW_text, Pt_ARG_TEXT_STRING, &text, 0 ); if( text ) { int s = utf8strnlen( text, start, NULL ), l = utf8strnlen( text + s, end - start, NULL ); if( NULL != (selstring = malloc( l + 1 )) ) { // Copy text to clipboard memcpy( selstring, text + s, l ); selstring[l] = 0; strcpy(clip[0].type,Ph_CLIPBOARD_TYPE_TEXT); clip[0].length=strlen(selstring); clip[0].data = selstring; PhClipboardWrite(ig, 1, clip); free(selstring); selstring=NULL; } } } PtContainerGiveFocus(ABW_text, NULL); return(Pt_CONTINUE); }
Photon
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | No |
PhClipboardCopyString(), PhClipboardHdr, PhClipboardPasteString(), PhClipboardRead(), PhClipboardHdr