Re: PROP_TYPE_LIST declaration



On Thu, 10 Apr 2003, ashalper cox net wrote:
I was wondering if someone could help me out with a PROP_TYPE_LIST
declaration (I couldn't find any examples in the CVS code). 

There aren't any, in fact.

Note that if your list is static, you may want to use PROP_TYPE_ENUM.  I
think it's prettier and easier to deal with (though I may end up changing
the PROP_TYPE_LIST widget (or even removing it -- there's not much
difference between the two, all PROP_TYPE_LIST seems to have going for it
is that it uses GPtrArray)).

I think I've got my PropDescription struct correct, but I need help on
the offsets and the declaration in my object struct.  The PROP_TYPE_LIST
macro in properties.h is:

#define PROP_TYPE_LIST "list"  /* ListProperty */
/* (offset is a GPtrArray of (const gchar *). offset2 is a gint, index of the 
   active item, -1 if none active.) */

My object struct looks something like:

typedef struct _Independent {
  Element element;

  GPtrArray *column_list;     /* the ListProperty? */
     .
     .
     .

} Independent;

but I'm missing the index, and I'm not at all sure how to declare the
PropOffset array correctly.

You need to declare the index within your structure as well:

   GPtrArray *column_list;      /* The list of items */
   int column_list_index;       /* The currently selected item */

To declare a ListProp in the PropOffset array, you give it the offset of
both the list and the index:

  { "column_list", PROP_TYPE_LIST, offsetof(Independent, column_list),
                                   offsetof(Independent, column_list_index) },

Remember to create the GPtrArray when you create the array, and set the
index to something reasonable (-1 for no initial selection).  You may also
need to do a deep copy of the list when the object gets copied.

-Lars

-- 
Lars Clausen (http://shasta.cs.uiuc.edu/~lrclause)| HÃrdgrim of Numenor
"I do not agree with a word that you say, but I   |----------------------------
will defend to the death your right to say it."   | Where are we going, and
    --Evelyn Beatrice Hall paraphrasing Voltaire  | what's with the handbasket?



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