[Caml-list] Re: missing gtk_button_set_image in lablgtk

Olivier Andrieu oandrieu at nerim.net
Mon Oct 30 22:54:54 CET 2006


following up on a old thread, sorry for the delay.

 j.romildo at gmail.com [Wednesday 4 October 2006] :
 >
 > On Tue, Oct 03, 2006 at 09:12:58PM +0200, Olivier Andrieu wrote:
 > Content-Description: message body and .signature
 > >  Olivier Andrieu [Tuesday 3 October 2006] :
 > >  > Here is a patch, with a bunch of other missing properties of
 > >  > GtkButton.
 > 
 > > Index: gtkButton.props
 > > ===================================================================
 > > RCS file: /net/yquem/devel/caml/repository/bazar-ocaml/lablgtk/src/gtkButton.props,v
 > > retrieving revision 1.5
 > > diff -u -r1.5 gtkButton.props
 > > --- gtkButton.props	16 Sep 2006 10:33:02 -0000	1.5
 > > +++ gtkButton.props	3 Oct 2006 19:11:02 -0000
 > > @@ -11,10 +11,14 @@
 > >  }
 > >  
 > >  class Button set wrap wrapsig : Bin {
 > > +  "focus-on-click"       gboolean             : Read / Write / NoSet
 > > +  "image"                GtkWidget_opt        : Read / Write / NoSet
 > 
 > It seems that defining image this way, as a property, will force the
 > type of set_image to GObj.widget option -> unit, while one may expect it
 > to be GObj.widget -> unit  , from the Gtk API documentation.

It's the usual problem when wrapping functions that take a pointer
value as argument: is NULL an acceptable value or not ? In this case,
it is. The "right" type mapping in OCaml should be an option type
then.

 > > --- gButton.mli	16 Sep 2006 10:33:02 -0000	1.34
 > > +++ gButton.mli	3 Oct 2006 19:11:02 -0000
 > > @@ -25,6 +25,14 @@
 > >      method use_underline : bool
 > >      method grab_default : unit -> unit
 > >      method event : event_ops
 > > +    method set_focus_on_click : bool -> unit
 > > +    method focus_on_click : bool
 > > +    method image : GObj.widget option             (** @since GTK 2.6 *)
 > > +    method set_image : GObj.widget option -> unit (** @since GTK 2.6 *)
 > 
 > Is this really the type we want for set_image? I am not sure.

Well, having an option argument is a bit cumbersome, I agree. It's not
absolutely required for the getter method since we'd get Gpointer.Null
exception if we try to wrap a NULL value. But if the setter method
only has type `GObj.widget -> unit', then there's no way to unset the
image.  A solution would be to add a 3rd method (I believe there are
couple of unset_* method already in LablGTK).
,----
| method image : GObj.widget
| method set_image : GObj.widget -> unit
| method unset_image : unit -> unit
`----

 > Comparing with the types for label (string), and set_label (string
 > -> unit), option is not used. But probably because here an empty
 > string may be used for un unset label. Although the API doc. says
 > that "If the label text has not been set the return value will be
 > NULL". So, in C, an unset label would return a NULL pointer,
 > instead of the empty string "".

Indeed.

-- 
   Olivier




More information about the Lablgtk-list mailing list