Problem
GTK# documentation and examples do not provide excessive information about using Gtk.Clipboard
object to get various types of content. To get text from clipboard, the Gtk.Clipboard.WaitForText()
method could be used, but how to get, by example, HTML table from LibreOffice Writer document or formatted text from webpage?
Solution
In this solution we:
- Create target using
Gdk.Atom.Intern()
method, passing MIME type stringtext/html
to it. - Get selection object by using
Gtk.Clipboard.WaitForContents()
method for created target. - If the selection is not null, then it’s
Data
property generally contains UTF-8 encoded string with HTML markup.
The solution is currently tested only on Linux with Mono 3.10.
Note, that Gtk.Clipboard.WaitForTargets()
method in the GTK# 2.12 seems to have broken interface. It defined as bool WaitForTargets (Gdk.Atom targets, out int n_targets)
, but should be something like bool WaitForTargets (Gdk.Atom [] targets, out int n_targets)
to return array of available targets. As a result, we can’t see what targets are available in the clipboard, but only a number of them:
More to Explore
We got the basic example to work, but many things are need to be explored:
- Primary: the selection data encoding seems to not always UTF-8, so we need a way to determine the encoding.
- Which other common MIME types are supported by
Gtk.Clipboard
? - How this code will behave on the different platforms?