/*************************************************************************
* This program is copyright (C) 1985, 1986 by Jonathan Payne. It is *
* provided to you without charge for use only on a licensed Unix *
* system. You may copy JOVE provided that this notice is included with *
* the copy. You may not sell copies of this program or versions *
* modified for use on microcomputer systems, unless the copies are *
* included with a Unix system distribution and the source is provided. *
*************************************************************************/
/* This creates/deletes/divides/grows/shrinks windows. */
static char onlyone
[] = "You only have one window!",
toosmall
[] = "Resulting window would be too small.";
/* First line in a Window */
register Window
*wp
= fwind
;
register int lineno
= -1;
/* Delete `wp' from the screen. If it is the only window left
on the screen, then complain. It gives its body
to the next window if there is one, otherwise the previous
register Window
*prev
= wp
->w_prev
;
wp
->w_prev
->w_next
= wp
->w_next
;
wp
->w_next
->w_prev
= wp
->w_prev
;
fwind
->w_height
+= wp
->w_height
;
/* Here try to do something intelligent for redisplay() */
SetTop(fwind
, prev_line(fwind
->w_top
, wp
->w_height
));
prev
->w_height
+= wp
->w_height
;
/* Divide the window WP N times, or at least once. Complains if WP is too
small to be split into that many pieces. It returns the new window. */
amt
= wp
->w_height
/ (n
+ 1);
new = (Window
*) emalloc(sizeof (Window
));
new->w_visspace
= new->w_numlines
= 0;
/* set the lines such that w_line is the center in
new->w_line
= wp
->w_line
;
new->w_char
= wp
->w_char
;
new->w_bufp
= wp
->w_bufp
;
new->w_top
= prev_line(new->w_line
, HALF(new));
/* Link the new window into the list */
new->w_next
= wp
->w_next
;
new->w_next
->w_prev
= new;
/* Initialze the first window setting the bounds to the size of the
screen. There is no buffer with this window. See parse for the
setting of this window. */
w
= curwind
= fwind
= (Window
*) emalloc(sizeof (Window
));
w
->w_line
= w
->w_top
= 0;
w
->w_visspace
= w
->w_numlines
= 0;
w
->w_next
= w
->w_prev
= fwind
;
/* Change to previous window. */
register Window
*new = curwind
->w_prev
;
/* Make NEW the current Window */
if (!Asking
){ /* can you say kludge? */
curwind
->w_line
= curline
;
curwind
->w_char
= curchar
;
curwind
->w_bufp
= curbuf
;
if (!inlist(new->w_bufp
->b_first
, new->w_line
)) {
DotTo(new->w_line
, new->w_char
);
if (curchar
> strlen(linebuf
))
new->w_char
= curchar
= strlen(linebuf
);
/* Delete the current window if it isn't the only one left */
/* Put the current line of `w' in the middle of the window */
SetTop(w
, prev_line(w
->w_line
, HALF(w
)));
int ScrollStep
= 0; /* Full scrolling */
/* Calculate the new topline of the screen. If ScrollStep == 0
it means we should center the current line in the window. */
if (ScrollStep
== 0) /* Means just center it */
up
= inorder(w
->w_line
, 0, w
->w_top
, 0);
if (up
) /* Dot is above the screen */
newtop
= prev_line(w
->w_line
, min(ScrollStep
- 1, HALF(w
)));
newtop
= prev_line(w
->w_line
, (SIZE(w
) - 1) -
min(ScrollStep
- 1, HALF(w
)));
if (LineDist(newtop
, w
->w_top
) >= SIZE(w
) - 1)
register Buffer
*savebuf
= curbuf
;
ExecCmd((data_obj
*) FindCmd(FindTag
));
ExecCmd((data_obj
*) FindCmd(BufSelect
));
ExecCmd((data_obj
*) FindCmd(FindFile
));
complain("T: find-tag, F: find-file, B: select-buffer.");
(void) div_wind(curwind
, 1);
tiewind(curwind
->w_next
, curbuf
);
SetBuf(savebuf
); /* Back to original buffer */
SetDot(&savedot
); /* in original position */
tiewind(curwind
, curbuf
);
SetWind(curwind
->w_next
);
/* Go into one window mode by deleting all the other windows */
while (curwind
->w_next
!= curwind
)
del_wind(curwind
->w_next
);
register Window
*wp
= fwind
;
/* Look for a window containing a buffer whose name is `name' */
return windbp(buf_exists(name
));
/* Change window into the next window. Curwind becomes the new window. */
register Window
*new = curwind
->w_next
;
/* Scroll the next Window */
} while ((w
= w
->w_next
) != fwind
);
if (w
->w_bufp
->b_type
== type
)
} while ((w
= w
->w_next
) != fwind
);
/* Put a window with the buffer `name' in it. Erase the buffer if
`clobber' is non-zero. */
pop_wind(name
, clobber
, btype
)
if ((wp
= w_nam_typ(name
, btype
)) == 0) {
SetWind(div_wind(curwind
, 1));
newb
= do_select((Window
*) 0, name
);
if (newb
->b_type
!= B_IPROCESS
&& btype
!= -1)
WindSize(curwind
, abs(exp
));
WindSize(curwind
, -abs(exp
));
/* Change the size of the window by inc. First arg is the window,
second is the increment. */
else if (inc
< 0) { /* Shrinking this Window. */
if (w
->w_height
+ inc
< 2)
w
->w_prev
->w_height
-= inc
;
} else /* Growing the window. */
WindSize(w
->w_next
, -inc
);
/* Set the topline of the window, calculating its number in the buffer.
This is for numbering the lines only. */
register Line
*lp
= w
->w_bufp
->b_first
;
curwind
->w_numlines
= !curwind
->w_numlines
;
SetTop(curwind
, curwind
->w_top
);
curwind
->w_visspace
= !curwind
->w_visspace
;
/* Return the line number that `line' occupies in `windes' */
register Line
*top
= windes
->w_top
;
for (i
= 0; top
&& i
< windes
->w_height
- 1; i
++, top
= top
->l_next
)
return FLine(windes
) + i
;
SetWind(div_wind(curwind
, exp_p
? (exp
- 1) : 1));