Laxkit  0.0.7.1
treeselector.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) 2012 by Tom Lechner
22 //
23 #ifndef _LAX_TREESELECTOR_H
24 #define _LAX_TREESELECTOR_H
25 
26 #include <lax/anxapp.h>
27 #include <lax/menuinfo.h>
28 #include <lax/scrolledwindow.h>
29 #include <lax/buttondowninfo.h>
30 #include <lax/vectors.h>
31 
32 #include <cstring>
33 
34 
35 
36  // Item placement and display flags
37 #define TREESEL_SUB_PLUS (1LL<<0)
38 #define TREESEL_LEFT (1LL<<1)
39 #define TREESEL_RIGHT (1LL<<2)
40 #define TREESEL_SCROLLERS (1LL<<3)
41 #define TREESEL_USE_TITLE (1LL<<4)
42 
43 #define TREESEL_SORT_NUMBERS (1LL<<7)
44 #define TREESEL_SORT_LETTERS (1LL<<8)
45 #define TREESEL_SORT_REVERSE (1LL<<9)
46 #define TREESEL_SORT_IGNORE_CASE (1LL<<10)
47 #define TREESEL_SORT_BY_EXTENSIONS (1LL<<11)
48 
49 #define TREESEL_USE_DOT (1LL<<12)
50 #define TREESEL_USE_DOT_DOT (1LL<<13)
51 
52 #define TREESEL_ONE_ONLY (1LL<<14)
53 #define TREESEL_ZERO_OR_ONE (1LL<<15)
54 #define TREESEL_SELECT_ANY (1LL<<16)
55 #define TREESEL_SELECT_LEAF_ONLY (1LL<<17)
56 #define TREESEL_SELECT_SUB_ONLY (1LL<<18)
57 #define TREESEL_CURSSELECTS (1LL<<19)
58 #define TREESEL_FOLLOW_MOUSE (1LL<<20)
59 #define TREESEL_GRAB_ON_MAP (1LL<<21)
60 #define TREESEL_GRAB_ON_ENTER (1LL<<22)
61 
62 #define TREESEL_REARRANGEABLE (1LL<<23)
63 #define TREESEL_EDIT_IN_PLACE (1LL<<24)
64 //*** add items?? (more than just editing names)
65 //*** remove items??
66 
67 #define TREESEL_SEND_ON_UP (1LL<<25)
68 #define TREESEL_SEND_ON_ENTER (1LL<<26)
69 #define TREESEL_SEND_IDS (1LL<<27)
70 #define TREESEL_SEND_STRINGS (1LL<<28)
71 
72 #define TREESEL_GRAPHIC_ON_RIGHT (1LL<<29)
73 
74 //... remember that the buck stops with (1<<63)
75 
76 
77 namespace Laxkit {
78 
79 
80 
81 
83 {
84  private:
85  void base_init();
86  protected:
87 
88  ButtonDownInfo buttondown;
91  int offsetx,offsety;
92  int firstinw;
93  int textheight,lineheight,pagesize;
94  int timerid;
95 
98  PtrStack<MenuItem> selection;
99 
100  char *searchfilter;
101  int showsearch;
102 
103  int needtobuildcache;
104  MenuInfo visibleitems;
105 
106  virtual void adjustinrect();
107  virtual void findoutrect();
108  virtual double getitemextent(MenuItem *mitem,double *w,double *h,double *gx,double *tx);
109  virtual double getgraphicextent(MenuItem *mitem,double *w,double *h);
110  virtual void drawitem(MenuItem *mitem,IntRectangle *itemspot);
111  virtual void drawitem(int c);
112  virtual void drawsep(const char *name,IntRectangle *rect);
113  virtual void drawSubIndicator(MenuItem *mitem,int x,int y, int selected);
114  virtual void drawitemname(MenuItem *mitem,IntRectangle *rect);
115  virtual void drawtitle();
116  virtual int findmaxwidth(int s,int e, int *h_ret);
117  virtual int findColumnWidth(int which);
118 
119  virtual int send(int deviceid);
120  virtual void addselect(int i,unsigned int state);
121  virtual int findItem(int x,int y, int *onsub, int *column);
122  virtual int findRect(int c,IntRectangle *itemspot);
123  virtual void arrangeItems();
124  virtual void syncWindows(int useinrect=0);
125  virtual int makeinwindow();
126  virtual int numItems();
127  virtual MenuItem *item(int i,char skipcache=0);
128 
129  virtual int addToCache(int indent,MenuInfo *menu, int cury);
130  virtual int DrawItems(int indent, MenuInfo *item, int &n, flatpoint offset);
131  virtual void drawItemContents(MenuItem *i,int offsetx,int offsety, int fill=1);
132  virtual void drawarrow(int x,int y,int r,int type);
133 
134  virtual void editInPlace(int which);
135 
136  public:
138  {
139  public:
140  char *title;
141  int pos, width;
142  int detail; //for remapping order of columns
143  ColumnInfo(const char *ntitle, int nwidth);
144  ~ColumnInfo();
145  };
146  PtrStack<ColumnInfo> columns;
147  int sort_detail;
148  int sort_descending;
149 
150  int gap;
151  unsigned long highlight,shadow;
152  unsigned long long menustyle;
154 
155  TreeSelector(anXWindow *parnt,const char *nname,const char *ntitle,unsigned long nstyle,
156  int xx,int yy,int ww,int hh,int brder,
157  anXWindow *prev,unsigned long nowner=0,const char *mes=0,
158  unsigned long long nmstyle=0,MenuInfo *minfo=NULL);
159  virtual ~TreeSelector();
160  virtual int init();
161  virtual void Refresh();
162  virtual int CharInput(unsigned int ch,const char *buffer,int len,unsigned int state,const LaxKeyboard *d);
163  virtual int LBDown(int x,int y,unsigned int state,int count,const LaxMouse *d);
164  virtual int LBUp(int x,int y,unsigned int state,const LaxMouse *d);
165  virtual int RBDown(int x,int y,unsigned int state,int count,const LaxMouse *d);
166  virtual int RBUp(int x,int y,unsigned int state,const LaxMouse *d);
167  virtual int WheelUp(int x,int y,unsigned int state,int count,const LaxMouse *d);
168  virtual int WheelDown(int x,int y,unsigned int state,int count,const LaxMouse *d);
169  virtual int MouseMove(int x,int y,unsigned int state,const LaxMouse *d);
170  virtual int Idle(int tid);
171  virtual int MoveResize(int nx,int ny,int nw,int nh);
172  virtual int Resize(int nw,int nh);
173  virtual int FocusOn(const FocusChangeData *e);
174  virtual int FocusOff(const FocusChangeData *e);
175 
176  virtual int movescreen(int dx,int dy);
177  virtual int SetFirst(int which,int x,int y);
178  virtual int Curitem() { return curitem; }
179  virtual const MenuItem *Item(int c) { return item(c); }
180  virtual MenuInfo *Menu() { return menu; }
181  virtual int InstallMenu(MenuInfo *nmenu);
182 
183  virtual int Expand(int which);
184  virtual int Collapse(int which);
185  virtual int Select(int which);
186  virtual int Deselect(int which);
187  virtual int RebuildCache();
188 
189  virtual MenuItem *GetSelected(int i);
190  virtual int NumSelected();
191 
192  //virtual int WhichSelected(unsigned int state);
193  virtual void SetLineHeight(int ntotalheight,int newleading, char forcearrange);
194  virtual void Sync();
195 
196  //virtual int RemoveItem(int whichid);
197  //virtual int RemoveItem(const char *i);
198  virtual void Sort(int t, int detail);
199  virtual int AddItems(const char **i,int n,int startid); // assume ids sequential, state=0
200  virtual int AddItem(const char *i,LaxImage *img,int nid,int newstate);
201 
202  virtual int AddColumn(const char *i,LaxImage *img,int width);
203  virtual void ClearColumns();
204  virtual void RemapColumns();
205 };
206 
207 
208 } // namespace Laxkit
209 
210 #endif
211 
212 

Mon Feb 17 2014 11:52:57, Laxkit