frinit.c - sam - An updated version of the sam text editor.
(HTM) git clone git://vernunftzentrum.de/sam.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
frinit.c (1199B)
---
1 /* Copyright (c) 1998 Lucent Technologies - All rights reserved. */
2 #include <u.h>
3 #include <libg.h>
4 #include <frame.h>
5
6 int tabwidth = 8;
7 extern bool expandtabs;
8
9 void
10 frinit(Frame *f, Rectangle r, XftFont *ft, Bitmap *b, uint64_t bg)
11 {
12 int tabs = atoi(getenv("TABS") ? getenv("TABS") : "");
13 if (tabs < 0){
14 tabs = -tabs;
15 expandtabs = true;
16 }
17
18 if (tabs > 0 && tabs <= 12)
19 tabwidth = tabs;
20
21 f->font = ft;
22 /* ft->height is NOT CORRECT; we must use ascent + descent to
23 clear the lowest edge of characters. - cks */
24 f->fheight = ft->ascent + ft->descent;
25 f->maxtab = tabwidth*charwidth(ft, '0');
26 f->nbox = 0;
27 f->nalloc = 0;
28 f->nchars = 0;
29 f->nlines = 0;
30 f->p0 = 0;
31 f->p1 = 0;
32 f->box = 0;
33 f->lastlinefull = 0;
34 f->bg = bg;
35 frsetrects(f, r, b);
36 }
37
38 void
39 frsetrects(Frame *f, Rectangle r, Bitmap *b)
40 {
41 f->b = b;
42 f->entire = r;
43 f->r = r;
44 f->r.max.y -= (r.max.y-r.min.y)%f->fheight;
45 f->left = r.min.x+1;
46 f->maxlines = (r.max.y-r.min.y)/f->fheight;
47 }
48
49 void
50 frclear(Frame *f)
51 {
52 if(f->nbox)
53 _frdelbox(f, 0, f->nbox-1);
54 if(f->box)
55 free(f->box);
56 f->box = 0;
57 }