Re: Patch GtkSelection 2.16




On Jan 17, 2009, at 12:29 PM, Emmanuel Rodriguez wrote:

Hi,

Here's the patch for upgrading GtkSelection to Gtk 2.16.

This patch is tricky and needs some revision because the new method added gtk_selection_data_get_selection() exists already and is aliased to 13 methods! Here's the old definition:

[snip]

I renamed the old implementation get_selection_. I used such an ugly syntax in order to stress that this is a private method, at least that's what the lack of documentation seems to be telling.

Not necessary.  If you look in cases 0 and 1, you'll see

            /* selection doesn't have an accessor yet. */
            RETVAL = newSVGdkAtom (d->selection);

but the other cases look like this:

    #if GTK_CHECK_VERSION (2, 14, 0)
            RETVAL = newSVGdkAtom (gtk_selection_data_get_target (d));
    #else
            RETVAL = newSVGdkAtom (d->target);
    #endif

So, the existing get_selection() is just a single xsub that is aliased to all those others to reduce the amount of duplicated boilerplate code that gets compiled. All you have to do is change the first case to

    #if GTK_CHECK_VERSION (2, 15, 0) /* FIXME 2.16.0 */
RETVAL = newSVGdkAtom (gtk_selection_data_get_selection (d));
    #else
            RETVAL = newSVGdkAtom (d->selection);
    #endif

And you're done.

For extra points, you could golf the code a little bit with these definitions up before the first MODULE:

    #if ! GTK_CHECK_VERSION (2, 15, 0) /* FIXME 2.16 */
    # define gtk_selection_data_get_selection (d)  ((d)->selection)
    #endif
    #if ! GTK_CHECK_VERSION (2, 14, 0)
    # define gtk_selection_data_get_target (d)  ((d)->target)
    # define gtk_selection_data_get_data_type (d)  ((d)->data_type)
    # define gtk_selection_data_get_format (d)  ((d)->format)
    ...
    #endif

and unconditionally use the accessors in the switch.


Index: t/GtkClipboard.t

The clipboard test looks pretty good.




--
If the monkey could type one keystroke every nanosecond, the expected waiting time until the monkey types out Hamlet is so long that the estimated age of the universe is insignificant by comparison ... this is not a practical method for writing plays.
  -- Gian-Carlo Rota





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