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