static char* tklabelconf(Tk *tk, char *arg, char **val) { char *e; TkGeom g; int bd; TkOptab tko[3]; TkLabel *tkl = TKobj(TkLabel, tk); tko[0].ptr = tk; tko[0].optab = tkgeneric; tko[1].ptr = tkl; tko[1].optab = tklabelopts; tko[2].ptr = nil; if(*arg == '\0') return tkconflist(tko, val); g = tk->req; bd = tk->borderwidth; e = tkparse(tk->env->top, arg, tko, nil); tksizelabel(tk); tksettransparent(tk, tkhasalpha(tk->env, TkCbackgnd)); tkgeomchg(tk, &g, bd); tk->dirty = tkrect(tk, 1); return e; }
char* tkscale(TkTop *t, char *arg, char **ret) { Tk *tk; char *e; TkName *names; TkScale *tks; TkOptab tko[3]; tk = tknewobj(t, TKscale, sizeof(Tk)+sizeof(TkScale)); if(tk == nil) return TkNomem; tk->flag |= Tktakefocus; tks = TKobj(TkScale, tk); tks->res = TKI2F(1); tks->to = TKI2F(100); tks->len = ScaleLen; tks->orient = Tkvertical; tks->relief = TKraised; tks->sl = ScaleSlider; tks->sv = BoolT; tks->bigi = 0; tko[0].ptr = tk; tko[0].optab = tkgeneric; tko[1].ptr = tks; tko[1].optab = opts; tko[2].ptr = nil; names = nil; e = tkparse(t, arg, tko, &names); if(e != nil) { tkfreeobj(tk); return e; } tksettransparent(tk, tkhasalpha(tk->env, TkCbackgnd)); tkscalecheckvalue(tk); tksizescale(tk); if (tks->bigi == 0) tks->bigi = TKI2F(TKF2I(tks->to - tks->from) / 10); e = tkbindings(t, tk, b, nelem(b)); if(e != nil) { tkfreeobj(tk); return e; } e = tkaddchild(t, tk, &names); tkfreename(names); if(e != nil) { tkfreeobj(tk); return e; } tk->name->link = nil; return tkvalue(ret, "%s", tk->name->name); }
char* tkcvsrectcreat(Tk* tk, char *arg, char **val) { char *e; TkCrect *r; TkCitem *i; TkCanvas *c; TkOptab tko[3]; c = TKobj(TkCanvas, tk); i = tkcnewitem(tk, TkCVrect, sizeof(TkCitem)+sizeof(TkCrect)); if(i == nil) return TkNomem; r = TKobj(TkCrect, i); r->width = TKI2F(1); e = tkparsepts(tk->env->top, &i->p, &arg, 0); if(e != nil) { tkcvsfreeitem(i); return e; } if(i->p.npoint != 2) { tkcvsfreeitem(i); return TkFewpt; } tko[0].ptr = r; tko[0].optab = rectopts; tko[1].ptr = i; tko[1].optab = itemopts; tko[2].ptr = nil; e = tkparse(tk->env->top, arg, tko, nil); if(e != nil) { tkcvsfreeitem(i); return e; } tkmkstipple(r->stipple); e = tkcaddtag(tk, i, 1); if(e != nil) { tkcvsfreeitem(i); return e; } tkcvsrectsize(i); e = tkvalue(val, "%d", i->id); if(e != nil) { tkcvsfreeitem(i); return e; } tkcvsappend(c, i); tkbbmax(&c->update, &i->p.bb); tkcvssetdirty(tk); return nil; }
char* tkcvslinecreat(Tk* tk, char *arg, char **val) { char *e; TkCline *l; TkCitem *i; TkCanvas *c; TkOptab tko[3]; c = TKobj(TkCanvas, tk); i = tkcnewitem(tk, TkCVline, sizeof(TkCitem)+sizeof(TkCline)); if(i == nil) return TkNomem; l = TKobj(TkCline, i); l->width = TKI2F(1); e = tkparsepts(tk->env->top, &i->p, &arg, 0); if(e != nil) { tkcvsfreeitem(i); return e; } tko[0].ptr = l; tko[0].optab = lineopts; tko[1].ptr = i; tko[1].optab = itemopts; tko[2].ptr = nil; e = tkparse(tk->env->top, arg, tko, nil); if(e != nil) { tkcvsfreeitem(i); return e; } tkmkpen(&l->pen, i->env, l->stipple); e = tkcaddtag(tk, i, 1); if(e != nil) { tkcvsfreeitem(i); return e; } tkcvslinesize(i); e = tkvalue(val, "%d", i->id); if(e != nil) { tkcvsfreeitem(i); return e; } tkcvsappend(c, i); tkbbmax(&c->update, &i->p.bb); tkcvssetdirty(tk); return nil; }
char* tkseecmd(TkTop *t, char *arg, char **ret) { TkOptab tko[2]; TkSee opts; TkName *names; Tk *tk; char *e; Rectangle vr; Point vp; opts.r[0] = bbnil.min.x; opts.r[1] = bbnil.min.y; opts.r[2] = bbnil.max.x; opts.r[3] = bbnil.max.y; opts.p[0] = bbnil.max.x; opts.p[1] = bbnil.max.y; opts.query = 0; tko[0].ptr = &opts; tko[0].optab = seeopts; tko[1].ptr = nil; names = nil; e = tkparse(t, arg, tko, &names); if (e != nil) return e; if (names == nil) return TkBadwp; tk = tklook(t, names->name, 0); tkfreename(names); if (tk == nil) return TkBadwp; if (opts.query) { if (!tkvisiblerect(tk, &vr)) return nil; /* XXX should this be converted into screen coords? */ return tkvalue(ret, "%d %d %d %d", vr.min.x, vr.min.y, vr.max.x, vr.max.y); } vr.min.x = opts.r[0]; vr.min.y = opts.r[1]; vr.max.x = opts.r[2]; vr.max.y = opts.r[3]; vp.x = opts.p[0]; vp.y = opts.p[1]; if (eqrect(vr, bbnil)) vr = tkrect(tk, 1); if (eqpt(vp, bbnil.max)) vp = vr.min; tksee(tk, vr, vp); return nil; }
char* tkentry(TkTop *t, char *arg, char **ret) { Tk *tk; char *e; TkName *names; TkEntry *tke; TkOptab tko[3]; tk = tknewobj(t, TKentry, sizeof(Tk)+sizeof(TkEntry)); if(tk == nil) return TkNomem; tk->relief = TKsunken; tk->borderwidth = 2; tk->flag |= Tktakefocus; tk->highlightwidth = 1; tke = TKobj(TkEntry, tk); tko[0].ptr = tk; tko[0].optab = tkgeneric; tko[1].ptr = tke; tko[1].optab = opts; tko[2].ptr = nil; names = nil; e = tkparse(t, arg, tko, &names); if(e != nil) { tkfreeobj(tk); return e; } tksettransparent(tk, tkhasalpha(tk->env, TkCbackgnd)); tksizeentry(tk); e = tkbindings(t, tk, b, nelem(b)); if(e != nil) { tkfreeobj(tk); return e; } e = tkaddchild(t, tk, &names); tkfreename(names); if(e != nil) { tkfreeobj(tk); return e; } tk->name->link = nil; recalcentry(tk); return tkvalue(ret, "%s", tk->name->name); }
char* tkscrollbar(TkTop *t, char *arg, char **ret) { Tk *tk; char *e; TkName *names; TkScroll *tks; TkOptab tko[3]; tk = tknewobj(t, TKscrollbar, sizeof(Tk)+sizeof(TkScroll)); if(tk == nil) return TkNomem; tks = TKobj(TkScroll, tk); tk->relief = TKflat; tk->borderwidth = 1; tks->activer = TKraised; tks->orient = Tkvertical; tko[0].ptr = tk; tko[0].optab = tkgeneric; tko[1].ptr = tks; tko[1].optab = opts; tko[2].ptr = nil; names = nil; e = tkparse(t, arg, tko, &names); if(e != nil) { tkfreeobj(tk); return e; } tksettransparent(tk, tkhasalpha(tk->env, TkCbackgnd)); e = tkinitscroll(tk); if(e != nil) { tkfreeobj(tk); return e; } e = tkaddchild(t, tk, &names); tkfreename(names); if(e != nil) { tkfreeobj(tk); return e; } tk->name->link = nil; return tkvalue(ret, "%s", tk->name->name); }
char* tkcvsrectconf(Tk *tk, TkCitem *i, char *arg) { char *e; TkOptab tko[3]; TkCrect *r = TKobj(TkCrect, i); tko[0].ptr = r; tko[0].optab = rectopts; tko[1].ptr = i; tko[1].optab = itemopts; tko[2].ptr = nil; e = tkparse(tk->env->top, arg, tko, nil); tkcvsrectsize(i); tkmkstipple(r->stipple); return e; }
char* tklabel(TkTop *t, char *arg, char **ret) { Tk *tk; char *e; TkLabel *tkl; TkName *names; TkOptab tko[3]; tk = tknewobj(t, TKlabel, sizeof(Tk)+sizeof(TkLabel)); if(tk == nil) return TkNomem; tkl = TKobj(TkLabel, tk); tkl->ul = -1; tkl->justify = Tkleft; tko[0].ptr = tk; tko[0].optab = tkgeneric; tko[1].ptr = tkl; tko[1].optab = tklabelopts; tko[2].ptr = nil; names = nil; e = tkparse(t, arg, tko, &names); if(e != nil) { tkfreeobj(tk); return e; } tksizelabel(tk); tksettransparent(tk, tkhasalpha(tk->env, TkCbackgnd)); e = tkaddchild(t, tk, &names); tkfreename(names); if(e != nil) { tkfreeobj(tk); return e; } tk->name->link = nil; return tkvalue(ret, "%s", tk->name->name); }
char* tkcvslineconf(Tk *tk, TkCitem *i, char *arg) { char *e; TkOptab tko[3]; TkCline *l = TKobj(TkCline, i); tko[0].ptr = l; tko[0].optab = lineopts; tko[1].ptr = i; tko[1].optab = itemopts; tko[2].ptr = nil; e = tkparse(tk->env->top, arg, tko, nil); tkmkpen(&l->pen, i->env, l->stipple); tkcvslinesize(i); return e; }
char* tkcvswindconf(Tk *tk, TkCitem *i, char *arg) { char *e; int dx, dy; TkOptab tko[3]; TkCwind *w = TKobj(TkCwind, i); Tk *oldsub; tko[0].ptr = w; tko[0].optab = windopts; tko[1].ptr = i; tko[1].optab = itemopts; tko[2].ptr = nil; dx = w->width; dy = w->height; w->width = -1; w->height = -1; oldsub = w->sub; e = tkparse(tk->env->top, arg, tko, nil); if(e == nil) { e = tkcvswindchk(tk, w, oldsub); if(e != nil) return e; if(w->width == -1) w->width = dx; else w->flags |= Tksetwidth; if(w->height == -1) w->height = dy; else w->flags |= Tksetheight; tkcvswindsize(i); } else { w->width = dx; w->height = dy; } return e; }
void tktopopt(Tk *tk, char *opt) { TkTop *t; TkWin *tkw; TkOptab tko[4]; tkw = TKobj(TkWin, tk); t = tk->env->top; tko[0].ptr = tkw; tko[0].optab = tktop; tko[1].ptr = tk; tko[1].optab = tkgeneric; tko[2].ptr = t; tko[2].optab = tktopdbg; tko[3].ptr = nil; tkparse(t, opt, tko, nil); }
static char* tkcvsconf(Tk *tk, char *arg, char **val) { char *e; int bd; TkGeom g; Rectangle r; TkOptab tko[3]; TkCanvas *c = TKobj(TkCanvas, tk); tko[0].ptr = c; tko[0].optab = opts; tko[1].ptr = tk; tko[1].optab = tkgeneric; tko[2].ptr = nil; if(*arg == '\0') return tkconflist(tko, val); r.min = c->view; r.max.x = r.min.x+tk->act.width; r.max.y = r.min.y+tk->act.height; tkbbmax(&c->update, &r); tkbbmax(&c->update, &c->region); bd = tk->borderwidth; g = tk->req; e = tkparse(tk->env->top, arg, tko, nil); if(e != nil) return e; tksettransparent(tk, tkhasalpha(tk->env, TkCbackgnd)); tkcvsf2i(tk, c); tkcvsgeom(tk); tkgeomchg(tk, &g, bd); tkbbmax(&c->update, &c->region); tk->dirty = tkrect(tk, 1); return nil; }
char* tkcvstextconf(Tk *tk, TkCitem *i, char *arg) { char *e; TkOptab tko[3]; TkCtext *t = TKobj(TkCtext, i); tko[0].ptr = t; tko[0].optab = textopts; tko[1].ptr = i; tko[1].optab = itemopts; tko[2].ptr = nil; e = tkparse(tk->env->top, arg, tko, nil); t->tlen = 0; if(t->text != nil) t->tlen = strlen(t->text); tkmkpen(&t->pen, i->env, t->stipple); tkcvstextsize(i); return e; }
char* tkcvstextcreat(Tk* tk, char *arg, char **val) { char *e; TkCtext *t; TkCitem *i; TkCanvas *c; TkOptab tko[3]; c = TKobj(TkCanvas, tk); i = tkcnewitem(tk, TkCVtext, sizeof(TkCitem)+sizeof(TkCtext)); if(i == nil) return TkNomem; t = TKobj(TkCtext, i); t->justify = Tkleft; t->anchor = Tkcenter; t->sell = -1; t->self = -1; t->icursor = -1; t->sbw = c->sborderwidth; t->env = tk->env; e = tkparsepts(tk->env->top, &i->p, &arg, 0); if(e != nil) { tkcvsfreeitem(i); return e; } if(i->p.npoint != 1) { tkcvsfreeitem(i); return TkFewpt; } tko[0].ptr = t; tko[0].optab = textopts; tko[1].ptr = i; tko[1].optab = itemopts; tko[2].ptr = nil; e = tkparse(tk->env->top, arg, tko, nil); if(e != nil) { tkcvsfreeitem(i); return e; } e = tkcaddtag(tk, i, 1); if(e != nil) { tkcvsfreeitem(i); return e; } t->tlen = 0; if(t->text != nil) t->tlen = strlen(t->text); tkmkpen(&t->pen, i->env, t->stipple); tkcvstextsize(i); e = tkvalue(val, "%d", i->id); if(e != nil) { tkcvsfreeitem(i); return e; } tkcvsappend(c, i); tkbbmax(&c->update, &i->p.bb); tkcvssetdirty(tk); return nil; }
char* tkpack(TkTop *t, char *arg, char **val) { TkParam param = defparam; TkParam *p = ¶m; TkOptab tko[2]; Tk *tk, **l, *tkp; TkName *names, *n; char *e, *w, *buf; buf = mallocz(Tkminitem, 0); if(buf == nil) return TkNomem; w = tkword(t, arg, buf, buf+Tkminitem, nil); if(strcmp(buf, "forget") == 0) { e = tkforget(t, w); free(buf); return e; } if(strcmp(buf, "propagate") == 0) { e = tkpropagate(t, w); free(buf); return e; } if(strcmp(buf, "slaves") == 0) { e = tkslaves(t, w, val); free(buf); return e; } free(buf); tko[0].ptr = p; tko[0].optab = opts; tko[1].ptr = nil; names = nil; e = tkparse(t, arg, tko, &names); if(e != nil) return e; if((p->before && p->before->master == nil) || (p->after && p->after->master == nil)) { tkfreename(names); return TkNotpk; } for(n = names; n; n = n->link) { tkp = tklook(t, n->name, 0); if(tkp == nil) { tkerr(t, n->name); tkfreename(names); return TkBadwp; } if(tkp->flag & Tkwindow) { tkfreename(names); return TkIstop; } if(tkp->parent != nil) { tkfreename(names); return TkWpack; } n->obj = tkp; } e = nil; for(n = names; n; n = n->link) { tk = n->obj; if(tk->master == nil) { tk->pad = ZP; tk->ipad = ZP; tk->flag &= ~(Tkanchor|Tkside|Tkfill|Tkexpand); tk->flag |= Tktop; } if(tk->master != nil) { tkpackqit(tk->master); tkdelpack(tk); } if(p->before == nil && p->after == nil && p->in == nil) { tkp = tklook(t, n->name, 1); if(tkp == nil) { e = TkBadwp; tkerr(t, n->name); goto Error; } e = tkcanpack(tk, tkp); if (e != nil) goto Error; tkappendpack(tkp, tk, -1); } else { if(p->in != nil) { e = tkcanpack(tk, p->in); if(e != nil) goto Error; tkappendpack(p->in, tk, -1); } else if(p->before != nil) { e = tkcanpack(tk, p->before->master); if (e != nil) goto Error; tk->master = p->before->master; l = &tk->master->slave; for(;;) { if(*l == p->before) { tk->next = *l; *l = tk; break; } l = &(*l)->next; } p->before = tk; } else { e = tkcanpack(tk, p->after->master); if (e != nil) goto Error; tk->master = p->after->master; tk->next = p->after->next; p->after->next = tk; p->after = tk; } } tksetopt(p, tk); if (tk->master->flag&Tksubsub) tksetbits(tk, Tksubsub); tkpackqit(tk->master); } Error: tkfreename(names); tkrunpack(t); return e; }
char* tkcvswindcreat(Tk* tk, char *arg, char **val) { char *e; TkCwind *w; TkCitem *i; TkCanvas *c; TkOptab tko[3]; c = TKobj(TkCanvas, tk); i = tkcnewitem(tk, TkCVwindow, sizeof(TkCitem)+sizeof(TkCwind)); if(i == nil) return TkNomem; w = TKobj(TkCwind, i); w->flags = Tkcenter; e = tkparsepts(tk->env->top, &i->p, &arg, 0); if(e != nil) { tkcvsfreeitem(i); return e; } if(i->p.npoint != 1) { tkcvsfreeitem(i); return TkFewpt; } tko[0].ptr = w; tko[0].optab = windopts; tko[1].ptr = i; tko[1].optab = itemopts; tko[2].ptr = nil; e = tkparse(tk->env->top, arg, tko, nil); if(e != nil) { tkcvsfreeitem(i); return e; } e = tkcvswindchk(tk, w, nil); if(e != nil) { tkcvsfreeitem(i); return e; } e = tkcaddtag(tk, i, 1); if(e != nil) { tkcvsfreeitem(i); return e; } e = tkvalue(val, "%d", i->id); if(e != nil) { tkcvsfreeitem(i); return e; } tkcvsappend(c, i); tkcvswindsize(i); tkbbmax(&c->update, &i->p.bb); tkcvssetdirty(tk); return nil; }
char* tkcanvas(TkTop *t, char *arg, char **ret) { Tk *tk; char *e; TkCanvas *tkc; TkName *names; TkOptab tko[3]; tk = tknewobj(t, TKcanvas, sizeof(Tk)+sizeof(TkCanvas)); if(tk == nil) return TkNomem; tkc = TKobj(TkCanvas, tk); tkc->close = TKI2F(1); tkc->xscrolli = TKI2F(1); tkc->yscrolli = TKI2F(1); tkc->width = TKI2F(360); tkc->height = TKI2F(270); tkc->actions = 0; tkc->actlim = Tksweep; tkc->mask = nil; tkc->sborderwidth = 1; tko[0].ptr = tkc; tko[0].optab = opts; tko[1].ptr = tk; tko[1].optab = tkgeneric; tko[2].ptr = nil; names = nil; e = tkparse(t, arg, tko, &names); if(e != nil) goto err; if(names == nil) { /* tkerr(t, arg); XXX */ e = TkBadwp; goto err; } tkc->current = tkmkname("current"); if(tkc->current == nil) { e = TkNomem; goto err; } tksettransparent(tk, tkhasalpha(tk->env, TkCbackgnd)); tkcvsf2i(tk, tkc); e = tkaddchild(t, tk, &names); tkfreename(names); if(e != nil) { tkfreename(tkc->current); tkc->current = nil; goto err; } tk->name->link = nil; e = tkvalue(ret, "%s", tk->name->name); if(e == nil) return nil; tkfreename(tkc->current); return e; err: tkfreeobj(tk); return e; }