10 _fraddbox(Frame *f, int bn, int n) /* add n boxes after bn, shift the rest up,
11 * box[bn+n]==box[bn] */
16 drawerror(f->display, "_fraddbox");
17 if(f->nbox+n > f->nalloc)
18 _frgrowbox(f, n+SLOP);
19 for(i=f->nbox; --i>=bn; )
20 f->box[i+n] = f->box[i];
25 _frclosebox(Frame *f, int n0, int n1) /* inclusive */
29 if(n0>=f->nbox || n1>=f->nbox || n1<n0)
30 drawerror(f->display, "_frclosebox");
32 for(i=n1; i<f->nbox; i++)
33 f->box[i-(n1-n0)] = f->box[i];
38 _frdelbox(Frame *f, int n0, int n1) /* inclusive */
40 if(n0>=f->nbox || n1>=f->nbox || n1<n0)
41 drawerror(f->display, "_frdelbox");
42 _frfreebox(f, n0, n1);
43 _frclosebox(f, n0, n1);
47 _frfreebox(Frame *f, int n0, int n1) /* inclusive */
53 if(n0>=f->nbox || n1>=f->nbox)
54 drawerror(f->display, "_frfreebox");
57 if(f->box[i].nrune >= 0)
62 _frgrowbox(Frame *f, int delta)
65 f->box = realloc(f->box, f->nalloc*sizeof(Frbox));
67 drawerror(f->display, "_frgrowbox");
72 dupbox(Frame *f, int bn)
76 if(f->box[bn].nrune < 0)
77 drawerror(f->display, "dupbox");
79 if(f->box[bn].nrune >= 0){
80 p = _frallocstr(f, NBYTE(&f->box[bn])+1);
81 strcpy((char*)p, (char*)f->box[bn].ptr);
88 runeindex(uchar *p, int n)
93 for(i=0; i<n; i++,p+=w)
97 w = chartorune(&rune, (char*)p);
105 truncatebox(Frame *f, Frbox *b, int n) /* drop last n chars; no allocation done */
107 if(b->nrune<0 || b->nrune<n)
108 drawerror(f->display, "truncatebox");
110 runeindex(b->ptr, b->nrune)[0] = 0;
111 b->wid = stringwidth(f->font, (char *)b->ptr);
116 chopbox(Frame *f, Frbox *b, int n) /* drop first n chars; no allocation done */
120 if(b->nrune<0 || b->nrune<n)
121 drawerror(f->display, "chopbox");
122 p = (char*)runeindex(b->ptr, n);
123 memmove((char*)b->ptr, p, strlen(p)+1);
125 b->wid = stringwidth(f->font, (char *)b->ptr);
129 _frsplitbox(Frame *f, int bn, int n)
132 truncatebox(f, &f->box[bn], f->box[bn].nrune-n);
133 chopbox(f, &f->box[bn+1], n);
137 _frmergebox(Frame *f, int bn) /* merge bn and bn+1 */
142 _frinsure(f, bn, NBYTE(&b[0])+NBYTE(&b[1])+1);
143 strcpy((char*)runeindex(b[0].ptr, b[0].nrune), (char*)b[1].ptr);
144 b[0].wid += b[1].wid;
145 b[0].nrune += b[1].nrune;
146 _frdelbox(f, bn+1, bn+1);
150 _frfindbox(Frame *f, int bn, ulong p, ulong q) /* find box containing q and put q on a box boundary */
154 for(b = &f->box[bn]; bn<f->nbox && p+NRUNE(b)<=q; bn++, b++)
157 _frsplitbox(f, bn++, (int)(q-p));