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