2000-04-26 04:03:38 -04:00
|
|
|
/*
|
|
|
|
gui-entry.c : irssi
|
|
|
|
|
|
|
|
Copyright (C) 1999 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.
|
2000-04-26 04:03:38 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
2002-02-15 08:38:24 -05:00
|
|
|
#include "misc.h"
|
2002-01-28 22:13:06 -05:00
|
|
|
#include "utf8.h"
|
2001-02-20 23:21:15 -05:00
|
|
|
#include "formats.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
#include "gui-entry.h"
|
2001-02-20 23:21:15 -05:00
|
|
|
#include "gui-printtext.h"
|
2001-10-28 06:30:26 -05:00
|
|
|
#include "term.h"
|
2014-11-04 06:08:27 -05:00
|
|
|
#include "recode.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2007-05-25 19:21:38 -04:00
|
|
|
#undef i_toupper
|
|
|
|
#undef i_tolower
|
|
|
|
#undef i_isalnum
|
|
|
|
|
|
|
|
static unichar i_toupper(unichar c)
|
|
|
|
{
|
|
|
|
if (term_type == TERM_TYPE_UTF8)
|
|
|
|
return g_unichar_toupper(c);
|
2015-10-02 14:29:19 -04:00
|
|
|
return c <= 255 ? toupper(c) : c;
|
2007-05-25 19:21:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static unichar i_tolower(unichar c)
|
|
|
|
{
|
|
|
|
if (term_type == TERM_TYPE_UTF8)
|
|
|
|
return g_unichar_tolower(c);
|
2015-10-02 14:29:19 -04:00
|
|
|
return c <= 255 ? tolower(c) : c;
|
2007-05-25 19:21:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int i_isalnum(unichar c)
|
|
|
|
{
|
|
|
|
if (term_type == TERM_TYPE_UTF8)
|
|
|
|
return (g_unichar_isalnum(c) || mk_wcwidth(c) == 0);
|
2015-10-02 14:29:19 -04:00
|
|
|
return c <= 255 ? isalnum(c) : 0;
|
2007-05-25 19:21:38 -04:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
GUI_ENTRY_REC *active_entry;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2002-02-15 08:38:24 -05:00
|
|
|
static void entry_text_grow(GUI_ENTRY_REC *entry, int grow_size)
|
|
|
|
{
|
|
|
|
if (entry->text_len+grow_size < entry->text_alloc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
entry->text_alloc = nearest_power(entry->text_alloc+grow_size);
|
2002-02-20 07:44:23 -05:00
|
|
|
entry->text = g_realloc(entry->text,
|
|
|
|
sizeof(unichar) * entry->text_alloc);
|
2002-02-15 08:38:24 -05:00
|
|
|
}
|
|
|
|
|
2002-01-28 22:13:06 -05:00
|
|
|
GUI_ENTRY_REC *gui_entry_create(int xpos, int ypos, int width, int utf8)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
GUI_ENTRY_REC *rec;
|
|
|
|
|
|
|
|
rec = g_new0(GUI_ENTRY_REC, 1);
|
|
|
|
rec->xpos = xpos;
|
|
|
|
rec->ypos = ypos;
|
|
|
|
rec->width = width;
|
2002-02-15 08:38:24 -05:00
|
|
|
rec->text_alloc = 1024;
|
|
|
|
rec->text = g_new(unichar, rec->text_alloc);
|
|
|
|
rec->text[0] = '\0';
|
2002-01-28 22:13:06 -05:00
|
|
|
rec->utf8 = utf8;
|
2001-10-13 12:11:13 -04:00
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_entry_destroy(GUI_ENTRY_REC *entry)
|
|
|
|
{
|
|
|
|
g_return_if_fail(entry != NULL);
|
|
|
|
|
2001-10-13 12:59:03 -04:00
|
|
|
if (active_entry == entry)
|
|
|
|
gui_entry_set_active(NULL);
|
|
|
|
|
2002-02-15 08:38:24 -05:00
|
|
|
g_free(entry->text);
|
|
|
|
g_free(entry->prompt);
|
2001-10-13 12:11:13 -04:00
|
|
|
g_free(entry);
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2004-03-24 12:28:55 -05:00
|
|
|
/* big5 functions */
|
|
|
|
#define big5_width(ch) ((ch)>0xff ? 2:1)
|
|
|
|
|
|
|
|
void unichars_to_big5(const unichar *str, char *out)
|
|
|
|
{
|
|
|
|
for (; *str != '\0'; str++) {
|
|
|
|
if (*str > 0xff)
|
|
|
|
*out++ = (*str >> 8) & 0xff;
|
|
|
|
*out++ = *str & 0xff;
|
|
|
|
}
|
|
|
|
*out = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
int strlen_big5(const unsigned char *str)
|
2003-10-19 15:09:51 -04:00
|
|
|
{
|
2004-03-24 12:28:55 -05:00
|
|
|
int len=0;
|
2003-10-19 15:09:51 -04:00
|
|
|
|
2004-03-24 12:28:55 -05:00
|
|
|
while (*str != '\0') {
|
|
|
|
if (is_big5(str[0], str[1]))
|
|
|
|
str++;
|
|
|
|
len++;
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2006-01-29 17:37:24 -05:00
|
|
|
void unichars_to_big5_with_pos(const unichar *str, int spos, char *out, int *opos)
|
|
|
|
{
|
|
|
|
const unichar *sstart = str;
|
|
|
|
char *ostart = out;
|
|
|
|
|
|
|
|
*opos = 0;
|
|
|
|
while(*str != '\0')
|
|
|
|
{
|
|
|
|
if(*str > 0xff)
|
|
|
|
*out ++ = (*str >> 8) & 0xff;
|
|
|
|
*out ++ = *str & 0xff;
|
|
|
|
str ++;
|
|
|
|
if(str - sstart == spos)
|
|
|
|
*opos = out - ostart;
|
|
|
|
}
|
|
|
|
*out = '\0';
|
|
|
|
}
|
|
|
|
|
2004-03-24 12:28:55 -05:00
|
|
|
void big5_to_unichars(const char *str, unichar *out)
|
|
|
|
{
|
|
|
|
const unsigned char *p = (const unsigned char *) str;
|
2003-10-26 01:31:19 -04:00
|
|
|
|
2004-03-24 12:28:55 -05:00
|
|
|
while (*p != '\0') {
|
|
|
|
if (is_big5(p[0], p[1])) {
|
|
|
|
*out++ = p[0] << 8 | p[1];
|
|
|
|
p += 2;
|
|
|
|
} else {
|
|
|
|
*out++ = *p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*out = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------- */
|
|
|
|
|
|
|
|
static int pos2scrpos(GUI_ENTRY_REC *entry, int pos)
|
|
|
|
{
|
2008-12-03 14:09:54 -05:00
|
|
|
int i;
|
2004-03-24 12:28:55 -05:00
|
|
|
int xpos = 0;
|
|
|
|
|
2008-12-03 14:09:54 -05:00
|
|
|
for (i = 0; i < pos; i++) {
|
|
|
|
unichar c = entry->text[i];
|
|
|
|
|
2004-03-24 12:28:55 -05:00
|
|
|
if (term_type == TERM_TYPE_BIG5)
|
2008-12-03 14:09:54 -05:00
|
|
|
xpos += big5_width(c);
|
2004-03-24 12:28:55 -05:00
|
|
|
else if (entry->utf8)
|
2008-12-03 14:09:54 -05:00
|
|
|
xpos += unichar_isprint(c) ? mk_wcwidth(c) : 1;
|
2003-10-19 15:09:51 -04:00
|
|
|
else
|
2004-03-24 12:28:55 -05:00
|
|
|
xpos++;
|
2003-10-19 15:09:51 -04:00
|
|
|
}
|
2004-03-24 12:28:55 -05:00
|
|
|
return xpos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int scrpos2pos(GUI_ENTRY_REC *entry, int pos)
|
|
|
|
{
|
|
|
|
int i, width, xpos;
|
|
|
|
|
2008-12-03 14:09:54 -05:00
|
|
|
for (i = 0, xpos = 0; i < entry->text_len; i++) {
|
|
|
|
unichar c = entry->text[i];
|
2003-10-19 15:09:51 -04:00
|
|
|
|
2004-03-24 12:28:55 -05:00
|
|
|
if (term_type == TERM_TYPE_BIG5)
|
2008-12-03 14:09:54 -05:00
|
|
|
width = big5_width(c);
|
2004-03-24 12:28:55 -05:00
|
|
|
else if (entry->utf8)
|
2008-12-03 14:09:54 -05:00
|
|
|
width = unichar_isprint(c) ? mk_wcwidth(c) : 1;
|
2004-03-24 12:28:55 -05:00
|
|
|
else
|
|
|
|
width = 1;
|
|
|
|
|
|
|
|
if (xpos + width > pos)
|
|
|
|
break;
|
|
|
|
xpos += width;
|
|
|
|
}
|
2003-10-19 15:09:51 -04:00
|
|
|
|
2004-03-24 12:28:55 -05:00
|
|
|
if (xpos == pos)
|
|
|
|
return i;
|
|
|
|
else
|
|
|
|
return i-1;
|
2003-10-19 15:09:51 -04:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
/* Fixes the cursor position in screen */
|
|
|
|
static void gui_entry_fix_cursor(GUI_ENTRY_REC *entry)
|
|
|
|
{
|
2001-10-28 13:40:12 -05:00
|
|
|
int old_scrstart;
|
|
|
|
|
2004-03-24 12:28:55 -05:00
|
|
|
/* assume prompt len == prompt scrlen */
|
|
|
|
int start = pos2scrpos(entry, entry->scrstart);
|
|
|
|
int now = pos2scrpos(entry, entry->pos);
|
|
|
|
|
|
|
|
old_scrstart = entry->scrstart;
|
|
|
|
if (now-start < entry->width - 2 - entry->promptlen && now-start > 0)
|
|
|
|
entry->scrpos = now-start;
|
|
|
|
else if (now < entry->width - 1 - entry->promptlen) {
|
2001-10-13 12:11:13 -04:00
|
|
|
entry->scrstart = 0;
|
2004-03-24 12:28:55 -05:00
|
|
|
entry->scrpos = now;
|
2000-04-26 04:03:38 -04:00
|
|
|
} else {
|
2004-03-24 12:28:55 -05:00
|
|
|
entry->scrstart = scrpos2pos(entry, now-(entry->width -
|
|
|
|
entry->promptlen)*2/3);
|
|
|
|
start = pos2scrpos(entry, entry->scrstart);
|
|
|
|
entry->scrpos = now - start;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
2001-10-28 13:40:12 -05:00
|
|
|
|
|
|
|
if (old_scrstart != entry->scrstart)
|
|
|
|
entry->redraw_needed_from = 0;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
static void gui_entry_draw_from(GUI_ENTRY_REC *entry, int pos)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2008-12-03 14:09:54 -05:00
|
|
|
int i;
|
2001-10-13 12:11:13 -04:00
|
|
|
int xpos, end_xpos;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2014-09-11 13:10:33 -04:00
|
|
|
xpos = entry->xpos + entry->promptlen +
|
|
|
|
pos2scrpos(entry, pos + entry->scrstart) -
|
2004-03-24 12:28:55 -05:00
|
|
|
pos2scrpos(entry, entry->scrstart);
|
2001-10-13 12:11:13 -04:00
|
|
|
end_xpos = entry->xpos + entry->width;
|
2004-03-24 12:28:55 -05:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
if (xpos > end_xpos)
|
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-28 06:30:26 -05:00
|
|
|
term_set_color(root_window, ATTR_RESET);
|
|
|
|
term_move(root_window, xpos, entry->ypos);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2008-12-03 14:09:54 -05:00
|
|
|
for (i = entry->scrstart + pos; i < entry->text_len; i++) {
|
|
|
|
unichar c = entry->text[i];
|
|
|
|
|
2004-03-24 12:28:55 -05:00
|
|
|
if (entry->hidden)
|
|
|
|
xpos++;
|
|
|
|
else if (term_type == TERM_TYPE_BIG5)
|
2008-12-03 14:09:54 -05:00
|
|
|
xpos += big5_width(c);
|
2004-03-24 12:28:55 -05:00
|
|
|
else if (entry->utf8)
|
2008-12-03 14:09:54 -05:00
|
|
|
xpos += unichar_isprint(c) ? mk_wcwidth(c) : 1;
|
2004-03-24 12:28:55 -05:00
|
|
|
else
|
|
|
|
xpos++;
|
|
|
|
|
2002-10-14 14:33:29 -04:00
|
|
|
if (xpos > end_xpos)
|
|
|
|
break;
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
if (entry->hidden)
|
2001-10-28 06:30:26 -05:00
|
|
|
term_addch(root_window, ' ');
|
2008-12-03 14:09:54 -05:00
|
|
|
else if (unichar_isprint(c))
|
|
|
|
term_add_unichar(root_window, c);
|
2002-02-15 08:38:24 -05:00
|
|
|
else {
|
2001-10-28 06:30:26 -05:00
|
|
|
term_set_color(root_window, ATTR_RESET|ATTR_REVERSE);
|
2008-12-03 14:09:54 -05:00
|
|
|
term_addch(root_window, (c & 127)+'A'-1);
|
2001-10-28 06:30:26 -05:00
|
|
|
term_set_color(root_window, ATTR_RESET);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
/* clear the rest of the input line */
|
2007-04-14 16:20:37 -04:00
|
|
|
if (xpos < end_xpos) {
|
2007-04-14 16:26:22 -04:00
|
|
|
if (end_xpos == term_width)
|
|
|
|
term_clrtoeol(root_window);
|
|
|
|
else {
|
|
|
|
while (xpos < end_xpos) {
|
|
|
|
term_addch(root_window, ' ');
|
|
|
|
xpos++;
|
|
|
|
}
|
2001-10-13 12:11:13 -04:00
|
|
|
}
|
|
|
|
}
|
2001-10-28 13:40:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gui_entry_draw(GUI_ENTRY_REC *entry)
|
|
|
|
{
|
|
|
|
if (entry->redraw_needed_from >= 0) {
|
|
|
|
gui_entry_draw_from(entry, entry->redraw_needed_from);
|
|
|
|
entry->redraw_needed_from = -1;
|
|
|
|
}
|
2001-10-13 12:11:13 -04:00
|
|
|
|
2001-10-28 06:30:26 -05:00
|
|
|
term_move_cursor(entry->xpos + entry->scrpos + entry->promptlen,
|
|
|
|
entry->ypos);
|
|
|
|
term_refresh(NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-10-28 13:40:12 -05:00
|
|
|
static void gui_entry_redraw_from(GUI_ENTRY_REC *entry, int pos)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-28 13:40:12 -05:00
|
|
|
pos -= entry->scrstart;
|
|
|
|
if (pos < 0) pos = 0;
|
|
|
|
|
|
|
|
if (entry->redraw_needed_from == -1 ||
|
|
|
|
entry->redraw_needed_from > pos)
|
|
|
|
entry->redraw_needed_from = pos;
|
2001-10-13 12:11:13 -04:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
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;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
if (entry->width == width)
|
|
|
|
return; /* no changes */
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
if (width > entry->width) {
|
|
|
|
/* input line grew - need to draw text at the end */
|
|
|
|
old_width = width;
|
|
|
|
entry->width = width;
|
2001-10-28 13:40:12 -05:00
|
|
|
gui_entry_redraw_from(entry, old_width);
|
2001-10-13 12:11:13 -04:00
|
|
|
} else {
|
|
|
|
/* input line shrinked - make sure the cursor
|
|
|
|
is inside the input line */
|
2001-10-24 10:13:42 -04:00
|
|
|
entry->width = width;
|
2001-10-13 12:11:13 -04:00
|
|
|
if (entry->pos - entry->scrstart >
|
|
|
|
entry->width-2 - entry->promptlen) {
|
|
|
|
gui_entry_fix_cursor(entry);
|
|
|
|
}
|
|
|
|
}
|
2001-10-28 13:40:12 -05:00
|
|
|
|
|
|
|
gui_entry_draw(entry);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
void gui_entry_set_active(GUI_ENTRY_REC *entry)
|
2000-05-04 06:32:42 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
active_entry = entry;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-10-13 12:59:03 -04:00
|
|
|
if (entry != NULL) {
|
2001-10-28 06:30:26 -05:00
|
|
|
term_move_cursor(entry->xpos + entry->scrpos +
|
|
|
|
entry->promptlen, entry->ypos);
|
|
|
|
term_refresh(NULL);
|
2001-10-13 12:59:03 -04:00
|
|
|
}
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
2014-11-04 06:08:27 -05:00
|
|
|
/* Return screen length of plain string */
|
|
|
|
static int scrlen_str(const char *str)
|
|
|
|
{
|
|
|
|
int len = 0;
|
|
|
|
char *stripped;
|
|
|
|
g_return_val_if_fail(str != NULL, 0);
|
|
|
|
|
|
|
|
str = stripped = strip_codes(str);
|
|
|
|
if (is_utf8() && g_utf8_validate(str, -1, NULL)) {
|
|
|
|
|
|
|
|
while (*str != '\0') {
|
|
|
|
gunichar c;
|
|
|
|
|
|
|
|
c = g_utf8_get_char(str);
|
|
|
|
str = g_utf8_next_char(str);
|
|
|
|
|
|
|
|
len += unichar_isprint(c) ? mk_wcwidth(c) : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
len = strlen(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(stripped);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
void gui_entry_set_prompt(GUI_ENTRY_REC *entry, const char *str)
|
2001-01-04 13:01:51 -05:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
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);
|
2014-11-04 06:08:27 -05:00
|
|
|
entry->promptlen = scrlen_str(str);
|
2001-10-13 12:11:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (entry->prompt != NULL)
|
2014-11-04 06:08:27 -05:00
|
|
|
gui_printtext_internal(entry->xpos, entry->ypos, entry->prompt);
|
2001-10-13 12:11:13 -04:00
|
|
|
|
|
|
|
if (entry->promptlen != oldlen) {
|
|
|
|
gui_entry_fix_cursor(entry);
|
|
|
|
gui_entry_draw(entry);
|
|
|
|
}
|
2001-01-04 13:01:51 -05:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
void gui_entry_set_hidden(GUI_ENTRY_REC *entry, int hidden)
|
2000-05-04 06:32:42 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
g_return_if_fail(entry != NULL);
|
|
|
|
|
|
|
|
entry->hidden = hidden;
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
2002-01-28 22:13:06 -05:00
|
|
|
void gui_entry_set_utf8(GUI_ENTRY_REC *entry, int utf8)
|
|
|
|
{
|
|
|
|
g_return_if_fail(entry != NULL);
|
|
|
|
|
|
|
|
entry->utf8 = utf8;
|
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
void gui_entry_set_text(GUI_ENTRY_REC *entry, const char *str)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2002-02-15 08:38:24 -05:00
|
|
|
g_return_if_fail(entry != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
g_return_if_fail(str != NULL);
|
|
|
|
|
2002-02-15 08:38:24 -05:00
|
|
|
entry->text_len = 0;
|
|
|
|
entry->pos = 0;
|
|
|
|
entry->text[0] = '\0';
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2002-02-15 08:38:24 -05:00
|
|
|
gui_entry_insert_text(entry, str);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
char *gui_entry_get_text(GUI_ENTRY_REC *entry)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2002-02-15 08:38:24 -05:00
|
|
|
char *buf;
|
|
|
|
int i;
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
g_return_val_if_fail(entry != NULL, NULL);
|
|
|
|
|
2002-02-15 08:38:24 -05:00
|
|
|
if (entry->utf8)
|
2008-12-09 06:59:16 -05:00
|
|
|
buf = g_ucs4_to_utf8(entry->text, -1, NULL, NULL, NULL);
|
2002-02-15 08:38:24 -05:00
|
|
|
else {
|
2008-12-09 06:59:16 -05:00
|
|
|
buf = g_malloc(entry->text_len*6 + 1);
|
2004-03-24 12:28:55 -05:00
|
|
|
if (term_type == TERM_TYPE_BIG5)
|
|
|
|
unichars_to_big5(entry->text, buf);
|
|
|
|
else
|
|
|
|
for (i = 0; i <= entry->text_len; i++)
|
|
|
|
buf[i] = entry->text[i];
|
2002-02-15 08:38:24 -05:00
|
|
|
}
|
|
|
|
return buf;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2006-01-29 17:37:24 -05:00
|
|
|
char *gui_entry_get_text_and_pos(GUI_ENTRY_REC *entry, int *pos)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
g_return_val_if_fail(entry != NULL, NULL);
|
|
|
|
|
2008-12-09 06:59:16 -05:00
|
|
|
if (entry->utf8) {
|
|
|
|
buf = g_ucs4_to_utf8(entry->text, -1, NULL, NULL, NULL);
|
|
|
|
*pos = g_utf8_offset_to_pointer(buf, entry->pos) - buf;
|
|
|
|
} else {
|
|
|
|
buf = g_malloc(entry->text_len*6 + 1);
|
2006-01-29 17:37:24 -05:00
|
|
|
if(term_type==TERM_TYPE_BIG5)
|
|
|
|
unichars_to_big5_with_pos(entry->text, entry->pos, buf, pos);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i <= entry->text_len; i++)
|
|
|
|
buf[i] = entry->text[i];
|
|
|
|
*pos = entry->pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
void gui_entry_insert_text(GUI_ENTRY_REC *entry, const char *str)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2002-02-15 08:38:24 -05:00
|
|
|
unichar chr;
|
|
|
|
int i, len;
|
2008-12-09 06:59:16 -05:00
|
|
|
const char *ptr;
|
2002-02-15 08:38:24 -05:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
g_return_if_fail(entry != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
g_return_if_fail(str != NULL);
|
|
|
|
|
2001-10-28 13:40:12 -05:00
|
|
|
gui_entry_redraw_from(entry, entry->pos);
|
2002-02-15 08:38:24 -05:00
|
|
|
|
2008-12-09 06:59:16 -05:00
|
|
|
if (entry->utf8) {
|
|
|
|
g_utf8_validate(str, -1, &ptr);
|
|
|
|
len = g_utf8_pointer_to_offset(str, ptr);
|
|
|
|
} else if (term_type == TERM_TYPE_BIG5)
|
2014-07-06 13:56:17 -04:00
|
|
|
len = strlen_big5((const unsigned char *)str);
|
2008-11-18 04:59:54 -05:00
|
|
|
else
|
|
|
|
len = strlen(str);
|
2002-02-15 08:38:24 -05:00
|
|
|
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) {
|
2004-03-24 12:28:55 -05:00
|
|
|
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];
|
|
|
|
}
|
2002-02-15 08:38:24 -05:00
|
|
|
} else {
|
2008-12-09 06:59:16 -05:00
|
|
|
ptr = str;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
entry->text[entry->pos + i] = g_utf8_get_char(ptr);
|
|
|
|
ptr = g_utf8_next_char(ptr);
|
|
|
|
}
|
2002-02-15 08:38:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
entry->text_len += len;
|
|
|
|
entry->pos += len;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
gui_entry_fix_cursor(entry);
|
|
|
|
gui_entry_draw(entry);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2002-02-15 08:38:24 -05:00
|
|
|
void gui_entry_insert_char(GUI_ENTRY_REC *entry, unichar chr)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
g_return_if_fail(entry != NULL);
|
|
|
|
|
2001-12-19 10:25:16 -05:00
|
|
|
if (chr == 0 || chr == 13 || chr == 10)
|
|
|
|
return; /* never insert NUL, CR or LF characters */
|
2001-08-08 12:39:27 -04:00
|
|
|
|
2007-05-25 18:06:32 -04:00
|
|
|
if (entry->utf8 && entry->pos == 0 && mk_wcwidth(chr) == 0)
|
|
|
|
return;
|
|
|
|
|
2001-10-28 13:40:12 -05:00
|
|
|
gui_entry_redraw_from(entry, entry->pos);
|
2002-02-15 08:38:24 -05:00
|
|
|
|
|
|
|
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++;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
gui_entry_fix_cursor(entry);
|
|
|
|
gui_entry_draw(entry);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2002-02-15 08:38:24 -05:00
|
|
|
char *gui_entry_get_cutbuffer(GUI_ENTRY_REC *entry)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
g_return_val_if_fail(entry != NULL, NULL);
|
|
|
|
|
2002-02-25 12:28:55 -05:00
|
|
|
if (entry->cutbuffer == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2002-02-15 08:38:24 -05:00
|
|
|
if (entry->utf8)
|
2008-12-09 06:59:16 -05:00
|
|
|
buf = g_ucs4_to_utf8(entry->cutbuffer, -1, NULL, NULL, NULL);
|
2008-12-09 06:45:23 -05:00
|
|
|
else {
|
2008-12-09 06:59:16 -05:00
|
|
|
buf = g_malloc(entry->cutbuffer_len*6 + 1);
|
2008-12-09 06:45:23 -05:00
|
|
|
if (term_type == TERM_TYPE_BIG5)
|
|
|
|
unichars_to_big5(entry->cutbuffer, buf);
|
|
|
|
else
|
|
|
|
for (i = 0; i <= entry->cutbuffer_len; i++)
|
|
|
|
buf[i] = entry->cutbuffer[i];
|
2002-02-15 08:38:24 -05:00
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2015-11-13 13:42:28 -05:00
|
|
|
void gui_entry_erase_to(GUI_ENTRY_REC *entry, int pos, CUTBUFFER_UPDATE_OP update_cutbuffer)
|
2003-10-19 15:09:51 -04:00
|
|
|
{
|
|
|
|
int newpos, size = 0;
|
|
|
|
|
|
|
|
g_return_if_fail(entry != NULL);
|
|
|
|
|
|
|
|
for (newpos = gui_entry_get_pos(entry); newpos > pos; size++)
|
2004-03-24 12:28:55 -05:00
|
|
|
newpos = newpos - 1;
|
2003-10-19 15:09:51 -04:00
|
|
|
gui_entry_erase(entry, size, update_cutbuffer);
|
|
|
|
}
|
|
|
|
|
2015-11-13 13:42:28 -05:00
|
|
|
void gui_entry_erase(GUI_ENTRY_REC *entry, int size, CUTBUFFER_UPDATE_OP update_cutbuffer)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2007-02-07 13:20:49 -05:00
|
|
|
size_t w = 0;
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
g_return_if_fail(entry != NULL);
|
|
|
|
|
2007-12-12 07:35:14 -05:00
|
|
|
if (size == 0 || entry->pos < size)
|
2001-10-13 12:11:13 -04:00
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2016-02-10 09:47:10 -05:00
|
|
|
if (entry->cutbuffer_len == 0) {
|
|
|
|
update_cutbuffer = CUTBUFFER_UPDATE_REPLACE;
|
|
|
|
}
|
|
|
|
int cutbuffer_new_size = entry->cutbuffer_len + size;
|
|
|
|
unichar *tmpcutbuffer = entry->cutbuffer;
|
2015-11-13 13:42:28 -05:00
|
|
|
switch (update_cutbuffer) {
|
2016-01-30 09:34:46 -05:00
|
|
|
case CUTBUFFER_UPDATE_APPEND:
|
2016-01-30 11:32:08 -05:00
|
|
|
entry->cutbuffer = g_new(unichar, cutbuffer_new_size+1);
|
|
|
|
memcpy(entry->cutbuffer, tmpcutbuffer,
|
|
|
|
entry->cutbuffer_len * sizeof(unichar));
|
|
|
|
memcpy(entry->cutbuffer + entry->cutbuffer_len * sizeof(unichar),
|
|
|
|
entry->text + entry->pos - size, size * sizeof(unichar));
|
|
|
|
|
|
|
|
entry->cutbuffer_len = cutbuffer_new_size;
|
|
|
|
entry->cutbuffer[cutbuffer_new_size] = '\0';
|
|
|
|
g_free(tmpcutbuffer);
|
|
|
|
break;
|
2015-11-02 08:00:52 -05:00
|
|
|
|
2016-01-30 09:34:46 -05:00
|
|
|
case CUTBUFFER_UPDATE_PREPEND:
|
2016-01-30 11:32:08 -05:00
|
|
|
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;
|
2015-11-02 08:00:52 -05:00
|
|
|
|
2015-11-13 13:42:28 -05:00
|
|
|
case CUTBUFFER_UPDATE_REPLACE:
|
2015-11-02 08:00:52 -05:00
|
|
|
/* put erased text to cutbuffer */
|
|
|
|
if (entry->cutbuffer_len < size) {
|
|
|
|
g_free(entry->cutbuffer);
|
|
|
|
entry->cutbuffer = g_new(unichar, size+1);
|
|
|
|
}
|
2015-11-13 13:42:28 -05:00
|
|
|
|
2015-11-02 08:00:52 -05:00
|
|
|
entry->cutbuffer_len = size;
|
|
|
|
entry->cutbuffer[size] = '\0';
|
2016-02-10 09:47:10 -05:00
|
|
|
memcpy(entry->cutbuffer, entry->text + entry->pos - size, size * sizeof(unichar));
|
2015-11-13 13:42:28 -05:00
|
|
|
break;
|
2016-01-30 09:34:46 -05:00
|
|
|
|
2015-11-13 13:42:28 -05:00
|
|
|
case CUTBUFFER_UPDATE_NOOP:
|
|
|
|
break;
|
2002-02-20 07:46:45 -05:00
|
|
|
}
|
2002-02-15 08:38:24 -05:00
|
|
|
|
2007-02-07 13:20:49 -05:00
|
|
|
if (entry->utf8)
|
2008-12-03 15:14:58 -05:00
|
|
|
while (entry->pos-size-w > 0 &&
|
|
|
|
mk_wcwidth(entry->text[entry->pos-size-w]) == 0) w++;
|
2007-02-07 13:20:49 -05:00
|
|
|
|
2002-02-15 08:38:24 -05:00
|
|
|
g_memmove(entry->text + entry->pos - size, entry->text + entry->pos,
|
|
|
|
(entry->text_len-entry->pos+1) * sizeof(unichar));
|
2001-05-01 05:38:06 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
entry->pos -= size;
|
2002-02-15 08:38:24 -05:00
|
|
|
entry->text_len -= size;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2007-02-07 13:20:49 -05:00
|
|
|
gui_entry_redraw_from(entry, entry->pos-w);
|
2001-10-13 12:11:13 -04:00
|
|
|
gui_entry_fix_cursor(entry);
|
|
|
|
gui_entry_draw(entry);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2007-05-25 18:21:39 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-11-13 13:42:28 -05:00
|
|
|
void gui_entry_erase_word(GUI_ENTRY_REC *entry, int to_space, CUTBUFFER_UPDATE_OP cutbuffer_op)
|
2000-06-14 14:02:13 -04:00
|
|
|
{
|
|
|
|
int to;
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
g_return_if_fail(entry != NULL);
|
|
|
|
if (entry->pos == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
to = entry->pos - 1;
|
2000-06-14 14:02:13 -04:00
|
|
|
|
2001-10-14 07:32:06 -04:00
|
|
|
if (to_space) {
|
2002-02-15 08:38:24 -05:00
|
|
|
while (entry->text[to] == ' ' && to > 0)
|
2001-10-14 07:32:06 -04:00
|
|
|
to--;
|
2002-02-15 08:38:24 -05:00
|
|
|
while (entry->text[to] != ' ' && to > 0)
|
2001-10-14 07:32:06 -04:00
|
|
|
to--;
|
|
|
|
} else {
|
2002-02-15 08:38:24 -05:00
|
|
|
while (!i_isalnum(entry->text[to]) && to > 0)
|
2001-10-14 07:32:06 -04:00
|
|
|
to--;
|
2002-02-15 08:38:24 -05:00
|
|
|
while (i_isalnum(entry->text[to]) && to > 0)
|
2001-10-14 07:32:06 -04:00
|
|
|
to--;
|
|
|
|
}
|
|
|
|
if (to > 0) to++;
|
2000-06-14 14:02:13 -04:00
|
|
|
|
2015-11-14 09:07:35 -05:00
|
|
|
gui_entry_erase(entry, entry->pos-to, CUTBUFFER_UPDATE_REPLACE);
|
2000-06-14 14:02:13 -04:00
|
|
|
}
|
|
|
|
|
2001-10-14 07:32:06 -04:00
|
|
|
void gui_entry_erase_next_word(GUI_ENTRY_REC *entry, int to_space)
|
2001-03-03 13:04:10 -05:00
|
|
|
{
|
2002-02-15 08:38:24 -05:00
|
|
|
int to, size;
|
2001-10-13 12:11:13 -04:00
|
|
|
|
|
|
|
g_return_if_fail(entry != NULL);
|
2002-02-15 08:38:24 -05:00
|
|
|
if (entry->pos == entry->text_len)
|
2001-10-13 12:11:13 -04:00
|
|
|
return;
|
2001-03-03 13:04:10 -05:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
to = entry->pos;
|
2001-10-14 07:32:06 -04:00
|
|
|
if (to_space) {
|
2002-02-15 08:38:24 -05:00
|
|
|
while (entry->text[to] == ' ' && to < entry->text_len)
|
2001-10-14 07:32:06 -04:00
|
|
|
to++;
|
2002-02-15 08:38:24 -05:00
|
|
|
while (entry->text[to] != ' ' && to < entry->text_len)
|
2001-10-14 07:32:06 -04:00
|
|
|
to++;
|
|
|
|
} else {
|
2002-02-15 08:38:24 -05:00
|
|
|
while (!i_isalnum(entry->text[to]) && to < entry->text_len)
|
2001-10-14 07:32:06 -04:00
|
|
|
to++;
|
2002-02-15 08:38:24 -05:00
|
|
|
while (i_isalnum(entry->text[to]) && to < entry->text_len)
|
2001-10-14 07:32:06 -04:00
|
|
|
to++;
|
|
|
|
}
|
2001-03-03 13:04:10 -05:00
|
|
|
|
2002-02-15 08:38:24 -05:00
|
|
|
size = to-entry->pos;
|
|
|
|
entry->pos = to;
|
2015-11-13 13:42:28 -05:00
|
|
|
gui_entry_erase(entry, size, CUTBUFFER_UPDATE_REPLACE);
|
2001-03-03 13:04:10 -05:00
|
|
|
}
|
|
|
|
|
2002-02-15 11:02:14 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2005-08-27 18:06:34 -04:00
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
2014-09-11 13:10:33 -04:00
|
|
|
|
2005-08-27 18:06:34 -04:00
|
|
|
gui_entry_redraw_from(entry, spos1);
|
|
|
|
gui_entry_fix_cursor(entry);
|
|
|
|
gui_entry_draw(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_entry_capitalize_word(GUI_ENTRY_REC *entry)
|
|
|
|
{
|
|
|
|
int pos = entry->pos;
|
2005-11-02 16:05:24 -05:00
|
|
|
while (pos < entry->text_len && !i_isalnum(entry->text[pos]))
|
2005-08-27 18:06:34 -04:00
|
|
|
pos++;
|
|
|
|
|
|
|
|
if (pos < entry->text_len) {
|
2005-11-02 16:05:24 -05:00
|
|
|
entry->text[pos] = i_toupper(entry->text[pos]);
|
2005-08-27 18:06:34 -04:00
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
|
2005-11-02 16:05:24 -05:00
|
|
|
while (pos < entry->text_len && i_isalnum(entry->text[pos])) {
|
|
|
|
entry->text[pos] = i_tolower(entry->text[pos]);
|
2005-08-27 18:06:34 -04:00
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
gui_entry_redraw_from(entry, entry->pos);
|
|
|
|
entry->pos = pos;
|
|
|
|
gui_entry_fix_cursor(entry);
|
|
|
|
gui_entry_draw(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_entry_downcase_word(GUI_ENTRY_REC *entry)
|
|
|
|
{
|
|
|
|
int pos = entry->pos;
|
2005-11-02 16:05:24 -05:00
|
|
|
while (pos < entry->text_len && !i_isalnum(entry->text[pos]))
|
2005-08-27 18:06:34 -04:00
|
|
|
pos++;
|
|
|
|
|
2005-11-02 16:05:24 -05:00
|
|
|
while (pos < entry->text_len && i_isalnum(entry->text[pos])) {
|
|
|
|
entry->text[pos] = i_tolower(entry->text[pos]);
|
2005-08-27 18:06:34 -04:00
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
gui_entry_redraw_from(entry, entry->pos);
|
|
|
|
entry->pos = pos;
|
|
|
|
gui_entry_fix_cursor(entry);
|
|
|
|
gui_entry_draw(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gui_entry_upcase_word(GUI_ENTRY_REC *entry)
|
|
|
|
{
|
|
|
|
int pos = entry->pos;
|
2005-11-02 16:05:24 -05:00
|
|
|
while (pos < entry->text_len && !i_isalnum(entry->text[pos]))
|
2005-08-27 18:06:34 -04:00
|
|
|
pos++;
|
|
|
|
|
2005-11-02 16:05:24 -05:00
|
|
|
while (pos < entry->text_len && i_isalnum(entry->text[pos])) {
|
|
|
|
entry->text[pos] = i_toupper(entry->text[pos]);
|
2005-08-27 18:06:34 -04:00
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
gui_entry_redraw_from(entry, entry->pos);
|
|
|
|
entry->pos = pos;
|
|
|
|
gui_entry_fix_cursor(entry);
|
|
|
|
gui_entry_draw(entry);
|
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
int gui_entry_get_pos(GUI_ENTRY_REC *entry)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
g_return_val_if_fail(entry != NULL, 0);
|
|
|
|
|
|
|
|
return entry->pos;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
void gui_entry_set_pos(GUI_ENTRY_REC *entry, int pos)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
g_return_if_fail(entry != NULL);
|
|
|
|
|
2002-02-15 08:38:24 -05:00
|
|
|
if (pos >= 0 && pos <= entry->text_len)
|
2001-10-13 12:11:13 -04:00
|
|
|
entry->pos = pos;
|
2000-06-14 13:44:03 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
gui_entry_fix_cursor(entry);
|
|
|
|
gui_entry_draw(entry);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
void gui_entry_move_pos(GUI_ENTRY_REC *entry, int pos)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
g_return_if_fail(entry != NULL);
|
|
|
|
|
2004-03-24 12:28:55 -05:00
|
|
|
if (entry->pos + pos >= 0 && entry->pos + pos <= entry->text_len)
|
|
|
|
entry->pos += pos;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2007-05-25 18:13:24 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
gui_entry_fix_cursor(entry);
|
|
|
|
gui_entry_draw(entry);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-10-25 10:39:36 -04:00
|
|
|
static void gui_entry_move_words_left(GUI_ENTRY_REC *entry, int count, int to_space)
|
2000-07-22 20:29:31 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
int pos;
|
2000-07-22 20:29:31 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
pos = entry->pos;
|
2000-07-22 20:29:31 -04:00
|
|
|
while (count > 0 && pos > 0) {
|
2001-10-25 10:39:36 -04:00
|
|
|
if (to_space) {
|
2002-02-15 08:38:24 -05:00
|
|
|
while (pos > 0 && entry->text[pos-1] == ' ')
|
2001-10-25 10:39:36 -04:00
|
|
|
pos--;
|
2002-02-15 08:38:24 -05:00
|
|
|
while (pos > 0 && entry->text[pos-1] != ' ')
|
2001-10-25 10:39:36 -04:00
|
|
|
pos--;
|
|
|
|
} else {
|
2002-02-15 08:38:24 -05:00
|
|
|
while (pos > 0 && !i_isalnum(entry->text[pos-1]))
|
2001-10-25 10:39:36 -04:00
|
|
|
pos--;
|
2002-02-15 08:38:24 -05:00
|
|
|
while (pos > 0 && i_isalnum(entry->text[pos-1]))
|
2001-10-25 10:39:36 -04:00
|
|
|
pos--;
|
|
|
|
}
|
2000-07-22 20:29:31 -04:00
|
|
|
count--;
|
|
|
|
}
|
2001-10-13 12:11:13 -04:00
|
|
|
|
|
|
|
entry->pos = pos;
|
2000-07-22 20:29:31 -04:00
|
|
|
}
|
|
|
|
|
2001-10-25 10:39:36 -04:00
|
|
|
static void gui_entry_move_words_right(GUI_ENTRY_REC *entry, int count, int to_space)
|
2000-07-22 20:29:31 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
int pos;
|
2000-07-22 20:29:31 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
pos = entry->pos;
|
2002-02-15 08:38:24 -05:00
|
|
|
while (count > 0 && pos < entry->text_len) {
|
2001-10-25 10:39:36 -04:00
|
|
|
if (to_space) {
|
2002-02-15 08:38:24 -05:00
|
|
|
while (pos < entry->text_len && entry->text[pos] == ' ')
|
2001-10-25 10:39:36 -04:00
|
|
|
pos++;
|
2002-02-15 08:38:24 -05:00
|
|
|
while (pos < entry->text_len && entry->text[pos] != ' ')
|
2001-10-25 10:39:36 -04:00
|
|
|
pos++;
|
|
|
|
} else {
|
2002-02-15 08:38:24 -05:00
|
|
|
while (pos < entry->text_len && !i_isalnum(entry->text[pos]))
|
2001-10-25 10:39:36 -04:00
|
|
|
pos++;
|
2002-02-15 08:38:24 -05:00
|
|
|
while (pos < entry->text_len && i_isalnum(entry->text[pos]))
|
2001-10-25 10:39:36 -04:00
|
|
|
pos++;
|
|
|
|
}
|
2000-07-22 20:29:31 -04:00
|
|
|
count--;
|
|
|
|
}
|
2001-10-13 12:11:13 -04:00
|
|
|
|
|
|
|
entry->pos = pos;
|
2000-07-22 20:29:31 -04:00
|
|
|
}
|
|
|
|
|
2001-10-25 10:39:36 -04:00
|
|
|
void gui_entry_move_words(GUI_ENTRY_REC *entry, int count, int to_space)
|
2000-07-22 20:29:31 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
g_return_if_fail(entry != NULL);
|
|
|
|
|
2000-07-22 20:29:31 -04:00
|
|
|
if (count < 0)
|
2001-10-25 10:39:36 -04:00
|
|
|
gui_entry_move_words_left(entry, -count, to_space);
|
2000-07-22 20:29:31 -04:00
|
|
|
else if (count > 0)
|
2001-10-25 10:39:36 -04:00
|
|
|
gui_entry_move_words_right(entry, count, to_space);
|
2000-07-22 20:29:31 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
gui_entry_fix_cursor(entry);
|
|
|
|
gui_entry_draw(entry);
|
2000-07-22 20:29:31 -04:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
void gui_entry_redraw(GUI_ENTRY_REC *entry)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
g_return_if_fail(entry != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
gui_entry_set_prompt(entry, NULL);
|
2001-10-28 13:40:12 -05:00
|
|
|
gui_entry_redraw_from(entry, 0);
|
2001-10-13 12:11:13 -04:00
|
|
|
gui_entry_fix_cursor(entry);
|
|
|
|
gui_entry_draw(entry);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|