xref: /plan9/sys/include/control.h (revision 41dd6b4775bcffc7275c15aee7294944759a2ea7)
1 #pragma src "/sys/src/libcontrol"
2 #pragma lib "libcontrol.a"
3 
4 #pragma	varargck	argpos	ctlprint	2
5 #pragma varargck	argpos	_ctlprint	2
6 
7 typedef struct Control Control;
8 typedef struct Controlset Controlset;
9 typedef struct CParse CParse;
10 typedef struct CCache CCache;
11 typedef struct CCache CImage;
12 typedef struct CCache CFont;
13 
14 enum	/* types */
15 {
16 	Ctlunknown,
17 	Ctlbox,
18 	Ctlbutton,
19 	Ctlentry,
20 	Ctlkeyboard,
21 	Ctllabel,
22 	Ctlmenu,
23 	Ctlradio,
24 	Ctlscribble,
25 	Ctlslider,
26 	Ctltabs,
27 	Ctltext,
28 	Ctltextbutton,
29 	Ctltextbutton3,
30 	Ctlgroup,		/* divider between controls and metacontrols */
31 	Ctlboxbox,
32 	Ctlcolumn,
33 	Ctlrow,
34 	Ctlstack,
35 	Ctltab,
36 	Ntypes,
37 };
38 
39 struct Controlset
40 {
41 	Control		*controls;
42 	Image		*screen;
43 	Control		*actives;
44 	Control		*focus;
45 	Channel		*ctl;
46 	Channel		*data;		/* currently only for sync */
47 	Channel		*kbdc;
48 	Channel		*mousec;
49 	Channel		*resizec;
50 	Channel		*resizeexitc;
51 	Channel		*csexitc;
52 	Keyboardctl	*keyboardctl;	/* will be nil if user supplied keyboard */
53 	Mousectl	*mousectl;	/* will be nil if user supplied mouse */
54 	int		clicktotype;	/* flag */
55 };
56 
57 struct Control
58 {
59 	/* known to client */
60 	char		*name;
61 	Rectangle	rect;
62 	Rectangle	size;		/* minimum/maximum Dx, Dy (not a rect) */
63 	Channel		*event;		/* chan(char*) to client */
64 	Channel		*data;		/* chan(char*) to client */
65 
66 	/* internal to control set */
67 	int		type;
68 	int		hidden;		/* hide hides, show unhides (and redraws) */
69 	Controlset	*controlset;
70 	Image		*screen;	/* where Control appears */
71 	char		*format;	/* used to generate events */
72 	char		wevent;		/* event channel rewired */
73 	char		wdata;		/* data channel rewired */
74 
75 	/* method table */
76 	void		(*ctl)(Control*, CParse*);
77 	void		(*mouse)(Control*, Mouse*);
78 	void		(*key)(Control*, Rune*);
79 	void		(*exit)(Control*);
80 	void		(*setsize)(Control*);
81 	void		(*activate)(Control*, int);
82 	Control		*nextactive;
83 	Control		*next;
84 };
85 
86 struct CCache
87 {
88 	union{
89 		Image	*image;
90 		Font	*font;
91 	};
92 	char		*name;
93 	int		index;		/* entry number in cache */
94 	int		ref;		/* one for client, plus one for each use */
95 };
96 
97 struct CParse
98 {
99 	char	str[256];
100 	char	*sender;
101 	char	*receiver;
102 	int	cmd;
103 	char	*pargs[32];
104 	int	iargs[32];
105 	char	**args;
106 	int	nargs;
107 };
108 
109 enum	/* alignments */
110 {
111 	Aupperleft = 0,
112 	Auppercenter,
113 	Aupperright,
114 	Acenterleft,
115 	Acenter,
116 	Acenterright,
117 	Alowerleft,
118 	Alowercenter,
119 	Alowerright,
120 	Nalignments
121 };
122 
123 enum
124 {
125 	_Ctlmaxsize = 10000,
126 };
127 
128 extern char *ctltypenames[];
129 
130 /* Functions used internally */
131 void		_ctladdgroup(Control*, Control*);
132 void		_ctlargcount(Control*, CParse*, int);
133 Control*	_createctl(Controlset*, char*, uint, char*);
134 Rune*		_ctlrunestr(char*);
135 char*		_ctlstrrune(Rune*);
136 void		_ctlputsnarf(Rune*);
137 Rune*		_ctlgetsnarf(void);
138 int		_ctlalignment(char*);
139 Point		_ctlalignpoint(Rectangle, int, int, int);
140 void		_ctlfocus(Control*, int);
141 void		_activategroup(Control*);
142 void		_deactivategroup(Control*);
143 int		_ctllookup(char *s, char *tab[], int ntab);
144 void		_ctlprint(Control *c, char *fmt, ...);
145 
146 /* images */
147 CImage*		_getctlimage(char*);
148 void		_setctlimage(Control*, CImage**, char*);
149 void		_putctlimage(CImage*);
150 CFont*		_getctlfont(char*);
151 void		_putctlfont(CFont*);
152 
153 /* fonts */
154 CImage*		_getctlfont(char*);
155 void		_setctlfont(Control*, CImage**, char*);
156 void		_putctlfont(CImage*);
157 CFont*		_getctlfont(char*);
158 void		_putctlfont(CFont*);
159 
160 /* Public functions */
161 
162 /* images */
163 int		namectlimage(Image*, char*);
164 int		freectlimage(char*);
165 
166 /* fonts */
167 int		namectlfont(Font*, char*);
168 int		freectlfont(char*);
169 
170 /* commands */
171 int		ctlprint(Control*, char*, ...);
172 
173 /* general */
174 void		initcontrols(void);
175 Controlset*	newcontrolset(Image*, Channel*, Channel*, Channel*);
176 void		closecontrolset(Controlset*);
177 void		closecontrol(Control*);
178 void		ctlerror(char*, ...);
179 Control*	controlcalled(char*);
180 
181 /* publicly visible error-checking allocation routines */
182 void*		ctlmalloc(uint);
183 void*		ctlrealloc(void*, uint);
184 char*		ctlstrdup(char*);
185 
186 /* creation */
187 void		controlwire(Control*, char*, Channel*);
188 void		activate(Control*);
189 void		deactivate(Control*);
190 Control*	createbox(Controlset*, char*);
191 Control*	createbutton(Controlset*, char*);
192 Control*	createcolumn(Controlset*, char*);
193 Control*	createboxbox(Controlset*, char*);
194 Control*	createentry(Controlset*, char*);
195 Control*	createkeyboard(Controlset*, char*);
196 Control*	createlabel(Controlset*, char*);
197 Control*	createmenu(Controlset*, char*);
198 Control*	createradiobutton(Controlset*, char*);
199 Control*	createrow(Controlset*, char*);
200 Control*	createscribble(Controlset*, char*);
201 Control*	createslider(Controlset*, char*);
202 Control*	createstack(Controlset*, char*);
203 Control*	createtab(Controlset*, char*);
204 Control*	createtext(Controlset*, char*);
205 Control*	createtextbutton(Controlset*, char*);
206 Control*	createtextbutton3(Controlset*, char*);
207 
208 /* user-supplied */
209 void		resizecontrolset(Controlset*);
210 
211 int		_ctlsnarffd;
212 char		*alignnames[];
213 int		ctldeletequits;
214