示例#1
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);
}
示例#2
0
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, int update_cutbuffer)
{
        g_return_if_fail(entry != NULL);

	if (entry->pos < size)
		return;

	if (update_cutbuffer) {
		/* put erased text to cutbuffer */
		if (entry->cutbuffer == NULL || entry->cutbuffer_len < size) {
			g_free(entry->cutbuffer);
			entry->cutbuffer = g_new(unichar, size+1);
		}

		entry->cutbuffer_len = size;
		entry->cutbuffer[size] = '\0';
		memcpy(entry->cutbuffer, entry->text + entry->pos - size,
		       size * sizeof(unichar));
	}

	if (size == 0) {
                /* we just wanted to clear the cutbuffer */
		return;
	}

	g_memmove(entry->text + entry->pos - size, entry->text + entry->pos,
		  (entry->text_len-entry->pos+1) * sizeof(unichar));

	entry->pos -= size;
        entry->text_len -= size;

	gui_entry_redraw_from(entry, entry->pos);
	gui_entry_fix_cursor(entry);
	gui_entry_draw(entry);
}
示例#3
0
void gui_entry_move(GUI_ENTRY_REC *entry, int xpos, int ypos, int width)
{
	int old_width;

        g_return_if_fail(entry != NULL);

	if (entry->xpos != xpos || entry->ypos != ypos) {
                /* position in screen changed - needs a full redraw */
		entry->xpos = xpos;
		entry->ypos = ypos;
		entry->width = width;
		gui_entry_redraw(entry);
                return;
	}

	if (entry->width == width)
                return; /* no changes */

	if (width > entry->width) {
                /* input line grew - need to draw text at the end */
                old_width = width;
		entry->width = width;
		gui_entry_redraw_from(entry, old_width);
	} else {
		/* input line shrinked - make sure the cursor
		   is inside the input line */
		entry->width = width;
		if (entry->pos - entry->scrstart >
		    entry->width-2 - entry->promptlen) {
			gui_entry_fix_cursor(entry);
		}
	}

	gui_entry_draw(entry);
}
示例#4
0
文件: gui-entry.c 项目: Adam-/irssi
void gui_entry_transpose_words(GUI_ENTRY_REC *entry)
{
	int spos1, epos1, spos2, epos2;

	/* find last position */
	epos2 = entry->pos;
	while (epos2 < entry->text_len && !i_isalnum(entry->text[epos2]))
		epos2++;
	while (epos2 < entry->text_len &&  i_isalnum(entry->text[epos2]))
		epos2++;

	/* find other position */
	spos2 = epos2;
	while (spos2 > 0 && !i_isalnum(entry->text[spos2-1]))
		spos2--;
	while (spos2 > 0 &&  i_isalnum(entry->text[spos2-1]))
		spos2--;

	epos1 = spos2;
	while (epos1 > 0 && !i_isalnum(entry->text[epos1-1]))
		epos1--;

	spos1 = epos1;
	while (spos1 > 0 && i_isalnum(entry->text[spos1-1]))
		spos1--;

	/* do wordswap if any found */
	if (spos1 < epos1 && epos1 < spos2 && spos2 < epos2) {
		unichar *first, *sep, *second;
		int i;

		first  = (unichar *) g_malloc( (epos1 - spos1) * sizeof(unichar) );
		sep    = (unichar *) g_malloc( (spos2 - epos1) * sizeof(unichar) );
		second = (unichar *) g_malloc( (epos2 - spos2) * sizeof(unichar) );

		for (i = spos1; i < epos1; i++)
			first[i-spos1] = entry->text[i];
		for (i = epos1; i < spos2; i++)
			sep[i-epos1] = entry->text[i];
		for (i = spos2; i < epos2; i++)
			second[i-spos2] = entry->text[i];

		entry->pos = spos1;
		for (i = 0; i < epos2-spos2; i++)
			entry->text[entry->pos++] = second[i];
		for (i = 0; i < spos2-epos1; i++)
			entry->text[entry->pos++] = sep[i];
		for (i = 0; i < epos1-spos1; i++)
			entry->text[entry->pos++] = first[i];

		g_free(first);
		g_free(sep);
		g_free(second);

	}

	gui_entry_redraw_from(entry, spos1);
	gui_entry_fix_cursor(entry);
	gui_entry_draw(entry);
}
示例#5
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);
}
示例#6
0
文件: gui-entry.c 项目: lanurmi/irssi
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_cutbuffer)
{
	size_t w = 0;

        g_return_if_fail(entry != NULL);

	if (size == 0 || entry->pos < size)
		return;

	switch (update_cutbuffer) {
		case CUTBUFFER_UPDATE_PREPEND:
			if (entry->cutbuffer_len) {
				int cutbuffer_new_size = entry->cutbuffer_len + size;
				unichar *tmpcutbuffer = entry->cutbuffer;
				entry->cutbuffer = g_new(unichar, cutbuffer_new_size+1);

				memcpy(entry->cutbuffer, entry->text + entry->pos - size,
						size * sizeof(unichar));
				memcpy(entry->cutbuffer + size, tmpcutbuffer,
						entry->cutbuffer_len * sizeof(unichar));

				entry->cutbuffer_len = cutbuffer_new_size;
				entry->cutbuffer[cutbuffer_new_size] = '\0';

				g_free(tmpcutbuffer);
				break;
			}
			/* fall through to REPLACE if cutbuffer_len was 0 */
		case CUTBUFFER_UPDATE_REPLACE:
			/* put erased text to cutbuffer */
			if (entry->cutbuffer_len < size) {
				g_free(entry->cutbuffer);
				entry->cutbuffer = g_new(unichar, size+1);
			}

			entry->cutbuffer_len = size;
			entry->cutbuffer[size] = '\0';
			memcpy(entry->cutbuffer, entry->text + entry->pos - size,
			       size * sizeof(unichar));
			break;
		case CUTBUFFER_UPDATE_NOOP:
			break;
	}

	if (entry->utf8)
		while (entry->pos-size-w > 0 &&
		       mk_wcwidth(entry->text[entry->pos-size-w]) == 0) w++;

	g_memmove(entry->text + entry->pos - size, entry->text + entry->pos,
		  (entry->text_len-entry->pos+1) * sizeof(unichar));

	entry->pos -= size;
        entry->text_len -= size;

	gui_entry_redraw_from(entry, entry->pos-w);
	gui_entry_fix_cursor(entry);
	gui_entry_draw(entry);
}
示例#7
0
void gui_entry_redraw(GUI_ENTRY_REC *entry)
{
        g_return_if_fail(entry != NULL);

	gui_entry_set_prompt(entry, NULL);
        gui_entry_redraw_from(entry, 0);
	gui_entry_fix_cursor(entry);
	gui_entry_draw(entry);
}
示例#8
0
void gui_entry_move_pos(GUI_ENTRY_REC *entry, int pos)
{
        g_return_if_fail(entry != NULL);

	if (entry->pos+pos >= 0 && entry->pos+pos <= entry->text_len)
		entry->pos += pos;

	gui_entry_fix_cursor(entry);
	gui_entry_draw(entry);
}
示例#9
0
void gui_entry_move_words(GUI_ENTRY_REC *entry, int count, int to_space)
{
        g_return_if_fail(entry != NULL);

	if (count < 0)
		gui_entry_move_words_left(entry, -count, to_space);
	else if (count > 0)
		gui_entry_move_words_right(entry, count, to_space);

	gui_entry_fix_cursor(entry);
	gui_entry_draw(entry);
}
示例#10
0
文件: gui-entry.c 项目: Adam-/irssi
void gui_entry_upcase_word(GUI_ENTRY_REC *entry)
{
	int pos = entry->pos;
	while (pos < entry->text_len && !i_isalnum(entry->text[pos]))
		pos++;

	while (pos < entry->text_len && i_isalnum(entry->text[pos])) {
		entry->text[pos] = i_toupper(entry->text[pos]);
		pos++;
	}

	gui_entry_redraw_from(entry, entry->pos);
	entry->pos = pos;
	gui_entry_fix_cursor(entry);
	gui_entry_draw(entry);
}
示例#11
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);
}
示例#12
0
文件: gui-entry.c 项目: Adam-/irssi
void gui_entry_move_pos(GUI_ENTRY_REC *entry, int pos)
{
        g_return_if_fail(entry != NULL);

	if (entry->pos + pos >= 0 && entry->pos + pos <= entry->text_len)
		entry->pos += pos;

	if (entry->utf8) {
		int step = pos < 0 ? -1 : 1;
		while(mk_wcwidth(entry->text[entry->pos]) == 0 &&
		      entry->pos + step >= 0 && entry->pos + step <= entry->text_len)
			entry->pos += step;
	}

	gui_entry_fix_cursor(entry);
	gui_entry_draw(entry);
}
示例#13
0
void gui_entry_transpose_chars(GUI_ENTRY_REC *entry)
{
        unichar chr;

	if (entry->pos == 0 || entry->text_len < 2)
                return;

	if (entry->pos == entry->text_len)
                entry->pos--;

        /* swap chars */
	chr = entry->text[entry->pos];
	entry->text[entry->pos] = entry->text[entry->pos-1];
        entry->text[entry->pos-1] = chr;

        entry->pos++;

	gui_entry_redraw_from(entry, entry->pos-2);
	gui_entry_fix_cursor(entry);
	gui_entry_draw(entry);
}
示例#14
0
void gui_entry_set_prompt(GUI_ENTRY_REC *entry, const char *str)
{
	int oldlen;

        g_return_if_fail(entry != NULL);

        oldlen = entry->promptlen;
	if (str != NULL) {
		g_free_not_null(entry->prompt);
		entry->prompt = g_strdup(str);
		entry->promptlen = format_get_length(str);
	}

        if (entry->prompt != NULL)
		gui_printtext(entry->xpos, entry->ypos, entry->prompt);

	if (entry->promptlen != oldlen) {
		gui_entry_fix_cursor(entry);
		gui_entry_draw(entry);
	}
}
示例#15
0
文件: gui-entry.c 项目: Adam-/irssi
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, int update_cutbuffer)
{
	size_t w = 0;

        g_return_if_fail(entry != NULL);

	if (size == 0 || entry->pos < size)
		return;

	if (update_cutbuffer) {
		/* put erased text to cutbuffer */
		if (entry->cutbuffer_len < size) {
			g_free(entry->cutbuffer);
			entry->cutbuffer = g_new(unichar, size+1);
		}

		entry->cutbuffer_len = size;
		entry->cutbuffer[size] = '\0';
		memcpy(entry->cutbuffer, entry->text + entry->pos - size,
		       size * sizeof(unichar));
	}

	if (entry->utf8)
		while (entry->pos-size-w > 0 &&
		       mk_wcwidth(entry->text[entry->pos-size-w]) == 0) w++;

	g_memmove(entry->text + entry->pos - size, entry->text + entry->pos,
		  (entry->text_len-entry->pos+1) * sizeof(unichar));

	entry->pos -= size;
        entry->text_len -= size;

	gui_entry_redraw_from(entry, entry->pos-w);
	gui_entry_fix_cursor(entry);
	gui_entry_draw(entry);
}