[XForms] Question #2: Relying on menu subitem IDs after fl_delete_menu_item().

Jason Cipriani jason.cipriani at gmail.com
Fri Jul 4 13:25:31 EDT 2008


To subscribers of the xforms list

On Fri, Jul 4, 2008 at 6:57 AM, Jens Thoms Toerring <jt at toerring.de> wrote:
> To get around that you have to change the file lib/menu.c.
> I append a version for 1.0.90 that hopefully works but I
> didn't test the changes with that version, just my newer
> one. Then add to lib/private/menu.h

Thanks a lot for digging into this. I've tested your changes and so
far everything seems to be working well, I can remove items and use
fl_get_menu_value to get the correct ID.

> This should give you a new function named fl_get_menu_value()
> that expects the menu object and the item index as returned
> by fl_get_menu(). If you now create the menu items in fdesign
> with texts like

One problem that I found is fl_delete_menu_item refers to the item
index, not the value. This can make deleting items pretty tricky. To
that end I've added a function to go the other way, from value to
item. It works for me although I may have missed some things
(specifically, I'm not sure if the ISPUP thing is right -- and also,
is the item index really 1-based?), I tried to make it the inverse of
fl_get_menu_value. Note that if multiple items have the same value,
this returns the first item with that value. Returns -1 if value is
not found.

=== menu.c ===

int
fl_get_menu_item_from_value( FL_OBJECT * ob,
			     int         value )
{

  FL_MENU_SPEC *sp = ob->spec;
  int item;

  if( ISPUP( sp ) )
    return value;

  for( item = 1; item <= sp->numitems; ++ item )
    if (sp->mval[item] == value)
      return item;

  return -1;

}

=== menu.h ===

FL_EXPORT int fl_get_menu_item_from_value(
               FL_OBJECT * ob,
               int         value
               );



Jason
_______________________________________________
To unsubscribe, send any message to
xforms-leave at bob.usuhs.mil or see: 
http://cweblog.usuhs.mil/mailman/listinfo/xforms
List Archive: http://bob.usuhs.mil/pipermail/xforms and
http://bob.usuhs.mil/mailserv/list-archives/
Development: http://savannah.nongnu.org/files/?group=xforms



More information about the Xforms mailing list