How about this:
static char* iListGetValueStringAttrib(Ihandle* ih)
{
if (!ih->data->has_editbox && (ih->data->is_dropdown ||
!ih->data->is_multiple))
{
int i = IupGetInt(ih, "VALUE");
return IupGetAttributeId(ih, "", i);
}
return NULL;
}
static int iListSetValueStringAttrib(Ihandle* ih, const char* value)
{
if (!ih->data->has_editbox && (ih->data->is_dropdown ||
!ih->data->is_multiple))
{
int i, count = iListGetCount(ih);
for (i = 1; i <= count; i++)
{
char* item = IupGetAttributeId(ih, "", i);
if (iupStrEqual(value, item))
{
IupSetInt(ih, "VALUE", i);
return 0;
}
}
}
return 0;
}
Just committed to SVN.
Best,
Scuri
On Wed, Oct 8, 2014 at 5:25 AM, Benoit Germain <[email protected]>
wrote:
> Hello,
>
> According to the iup.list documentation, we have:
>
> *VALUE* (non inheritable): Depends on the DROPDOWN+EDITBOX combination:
>
> - DROPDOWN=YES or MULTIPLE=NO: Integer number representing the
> selected item in the list (begins at 1). It can be zero if there is no
> selected item. The value can be NULL for no item selected (since 3.0) (In
> Motif when DROPDOWN=YES there is always an item selected, except only when
> the list is empty).
>
>
> This means that the value we get/set is an index (which is in fact
> returned as a string).
>
> My request would be to be able to get/set value with an actual string
> present in the list instead of an index, possibly through another attribute
> valuestring.
>
> This would be useful when creating interfaces used to edit data. The data
> item associated to a dropdown is saved by storing the list entry's string
> and not by its index (in case we add new elements to the possible values
> and the list is sorted, which would break existing data because of
> reordering). Currently, reading the value involves doing
> my_list[my_list.value], and setting the value from loaded data is even
> worse: we have to iterate over all strings present in the list, looking for
> the one we got from the data, and set the list value to the index where we
> found it.
>
> Of course, this poses a problem when the list contains several occurrences
> of the same string, but then setting valuestring would select the first
> encountered one.
>
> So if I have a list
>
> my_list = iup.list{ "this", "is", "a", "list"}
>
> I would have
>
> my_list.value = 2 -- my_list displays "is"
> val = my_list.value -- return 2
> val = my_list.valuestring -- return "is"
> my_list.valuestring = "this" -- -- my_list selects "this"
> my_list.value -- return 1
>
>
> What do you think?
>
>
> Regards,
>
>
> --
> Benoit.
>
>
> ------------------------------------------------------------------------------
> Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
> Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
> Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
> Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
>
> http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
> _______________________________________________
> Iup-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/iup-users
>
>
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Iup-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/iup-users