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

(use <source> and <code>, wikify slightly)
m (GtkTextBuffer API changes: MaemoPad link)
 
(One intermediate revision not shown)
Line 49: Line 49:
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:
+
To prevent applications from getting confused, when text with unexpected tags is pasted to a buffer, the notion of ''rich text format'' was added:
<source lang="c">
<source lang="c">
Line 59: Line 59:
</source>
</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.
+
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:Development]]
[[Category:Documentation]]
[[Category:Documentation]]
[[Category:Fremantle]]
[[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.