(This is regarding solving STR#1758 and STR#1113 simultaneously)
Fl_Menu is lacking a few needed functions, namely:
insert() -- a way to insert a new Fl_Menu_Item at a specified
position
clear_submenu() -- a way to clear a submenu (given either an item or
item pathname)
find_index() -- similar to existing find_item(), returns the index
instead of the item*
REASONS FOR ADDITIONS
insert() is almost impossible to implemented outside of fltk (eg. by
deriving a class).
clear_submenu() is useful for repopulating dynamically created submenus
(like File -> Recent -> ..)
find_index() is needed because sometimes you really need the index.
SUGGESTED INTERFACE
int insert(int index, ..)
Similar to add(), but inserts the new item at 'index'.
If index == -1, the new item is added to the end of the array (same as
'add()')
The return value would be the same as add().
'..' would be the exact calling parameters of the existing two public
add() methods.
Since there are currently two overloads of add(), insert() would have
similarly
two equivalents. (They differ by the shortcuts, which can be either a
char* or int)
To implement should be fairly easy; I plan to change the existing add()
methods to call insert() to do their work, and move the existing code
for add()
to insert(). (The functionality of add() is really a subset of insert())
int clear_submenu(int submenu_index)
int clear_submenu(Fl_Menu_Item *submenu)
int clear_submenu(const char *submenu_pathname)
Clears the specified submenu of all items (from one end to the other).
Submenu can either be specified as an index, item, or pathname.
Returns -1 if the specified submenu is not a submenu.
Similar to add(), this would have to first check to see if the
menu has been malloc()ed, and if not, make a malloc copy of it first
before doing any operations.
int find_index(Fl_Callback *cb) const
int find_index(const char *pathname) const
int find_index(Fl_Menu_Item *item) const
Same as find_item(), only returns the index number instead of the item*.
Returns -1 if item was not found.
The last case makes it possible to easily convert an item into an index,
a functionality that has been lacking for a while, and simply involves
a math operation on the array pointers that can involve safe bounds
checks
for sanity.
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev