/* ARGSUSED */ int delwind(int f, int n) { struct mgwin *wp, *nwp; wp = curwp; /* Cheap... */ /* shrinkwind returning false means only one window... */ if (shrinkwind(FFRAND, wp->w_ntrows + 1) == FALSE) return (FALSE); if (--wp->w_bufp->b_nwnd == 0) { wp->w_bufp->b_dotp = wp->w_dotp; wp->w_bufp->b_doto = wp->w_doto; wp->w_bufp->b_markp = wp->w_markp; wp->w_bufp->b_marko = wp->w_marko; wp->w_bufp->b_dotline = wp->w_dotline; wp->w_bufp->b_markline = wp->w_markline; } /* since shrinkwind did't crap out, we know we have a second window */ if (wp == wheadp) wheadp = curwp = wp->w_wndp; else if ((curwp = wp->w_wndp) == NULL) curwp = wheadp; curbp = curwp->w_bufp; for (nwp = wheadp; nwp != NULL; nwp = nwp->w_wndp) if (nwp->w_wndp == wp) { nwp->w_wndp = wp->w_wndp; break; } free(wp); return (TRUE); }
/*ARGSUSED*/ enlargewind(f, n) { register WINDOW *adjwp; register LINE *lp; register int i; if (n < 0) return shrinkwind(f, -n); if (wheadp->w_wndp == NULL) { ewprintf("Only one window"); return FALSE; } if ((adjwp=curwp->w_wndp) == NULL) { adjwp = wheadp; while (adjwp->w_wndp != curwp) adjwp = adjwp->w_wndp; } if (adjwp->w_ntrows <= n) { ewprintf("Impossible change"); return FALSE; } if (curwp->w_wndp == adjwp) { /* Shrink below. */ lp = adjwp->w_linep; for (i=n+adjwp->w_lines; i>0 && lp!=adjwp->w_bufp->b_linep; ) { i -= countlines(lp); if (i < 0) break; lp = lforw(lp); } if (i>0) i=countlines(lp)-1; /* LAST row */ if (i<0) i=countlines(lp)+i; adjwp->w_linep = lp; adjwp->w_lines = i; adjwp->w_toprow += n; } else { /* Shrink above. */ lp = curwp->w_linep; for (i=n-curwp->w_lines; i>0 && lback(lp)!=curbp->b_linep; ){ lp = lback(lp); i -= countlines(lp); } if (i>0) i= 0; if (i<0) i= -i; curwp->w_linep = lp; curwp->w_lines = i; curwp->w_toprow -= n; } curwp->w_ntrows += n; adjwp->w_ntrows -= n; curwp->w_flag |= WFMODE|WFHARD; adjwp->w_flag |= WFMODE|WFHARD; return TRUE; }
/* * Shrink a window by dragging the modeline */ static int adjust_window(WINDOW *wp, COORD * current, COORD * latest) { if (latest->Y == mode_row(wp)) { if (current->Y != latest->Y) { WINDOW *save_wp = curwp; set_curwp(wp); shrinkwind(FALSE, latest->Y - current->Y); set_curwp(save_wp); update(TRUE); } *latest = *current; return TRUE; } return FALSE; }
/* ARGSUSED */ int enlargewind(int f, int n) { struct mgwin *adjwp; struct line *lp; int i; if (n < 0) return (shrinkwind(f, -n)); if (wheadp->w_wndp == NULL) { dobeep(); ewprintf("Only one window"); return (FALSE); } if ((adjwp = curwp->w_wndp) == NULL) { adjwp = wheadp; while (adjwp->w_wndp != curwp) adjwp = adjwp->w_wndp; } if (adjwp->w_ntrows <= n) { dobeep(); ewprintf("Impossible change"); return (FALSE); } /* shrink below */ if (curwp->w_wndp == adjwp) { lp = adjwp->w_linep; for (i = 0; i < n && lp != adjwp->w_bufp->b_headp; ++i) lp = lforw(lp); adjwp->w_linep = lp; adjwp->w_toprow += n; /* shrink above */ } else { lp = curwp->w_linep; for (i = 0; i < n && lback(lp) != curbp->b_headp; ++i) lp = lback(lp); curwp->w_linep = lp; curwp->w_toprow -= n; } curwp->w_ntrows += n; adjwp->w_ntrows -= n; curwp->w_rflag |= WFMODE | WFFULL; adjwp->w_rflag |= WFMODE | WFFULL; return (TRUE); }
/* * Enlarge the current window. Find the window that loses space. Make sure it * is big enough. If so, hack the window descriptions, and ask redisplay to do * all the hard work. You don't just set "force reframe" because dot would * move. Bound to "C-X Z" */ int enlargewind(int f, int n) { WINDOW *adjwp; LINE *lp; int i; if (n < 0) return (shrinkwind(f, -n)); if (wheadp->w_wndp == NULL) { mlwrite("Only one window"); return (FALSE); } if ((adjwp = curwp->w_wndp) == NULL) { adjwp = wheadp; while (adjwp->w_wndp != curwp) adjwp = adjwp->w_wndp; } if (adjwp->w_ntrows <= n) { mlwrite("Impossible change"); return (FALSE); } if (curwp->w_wndp == adjwp) { /* Shrink below */ lp = adjwp->w_linep; for (i = 0; i < n && lp != adjwp->w_bufp->b_linep; ++i) lp = lforw(lp); adjwp->w_linep = lp; adjwp->w_toprow += n; } else { /* Shrink above */ lp = curwp->w_linep; for (i = 0; i < n && lback(lp) != curbp->b_linep; ++i) lp = lback(lp); curwp->w_linep = lp; curwp->w_toprow -= n; } curwp->w_ntrows += n; adjwp->w_ntrows -= n; curwp->w_flag |= WFMODE | WFHARD; adjwp->w_flag |= WFMODE | WFHARD; return (TRUE); }
/*ARGSUSED*/ delwind(f, n) { register WINDOW *wp, *nwp; wp = curwp; /* Cheap... */ /* shrinkwind returning false means only one window... */ if (shrinkwind(FFRAND, wp->w_ntrows + 1) == FALSE) return FALSE; if (--wp->w_bufp->b_nwnd == 0) { wp->w_bufp->b_dotp = wp->w_dotp; wp->w_bufp->b_doto = wp->w_doto; } /* since shrinkwind did't crap out, we know we have a second window */ if (wp == wheadp) wheadp = curwp = wp->w_wndp; else if ((curwp = wp->w_wndp) == NULL) curwp = wheadp; curbp = curwp->w_bufp; for (nwp = wheadp; nwp != NULL; nwp = nwp->w_wndp) if (nwp->w_wndp == wp) { nwp->w_wndp = wp->w_wndp; break ; } free((char *) wp); return TRUE; }
/* * On button press, we get an explicit number (1,2,3), and on release we don't * really know which button, but assume it is the last-pressed button. */ int on_mouse_click(int button, int y, int x) { static int first_x, first_y, pending; WINDOW *this_wp, *that_wp; int status; if (button > 0) { if (valid_window(this_wp = row2window(y)) && (y != mode_row(this_wp))) { /* * If we get a click on the "<" marking the left side * of a shifted window, force the screen right. This * makes it more consistent if there's a tab. */ if (w_val(this_wp, WVAL_SIDEWAYS) && x == 0) { mvleftwind(FALSE, 1); } if (!doingsweep) { if (button == BTN_EXTEND) { first_x = offs2col(this_wp, this_wp->w_dot.l, this_wp->w_dot.o); first_y = line_no(this_wp->w_bufp, this_wp->w_dot.l) - line_no(this_wp->w_bufp, this_wp->w_line.l); } else { first_x = x; first_y = y; } } status = setcursor(y, x); /* * Check for button1-down while we're in multimotion * sweep, so we can suppress highlighting extension. */ if (button != BTN_EXTEND && status == TRUE && doingsweep) { status = SORTOFTRUE; if (button == BTN_BEGIN) { first_x = x; first_y = y; } } } else { /* pressed button on modeline */ status = SORTOFTRUE; first_x = x; first_y = y; } pending = button; } else if (pending) { button = pending; pending = FALSE; this_wp = row2window(y); that_wp = row2window(first_y); if (this_wp == 0 || that_wp == 0 || reading_msg_line) { TRACE(("MOUSE cannot move msg-line\n")); status = FALSE; } else if (insertmode && (this_wp != curwp || that_wp != curwp)) { TRACE(("MOUSE cannot move from window while inserting\n")); kbd_alarm(); status = ABORT; } else if (first_y == mode_row(that_wp)) { /* drag modeline? */ if (first_y == y) { sel_release(); status = SEL_RELEASE; } else { WINDOW *save_wp = curwp; TRACE(("MOUSE dragging modeline\n")); set_curwp(that_wp); status = shrinkwind(FALSE, first_y - y); set_curwp(save_wp); } } else if (y != first_y || x != first_x) { /* drag selection */ if (button == BTN_PASTE) { (void) setcursor(y, x); status = paste_selection(); } else if (doingsweep) { switch (button) { case BTN_BEGIN: (void) release_selection(TRUE); status = setcursor(first_y, first_x); if (status == TRUE) { MK = DOT; status = SEL_BEGIN; TRACE(("MOUSE setting SEL_BEGIN MK %d.%d\n", line_no(curbp, MK.l), MK.o)); } break; default: (void) setcursor(y, x); status = SEL_EXTEND; TRACE(("MOUSE setting SEL_EXTEND DOT %d.%d MK %d.%d\n", line_no(curbp, MK.l), MK.o, line_no(curbp, DOT.l), DOT.o)); break; } } else { TRACE(("MOUSE begin multimotion on button%d-up\n", button)); if (button == BTN_EXTEND) { (void) setcursor(y, x); y = first_y; x = first_x; } do_sweep(SORTOFTRUE); (void) sel_begin(); (void) sel_setshape(rgn_EXACT); (void) setcursor(y, x); status = multimotion(TRUE, 1); TRACE(("MOUSE end multimotion after button%d-up\n", button)); if (status == SEL_PASTE) status = paste_selection(); } } else { /* position the cursor */ TRACE(("MOUSE button %d position cursor\n", button)); (void) setcursor(y, x); switch (button) { case BTN_BEGIN: status = SEL_FINISH; break; case BTN_PASTE: status = paste_selection(); break; default: status = release_selection(TRUE); break; } } } else { TRACE(("MOUSE ignored (illegal state)\n")); status = FALSE; } if (status == TRUE || status >= SORTOFTRUE) (void) update(TRUE); TRACE(("MOUSE status:%d\n", status)); return status; }