Re: [Vala] How to call base constructors



În data de Mi, 06-05-2009 la 17:48 +0000, Jan Hudec a scris:
Vlad Grecescu <b100dian    > writes:
On Mon, May 4, 2009 at 4:40 PM, Adi Roiban 
<adi roiban ro> wrote:
I'm trying to extend the Gtk.CheckMenuItem and unfortunately there are
no set_label or set_mnemonic methods.
I was thinking to call the base constructor, but instead of
gtk_check_menu_item_new_with_label, vala generates
gtk_check_menu_item_construct_with_label
Do you know how can I call a base constructor?

You don't want to call gtk_check_menu_item_new_with_label, because it's
not a constructor! It's an allocator, which is not the thing you want.
True! 

My goal is to call the contructor callend for
gtk_check_menu_item_new_with_label

GObject is limited to initializing base objects is by setting their
construct-time properties. Unfortunately the check_menu_item does not seem to
have one for label or mnemonic, so you'll have to manually
   add(new Gtk.Label(...))
in your constructor.
That's what I did... but I don't want to recreate the widget.
It is not feasible for more complex widgets.

Other thing is, that you should only ever subclass widgets when you want to
modify their look & feel, not to implement functionality. And if you are to
override the look & feel, you probably don't want to add a plain label, no?
So you should not need those base constructors in your case anyway.
True!

Functionality is better implemented by connecting handlers to the signals
emited by the widget, where the handlers are implemented either in a class
representing the document or dialog. You can also take advantage of the
GtkAction (GtkToggleAction in your case) class, that can connect to or serve
as factory for menu items, buttons and toolbar buttons and inherit that to
provide your common functionality.
True!
Basicaly, that what I wanted to do .... but I failed.

For example in the case of MenuItem, we have the "activated" signal and
there is not way to pass userdata when connecting the signal.

The method called for the "activate" signal will only receive a pointer
to the MenuItem... and I can not pass userdata.

Maybe this is a problem with GTK bindings for Vala.


Thank you for your help!

Cheers!
-- 
Adi Roiban




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