mirror of
https://github.com/fltk/fltk.git
synced 2026-06-01 23:06:54 +08:00
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
This commit is contained in:
@@ -61,6 +61,8 @@ protected:
|
|||||||
Fl_Fontsize textsize_;
|
Fl_Fontsize textsize_;
|
||||||
Fl_Color textcolor_;
|
Fl_Color textcolor_;
|
||||||
|
|
||||||
|
int item_pathname_(char *name, int namelen, const Fl_Menu_Item *finditem,
|
||||||
|
const Fl_Menu_Item *menu=0) const;
|
||||||
public:
|
public:
|
||||||
Fl_Menu_(int,int,int,int,const char * =0);
|
Fl_Menu_(int,int,int,int,const char * =0);
|
||||||
~Fl_Menu_();
|
~Fl_Menu_();
|
||||||
|
|||||||
+63
-28
@@ -63,39 +63,68 @@
|
|||||||
\see find_item()
|
\see find_item()
|
||||||
*/
|
*/
|
||||||
int Fl_Menu_::item_pathname(char *name, int namelen, const Fl_Menu_Item *finditem) const {
|
int Fl_Menu_::item_pathname(char *name, int namelen, const Fl_Menu_Item *finditem) const {
|
||||||
int len = 0;
|
name[0] = '\0';
|
||||||
finditem = finditem ? finditem : mvalue();
|
return item_pathname_(name, namelen, finditem, menu_);
|
||||||
name[0] = '\0';
|
}
|
||||||
for ( int t=0; t<size(); t++ ) {
|
|
||||||
const Fl_Menu_Item *m = &(menu()[t]);
|
// INTERNAL: Descend into a specific menu hierarchy
|
||||||
if ( m->submenu() ) { // submenu? descend
|
int Fl_Menu_::item_pathname_(char *name,
|
||||||
if (*name) SAFE_STRCAT("/");
|
int namelen,
|
||||||
if (m->label()) SAFE_STRCAT(m->label());
|
const Fl_Menu_Item *finditem,
|
||||||
if ( m == finditem ) return(0); // found? done.
|
const Fl_Menu_Item *menu) const {
|
||||||
} else {
|
int len = 0;
|
||||||
if (m->label()) { // menu item?
|
int level = 0;
|
||||||
if ( m == finditem ) { // found? tack on itemname, done.
|
finditem = finditem ? finditem : mvalue();
|
||||||
SAFE_STRCAT("/");
|
menu = menu ? menu : this->menu();
|
||||||
SAFE_STRCAT(m->label());
|
for ( int t=0; t<size(); t++ ) {
|
||||||
return(0);
|
const Fl_Menu_Item *m = menu + t;
|
||||||
}
|
if (m->submenu()) { // submenu? descend
|
||||||
} else { // end of submenu? pop
|
if (m->flags & FL_SUBMENU_POINTER) {
|
||||||
char *ss = strrchr(name, '/');
|
// SUBMENU POINTER? Recurse to descend
|
||||||
if ( ss ) { *ss = 0; len = (int) strlen(name); } // "File/Edit" -> "File"
|
int slen = strlen(name);
|
||||||
else { name[0] = '\0'; len = 0; } // "File" -> ""
|
const Fl_Menu_Item *submenu = (const Fl_Menu_Item*)m->user_data();
|
||||||
continue;
|
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".
|
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
|
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*)
|
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.
|
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.
|
Current implementation is fast and not expensive.
|
||||||
|
|
||||||
\code
|
\code
|
||||||
@@ -155,8 +189,9 @@ int Fl_Menu_::find_index(const Fl_Menu_Item *item) const {
|
|||||||
Find the index into the menu array for a given callback \p cb.
|
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
|
This method finds a menu item's index position, also traversing submenus, but
|
||||||
not submenu pointers. This is useful if an application uses internationalisation
|
\b not submenu pointers (FL_SUBMENU_POINTER). This is useful if an
|
||||||
and a menu item can not be found using its label. This search is also much faster.
|
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
|
\param cb Find the first item with this callback
|
||||||
\returns The index of the item with the specific callback, or -1 if not found
|
\returns The index of the item with the specific callback, or -1 if not found
|
||||||
@@ -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".
|
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,
|
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()
|
To get the menu item pointer for a pathname, use find_item()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user