Another way of getting data from one program into another is via the system clipboard. Unlike other forms of data exchange, using the clipboard requires very little effort or code because you have to do is to plunk data into a particular BMessage. Some of the standard controls already do it for you. The BTextView class already implements copying, cutting, and pasting by way of keyboard accelerators. In cases like these, all that you will want to do is add some menu items for less advanced users.

Standardized Clipboard Data Formats

Plain Text
It is easiest to describe the basics with this code snippet. clipboard->AddData("text/plain", B_MIME_TYPE, your_text_string_here);
Styled Text
Use the same format as for plain text but add a text run array field to the message also. You probably won't need to worry about this unless you're writing a word processor or something similar. clipboard->AddData("application/x-vnd.Be-text_run_array", B_MIME_TYPE, run_array, run_array_size);
Generic File References
If the amount of data you wish to pass to another program is too large to place on the clipboard without straining the system, dump the data to a temporary file and place an entry_ref which points to it on the clipboard instead. Audio and video files commonly suffer from this problem. To do this, call AddRef() with the field name "refs" and add an entry_ref pointing to the file you wish to pass this may. Multiple entry_ref objects can be sent just by doing it more than once. If your program is going to handle these kinds of drops file references, it should look for multiple entries in the 'refs' field unless it would be inappropriate to do so.
Image Data
If your program uses a different kind of data than what has already been standardized, there are some guidelines you can follow so that other programs can use it. First, make sure that the data that is put on the clipboard is in as generalized a form as possible.


Name: class

Descriptions: "BBitmap"

Field Type: B_RECT_TYPE

Name: _frame

Descriptions: A BRect containing the bounds of the bitmap data in pixels

Field Type: B_INT32_TYPE

Name: _cspace

Descriptions: The color_space constant for the image data, such as B_RGBA32

Field Type: B_INT32_TYPE

Name: _bmflags

Descriptions: The Flags() argument from BBitmap

Field Type: B_INT32_TYPE

Name: _rowbytes

Descriptions: The number of bytes per row, including padding

Field Type: B_RAW_TYPE

Name: _data

Descriptions: The raw image data

Field Type: B_POINT_TYPE

Name: be:location

Descriptions: The location from which the image data was copied. May be ignored.

Материалы сообщества доступны в соответствии с условиями лицензии CC-BY-SA , если не указано иное.