Laxkit  0.0.7.1
Public Member Functions | Public Attributes | Protected Attributes
Laxkit::MenuInfo Class Reference

General container for menu types of lists. More...

Inheritance diagram for Laxkit::MenuInfo:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 MenuInfo (const char *ntitle=NULL)
 Constructor, just make empty menu with title set to ntitle.
virtual ~MenuInfo ()
 Destructor, just frees the title. The stack is flushed automatically.
virtual void SetCompareFunc (CompareFunc func)
 Set the compare function to some "int (*func)(const char *,const char *).
virtual void SetCompareFunc (int newsortstyle)
 Set Compare to the appropriate function for newsortstyle.
virtual void Sort (int detail=0, int newsortstyle=0)
 Sort the items according to sortstyle.
virtual void sort (int start, int end, int detail)
 Recursive quick sort routine.
virtual MenuInfofindparent (MenuInfo *m, int *index=NULL)
 Find the parent menu (MenuInfo that has the item, not the MenuItem that has m) of m.
virtual MenuItemfindFromLine (int i)
 Get the element at line number i, including all open submenus and separators.
virtual int findLine (MenuItem *mi)
 Find the line number of mi (starting at 0), counting all open submenus, thus as it would appear onscreen in a tree.
virtual int findIndex (MenuItem *mi)
 returns index in menuitems.e of mi only if mi is in this menu, not a submenu.
virtual int findIndex (const char *name, int start_at=0)
virtual int findIndex (int checkid)
 Returns index in menuitems.e of element with id==checkid in this menu, not a submenu.
virtual MenuItemfindid (int checkid)
 Find the MenuItem anywhere that has checkid as its id.
virtual int idexists (int check, MenuInfo *look)
 Check to see if an id==check exists somewhere in the menu hierarchy.
virtual int getuniqueid (int trythis=-1)
 Return a unique id number, starting with trythis.
virtual int howmany (int maxn, int all=0)
 Counts how many items are visible (including separators, but not hidden).
virtual int AddItem (const char *newitem, int nid=0)
 Add item at position where, or to end of menu if where<0.
virtual int AddDelimited (const char *newitem, char delimiter='/', int nid=0)
virtual int AddItem (const char *newitem, LaxImage *img, int nid=0)
 Add item at position where, or to end of menu if where<0.
virtual int AddItem (const char *newitem, int nid, unsigned int nstate, int ninfo=0, MenuInfo *nsub=NULL, int where=-1, char subislocal=1)
 Add item at position where, or to end of menu if where<0.
virtual int AddItem (const char *newitem, LaxImage *img, int nid, unsigned int nstate, int ninfo=0, MenuInfo *nsub=NULL, int where=-1, char subislocal=1)
 Add item at position where, or to end of menu if where<0.
virtual int AddItem (MenuItem *mi, char islocal, int where=-1)
 Add an already made MenuItem.
virtual int AddItemAsIs (MenuItem *mi, char islocal, int where=-1)
 Add an already made MenuItem, but DO NOT reparent. This is for temporary lists refering to the main one.
virtual int AddItems (const char **i, int n, int startid)
 Add a whole bunch of items at the same time.
virtual int AddDetail (const char *newitem, LaxImage *img, int nid=0, int ninfo=0, int towhich=-1)
 Add item detail to the item at the top of menuitems, or to towhich.
virtual int AddSep (const char *name=NULL, int where=-1)
 Currently adds a grayed separator with name="", id=0, no submenu, (but it is still legal to add a submenu!!)
virtual int SubMenu (const char *ntitle=NULL, int which=-1)
 Future Add*() go on a new submenu for item which, or top of the stack.
virtual void EndSubMenu ()
 Stop adding to a submenu, revert curmenu to the parent of that submenu.
virtual void DoneSubMenus ()
 Just resets curmenu to this.
virtual void NewTitle (const char *ntitle)
 Set the title if the curmenu to ntitle.
virtual void Flush ()
 Flush menuitems and set curmenu=this.
virtual int SetRecursively (unsigned long nstate, int on, int ignoreunmade=0)
virtual int Search (const char *search, int isprogressive, int ignoreunmade=0)
 Progressively search for items, caseless+partial. search==NULL matches all.
virtual void ClearSearch ()
virtual int n ()
virtual MenuIteme (int i)
- Public Member Functions inherited from Laxkit::anObject
 anObject ()
 Set object_id=getUniqueNumber().
virtual ~anObject ()
 Empty virtual destructor.
virtual const charwhattype ()
 Returns the type of anObject.
virtual anObjectduplicate (anObject *ref=NULL)
virtual int inc_count ()
 Increment the data's count by 1. Returns count.
virtual int dec_count ()
 Decrement the count of the data, deleting if count is less than or equal to 0.
virtual int the_count ()

Public Attributes

int sortstyle
 Indicates how to sort.
MenuInfocurmenu
 Holds a temporary pointer to the (sub)menu that should be added to or modified.
chartitle
 The title of the menu.
MenuItemparent
RefPtrStack< MenuItemmenuitems
 Holds the individual menu items.
- Public Attributes inherited from Laxkit::anObject
int suppress_debug
DeleteRefCountedFunc deleteMe
 Called when the count is decremented to 0.
unsigned long object_id
charobject_idstr

Protected Attributes

CompareFunc Compare
- Protected Attributes inherited from Laxkit::anObject
int _count
 The reference count of the object.

Detailed Description

General container for menu types of lists.

This class stores lists that are used by MenuSelector, StrSliderPopup, and PopupMenu. It is basically a stack of MenuItem objects, and an optional title.

Todo:

*** RemoveItem

hot keys

const char menustuff[][**] = {
"g,id#,blah1",
"2,blah2",
"g,-34,blah3d",
"=:Submenu Title",
"=a",
"=b",
"=c",
"=d",
"==1",
"==2",
"==3",
"--", <-- separator(??? not imp?)
NULL, <-- or separator! or perhaps NULL means end of list?
"blah4",
"--",
"blah5", }
menu.AddItem("blah1",id=1,LAX_GRAY);
menu.AddItem("blah2",2);
menu.SubMenu([title]);
menu.AddItem("a");
menu.AddItem("b");
menu.SubMenu([title],position==last added);
menu.AddItem("1");
menu.AddItem("2");
menu.EndSubmenu();
menu.EndSubmenu();
menu.AddItem("blah4");
menu.AddSep();
menu.AddItem("blah5");
menu.AddItems(menustuff,n,startid);

Member Function Documentation

int Laxkit::MenuInfo::AddDelimited ( const char newitem,
char  delimiter = '/',
int  nid = 0 
)
virtual

A shortcut to add something like "group 1/subgroup/item" to submenu. Adds any non-existing intermediate groups (with id==0). Afterwards, curmenu is unchanged.

References newnstr().

int Laxkit::MenuInfo::AddDetail ( const char newitem,
LaxImage img,
int  nid = 0,
int  ninfo = 0,
int  towhich = -1 
)
virtual

Add item detail to the item at the top of menuitems, or to towhich.

If there is no recent item, then return 1. On success, return 0.

int Laxkit::MenuInfo::AddItem ( const char newitem,
int  nid = 0 
)
virtual

Add item at position where, or to end of menu if where<0.

Please note that the MenuItem that is created is local to the menuitems stack (it will be deleted when the item stack is flushed), while the passed in submenu is local according to subislocal.

References menuitems, and Laxkit::PtrStack< T >::n.

Referenced by Laxkit::SliderPopup::AddItem(), Laxkit::MenuSelector::AddItem(), Laxkit::TreeSelector::AddItem(), Laxkit::FileDialog::BuildBookmarks(), Laxkit::FileMenuItem::CreateSubmenu(), Laxkit::FileDialog::getDirectory(), Laxkit::SplitWindow::GetMenu(), Laxkit::FileDialog::init(), and Laxkit::RulerWindow::RBUp().

int Laxkit::MenuInfo::AddItem ( const char newitem,
LaxImage img,
int  nid = 0 
)
virtual

Add item at position where, or to end of menu if where<0.

Please note that the MenuItem that is created is local to the menuitems stack (it will be deleted when the item stack is flushed), while the passed in submenu is local according to subislocal.

References menuitems, and Laxkit::PtrStack< T >::n.

int Laxkit::MenuInfo::AddItem ( const char newitem,
int  nid,
unsigned int  nstate,
int  ninfo = 0,
MenuInfo nsub = NULL,
int  where = -1,
char  subislocal = 1 
)
virtual

Add item at position where, or to end of menu if where<0.

Please note that the MenuItem that is created is local to the menuitems stack (it will be deleted when the item stack is flushed), while the passed in submenu is local according to subislocal.

References menuitems, and Laxkit::PtrStack< T >::n.

int Laxkit::MenuInfo::AddItem ( const char newitem,
LaxImage img,
int  nid,
unsigned int  nstate,
int  ninfo = 0,
MenuInfo nsub = NULL,
int  where = -1,
char  subislocal = 1 
)
virtual

Add item at position where, or to end of menu if where<0.

Please note that the MenuItem that is created is local to the menuitems stack (it will be deleted when the item stack is flushed), while the passed in submenu is local according to subislocal.

References menuitems, and Laxkit::PtrStack< T >::n.

int Laxkit::MenuInfo::AddItem ( MenuItem mi,
char  islocal,
int  where = -1 
)
virtual

Add an already made MenuItem.

Note that mi->parent is set to curmenu. Returns the number of menuitems.

If islocal is nonzero then this menuitem is not deleted when the menuitems stack is flushed.

References menuitems, and Laxkit::PtrStack< T >::n.

int Laxkit::MenuInfo::AddItemAsIs ( MenuItem mi,
char  islocal,
int  where = -1 
)
virtual

Add an already made MenuItem, but DO NOT reparent. This is for temporary lists refering to the main one.

Returns the number of menuitems.

If islocal is nonzero then this menuitem is not deleted when the menuitems stack is flushed.

Referenced by Laxkit::TreeSelector::addToCache().

int Laxkit::MenuInfo::AddItems ( const char **  i,
int  n,
int  startid 
)
virtual

Add a whole bunch of items at the same time.

Assigns ids sequentially starting with startid. Does not check for multiple occurences of the ids used.

Returns number of items added. ***this is cheap, should be optimized for large arrays?? add in one lump, then sort??

References isblank().

Referenced by Laxkit::SliderPopup::AddItems(), and Laxkit::FileDialog::BuildBookmarks().

int Laxkit::MenuInfo::AddSep ( const char name = NULL,
int  where = -1 
)
virtual

Currently adds a grayed separator with name="", id=0, no submenu, (but it is still legal to add a submenu!!)

Returns whatever AddItem returns.

Referenced by Laxkit::SliderPopup::AddSep(), and Laxkit::FileDialog::BuildBookmarks().

MenuItem * Laxkit::MenuInfo::findid ( int  checkid)
virtual

Find the MenuItem anywhere that has checkid as its id.

Searches recursively through all submenus. When changing states, labels, ordering, etc. from the outside, this is handy.

Any potential submenus that do not currently exist are skipped.

References findid(), and Laxkit::MenuItem::GetSubmenu().

Referenced by findid().

int Laxkit::MenuInfo::findIndex ( const char name,
int  start_at = 0 
)
virtual

Return index if name is in this menu, not a submenu. Note that name is not necessarily unique. If start_at>0, then start the search at that item.

Return -1 if not found.

int Laxkit::MenuInfo::findLine ( MenuItem mi)
virtual

Find the line number of mi (starting at 0), counting all open submenus, thus as it would appear onscreen in a tree.

This includes separators but not hidden items, thus if mi is in the tree but hidden, then no valid index is returned for it.

If mi is not found, then -1 is returned.

References findLine(), Laxkit::MenuItem::GetSubmenu(), and howmany().

Referenced by findLine().

MenuInfo * Laxkit::MenuInfo::findparent ( MenuInfo m,
int index = NULL 
)
virtual

Find the parent menu (MenuInfo that has the item, not the MenuItem that has m) of m.

If index is not null, then also put the index of the item within the found parent menu whose submenu is equal to m. If there is no such m, then -1 is put in index. If m==this, index is set to -2 and NULL is returned.

If no parent menu is found, which should only happen when m is nowhere in the tree, then index is set to -1, and NULL is returned.

Please note that this basically assumes that all the relevant submenus are already defined. That is, any potential submenus that are not currently defined do not get defined in the process of searching.

References findparent(), and Laxkit::MenuItem::GetSubmenu().

Referenced by findparent().

int Laxkit::MenuInfo::getuniqueid ( int  trythis = -1)
virtual

Return a unique id number, starting with trythis.

Cheap, inefficient function to simply return a number 1 larger than the current largest id.

If trythis<=0, then start looking with 1.

int Laxkit::MenuInfo::howmany ( int  maxn,
int  all = 0 
)
virtual

Counts how many items are visible (including separators, but not hidden).

If all is 1, then include all the items from submenus, whether they are open or not. If all is 0, then include all items from only the submenus that are open. If all is -1, then include only the items from this menu.

Any potential menus that do not currently exist are skipped.

Only include items whose stack indices i in this top menu where i<maxn. If maxn is out of bounds, then consider all the items in this menu.

***TODO: Should decide whether to include a submenu title as a line for open menus!! right now it does not. note the title of a submenu is not the same as the name of the item that has the submenu.

References Laxkit::MenuItem::GetSubmenu(), and howmany().

Referenced by Laxkit::TreeSelector::Collapse(), Laxkit::TreeSelector::Deselect(), Laxkit::TreeSelector::Expand(), findFromLine(), findLine(), howmany(), and Laxkit::TreeSelector::SetFirst().

int Laxkit::MenuInfo::idexists ( int  check,
MenuInfo look 
)
virtual

Check to see if an id==check exists somewhere in the menu hierarchy.

if look is NULL, then default is to start checking in this->menu.

References Laxkit::PtrStack< T >::e, Laxkit::MenuItem::GetSubmenu(), menuitems, Laxkit::PtrStack< T >::n, and Laxkit::MenuItem::state.

int Laxkit::MenuInfo::Search ( const char search,
int  isprogressive,
int  ignoreunmade = 0 
)
virtual

Progressively search for items, caseless+partial. search==NULL matches all.

Sets MENU_SEARCH_HIT on matching items. Sets MENU_SEARCH_PARENT on items that don't match, but who has descendents.

If isprogressive, then assume that search is a string that contains the previous search.

Return number of hits.

References Laxkit::MenuItem::GetSubmenu(), Search(), and Laxkit::MenuItem::state.

Referenced by Search().

void Laxkit::MenuInfo::SetCompareFunc ( CompareFunc  func)
virtual

Set the compare function to some "int (*func)(const char *,const char *).

If func==NULL, then reset Compare to strcmp.

int Laxkit::MenuInfo::SetRecursively ( unsigned long  nstate,
int  on,
int  ignoreunmade = 0 
)
virtual

If ignoreunmade!=0, then do not use GetSubmenu(), which will generate unmade submenus. You would want to do this, for instance, to avoid FileMenuItem generation of the entire harddrive.

Returns number of items affected.

References Laxkit::MenuItem::GetSubmenu(), and SetRecursively().

Referenced by SetRecursively().

void Laxkit::MenuInfo::Sort ( int  detail = 0,
int  newsortstyle = 0 
)
virtual

Sort the items according to sortstyle.

*** should be able to sort only a subset, for instance all items between separators.

Referenced by Laxkit::FileDialog::getDirectory().

void Laxkit::MenuInfo::sort ( int  start,
int  end,
int  detail 
)
virtual

Recursive quick sort routine.

This can be called to only sort a subset of the menu. If end<0, then sort all from start to the final item.

Currently only sorts in a,b,c order. Only the top is sorted, not submenus.

Todo:
*** Really, there should be some other MenuItem based function pointer for the sorting, to accommodate sorting as text, or as numbers, or as some other format, without having to derive a new class???

Referenced by Laxkit::MenuSelector::Sort(), and Laxkit::TreeSelector::Sort().

int Laxkit::MenuInfo::SubMenu ( const char ntitle = NULL,
int  which = -1 
)
virtual

Future Add*() go on a new submenu for item which, or top of the stack.

This prompts the MenuItem to establish a new MenuInfo

If which is out of bounds, it is set to the final item on the stack

On success, 0 is returned. If curmenu has no items then nothing is done, and 1 is returned. If there is a problem creating a new submenu, then curmenu is not changed and 2 is returned.

References Laxkit::PtrStack< T >::e, Laxkit::MenuItem::GetSubmenu(), and menuitems.

Referenced by Laxkit::SplitWindow::GetMenu().


Member Data Documentation

MenuInfo * Laxkit::MenuInfo::curmenu

Holds a temporary pointer to the (sub)menu that should be added to or modified.

curmenu is set to this in the constructor. At no time should it be NULL.

Referenced by DoneSubMenus().

int Laxkit::MenuInfo::sortstyle

Indicates how to sort.

//These:
#define SORT_NONE (1<<0)
#define SORT_ABC (1<<1)
#define SORT_CBA (1<<2)
#define SORT_123 (1<<3)
#define SORT_321 (1<<4)
// Or'd with any of these:
// DOT_FIRST means place "." and ".." at the beginning always. (if they are included)
// HIDE_HIDDEN means don't show any entries that begin with a . (except "." or "..")
#define SORT_IGNORE_CASE (1<<8)
#define SORT_DIRS_FIRST (1<<9)
#define SORT_HIDE_HIDDEN (1<<10)
#define SORT_DOT_FIRST (1<<11)
#define SORT_BY_EXTENSION (1<<12)

The documentation for this class was generated from the following files:

Mon Feb 17 2014 11:52:59, Laxkit