Re: An interface! / GtkEntry,GtkEditable,GtkOldEditable



On 14 Sep 2000, Owen Taylor wrote:

> A possibly odd thing about GtkEditable is that to conform to the
> GtkEditable interface, you need to not just export the vtable in the
> GObject manner, you also need to have a 'editable' argument and
> ::cut_clipboard, ::copy_clipboard, and ::paste_clipboard action
> signals.

as for the signals, we can't simply rely on the class that an
interface is being introduced for to come with certain signals.
instead, the signals have to be introduced for the interface
type, though, obviously GtkSignal doesn't account for that,
but GSignal will (does).
on the parameters, i'm not so sure, i'm having a hard time imagining
how to enforce existance of certain properties for a class that's
supposed to export a certain interface (suggestions welcome ;)

> I've appended gtkeditable.[ch] below and also gtkoldeditable.[ch]
> as an example of a class exporting GtkEditable. I'd appreciate
> if Tim in particular would take a look at this and see if
> it matches his imagination for how the interfaces would be
> used.

pretty much, and the implementaitons do btw look exceptionally clean ;)

> Notes on GInterface (in addition to the previous comment that
> interfaces vtables should simply be initialized in the class_init
> function):
> 
>  - The GInterfaceInfo argument g_type_add_interface_static needs
>    to be const.

yep sure. though i have to note that i don't see us gaining any advantage
from making the interface type a static one. suppose someone implements
a GtkSomethingEditable as a dynamic type, and wants to export the
GtkEditable interface for it. for that, the type system wouldn't be
able to ever unload GtkSomethingEditable anymore, because one of the
interfaces it exports doesn't provide unloading facilities.

>  - There clearly needs to be G_TYPE_INSTANCE_GET_IFACE macro
>    to simplify:
> 
>   #define GTK_EDITABLE_GET_IFACE(obj) \
>     ((GtkEditableIface *)g_type_interface_peek (((GTypeInstance *)GTK_EDITABLE (obj))->g_class, \
>                                                 GTK_TYPE_EDITABLE))

jup.

> 
> Other than that, the interface stuff seemed to work flawlessly.

that is strange. really. ;)
see, you do:

struct _GtkEditableIface
{
  /* Signals for notification/filtering of changes */
  void (* insert_text)              (GtkEditable    *editable,
                                     const gchar    *text,
                                     gint            length,
                                     gint           *position);

but you actually have to (as with classes and instances) do:

struct _GtkEditableIface
{
  GTypeInterface g_iface;
  
  /* Signals for notification/filtering of changes */
  void (* insert_text)              (GtkEditable    *editable,
                                     const gchar    *text,
                                     gint            length,
                                     gint           *position);

so the type system has enough room to store away necessary
type information to do cinstance vtable checks etc.

other than that, i'm pretty happy with this first publicized
interface implementaiton ;)

> 
> Regards,
>                                         Owen
> 

---
ciaoTJ





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