9 _frdrawtext(Frame *f, Point pt, Image *text, Image *back)
14 for(nb=0,b=f->box; nb<f->nbox; nb++, b++){
15 _frcklinewrap(f, &pt, b);
17 stringbg(f->b, pt, text, ZP, f->font, (char*)b->ptr, back, ZP);
24 nbytes(char *s0, int nr)
31 s += chartorune(&r, s);
36 frdrawsel(Frame *f, Point pt, ulong p0, ulong p1, int issel)
41 frtick(f, frptofchar(f, f->p0), 0);
50 text = f->cols[HTEXT];
56 frdrawsel0(f, pt, p0, p1, back, text);
60 frdrawsel0(Frame *f, Point pt, ulong p0, ulong p1, Image *back, Image *text)
63 int nb, nr, w, x, trim;
71 for(nb=0; nb<f->nbox && p<p1; nb++){
79 _frcklinewrap(f, &pt, b);
80 /* fill in the end of a wrapped line */
82 draw(f->b, Rect(qt.x, qt.y, f->r.max.x, pt.y), back, nil, qt);
85 if(p < p0){ /* beginning of region: advance into box */
86 ptr += nbytes(ptr, p0-p);
91 if(p+nr > p1){ /* end of region: trim box */
95 if(b->nrune<0 || nr==b->nrune)
98 w = stringnwidth(f->font, ptr, nr);
102 draw(f->b, Rect(pt.x, pt.y, x, pt.y+f->font->height), back, nil, pt);
104 stringnbg(f->b, pt, text, ZP, f->font, ptr, nr, back, ZP);
110 /* if this is end of last plain text box on wrapped line, fill to end of line */
111 if(p1>p0 && b>f->box && b<f->box+f->nbox && b[-1].nrune>0 && !trim){
113 _frcklinewrap(f, &pt, b);
115 draw(f->b, Rect(qt.x, qt.y, f->r.max.x, pt.y), back, nil, qt);
129 frtick(f, frptofchar(f, f->p0), 0);
130 frdrawsel0(f, frptofchar(f, 0), 0, f->nchars, f->cols[BACK], f->cols[TEXT]);
132 frtick(f, frptofchar(f, f->p0), 1);
136 pt = frptofchar(f, 0);
137 pt = frdrawsel0(f, pt, 0, f->p0, f->cols[BACK], f->cols[TEXT]);
138 pt = frdrawsel0(f, pt, f->p0, f->p1, f->cols[HIGH], f->cols[HTEXT]);
139 pt = frdrawsel0(f, pt, f->p1, f->nchars, f->cols[BACK], f->cols[TEXT]);
143 frtick(Frame *f, Point pt, int ticked)
147 if(f->ticked==ticked || f->tick==nil || !ptinrect(pt, f->r))
149 pt.x--; /* looks best just left of where requested */
150 r = Rect(pt.x, pt.y, pt.x+FRTICKW, pt.y+f->font->height);
151 /* can go into left border but not right */
152 if(r.max.x > f->r.max.x)
153 r.max.x = f->r.max.x;
155 draw(f->tickback, f->tickback->r, f->b, nil, pt);
156 draw(f->b, r, f->tick, nil, ZP);
158 draw(f->b, r, f->tickback, nil, ZP);
163 _frdraw(Frame *f, Point pt)
168 for(b=f->box,nb=0; nb<f->nbox; nb++, b++){
169 _frcklinewrap0(f, &pt, b);
170 if(pt.y == f->r.max.y){
171 f->nchars -= _frstrlen(f, nb);
172 _frdelbox(f, nb, f->nbox-1);
176 n = _frcanfit(f, pt, b);
178 drawerror(f->display, "_frcanfit==0");
180 _frsplitbox(f, nb, n);
187 pt.y+=f->font->height;
189 pt.x += _frnewwid(f, pt, b);
196 _frstrlen(Frame *f, int nb)
200 for(n=0; nb<f->nbox; nb++)
201 n += NRUNE(&f->box[nb]);