10 typedef struct Tab Tab;
46 static char *cmds[] = {
49 [EBordercolor] = "bordercolor",
57 [ESeparation] = "separation",
58 [ESeparatorcolor] = "separatorcolor",
73 for(i=0; i<t->nbuttons; i++){
74 _ctlprint(t->buttons[i], "value %d", (t->selected==i));
76 _ctlprint(t->tabstack, "reveal %d", t->selected);
77 _ctlprint(t->tabcolumn, "show");
80 g = (Group*)t->tabcolumn;
81 if (g->nseparators == 0){
85 r.min.x = t->buttons[t->selected]->rect.min.x;
86 r.max.x = t->buttons[t->selected]->rect.max.x;
87 draw(t->screen, r, t->image->image, nil, t->image->image->r.min);
88 flushimage(display, 1);
95 if (t->tabcolumn && t->tabcolumn->setsize)
96 t->tabcolumn->setsize((Control*)t->tabcolumn);
100 tabctl(Control *c, CParse *cp)
103 Control *cbut, *cwin;
108 cmd = _ctllookup(cp->args[0], cmds, nelem(cmds));
111 if ((cp->nargs & 1) == 0)
112 ctlerror("%q: arg count: %s", t->name, cp->args[1]);
113 for (i = 1; i < cp->nargs; i += 2){
114 cbut = controlcalled(cp->args[i]);
116 ctlerror("%q: no such control: %s", t->name, cp->args[i]);
117 cwin = controlcalled(cp->args[i+1]);
119 ctlerror("%q: no such control: %s", t->name, cp->args[i+1]);
120 _ctladdgroup(t->tabrow, cbut);
121 _ctlprint(t->tabstack, "add %q", cp->args[i+1]);
122 _ctlprint(cbut, "format '%%s: %q button %%d'", t->name);
123 controlwire(cbut, "event", t->controlset->ctl);
124 t->buttons = ctlrealloc(t->buttons, (t->nbuttons+1)*sizeof(Control*));
125 t->buttons[t->nbuttons] = cbut;
129 _ctlprint(t->tabcolumn, "size");
130 t->size = t->tabcolumn->size;
133 _ctlargcount(t, cp, 2);
135 ctlerror("%q: bad border: %c", t->name, cp->str);
136 t->border = cp->iargs[1];
139 _ctlargcount(t, cp, 2);
140 _setctlimage(t, &t->bordercolor, cp->args[1]);
143 _ctlargcount(t, cp, 2);
144 if (cp->sender == nil)
145 ctlerror("%q: senderless buttonevent: %q", t->name, cp->str);
146 cbut = controlcalled(cp->sender);
147 for(i=0; i<t->nbuttons; i++)
148 if (cbut == t->buttons[i])
150 if (i == t->nbuttons)
151 ctlerror("%q: not my event: %q", t->name, cp->str);
152 if(cp->iargs[1] == 0){
153 /* button was turned off; turn it back on */
154 _ctlprint(cbut, "value 1");
158 chanprint(t->event, t->format, t->name, i);
163 /* ignore focus change */
166 _ctlargcount(t, cp, 2);
167 t->format = ctlstrdup(cp->args[1]);
170 _ctlargcount(t, cp, 2);
171 _setctlimage(t, &t->image, cp->args[1]);
174 t->tabrow->ctl(t->tabrow, cp);
175 t->tabcolumn->ctl(t->tabcolumn, cp);
178 _ctlargcount(t, cp, 5);
179 r.min.x = cp->iargs[1];
180 r.min.y = cp->iargs[2];
181 r.max.x = cp->iargs[3];
182 r.max.y = cp->iargs[4];
183 if(Dx(r)<=0 || Dy(r)<=0)
184 ctlerror("%q: bad rectangle: %s", t->name, cp->str);
186 r = insetrect(r, t->border);
187 _ctlprint(t->tabcolumn, "rect %R", r);
190 _ctlargcount(t, cp, 1);
193 t->tabcolumn->ctl(t->tabcolumn, cp);
199 _ctlargcount(t, cp, 2);
200 if (cp->iargs[1] < 0 || cp->iargs[1] >= t->nbuttons)
201 ctlerror("%q: illegal value '%s'", t->name, cp->str);
202 t->selected = cp->iargs[1];
206 ctlerror("%q: unrecognized message '%s'", t->name, cp->str);
221 activatetab(Control *c, int act)
227 activate(t->tabcolumn);
229 deactivate(t->tabcolumn);
233 createtab(Controlset *cs, char *name)
238 t = (Tab*)_createctl(cs, "tab", sizeof(Tab), name);
244 snprint(s, sizeof s, "_%s-row", name);
245 t->tabrow = createrow(cs, s);
246 snprint(s, sizeof s, "_%s-stack", name);
247 t->tabstack = createstack(cs, s);
248 snprint(s, sizeof s, "_%s-column", name);
249 t->tabcolumn = createcolumn(cs, s);
250 ctlprint(t->tabcolumn, "add %q %q", t->tabrow->name, t->tabstack->name);
251 t->bordercolor = _getctlimage("black");
252 t->image = _getctlimage("white");
253 t->setsize = tabsize;
254 t->activate = activatetab;