1 //#pragma src "/sys/src/libpanel"
2 //#pragma lib "libpanel.a"
3 typedef struct Scroll Scroll;
4 typedef struct Panel Panel; /* a Graphical User Interface element */
5 typedef struct Rtext Rtext; /* formattable text */
6 typedef void Icon; /* Always used as Icon * -- Image or char */
7 typedef struct Idol Idol; /* A picture/text combo */
12 int flags; /* responds to hits? text selection? */
13 void *user; /* user data */
14 int space; /* how much space before, if no break */
15 int indent; /* how much space before, after a break */
16 Image *b; /* what to display, if nonzero */
17 Panel *p; /* what to display, if nonzero and b==0 */
18 Font *font; /* font in which to draw text */
19 char *text; /* what to display, if b==0 and p==0 */
20 Rtext *next; /* next piece */
22 Rtext *nextline; /* links line to line */
23 Rtext *last; /* last, for append */
24 Rectangle r; /* where to draw, if origin were Pt(0,0) */
25 int topy; /* y coord of top of line */
26 int wid; /* not including space */
29 Point ipad, pad; /* extra space inside and outside */
30 Point fixedsize; /* size of Panel, if FIXED */
31 int user; /* available for user */
32 void *userp; /* available for user */
33 Rectangle r; /* where the Panel goes */
35 Panel *next; /* It's a list! */
36 Panel *child, *echild, *parent; /* No, it's a tree! */
37 Image *b; /* where we're drawn */
38 int flags; /* position flags, see below */
39 char *kind; /* what kind of panel? */
40 int state; /* for hitting & drawing purposes */
41 Point size; /* space for this Panel */
42 Point sizereq; /* size requested by this Panel */
43 Point childreq; /* total size needed by children */
44 Panel *lastmouse; /* who got the last mouse event? */
45 Panel *scrollee; /* pointer to scrolled window */
46 Panel *xscroller, *yscroller; /* pointers to scroll bars */
47 Scroll scr; /* scroll data */
48 void *data; /* kind-specific data */
49 void (*draw)(Panel *); /* draw panel and children */
50 int (*pri)(Panel *, Point); /* priority for hitting */
51 int (*hit)(Panel *, Mouse *); /* process mouse event */
52 void (*type)(Panel *, Rune); /* process keyboard event */
53 Point (*getsize)(Panel *, Point); /* return size, given child size */
54 void (*childspace)(Panel *, Point *, Point *); /* child ul & size given our size */
55 void (*scroll)(Panel *, int, int, int, int); /* scroll bar to scrollee */
56 void (*setscrollbar)(Panel *, int, int, int); /* scrollee to scroll bar */
57 void (*free)(Panel *); /* free fields of data when done */
58 char* (*snarf)(Panel *); /* snarf text from panel */
59 void (*paste)(Panel *, char *); /* paste text into panel */
64 #define PACK 0x0007 /* which side of the parent is the Panel attached to? */
69 #define PACKCEN 0x0004 /* only used by pulldown */
70 #define FILLX 0x0008 /* grow horizontally to fill the available space */
71 #define FILLY 0x0010 /* grow vertically to fill the available space */
72 #define PLACE 0x01e0 /* which side of its space should the Panel adhere to? */
73 #define PLACECEN 0x0000
78 #define PLACENE 0x00a0
79 #define PLACENW 0x00c0
80 #define PLACESE 0x00e0
81 #define PLACESW 0x0100
82 #define EXPAND 0x0200 /* use up all extra space in the parent */
83 #define FIXED 0x0c00 /* don't pass children's size requests through to parent */
86 #define MAXX 0x1000 /* make x size as big as biggest sibling's */
87 #define MAXY 0x2000 /* make y size as big as biggest sibling's */
88 #define BITMAP 0x4000 /* text argument is a bitmap, not a string */
89 /* pldefs.h flags 0x08000-0x40000 */
90 #define IGNORE 0x080000 /* ignore this panel totally */
91 #define USERFL 0x100000 /* start of user flag */
94 * An extra bit in Mouse.buttons
96 #define OUT 8 /* Mouse.buttons bit, set when mouse leaves Panel */
100 #define PRI_NORMAL 0 /* ordinary panels */
101 #define PRI_POPUP 1 /* popup menus */
102 #define PRI_SCROLLBAR 2 /* scroll bars */
109 Panel *plkbfocus; /* the panel in keyboard focus */
111 int plinit(int); /* initialization */
112 void plpack(Panel *, Rectangle); /* figure out where to put the Panel & children */
113 void plmove(Panel *, Point); /* move an already-packed panel to a new location */
114 void pldraw(Panel *, Image *); /* display the panel on the bitmap */
115 void plfree(Panel *); /* give back space */
116 void plgrabkb(Panel *); /* this Panel should receive keyboard events */
117 void plkeyboard(Rune); /* send a keyboard event to the appropriate Panel */
118 void plmouse(Panel *, Mouse *); /* send a Mouse event to a Panel tree */
119 void plscroll(Panel *, Panel *, Panel *); /* link up scroll bars */
120 char *plentryval(Panel *); /* entry delivers its value */
121 void plsetbutton(Panel *, int); /* set or clear the mark on a button */
122 void plsetslider(Panel *, int, int); /* set the value of a slider */
123 Rune *pleget(Panel *); /* get the text from an edit window */
124 int plelen(Panel *); /* get the length of the text from an edit window */
125 void plegetsel(Panel *, int *, int *); /* get the selection from an edit window */
126 void plepaste(Panel *, Rune *, int); /* paste in an edit window */
127 void plesel(Panel *, int, int); /* set the selection in an edit window */
128 void plescroll(Panel *, int); /* scroll an edit window */
129 Scroll plgetscroll(Panel *); /* get scrolling information from panel */
130 void plsetscroll(Panel *, Scroll); /* set scrolling information */
131 void plplacelabel(Panel *, int); /* label placement */
134 * Panel creation & reinitialization functions
136 Panel *plbutton(Panel *pl, int, Icon *, void (*)(Panel *pl, int));
137 Panel *plcanvas(Panel *pl, int, void (*)(Panel *), void (*)(Panel *pl, Mouse *));
138 Panel *plcheckbutton(Panel *pl, int, Icon *, void (*)(Panel *pl, int, int));
139 Panel *pledit(Panel *, int, Point, Rune *, int, void (*)(Panel *));
140 Panel *plentry(Panel *pl, int, int, char *, void (*)(Panel *pl, char *));
141 Panel *plframe(Panel *pl, int);
142 Panel *plgroup(Panel *pl, int);
143 Panel *plidollist(Panel*, int, Point, Font*, Idol*, void (*)(Panel*, int, void*));
144 Panel *pllabel(Panel *pl, int, Icon *);
145 Panel *pllist(Panel *pl, int, char *(*)(Panel *, int), int, void(*)(Panel *pl, int, int));
146 Panel *plmenu(Panel *pl, int, Icon **, int, void (*)(int, int));
147 Panel *plmenubar(Panel *pl, int, int, Icon *, Panel *pl, Icon *, ...);
148 Panel *plmessage(Panel *pl, int, int, char *);
149 Panel *plpopup(Panel *pl, int, Panel *pl, Panel *pl, Panel *pl);
150 Panel *plpulldown(Panel *pl, int, Icon *, Panel *pl, int);
151 Panel *plradiobutton(Panel *pl, int, Icon *, void (*)(Panel *pl, int, int));
152 Panel *plscrollbar(Panel *plparent, int flags);
153 Panel *plslider(Panel *pl, int, Point, void(*)(Panel *pl, int, int, int));
154 Panel *pltextview(Panel *, int, Point, Rtext *, void (*)(Panel *, int, Rtext *));
155 void plinitbutton(Panel *, int, Icon *, void (*)(Panel *, int));
156 void plinitcanvas(Panel *, int, void (*)(Panel *), void (*)(Panel *, Mouse *));
157 void plinitcheckbutton(Panel *, int, Icon *, void (*)(Panel *, int, int));
158 void plinitedit(Panel *, int, Point, Rune *, int, void (*)(Panel *));
159 void plinitentry(Panel *, int, int, char *, void (*)(Panel *, char *));
160 void plinitframe(Panel *, int);
161 void plinitgroup(Panel *, int);
162 void plinitidollist(Panel*, int, Point, Font*, Idol*, void (*)(Panel*, int, void*));
163 void plinitlabel(Panel *, int, Icon *);
164 void plinitlist(Panel *, int, char *(*)(Panel *, int), int, void(*)(Panel *, int, int));
165 void plinitmenu(Panel *, int, Icon **, int, void (*)(int, int));
166 void plinitmessage(Panel *, int, int, char *);
167 void plinitpopup(Panel *, int, Panel *, Panel *, Panel *);
168 void plinitpulldown(Panel *, int, Icon *, Panel *, int);
169 void plinitradiobutton(Panel *, int, Icon *, void (*)(Panel *, int, int));
170 void plinitscrollbar(Panel *parent, int flags);
171 void plinitslider(Panel *, int, Point, void(*)(Panel *, int, int, int));
172 void plinittextview(Panel *, int, Point, Rtext *, void (*)(Panel *, int, Rtext *));
174 * Rtext constructors & destructor
176 Rtext *plrtstr(Rtext **, int, int, Font *, char *, int, void *);
177 Rtext *plrtbitmap(Rtext **, int, int, Image *, int, void *);
178 Rtext *plrtpanel(Rtext **, int, int, Panel *, void *);
179 void plrtfree(Rtext *);
180 void plrtseltext(Rtext *, Rtext *, Rtext *);
181 char *plrtsnarftext(Rtext *);
183 int plgetpostextview(Panel *);
184 void plsetpostextview(Panel *, int);
189 Idol *plmkidol(Idol**, Image*, Image*, char*, void*);
190 void plfreeidol(Idol*);
191 Point plidolsize(Idol*, Font*, int);
192 void *plidollistgetsel(Panel*);
197 void plputsnarf(char *);
198 char *plgetsnarf(void);
199 void plsnarf(Panel *); /* snarf a panel */
200 void plpaste(Panel *); /* paste a panel */