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 Maemo, there is a number of clipboard enhancements to the X clipboard and Gtk+, in order to
+
=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 GTK+ text views in different applications.
+
* 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://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/maemopad/src/ maemopad]
+
* [https://garage.maemo.org/svn/maemoexamples/trunk/maemopad/src/ maemopad]
-
== GtkClipboard API changes ==
+
=GtkClipboard API changes =
-
<source lang="c">
+
<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
-
gboolean gtk_clipboard_set_can_store (GtkClipboard  *clipboard
+
                                      GtkTargetEntry <span><font color="#990000"><nowiki>*</nowiki></font></span>targets<span><font color="#990000">,</font></span>
-
                                      GtkTargetEntry *targets,
+
                                      gint            n_targets<span><font color="#990000">);</font></span></tt>
-
                                      gint            n_targets);
+
-
</source>
+
-
This function sets what data targets the current clipboard owner can transfer to the clipboard manager. <code>NULL</code> can be passed as targets, together with 0 as <code>n_targets</code> to indicate that all targets can be transferred.
+
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.
-
<source lang="c">
+
<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);
+
-
</source>
+
-
This function tells the clipboard to try and store the contents of the targets specified using <code>gtk_clipboard_set_can_store</code>. If no such call has been made, or if there is no clipboard manager around, this function is simply a no-op.
+
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 <code>gtk_main_quit()</code>. If the application is not the owner of the clipboard, the function will simply be a no-op.
+
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>
-
<source lang="c">
+
<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>
-
gboolean gtk_clipboard_wait_is_target_available (GtkClipboard *clipboard,
+
                                                  GdkAtom      target<span><font color="#990000">);</font></span></tt>
-
                                                GdkAtom      target);
+
-
</source>
+
-
== GtkTextBuffer API changes ==
+
= 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:
-
<source lang="c">
+
<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      can_paste_rich_text);
+
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);
+
-
</source>
+
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 ''rich text format'' was added:
+
<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>
-
<source lang="c">
+
<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>
-
                                      const gchar  *format);
+
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);
+
-
</source>
+
-
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 <code>NULL</code>, 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> 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, [[Documentation/Maemo 5 Developer Guide/Application Development/Writing a new maemo application|MaemoPad]] source code is a good example to study.
+
For further details, MaemoPad source code is a good example to study.
-
 
+
-
[[Category:Development]]
+
-
[[Category:Documentation]]
+
-
[[Category:Fremantle]]
+

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)