4 Copyright (C) 1999 Timo Sirainen
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "gui-printtext.h"
27 static GString *entry;
28 static int promptlen, permanent_prompt, pos, scrstart, scrpos;
29 static int prompt_hidden;
32 static void entry_screenpos(void)
34 if (pos-scrstart < COLS-2-promptlen && pos-scrstart > 0) {
35 scrpos = pos-scrstart;
39 if (pos < COLS-1-promptlen) {
43 scrpos = (COLS-promptlen)*2/3;
44 scrstart = pos-scrpos;
48 static void entry_update(void)
53 len = entry->len-scrstart > COLS-1-promptlen ?
54 COLS-1-promptlen : entry->len-scrstart;
57 move(LINES-1, promptlen);
59 for (p = entry->str+scrstart, n = 0; n < len; n++, p++) {
62 else if ((unsigned char) *p >= 32)
63 addch((unsigned char) *p);
65 set_color(stdscr, ATTR_REVERSE);
72 move_cursor(LINES-1, scrpos+promptlen);
76 void gui_entry_set_prompt(const char *str)
79 if (permanent_prompt) return;
81 g_free_not_null(prompt);
82 prompt = g_strdup(str);
83 promptlen = format_get_length(prompt);
87 gui_printtext(0, LINES-1, prompt);
93 void gui_entry_set_perm_prompt(const char *str)
95 g_return_if_fail(str != NULL);
97 g_free_not_null(prompt);
98 prompt = g_strdup(str);
99 promptlen = format_get_length(prompt);
101 permanent_prompt = TRUE;
102 gui_entry_set_prompt(NULL);
105 void gui_entry_set_hidden(int hidden)
107 prompt_hidden = hidden;
110 void gui_entry_remove_perm_prompt(void)
112 permanent_prompt = FALSE;
115 void gui_entry_set_text(const char *str)
117 g_return_if_fail(str != NULL);
119 g_string_assign(entry, str);
126 char *gui_entry_get_text(void)
131 void gui_entry_insert_text(const char *str)
133 g_return_if_fail(str != NULL);
135 g_string_insert(entry, pos, str);
142 void gui_entry_insert_char(char chr)
144 g_string_insert_c(entry, pos, chr);
151 void gui_entry_erase(int size)
153 if (pos < size) return;
156 if (is_big5(entry->str[pos-2], entry->str[pos-1]))
161 g_string_erase(entry, pos, size);
167 void gui_entry_erase_word(void)
171 if (pos == 0) return;
175 while (entry->str[to] == ' ' && to > 0)
178 while (entry->str[to] != ' ' && to > 0)
181 if (entry->str[to] == ' ' && to > 0)
184 g_string_erase(entry, to, pos - to);
191 void gui_entry_erase_next_word(void)
195 if (pos == entry->len) return;
197 while (entry->str[to] == ' ' && to < entry->len)
200 while (entry->str[to] != ' ' && to < entry->len)
203 g_string_erase(entry, pos, to - pos);
209 int gui_entry_get_pos(void)
214 void gui_entry_set_pos(int p)
216 if (p >= 0 && p <= entry->len)
223 void gui_entry_move_pos(int p)
226 if (p > 0 && is_big5 (entry->str[pos], entry->str[pos+1]))
228 else if (p < 0 && is_big5 (entry->str[pos-1], entry->str[pos]))
232 if (pos+p >= 0 && pos+p <= entry->len)
239 static void gui_entry_move_words_left(int count)
241 if (pos == 0) return;
243 while (count > 0 && pos > 0) {
244 while (pos > 0 && entry->str[pos-1] == ' ')
246 while (pos > 0 && entry->str[pos-1] != ' ')
252 static void gui_entry_move_words_right(int count)
254 if (pos == entry->len) return;
256 while (count > 0 && pos < entry->len) {
257 while (pos < entry->len && entry->str[pos] != ' ')
259 while (pos < entry->len && entry->str[pos] == ' ')
265 void gui_entry_move_words(int count)
268 gui_entry_move_words_left(-count);
270 gui_entry_move_words_right(count);
276 void gui_entry_redraw(void)
278 gui_entry_set_prompt(NULL);
284 void gui_entry_init(void)
286 entry = g_string_new(NULL);
289 prompt = NULL; promptlen = 0;
290 permanent_prompt = FALSE;
291 prompt_hidden = FALSE;
294 void gui_entry_deinit(void)
296 if (prompt != NULL) g_free(prompt);
297 g_string_free(entry, TRUE);