text buffer fixes

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@247 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-05-28 22:53:35 +00:00 committed by cras
commit 8c06612a28
2 changed files with 57 additions and 27 deletions

View file

@ -82,6 +82,9 @@ static TEXT_CHUNK_REC *create_text_chunk(GUI_WINDOW_REC *gui)
ptr = rec->buffer; ptr = rec->buffer;
memcpy(buffer, &ptr, sizeof(char *)); memcpy(buffer, &ptr, sizeof(char *));
} else {
/* just to be safe */
mark_temp_eol(rec);
} }
gui->cur_text = rec; gui->cur_text = rec;

View file

@ -36,6 +36,8 @@
#define DEFAULT_INDENT_POS 10 #define DEFAULT_INDENT_POS 10
#define DEBUG_TEXTBUFFER
static int window_create_override; static int window_create_override;
static GUI_WINDOW_REC *gui_window_init(WINDOW_REC *window, MAIN_WINDOW_REC *parent) static GUI_WINDOW_REC *gui_window_init(WINDOW_REC *window, MAIN_WINDOW_REC *parent)
@ -178,34 +180,58 @@ static int gui_window_update_bottom(GUI_WINDOW_REC *gui, int lines)
return last_linecount; return last_linecount;
} }
#define is_window_bottom(gui) \
((gui)->ypos >= -1 && (gui)->ypos <= (gui)->parent->last_line-(gui)->parent->first_line)
/*FIXME: remove ((gui)->startline == (gui)->bottom_startline && \
(gui)->subline >= (gui)->bottom_subline)*/
void gui_window_newline(GUI_WINDOW_REC *gui, int visible) void gui_window_newline(GUI_WINDOW_REC *gui, int visible)
{ {
/* FIXME: I'm pretty sure this could be done cleaner :) */
int lines; int lines;
g_return_if_fail(gui != NULL); g_return_if_fail(gui != NULL);
gui->xpos = 0; gui->xpos = 0;
lines = gui_window_get_linecount(gui, gui->bottom_startline->data);
if (gui->bottom_subline >= lines) {
/* after screen gets full after /CLEAR we end up here.. */
gui->bottom_startline = gui->bottom_startline->next;
gui->bottom_subline = 0;
}
lines = gui_window_get_linecount(gui, gui->startline->data);
if (gui->subline >= lines) {
/* after screen gets full after /CLEAR we end up here.. */
gui->startline = gui->startline->next;
gui->subline = 0;
}
if (gui->empty_linecount > 0) { if (gui->empty_linecount > 0) {
/* window buffer height isn't even the size of the screen yet */ /* window buffer height isn't even the size of the screen yet */
gui->empty_linecount--; gui->empty_linecount--;
if (!gui->bottom) {
gui->ypos++;
return;
}
}
if ((gui)->ypos >= -1 && (gui)->ypos <= (gui)->parent->last_line-(gui)->parent->first_line-1) {
gui->ypos++; gui->ypos++;
return; return;
} }
if (!gui->bottom || ((gui)->startline == (gui)->bottom_startline && \
(gui)->subline >= (gui)->bottom_subline)) {
lines = gui_window_update_bottom(gui, 1); lines = gui_window_update_bottom(gui, 1);
if (!gui->bottom) { if (!gui->bottom) {
gui->ypos++; gui->ypos++;
return; return;
} }
} else {
if (gui->subline >= lines) { lines = gui_window_get_linecount(gui, gui->startline->data);
/* after screen gets full after /CLEAR we end up here.. */
gui->startline = gui->startline->next;
gui->subline = 0;
lines = gui_window_update_bottom(gui, 1);
} }
if (lines > 1+gui->subline) if (lines > 1+gui->subline)
@ -219,6 +245,13 @@ void gui_window_newline(GUI_WINDOW_REC *gui, int visible)
scroll_up(gui->parent->first_line, gui->parent->last_line); scroll_up(gui->parent->first_line, gui->parent->last_line);
move(gui->parent->last_line, 0); clrtoeol(); move(gui->parent->last_line, 0); clrtoeol();
} }
#ifdef DEBUG_TEXTBUFFER
if (gui->startline != gui->bottom_startline &&
g_list_find(gui->bottom_startline, gui->startline) != NULL) {
g_warning("startline > bottom_startline! SHOULDN'T HAPPEN!");
}
#endif
} }
static LINE_CACHE_REC *gui_window_line_cache(GUI_WINDOW_REC *gui, LINE_REC *line) static LINE_CACHE_REC *gui_window_line_cache(GUI_WINDOW_REC *gui, LINE_REC *line)
@ -257,7 +290,7 @@ static LINE_CACHE_REC *gui_window_line_cache(GUI_WINDOW_REC *gui, LINE_REC *line
color = (color & ATTR_UNDERLINE) | *ptr; color = (color & ATTR_UNDERLINE) | *ptr;
} else switch (*ptr) { } else switch (*ptr) {
case LINE_CMD_OVERFLOW: case LINE_CMD_OVERFLOW:
g_error("buffer overflow!"); g_error("buffer overflow! (cache)");
case LINE_CMD_UNDERLINE: case LINE_CMD_UNDERLINE:
color ^= ATTR_UNDERLINE; color ^= ATTR_UNDERLINE;
break; break;
@ -380,7 +413,7 @@ static void single_line_draw(GUI_WINDOW_REC *gui, int ypos, LINE_CACHE_SUB_REC *
continue; continue;
} else switch ((unsigned char) *text) { } else switch ((unsigned char) *text) {
case LINE_CMD_OVERFLOW: case LINE_CMD_OVERFLOW:
g_error("buffer overflow!"); g_error("buffer overflow! (draw)");
case LINE_CMD_EOL: case LINE_CMD_EOL:
return; return;
case LINE_CMD_UNDERLINE: case LINE_CMD_UNDERLINE:
@ -474,10 +507,6 @@ void gui_window_redraw(WINDOW_REC *window)
screen_refresh(); screen_refresh();
} }
#define is_window_bottom(gui) \
((gui)->startline == (gui)->bottom_startline && \
(gui)->subline >= (gui)->bottom_subline)
static void gui_window_scroll_up(GUI_WINDOW_REC *gui, int lines) static void gui_window_scroll_up(GUI_WINDOW_REC *gui, int lines)
{ {
LINE_REC *line; LINE_REC *line;
@ -511,7 +540,8 @@ static void gui_window_scroll_down(GUI_WINDOW_REC *gui, int lines)
LINE_REC *line; LINE_REC *line;
int count, linecount; int count, linecount;
if (is_window_bottom(gui)) if (((gui)->startline == (gui)->bottom_startline && \
(gui)->subline >= (gui)->bottom_subline))
return; return;
count = lines+gui->subline; gui->ypos += gui->subline; count = lines+gui->subline; gui->ypos += gui->subline;
@ -534,6 +564,10 @@ static void gui_window_scroll_down(GUI_WINDOW_REC *gui, int lines)
} }
if (count == 0) { if (count == 0) {
if (gui->startline->next == NULL) {
gui->subline = linecount;
break;
}
gui->startline = gui->startline->next; gui->startline = gui->startline->next;
break; break;
} }
@ -544,10 +578,6 @@ static void gui_window_scroll_down(GUI_WINDOW_REC *gui, int lines)
break; break;
} }
if (gui->startline->next == NULL) {
gui->subline = linecount;
break;
}
gui->startline = gui->startline->next; gui->startline = gui->startline->next;
} }
@ -683,7 +713,7 @@ GList *gui_window_find_text(WINDOW_REC *window, gchar *text, GList *startline, i
else if ((guchar) *ptr == LINE_CMD_EOL) else if ((guchar) *ptr == LINE_CMD_EOL)
break; break;
else if ((guchar) *ptr == LINE_CMD_OVERFLOW) else if ((guchar) *ptr == LINE_CMD_OVERFLOW)
g_error("buffer overflow!"); g_error("buffer overflow! (find)");
} }
} }
str[n] = '\0'; str[n] = '\0';
@ -726,11 +756,8 @@ static void gui_window_horiz_resize(WINDOW_REC *window)
gui->bottom_startline = gui->startline; gui->bottom_startline = gui->startline;
gui->bottom_subline = gui->subline; gui->bottom_subline = gui->subline;
/* remove the empty lines from the end */ gui->bottom = TRUE;
if (gui->bottom && gui->startline == gui->lines) gui->empty_linecount = (gui->parent->last_line-gui->parent->first_line)-gui->ypos;
gui->empty_linecount = (gui->parent->last_line-gui->parent->first_line);
else
gui->empty_linecount = 0;
} }
void gui_window_resize(WINDOW_REC *window, int ychange, int xchange) void gui_window_resize(WINDOW_REC *window, int ychange, int xchange)