Ejemplo n.º 1
0
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);
	}
}
Ejemplo n.º 2
0
/* Create new view. */
TEXT_BUFFER_VIEW_REC *textbuffer_view_create(TEXT_BUFFER_REC *buffer,
					     int width, int height,
					     int scroll, int utf8)
{
	TEXT_BUFFER_VIEW_REC *view;

        g_return_val_if_fail(buffer != NULL, NULL);
        g_return_val_if_fail(width > 0, NULL);

	view = g_new0(TEXT_BUFFER_VIEW_REC, 1);
	view->buffer = buffer;
        view->siblings = textbuffer_get_views(buffer);

	view->width = width;
        view->height = height;
	view->scroll = scroll;
        view->utf8 = utf8;

	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;

	textbuffer_view_init_ypos(view);

	view->bookmarks = g_hash_table_new((GHashFunc) g_str_hash,
					   (GCompareFunc) g_str_equal);

	views = g_slist_append(views, view);
        return view;
}
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 4
0
static void view_unregister_indent_func(TEXT_BUFFER_VIEW_REC *view,
					INDENT_FUNC indent_func)
{
        INDENT_FUNC func;
	LINE_REC *line;
        const unsigned char *text, *tmp;

	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);

        /* remove all references to the indent function from buffer */
	line = view->buffer->first_line;
	while (line != NULL) {
		text = line->text;

		for (text = line->text;; text++) {
			if (*text != '\0')
				continue;

                        text++;
			if (*text == LINE_CMD_EOL)
				break;

			if (*text == LINE_CMD_INDENT_FUNC) {
				text++;
				memcpy(&func, text, sizeof(INDENT_FUNC));
				if (func == indent_func)
                                        memset(&func, 0, sizeof(INDENT_FUNC));
				text += sizeof(INDENT_FUNC);
			} else if (*text == LINE_CMD_CONTINUE) {
				memcpy(&tmp, text+1, sizeof(char *));
				text = tmp-1;
			}
		}

		line = line->next;
	}
}
Ejemplo n.º 5
0
/* Resize the view. */
void textbuffer_view_resize(TEXT_BUFFER_VIEW_REC *view, int width, int height)
{
	int linecount;

        g_return_if_fail(view != NULL);
        g_return_if_fail(width > 0);

	if (view->width != width) {
                /* line cache needs to be recreated */
		textbuffer_cache_unref(view->cache);
		view->cache = textbuffer_cache_get(view->siblings, width);
	}

	view->width = width > 10 ? width : 10;
	view->height = height > 1 ? height : 1;

	if (view->buffer->first_line == NULL) {
                view->empty_linecount = height;
		return;
	}

	textbuffer_view_init_bottom(view);

	/* check that we didn't scroll lower than bottom startline.. */
	if (textbuffer_line_exists_after(view->bottom_startline->next,
					 view->startline)) {
		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 */
		linecount = view_get_linecount(view, view->startline);
		if (view->subline > linecount)
                        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 */
		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);
		}
		textbuffer_view_init_ypos(view);
	}

	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;
                view->more_text = FALSE;
	}

	view->dirty = TRUE;
}