add config.h, fix tag pixel bug, tweak colors, add libframe with cursor fix

This commit is contained in:
Iris Lightshard 2022-02-20 13:43:24 -07:00
parent fe2024f43e
commit 27aa20a319
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
21 changed files with 1457 additions and 51 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
config.h
**/*.o
**/*.a
**/o.*
acme

69
acme.c
View file

@ -15,6 +15,9 @@
#include <bio.h>
#include "edit.h"
/* configuration file */
#include "config.h"
void mousethread(void*);
void keyboardthread(void*);
void waitthread(void*);
@ -37,9 +40,7 @@ enum {
};
Rune snarfrune[NSnarf + 1];
char* fontnames[2] = {
"/lib/font/bit/lucsans/typeunicode.7.font",
"/lib/font/bit/lucm/unicode.9.font"};
char* fontnames[2] = {PRIMARY_FONT, SECONDARY_FONT};
Command* command;
@ -53,13 +54,14 @@ void derror(Display* d, char* errorstr) {
error(errorstr);
}
// we need to share this btw mainthread and mousethread
void threadmain(int argc, char* argv[]) {
int i;
char *p, *loadfile;
Column* c;
int ncol;
Display* d;
int ncol;
Column* c;
rfork(RFENVG | RFNAMEG);
ncol = -1;
@ -71,10 +73,10 @@ void threadmain(int argc, char* argv[]) {
_threaddebuglevel = ~0;
} break;
case 'a':
globalindent[AUTOINDENT] = TRUE;
globalindent[AUTOINDENT] = !AUTOINDENT_DEFAULT;
break;
case 'b':
bartflag = TRUE;
bartflag = !CLICKFOCUS_DEFAULT;
break;
case 'c':
p = ARGF();
@ -95,7 +97,7 @@ void threadmain(int argc, char* argv[]) {
goto Usage;
break;
case 'i':
globalindent[SPACESINDENT] = TRUE;
globalindent[SPACESINDENT] = !TABSTOSPACES_DEFAULT;
break;
case 'l':
loadfile = ARGF();
@ -501,6 +503,7 @@ void mousethread(void* v) {
char* act;
enum { MResize, MMouse, MPlumb, MWarnings, NMALT };
static Alt alts[NMALT + 1];
int click;
USED(v);
threadsetname("mousethread");
@ -521,6 +524,7 @@ void mousethread(void* v) {
alts[NMALT].op = CHANEND;
for (;;) {
click = 0;
qlock(&row.lk);
flushwarnings();
qunlock(&row.lk);
@ -532,7 +536,7 @@ void mousethread(void* v) {
draw(
screen,
screen->r,
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x222222FF),
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_EMPTY),
nil,
ZP);
iconinit();
@ -630,8 +634,10 @@ void mousethread(void* v) {
goto Continue;
}
if (m.buttons) {
if (w)
if (w) {
click = 1;
winlock(w, 'M');
}
t->eq0 = ~0;
if (w)
wincommit(w, t);
@ -647,6 +653,7 @@ void mousethread(void* v) {
activecol = t->col; /* button 1 only */
if (t->w != nil && t == &t->w->body)
activewin = t->w;
} else if (m.buttons & 2) {
if (textselect2(t, &q0, &q1, &argt))
execute(t, q0, q1, FALSE, argt);
@ -659,6 +666,10 @@ void mousethread(void* v) {
goto Continue;
}
Continue:
/*if (click && w) {
/* draw hilighted border around active window
windrawideco(w, w->col->row->col, w->col->row->ncol);
}*/
qunlock(&row.lk);
break;
}
@ -968,34 +979,36 @@ Cursor2 boxcursor2 = {
0xFF, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
void iconinit(void) {
Rectangle r;
Rectangle r, r1;
Image* tmp;
if (tagcols[BACK] == nil) {
/* Black */
tagcols[BACK] =
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DBlack);
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_TAG_BG);
tagcols[HIGH] =
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x1F9B92FF);
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_TAG_HI);
tagcols[BORD] =
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x797979FF);
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_TAG_BD);
tagcols[TEXT] =
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x797979FF);
tagcols[HTEXT] = display->black;
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_TAG_TX);
tagcols[HTEXT] =
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_TAG_HT);
/* Blue */
textcols[BACK] =
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x000F19FF);
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_BODY_BG);
textcols[HIGH] =
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x1F9B92FF);
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_BODY_HI);
textcols[BORD] =
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x93A1A1FF);
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_BODY_BD);
textcols[TEXT] =
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x93A1A1FF);
textcols[HTEXT] = display->black;
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_BODY_TX);
textcols[HTEXT] =
allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_BODY_HT);
}
r = Rect(0, 0, Scrollwid + ButtonBorder, font->height + 1);
r = Rect(0, 0, Scrollwid, font->height + 1);
if (button && eqrect(r, button->r))
return;
@ -1007,24 +1020,22 @@ void iconinit(void) {
button = allocimage(display, r, screen->chan, 0, DNofill);
draw(button, r, tagcols[BACK], nil, r.min);
r.max.x -= ButtonBorder;
border(button, r, ButtonBorder, tagcols[BORD], ZP);
r = button->r;
modbutton = allocimage(display, r, screen->chan, 0, DNofill);
draw(modbutton, r, tagcols[BACK], nil, r.min);
r.max.x -= ButtonBorder;
border(modbutton, r, ButtonBorder, tagcols[BORD], ZP);
r = insetrect(r, ButtonBorder);
tmp = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x09998DFF);
tmp = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_BTN_MD);
draw(modbutton, r, tmp, nil, ZP);
freeimage(tmp);
r = button->r;
colbutton = allocimage(display, r, screen->chan, 0, 0x586E75FF);
colbutton = allocimage(display, r, screen->chan, 0, COLOR_BTN_CO);
but2col = allocimage(display, r, screen->chan, 1, 0x797979FF);
but3col = allocimage(display, r, screen->chan, 1, 0x36D3C6FF);
but2col = allocimage(display, r, screen->chan, 1, COLOR_B2_HI);
but3col = allocimage(display, r, screen->chan, 1, COLOR_B3_HI);
}
/*

View file

@ -1,7 +1,12 @@
#!/bin/sh
if [ ! -e ./config.h ]; then
cp config.def.h config.h
fi
clang-format -i ./*.c
clang-format -i ./mail/*.c
clang-format -i ./libframe/*.c
mk clean
mk

59
config.def.h Normal file
View file

@ -0,0 +1,59 @@
/******************
* acme9k1 config *
******************/
/**********
* colors *
**********/
/* when column is empty */
#define COLOR_EMPTY 0x222222FF
/* tag & body colors: bg, hilight, border, text, hilighted text */
#define COLOR_TAG_BG 0x000000FF
#define COLOR_TAG_HI 0x1F9b92FF
#define COLOR_TAG_BD 0x797979FF
#define COLOR_TAG_TX 0xC9C9C9FF
#define COLOR_TAG_HT 0x000000FF
#define COLOR_BODY_BG 0x000F19FF
#define COLOR_BODY_HI 0x1F9B92FF
#define COLOR_BODY_BD 0x797979FF
#define COLOR_BODY_TX 0x93A1A1FF
#define COLOR_BODY_HT 0x000000FF
/* button colors: dirty file (mod) indicator and column handles */
#define COLOR_BTN_MD 0x1F9B92FF
#define COLOR_BTN_CO 0x586E75FF
/* button 2 and 3 selection colors */
#define COLOR_B2_HI 0x797979FF
#define COLOR_B3_HI 0x002B36FF
/*********
* fonts *
*********/
/* can use either x fonts via fontsrv or p9p fonts */
#define PRIMARY_FONT "/mnt/font/SauceCodeProNerdFontComplete-Regular/9a/font"
#define SECONDARY_FONT "/lib/font/bit/lucm/unicode.9.font"
/********
* misc *
********/
/* 0 = focus follows mouse, 1 = click to focus; -b flag will invert this */
#define CLICKFOCUS_DEFAULT 0
/* 0 = literal tabs, 1 = tabs to spaces; -i flag will invert this */
#define TABSTOSPACES_DEFAULT 0
/* 0 = no auto indent, 1 = autoindent; -a flag will invert this */
#define AUTOINDENT_DEFAULT 0

3
dat.h
View file

@ -215,7 +215,7 @@ void textinit(Text*, File*, Rectangle, Reffont*, Image**);
void textinsert(Text*, uint, Rune*, uint, int);
int textload(Text*, uint, char*, int);
Rune textreadc(Text*, uint);
void textredraw(Text*, Rectangle, Font*, Image*, int);
void textredraw(Text*, Rectangle, Font*, Image*, int, int);
void textreset(Text*);
int textresize(Text*, Rectangle, int);
void textscrdraw(Text*);
@ -304,6 +304,7 @@ void winmousebut(Window*);
void winaddincl(Window*, Rune*, int);
void wincleartag(Window*);
char *winctlprint(Window*, char*, int);
void windrawideco(Window*, Column**, int);
struct Column
{

143
libframe/frbox.c Normal file
View file

@ -0,0 +1,143 @@
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <mouse.h>
#include <frame.h>
#define SLOP 25
void _fraddbox(Frame* f, int bn, int n) /* add n boxes after bn, shift the rest
* up, box[bn+n]==box[bn] */
{
int i;
if (bn > f->nbox)
drawerror(f->display, "_fraddbox");
if (f->nbox + n > f->nalloc)
_frgrowbox(f, n + SLOP);
for (i = f->nbox; --i >= bn;)
f->box[i + n] = f->box[i];
f->nbox += n;
}
void _frclosebox(Frame* f, int n0, int n1) /* inclusive */
{
int i;
if (n0 >= f->nbox || n1 >= f->nbox || n1 < n0)
drawerror(f->display, "_frclosebox");
n1++;
for (i = n1; i < f->nbox; i++)
f->box[i - (n1 - n0)] = f->box[i];
f->nbox -= n1 - n0;
}
void _frdelbox(Frame* f, int n0, int n1) /* inclusive */
{
if (n0 >= f->nbox || n1 >= f->nbox || n1 < n0)
drawerror(f->display, "_frdelbox");
_frfreebox(f, n0, n1);
_frclosebox(f, n0, n1);
}
void _frfreebox(Frame* f, int n0, int n1) /* inclusive */
{
int i;
if (n1 < n0)
return;
if (n0 >= f->nbox || n1 >= f->nbox)
drawerror(f->display, "_frfreebox");
n1++;
for (i = n0; i < n1; i++)
if (f->box[i].nrune >= 0)
free(f->box[i].ptr);
}
void _frgrowbox(Frame* f, int delta) {
f->nalloc += delta;
f->box = realloc(f->box, f->nalloc * sizeof(Frbox));
if (f->box == 0)
drawerror(f->display, "_frgrowbox");
}
static void dupbox(Frame* f, int bn) {
uchar* p;
if (f->box[bn].nrune < 0)
drawerror(f->display, "dupbox");
_fraddbox(f, bn, 1);
if (f->box[bn].nrune >= 0) {
p = _frallocstr(f, NBYTE(&f->box[bn]) + 1);
strcpy((char*)p, (char*)f->box[bn].ptr);
f->box[bn + 1].ptr = p;
}
}
static uchar* runeindex(uchar* p, int n) {
int i, w;
Rune rune;
for (i = 0; i < n; i++, p += w)
if (*p < Runeself)
w = 1;
else {
w = chartorune(&rune, (char*)p);
USED(rune);
}
return p;
}
static void truncatebox(
Frame* f, Frbox* b, int n) /* drop last n chars; no allocation done */
{
if (b->nrune < 0 || b->nrune < n)
drawerror(f->display, "truncatebox");
b->nrune -= n;
runeindex(b->ptr, b->nrune)[0] = 0;
b->wid = stringwidth(f->font, (char*)b->ptr);
}
static void chopbox(
Frame* f, Frbox* b, int n) /* drop first n chars; no allocation done */
{
char* p;
if (b->nrune < 0 || b->nrune < n)
drawerror(f->display, "chopbox");
p = (char*)runeindex(b->ptr, n);
memmove((char*)b->ptr, p, strlen(p) + 1);
b->nrune -= n;
b->wid = stringwidth(f->font, (char*)b->ptr);
}
void _frsplitbox(Frame* f, int bn, int n) {
dupbox(f, bn);
truncatebox(f, &f->box[bn], f->box[bn].nrune - n);
chopbox(f, &f->box[bn + 1], n);
}
void _frmergebox(Frame* f, int bn) /* merge bn and bn+1 */
{
Frbox* b;
b = &f->box[bn];
_frinsure(f, bn, NBYTE(&b[0]) + NBYTE(&b[1]) + 1);
strcpy((char*)runeindex(b[0].ptr, b[0].nrune), (char*)b[1].ptr);
b[0].wid += b[1].wid;
b[0].nrune += b[1].nrune;
_frdelbox(f, bn + 1, bn + 1);
}
int _frfindbox(
Frame* f, int bn, ulong p,
ulong q) /* find box containing q and put q on a box boundary */
{
Frbox* b;
for (b = &f->box[bn]; bn < f->nbox && p + NRUNE(b) <= q; bn++, b++)
p += NRUNE(b);
if (p != q)
_frsplitbox(f, bn++, (int)(q - p));
return bn;
}

139
libframe/frdelete.c Normal file
View file

@ -0,0 +1,139 @@
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <mouse.h>
#include <frame.h>
int frdelete(Frame* f, ulong p0, ulong p1) {
Point pt0, pt1, ppt0;
Frbox* b;
int n0, n1, n, w0;
ulong cn1;
Rectangle r;
int nn0;
Image* col;
if (p0 >= f->nchars || p0 == p1 || f->b == nil)
return 0;
if (p1 > f->nchars)
p1 = f->nchars;
n0 = _frfindbox(f, 0, 0, p0);
if (n0 == f->nbox)
drawerror(f->display, "off end in frdelete");
n1 = _frfindbox(f, n0, p0, p1);
pt0 = _frptofcharnb(f, p0, n0);
pt1 = frptofchar(f, p1);
if (f->p0 == f->p1)
frtick(f, frptofchar(f, f->p0), 0);
nn0 = n0;
ppt0 = pt0;
_frfreebox(f, n0, n1 - 1);
f->modified = 1;
/*
* Invariants:
* - pt0 points to beginning, pt1 points to end
* - n0 is box containing beginning of stuff being deleted
* - n1, b are box containing beginning of stuff to be kept after deletion
* - cn1 is char position of n1
* - f->p0 and f->p1 are not adjusted until after all deletion is done
*/
b = &f->box[n1];
cn1 = p1;
while (pt1.x != pt0.x && n1 < f->nbox) {
_frcklinewrap0(f, &pt0, b);
_frcklinewrap(f, &pt1, b);
n = _frcanfit(f, pt0, b);
if (n == 0)
drawerror(f->display, "_frcanfit==0");
r.min = pt0;
r.max = pt0;
r.max.y += f->font->height;
if (b->nrune > 0) {
w0 = b->wid;
if (n != b->nrune) {
_frsplitbox(f, n1, n);
b = &f->box[n1];
}
r.max.x += b->wid;
draw(f->b, r, f->b, nil, pt1);
cn1 += b->nrune;
/* blank remainder of line */
r.min.x = r.max.x;
r.max.x += w0 - b->wid;
if (r.max.x > f->r.max.x)
r.max.x = f->r.max.x;
draw(f->b, r, f->cols[BACK], nil, r.min);
} else {
r.max.x += _frnewwid0(f, pt0, b);
if (r.max.x > f->r.max.x)
r.max.x = f->r.max.x;
col = f->cols[BACK];
if (f->p0 <= cn1 && cn1 < f->p1)
col = f->cols[HIGH];
draw(f->b, r, col, nil, pt0);
cn1++;
}
_fradvance(f, &pt1, b);
pt0.x += _frnewwid(f, pt0, b);
f->box[n0++] = f->box[n1++];
b++;
}
if (n1 == f->nbox && pt0.x != pt1.x) /* deleting last thing in window; must
clean up */
frselectpaint(f, pt0, pt1, f->cols[BACK]);
if (pt1.y != pt0.y) {
Point pt2;
pt2 = _frptofcharptb(f, 32767, pt1, n1);
if (pt2.y > f->r.max.y)
drawerror(f->display, "frptofchar in frdelete");
if (n1 < f->nbox) {
int q0, q1, q2;
q0 = pt0.y + f->font->height;
q1 = pt1.y + f->font->height;
q2 = pt2.y + f->font->height;
if (q2 > f->r.max.y)
q2 = f->r.max.y;
draw(
f->b,
Rect(pt0.x, pt0.y, pt0.x + (f->r.max.x - pt1.x), q0),
f->b,
nil,
pt1);
draw(
f->b,
Rect(f->r.min.x, q0, f->r.max.x, q0 + (q2 - q1)),
f->b,
nil,
Pt(f->r.min.x, q1));
frselectpaint(f, Pt(pt2.x, pt2.y - (pt1.y - pt0.y)), pt2, f->cols[BACK]);
} else
frselectpaint(f, pt0, pt2, f->cols[BACK]);
}
_frclosebox(f, n0, n1 - 1);
if (
nn0 > 0 && f->box[nn0 - 1].nrune >= 0 &&
ppt0.x - f->box[nn0 - 1].wid >= (int)f->r.min.x) {
--nn0;
ppt0.x -= f->box[nn0].wid;
}
_frclean(f, ppt0, nn0, n0 < f->nbox - 1 ? n0 + 1 : n0);
if (f->p1 > p1)
f->p1 -= p1 - p0;
else if (f->p1 > p0)
f->p1 = p0;
if (f->p0 > p1)
f->p0 -= p1 - p0;
else if (f->p0 > p0)
f->p0 = p0;
f->nchars -= p1 - p0;
if (f->p0 == f->p1)
frtick(f, frptofchar(f, f->p0), 1);
pt0 = frptofchar(f, f->nchars);
n = f->nlines;
f->nlines = (pt0.y - f->r.min.y) / f->font->height + (pt0.x > f->r.min.x);
return n - f->nlines;
}

200
libframe/frdraw.c Normal file
View file

@ -0,0 +1,200 @@
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <mouse.h>
#include <frame.h>
void _frdrawtext(Frame* f, Point pt, Image* text, Image* back) {
Frbox* b;
int nb;
for (nb = 0, b = f->box; nb < f->nbox; nb++, b++) {
_frcklinewrap(f, &pt, b);
if (!f->noredraw && b->nrune >= 0)
stringbg(f->b, pt, text, ZP, f->font, (char*)b->ptr, back, ZP);
pt.x += b->wid;
}
}
static int nbytes(char* s0, int nr) {
char* s;
Rune r;
s = s0;
while (--nr >= 0)
s += chartorune(&r, s);
return s - s0;
}
void frdrawsel(Frame* f, Point pt, ulong p0, ulong p1, int issel) {
Image *back, *text;
if (f->ticked)
frtick(f, frptofchar(f, f->p0), 0);
if (p0 == p1) {
frtick(f, pt, issel);
return;
}
if (issel) {
back = f->cols[HIGH];
text = f->cols[HTEXT];
} else {
back = f->cols[BACK];
text = f->cols[TEXT];
}
frdrawsel0(f, pt, p0, p1, back, text);
}
Point frdrawsel0(
Frame* f, Point pt, ulong p0, ulong p1, Image* back, Image* text) {
Frbox* b;
int nb, nr, w, x, trim;
Point qt;
uint p;
char* ptr;
if (p0 > p1)
sysfatal("libframe: frdrawsel0 p0=%lud > p1=%lud", p0, p1);
p = 0;
b = f->box;
trim = 0;
for (nb = 0; nb < f->nbox && p < p1; nb++) {
nr = b->nrune;
if (nr < 0)
nr = 1;
if (p + nr <= p0)
goto Continue;
if (p >= p0) {
qt = pt;
_frcklinewrap(f, &pt, b);
/* fill in the end of a wrapped line */
if (pt.y > qt.y)
draw(f->b, Rect(qt.x, qt.y, f->r.max.x, pt.y), back, nil, qt);
}
ptr = (char*)b->ptr;
if (p < p0) { /* beginning of region: advance into box */
ptr += nbytes(ptr, p0 - p);
nr -= (p0 - p);
p = p0;
}
trim = 0;
if (p + nr > p1) { /* end of region: trim box */
nr -= (p + nr) - p1;
trim = 1;
}
if (b->nrune < 0 || nr == b->nrune)
w = b->wid;
else
w = stringnwidth(f->font, ptr, nr);
x = pt.x + w;
if (x > f->r.max.x)
x = f->r.max.x;
draw(f->b, Rect(pt.x, pt.y, x, pt.y + f->font->height), back, nil, pt);
if (b->nrune >= 0)
stringnbg(f->b, pt, text, ZP, f->font, ptr, nr, back, ZP);
pt.x += w;
Continue:
b++;
p += nr;
}
/* if this is end of last plain text box on wrapped line, fill to end of line
*/
if (
p1 > p0 && b > f->box && b < f->box + f->nbox && b[-1].nrune > 0 && !trim) {
qt = pt;
_frcklinewrap(f, &pt, b);
if (pt.y > qt.y)
draw(f->b, Rect(qt.x, qt.y, f->r.max.x, pt.y), back, nil, qt);
}
return pt;
}
void frredraw(Frame* f) {
int ticked;
Point pt;
if (f->p0 == f->p1) {
ticked = f->ticked;
if (ticked)
frtick(f, frptofchar(f, f->p0), 0);
frdrawsel0(f, frptofchar(f, 0), 0, f->nchars, f->cols[BACK], f->cols[TEXT]);
if (ticked)
frtick(f, frptofchar(f, f->p0), 1);
return;
}
pt = frptofchar(f, 0);
pt = frdrawsel0(f, pt, 0, f->p0, f->cols[BACK], f->cols[TEXT]);
pt = frdrawsel0(f, pt, f->p0, f->p1, f->cols[HIGH], f->cols[HTEXT]);
pt = frdrawsel0(f, pt, f->p1, f->nchars, f->cols[BACK], f->cols[TEXT]);
}
static void _frtick(Frame* f, Point pt, int ticked) {
Rectangle r;
if (f->ticked == ticked || f->tick == 0 || !ptinrect(pt, f->r))
return;
pt.x -= f->tickscale; /* looks best just left of where requested */
r = Rect(pt.x, pt.y, pt.x + FRTICKW * f->tickscale, pt.y + f->font->height);
/* can go into left border but not right */
if (r.max.x > f->r.max.x)
r.max.x = f->r.max.x;
if (ticked) {
draw(f->tickback, f->tickback->r, f->b, nil, pt);
draw(f->b, r, f->tick, nil, ZP);
} else
draw(f->b, r, f->tickback, nil, ZP);
f->ticked = ticked;
}
void frtick(Frame* f, Point pt, int ticked) {
if (f->tickscale != scalesize(f->display, 1)) {
if (f->ticked)
_frtick(f, pt, 0);
frinittick(f);
}
_frtick(f, pt, ticked);
}
Point _frdraw(Frame* f, Point pt) {
Frbox* b;
int nb, n;
for (b = f->box, nb = 0; nb < f->nbox; nb++, b++) {
_frcklinewrap0(f, &pt, b);
if (pt.y == f->r.max.y) {
f->nchars -= _frstrlen(f, nb);
_frdelbox(f, nb, f->nbox - 1);
break;
}
if (b->nrune > 0) {
n = _frcanfit(f, pt, b);
if (n == 0)
break;
if (n != b->nrune) {
_frsplitbox(f, nb, n);
b = &f->box[nb];
}
pt.x += b->wid;
} else {
if (b->bc == '\n') {
pt.x = f->r.min.x;
pt.y += f->font->height;
} else
pt.x += _frnewwid(f, pt, b);
}
}
return pt;
}
int _frstrlen(Frame* f, int nb) {
int n;
for (n = 0; nb < f->nbox; nb++)
n += NRUNE(&f->box[nb]);
return n;
}

106
libframe/frinit.c Normal file
View file

@ -0,0 +1,106 @@
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <mouse.h>
#include <frame.h>
void frinit(Frame* f, Rectangle r, Font* ft, Image* b, Image* cols[NCOL]) {
f->font = ft;
f->display = b->display;
f->maxtab = 8 * stringwidth(ft, "0");
f->nbox = 0;
f->nalloc = 0;
f->nchars = 0;
f->nlines = 0;
f->p0 = 0;
f->p1 = 0;
f->box = 0;
f->lastlinefull = 0;
if (cols != 0)
memmove(f->cols, cols, sizeof f->cols);
frsetrects(f, r, b);
if (f->tick == nil && f->cols[BACK] != 0)
frinittick(f);
}
void frinittick(Frame* f) {
Image* b;
Font* ft;
if (f->cols[BACK] == nil || f->display == nil)
return;
f->tickscale = scalesize(f->display, 1);
b = f->display->screenimage;
ft = f->font;
if (f->tick)
freeimage(f->tick);
f->tick = allocimage(
f->display,
Rect(0, 0, f->tickscale * FRTICKW, ft->height),
b->chan,
0,
DWhite);
if (f->tick == nil)
return;
if (f->tickback)
freeimage(f->tickback);
f->tickback = allocimage(f->display, f->tick->r, b->chan, 0, DWhite);
if (f->tickback == 0) {
freeimage(f->tick);
f->tick = 0;
return;
}
/* background color */
draw(f->tick, f->tick->r, f->cols[BACK], nil, ZP);
/* vertical line */
draw(
f->tick,
Rect(
f->tickscale * (FRTICKW / 2),
0,
f->tickscale * (FRTICKW / 2 + 1),
ft->height),
f->cols[TEXT],
nil,
ZP);
/* box on each end */
draw(
f->tick,
Rect(0, 0, f->tickscale * FRTICKW, f->tickscale * FRTICKW),
f->cols[TEXT],
nil,
ZP);
draw(
f->tick,
Rect(
0,
ft->height - f->tickscale * FRTICKW,
f->tickscale * FRTICKW,
ft->height),
f->cols[TEXT],
nil,
ZP);
}
void frsetrects(Frame* f, Rectangle r, Image* b) {
f->b = b;
f->entire = r;
f->r = r;
f->r.max.y -= (r.max.y - r.min.y) % f->font->height;
f->maxlines = (r.max.y - r.min.y) / f->font->height;
}
void frclear(Frame* f, int freeall) {
if (f->nbox)
_frdelbox(f, 0, f->nbox - 1);
if (f->box)
free(f->box);
if (freeall) {
freeimage(f->tick);
freeimage(f->tickback);
f->tick = 0;
f->tickback = 0;
}
f->box = 0;
f->ticked = 0;
}

285
libframe/frinsert.c Normal file
View file

@ -0,0 +1,285 @@
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <mouse.h>
#include <frame.h>
#define DELTA 25
#define TMPSIZE 256
static Frame frame;
static Point bxscan(Frame* f, Rune* sp, Rune* ep, Point* ppt) {
int w, c, nb, delta, nl, nr, rw;
Frbox* b;
char *s, tmp[TMPSIZE + 3]; /* +3 for rune overflow */
uchar* p;
frame.r = f->r;
frame.b = f->b;
frame.font = f->font;
frame.maxtab = f->maxtab;
frame.nbox = 0;
frame.nchars = 0;
memmove(frame.cols, f->cols, sizeof frame.cols);
delta = DELTA;
nl = 0;
for (nb = 0; sp < ep && nl <= f->maxlines; nb++, frame.nbox++) {
if (nb == frame.nalloc) {
_frgrowbox(&frame, delta);
if (delta < 10000)
delta *= 2;
}
b = &frame.box[nb];
c = *sp;
if (c == '\t' || c == '\n') {
b->bc = c;
b->wid = 5000;
b->minwid = (c == '\n') ? 0 : stringwidth(frame.font, " ");
b->nrune = -1;
if (c == '\n')
nl++;
frame.nchars++;
sp++;
} else {
s = tmp;
nr = 0;
w = 0;
while (sp < ep) {
c = *sp;
if (c == '\t' || c == '\n')
break;
rw = runetochar(s, sp);
if (s + rw >= tmp + TMPSIZE)
break;
w += runestringnwidth(frame.font, sp, 1);
sp++;
s += rw;
nr++;
}
*s++ = 0;
p = _frallocstr(f, s - tmp);
b = &frame.box[nb];
b->ptr = p;
memmove(p, tmp, s - tmp);
b->wid = w;
b->nrune = nr;
frame.nchars += nr;
}
}
_frcklinewrap0(f, ppt, &frame.box[0]);
return _frdraw(&frame, *ppt);
}
static void chopframe(Frame* f, Point pt, ulong p, int bn) {
Frbox* b;
for (b = &f->box[bn];; b++) {
if (b >= &f->box[f->nbox])
drawerror(f->display, "endofframe");
_frcklinewrap(f, &pt, b);
if (pt.y >= f->r.max.y)
break;
p += NRUNE(b);
_fradvance(f, &pt, b);
}
f->nchars = p;
f->nlines = f->maxlines;
if (b < &f->box[f->nbox]) /* BUG */
_frdelbox(f, (int)(b - f->box), f->nbox - 1);
}
void frinsert(Frame* f, Rune* sp, Rune* ep, ulong p0) {
Point pt0, pt1, opt0, ppt0, ppt1, pt;
Frbox* b;
int n, n0, nn0, y;
ulong cn0;
Image *col, *tcol;
Rectangle r;
static struct { Point pt0, pt1; } * pts;
static int nalloc = 0;
int npts;
if (p0 > f->nchars || sp == ep || f->b == nil)
return;
n0 = _frfindbox(f, 0, 0, p0);
cn0 = p0;
nn0 = n0;
pt0 = _frptofcharnb(f, p0, n0);
ppt0 = pt0;
opt0 = pt0;
pt1 = bxscan(f, sp, ep, &ppt0);
ppt1 = pt1;
if (n0 < f->nbox) {
_frcklinewrap(f, &pt0, b = &f->box[n0]); /* for frdrawsel() */
_frcklinewrap0(f, &ppt1, b);
}
f->modified = 1;
/*
* ppt0 and ppt1 are start and end of insertion as they will appear when
* insertion is complete. pt0 is current location of insertion position
* (p0); pt1 is terminal point (without line wrap) of insertion.
*/
if (f->p0 == f->p1)
frtick(f, frptofchar(f, f->p0), 0);
/*
* Find point where old and new x's line up
* Invariants:
* pt0 is where the next box (b, n0) is now
* pt1 is where it will be after the insertion
* If pt1 goes off the rectangle, we can toss everything from there on
*/
for (b = &f->box[n0], npts = 0;
pt1.x != pt0.x && pt1.y != f->r.max.y && n0 < f->nbox;
b++, n0++, npts++) {
_frcklinewrap(f, &pt0, b);
_frcklinewrap0(f, &pt1, b);
if (b->nrune > 0) {
n = _frcanfit(f, pt1, b);
if (n == 0)
drawerror(f->display, "_frcanfit==0");
if (n != b->nrune) {
_frsplitbox(f, n0, n);
b = &f->box[n0];
}
}
if (npts == nalloc) {
pts = realloc(pts, (npts + DELTA) * sizeof(pts[0]));
nalloc += DELTA;
b = &f->box[n0];
}
pts[npts].pt0 = pt0;
pts[npts].pt1 = pt1;
/* has a text box overflowed off the frame? */
if (pt1.y == f->r.max.y)
break;
_fradvance(f, &pt0, b);
pt1.x += _frnewwid(f, pt1, b);
cn0 += NRUNE(b);
}
if (pt1.y > f->r.max.y)
drawerror(f->display, "frinsert pt1 too far");
if (pt1.y == f->r.max.y && n0 < f->nbox) {
f->nchars -= _frstrlen(f, n0);
_frdelbox(f, n0, f->nbox - 1);
}
if (n0 == f->nbox)
f->nlines = (pt1.y - f->r.min.y) / f->font->height + (pt1.x > f->r.min.x);
else if (pt1.y != pt0.y) {
int q0, q1;
y = f->r.max.y;
q0 = pt0.y + f->font->height;
q1 = pt1.y + f->font->height;
f->nlines += (q1 - q0) / f->font->height;
if (f->nlines > f->maxlines)
chopframe(f, ppt1, p0, nn0);
if (pt1.y < y) {
r = f->r;
r.min.y = q1;
r.max.y = y;
if (q1 < y)
draw(f->b, r, f->b, nil, Pt(f->r.min.x, q0));
r.min = pt1;
r.max.x = pt1.x + (f->r.max.x - pt0.x);
r.max.y = q1;
draw(f->b, r, f->b, nil, pt0);
}
}
/*
* Move the old stuff down to make room. The loop will move the stuff
* between the insertion and the point where the x's lined up.
* The draw()s above moved everything down after the point they lined up.
*/
for ((y = pt1.y == f->r.max.y ? pt1.y : 0), b = &f->box[n0 - 1]; --npts >= 0;
--b) {
pt = pts[npts].pt1;
if (b->nrune > 0) {
r.min = pt;
r.max = r.min;
r.max.x += b->wid;
r.max.y += f->font->height;
draw(f->b, r, f->b, nil, pts[npts].pt0);
/* clear bit hanging off right */
if (npts == 0 && pt.y > pt0.y) {
/*
* first new char is bigger than first char we're
* displacing, causing line wrap. ugly special case.
*/
r.min = opt0;
r.max = opt0;
r.max.x = f->r.max.x;
r.max.y += f->font->height;
if (f->p0 <= cn0 && cn0 < f->p1) /* b+1 is inside selection */
col = f->cols[HIGH];
else
col = f->cols[BACK];
draw(f->b, r, col, nil, r.min);
} else if (pt.y < y) {
r.min = pt;
r.max = pt;
r.min.x += b->wid;
r.max.x = f->r.max.x;
r.max.y += f->font->height;
if (f->p0 <= cn0 && cn0 < f->p1) /* b+1 is inside selection */
col = f->cols[HIGH];
else
col = f->cols[BACK];
draw(f->b, r, col, nil, r.min);
}
y = pt.y;
cn0 -= b->nrune;
} else {
r.min = pt;
r.max = pt;
r.max.x += b->wid;
r.max.y += f->font->height;
if (r.max.x >= f->r.max.x)
r.max.x = f->r.max.x;
cn0--;
if (f->p0 <= cn0 && cn0 < f->p1) { /* b is inside selection */
col = f->cols[HIGH];
tcol = f->cols[HTEXT];
} else {
col = f->cols[BACK];
tcol = f->cols[TEXT];
}
draw(f->b, r, col, nil, r.min);
y = 0;
if (pt.x == f->r.min.x)
y = pt.y;
}
}
/* insertion can extend the selection, so the condition here is different */
if (f->p0 < p0 && p0 <= f->p1) {
col = f->cols[HIGH];
tcol = f->cols[HTEXT];
} else {
col = f->cols[BACK];
tcol = f->cols[TEXT];
}
frselectpaint(f, ppt0, ppt1, col);
_frdrawtext(&frame, ppt0, tcol, col);
_fraddbox(f, nn0, frame.nbox);
for (n = 0; n < frame.nbox; n++)
f->box[nn0 + n] = frame.box[n];
if (
nn0 > 0 && f->box[nn0 - 1].nrune >= 0 &&
ppt0.x - f->box[nn0 - 1].wid >= f->r.min.x) {
--nn0;
ppt0.x -= f->box[nn0].wid;
}
n0 += frame.nbox;
_frclean(f, ppt0, nn0, n0 < f->nbox - 1 ? n0 + 1 : n0);
f->nchars += frame.nchars;
if (f->p0 >= p0)
f->p0 += frame.nchars;
if (f->p0 > f->nchars)
f->p0 = f->nchars;
if (f->p1 >= p0)
f->p1 += frame.nchars;
if (f->p1 > f->nchars)
f->p1 = f->nchars;
if (f->p0 == f->p1)
frtick(f, frptofchar(f, f->p0), 1);
}

106
libframe/frptofchar.c Normal file
View file

@ -0,0 +1,106 @@
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <mouse.h>
#include <frame.h>
Point _frptofcharptb(Frame* f, ulong p, Point pt, int bn) {
uchar* s;
Frbox* b;
int w, l;
Rune r;
for (b = &f->box[bn]; bn < f->nbox; bn++, b++) {
_frcklinewrap(f, &pt, b);
if (p < (l = NRUNE(b))) {
if (b->nrune > 0)
for (s = b->ptr; p > 0; s += w, p--) {
if ((r = *s) < Runeself)
w = 1;
else
w = chartorune(&r, (char*)s);
pt.x += stringnwidth(f->font, (char*)s, 1);
if (r == 0 || pt.x > f->r.max.x)
drawerror(f->display, "frptofchar");
}
break;
}
p -= l;
_fradvance(f, &pt, b);
}
return pt;
}
Point frptofchar(Frame* f, ulong p) {
return _frptofcharptb(f, p, f->r.min, 0);
}
Point _frptofcharnb(
Frame* f, ulong p, int nb) /* doesn't do final _fradvance to next line */
{
Point pt;
int nbox;
nbox = f->nbox;
f->nbox = nb;
pt = _frptofcharptb(f, p, f->r.min, 0);
f->nbox = nbox;
return pt;
}
static Point _frgrid(Frame* f, Point p) {
p.y -= f->r.min.y;
p.y -= p.y % f->font->height;
p.y += f->r.min.y;
if (p.x > f->r.max.x)
p.x = f->r.max.x;
return p;
}
ulong frcharofpt(Frame* f, Point pt) {
Point qt;
int w, bn;
uchar* s;
Frbox* b;
ulong p;
Rune r;
pt = _frgrid(f, pt);
qt = f->r.min;
for (b = f->box, bn = 0, p = 0; bn < f->nbox && qt.y < pt.y; bn++, b++) {
_frcklinewrap(f, &qt, b);
if (qt.y >= pt.y)
break;
_fradvance(f, &qt, b);
p += NRUNE(b);
}
for (; bn < f->nbox && qt.x <= pt.x; bn++, b++) {
_frcklinewrap(f, &qt, b);
if (qt.y > pt.y)
break;
if (qt.x + b->wid > pt.x) {
if (b->nrune < 0)
_fradvance(f, &qt, b);
else {
s = b->ptr;
for (;;) {
if ((r = *s) < Runeself)
w = 1;
else
w = chartorune(&r, (char*)s);
if (r == 0)
drawerror(f->display, "end of string in frcharofpt");
qt.x += stringnwidth(f->font, (char*)s, 1);
s += w;
if (qt.x > pt.x)
break;
p++;
}
}
} else {
p += NRUNE(b);
_fradvance(f, &qt, b);
}
}
return p;
}

123
libframe/frselect.c Normal file
View file

@ -0,0 +1,123 @@
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <mouse.h>
#include <frame.h>
static int region(int a, int b) {
if (a < b)
return -1;
if (a == b)
return 0;
return 1;
}
void frselect(Frame* f, Mousectl* mc) /* when called, button 1 is down */
{
ulong p0, p1, q;
Point mp, pt0, pt1, qt;
int reg, b, scrled;
mp = mc->m.xy;
b = mc->m.buttons;
f->modified = 0;
frdrawsel(f, frptofchar(f, f->p0), f->p0, f->p1, 0);
p0 = p1 = frcharofpt(f, mp);
f->p0 = p0;
f->p1 = p1;
pt0 = frptofchar(f, p0);
pt1 = frptofchar(f, p1);
frdrawsel(f, pt0, p0, p1, 1);
reg = 0;
do {
scrled = 0;
if (f->scroll) {
if (mp.y < f->r.min.y) {
(*f->scroll)(f, -(f->r.min.y - mp.y) / (int)f->font->height - 1);
p0 = f->p1;
p1 = f->p0;
scrled = 1;
} else if (mp.y > f->r.max.y) {
(*f->scroll)(f, (mp.y - f->r.max.y) / (int)f->font->height + 1);
p0 = f->p0;
p1 = f->p1;
scrled = 1;
}
if (scrled) {
if (reg != region(p1, p0))
q = p0, p0 = p1, p1 = q; /* undo the swap that will happen below */
pt0 = frptofchar(f, p0);
pt1 = frptofchar(f, p1);
reg = region(p1, p0);
}
}
q = frcharofpt(f, mp);
if (p1 != q) {
if (reg != region(q, p0)) { /* crossed starting point; reset */
if (reg > 0)
frdrawsel(f, pt0, p0, p1, 0);
else if (reg < 0)
frdrawsel(f, pt1, p1, p0, 0);
p1 = p0;
pt1 = pt0;
reg = region(q, p0);
if (reg == 0)
frdrawsel(f, pt0, p0, p1, 1);
}
qt = frptofchar(f, q);
if (reg > 0) {
if (q > p1)
frdrawsel(f, pt1, p1, q, 1);
else if (q < p1)
frdrawsel(f, qt, q, p1, 0);
} else if (reg < 0) {
if (q > p1)
frdrawsel(f, pt1, p1, q, 0);
else
frdrawsel(f, qt, q, p1, 1);
}
p1 = q;
pt1 = qt;
}
f->modified = 0;
if (p0 < p1) {
f->p0 = p0;
f->p1 = p1;
} else {
f->p0 = p1;
f->p1 = p0;
}
if (scrled)
(*f->scroll)(f, 0);
flushimage(f->display, 1);
if (!scrled)
readmouse(mc);
mp = mc->m.xy;
} while (mc->m.buttons == b);
}
void frselectpaint(Frame* f, Point p0, Point p1, Image* col) {
int n;
Point q0, q1;
q0 = p0;
q1 = p1;
q0.y += f->font->height;
q1.y += f->font->height;
n = (p1.y - p0.y) / f->font->height;
if (f->b == nil)
drawerror(f->display, "frselectpaint b==0");
if (p0.y == f->r.max.y)
return;
if (n == 0)
draw(f->b, Rpt(p0, q1), col, nil, ZP);
else {
if (p0.x >= f->r.max.x)
p0.x = f->r.max.x - 1;
draw(f->b, Rect(p0.x, p0.y, f->r.max.x, q0.y), col, nil, ZP);
if (n > 1)
draw(f->b, Rect(f->r.min.x, q0.y, f->r.max.x, p1.y), col, nil, ZP);
draw(f->b, Rect(f->r.min.x, p1.y, q1.x, q1.y), col, nil, ZP);
}
}

33
libframe/frstr.c Normal file
View file

@ -0,0 +1,33 @@
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <mouse.h>
#include <frame.h>
#define CHUNK 16
#define ROUNDUP(n) ((n + CHUNK) & ~(CHUNK - 1))
uchar* _frallocstr(Frame* f, unsigned n) {
uchar* p;
p = malloc(ROUNDUP(n));
if (p == 0)
drawerror(f->display, "out of memory");
return p;
}
void _frinsure(Frame* f, int bn, unsigned n) {
Frbox* b;
uchar* p;
b = &f->box[bn];
if (b->nrune < 0)
drawerror(f->display, "_frinsure");
if (ROUNDUP(b->nrune) > n) /* > guarantees room for terminal NUL */
return;
p = _frallocstr(f, n);
b = &f->box[bn];
memmove(p, b->ptr, NBYTE(b) + 1);
free(b->ptr);
b->ptr = p;
}

99
libframe/frutil.c Normal file
View file

@ -0,0 +1,99 @@
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <mouse.h>
#include <frame.h>
int _frcanfit(Frame* f, Point pt, Frbox* b) {
int left, w, nr;
uchar* p;
Rune r;
left = f->r.max.x - pt.x;
if (b->nrune < 0)
return b->minwid <= left;
if (left >= b->wid)
return b->nrune;
for (nr = 0, p = b->ptr; *p; p += w, nr++) {
r = *p;
if (r < Runeself)
w = 1;
else
w = chartorune(&r, (char*)p);
left -= stringnwidth(f->font, (char*)p, 1);
if (left < 0)
return nr;
}
drawerror(f->display, "_frcanfit can't");
return 0;
}
void _frcklinewrap(Frame* f, Point* p, Frbox* b) {
if ((b->nrune < 0 ? b->minwid : b->wid) > f->r.max.x - p->x) {
p->x = f->r.min.x;
p->y += f->font->height;
}
}
void _frcklinewrap0(Frame* f, Point* p, Frbox* b) {
if (_frcanfit(f, *p, b) == 0) {
p->x = f->r.min.x;
p->y += f->font->height;
}
}
void _fradvance(Frame* f, Point* p, Frbox* b) {
if (b->nrune < 0 && b->bc == '\n') {
p->x = f->r.min.x;
p->y += f->font->height;
} else
p->x += b->wid;
}
int _frnewwid(Frame* f, Point pt, Frbox* b) {
b->wid = _frnewwid0(f, pt, b);
return b->wid;
}
int _frnewwid0(Frame* f, Point pt, Frbox* b) {
int c, x;
c = f->r.max.x;
x = pt.x;
if (b->nrune >= 0 || b->bc != '\t')
return b->wid;
if (x + b->minwid > c)
x = pt.x = f->r.min.x;
x += f->maxtab;
x -= (x - f->r.min.x) % f->maxtab;
if (x - pt.x < b->minwid || x > c)
x = pt.x + b->minwid;
return x - pt.x;
}
void _frclean(Frame* f, Point pt, int n0, int n1) /* look for mergeable boxes */
{
Frbox* b;
int nb, c;
c = f->r.max.x;
for (nb = n0; nb < n1 - 1; nb++) {
b = &f->box[nb];
_frcklinewrap(f, &pt, b);
while (b[0].nrune >= 0 && nb < n1 - 1 && b[1].nrune >= 0 &&
pt.x + b[0].wid + b[1].wid < c) {
_frmergebox(f, nb);
n1--;
b = &f->box[nb];
}
_fradvance(f, &pt, &f->box[nb]);
}
for (; nb < f->nbox; nb++) {
b = &f->box[nb];
_frcklinewrap(f, &pt, b);
_fradvance(f, &pt, &f->box[nb]);
}
f->lastlinefull = 0;
if (pt.y >= f->r.max.y)
f->lastlinefull = 1;
}

BIN
libframe/libframe.a Normal file

Binary file not shown.

37
libframe/mkfile Normal file
View file

@ -0,0 +1,37 @@
<$PLAN9/src/mkhdr
LIB=libframe.a
OFILES=\
frbox.$O\
frdelete.$O\
frdraw.$O\
frinit.$O\
frinsert.$O\
frptofchar.$O\
frselect.$O\
frstr.$O\
frutil.$O\
HFILES=\
$PLAN9/include/frame.h\
$PLAN9/include/draw.h\
default:V: ./$LIB
# ./$LIB: $OFILES
# $AR rsc ./$LIB $newprereq
./$LIB(%):N: %
./$LIB: ${OFILES:%=./$LIB(%)}
$AR rsc ./$LIB $newmember
&:n: &.$O
$AR rsc ./$LIB $stem.$O
all install:V: ./$LIB
NUKEFILES=$NUKEFILES ./$LIB
<$PLAN9/src/mkcommon

9
libframe/portdate Normal file
View file

@ -0,0 +1,9 @@
frbox.c 2004/1225
frdelete.c 2004/1225
frdraw.c 2004/1225
frinit.c 2004/1225
frinsert.c 2004/1225
frptofchar.c 2004/1225
frselect.c 2004/1225
frstr.c 2004/1225
frutil.c 2004/1225

5
mkfile
View file

@ -1,9 +1,10 @@
<$PLAN9/src/mkhdr
TARG=acme
DIRS=mail
DIRS=mail libframe
OFILES=\
libframe/frinit.$O\
acme.$O\
addr.$O\
buff.$O\
@ -35,6 +36,8 @@ HFILES=dat.h\
edit.$O ecmd.$O elog.$O: edit.h
LDFLAGS=-L./libframe -lframe $LDFLAGS
likeplan9:V:
mkdir -p likeplan9
rm -f likeplan9/*

20
text.c
View file

@ -33,10 +33,23 @@ void textinit(Text* t, File* f, Rectangle r, Reffont* rf, Image* cols[NCOL]) {
t->reffont = rf;
t->tabstop = maxtab;
memmove(t->fr.cols, cols, sizeof t->fr.cols);
textredraw(t, r, rf->f, screen, -1);
textredraw(t, r, rf->f, screen, -1, 0);
}
void textredraw(Text* t, Rectangle r, Font* f, Image* b, int odx) {
void textdrawactive(Text* t, int active) {
Image* b;
Rectangle br;
b = t->fr.cols[BACK];
if (active)
b = t->fr.cols[HIGH];
br.min = t->scrollr.max;
br.max.x = br.min.x + 1;
br.max.y = br.min.y + Dy(t->all);
draw(screen, br, b, nil, b->r.min);
}
void textredraw(Text* t, Rectangle r, Font* f, Image* b, int odx, int active) {
int maxt;
Rectangle rr;
@ -64,6 +77,7 @@ void textredraw(Text* t, Rectangle r, Font* f, Image* b, int odx) {
textfill(t);
textsetselect(t, t->q0, t->q1);
}
/*textdrawactive(t, active);*/
}
int textresize(Text* t, Rectangle r, int keepextra) {
@ -80,7 +94,7 @@ int textresize(Text* t, Rectangle r, int keepextra) {
t->lastsr = nullrect;
r.min.x += Scrollwid + Scrollgap;
frclear(&t->fr, 0);
textredraw(t, r, t->fr.font, t->fr.b, odx);
textredraw(t, r, t->fr.font, t->fr.b, odx, 0);
if (keepextra && t->fr.r.max.y < t->all.max.y && !t->fr.noredraw) {
/* draw background in bottom fringe of window */
r.min.x -= Scrollgap;

33
wind.c
View file

@ -89,6 +89,35 @@ void wininit(Window* w, Window* clone, Rectangle r) {
}
}
void windrawideco(Window* active, Column** allcols, int ncol) {
Window* wptr;
Column* cptr;
int wcnt, ccnt;
for (ccnt = 0; ccnt < ncol; ccnt++) {
cptr = allcols[ccnt];
for (wcnt = 0; wcnt < cptr->nw; wcnt++) {
wptr = cptr->w[wcnt];
winlock(wptr, 'M');
textredraw(
&wptr->tag,
wptr->tag.scrollr,
wptr->tag.fr.font,
screen,
-1,
wptr->id == active->id);
textredraw(
&wptr->body,
wptr->body.scrollr,
wptr->body.fr.font,
screen,
-1,
wptr->id == active->id);
winunlock(wptr);
}
}
}
/*
* Draw the appropriate button.
*/
@ -573,8 +602,10 @@ void wincommit(Window* w, Text* t) {
if (f->ntext > 1)
for (i = 0; i < f->ntext; i++)
textcommit(f->text[i], FALSE); /* no-op for t */
if (t->what == Body)
if (t->what == Body) {
winresize(w, w->r, TRUE, TRUE);
return;
}
r = parsetag(w, 0, &i);
if (runeeq(r, i, w->body.file->name, w->body.file->nname) == FALSE) {
seq++;