Documentation/Maemo 5 Developer Guide/Using Data Sharing/Clipboard Usage

(Overview)
m (GtkTextBuffer API changes: MaemoPad link)
 
(6 intermediate revisions not shown)
Line 1: Line 1:
-
=Overview=
+
In Maemo, there is a number of clipboard enhancements to the X clipboard and Gtk+, in order to
-
 
+
-
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.
-
* <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>
+
* 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.
This section uses the following example code:
This section uses the following example code:
-
* [https://garage.maemo.org/svn/maemoexamples/trunk/maemopad/src/ maemopad]
+
* [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/maemopad/src/ maemopad]
-
=GtkClipboard API changes =
+
== 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
+
<source lang="c">
-
                                      GtkTargetEntry <span><font color="#990000"><nowiki>*</nowiki></font></span>targets<span><font color="#990000">,</font></span>
+
gboolean gtk_clipboard_set_can_store (GtkClipboard  *clipboard
-
                                      gint            n_targets<span><font color="#990000">);</font></span></tt>
+
                                      GtkTargetEntry *targets,
 +
                                      gint            n_targets);
 +
</source>
-
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.
+
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.
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>
+
<source lang="c">
 +
void gtk_clipboard_store (GtkClipboard *clipboard);
 +
</source>
-
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.
+
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.
-
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.
+
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.
-
<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>
+
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)
-
<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>
+
<source lang="c">
-
                                                  GdkAtom      target<span><font color="#990000">);</font></span></tt>
+
gboolean gtk_clipboard_wait_is_target_available (GtkClipboard *clipboard,
 +
                                                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:
-
<tt><span><font color="#009900">void</font></span>
+
<source lang="c">
-
<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>
+
void
-
                                            gboolean      can_paste_rich_text<span><font color="#990000">);</font></span>
+
gtk_text_buffer_set_enable_paste_rich_text (GtkTextBuffer *buffer,
-
gboolean
+
                                            gboolean      can_paste_rich_text);
-
<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>
+
gboolean
 +
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.
-
<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>
+
To prevent applications from getting confused, when text with unexpected tags is pasted to a buffer, the notion of ''rich text format'' was added:
-
<tt><span><font color="#009900">void</font></span>
+
<source lang="c">
-
<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>
+
void
-
                                      <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>
+
gtk_text_buffer_set_rich_text_format (GtkTextBuffer *buffer,
-
G_CONST_RETURN <span><font color="#990000"><nowiki>*</nowiki></font></span>
+
                                      const gchar  *format);
-
<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>
+
G_CONST_RETURN *
 +
gtk_text_buffer_get_rich_text_format (GtkTextBuffer *buffer);
 +
</source>
-
<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>
+
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.
'''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, MaemoPad source code is a good example to study.
+
For further details, [[Documentation/Maemo 5 Developer Guide/Application Development/Writing a new maemo application|MaemoPad]] source code is a good example to study.
 +
 
 +
[[Category:Development]]
 +
[[Category:Documentation]]
 +
[[Category:Fremantle]]

Latest revision as of 11:49, 8 September 2010

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.
  • 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.

This section uses the following example code:

[edit] GtkClipboard API changes

gboolean gtk_clipboard_set_can_store (GtkClipboard   *clipboard
                                      GtkTargetEntry *targets,
                                      gint            n_targets);

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.

void gtk_clipboard_store (GtkClipboard *clipboard);

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

gboolean gtk_clipboard_wait_is_target_available (GtkClipboard *clipboard,
                                                 GdkAtom       target);

[edit] GtkTextBuffer API changes

In order to support rich text copy and paste, some new functions were introduced:

void
gtk_text_buffer_set_enable_paste_rich_text (GtkTextBuffer *buffer,
                                            gboolean       can_paste_rich_text);
gboolean
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.

To prevent applications from getting confused, when text with unexpected tags is pasted to a buffer, the notion of rich text format was added:

void
gtk_text_buffer_set_rich_text_format (GtkTextBuffer *buffer,
                                      const gchar   *format);
G_CONST_RETURN *
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 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.

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, MaemoPad source code is a good example to study.