From af0c12aae659acf6f5a97abae337cd27cf6325cc Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Tue, 6 Apr 2004 19:19:41 +0000 Subject: Add Fl_Menu_::find_item() method (STR #316) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@3304 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Menu_.cxx | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Fl_Menu_.cxx b/src/Fl_Menu_.cxx index 56ca4e4b3..21b869668 100644 --- a/src/Fl_Menu_.cxx +++ b/src/Fl_Menu_.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Menu_.cxx,v 1.7.2.8.2.7 2004/03/11 05:17:12 easysw Exp $" +// "$Id: Fl_Menu_.cxx,v 1.7.2.8.2.8 2004/04/06 19:19:41 easysw Exp $" // // Common menu code for the Fast Light Tool Kit (FLTK). // @@ -73,6 +73,44 @@ int Fl_Menu_::item_pathname(char *name, int namelen, const Fl_Menu_Item *findite return(-1); // item not found } +// FIND MENU ITEM INDEX, GIVEN MENU PATHNAME +// eg. "Edit/Copy" +// Will also return submenus, eg. "Edit" +// Returns NULL if not found. +// +const Fl_Menu_Item * +Fl_Menu_::find_item(const char *name) +{ + char menupath[1024] = ""; // File/Export + + for ( int t=0; t < size(); t++ ) { + Fl_Menu_Item *m = menu_ + t; + + if (m->submenu()) { + // IT'S A SUBMENU + if (menupath[0]) strlcat(menupath, "/", sizeof(menupath)); + strlcat(menupath, m->label(), sizeof(menupath)); + if (!strcmp(menupath, name)) return m; + } else { + if (!m->label()) { + // END OF SUBMENU? Pop back one level. + char *ss = strrchr(menupath, '/'); + if ( ss ) *ss = 0; + continue; + } + + // IT'S A MENU ITEM + char itempath[1024]; // eg. Edit/Copy + strcpy(itempath, menupath); + if (itempath[0]) strlcat(itempath, "/", sizeof(itempath)); + strlcat(itempath, m->label(), sizeof(itempath)); + if (!strcmp(itempath, name)) return m; + } + } + + return (const Fl_Menu_Item *)0; +} + int Fl_Menu_::value(const Fl_Menu_Item* m) { clear_changed(); if (value_ != m) {value_ = m; return 1;} @@ -187,5 +225,5 @@ void Fl_Menu_::clear() { } // -// End of "$Id: Fl_Menu_.cxx,v 1.7.2.8.2.7 2004/03/11 05:17:12 easysw Exp $". +// End of "$Id: Fl_Menu_.cxx,v 1.7.2.8.2.8 2004/04/06 19:19:41 easysw Exp $". // -- cgit v1.2.3