示例#1
0
文件: gui-entry.c 项目: Adam-/irssi
void gui_entry_insert_char(GUI_ENTRY_REC *entry, unichar chr)
{
        g_return_if_fail(entry != NULL);

	if (chr == 0 || chr == 13 || chr == 10)
		return; /* never insert NUL, CR or LF characters */

	if (entry->utf8 && entry->pos == 0 && mk_wcwidth(chr) == 0)
		return;

        gui_entry_redraw_from(entry, entry->pos);

	entry_text_grow(entry, 1);

	/* make space for the string */
	g_memmove(entry->text + entry->pos + 1, entry->text + entry->pos,
		  (entry->text_len-entry->pos + 1) * sizeof(unichar));

	entry->text[entry->pos] = chr;
	entry->text_len++;
        entry->pos++;

	gui_entry_fix_cursor(entry);
	gui_entry_draw(entry);
}
示例#2
0
void gui_entry_insert_text(GUI_ENTRY_REC *entry, const char *str)
{
        unichar chr;
	int i, len;

        g_return_if_fail(entry != NULL);
	g_return_if_fail(str != NULL);

        gui_entry_redraw_from(entry, entry->pos);

	len = !entry->utf8 ? strlen(str) : strlen_utf8(str);
        entry_text_grow(entry, len);

        /* make space for the string */
	g_memmove(entry->text + entry->pos + len, entry->text + entry->pos,
		  (entry->text_len-entry->pos + 1) * sizeof(unichar));

	if (!entry->utf8) {
		for (i = 0; i < len; i++)
                        entry->text[entry->pos+i] = str[i];
	} else {
                chr = entry->text[entry->pos+len];
		utf8_to_utf16(str, entry->text+entry->pos);
                entry->text[entry->pos+len] = chr;
	}

	entry->text_len += len;
        entry->pos += len;

	gui_entry_fix_cursor(entry);
	gui_entry_draw(entry);
}
示例#3
0
文件: gui-entry.c 项目: Adam-/irssi
void gui_entry_insert_text(GUI_ENTRY_REC *entry, const char *str)
{
        unichar chr;
	int i, len;
	const char *ptr;

        g_return_if_fail(entry != NULL);
	g_return_if_fail(str != NULL);

        gui_entry_redraw_from(entry, entry->pos);

	if (entry->utf8) {
		g_utf8_validate(str, -1, &ptr);
		len = g_utf8_pointer_to_offset(str, ptr);
	} else if (term_type == TERM_TYPE_BIG5)
		len = strlen_big5((const unsigned char *)str);
	else
		len = strlen(str);
        entry_text_grow(entry, len);

        /* make space for the string */
	g_memmove(entry->text + entry->pos + len, entry->text + entry->pos,
		  (entry->text_len-entry->pos + 1) * sizeof(unichar));

	if (!entry->utf8) {
		if (term_type == TERM_TYPE_BIG5) {
			chr = entry->text[entry->pos + len];
			big5_to_unichars(str, entry->text + entry->pos);
			entry->text[entry->pos + len] = chr;
		} else {
			for (i = 0; i < len; i++)
				entry->text[entry->pos + i] = str[i];
		}
	} else {
		ptr = str;
		for (i = 0; i < len; i++) {
			entry->text[entry->pos + i] = g_utf8_get_char(ptr);
			ptr = g_utf8_next_char(ptr);
		}
	}

	entry->text_len += len;
        entry->pos += len;

	gui_entry_fix_cursor(entry);
	gui_entry_draw(entry);
}