Caution: This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.

PhClipboardWrite()

Copy data to the clipboard

Synopsis:

int32_t PhClipboardWrite(unsigned short ig,
                         uint32_t n,
                         PhClipboardHdr const clip[]);

Arguments:

ig
The input group. Each input group has its own private clipboard. To determine the current input group, call PhInputGroup(), passing to it the event that triggered the clipboard operation (e.g. cbinfo->event).
n
The number of items in the clip array.
clip
An array of PhClipboardHdr structures, that specify the information you want to save to the clipboard. Each entry includes the data, its type, and its length.

Library:

ph

Description:

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.

Returns:

0
Successful completion.
-1
An error occurred.

Examples:

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);
}

Classification:

Photon

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

PhClipboardCopyString(), PhClipboardHdr, PhClipboardPasteString(), PhClipboardRead(), PhClipboardHdr