예제 #1
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);
}
예제 #2
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);
}
예제 #3
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);
}
예제 #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
파일: 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);
}
예제 #9
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);
}
예제 #10
0
파일: gui-entry.c 프로젝트: Adam-/irssi
void gui_entry_erase_cell(GUI_ENTRY_REC *entry)
{
	int size = 1;

	g_return_if_fail(entry != NULL);

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

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

	entry->text_len -= size;

	gui_entry_redraw_from(entry, entry->pos);
	gui_entry_draw(entry);
}
예제 #11
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);
}
예제 #12
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);
}