2001-04-14 18:24:56 -04:00
|
|
|
/*
|
|
|
|
textbuffer-view.c : Text buffer handling
|
|
|
|
|
|
|
|
Copyright (C) 1999-2001 Timo Sirainen
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2007-05-08 14:41:10 -04:00
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2001-04-14 18:24:56 -04:00
|
|
|
*/
|
|
|
|
|
2002-05-13 13:07:37 -04:00
|
|
|
#define G_LOG_DOMAIN "TextBufferView"
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
#include "module.h"
|
|
|
|
#include "textbuffer-view.h"
|
2002-01-28 20:33:41 -05:00
|
|
|
#include "utf8.h"
|
2001-04-14 18:24:56 -04:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char *name;
|
|
|
|
LINE_REC *line;
|
|
|
|
} BOOKMARK_REC;
|
|
|
|
|
|
|
|
/* how often to scan line cache for lines not accessed for a while (ms) */
|
|
|
|
#define LINE_CACHE_CHECK_TIME (5*60*1000)
|
|
|
|
/* how long to keep line cache in memory (seconds) */
|
|
|
|
#define LINE_CACHE_KEEP_TIME (10*60)
|
|
|
|
|
|
|
|
static int linecache_tag;
|
|
|
|
static GSList *views;
|
|
|
|
|
2008-12-12 05:42:14 -05:00
|
|
|
#define view_is_bottom(view) \
|
|
|
|
((view)->ypos >= -1 && (view)->ypos < (view)->height)
|
2001-04-14 18:24:56 -04:00
|
|
|
|
|
|
|
#define view_get_linecount(view, line) \
|
|
|
|
textbuffer_view_get_line_cache(view, line)->count
|
|
|
|
|
|
|
|
static GSList *textbuffer_get_views(TEXT_BUFFER_REC *buffer)
|
|
|
|
{
|
|
|
|
GSList *tmp, *list;
|
|
|
|
|
|
|
|
for (tmp = views; tmp != NULL; tmp = tmp->next) {
|
|
|
|
TEXT_BUFFER_VIEW_REC *view = tmp->data;
|
|
|
|
|
|
|
|
if (view->buffer == buffer) {
|
|
|
|
list = g_slist_copy(view->siblings);
|
|
|
|
return g_slist_prepend(list, view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static TEXT_BUFFER_CACHE_REC *
|
|
|
|
textbuffer_cache_get(GSList *views, int width)
|
|
|
|
{
|
|
|
|
TEXT_BUFFER_CACHE_REC *cache;
|
|
|
|
|
|
|
|
/* check if there's existing cache with correct width */
|
|
|
|
while (views != NULL) {
|
|
|
|
TEXT_BUFFER_VIEW_REC *view = views->data;
|
|
|
|
|
|
|
|
if (view->width == width) {
|
|
|
|
view->cache->refcount++;
|
|
|
|
return view->cache;
|
|
|
|
}
|
|
|
|
views = views->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create new cache */
|
|
|
|
cache = g_new0(TEXT_BUFFER_CACHE_REC, 1);
|
|
|
|
cache->refcount = 1;
|
|
|
|
cache->width = width;
|
|
|
|
cache->line_cache = g_hash_table_new((GHashFunc) g_direct_hash,
|
|
|
|
(GCompareFunc) g_direct_equal);
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int line_cache_destroy(void *key, LINE_CACHE_REC *cache)
|
|
|
|
{
|
|
|
|
g_free(cache);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void textbuffer_cache_destroy(TEXT_BUFFER_CACHE_REC *cache)
|
|
|
|
{
|
|
|
|
g_hash_table_foreach(cache->line_cache,
|
|
|
|
(GHFunc) line_cache_destroy, NULL);
|
|
|
|
g_hash_table_destroy(cache->line_cache);
|
|
|
|
g_free(cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void textbuffer_cache_unref(TEXT_BUFFER_CACHE_REC *cache)
|
|
|
|
{
|
|
|
|
if (--cache->refcount == 0)
|
|
|
|
textbuffer_cache_destroy(cache);
|
|
|
|
}
|
|
|
|
|
2014-01-09 09:20:29 -05:00
|
|
|
#define FGATTR (ATTR_NOCOLORS | ATTR_RESETFG | FG_MASK | ATTR_FGCOLOR24)
|
|
|
|
#define BGATTR (ATTR_NOCOLORS | ATTR_RESETBG | BG_MASK | ATTR_BGCOLOR24)
|
2001-10-28 06:30:26 -05:00
|
|
|
|
|
|
|
static void update_cmd_color(unsigned char cmd, int *color)
|
|
|
|
{
|
2014-01-09 09:20:29 -05:00
|
|
|
if ((cmd & 0x80) == 0) {
|
|
|
|
if (cmd & LINE_COLOR_BG) {
|
|
|
|
/* set background color */
|
|
|
|
*color &= FGATTR;
|
|
|
|
*color &= ~ATTR_FGCOLOR24;
|
|
|
|
if ((cmd & LINE_COLOR_DEFAULT) == 0)
|
|
|
|
*color |= (cmd & 0x0f) << BG_SHIFT;
|
|
|
|
else {
|
|
|
|
*color = (*color & FGATTR) | ATTR_RESETBG;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* set foreground color */
|
|
|
|
*color &= BGATTR;
|
|
|
|
*color &= ~ATTR_BGCOLOR24;
|
|
|
|
if ((cmd & LINE_COLOR_DEFAULT) == 0)
|
|
|
|
*color |= cmd & 0x0f;
|
|
|
|
else {
|
|
|
|
*color = (*color & BGATTR) | ATTR_RESETFG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else switch (cmd) {
|
2001-10-28 06:30:26 -05:00
|
|
|
case LINE_CMD_UNDERLINE:
|
|
|
|
*color ^= ATTR_UNDERLINE;
|
|
|
|
break;
|
|
|
|
case LINE_CMD_REVERSE:
|
|
|
|
*color ^= ATTR_REVERSE;
|
|
|
|
break;
|
2008-11-15 16:51:07 -05:00
|
|
|
case LINE_CMD_BLINK:
|
|
|
|
*color ^= ATTR_BLINK;
|
|
|
|
break;
|
|
|
|
case LINE_CMD_BOLD:
|
|
|
|
*color ^= ATTR_BOLD;
|
|
|
|
break;
|
2001-10-28 06:30:26 -05:00
|
|
|
case LINE_CMD_COLOR0:
|
|
|
|
*color &= BGATTR;
|
2014-01-09 09:20:29 -05:00
|
|
|
*color &= ~ATTR_FGCOLOR24;
|
2001-10-28 06:30:26 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 09:20:29 -05:00
|
|
|
#ifdef TERM_TRUECOLOR
|
|
|
|
static void unformat_24bit_line_color(const unsigned char **ptr, int off, int *flags, int *fg, int *bg)
|
|
|
|
{
|
|
|
|
unsigned int color;
|
|
|
|
unsigned char rgbx[4];
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < 4; ++i) {
|
|
|
|
rgbx[i] = (*ptr)[i + off];
|
|
|
|
}
|
|
|
|
rgbx[3] -= 0x20;
|
|
|
|
*ptr += 4;
|
|
|
|
for (i = 0; i < 3; ++i) {
|
|
|
|
if (rgbx[3] & (0x10 << i))
|
|
|
|
rgbx[i] -= 0x20;
|
|
|
|
}
|
|
|
|
color = rgbx[0] << 16 | rgbx[1] << 8 | rgbx[2];
|
|
|
|
if (rgbx[3] & 0x1) {
|
|
|
|
*flags = (*flags & FGATTR) | ATTR_BGCOLOR24;
|
|
|
|
*bg = color;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*flags = (*flags & BGATTR) | ATTR_FGCOLOR24;
|
|
|
|
*fg = color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-08 18:58:27 -04:00
|
|
|
static inline unichar read_unichar(const unsigned char *data, const unsigned char **next, int *width)
|
2008-03-09 14:08:40 -04:00
|
|
|
{
|
|
|
|
unichar chr = g_utf8_get_char_validated(data, -1);
|
|
|
|
|
|
|
|
if (chr & 0x80000000) {
|
2009-01-18 07:46:57 -05:00
|
|
|
chr = 0xfffd;
|
2008-03-09 14:08:40 -04:00
|
|
|
*next = data + 1;
|
|
|
|
*width = 1;
|
|
|
|
} else {
|
|
|
|
*next = g_utf8_next_char(data);
|
|
|
|
*width = unichar_isprint(chr) ? mk_wcwidth(chr) : 1;
|
|
|
|
}
|
|
|
|
return chr;
|
|
|
|
}
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
static LINE_CACHE_REC *
|
|
|
|
view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
|
|
|
|
{
|
2001-10-24 18:52:15 -04:00
|
|
|
INDENT_FUNC indent_func;
|
2001-04-14 18:24:56 -04:00
|
|
|
LINE_CACHE_REC *rec;
|
|
|
|
LINE_CACHE_SUB_REC *sub;
|
|
|
|
GSList *lines;
|
|
|
|
unsigned char cmd;
|
2002-10-14 14:33:29 -04:00
|
|
|
const unsigned char *ptr, *next_ptr, *last_space_ptr;
|
2001-04-14 18:24:56 -04:00
|
|
|
int xpos, pos, indent_pos, last_space, last_color, color, linecount;
|
2014-01-09 09:20:29 -05:00
|
|
|
int last_bg24, last_fg24, bg24, fg24;
|
2008-03-09 14:16:50 -04:00
|
|
|
int char_width;
|
2001-04-14 18:24:56 -04:00
|
|
|
|
|
|
|
g_return_val_if_fail(line->text != NULL, NULL);
|
|
|
|
|
2001-10-28 06:30:26 -05:00
|
|
|
color = ATTR_RESETFG | ATTR_RESETBG;
|
|
|
|
xpos = 0; indent_pos = view->default_indent;
|
2001-04-14 18:24:56 -04:00
|
|
|
last_space = last_color = 0; last_space_ptr = NULL; sub = NULL;
|
|
|
|
|
2001-10-24 18:52:15 -04:00
|
|
|
indent_func = view->default_indent_func;
|
2001-04-14 18:24:56 -04:00
|
|
|
linecount = 1;
|
|
|
|
lines = NULL;
|
|
|
|
for (ptr = line->text;;) {
|
|
|
|
if (*ptr == '\0') {
|
|
|
|
/* command */
|
|
|
|
ptr++;
|
|
|
|
cmd = *ptr;
|
|
|
|
ptr++;
|
|
|
|
|
2009-01-10 13:38:08 -05:00
|
|
|
if (cmd == LINE_CMD_EOL)
|
2001-04-14 18:24:56 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (cmd == LINE_CMD_CONTINUE) {
|
2002-02-01 15:14:30 -05:00
|
|
|
unsigned char *tmp;
|
2001-04-14 18:24:56 -04:00
|
|
|
|
|
|
|
memcpy(&tmp, ptr, sizeof(char *));
|
|
|
|
ptr = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-10-28 06:30:26 -05:00
|
|
|
if (cmd == LINE_CMD_INDENT) {
|
2001-04-14 18:24:56 -04:00
|
|
|
/* set indentation position here - don't do
|
|
|
|
it if we're too close to right border */
|
|
|
|
if (xpos < view->width-5) indent_pos = xpos;
|
2014-01-09 09:20:29 -05:00
|
|
|
} else if (cmd == LINE_COLOR_EXT) {
|
|
|
|
color &= ~ATTR_FGCOLOR24;
|
|
|
|
color = (color & BGATTR) | *ptr++;
|
|
|
|
} else if (cmd == LINE_COLOR_EXT_BG) {
|
|
|
|
color &= ~ATTR_BGCOLOR24;
|
|
|
|
color = (color & FGATTR) | (*ptr++ << BG_SHIFT);
|
|
|
|
}
|
|
|
|
#ifdef TERM_TRUECOLOR
|
|
|
|
else if (cmd == LINE_COLOR_24)
|
|
|
|
unformat_24bit_line_color(&ptr, 0, &color, &fg24, &bg24);
|
|
|
|
#endif
|
|
|
|
else
|
2001-10-28 06:30:26 -05:00
|
|
|
update_cmd_color(cmd, &color);
|
2001-04-14 18:24:56 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-10-14 14:33:29 -04:00
|
|
|
if (!view->utf8) {
|
2003-10-19 15:09:51 -04:00
|
|
|
/* MH */
|
2003-10-26 01:31:19 -04:00
|
|
|
if (term_type != TERM_TYPE_BIG5 ||
|
|
|
|
ptr[1] == '\0' || !is_big5(ptr[0], ptr[1]))
|
2008-03-09 14:16:50 -04:00
|
|
|
char_width = 1;
|
2003-10-19 15:09:51 -04:00
|
|
|
else
|
2008-03-09 14:16:50 -04:00
|
|
|
char_width = 2;
|
|
|
|
next_ptr = ptr+char_width;
|
2002-10-14 14:33:29 -04:00
|
|
|
} else {
|
2008-03-09 14:16:50 -04:00
|
|
|
read_unichar(ptr, &next_ptr, &char_width);
|
2002-10-14 14:33:29 -04:00
|
|
|
}
|
|
|
|
|
2008-03-09 14:16:50 -04:00
|
|
|
if (xpos + char_width > view->width && sub != NULL &&
|
2001-04-22 19:20:42 -04:00
|
|
|
(last_space <= indent_pos || last_space <= 10) &&
|
2001-10-28 16:17:34 -05:00
|
|
|
view->longword_noindent) {
|
2001-04-14 18:24:56 -04:00
|
|
|
/* long word, remove the indentation from this line */
|
|
|
|
xpos -= sub->indent;
|
|
|
|
sub->indent = 0;
|
|
|
|
}
|
|
|
|
|
2008-03-09 14:16:50 -04:00
|
|
|
if (xpos + char_width > view->width) {
|
2001-10-24 18:52:15 -04:00
|
|
|
xpos = indent_func == NULL ? indent_pos :
|
|
|
|
indent_func(view, line, -1);
|
2001-04-14 18:24:56 -04:00
|
|
|
|
|
|
|
sub = g_new0(LINE_CACHE_SUB_REC, 1);
|
|
|
|
if (last_space > indent_pos && last_space > 10) {
|
|
|
|
/* go back to last space */
|
2014-01-09 09:20:29 -05:00
|
|
|
color = last_color; fg24 = last_fg24; bg24 = last_bg24;
|
2001-04-14 18:24:56 -04:00
|
|
|
ptr = last_space_ptr;
|
|
|
|
while (*ptr == ' ') ptr++;
|
2001-10-28 16:17:34 -05:00
|
|
|
} else if (view->longword_noindent) {
|
2001-04-14 18:24:56 -04:00
|
|
|
/* long word, no indentation in next line */
|
|
|
|
xpos = 0;
|
|
|
|
sub->continues = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub->start = ptr;
|
|
|
|
sub->indent = xpos;
|
2001-10-24 18:52:15 -04:00
|
|
|
sub->indent_func = indent_func;
|
2001-04-14 18:24:56 -04:00
|
|
|
sub->color = color;
|
2014-01-09 09:20:29 -05:00
|
|
|
#ifdef TERM_TRUECOLOR
|
|
|
|
sub->fg24 = fg24; sub->bg24 = bg24;
|
|
|
|
#endif
|
2001-04-14 18:24:56 -04:00
|
|
|
|
|
|
|
lines = g_slist_append(lines, sub);
|
|
|
|
linecount++;
|
|
|
|
|
|
|
|
last_space = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-03-09 14:16:50 -04:00
|
|
|
if (!view->utf8 && char_width > 1) {
|
2003-10-19 15:09:51 -04:00
|
|
|
last_space = xpos;
|
|
|
|
last_space_ptr = next_ptr;
|
2014-01-09 09:20:29 -05:00
|
|
|
last_color = color; last_fg24 = fg24; last_bg24 = bg24;
|
2003-10-19 15:09:51 -04:00
|
|
|
} else if (*ptr == ' ') {
|
2002-10-14 14:33:29 -04:00
|
|
|
last_space = xpos;
|
2001-04-14 18:24:56 -04:00
|
|
|
last_space_ptr = ptr;
|
2014-01-09 09:20:29 -05:00
|
|
|
last_color = color; last_fg24 = fg24; last_bg24 = bg24;
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
2002-10-14 14:33:29 -04:00
|
|
|
|
2008-03-09 14:16:50 -04:00
|
|
|
xpos += char_width;
|
2002-10-14 14:33:29 -04:00
|
|
|
ptr = next_ptr;
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
rec = g_malloc(sizeof(LINE_CACHE_REC)-sizeof(LINE_CACHE_SUB_REC) +
|
|
|
|
sizeof(LINE_CACHE_SUB_REC) * (linecount-1));
|
|
|
|
rec->last_access = time(NULL);
|
|
|
|
rec->count = linecount;
|
|
|
|
|
|
|
|
if (rec->count > 1) {
|
|
|
|
for (pos = 0; lines != NULL; pos++) {
|
2002-12-10 15:30:03 -05:00
|
|
|
void *data = lines->data;
|
|
|
|
|
|
|
|
memcpy(&rec->lines[pos], data,
|
2001-04-14 18:24:56 -04:00
|
|
|
sizeof(LINE_CACHE_SUB_REC));
|
|
|
|
|
2002-12-10 15:30:03 -05:00
|
|
|
lines = g_slist_remove(lines, data);
|
|
|
|
g_free(data);
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_insert(view->cache->line_cache, line, rec);
|
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
2001-10-24 18:52:15 -04:00
|
|
|
static void view_remove_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
|
|
|
|
unsigned char update_counter)
|
|
|
|
{
|
|
|
|
LINE_CACHE_REC *cache;
|
|
|
|
|
|
|
|
if (view->cache->update_counter == update_counter)
|
|
|
|
return;
|
|
|
|
view->cache->update_counter = update_counter;
|
|
|
|
|
|
|
|
cache = g_hash_table_lookup(view->cache->line_cache, line);
|
|
|
|
if (cache != NULL) {
|
|
|
|
g_free(cache);
|
|
|
|
g_hash_table_remove(view->cache->line_cache, line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void view_update_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
|
|
|
|
unsigned char update_counter)
|
|
|
|
{
|
|
|
|
view_remove_cache(view, line, update_counter);
|
|
|
|
|
|
|
|
if (view->buffer->cur_line == line)
|
|
|
|
view->cache->last_linecount = view_get_linecount(view, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void view_reset_cache(TEXT_BUFFER_VIEW_REC *view)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
/* destroy line caches - note that you can't do simultaneously
|
|
|
|
unrefs + cache_get()s or it will keep using the old caches */
|
|
|
|
textbuffer_cache_unref(view->cache);
|
|
|
|
g_slist_foreach(view->siblings, (GFunc) textbuffer_cache_unref, NULL);
|
|
|
|
|
|
|
|
view->cache = textbuffer_cache_get(view->siblings, view->width);
|
|
|
|
for (tmp = view->siblings; tmp != NULL; tmp = tmp->next) {
|
|
|
|
TEXT_BUFFER_VIEW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
rec->cache = textbuffer_cache_get(rec->siblings, rec->width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
|
|
|
|
int subline, int ypos, int max)
|
|
|
|
{
|
2001-10-24 18:52:15 -04:00
|
|
|
INDENT_FUNC indent_func;
|
2001-04-14 18:24:56 -04:00
|
|
|
LINE_CACHE_REC *cache;
|
2002-10-14 14:33:29 -04:00
|
|
|
const unsigned char *text, *end, *text_newline;
|
2002-02-01 15:14:30 -05:00
|
|
|
unsigned char *tmp;
|
2007-02-20 07:39:17 -05:00
|
|
|
unichar chr;
|
2014-01-09 09:20:29 -05:00
|
|
|
int xpos, color, fg24, bg24, drawcount, first, need_move, need_clrtoeol, char_width;
|
2001-04-14 18:24:56 -04:00
|
|
|
|
2001-10-28 13:40:12 -05:00
|
|
|
if (view->dirty) /* don't bother drawing anything - redraw is coming */
|
|
|
|
return 0;
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
cache = textbuffer_view_get_line_cache(view, line);
|
|
|
|
if (subline >= cache->count)
|
|
|
|
return 0;
|
|
|
|
|
2001-11-15 16:01:38 -05:00
|
|
|
color = ATTR_RESET;
|
2001-10-28 16:17:34 -05:00
|
|
|
need_move = TRUE; need_clrtoeol = FALSE;
|
2001-11-15 16:01:38 -05:00
|
|
|
xpos = drawcount = 0; first = TRUE;
|
2001-04-14 18:24:56 -04:00
|
|
|
text_newline = text =
|
|
|
|
subline == 0 ? line->text : cache->lines[subline-1].start;
|
|
|
|
for (;;) {
|
|
|
|
if (text == text_newline) {
|
2001-11-03 07:54:29 -05:00
|
|
|
if (need_clrtoeol && xpos < term_width) {
|
2001-10-28 16:17:34 -05:00
|
|
|
term_set_color(view->window, ATTR_RESET);
|
|
|
|
term_clrtoeol(view->window);
|
|
|
|
}
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
if (first)
|
|
|
|
first = FALSE;
|
|
|
|
else {
|
|
|
|
ypos++;
|
|
|
|
if (--max == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-10-24 18:52:15 -04:00
|
|
|
if (subline > 0) {
|
2001-11-03 07:54:29 -05:00
|
|
|
/* continuing previous line - indent it */
|
|
|
|
indent_func = cache->lines[subline-1].indent_func;
|
2002-05-18 07:51:04 -04:00
|
|
|
if (indent_func == NULL)
|
|
|
|
xpos = cache->lines[subline-1].indent;
|
2001-10-24 18:52:15 -04:00
|
|
|
color = cache->lines[subline-1].color;
|
2014-01-09 09:20:29 -05:00
|
|
|
#ifdef TERM_TRUECOLOR
|
|
|
|
fg24 = cache->lines[subline-1].fg24;
|
|
|
|
bg24 = cache->lines[subline-1].bg24;
|
|
|
|
#endif
|
2002-05-18 07:51:04 -04:00
|
|
|
} else {
|
|
|
|
indent_func = NULL;
|
2001-10-24 18:52:15 -04:00
|
|
|
}
|
|
|
|
|
2002-05-18 07:51:04 -04:00
|
|
|
if (xpos == 0 && indent_func == NULL)
|
2001-11-03 07:54:29 -05:00
|
|
|
need_clrtoeol = TRUE;
|
|
|
|
else {
|
|
|
|
/* line was indented - need to clear the
|
|
|
|
indented area first */
|
|
|
|
term_set_color(view->window, ATTR_RESET);
|
|
|
|
term_move(view->window, 0, ypos);
|
|
|
|
term_clrtoeol(view->window);
|
2002-05-18 07:51:04 -04:00
|
|
|
|
|
|
|
if (indent_func != NULL)
|
|
|
|
xpos = indent_func(view, line, ypos);
|
2001-11-03 07:54:29 -05:00
|
|
|
}
|
2001-10-28 16:17:34 -05:00
|
|
|
|
2014-01-09 09:20:29 -05:00
|
|
|
if (need_move || xpos > 0)
|
2001-10-28 16:17:34 -05:00
|
|
|
term_move(view->window, xpos, ypos);
|
2001-11-03 07:54:29 -05:00
|
|
|
|
2014-01-09 09:20:29 -05:00
|
|
|
term_set_color2(view->window, color, fg24, bg24);
|
2001-04-14 18:24:56 -04:00
|
|
|
|
2001-11-01 17:30:45 -05:00
|
|
|
if (subline == cache->count-1) {
|
|
|
|
text_newline = NULL;
|
|
|
|
need_move = FALSE;
|
|
|
|
} else {
|
|
|
|
/* get the beginning of the next subline */
|
|
|
|
text_newline = cache->lines[subline].start;
|
|
|
|
need_move = !cache->lines[subline].continues;
|
|
|
|
}
|
2001-04-14 18:24:56 -04:00
|
|
|
drawcount++;
|
|
|
|
subline++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*text == '\0') {
|
|
|
|
/* command */
|
|
|
|
text++;
|
2009-01-10 13:38:08 -05:00
|
|
|
if (*text == LINE_CMD_EOL)
|
2001-04-14 18:24:56 -04:00
|
|
|
break;
|
|
|
|
|
2001-10-28 06:30:26 -05:00
|
|
|
if (*text == LINE_CMD_CONTINUE) {
|
2001-04-14 18:24:56 -04:00
|
|
|
/* jump to next block */
|
|
|
|
memcpy(&tmp, text+1, sizeof(unsigned char *));
|
|
|
|
text = tmp;
|
|
|
|
continue;
|
2001-10-28 06:30:26 -05:00
|
|
|
} else {
|
2014-01-09 09:20:29 -05:00
|
|
|
if (*text == LINE_COLOR_EXT)
|
|
|
|
color = (color & BGATTR & ~ATTR_FGCOLOR24) | *++text;
|
|
|
|
else if (*text == LINE_COLOR_EXT_BG)
|
|
|
|
color = (color & FGATTR & ~ATTR_BGCOLOR24) | (*++text << BG_SHIFT);
|
|
|
|
#ifdef TERM_TRUECOLOR
|
|
|
|
else if (*text == LINE_COLOR_24)
|
|
|
|
unformat_24bit_line_color(&text, 1, &color, &fg24, &bg24);
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
update_cmd_color(*text, &color);
|
|
|
|
term_set_color2(view->window, color, fg24, bg24);
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
text++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-10-14 14:33:29 -04:00
|
|
|
if (view->utf8) {
|
2008-03-09 14:08:40 -04:00
|
|
|
chr = read_unichar(text, &end, &char_width);
|
2002-10-14 14:33:29 -04:00
|
|
|
} else {
|
2008-03-09 14:08:40 -04:00
|
|
|
chr = *text;
|
|
|
|
end = text;
|
2004-03-24 12:28:55 -05:00
|
|
|
if (term_type == TERM_TYPE_BIG5 &&
|
|
|
|
is_big5(end[0], end[1]))
|
|
|
|
char_width = 2;
|
|
|
|
else
|
|
|
|
char_width = 1;
|
2008-04-21 16:44:04 -04:00
|
|
|
end += char_width;
|
2002-10-14 14:33:29 -04:00
|
|
|
}
|
2002-01-28 22:13:06 -05:00
|
|
|
|
2002-10-14 14:33:29 -04:00
|
|
|
xpos += char_width;
|
|
|
|
if (xpos <= term_width) {
|
2007-05-31 09:19:05 -04:00
|
|
|
if (unichar_isprint(chr)) {
|
2008-04-21 16:44:04 -04:00
|
|
|
if (view->utf8)
|
|
|
|
term_add_unichar(view->window, chr);
|
|
|
|
else
|
2002-01-28 22:13:06 -05:00
|
|
|
for (; text < end; text++)
|
|
|
|
term_addch(view->window, *text);
|
2002-01-28 20:33:41 -05:00
|
|
|
} else {
|
2001-11-18 09:28:04 -05:00
|
|
|
/* low-ascii */
|
|
|
|
term_set_color(view->window, ATTR_RESET|ATTR_REVERSE);
|
2007-02-20 07:39:17 -05:00
|
|
|
term_addch(view->window, (chr & 127)+'A'-1);
|
2014-01-09 09:20:29 -05:00
|
|
|
term_set_color2(view->window, color, fg24, bg24);
|
2001-11-18 09:28:04 -05:00
|
|
|
}
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
2008-04-21 16:44:04 -04:00
|
|
|
text = end;
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
2001-11-03 07:54:29 -05:00
|
|
|
if (need_clrtoeol && xpos < term_width) {
|
2001-10-28 18:52:36 -05:00
|
|
|
term_set_color(view->window, ATTR_RESET);
|
|
|
|
term_clrtoeol(view->window);
|
|
|
|
}
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
return drawcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Recalculate view's bottom line information - try to keep the
|
|
|
|
original if possible */
|
|
|
|
static void textbuffer_view_init_bottom(TEXT_BUFFER_VIEW_REC *view)
|
|
|
|
{
|
2001-07-12 17:44:01 -04:00
|
|
|
LINE_REC *line;
|
2001-04-14 18:24:56 -04:00
|
|
|
int linecount, total;
|
|
|
|
|
|
|
|
if (view->empty_linecount == 0) {
|
|
|
|
/* no empty lines in screen, no need to try to keep
|
|
|
|
the old bottom startline */
|
|
|
|
view->bottom_startline = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
total = 0;
|
2001-07-12 17:44:01 -04:00
|
|
|
line = textbuffer_line_last(view->buffer);
|
|
|
|
for (; line != NULL; line = line->prev) {
|
2001-04-14 18:24:56 -04:00
|
|
|
linecount = view_get_linecount(view, line);
|
2001-07-12 17:44:01 -04:00
|
|
|
if (line == view->bottom_startline) {
|
2001-04-14 18:24:56 -04:00
|
|
|
/* keep the old one, make sure that subline is ok */
|
|
|
|
if (view->bottom_subline > linecount)
|
|
|
|
view->bottom_subline = linecount;
|
|
|
|
view->empty_linecount = view->height - total -
|
|
|
|
(linecount-view->bottom_subline);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
total += linecount;
|
|
|
|
if (total >= view->height) {
|
2001-07-12 17:44:01 -04:00
|
|
|
view->bottom_startline = line;
|
2001-04-14 18:24:56 -04:00
|
|
|
view->bottom_subline = total - view->height;
|
|
|
|
view->empty_linecount = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not enough lines so we must be at the beginning of the buffer */
|
2001-07-12 17:44:01 -04:00
|
|
|
view->bottom_startline = view->buffer->first_line;
|
2001-04-14 18:24:56 -04:00
|
|
|
view->bottom_subline = 0;
|
|
|
|
view->empty_linecount = view->height - total;
|
|
|
|
}
|
|
|
|
|
2008-12-12 05:42:14 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
/* Create new view. */
|
|
|
|
TEXT_BUFFER_VIEW_REC *textbuffer_view_create(TEXT_BUFFER_REC *buffer,
|
|
|
|
int width, int height,
|
2002-01-28 20:33:41 -05:00
|
|
|
int scroll, int utf8)
|
2001-04-14 18:24:56 -04:00
|
|
|
{
|
|
|
|
TEXT_BUFFER_VIEW_REC *view;
|
|
|
|
|
2001-04-16 12:44:10 -04:00
|
|
|
g_return_val_if_fail(buffer != NULL, NULL);
|
|
|
|
g_return_val_if_fail(width > 0, NULL);
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
view = g_new0(TEXT_BUFFER_VIEW_REC, 1);
|
|
|
|
view->buffer = buffer;
|
|
|
|
view->siblings = textbuffer_get_views(buffer);
|
|
|
|
|
|
|
|
view->width = width;
|
|
|
|
view->height = height;
|
2002-01-28 20:33:41 -05:00
|
|
|
view->scroll = scroll;
|
|
|
|
view->utf8 = utf8;
|
2001-04-14 18:24:56 -04:00
|
|
|
|
|
|
|
view->cache = textbuffer_cache_get(view->siblings, width);
|
|
|
|
textbuffer_view_init_bottom(view);
|
|
|
|
|
|
|
|
view->startline = view->bottom_startline;
|
|
|
|
view->subline = view->bottom_subline;
|
|
|
|
view->bottom = TRUE;
|
|
|
|
|
2008-12-12 05:42:14 -05:00
|
|
|
textbuffer_view_init_ypos(view);
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
view->bookmarks = g_hash_table_new((GHashFunc) g_str_hash,
|
|
|
|
(GCompareFunc) g_str_equal);
|
|
|
|
|
|
|
|
views = g_slist_append(views, view);
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Destroy the view. */
|
|
|
|
void textbuffer_view_destroy(TEXT_BUFFER_VIEW_REC *view)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
|
2001-04-16 12:44:10 -04:00
|
|
|
g_return_if_fail(view != NULL);
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
views = g_slist_remove(views, view);
|
|
|
|
|
|
|
|
if (view->siblings == NULL) {
|
|
|
|
/* last view for textbuffer, destroy */
|
|
|
|
textbuffer_destroy(view->buffer);
|
|
|
|
} else {
|
|
|
|
/* remove ourself from siblings lists */
|
|
|
|
for (tmp = view->siblings; tmp != NULL; tmp = tmp->next) {
|
|
|
|
TEXT_BUFFER_VIEW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
rec->siblings = g_slist_remove(rec->siblings, view);
|
|
|
|
}
|
|
|
|
g_slist_free(view->siblings);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_foreach(view->bookmarks, (GHFunc) g_free, NULL);
|
|
|
|
g_hash_table_destroy(view->bookmarks);
|
|
|
|
|
|
|
|
textbuffer_cache_unref(view->cache);
|
|
|
|
g_free(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Change the default indent position */
|
|
|
|
void textbuffer_view_set_default_indent(TEXT_BUFFER_VIEW_REC *view,
|
2001-04-22 19:20:42 -04:00
|
|
|
int default_indent,
|
2001-10-24 18:52:15 -04:00
|
|
|
int longword_noindent,
|
|
|
|
INDENT_FUNC indent_func)
|
2001-04-14 18:24:56 -04:00
|
|
|
{
|
2001-10-24 18:52:15 -04:00
|
|
|
if (default_indent != -1)
|
|
|
|
view->default_indent = default_indent;
|
2001-10-28 16:17:34 -05:00
|
|
|
if (longword_noindent != -1)
|
2001-10-24 18:52:15 -04:00
|
|
|
view->longword_noindent = longword_noindent;
|
|
|
|
|
|
|
|
view->default_indent_func = indent_func;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void view_unregister_indent_func(TEXT_BUFFER_VIEW_REC *view,
|
|
|
|
INDENT_FUNC indent_func)
|
|
|
|
{
|
|
|
|
if (view->default_indent_func == indent_func)
|
|
|
|
view->default_indent_func = NULL;
|
|
|
|
|
|
|
|
/* recreate cache so it won't contain references
|
|
|
|
to the indent function */
|
|
|
|
view_reset_cache(view);
|
|
|
|
view->cache = textbuffer_cache_get(view->siblings, view->width);
|
|
|
|
}
|
|
|
|
|
|
|
|
void textbuffer_views_unregister_indent_func(INDENT_FUNC indent_func)
|
|
|
|
{
|
|
|
|
g_slist_foreach(views, (GFunc) view_unregister_indent_func,
|
2002-02-01 15:14:30 -05:00
|
|
|
(void *) indent_func);
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
2001-08-13 21:14:26 -04:00
|
|
|
void textbuffer_view_set_scroll(TEXT_BUFFER_VIEW_REC *view, int scroll)
|
|
|
|
{
|
|
|
|
view->scroll = scroll;
|
|
|
|
}
|
|
|
|
|
2002-01-28 20:33:41 -05:00
|
|
|
void textbuffer_view_set_utf8(TEXT_BUFFER_VIEW_REC *view, int utf8)
|
|
|
|
{
|
|
|
|
view->utf8 = utf8;
|
|
|
|
}
|
|
|
|
|
2001-07-12 17:44:01 -04:00
|
|
|
static int view_get_linecount_all(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
|
2001-04-14 18:24:56 -04:00
|
|
|
{
|
|
|
|
int linecount;
|
|
|
|
|
|
|
|
linecount = 0;
|
2001-07-12 17:44:01 -04:00
|
|
|
while (line != NULL) {
|
|
|
|
linecount += view_get_linecount(view, line);
|
|
|
|
line = line->next;
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return linecount;
|
|
|
|
}
|
|
|
|
|
2001-07-12 17:44:01 -04:00
|
|
|
static void view_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
|
2001-10-28 13:40:12 -05:00
|
|
|
int subline, int ypos, int lines, int fill_bottom)
|
2001-04-14 18:24:56 -04:00
|
|
|
{
|
|
|
|
int linecount;
|
|
|
|
|
2001-10-28 13:40:12 -05:00
|
|
|
if (view->dirty) /* don't bother drawing anything - redraw is coming */
|
|
|
|
return;
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
while (line != NULL && lines > 0) {
|
2001-07-12 17:44:01 -04:00
|
|
|
linecount = view_line_draw(view, line, subline, ypos, lines);
|
2001-04-14 18:24:56 -04:00
|
|
|
ypos += linecount; lines -= linecount;
|
|
|
|
|
|
|
|
subline = 0;
|
|
|
|
line = line->next;
|
|
|
|
}
|
|
|
|
|
2001-10-28 13:40:12 -05:00
|
|
|
if (fill_bottom) {
|
|
|
|
/* clear the rest of the view */
|
|
|
|
term_set_color(view->window, ATTR_RESET);
|
|
|
|
while (lines > 0) {
|
|
|
|
term_move(view->window, 0, ypos);
|
|
|
|
term_clrtoeol(view->window);
|
|
|
|
ypos++; lines--;
|
|
|
|
}
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-28 13:40:12 -05:00
|
|
|
#define view_draw_top(view, lines, fill_bottom) \
|
|
|
|
view_draw(view, (view)->startline, (view)->subline, \
|
|
|
|
0, lines, fill_bottom)
|
2001-04-14 18:24:56 -04:00
|
|
|
|
|
|
|
static void view_draw_bottom(TEXT_BUFFER_VIEW_REC *view, int lines)
|
|
|
|
{
|
2001-07-12 17:44:01 -04:00
|
|
|
LINE_REC *line;
|
2001-04-14 18:24:56 -04:00
|
|
|
int ypos, maxline, subline, linecount;
|
|
|
|
|
|
|
|
maxline = view->height-lines;
|
|
|
|
line = view->startline; ypos = -view->subline; subline = 0;
|
|
|
|
while (line != NULL && ypos < maxline) {
|
2001-07-12 17:44:01 -04:00
|
|
|
linecount = view_get_linecount(view, line);
|
2001-04-14 18:24:56 -04:00
|
|
|
ypos += linecount;
|
|
|
|
if (ypos > maxline) {
|
|
|
|
subline = maxline-(ypos-linecount);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
line = line->next;
|
|
|
|
}
|
|
|
|
|
2001-10-28 13:40:12 -05:00
|
|
|
view_draw(view, line, subline, maxline, lines, TRUE);
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns number of lines actually scrolled */
|
2001-07-12 17:44:01 -04:00
|
|
|
static int view_scroll(TEXT_BUFFER_VIEW_REC *view, LINE_REC **lines,
|
|
|
|
int *subline, int scrollcount, int draw_nonclean)
|
2001-04-14 18:24:56 -04:00
|
|
|
{
|
|
|
|
int linecount, realcount, scroll_visible;
|
|
|
|
|
2001-05-21 19:50:13 -04:00
|
|
|
if (*lines == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
/* scroll down */
|
|
|
|
scroll_visible = lines == &view->startline;
|
|
|
|
|
|
|
|
realcount = -*subline;
|
|
|
|
scrollcount += *subline;
|
|
|
|
*subline = 0;
|
|
|
|
while (scrollcount > 0) {
|
2001-07-12 17:44:01 -04:00
|
|
|
linecount = view_get_linecount(view, *lines);
|
2001-04-14 18:24:56 -04:00
|
|
|
|
|
|
|
if ((scroll_visible && *lines == view->bottom_startline) &&
|
|
|
|
(scrollcount >= view->bottom_subline)) {
|
|
|
|
*subline = view->bottom_subline;
|
|
|
|
realcount += view->bottom_subline;
|
|
|
|
scrollcount = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
realcount += linecount;
|
|
|
|
scrollcount -= linecount;
|
|
|
|
if (scrollcount < 0) {
|
|
|
|
realcount += scrollcount;
|
|
|
|
*subline = linecount+scrollcount;
|
|
|
|
scrollcount = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-05-13 13:07:37 -04:00
|
|
|
if ((*lines)->next == NULL)
|
|
|
|
break;
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
*lines = (*lines)->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* scroll up */
|
|
|
|
while (scrollcount < 0 && (*lines)->prev != NULL) {
|
|
|
|
*lines = (*lines)->prev;
|
2001-07-12 17:44:01 -04:00
|
|
|
linecount = view_get_linecount(view, *lines);
|
2001-04-14 18:24:56 -04:00
|
|
|
|
|
|
|
realcount -= linecount;
|
|
|
|
scrollcount += linecount;
|
|
|
|
if (scrollcount > 0) {
|
|
|
|
realcount += scrollcount;
|
|
|
|
*subline = scrollcount;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-14 18:40:45 -04:00
|
|
|
if (scroll_visible && realcount != 0 && view->window != NULL) {
|
2001-04-14 18:24:56 -04:00
|
|
|
if (realcount <= -view->height || realcount >= view->height) {
|
|
|
|
/* scrolled more than screenful, redraw the
|
|
|
|
whole view */
|
|
|
|
textbuffer_view_redraw(view);
|
|
|
|
} else {
|
2001-11-13 08:01:09 -05:00
|
|
|
term_set_color(view->window, ATTR_RESET);
|
2001-10-28 06:30:26 -05:00
|
|
|
term_window_scroll(view->window, realcount);
|
2001-04-14 18:24:56 -04:00
|
|
|
|
|
|
|
if (draw_nonclean) {
|
|
|
|
if (realcount < 0)
|
2001-10-28 13:40:12 -05:00
|
|
|
view_draw_top(view, -realcount, TRUE);
|
2001-04-14 18:24:56 -04:00
|
|
|
else
|
|
|
|
view_draw_bottom(view, realcount);
|
|
|
|
}
|
|
|
|
|
2001-10-28 06:30:26 -05:00
|
|
|
term_refresh(view->window);
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return realcount >= 0 ? realcount : -realcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resize the view. */
|
|
|
|
void textbuffer_view_resize(TEXT_BUFFER_VIEW_REC *view, int width, int height)
|
|
|
|
{
|
|
|
|
int linecount;
|
|
|
|
|
2001-04-16 12:44:10 -04:00
|
|
|
g_return_if_fail(view != NULL);
|
|
|
|
g_return_if_fail(width > 0);
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
if (view->width != width) {
|
|
|
|
/* line cache needs to be recreated */
|
|
|
|
textbuffer_cache_unref(view->cache);
|
|
|
|
view->cache = textbuffer_cache_get(view->siblings, width);
|
|
|
|
}
|
|
|
|
|
2001-10-20 06:35:42 -04:00
|
|
|
view->width = width > 10 ? width : 10;
|
|
|
|
view->height = height > 1 ? height : 1;
|
2001-04-14 18:24:56 -04:00
|
|
|
|
2001-07-12 17:44:01 -04:00
|
|
|
if (view->buffer->first_line == NULL) {
|
2001-06-04 17:58:47 -04:00
|
|
|
view->empty_linecount = height;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
textbuffer_view_init_bottom(view);
|
|
|
|
|
|
|
|
/* check that we didn't scroll lower than bottom startline.. */
|
2001-07-12 17:44:01 -04:00
|
|
|
if (textbuffer_line_exists_after(view->bottom_startline->next,
|
|
|
|
view->startline)) {
|
2001-04-14 18:24:56 -04:00
|
|
|
view->startline = view->bottom_startline;
|
|
|
|
view->subline = view->bottom_subline;
|
|
|
|
} else if (view->startline == view->bottom_startline &&
|
|
|
|
view->subline > view->bottom_subline) {
|
|
|
|
view->subline = view->bottom_subline;
|
|
|
|
} else {
|
|
|
|
/* make sure the subline is still in allowed range */
|
2001-07-12 17:44:01 -04:00
|
|
|
linecount = view_get_linecount(view, view->startline);
|
2001-04-14 18:24:56 -04:00
|
|
|
if (view->subline > linecount)
|
|
|
|
view->subline = linecount;
|
|
|
|
}
|
|
|
|
|
2008-12-12 05:42:14 -05:00
|
|
|
textbuffer_view_init_ypos(view);
|
2001-04-14 18:24:56 -04:00
|
|
|
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 */
|
|
|
|
view->startline = view->bottom_startline;
|
|
|
|
view->subline = view->bottom_subline;
|
|
|
|
if (view->empty_linecount > 0) {
|
|
|
|
view_scroll(view, &view->startline, &view->subline,
|
|
|
|
-view->empty_linecount, FALSE);
|
|
|
|
}
|
2008-12-12 05:42:14 -05:00
|
|
|
textbuffer_view_init_ypos(view);
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
view->bottom = view_is_bottom(view);
|
|
|
|
if (view->bottom) {
|
|
|
|
/* check if we left empty space at the bottom.. */
|
|
|
|
linecount = view_get_linecount_all(view, view->startline) -
|
|
|
|
view->subline;
|
|
|
|
if (view->empty_linecount < view->height-linecount)
|
|
|
|
view->empty_linecount = view->height-linecount;
|
2001-11-18 17:17:31 -05:00
|
|
|
view->more_text = FALSE;
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
2001-10-28 13:40:12 -05:00
|
|
|
view->dirty = TRUE;
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear the view, don't actually remove any lines from buffer. */
|
|
|
|
void textbuffer_view_clear(TEXT_BUFFER_VIEW_REC *view)
|
|
|
|
{
|
2001-04-16 12:44:10 -04:00
|
|
|
g_return_if_fail(view != NULL);
|
|
|
|
|
2008-12-12 05:42:14 -05:00
|
|
|
view->ypos = -1;
|
2001-04-14 18:24:56 -04:00
|
|
|
view->bottom_startline = view->startline =
|
2001-07-12 17:44:01 -04:00
|
|
|
textbuffer_line_last(view->buffer);
|
2001-04-14 18:24:56 -04:00
|
|
|
view->bottom_subline = view->subline =
|
|
|
|
view->buffer->cur_line == NULL ? 0 :
|
|
|
|
view_get_linecount(view, view->buffer->cur_line);
|
|
|
|
view->empty_linecount = view->height;
|
|
|
|
view->bottom = TRUE;
|
2001-11-18 17:17:31 -05:00
|
|
|
view->more_text = FALSE;
|
2001-04-14 18:24:56 -04:00
|
|
|
|
|
|
|
textbuffer_view_redraw(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scroll the view up/down */
|
|
|
|
void textbuffer_view_scroll(TEXT_BUFFER_VIEW_REC *view, int lines)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
2001-04-16 12:44:10 -04:00
|
|
|
g_return_if_fail(view != NULL);
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
count = view_scroll(view, &view->startline, &view->subline,
|
|
|
|
lines, TRUE);
|
2008-12-12 05:42:14 -05:00
|
|
|
view->ypos += lines < 0 ? count : -count;
|
2001-04-14 18:24:56 -04:00
|
|
|
view->bottom = view_is_bottom(view);
|
2001-11-18 17:17:31 -05:00
|
|
|
if (view->bottom) view->more_text = FALSE;
|
2001-04-14 18:24:56 -04:00
|
|
|
|
2001-04-14 18:40:45 -04:00
|
|
|
if (view->window != NULL)
|
2001-10-28 06:30:26 -05:00
|
|
|
term_refresh(view->window);
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Scroll to specified line */
|
|
|
|
void textbuffer_view_scroll_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
|
|
|
|
{
|
2001-04-16 12:44:10 -04:00
|
|
|
g_return_if_fail(view != NULL);
|
|
|
|
|
2001-07-12 17:44:01 -04:00
|
|
|
if (textbuffer_line_exists_after(view->bottom_startline->next, line)) {
|
2001-04-14 18:24:56 -04:00
|
|
|
view->startline = view->bottom_startline;
|
|
|
|
view->subline = view->bottom_subline;
|
|
|
|
} else {
|
2001-07-12 17:44:01 -04:00
|
|
|
view->startline = line;
|
|
|
|
view->subline = 0;
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
2008-12-12 05:42:14 -05:00
|
|
|
textbuffer_view_init_ypos(view);
|
2001-04-14 18:24:56 -04:00
|
|
|
view->bottom = view_is_bottom(view);
|
2001-11-18 17:17:31 -05:00
|
|
|
if (view->bottom) view->more_text = FALSE;
|
2001-04-14 18:24:56 -04:00
|
|
|
|
|
|
|
textbuffer_view_redraw(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return line cache */
|
|
|
|
LINE_CACHE_REC *textbuffer_view_get_line_cache(TEXT_BUFFER_VIEW_REC *view,
|
|
|
|
LINE_REC *line)
|
|
|
|
{
|
|
|
|
LINE_CACHE_REC *cache;
|
|
|
|
|
2002-05-13 13:07:37 -04:00
|
|
|
g_assert(view != NULL);
|
|
|
|
g_assert(line != NULL);
|
2001-04-16 12:44:10 -04:00
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
cache = g_hash_table_lookup(view->cache->line_cache, line);
|
|
|
|
if (cache == NULL)
|
|
|
|
cache = view_update_line_cache(view, line);
|
|
|
|
else
|
|
|
|
cache->last_access = time(NULL);
|
|
|
|
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void view_insert_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
|
|
|
|
{
|
|
|
|
int linecount, ypos, subline;
|
|
|
|
|
2001-11-18 17:17:31 -05:00
|
|
|
if (!view->bottom)
|
|
|
|
view->more_text = TRUE;
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
if (view->bottom_startline == NULL) {
|
|
|
|
view->startline = view->bottom_startline =
|
2001-07-12 17:44:01 -04:00
|
|
|
view->buffer->first_line;
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (view->buffer->cur_line != line &&
|
2001-07-12 17:44:01 -04:00
|
|
|
!textbuffer_line_exists_after(view->bottom_startline, line))
|
2001-04-14 18:24:56 -04:00
|
|
|
return;
|
|
|
|
|
2014-01-08 07:48:38 -05:00
|
|
|
linecount = view_get_linecount(view, line);
|
2008-12-12 05:42:14 -05:00
|
|
|
view->ypos += linecount;
|
2001-04-14 18:24:56 -04:00
|
|
|
if (view->empty_linecount > 0) {
|
|
|
|
view->empty_linecount -= linecount;
|
|
|
|
if (view->empty_linecount >= 0)
|
|
|
|
linecount = 0;
|
|
|
|
else {
|
|
|
|
linecount = -view->empty_linecount;
|
|
|
|
view->empty_linecount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (linecount > 0) {
|
|
|
|
view_scroll(view, &view->bottom_startline,
|
|
|
|
&view->bottom_subline, linecount, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (view->bottom) {
|
2008-12-12 05:42:14 -05:00
|
|
|
if (view->scroll && view->ypos >= view->height) {
|
|
|
|
linecount = view->ypos-view->height+1;
|
2001-04-14 18:24:56 -04:00
|
|
|
view_scroll(view, &view->startline,
|
|
|
|
&view->subline, linecount, FALSE);
|
2008-12-12 05:42:14 -05:00
|
|
|
view->ypos -= linecount;
|
2001-08-13 21:14:26 -04:00
|
|
|
} else {
|
|
|
|
view->bottom = view_is_bottom(view);
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
2001-04-14 18:40:45 -04:00
|
|
|
if (view->window != NULL) {
|
2014-01-08 07:48:38 -05:00
|
|
|
ypos = view->ypos+1 - view_get_linecount(view, line);
|
2001-04-14 18:40:45 -04:00
|
|
|
if (ypos >= 0)
|
|
|
|
subline = 0;
|
|
|
|
else {
|
|
|
|
subline = -ypos;
|
|
|
|
ypos = 0;
|
|
|
|
}
|
2001-08-13 21:14:26 -04:00
|
|
|
if (ypos < view->height) {
|
|
|
|
view_line_draw(view, line, subline, ypos,
|
|
|
|
view->height - ypos);
|
|
|
|
}
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
}
|
2001-04-14 18:40:45 -04:00
|
|
|
|
|
|
|
if (view->window != NULL)
|
2001-10-28 06:30:26 -05:00
|
|
|
term_refresh(view->window);
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update some line in the buffer which has been modified using
|
|
|
|
textbuffer_append() or textbuffer_insert(). */
|
|
|
|
void textbuffer_view_insert_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
unsigned char update_counter;
|
|
|
|
|
2001-04-16 12:44:10 -04:00
|
|
|
g_return_if_fail(view != NULL);
|
|
|
|
g_return_if_fail(line != NULL);
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
if (!view->buffer->last_eol)
|
|
|
|
return;
|
|
|
|
|
|
|
|
update_counter = view->cache->update_counter+1;
|
|
|
|
view_update_cache(view, line, update_counter);
|
|
|
|
view_insert_line(view, line);
|
|
|
|
|
|
|
|
for (tmp = view->siblings; tmp != NULL; tmp = tmp->next) {
|
|
|
|
TEXT_BUFFER_VIEW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
view_update_cache(rec, line, update_counter);
|
|
|
|
view_insert_line(rec, line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
LINE_REC *remove_line;
|
|
|
|
GSList *remove_list;
|
|
|
|
} BOOKMARK_FIND_REC;
|
|
|
|
|
|
|
|
static void bookmark_check_remove(char *key, LINE_REC *line,
|
|
|
|
BOOKMARK_FIND_REC *rec)
|
|
|
|
{
|
|
|
|
if (line == rec->remove_line)
|
|
|
|
rec->remove_list = g_slist_append(rec->remove_list, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void view_bookmarks_check(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
|
|
|
|
{
|
|
|
|
BOOKMARK_FIND_REC rec;
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
rec.remove_line = line;
|
|
|
|
rec.remove_list = NULL;
|
|
|
|
g_hash_table_foreach(view->bookmarks,
|
|
|
|
(GHFunc) bookmark_check_remove, &rec);
|
|
|
|
|
|
|
|
if (rec.remove_list != NULL) {
|
|
|
|
for (tmp = rec.remove_list; tmp != NULL; tmp = tmp->next) {
|
|
|
|
g_hash_table_remove(view->bookmarks, tmp->data);
|
2007-03-12 18:54:45 -04:00
|
|
|
g_free(tmp->data);
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
g_slist_free(rec.remove_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return number of real lines `lines' list takes -
|
|
|
|
stops counting when the height reaches the view height */
|
|
|
|
static int view_get_lines_height(TEXT_BUFFER_VIEW_REC *view,
|
2001-07-12 17:44:01 -04:00
|
|
|
LINE_REC *line, int subline,
|
2001-04-14 18:24:56 -04:00
|
|
|
LINE_REC *skip_line)
|
|
|
|
{
|
|
|
|
int height, linecount;
|
|
|
|
|
|
|
|
height = -subline;
|
2001-07-12 17:44:01 -04:00
|
|
|
while (line != NULL && height < view->height) {
|
2001-04-14 18:24:56 -04:00
|
|
|
if (line != skip_line) {
|
|
|
|
linecount = view_get_linecount(view, line);
|
|
|
|
height += linecount;
|
|
|
|
}
|
2001-07-12 17:44:01 -04:00
|
|
|
line = line->next;
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return height < view->height ? height : view->height;
|
|
|
|
}
|
|
|
|
|
2001-08-12 14:25:43 -04:00
|
|
|
static void view_remove_line_update_startline(TEXT_BUFFER_VIEW_REC *view,
|
|
|
|
LINE_REC *line, int linecount)
|
|
|
|
{
|
|
|
|
int scroll;
|
|
|
|
|
|
|
|
if (view->startline == line) {
|
2006-09-12 18:33:14 -04:00
|
|
|
view->startline = view->startline->prev != NULL ?
|
|
|
|
view->startline->prev : view->startline->next;
|
2001-08-12 14:25:43 -04:00
|
|
|
view->subline = 0;
|
|
|
|
} else {
|
|
|
|
scroll = view->height -
|
|
|
|
view_get_lines_height(view, view->startline,
|
|
|
|
view->subline, line);
|
|
|
|
if (scroll > 0) {
|
|
|
|
view_scroll(view, &view->startline,
|
|
|
|
&view->subline, -scroll, FALSE);
|
|
|
|
}
|
|
|
|
}
|
2008-12-12 05:42:14 -05:00
|
|
|
|
|
|
|
/* 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;
|
2001-08-12 14:25:43 -04:00
|
|
|
}
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
static void view_remove_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
|
|
|
|
int linecount)
|
|
|
|
{
|
2001-08-12 14:25:43 -04:00
|
|
|
int realcount;
|
2001-04-14 18:24:56 -04:00
|
|
|
|
|
|
|
view_bookmarks_check(view, line);
|
|
|
|
|
|
|
|
if (view->buffer->cur_line == line) {
|
|
|
|
/* the last line is being removed */
|
|
|
|
LINE_REC *prevline;
|
|
|
|
|
2001-07-12 17:44:01 -04:00
|
|
|
prevline = view->buffer->first_line == line ? NULL :
|
|
|
|
textbuffer_line_last(view->buffer);
|
2001-04-14 18:24:56 -04:00
|
|
|
view->cache->last_linecount = prevline == NULL ? 0 :
|
|
|
|
view_get_linecount(view, prevline);
|
|
|
|
}
|
|
|
|
|
2001-08-12 14:25:43 -04:00
|
|
|
if (view->buffer->first_line == line) {
|
2001-04-14 18:24:56 -04:00
|
|
|
/* first line in the buffer - this is the most commonly
|
|
|
|
removed line.. */
|
2001-07-12 17:44:01 -04:00
|
|
|
if (view->bottom_startline == line) {
|
2001-04-14 18:24:56 -04:00
|
|
|
/* very small scrollback.. */
|
|
|
|
view->bottom_startline = view->bottom_startline->next;
|
|
|
|
view->bottom_subline = 0;
|
2001-05-21 18:45:49 -04:00
|
|
|
}
|
2001-04-14 18:24:56 -04:00
|
|
|
|
2001-07-12 17:44:01 -04:00
|
|
|
if (view->startline == line) {
|
2001-05-21 18:45:49 -04:00
|
|
|
/* removing the first line in screen */
|
2006-09-14 18:11:19 -04:00
|
|
|
int is_last = view->startline->next == NULL;
|
|
|
|
|
2001-05-21 18:45:49 -04:00
|
|
|
realcount = view_scroll(view, &view->startline,
|
|
|
|
&view->subline,
|
2001-08-12 14:25:43 -04:00
|
|
|
linecount, FALSE);
|
2008-12-12 05:42:14 -05:00
|
|
|
view->ypos -= realcount;
|
2001-05-21 18:45:49 -04:00
|
|
|
view->empty_linecount += linecount-realcount;
|
2006-09-14 18:11:19 -04:00
|
|
|
if (is_last == 1)
|
|
|
|
view->startline = NULL;
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
2001-08-12 14:25:43 -04:00
|
|
|
} else {
|
|
|
|
if (textbuffer_line_exists_after(view->bottom_startline,
|
|
|
|
line)) {
|
|
|
|
realcount = view_scroll(view, &view->bottom_startline,
|
|
|
|
&view->bottom_subline,
|
|
|
|
-linecount, FALSE);
|
|
|
|
view->empty_linecount += linecount-realcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (textbuffer_line_exists_after(view->startline,
|
|
|
|
line)) {
|
|
|
|
view_remove_line_update_startline(view, line,
|
|
|
|
linecount);
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
view->bottom = view_is_bottom(view);
|
2001-11-18 17:17:31 -05:00
|
|
|
if (view->bottom) view->more_text = FALSE;
|
2001-04-14 18:40:45 -04:00
|
|
|
if (view->window != NULL)
|
2001-10-28 06:30:26 -05:00
|
|
|
term_refresh(view->window);
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove one line from buffer. */
|
|
|
|
void textbuffer_view_remove_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
|
|
|
|
{
|
|
|
|
GSList *tmp;
|
|
|
|
unsigned char update_counter;
|
|
|
|
int linecount;
|
|
|
|
|
2001-04-16 12:44:10 -04:00
|
|
|
g_return_if_fail(view != NULL);
|
|
|
|
g_return_if_fail(line != NULL);
|
|
|
|
|
2014-01-08 07:49:46 -05:00
|
|
|
signal_emit("gui textbuffer line removed", 3, view, line, line->prev);
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
linecount = view_get_linecount(view, line);
|
|
|
|
update_counter = view->cache->update_counter+1;
|
|
|
|
|
|
|
|
view_remove_line(view, line, linecount);
|
|
|
|
view_remove_cache(view, line, update_counter);
|
|
|
|
|
|
|
|
for (tmp = view->siblings; tmp != NULL; tmp = tmp->next) {
|
|
|
|
TEXT_BUFFER_VIEW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
view_remove_line(rec, line, linecount);
|
|
|
|
view_remove_cache(rec, line, update_counter);
|
|
|
|
}
|
|
|
|
|
|
|
|
textbuffer_remove(view->buffer, line);
|
|
|
|
}
|
|
|
|
|
2007-02-17 10:31:10 -05:00
|
|
|
void textbuffer_view_remove_lines_by_level(TEXT_BUFFER_VIEW_REC *view, int level)
|
|
|
|
{
|
|
|
|
LINE_REC *line, *next;
|
|
|
|
|
|
|
|
term_refresh_freeze();
|
|
|
|
line = textbuffer_view_get_lines(view);
|
|
|
|
|
|
|
|
while (line != NULL) {
|
|
|
|
next = line->next;
|
|
|
|
|
|
|
|
if (line->info.level & level)
|
|
|
|
textbuffer_view_remove_line(view, line);
|
|
|
|
line = next;
|
|
|
|
}
|
|
|
|
textbuffer_view_redraw(view);
|
|
|
|
term_refresh_thaw();
|
|
|
|
}
|
|
|
|
|
2001-08-08 11:43:07 -04:00
|
|
|
static int g_free_true(void *data)
|
|
|
|
{
|
|
|
|
g_free(data);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
/* Remove all lines from buffer. */
|
|
|
|
void textbuffer_view_remove_all_lines(TEXT_BUFFER_VIEW_REC *view)
|
|
|
|
{
|
2001-04-16 12:44:10 -04:00
|
|
|
g_return_if_fail(view != NULL);
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
textbuffer_remove_all_lines(view->buffer);
|
|
|
|
|
2001-08-08 11:43:07 -04:00
|
|
|
g_hash_table_foreach_remove(view->bookmarks,
|
|
|
|
(GHRFunc) g_free_true, NULL);
|
|
|
|
|
2001-10-24 18:52:15 -04:00
|
|
|
view_reset_cache(view);
|
2001-04-14 18:24:56 -04:00
|
|
|
textbuffer_view_clear(view);
|
2001-10-24 18:52:15 -04:00
|
|
|
g_slist_foreach(view->siblings, (GFunc) textbuffer_view_clear, NULL);
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set a bookmark in view */
|
|
|
|
void textbuffer_view_set_bookmark(TEXT_BUFFER_VIEW_REC *view,
|
|
|
|
const char *name, LINE_REC *line)
|
|
|
|
{
|
|
|
|
gpointer key, value;
|
|
|
|
|
2001-04-16 12:44:10 -04:00
|
|
|
g_return_if_fail(view != NULL);
|
|
|
|
g_return_if_fail(name != NULL);
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
if (g_hash_table_lookup_extended(view->bookmarks, name,
|
|
|
|
&key, &value)) {
|
|
|
|
g_hash_table_remove(view->bookmarks, key);
|
|
|
|
g_free(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_insert(view->bookmarks, g_strdup(name), line);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set a bookmark in view to the bottom line */
|
|
|
|
void textbuffer_view_set_bookmark_bottom(TEXT_BUFFER_VIEW_REC *view,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
LINE_REC *line;
|
|
|
|
|
2001-04-16 12:44:10 -04:00
|
|
|
g_return_if_fail(view != NULL);
|
|
|
|
g_return_if_fail(name != NULL);
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
if (view->bottom_startline != NULL) {
|
2001-07-12 17:44:01 -04:00
|
|
|
line = textbuffer_line_last(view->buffer);
|
2001-04-14 18:24:56 -04:00
|
|
|
textbuffer_view_set_bookmark(view, name, line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the line for bookmark */
|
|
|
|
LINE_REC *textbuffer_view_get_bookmark(TEXT_BUFFER_VIEW_REC *view,
|
|
|
|
const char *name)
|
|
|
|
{
|
2001-04-16 12:44:10 -04:00
|
|
|
g_return_val_if_fail(view != NULL, NULL);
|
|
|
|
g_return_val_if_fail(name != NULL, NULL);
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
return g_hash_table_lookup(view->bookmarks, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Specify window where the changes in view should be drawn,
|
|
|
|
NULL disables it. */
|
2001-06-01 17:49:07 -04:00
|
|
|
void textbuffer_view_set_window(TEXT_BUFFER_VIEW_REC *view,
|
2001-10-28 06:30:26 -05:00
|
|
|
TERM_WINDOW *window)
|
2001-04-14 18:24:56 -04:00
|
|
|
{
|
2001-04-16 12:44:10 -04:00
|
|
|
g_return_if_fail(view != NULL);
|
|
|
|
|
2001-04-14 18:24:56 -04:00
|
|
|
if (view->window != window) {
|
|
|
|
view->window = window;
|
2001-10-28 13:40:12 -05:00
|
|
|
if (window != NULL)
|
|
|
|
view->dirty = TRUE;
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Redraw a view to window */
|
|
|
|
void textbuffer_view_redraw(TEXT_BUFFER_VIEW_REC *view)
|
|
|
|
{
|
2001-04-16 12:44:10 -04:00
|
|
|
g_return_if_fail(view != NULL);
|
|
|
|
|
2001-04-14 18:40:45 -04:00
|
|
|
if (view->window != NULL) {
|
2001-10-28 13:40:12 -05:00
|
|
|
view->dirty = FALSE;
|
2001-11-03 09:50:43 -05:00
|
|
|
view_draw_top(view, view->height, TRUE);
|
2001-10-28 06:30:26 -05:00
|
|
|
term_refresh(view->window);
|
2001-04-14 18:40:45 -04:00
|
|
|
}
|
2001-04-14 18:24:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int line_cache_check_remove(void *key, LINE_CACHE_REC *cache,
|
|
|
|
time_t *now)
|
|
|
|
{
|
|
|
|
if (cache->last_access+LINE_CACHE_KEEP_TIME > *now)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
line_cache_destroy(NULL, cache);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sig_check_linecache(void)
|
|
|
|
{
|
|
|
|
GSList *tmp, *caches;
|
|
|
|
time_t now;
|
|
|
|
|
|
|
|
now = time(NULL); caches = NULL;
|
|
|
|
for (tmp = views; tmp != NULL; tmp = tmp->next) {
|
|
|
|
TEXT_BUFFER_VIEW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
if (g_slist_find(caches, rec->cache) != NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
caches = g_slist_append(caches, rec->cache);
|
|
|
|
g_hash_table_foreach_remove(rec->cache->line_cache,
|
|
|
|
(GHRFunc) line_cache_check_remove,
|
|
|
|
&now);
|
|
|
|
}
|
2002-01-20 07:50:10 -05:00
|
|
|
|
|
|
|
g_slist_free(caches);
|
2001-04-14 18:24:56 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void textbuffer_view_init(void)
|
|
|
|
{
|
|
|
|
linecache_tag = g_timeout_add(LINE_CACHE_CHECK_TIME, (GSourceFunc) sig_check_linecache, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void textbuffer_view_deinit(void)
|
|
|
|
{
|
|
|
|
g_source_remove(linecache_tag);
|
|
|
|
}
|