mirror of
https://github.com/fltk/fltk.git
synced 2026-06-06 08:32:07 +08:00
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
This commit is contained in:
+6
-5
@@ -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 $".
|
||||
//
|
||||
|
||||
@@ -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>
|
||||
|
||||
+40
-2
@@ -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 $".
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user