Re: GTK clipboard on OS X



On Sat, 18 Jul 2009, Olivier Guilyardi wrote:

On 07/18/2009 10:39 PM, Olivier Guilyardi wrote:
On 07/18/2009 05:01 AM, Allin Cottrell wrote:
In some contexts my GTK app offers the user the opportunity to
copy chunks of output to the clipboard as RTF.  This is primarily
intended for use on MS Windows, but it also works fine for pasting
into (e.g.) an OpenOffice text document on Linux.  The chunk is
advertised via the relevant GtkTargetEntry as "application/rtf".

But this doesn't work on OS X (using GTK 2.14.N under X11).  All
paste targets, even ones that are certainly RTF-aware such as
OpenOffice, seem to ignore application/rtf and request plain text,
so that if pasting succeeds at all, it is just a raw dump of the
RTF "code".

If this a known issue of GTK/X11 on the Mac?  Is there a
workaround?  Or does it look as if I'm doing something wrong?
Thanks.

I can't tell about X11 but the clipboard seems to work ok
between my GTK-OSX 2.16 app and native OSX software, although
GtkEntry expects Ctrl+* instead of Cmd+* shortcuts.

Oups.. please ignore my answer above. I read too fast, and
didn't understand your rtf-specific issue. I was talking about
basic clipboard operations.

I can report a bit more about GTK, RTF and the clipboard on OS X.
The main limitation on what I have to say is that I'm relying on
the "gtk2-framework" distribution prepared by I-don't-know-who,
available at http://r.research.att.com/ , which is a build
of GTK 2.14.3.  I'm not in a position to build current GTK on OS X
myself, which seems like serious rocket science.

That said, the clipboard interaction for RTF appears to be broken
on the GTK I'm trying.  In the case of an RTF source, I'm
attempting to make it available via

gtk_clipboard_set_with_owner() and
gtk_selection_data_set()

using this array of targets:

GtkTargetEntry rtf_targets[] = {
    { "application/rtf",   0, TARGET_RTF },
    { "application/x-rtf", 0, TARGET_RTF },
    { "text/rtf",          0, TARGET_RTF },
    { "text/richtext",     0, TARGET_RTF },
    { "STRING",            0, TARGET_STRING },
    { "TEXT",              0, TARGET_TEXT }
};

(where the TARGET_* values are members of a local enum) in
conjunction with the following call:

        gtk_selection_data_set(selection_data,
                               GDK_SELECTION_TYPE_STRING,
                               8 * sizeof(gchar),
                               (guchar *) str,
                               strlen(str));

where "str" is a well-formed RTF buffer.

As I said, this works fine on Linux; it also works fine on MS
Windows.  But on OS X the "pastee" grabs plain text (raw RTF
markup), not RTF.

I tried the experiment of removing the last two (non-RTF) targets
from the GtkTargetEntry array I was passing to
gtk_clipboard_set_with_owner().  In that case the apps I tried
pasting into on OS X complained that the format they had requested
was not available, and didn't paste anything.

Now here's the final test: I tried putting in a special workaround
for OS X.  When pasting RTF to the clipboard, instead of using the
GTK mechanism described above, do popen() on /usr/bin/pbcopy and
dump the prepared string into that pipe.  This works perfectly:
OpenOffice (for example) pastes the RTF as RTF.  (pbcopy is a Mac
utility that puts stdin onto the clipboard -- or "pasteboard" as
they call it -- and that recognizes RTF via its header.)

Allin Cottrell






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