From 1b7296dc5fb2dfc5ebf4a9841f3e4aec320c5178 Mon Sep 17 00:00:00 2001 From: Emanuele Giaquinta Date: Fri, 12 Dec 2008 10:42:14 +0000 Subject: [PATCH] Revert r4964, at least one script uses ypos. git-svn-id: file:///var/www/svn.irssi.org/SVN/irssi/trunk@4965 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/fe-text/textbuffer-view.c | 42 ++++++++++++++++++++++++++--------- src/fe-text/textbuffer-view.h | 1 + src/perl/textui/TextUI.xs | 2 ++ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/fe-text/textbuffer-view.c b/src/fe-text/textbuffer-view.c index b5f702fd..9960911c 100644 --- a/src/fe-text/textbuffer-view.c +++ b/src/fe-text/textbuffer-view.c @@ -37,10 +37,8 @@ typedef struct { static int linecache_tag; static GSList *views; -static int view_is_bottom(TEXT_BUFFER_VIEW_REC *view) -{ - return view->startline == view->bottom_startline; -} +#define view_is_bottom(view) \ + ((view)->ypos >= -1 && (view)->ypos < (view)->height) #define view_get_linecount(view, line) \ textbuffer_view_get_line_cache(view, line)->count @@ -519,6 +517,17 @@ static void textbuffer_view_init_bottom(TEXT_BUFFER_VIEW_REC *view) view->empty_linecount = view->height - total; } +static void textbuffer_view_init_ypos(TEXT_BUFFER_VIEW_REC *view) +{ + LINE_REC *line; + + g_return_if_fail(view != NULL); + + view->ypos = -view->subline-1; + for (line = view->startline; line != NULL; line = line->next) + view->ypos += view_get_linecount(view, line); +} + /* Create new view. */ TEXT_BUFFER_VIEW_REC *textbuffer_view_create(TEXT_BUFFER_REC *buffer, int width, int height, @@ -545,6 +554,8 @@ TEXT_BUFFER_VIEW_REC *textbuffer_view_create(TEXT_BUFFER_REC *buffer, view->subline = view->bottom_subline; view->bottom = TRUE; + textbuffer_view_init_ypos(view); + view->bookmarks = g_hash_table_new((GHashFunc) g_str_hash, (GCompareFunc) g_str_equal); @@ -836,6 +847,7 @@ void textbuffer_view_resize(TEXT_BUFFER_VIEW_REC *view, int width, int height) view->subline = linecount; } + textbuffer_view_init_ypos(view); if (view->bottom && !view_is_bottom(view)) { /* we scrolled to far up, need to get down. go right over the empty lines if there's any */ @@ -845,6 +857,7 @@ void textbuffer_view_resize(TEXT_BUFFER_VIEW_REC *view, int width, int height) view_scroll(view, &view->startline, &view->subline, -view->empty_linecount, FALSE); } + textbuffer_view_init_ypos(view); } view->bottom = view_is_bottom(view); @@ -865,6 +878,7 @@ void textbuffer_view_clear(TEXT_BUFFER_VIEW_REC *view) { g_return_if_fail(view != NULL); + view->ypos = -1; view->bottom_startline = view->startline = textbuffer_line_last(view->buffer); view->bottom_subline = view->subline = @@ -886,6 +900,7 @@ void textbuffer_view_scroll(TEXT_BUFFER_VIEW_REC *view, int lines) count = view_scroll(view, &view->startline, &view->subline, lines, TRUE); + view->ypos += lines < 0 ? count : -count; view->bottom = view_is_bottom(view); if (view->bottom) view->more_text = FALSE; @@ -906,6 +921,7 @@ void textbuffer_view_scroll_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line) view->subline = 0; } + textbuffer_view_init_ypos(view); view->bottom = view_is_bottom(view); if (view->bottom) view->more_text = FALSE; @@ -946,9 +962,8 @@ static void view_insert_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line) !textbuffer_line_exists_after(view->bottom_startline, line)) return; - ypos = view->height - view->empty_linecount - 1; linecount = view->cache->last_linecount; - ypos += linecount; + view->ypos += linecount; if (view->empty_linecount > 0) { view->empty_linecount -= linecount; if (view->empty_linecount >= 0) @@ -965,17 +980,17 @@ static void view_insert_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line) } if (view->bottom) { - if (view->scroll && ypos >= view->height) { - linecount = ypos-view->height+1; + if (view->scroll && view->ypos >= view->height) { + linecount = view->ypos-view->height+1; view_scroll(view, &view->startline, &view->subline, linecount, FALSE); - ypos -= linecount; + view->ypos -= linecount; } else { view->bottom = view_is_bottom(view); } if (view->window != NULL) { - ypos = ypos+1 - view->cache->last_linecount; + ypos = view->ypos+1 - view->cache->last_linecount; if (ypos >= 0) subline = 0; else { @@ -1087,6 +1102,12 @@ static void view_remove_line_update_startline(TEXT_BUFFER_VIEW_REC *view, &view->subline, -scroll, FALSE); } } + + /* FIXME: this is slow and unnecessary, but it's easy and + really works :) */ + textbuffer_view_init_ypos(view); + if (textbuffer_line_exists_after(view->startline, line)) + view->ypos -= linecount; } static void view_remove_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line, @@ -1122,6 +1143,7 @@ static void view_remove_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line, realcount = view_scroll(view, &view->startline, &view->subline, linecount, FALSE); + view->ypos -= realcount; view->empty_linecount += linecount-realcount; if (is_last == 1) view->startline = NULL; diff --git a/src/fe-text/textbuffer-view.h b/src/fe-text/textbuffer-view.h index ba0b5af5..46da808e 100644 --- a/src/fe-text/textbuffer-view.h +++ b/src/fe-text/textbuffer-view.h @@ -58,6 +58,7 @@ struct _TEXT_BUFFER_VIEW_REC { unsigned int utf8:1; /* use UTF8 in this view */ TEXT_BUFFER_CACHE_REC *cache; + int ypos; /* cursor position - visible area is 0..height-1 */ LINE_REC *startline; /* line at the top of the screen */ int subline; /* number of "real lines" to skip from `startline' */ diff --git a/src/perl/textui/TextUI.xs b/src/perl/textui/TextUI.xs index 6dbbc959..67c4c87b 100644 --- a/src/perl/textui/TextUI.xs +++ b/src/perl/textui/TextUI.xs @@ -35,6 +35,8 @@ static void perl_text_buffer_view_fill_hash(HV *hv, TEXT_BUFFER_VIEW_REC *view) hv_store(hv, "longword_noindent", 17, newSViv(view->longword_noindent), 0); hv_store(hv, "scroll", 6, newSViv(view->scroll), 0); + hv_store(hv, "ypos", 4, newSViv(view->ypos), 0); + hv_store(hv, "startline", 9, plain_bless(view->startline, "Irssi::TextUI::Line"), 0); hv_store(hv, "subline", 7, newSViv(view->subline), 0);