From 6bb5a81cee7e76e8a4e69f7f49869f39c1c382f0 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Tue, 5 Sep 2023 14:45:51 +0200 Subject: Adds some convenience methods. fl_filename_absolute can no generate a path using arbitrary source paths. Fl_Menu_ adds find_item_with_user_data and find_item_with_argument Fl_String adds find(string, start) --- src/Fl_Menu_.cxx | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/Fl_Menu_.cxx') diff --git a/src/Fl_Menu_.cxx b/src/Fl_Menu_.cxx index 28a476e02..1769af9a1 100644 --- a/src/Fl_Menu_.cxx +++ b/src/Fl_Menu_.cxx @@ -266,6 +266,40 @@ const Fl_Menu_Item * Fl_Menu_::find_item(Fl_Callback *cb) { return (const Fl_Menu_Item *)0; } +/** + Find the menu item for the given user data \p v. + + \param[in] v find the first item with this user data + \returns The item found, or NULL if not found + \see find_item(const char*) + */ +const Fl_Menu_Item* Fl_Menu_::find_item_with_user_data(void *v) { + for ( int t=0; t < size(); t++ ) { + const Fl_Menu_Item *m = menu_ + t; + if (m->user_data_==v) { + return m; + } + } + return (const Fl_Menu_Item *)NULL; +} + +/** + Find the menu item for the given user argument \p v. + + \param[in] v find the first item with this user argument + \returns The item found, or NULL if not found + \see find_item(const char*) + */ +const Fl_Menu_Item* Fl_Menu_::find_item_with_argument(long v) { + for ( int t=0; t < size(); t++ ) { + const Fl_Menu_Item *m = menu_ + t; + if (m->argument()==v) { + return m; + } + } + return (const Fl_Menu_Item *)NULL; +} + /** 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