From 4a802a315952a1392a82e3dc42c7316b540320f9 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Fri, 26 Feb 2010 13:03:21 +0000 Subject: Fixed menu item counting issue in Fluid (STR #2322), Added Fl_Menu_::find_item by callback git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7150 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Menu_.cxx | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Fl_Menu_.cxx b/src/Fl_Menu_.cxx index 0775ecfce..62c73600e 100644 --- a/src/Fl_Menu_.cxx +++ b/src/Fl_Menu_.cxx @@ -99,11 +99,10 @@ int Fl_Menu_::item_pathname(char *name, int namelen, const Fl_Menu_Item *findite } /** - Find menu item index, given a menu pathname such as "Edit/Copy". - - Will also return submenu items, eg. "Edit". - - Returns NULL if not found. + Find menu item index, given a menu pathname such as "Edit/Copy". + + This method finds a menu item in a menu array, also traversing submenus, but + not submenu pointers. \b Example: \code @@ -121,8 +120,11 @@ int Fl_Menu_::item_pathname(char *name, int namelen, const Fl_Menu_Item *findite } \endcode \returns The item found, or NULL if not found. - \see item_pathname() + \see + \param name path and name of the menu item + \return NULL if not found + \see Fl_Menu_::find_item(Fl_Callback*), item_pathname() */ const Fl_Menu_Item * Fl_Menu_::find_item(const char *name) { char menupath[1024] = ""; // File/Export @@ -157,6 +159,28 @@ const Fl_Menu_Item * Fl_Menu_::find_item(const char *name) { return (const Fl_Menu_Item *)0; } +/** + Find menu item index given a callback. + + This method finds a menu item in a menu array, also traversing submenus, but + not submenu pointers. This is useful if an application uses + internationalisation and a menu item can not be found using its label. This + search is also much faster. + + \param cb find the first item with this callback + \return NULL if not found + \see Fl_Menu_::find_item(const char*) + */ +const Fl_Menu_Item * Fl_Menu_::find_item(Fl_Callback *cb) { + for ( int t=0; t < size(); t++ ) { + const Fl_Menu_Item *m = menu_ + t; + if (m->callback_==cb) { + return m; + } + } + return (const Fl_Menu_Item *)0; +} + /** The value is the index into menu() of the last item chosen by the user. It is zero initially. You can set it as an integer, or set -- cgit v1.2.3