Editing Documentation/Maemo 5 Developer Guide/Using Data Sharing/Clipboard Usage
Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
- | In | + | =Overview= |
+ | |||
+ | In maemo, there is a number of clipboard enhancements to the X clipboard and Gtk+, in order to | ||
* Support retaining the clipboard data when applications that own the clipboard exit. | * Support retaining the clipboard data when applications that own the clipboard exit. | ||
- | * Be able to copy and paste rich text data between | + | * Be able to copy and paste rich text data between Gtk+ text views in different applications. |
- | * Provide a generally more pleasant user experience; make it easy for application developers to gray out ``Paste'' menu items when the clipboard data format is not supported by the application. | + | * <nowiki>Provide a generally more pleasant user experience; make it easy for application developers to gray out ``Paste'' menu items when the clipboard data format is not supported by the application. </nowiki> |
This section uses the following example code: | This section uses the following example code: | ||
- | * [https:// | + | * [https://garage.maemo.org/svn/maemoexamples/trunk/maemopad/src/ maemopad] |
- | + | =GtkClipboard API changes = | |
- | < | + | <tt>gboolean <span>'''<span><font color="#000000">gtk_clipboard_set_can_store</font></span>'''</span> <span><font color="#990000">(</font></span>GtkClipboard <span><font color="#990000"><nowiki>*</nowiki></font></span>clipboard |
- | + | GtkTargetEntry <span><font color="#990000"><nowiki>*</nowiki></font></span>targets<span><font color="#990000">,</font></span> | |
- | + | gint n_targets<span><font color="#990000">);</font></span></tt> | |
- | + | ||
- | </ | + | |
- | This function sets what data targets the current clipboard owner can transfer to the clipboard manager. | + | This function sets what data targets the current clipboard owner can transfer to the clipboard manager. NULL can be passed as targets, together with 0 as n_targets to indicate that all targets can be transferred. |
When the clipboard owner changes, these values are reset. | When the clipboard owner changes, these values are reset. | ||
- | < | + | <tt><span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">gtk_clipboard_store</font></span>'''</span> <span><font color="#990000">(</font></span>GtkClipboard <span><font color="#990000"><nowiki>*</nowiki></font></span>clipboard<span><font color="#990000">);</font></span></tt> |
- | void gtk_clipboard_store (GtkClipboard *clipboard); | + | |
- | </ | + | |
- | This function tells the clipboard to try and store the contents of the targets specified using | + | This function tells the clipboard to try and store the contents of the targets specified using gtk_clipboard_set_can_store. If no such call has been made, or if there is no clipboard manager around, this function is simply a no-op. |
- | Applications can call this function when exiting, but it is called automatically, when the application is quitting, if quitting with | + | Applications can call this function when exiting, but it is called automatically, when the application is quitting, if quitting with gtk_main_quit(). If the application is not the owner of the clipboard, the function will simply be a no-op. |
- | In addition, adding a convenience function for finding out if a target is supported (in order to be able to gray out ``Paste'' items, if none of the existing clipboard targets are supported) | + | <nowiki> In addition, adding a convenience function for finding out if a target is supported (in order to be able to gray out ``Paste'' items, if none of the existing clipboard targets are supported) </nowiki> |
- | < | + | <tt>gboolean <span>'''<span><font color="#000000">gtk_clipboard_wait_is_target_available</font></span>'''</span> <span><font color="#990000">(</font></span>GtkClipboard <span><font color="#990000"><nowiki>*</nowiki></font></span>clipboard<span><font color="#990000">,</font></span> |
- | + | GdkAtom target<span><font color="#990000">);</font></span></tt> | |
- | + | ||
- | </ | + | |
- | + | = GtkTextBuffer API changes = | |
In order to support rich text copy and paste, some new functions were introduced: | In order to support rich text copy and paste, some new functions were introduced: | ||
- | < | + | <tt><span><font color="#009900">void</font></span> |
- | void | + | <span>'''<span><font color="#000000">gtk_text_buffer_set_enable_paste_rich_text</font></span>'''</span> <span><font color="#990000">(</font></span>GtkTextBuffer <span><font color="#990000"><nowiki>*</nowiki></font></span>buffer<span><font color="#990000">,</font></span> |
- | gtk_text_buffer_set_enable_paste_rich_text (GtkTextBuffer *buffer, | + | gboolean can_paste_rich_text<span><font color="#990000">);</font></span> |
- | + | gboolean | |
- | gboolean | + | <span>'''<span><font color="#000000">gtk_text_buffer_get_enable_paste_rich_text</font></span>'''</span> <span><font color="#990000">(</font></span>GtkTextBuffer <span><font color="#990000"><nowiki>*</nowiki></font></span>buffer<span><font color="#990000">);</font></span></tt> |
- | gtk_text_buffer_get_enable_paste_rich_text (GtkTextBuffer *buffer); | + | |
- | </ | + | |
The setter function toggles, whether it should be possible to paste rich text in a text buffer. | The setter function toggles, whether it should be possible to paste rich text in a text buffer. | ||
- | To prevent applications from getting confused, when text with unexpected tags is pasted to a buffer, the notion of | + | <nowiki> To prevent applications from getting confused, when text with unexpected tags is pasted to a buffer, the notion of ``rich text format'' was added: </nowiki> |
- | < | + | <tt><span><font color="#009900">void</font></span> |
- | void | + | <span>'''<span><font color="#000000">gtk_text_buffer_set_rich_text_format</font></span>'''</span> <span><font color="#990000">(</font></span>GtkTextBuffer <span><font color="#990000"><nowiki>*</nowiki></font></span>buffer<span><font color="#990000">,</font></span> |
- | gtk_text_buffer_set_rich_text_format (GtkTextBuffer *buffer, | + | <span>'''<span><font color="#0000FF">const</font></span>'''</span> gchar <span><font color="#990000"><nowiki>*</nowiki></font></span>format<span><font color="#990000">);</font></span> |
- | + | G_CONST_RETURN <span><font color="#990000"><nowiki>*</nowiki></font></span> | |
- | G_CONST_RETURN * | + | <span>'''<span><font color="#000000">gtk_text_buffer_get_rich_text_format</font></span>'''</span> <span><font color="#990000">(</font></span>GtkTextBuffer <span><font color="#990000"><nowiki>*</nowiki></font></span>buffer<span><font color="#990000">);</font></span></tt> |
- | gtk_text_buffer_get_rich_text_format (GtkTextBuffer *buffer); | + | |
- | </ | + | |
- | When a buffer has a certain text format, it can only paste rich text from buffers that have the same text format. If the formats differ, only plain text will be pasted. If a buffer has its format set to | + | <nowiki> When a buffer has a certain text format, it can only paste rich text from buffers that have the same text format. If the formats differ, only plain text will be pasted. If a buffer has its format set to NULL, it means that it can paste from any format. For example, a format called ``html'' could include the tags ``bold'', ``italic'' etc. Thus, it would only be possible to paste text from buffers having the same format specified. </nowiki> |
'''N.B.''' The string is just an identifier. It is up to the application developers to make sure that when specifying an application as supporting a certain format, also the tags in the buffer are specified for that format. | '''N.B.''' The string is just an identifier. It is up to the application developers to make sure that when specifying an application as supporting a certain format, also the tags in the buffer are specified for that format. | ||
- | For further details, | + | For further details, MaemoPad source code is a good example to study. |
- | + | ||
- | + | ||
- | + | ||
- | + |
Learn more about Contributing to the wiki.