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; }
static char* tkentryb1m(Tk *tk, char* arg, char **ret) { TkEntry *tke = TKobj(TkEntry, tk); Point p; Rectangle hitr; char buf[32]; USED(ret); p.x = atoi(arg); tke->oldx = p.x; p = tkscrn2local(tk, p); p.y = 0; if (!tkvisiblerect(tk, &hitr) || !ptinrect(p, hitr)) return nil; snprint(buf, sizeof(buf), "to @%d", p.x); tkentryselect(tk, buf, nil); return nil; }
static void autoselect(Tk *tk, void *v, int cancelled) { TkEntry *tke = TKobj(TkEntry, tk); Rectangle hitr; char buf[32]; Point p; USED(v); if (cancelled) return; p = tkscrn2local(tk, Pt(tke->oldx, 0)); p.y = 0; if (tkvisiblerect(tk, &hitr) && ptinrect(p, hitr)) return; snprint(buf, sizeof(buf), "to @%d", p.x); tkentryselect(tk, buf, nil); tkdirty(tk); tkupdate(tk->env->top); }