Rich Text copy and paste (bug #324177)

Hi all,

In the last few weeks, I've been working on refactoring and extending
a patch from maemo-gtk which enables copy/paste and DND of rich text
from/to GtkTextBuffer and GtkTextView.

It's here:

The patch has seen several iterations and extensions and has grown
to a medium API addition, so an announcement here is due.

It consists of several parts:

1. gtkrichtext.[ch] which allows to register rich text serialization
   and deserialization functions together with a mime-type for the
   serialized data. Along with the mime-type, one can register
   a "tagset". While the mime-type determines the format of the
   serialized data, the tagset restricts the text buffer tags that
   can be serialized/deserialized. Tagsets are registerd by their
   names, which are pure convention, and don't specify the set of
   tags that are allowed. The NULL tagset is special: it allows
   all kinds of tags and a deserialization function supporting
   the NULL tagset is allowed to create new tags in the receiving

2. gtkclipboard.[ch] and gtkselection.[ch] were extended to contain
   the usual bunch of convenience function, just as they exist
   for plain text and images.

3. gtktextutil.[ch] got a function to create a rich text DND icon

4. gtktextbufferserialize.[ch] contains (de)serialization functions
   for an internal format that just works between two text buffers.
   It is able to transport all tags plus embedded pixbufs. The
   format's mime-type is "application/x-gtk-text-buffer-rich-text"

5. gtktextbuffer.[ch] and gtktextview.c make use of all that stuff
   to enable copy/paste and DND. GtkTextBuffer got APIs to enable
   rich text pasting and to specify the tagsets it supports for both
   copy/drag and paste/drop. Rich text copy/drag in all registered
   formats is always enabled.

What is a "tagset"?

   Best explained by a small usecase: imagine you have an email client
   which has GUI to set bold, italic and underline text attributes.
   You don't want arbitrary rich text being pasted into that buffer.
   Most importantly, you don't want new tags being generated by pasting,
   because your app doesn't have a GUI for them. The way to go is to
   restrict pasting by just inventing a tagset name for your text
   buffer's features, e.g. "my-foobar-email-client-tagset", and register
   that tagset with both the rich text registry *and* all text buffers
   in your client. This way rich text pasting will be enabled between
   the open documents in the email client.

Missing Stuff:

   Currently, the patch allows having a NULL tagset on the receiving
   side, or a list of non-NULL tagsets. That's a restriction, because
   there may be use cases where one wants to allow both arbitrary stuff
   *and* well-defined formats. I'm currently working on changing the
   patch to allow this (by adding a boolean "can-receive-new-tags"
   property on the text buffer)

   Because allowing rich text transfer only between buffers of the same
   application (or group of applications) is rather boring, we need a
   simple rich text format that covers basic stuff, in addition to the
   existing functions which can handle everything. IMHO the best thing
   to do would be to use GMarkup together with a small, well defined set
   of allowed attributes (like <b>, <i>, <u>) and call that
   "gtk-simple-markup-tagset" or something.

awaiting your comments,

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]