summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2004-04-06 19:19:41 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2004-04-06 19:19:41 +0000
commitaf0c12aae659acf6f5a97abae337cd27cf6325cc (patch)
tree55c5890960fe5d3668f5b06ee6a2cc4a114aafd3
parent9202d0798ece69683954d72a1564f0b1ec8f5fbc (diff)
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
-rw-r--r--FL/Fl_Menu_.H11
-rw-r--r--documentation/Fl_Menu_.html9
-rw-r--r--src/Fl_Menu_.cxx42
3 files changed, 54 insertions, 8 deletions
diff --git a/FL/Fl_Menu_.H b/FL/Fl_Menu_.H
index 71192dd22..2503b40e3 100644
--- a/FL/Fl_Menu_.H
+++ b/FL/Fl_Menu_.H
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Menu_.H,v 1.7.2.4.2.8 2004/03/11 05:17:10 easysw Exp $"
+// "$Id: Fl_Menu_.H,v 1.7.2.4.2.9 2004/04/06 19:19:33 easysw Exp $"
//
// Menu base class header file for the Fast Light Tool Kit (FLTK).
//
@@ -45,12 +45,13 @@ protected:
unsigned textcolor_;
public:
- int item_pathname(char *name, int namelen, const Fl_Menu_Item *finditem=0) const;
- const Fl_Menu_Item* picked(const Fl_Menu_Item*);
-
Fl_Menu_(int,int,int,int,const char * =0);
~Fl_Menu_();
+ int item_pathname(char *name, int namelen, const Fl_Menu_Item *finditem=0) const;
+ const Fl_Menu_Item* picked(const Fl_Menu_Item*);
+ const Fl_Menu_Item* find_item(const char *name);
+
const Fl_Menu_Item* test_shortcut() {return picked(menu()->test_shortcut());}
void global();
@@ -95,5 +96,5 @@ public:
#endif
//
-// End of "$Id: Fl_Menu_.H,v 1.7.2.4.2.8 2004/03/11 05:17:10 easysw Exp $".
+// End of "$Id: Fl_Menu_.H,v 1.7.2.4.2.9 2004/04/06 19:19:33 easysw Exp $".
//
diff --git a/documentation/Fl_Menu_.html b/documentation/Fl_Menu_.html
index f9734599f..49e03a452 100644
--- a/documentation/Fl_Menu_.html
+++ b/documentation/Fl_Menu_.html
@@ -39,11 +39,12 @@ be "private": a dynamically allocated array managed by the Fl_Menu_.
<LI><A href=#Fl_Menu_.~Fl_Menu_>~Fl_Menu_</A></LI>
<LI><A href=#Fl_Menu_.add>add</A></LI>
<LI><A href=#Fl_Menu_.clear>clear</A></LI>
+<LI><A href=#Fl_Menu_.copy>copy</A></LI>
</UL>
</TD><TD align=left valign=top>
<UL>
-<LI><A href=#Fl_Menu_.copy>copy</A></LI>
<LI><A href=#Fl_Menu_.down_box>down_box</A></LI>
+<LI><A href=#Fl_Menu_.find_item>find_item</A></LI>
<LI><A href=#Fl_Menu_.global>global</A></LI>
<LI><A href=#Fl_Menu_.item_pathname>item_pathname</A></LI>
<LI><A href=#Fl_Menu_.menu>menu</A></LI>
@@ -216,6 +217,12 @@ not have to be put in a window at all).
one will replace the old one. There is no way to remove the <TT>
global()</TT> setting (so don't destroy the widget!)</P>
+<h4><a name="Fl_Menu_.find_item">const Fl_Menu_Item *Fl_Menu_::find_item(const char *name);</a></h4>
+
+<p>Returns a pointer to the menu item with the given pathname or
+label. If no matching menu item can be found, a NULL pointer is
+returned.</p>
+
<h4><a name=Fl_Menu_.item_pathname>int Fl_Menu_::item_pathname(char *name, int namelen ) const;</a><br>
int Fl_Menu_::item_pathname(char *name, int namelen,
const Fl_Menu_Item *finditem) const;</h4>
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 $".
//