add bigtags

This commit is contained in:
rsc 2005-12-16 15:14:14 +00:00
parent 20ae0b0fc2
commit f8dea3c178
5 changed files with 96 additions and 2 deletions

View file

@ -591,7 +591,11 @@ mousethread(void *v)
goto Continue; goto Continue;
} }
/* scroll buttons, wheels, etc. */ /* scroll buttons, wheels, etc. */
if(t->what==Body && w != nil && (m.buttons & (8|16))){ /*
* TAG used to require t->what==Body but now allow
* scroll wheel in tag too.
*/
if(w != nil && (m.buttons & (8|16))){
if(m.buttons & 8) if(m.buttons & 8)
but = Kscrolloneup; but = Kscrolloneup;
else else

View file

@ -467,6 +467,9 @@ coldragwin(Column *c, Window *w, int but)
error("can't find window"); error("can't find window");
Found: Found:
/* TAG - force recompute tag size (if in auto-expand mode) on mouse op. */
w->taglines = 1;
/* END TAG */
p = mouse->xy; p = mouse->xy;
if(abs(p.x-op.x)<5 && abs(p.y-op.y)<5){ if(abs(p.x-op.x)<5 && abs(p.y-op.y)<5){
colgrow(c, w, but); colgrow(c, w, but);

View file

@ -282,6 +282,17 @@ rowtype(Row *row, Rune r, Point p)
else{ else{
winlock(w, 'K'); winlock(w, 'K');
wintype(w, t, r); wintype(w, t, r);
/*
* TAG If we typed in the tag, might need to make it
* bigger to show text. \n causes tag to expand.
*/
if(t->what == Tag){
t->w->tagsafe = FALSE;
if(r == '\n')
t->w->tagexpand = TRUE;
winresize(w, w->r, TRUE, TRUE);
}
/* END TAG */
winunlock(w); winunlock(w);
} }
} }

View file

@ -646,11 +646,21 @@ texttype(Text *t, Rune r)
uint q0, q1; uint q0, q1;
int nnb, nb, n, i; int nnb, nb, n, i;
int nr; int nr;
Point p;
Rune *rp; Rune *rp;
Text *u; Text *u;
if(t->what!=Body && r=='\n') /*
* TAG
* Used to disallow \n in tag here.
* Also if typing in tag, mark that resize might be necessary.
*/
if(t->what!=Body && t->what!=Tag && r=='\n')
return; return;
if(t->what == Tag)
t->w->tagsafe = FALSE;
/* END TAG */
nr = 1; nr = 1;
rp = &r; rp = &r;
switch(r){ switch(r){
@ -667,9 +677,17 @@ texttype(Text *t, Rune r)
} }
return; return;
case Kdown: case Kdown:
/* TAG */
if(t->what == Tag)
goto Tagdown;
/* END TAG */
n = t->fr.maxlines/3; n = t->fr.maxlines/3;
goto case_Down; goto case_Down;
case Kscrollonedown: case Kscrollonedown:
/* TAG */
if(t->what == Tag)
goto Tagdown;
/* END TAG */
n = mousescrollsize(t->fr.maxlines); n = mousescrollsize(t->fr.maxlines);
if(n <= 0) if(n <= 0)
n = 1; n = 1;
@ -681,9 +699,17 @@ texttype(Text *t, Rune r)
textsetorigin(t, q0, TRUE); textsetorigin(t, q0, TRUE);
return; return;
case Kup: case Kup:
/* TAG */
if(t->what == Tag)
goto Tagup;
/* END TAG */
n = t->fr.maxlines/3; n = t->fr.maxlines/3;
goto case_Up; goto case_Up;
case Kscrolloneup: case Kscrolloneup:
/* TAG */
if(t->what == Tag)
goto Tagup;
/* END TAG */
n = mousescrollsize(t->fr.maxlines); n = mousescrollsize(t->fr.maxlines);
goto case_Up; goto case_Up;
case Kpgup: case Kpgup:
@ -715,6 +741,31 @@ texttype(Text *t, Rune r)
q0++; q0++;
textshow(t, q0, q0, TRUE); textshow(t, q0, q0, TRUE);
return; return;
/* TAG policy here */
Tagdown:
/* expand tag to show all text */
if(!t->w->tagexpand){
t->w->tagexpand = TRUE;
winresize(t->w, t->w->r, FALSE, TRUE);
}
return;
Tagup:
/* shrink tag to single line */
if(t->w->tagexpand){
t->w->tagexpand = FALSE;
t->w->taglines = 1;
/* move mouse to stay in tag */
p = mouse->xy;
if(ptinrect(p, t->w->tag.all)
&& !ptinrect(p, t->w->tagtop)){
p.y = t->w->tagtop.min.y + Dy(t->w->tagtop)/2;
moveto(mousectl, p);
}
winresize(t->w, t->w->r, FALSE, TRUE);
}
return;
/* END TAG */
} }
if(t->what == Body){ if(t->what == Body){
seq++; seq++;

View file

@ -100,17 +100,28 @@ wintaglines(Window *w, Rectangle r)
int n; int n;
Rune rune; Rune rune;
/* TAG policy here */
if(!w->tagexpand) if(!w->tagexpand)
return 1; return 1;
w->tag.fr.noredraw = 1; w->tag.fr.noredraw = 1;
textresize(&w->tag, r, TRUE); textresize(&w->tag, r, TRUE);
w->tag.fr.noredraw = 0; w->tag.fr.noredraw = 0;
/* can't use more than we have */
if(w->tag.fr.nlines >= w->tag.fr.maxlines) if(w->tag.fr.nlines >= w->tag.fr.maxlines)
return w->tag.fr.maxlines; return w->tag.fr.maxlines;
/* if tag ends with \n, include empty line at end for typing */
n = w->tag.fr.nlines; n = w->tag.fr.nlines;
bufread(&w->tag.file->b, w->tag.file->b.nc-1, &rune, 1); bufread(&w->tag.file->b, w->tag.file->b.nc-1, &rune, 1);
if(rune == '\n') if(rune == '\n')
n++; n++;
/* cannot magically shrink tag - would lose focus */
if(n < w->taglines)
n = w->taglines;
return n; return n;
} }
@ -125,6 +136,19 @@ if(0) fprint(2, "winresize %d %R safe=%d keep=%d h=%d\n", w->id, r, safe, keepex
w->tagtop = r; w->tagtop = r;
w->tagtop.max.y = r.min.y+font->height; w->tagtop.max.y = r.min.y+font->height;
/*
* TAG If necessary, recompute the number of lines that should
* be in the tag.
*/
r1 = r;
r1.max.y = min(r.max.y, r1.min.y + w->taglines*font->height);
y = r1.max.y;
if(1 || !safe || !w->tagsafe || !eqrect(w->tag.all, r1)){
w->taglines = wintaglines(w, r);
w->tagsafe = TRUE;
}
/* END TAG */
r1 = r; r1 = r;
r1.max.y = min(r.max.y, r1.min.y + w->taglines*font->height); r1.max.y = min(r.max.y, r1.min.y + w->taglines*font->height);
y = r1.max.y; y = r1.max.y;
@ -142,6 +166,7 @@ if(0) fprint(2, "=> %R (%R)\n", w->tag.all, w->tag.fr.r);
draw(screen, br, b, nil, b->r.min); draw(screen, br, b, nil, b->r.min);
} }
r1 = r; r1 = r;
r1.min.y = y; r1.min.y = y;
if(1 || !safe || !eqrect(w->body.all, r1)){ if(1 || !safe || !eqrect(w->body.all, r1)){