Laxkit  0.0.7.1
menuinfo.h
1 //
2 //
3 // The Laxkit, a windowing toolkit
4 // Please consult http://laxkit.sourceforge.net about where to send any
5 // correspondence about this software.
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 //
21 // Copyright (C) 2004-2007,2010,2012-2013 by Tom Lechner
22 //
23 #ifndef _LAX_MENUINFO_H
24 #define _LAX_MENUINFO_H
25 
26 #include <lax/lists.h>
27 #include <lax/laxdefs.h>
28 #include <lax/strmanip.h>
29 #include <lax/anobject.h>
30 #include <lax/laximages.h>
31 #include <lax/refptrstack.h>
32 
33 #ifndef NULL
34 #define NULL (0)
35 #endif
36 
37  //-----sorting styles
38  // These:
39 #define SORT_NONE (1<<0)
40 #define SORT_ABC (1<<1)
41 #define SORT_CBA (1<<2)
42 #define SORT_123 (1<<3)
43 #define SORT_321 (1<<4)
44  // Or'd with any of these:
45 #define SORT_IGNORE_CASE (1<<8)
46 #define SORT_DIRS_FIRST (1<<9)
47 #define SORT_HIDE_HIDDEN (1<<10)
48 #define SORT_DOT_FIRST (1<<11)
49 #define SORT_BY_EXTENSION (1<<12)
50 
51 //-------item state
52 //---from laxdefs.h:
53 //#define LAX_HIDDEN (0)
54 //#define LAX_OFF (1<<0)
55 //#define LAX_ON (1<<1)
56 //#define LAX_GRAY (1<<2)
57 //#define LAX_SEPARATOR (1<<3)
58 //#define LAX_MSTATE_MASK (0xff)
59 
60  // note to programmer: make sure this can be combined with above item state
61  // these must correspond to the equivalent LAX_*:
62 #define MENU_OPEN (1<<8)
63 #define MENU_CCUR (1<<9)
64 #define MENU_MOUSEIN (1<<10)
65 #define MENU_ISLEAF (1<<11)
66 #define MENU_HAS_SUBMENU (1<<12)
67 #define MENU_ISTOGGLE (1<<13)
68 #define MENU_CHECKED (1<<14)
69 #define MENU_SELECTED (1<<15)
70 
71 #define MENU_SEARCH_HIDDEN (1<<16)
72 #define MENU_SEARCH_PARENT (1<<17)
73 #define MENU_SEARCH_HIT (1<<18)
74 
75 namespace Laxkit {
76 
77 class MenuInfo;
78 
79 //----------------------------------- MenuItem --------------------------------
80 class MenuItem : public anObject
81 {
82  protected:
83  void base_init();
84  void base_init(const char *newitem,int nid,unsigned int nstate,int ninfo,MenuInfo *nsub,int sublocal);
85 
86  MenuInfo *submenu; // menu is the menu that this item is in, submenu is assumed local
88  public:
89  char *name;
90  LaxImage *image;
91  int formathint;
92  int id,info;
93  unsigned int state;
94  int x,y,w,h;
95  MenuItem *nextdetail;
96  MenuInfo *parent;
97 
98  MenuItem();
99  MenuItem(const char *newitem,int nid,unsigned int nstate,int ninfo,MenuInfo *nsub,int sublocal);
100  MenuItem(LaxImage *img=NULL);
101  MenuItem(const char *newitem,const char *img,int nid,unsigned int nstate,int ninfo,MenuInfo *nsub,int sublocal);
102  MenuItem(const char *newitem,LaxImage *img,int nid,unsigned int nstate,int ninfo,MenuInfo *nsub,int sublocal);
103  virtual ~MenuItem();
104  virtual MenuInfo *GetSubmenu(int create=0);
105  virtual MenuInfo *CreateSubmenu(const char *ntitle);
106  virtual int AddDetail(MenuItem *detail);
107  virtual void SetState(unsigned newstate, int on);
108 
109  virtual const char *GetString(int detail);
110 
111  virtual int isSelected(int oron=1);
112  virtual int hasSub() const;
113  virtual int isOpen() const;
114  virtual int hidden();
115  virtual int hasParent(MenuInfo *menuinfo);
116  virtual int hasParent(MenuItem *menuitem);
117 };
118 
119 //----------------------------------- MenuInfo --------------------------------
120 typedef int (*CompareFunc)(const char *s1,const char *s2);
121 
122 class MenuInfo : public anObject
123 {
124  protected:
125  CompareFunc Compare;
126  public:
128  MenuInfo *curmenu; // where adds get put on to, could be a submenu
129  char *title;
130  MenuItem *parent;
132  MenuInfo(const char *ntitle=NULL);
133  virtual ~MenuInfo();
134  virtual void SetCompareFunc(CompareFunc func);
135  virtual void SetCompareFunc(int newsortstyle);
136  virtual void Sort(int detail=0,int newsortstyle=0);
137  virtual void sort(int start,int end, int detail); // sort in 1,2,3.. flips elsewhere for 3,2,1
138  virtual MenuInfo *findparent(MenuInfo *m,int *index=NULL);
139  virtual MenuItem *findFromLine(int i); // find element with index i, counting all open submenus
140  virtual int findLine(MenuItem *mi); // return index of mi counting all open submenus
141  virtual int findIndex(MenuItem *mi); // return index of mi only if mi is in this menu, not a submenu
142  virtual int findIndex(const char *name, int start_at=0); // return index if name is in this menu, not a submenu
143  virtual int findIndex(int checkid); // return index of element with checkid in this menu, not a submenu
144  virtual MenuItem *findid(int checkid); // find MenuItem with id==checkid
145  virtual int idexists(int check,MenuInfo *look); // whether an id==check exists somewhere in the menu.
146  virtual int getuniqueid(int trythis=-1); // find a unique id number to use
147  virtual int howmany(int maxn,int all=0); // maxn=0, maxn is only consider menuitems.e[c<maxn]
148 
149  virtual int AddItem(const char *newitem,int nid=0);
150  virtual int AddDelimited(const char *newitem,char delimiter='/', int nid=0);
151  virtual int AddItem(const char *newitem,LaxImage *img,int nid=0);
152  virtual int AddItem(const char *newitem,int nid,unsigned int nstate,int ninfo=0,
153  MenuInfo *nsub=NULL,int where=-1,char subislocal=1);
154  virtual int AddItem(const char *newitem,LaxImage *img,int nid,unsigned int nstate,int ninfo=0,
155  MenuInfo *nsub=NULL,int where=-1,char subislocal=1);
156  virtual int AddItem(MenuItem *mi,char islocal,int where=-1); //where=-1
157  virtual int AddItemAsIs(MenuItem *mi,char islocal,int where=-1); //where=-1
158  virtual int AddItems(const char **i,int n,int startid); // assume ids sequential, state=0
159  virtual int AddDetail(const char *newitem,LaxImage *img,int nid=0,int ninfo=0, int towhich=-1);
160  virtual int AddSep(const char *name=NULL,int where=-1);
161  virtual int SubMenu(const char *ntitle=NULL,int which=-1); // future adds go on a new submenu for current item
162  virtual void EndSubMenu(); // stop adding to a submenu
163  virtual void DoneSubMenus() { curmenu=this; } // resets curmenu to this
164  virtual void NewTitle(const char *ntitle); // set a new title for curmenu
165  virtual void Flush();
166 
167  virtual int SetRecursively(unsigned long nstate, int on, int ignoreunmade=0);
168  virtual int Search(const char *search, int isprogressive, int ignoreunmade=0);
169  virtual void ClearSearch();
170 
171  virtual int n();
172  virtual MenuItem *e(int i);
173 };
174 
175 void menuinfoDump(MenuInfo *menu, int indent); //for debugging
176 
177 } // namespace Laxkit
178 
179 #endif
180 

Mon Feb 17 2014 11:52:57, Laxkit