Exemplo n.º 1
0
/* EXTPROTO */
int
rxvt_scrollbar_update (rxvt_t* r, int update)
{
    int		 ret = 0;
    int		 top, bot, len, adj;

    if (!rxvt_scrollbar_visible(r))
	return 0;

    if (update) {
	/* first line in the view */
	top = (AVTS(r)->nscrolled - AVTS(r)->view_start);
	/* last line in the view */
	bot = top + (r->TermWin.nrow - 1);
	/* total lines in scroll and view */
	len = max((AVTS(r)->nscrolled + (r->TermWin.nrow - 1)), 1);
	adj = (((bot - top) * scrollbar_size()) % len) > 0 ? 1 : 0;

	/*
	** scrollBar.beg  : beginning of scrollbar, always 0
	** scrollBar.end  : end of scrollbar excluding buttons
	** scrollbar_size : scrollbar length excluding minimal height
	**
	** scrollBar.top  : beginning of scroller
	** scrollBar.bot  : end of scroller
	** scroller_len  : length of scroller
	*/
	r->scrollBar.top = (r->scrollBar.beg + (top * scrollbar_size()) / len);
	r->h->scroller_len = ((bot - top) * scrollbar_size()) / len +
				scrollbar_minheight() + adj;
	r->scrollBar.bot = (r->scrollBar.top + r->h->scroller_len);

	/* no change */
	if (r->scrollBar.top == r->h->last_top &&
	    r->scrollBar.bot == r->h->last_bot &&
	    (r->scrollBar.state == r->h->last_state ||
	     !scrollbar_isUpDn()))
	    return 0;
    }

    ret = r->scrollBar.update(r, update, r->h->last_top, r->h->last_bot,
		    r->h->scroller_len);

    r->h->last_top = r->scrollBar.top;
    r->h->last_bot = r->scrollBar.bot;
    r->h->last_state = r->scrollBar.state;

    return ret;
}
Exemplo n.º 2
0
/* EXTPROTO */
int
rxvt_scrollbar_show(rxvt_t *r, int update)
{
    int             ret = 0;
#ifdef HAVE_SCROLLBARS
    int             top, bot, len, adj;

    if (!scrollbar_visible(r))
	return 0;

    if (update) {
	top = (r->TermWin.nscrolled - r->TermWin.view_start);
	bot = top + (r->TermWin.nrow - 1);
	len = max((r->TermWin.nscrolled + (r->TermWin.nrow - 1)), 1);
	adj = (((bot - top) * scrollbar_size()) % len) > 0 ? 1 : 0;

	r->scrollBar.top = (r->scrollBar.beg + (top * scrollbar_size()) / len);
	r->h->scrollbar_len = ((bot - top) * scrollbar_size()) / len +
			      scrollbar_minheight() + adj;
	r->scrollBar.bot = (r->scrollBar.top + r->h->scrollbar_len);
	/* no change */
	if (r->scrollBar.top == r->h->last_top
	    && r->scrollBar.bot == r->h->last_bot
	    && (r->scrollBar.state == r->h->last_state || !scrollbar_isUpDn()))
	    return 0;
    }

    ret = r->scrollBar.update(r, update, r->h->last_top, r->h->last_bot,
			      r->h->scrollbar_len);

    r->h->last_top = r->scrollBar.top;
    r->h->last_bot = r->scrollBar.bot;
    r->h->last_state = r->scrollBar.state;

#endif
    return ret;
}