9 _frdrawtext(Frame *f, Point pt, Image *text, Image *back)
15 for(nb=0,b=f->box; nb<f->nbox; nb++, b++){
16 _frcklinewrap(f, &pt, b);
18 stringbg(f->b, pt, text, ZP, f->font, (char*)b->ptr, back, ZP);
25 nbytes(char *s0, int nr)
32 s += chartorune(&r, s);
37 frdrawsel(Frame *f, Point pt, ulong p0, ulong p1, int issel)
42 frtick(f, frptofchar(f, f->p0), 0);
51 text = f->cols[HTEXT];
57 frdrawsel0(f, pt, p0, p1, back, text);
61 frdrawsel0(Frame *f, Point pt, ulong p0, ulong p1, Image *back, Image *text)
64 int nb, nr, w, x, trim;
72 for(nb=0; nb<f->nbox && p<p1; nb++){
80 _frcklinewrap(f, &pt, b);
81 /* fill in the end of a wrapped line */
83 draw(f->b, Rect(qt.x, qt.y, f->r.max.x, pt.y), back, nil, qt);
86 if(p < p0){ /* beginning of region: advance into box */
87 ptr += nbytes(ptr, p0-p);
92 if(p+nr > p1){ /* end of region: trim box */
96 if(b->nrune<0 || nr==b->nrune)
99 w = stringnwidth(f->font, ptr, nr);
103 draw(f->b, Rect(pt.x, pt.y, x, pt.y+f->font->height), back, nil, pt);
105 stringnbg(f->b, pt, text, ZP, f->font, ptr, nr, back, ZP);
111 /* if this is end of last plain text box on wrapped line, fill to end of line */
112 if(p1>p0 && b>f->box && b<f->box+f->nbox && b[-1].nrune>0 && !trim){
114 _frcklinewrap(f, &pt, b);
116 draw(f->b, Rect(qt.x, qt.y, f->r.max.x, pt.y), back, nil, qt);
130 frtick(f, frptofchar(f, f->p0), 0);
131 frdrawsel0(f, frptofchar(f, 0), 0, f->nchars, f->cols[BACK], f->cols[TEXT]);
133 frtick(f, frptofchar(f, f->p0), 1);
137 pt = frptofchar(f, 0);
138 pt = frdrawsel0(f, pt, 0, f->p0, f->cols[BACK], f->cols[TEXT]);
139 pt = frdrawsel0(f, pt, f->p0, f->p1, f->cols[HIGH], f->cols[HTEXT]);
140 pt = frdrawsel0(f, pt, f->p1, f->nchars, f->cols[BACK], f->cols[TEXT]);
144 frtick(Frame *f, Point pt, int ticked)
148 if(f->ticked==ticked || f->tick==0 || !ptinrect(pt, f->r))
150 pt.x--; /* looks best just left of where requested */
151 r = Rect(pt.x, pt.y, pt.x+FRTICKW, pt.y+f->font->height);
152 /* can go into left border but not right */
153 if(r.max.x > f->r.max.x)
154 r.max.x = f->r.max.x;
156 draw(f->tickback, f->tickback->r, f->b, nil, pt);
157 draw(f->b, r, f->tick, nil, ZP);
159 draw(f->b, r, f->tickback, nil, ZP);
164 _frdraw(Frame *f, Point pt)
169 for(b=f->box,nb=0; nb<f->nbox; nb++, b++){
170 _frcklinewrap0(f, &pt, b);
171 if(pt.y == f->r.max.y){
172 f->nchars -= _frstrlen(f, nb);
173 _frdelbox(f, nb, f->nbox-1);
177 n = _frcanfit(f, pt, b);
179 drawerror(f->display, "_frcanfit==0");
181 _frsplitbox(f, nb, n);
188 pt.y+=f->font->height;
190 pt.x += _frnewwid(f, pt, b);
197 _frstrlen(Frame *f, int nb)
201 for(n=0; nb<f->nbox; nb++)
202 n += NRUNE(&f->box[nb]);