9 typedef struct Radio Radio;
34 static char *cmds[] = {
48 static void radioshow(Radio*);
51 radiomouse(Control *c, Mouse *m)
57 for(i=0; i<r->nbuttons; i++)
58 if(ptinrect(m->xy, r->buttons[i]->rect) && r->buttons[i]->mouse){
59 (r->buttons[i]->mouse)(r->buttons[i], m);
71 for(i=0; i<r->nbuttons; i++){
72 _ctlprint(r->buttons[i], "value %d", (r->value==i));
73 _ctlprint(r->buttons[i], "show");
78 radioctl(Control *c, CParse *cp)
87 cmd = _ctllookup(cp->args[0], cmds, nelem(cmds));
90 ctlerror("%q: unrecognized message '%s'", r->name, cp->str);
93 _ctlargcount(r, cp, 2);
94 c = controlcalled(cp->args[1]);
96 ctlerror("%q: can't add %s: %r", r->name, cp->args[1]);
97 snprint(fmt, sizeof fmt, "%%q: %q button %%d", r->name);
98 _ctlprint(c, "format %q", fmt);
99 controlwire(c, "event", c->controlset->ctl);
100 r->buttons = ctlrealloc(r->buttons, (r->nbuttons+1)*sizeof(Control*));
101 r->buttons[r->nbuttons] = c;
107 if (cp->sender == nil)
108 ctlerror("%q: senderless buttonevent: %q", r->name, cp->str);
109 c = controlcalled(cp->sender);
110 for(i=0; i<r->nbuttons; i++)
111 if (c == r->buttons[i])
113 if (i == r->nbuttons)
114 ctlerror("%q: not my event: %q", r->name, cp->str);
115 if(cp->iargs[1] == 0){
116 /* button was turned off; turn it back on */
117 _ctlprint(c, "value 1");
120 chanprint(r->event, r->format, r->name, i);
125 _ctlargcount(r, cp, 2);
126 r->format = ctlstrdup(cp->args[1]);
129 _ctlargcount(r, cp, 1);
133 /* ignore focus change */
136 _ctlargcount(r, cp, 5);
137 rect.min.x = cp->iargs[1];
138 rect.min.y = cp->iargs[2];
139 rect.max.x = cp->iargs[3];
140 rect.max.y = cp->iargs[4];
144 _ctlargcount(r, cp, 1);
149 _ctlargcount(r, cp, 1);
154 rect.max = Pt(0x7fffffff, 0x7fffffff);
156 _ctlargcount(r, cp, 5);
157 rect.max.x = cp->iargs[3];
158 rect.max.y = cp->iargs[4];
160 rect.min.x = cp->iargs[1];
161 rect.min.y = cp->iargs[2];
162 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)
163 ctlerror("%q: bad sizes: %s", r->name, cp->str);
164 r->size.min = rect.min;
165 r->size.max = rect.max;
168 _ctlargcount(r, cp, 2);
169 r->value = cp->iargs[1];
176 createradiobutton(Controlset *cs, char *name)
180 r = (Radio*)_createctl(cs, "label", sizeof(Radio), name);
181 r->format = ctlstrdup("%q: value %d");
182 r->value = -1; /* nobody set at first */
183 r->mouse = radiomouse;