Re: calling functions defined in gtk's source file



On Sun, Oct 07, 2007 at 03:15:57PM +0200, Joël Krähemann wrote:
hello I want to call in my application functions like gtk_window_show,
gtk_widget_real_show and others

You cannot.  These are private Gtk+ functions (you should
have noticed they are delcared as static and therefore
visible ony to the source file that contains them).  They do
not belong to the public API and they can disappear, be
renamed or change the arguments and return values any time

Well, those implementing a virtual method cannot really
change arguments, but if they implement a virtual method,
then you should invoke the virtual method, NOT the function
implementing it.

the c file

void
ags_window_class_init(AgsWindow *window)
{
  GtkWidgetClass *widget = (GtkWidgetClass *) window;

  widget->show = ags_window_show;
}

void
ags_window_show(GtkWidget *widget)
{
  gtk_window_show(widget);
}

And if you want to call the parent's virtual method in
a subclass, do precisely that.  How do you know the nearest
parent that actually implements the method?  In most cases
you cannot.  It can even change from version to version.

That's why you can find this idiom common in the Gtk+ code:

  if (GTK_WIDGET_CLASS(args_window_parent_class)->show)
      GTK_WIDGET_CLASS(args_window_parent_class)->show(widget);

where args_window_parent_class is defined automatically if
you use the G_DEFINE_TYPE template macros.

If you are 100% sure the parent class always has implemented
and always will implement the virtual function, you can omit
the if-clause and just call the method.

Yeti

--
http://gwyddion.net/



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