static void tkentrysee(Tk *tk, int index, int jump) { TkEntry *tke = TKobj(TkEntry, tk); int dx, margin; Rectangle r; r = tkentrybbox(tk, index); dx = tk->act.width - 2*xinset(tk); if (jump) margin = dx / 4; else margin = 0; if (r.min.x <= tke->x0 || r.max.x > tke->x0 + dx) { if (r.min.x <= tke->x0) { tke->x0 = r.min.x - margin; if (tke->x0 < 0) tke->x0 = 0; } else if (r.max.x >= tke->x0 + dx) { tke->x0 = r.max.x - dx + margin; if (tke->x0 > tke->xlen - dx) tke->x0 = tke->xlen - dx; } tk->dirty = tkrect(tk, 0); } r = rectaddpt(r, Pt(xinset(tk) - tke->x0, yinset(tk))); tksee(tk, r, r.min); }
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; }