9 typedef struct Radio Radio;
34 static char *cmds[] = {
48 static void radioshow(Radio*);
49 static void radiofree(Radio*);
52 radiomouse(Control *c, Mouse *m)
58 for(i=0; i<r->nbuttons; i++)
59 if(ptinrect(m->xy, r->buttons[i]->rect) && r->buttons[i]->mouse){
60 (r->buttons[i]->mouse)(r->buttons[i], m);
77 for(i=0; i<r->nbuttons; i++){
78 _ctlprint(r->buttons[i], "value %d", (r->value==i));
79 _ctlprint(r->buttons[i], "show");
84 radioctl(Control *c, CParse *cp)
93 cmd = _ctllookup(cp->args[0], cmds, nelem(cmds));
96 ctlerror("%q: unrecognized message '%s'", r->name, cp->str);
99 _ctlargcount(r, cp, 2);
100 c = controlcalled(cp->args[1]);
102 ctlerror("%q: can't add %s: %r", r->name, cp->args[1]);
103 snprint(fmt, sizeof fmt, "%%q: %q button %%d", r->name);
104 _ctlprint(c, "format %q", fmt);
105 controlwire(c, "event", c->controlset->ctl);
106 r->buttons = ctlrealloc(r->buttons, (r->nbuttons+1)*sizeof(Control*));
107 r->buttons[r->nbuttons] = c;
113 if (cp->sender == nil)
114 ctlerror("%q: senderless buttonevent: %q", r->name, cp->str);
115 c = controlcalled(cp->sender);
116 for(i=0; i<r->nbuttons; i++)
117 if (c == r->buttons[i])
119 if (i == r->nbuttons)
120 ctlerror("%q: not my event: %q", r->name, cp->str);
121 if(cp->iargs[1] == 0){
122 /* button was turned off; turn it back on */
123 _ctlprint(c, "value 1");
126 chanprint(r->event, r->format, r->name, i);
131 _ctlargcount(r, cp, 2);
132 r->format = ctlstrdup(cp->args[1]);
135 _ctlargcount(r, cp, 1);
139 /* ignore focus change */
142 _ctlargcount(r, cp, 5);
143 rect.min.x = cp->iargs[1];
144 rect.min.y = cp->iargs[2];
145 rect.max.x = cp->iargs[3];
146 rect.max.y = cp->iargs[4];
150 _ctlargcount(r, cp, 1);
155 _ctlargcount(r, cp, 1);
160 rect.max = Pt(0x7fffffff, 0x7fffffff);
162 _ctlargcount(r, cp, 5);
163 rect.max.x = cp->iargs[3];
164 rect.max.y = cp->iargs[4];
166 rect.min.x = cp->iargs[1];
167 rect.min.y = cp->iargs[2];
168 if(rect.min.x<=0 || rect.min.y<=0 || rect.max.x<=0 || rect.max.y<=0 || rect.max.x < rect.min.x || rect.max.y < rect.min.y)
169 ctlerror("%q: bad sizes: %s", r->name, cp->str);
170 r->size.min = rect.min;
171 r->size.max = rect.max;
174 _ctlargcount(r, cp, 2);
175 r->value = cp->iargs[1];
182 createradiobutton(Controlset *cs, char *name)
186 r = (Radio*)_createctl(cs, "label", sizeof(Radio), name);
187 r->format = ctlstrdup("%q: value %d");
188 r->value = -1; /* nobody set at first */
189 r->mouse = radiomouse;