summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2015-07-26 21:10:18 +0000
committerGreg Ercolano <erco@seriss.com>2015-07-26 21:10:18 +0000
commita165f1ca3cf603c8b0719318ab02e993603d48f4 (patch)
treebdd178b28d5ac350c7bb61bf505d0dab6005feba
parent7819882874b4d501996991376c35b26b3a937115 (diff)
Fixes STR#3177; item_pathname() supports FL_SUBMENU_POINTER,
and small doc mods. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10819 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--FL/Fl_Menu_.H2
-rw-r--r--src/Fl_Menu_.cxx93
2 files changed, 66 insertions, 29 deletions
diff --git a/FL/Fl_Menu_.H b/FL/Fl_Menu_.H
index 5b6f5984e..c609e7a8d 100644
--- a/FL/Fl_Menu_.H
+++ b/FL/Fl_Menu_.H
@@ -61,6 +61,8 @@ protected:
Fl_Fontsize textsize_;
Fl_Color textcolor_;
+ int item_pathname_(char *name, int namelen, const Fl_Menu_Item *finditem,
+ const Fl_Menu_Item *menu=0) const;
public:
Fl_Menu_(int,int,int,int,const char * =0);
~Fl_Menu_();
diff --git a/src/Fl_Menu_.cxx b/src/Fl_Menu_.cxx
index 7b1b3c5ba..6ab3797a3 100644
--- a/src/Fl_Menu_.cxx
+++ b/src/Fl_Menu_.cxx
@@ -63,39 +63,68 @@
\see find_item()
*/
int Fl_Menu_::item_pathname(char *name, int namelen, const Fl_Menu_Item *finditem) const {
- int len = 0;
- finditem = finditem ? finditem : mvalue();
- name[0] = '\0';
- for ( int t=0; t<size(); t++ ) {
- const Fl_Menu_Item *m = &(menu()[t]);
- if ( m->submenu() ) { // submenu? descend
- if (*name) SAFE_STRCAT("/");
- if (m->label()) SAFE_STRCAT(m->label());
- if ( m == finditem ) return(0); // found? done.
- } else {
- if (m->label()) { // menu item?
- if ( m == finditem ) { // found? tack on itemname, done.
- SAFE_STRCAT("/");
- SAFE_STRCAT(m->label());
- return(0);
- }
- } else { // end of submenu? pop
- char *ss = strrchr(name, '/');
- if ( ss ) { *ss = 0; len = (int) strlen(name); } // "File/Edit" -> "File"
- else { name[0] = '\0'; len = 0; } // "File" -> ""
- continue;
- }
+ name[0] = '\0';
+ return item_pathname_(name, namelen, finditem, menu_);
+}
+
+// INTERNAL: Descend into a specific menu hierarchy
+int Fl_Menu_::item_pathname_(char *name,
+ int namelen,
+ const Fl_Menu_Item *finditem,
+ const Fl_Menu_Item *menu) const {
+ int len = 0;
+ int level = 0;
+ finditem = finditem ? finditem : mvalue();
+ menu = menu ? menu : this->menu();
+ for ( int t=0; t<size(); t++ ) {
+ const Fl_Menu_Item *m = menu + t;
+ if (m->submenu()) { // submenu? descend
+ if (m->flags & FL_SUBMENU_POINTER) {
+ // SUBMENU POINTER? Recurse to descend
+ int slen = strlen(name);
+ const Fl_Menu_Item *submenu = (const Fl_Menu_Item*)m->user_data();
+ if (m->label()) {
+ if (*name) SAFE_STRCAT("/");
+ SAFE_STRCAT(m->label());
+ }
+ if (item_pathname_(name, len, finditem, submenu) == 0)
+ return 0;
+ name[slen] = 0; // continue from where we were
+ } else {
+ // REGULAR SUBMENU? DESCEND
+ ++level;
+ if (*name) SAFE_STRCAT("/");
+ if (m->label()) SAFE_STRCAT(m->label());
+ if (m == finditem) return(0); // found? done.
+ }
+ } else {
+ if (m->label()) { // menu item?
+ if ( m == finditem ) { // found? tack on itemname, done.
+ SAFE_STRCAT("/");
+ SAFE_STRCAT(m->label());
+ return(0);
+ }
+ } else { // end of submenu? pop
+ if ( --level < 0 ) {
+ *name = '\0';
+ return -1;
}
+ char *ss = strrchr(name, '/');
+ if ( ss ) { *ss = 0; len = (int) strlen(name); } // "File/Edit" -> "File"
+ else { name[0] = '\0'; len = 0; } // "File" -> ""
+ continue;
+ }
}
- *name = '\0';
- return(-1); // item not found
+ }
+ *name = '\0';
+ return(-1); // item not found
}
/**
Find the menu item for a given menu \p pathname, such as "Edit/Copy".
This method finds a menu item in the menu array, also traversing submenus, but
- not submenu pointers.
+ not submenu pointers (FL_SUBMENU_POINTER).
To get the menu item's index, use find_index(const char*)
@@ -129,6 +158,11 @@ const Fl_Menu_Item * Fl_Menu_::find_item(const char *pathname) {
A way to convert a menu item pointer into an index.
+ Does \b not handle items that are in submenu pointers (FL_SUBMENU_POINTER).
+
+ -1 is returned if the item is not in this menu
+ or is part of an FL_SUBMENU_POINTER submenu.
+
Current implementation is fast and not expensive.
\code
@@ -155,9 +189,10 @@ int Fl_Menu_::find_index(const Fl_Menu_Item *item) const {
Find the index into the menu array for a given callback \p cb.
This method finds a menu item's index position, 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.
-
+ \b not submenu pointers (FL_SUBMENU_POINTER). 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
\returns The index of the item with the specific callback, or -1 if not found
\see find_index(const char*)
@@ -173,7 +208,7 @@ int Fl_Menu_::find_index(Fl_Callback *cb) const {
Find the menu item index for a given menu \p pathname, such as "Edit/Copy".
This method finds a menu item's index position for the given menu pathname,
- also traversing submenus, but not submenu pointers.
+ also traversing submenus, but \b not submenu pointers (FL_SUBMENU_POINTER).
To get the menu item pointer for a pathname, use find_item()