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* 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* 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* 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; }