Re: How to get the reference to widgets which were attached to a GtkTable, GtkVBox?



pythonstudy wrote:

I checked the head file of GtkTable and did not find a function to do
that. Why?

It can be done by using the GList * children in the structure. I just
thought it might be another way to do it. I mean I think it's a common
requirement to get a reference by xpos and ypos. ( Can't always keep a
global reference list for all time. :p ) so the function might exist.
I doubt why not there.

Getting references to widgets by xpos and ypos is probably NOT a common
requirement. Note that for a proper GTK+ GUI the programmer should never
be required to deal with pixel values / positions of the widgets. That's
why means to access them in GTK+ are rather hidden than obvious.

Some graphical applications may need exact pixel values for drawing
operations but they usually draw inside one or few special widgets only
and still don't need to reference arbitrary widgets by their onscreen
positions.

However, what you may be looking for instead is one of the following:

http://developer.gnome.org/doc/API/2.0/gtk/GtkContainer.html#gtk-container-get-children
http://developer.gnome.org/doc/API/2.0/gtk/GtkContainer.html#gtk-container-foreach

If your widgets are all named comprehensible then you may also like to
use a convenience function like this:
http://www.spamkiller.bytechase.cx/democode/widget_find_by_name.c

The reason why you don't find those functions in neither GtkTable nor
GtkVBox is that they apply to both of them, and others like GtkHBox,
GtkList and GtkTree as well.

GTK+ uses an object oriented programming model. Functions which apply to
multiple classes are usually not defined + implemented multiple times
inside of them, but rather once in parent classes. GtkContainer is such
a parent class for both GtkTable and GtkVBox. All its functions and
properties apply to all of its child classes (i.e. GtkTable, GtkVBox) as
well.

Actually GtkVBox and GtkHBox are no direct children of GtkContainer. In
between sits GtkBox. So GtkVBox is a child class of GtkBox, which is a
child class of GtkContainer. All of them are children of GtkWidget as
well, btw. So all operations which require a GtkWidget can be applied to
any of the widget classes mentioned here.

The tree-like structures of parent and child classes can be seen in
sections "Object Hierarchy" of the class documentations, i.e. in
http://developer.gnome.org/doc/API/2.0/gtk/GtkBox.html

The complete list of all GTK classes (it's not necessary to know / learn
by heart all of them) can be found at:
http://developer.gnome.org/doc/API/2.0/gtk/ch01.html

If you're not familiar with object oriented programming (OOP) then you
should make yourself familiar with the basics of it in general. There
are many free tutorials available in the WWW. Although most of them
focus on languages like C++ or Java (which provide language specific
extra support for OOP) most of the principles also apply for programming
GTK+ in C.



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