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

Jens Thoms Toerring jt at toerring.de
Fri Jul 4 06:57:48 EDT 2008


To subscribers of the xforms list

-------------- next part --------------
Hi Jason,

On Thu, Jul 03, 2008 at 07:21:01PM -0400, Jason Cipriani wrote:
> On Thu, Jul 3, 2008 at 7:05 PM, Jens Thoms Toerring <jt at toerring.de> wrote:
> > It looks as if the stuff for removing a menu item is badly
> > broken already in 1.0.0. I guess nobody ever has tried to use
> > it, so it went unnoticed for all those years. I will try to
> > come up with a fix that also works for 1.0.90 or 1.0.0 (tell
> > me what you are using) but since it's getting a bit late here
> 
> 1.0.90, with some unrelated custom patches to opengl stuff.

Here's some good and some bad news: If you want to create a
menu with fdesign were you can delete items then you must
switch off the "Use Struct" button in the "Spec" tab field
for the menus attributes. In that case the menu gets initia-
lized via several calls of the function fl_addto_menu() in-
stead of a single call of fl_set_menu_entries(). That looks
like a minor detail, but internally a rather different type
of menu gets created which allows deletion of items.

Now the bad news: Deleting an item will change the numbers
returned for the items following it, i.e. the number of the
selected item is always the (1 based) index of the item in
the menu. So you will have to work with comparing the text
of the item that you can get with fl_get_menu_item_text().

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

FL_EXPORT int fl_get_menu_value(
		FL_OBJECT * ob,
  		int         item
		);

and recompile.

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

red%x1
green%x2
blue%x3

(the "%xn" stuff will not be shown in the menu with the new
version of menu.c) then the new function will return the
number following the "%x" and this number does not change
after deleting an item.

Sorry for all this complexities but the whole stuff for hand-
ling menus/popups/choices is rather convoluted and IMHO not
very well designed. I guess a complete rewrite (but which
then will probably also require changes of the public API)
would be the best solution...

                          Best regards, Jens
-- 
  \   Jens Thoms Toerring  ________      jt at toerring.de
   \_______________________________      http://toerring.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: menu.c
Type: text/x-csrc
Size: 14618 bytes
Desc: not available
Url : attachments/20080704/bc78de63/attachment-0005.bin 
-------------- next part --------------
_______________________________________________
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