11 _fraddbox(Frame *f, int bn, int n) /* add n boxes after bn, shift the rest up,
12 * box[bn+n]==box[bn] */
17 drawerror(f->display, "_fraddbox");
18 if(f->nbox+n > f->nalloc)
19 _frgrowbox(f, n+SLOP);
20 for(i=f->nbox; --i>=bn; )
21 f->box[i+n] = f->box[i];
26 _frclosebox(Frame *f, int n0, int n1) /* inclusive */
30 if(n0>=f->nbox || n1>=f->nbox || n1<n0)
31 drawerror(f->display, "_frclosebox");
33 for(i=n1; i<f->nbox; i++)
34 f->box[i-(n1-n0)] = f->box[i];
39 _frdelbox(Frame *f, int n0, int n1) /* inclusive */
41 if(n0>=f->nbox || n1>=f->nbox || n1<n0)
42 drawerror(f->display, "_frdelbox");
43 _frfreebox(f, n0, n1);
44 _frclosebox(f, n0, n1);
48 _frfreebox(Frame *f, int n0, int n1) /* inclusive */
54 if(n0>=f->nbox || n1>=f->nbox)
55 drawerror(f->display, "_frfreebox");
58 if(f->box[i].nrune >= 0)
63 _frgrowbox(Frame *f, int delta)
66 f->box = realloc(f->box, f->nalloc*sizeof(Frbox));
68 drawerror(f->display, "_frgrowbox");
73 dupbox(Frame *f, int bn)
77 if(f->box[bn].nrune < 0)
78 drawerror(f->display, "dupbox");
80 if(f->box[bn].nrune >= 0){
81 p = _frallocstr(f, NBYTE(&f->box[bn])+1);
82 strcpy((char*)p, (char*)f->box[bn].ptr);
89 runeindex(uchar *p, int n)
94 for(i=0; i<n; i++,p+=w)
98 w = chartorune(&rune, (char*)p);
106 truncatebox(Frame *f, Frbox *b, int n) /* drop last n chars; no allocation done */
108 if(b->nrune<0 || b->nrune<n)
109 drawerror(f->display, "truncatebox");
111 runeindex(b->ptr, b->nrune)[0] = 0;
112 b->wid = stringwidth(f->font, (char *)b->ptr);
117 chopbox(Frame *f, Frbox *b, int n) /* drop first n chars; no allocation done */
121 if(b->nrune<0 || b->nrune<n)
122 drawerror(f->display, "chopbox");
123 p = (char*)runeindex(b->ptr, n);
124 memmove((char*)b->ptr, p, strlen(p)+1);
126 b->wid = stringwidth(f->font, (char *)b->ptr);
130 _frsplitbox(Frame *f, int bn, int n)
133 truncatebox(f, &f->box[bn], f->box[bn].nrune-n);
134 chopbox(f, &f->box[bn+1], n);
138 _frmergebox(Frame *f, int bn) /* merge bn and bn+1 */
143 _frinsure(f, bn, NBYTE(&b[0])+NBYTE(&b[1])+1);
144 strcpy((char*)runeindex(b[0].ptr, b[0].nrune), (char*)b[1].ptr);
145 b[0].wid += b[1].wid;
146 b[0].nrune += b[1].nrune;
147 _frdelbox(f, bn+1, bn+1);
151 _frfindbox(Frame *f, int bn, ulong p, ulong q) /* find box containing q and put q on a box boundary */
155 for(b = &f->box[bn]; bn<f->nbox && p+NRUNE(b)<=q; bn++, b++)
158 _frsplitbox(f, bn++, (int)(q-p));