Re: User data in GtkText?




Tim Janik <timj@gtk.org> writes:

Thomas Mailund Jensen <mailund@daimi.aau.dk> writes:
> 
> > In that case, I would really appreciate adding user data ASAP, since
> > it is currently necessary to patch the text widget to use my editor
> > widget.
> 
> i played with your patch a little today, since i'd like to get it into
> the next gtk release (atfer owen gave his ok).
> there are some minor issues about your patch, fisrt every *.gz
> patch file in gtk+/patches from you gives me a "compression data error"
> or something the like. i could only get acces to the .tar.gz stuff.

(I noticed that too, but only the older ones, which have been replaced
 with the newer ones were affected, so it wasn't in the end
 a problem)

> then, i'd like the `destroy' function to be passed with the data,
> conforming to e.g.
> void gtk_clist_set_row_data_full (GtkCList * clist,
>                                   gint row,
>                                   gpointer data,
>                                   GtkDestroyNotify destroy);
> so the `destroy' function is not implemented on the class basis.
> also, i'm not sure why we need a class function for user data comparision,
> couldn't the user data portion of a property just be ignored for comparisions?

Comparison is needed so that when inserting new text in, 
the property lists can be merged. (E.g., each time a character
is typed, GtkText finds the Font/Color/etc. at the cursor, and then
calls a generic insertion function with that information. So
the comparison is needed, to keep each new character from
getting a different property. 

The duplication function is needed because properties may
be split by inserting in the middle of one.

(There is an alternate approach we could take, which would be
to add an extra level of indirection and reference count 
the user data ourself, so we have:
 
struct _TextProperty
{
  TextFont* font;
  GdkColor back_color;
  GdkColor fore_color;
  TextUserData user_data;
  guint length;
};

struct _TextUserData
{
  guint refcount;
  gpointer user_data;
  GtkDestroyNotify destroy;
}
 
In this case, one could use simple pointer comparison. However,
the original approach of user-supplied functions may be 
considerably more efficient in some circumstances)
 
[ More comments elsewhere... ]

Regards,
                                        Owen



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