Re: How to obtain type of a widget?



On Mon, May 29, 2006 at 01:44:20PM +0200, Daniel Haude wrote:
I'd like to go through a number of widgets (children of a container  
widget) and to perform certain actions depending on the type of the  
widget. Like:

switch (widget_type) {
      case GTK_ENTRY : ...
      case GTK_COMBO_BOX ...
}

I'm sure it is possible but I don't know how.

Suggestions?

First of all, are you sure you want to exclude all derived
types?  If it is really so:

    GType type;

    type = G_TYPE_FROM_INSTANCE(widget);
    if (type == GTK_TYPE_ENTRY) {
        ...
    }
    else if (type == ...

(switch+case is not possible as types are allocated
run-time).

But if you want to accept subclasses too:

   if (GTK_IS_ENTRY(widget)) {
       ...
   }
   else if (GTK_IS...

Yeti


--
Anonyms eat their boogers.



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