2 * Changes Copyright (C) 1995 by Andrey A. Chernov, Moscow
6 * AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "dialog.priv.h"
27 static void redraw_field(WINDOW
*dialog
, int box_y
, int box_x
, int flen
, int box_width
, unsigned char instr
[], int input_x
, int scroll
, chtype attr
, chtype old_attr
, int fexit
, int attr_mask
);
32 int line_edit(WINDOW
* dialog
, int box_y
, int box_x
, int flen
, int box_width
, chtype attr
, int first
, unsigned char *result
, int attr_mask
)
36 static int input_x
, scroll
;
37 static unsigned char instr
[MAX_LEN
+1];
38 unsigned char erase_char
= erasechar();
39 unsigned char kill_char
= killchar();
41 unsignec
char werase_char
= cur_term
->Ottyb
.c_cc
[VWERASE
];
44 old_attr
= getattrs(dialog
);
48 memset(instr
, 0, sizeof(instr
));
49 strcpy(instr
, result
);
51 /* input_x = i % box_width;*/
52 input_x
= (i
> box_width
) ? box_width
- 1 : i
;
53 /* scroll = i - input_x;*/
54 scroll
= (i
> box_width
) ? i
- box_width
+ 1: 0;
56 redraw_field(dialog
, box_y
, box_x
, flen
, box_width
, instr
, input_x
, scroll
, attr
, old_attr
, FALSE
, attr_mask
);
59 wattrset(dialog
, attr
);
76 for (i
= strlen(instr
) - 1; i
>= scroll
+ input_x
&& instr
[i
] == ' '; i
--)
88 memset(instr
+ scroll
+ input_x
, '\0', sizeof(instr
) - scroll
- input_x
);
89 redraw_field(dialog
, box_y
, box_x
, flen
, box_width
, instr
, input_x
, scroll
, attr
, old_attr
, FALSE
, attr_mask
);
94 redraw_field(dialog
, box_y
, box_x
, flen
, box_width
, instr
, input_x
, scroll
, attr
, old_attr
, FALSE
, attr_mask
);
98 for (i
= strlen(instr
) - 1; i
>= scroll
+ input_x
&& instr
[i
] == ' '; i
--)
101 input_x
= i
% box_width
;
102 scroll
= i
- input_x
;
103 redraw_field(dialog
, box_y
, box_x
, flen
, box_width
, instr
, input_x
, scroll
, attr
, old_attr
, FALSE
, attr_mask
);
107 if (input_x
|| scroll
) {
109 int oldscroll
= scroll
;
110 scroll
= scroll
< box_width
-1 ? 0 : scroll
-(box_width
-1);
111 input_x
= oldscroll
- 1 - scroll
;
112 redraw_field(dialog
, box_y
, box_x
, flen
, box_width
, instr
, input_x
, scroll
, attr
, old_attr
, FALSE
, attr_mask
);
115 wmove(dialog
, box_y
, input_x
+ box_x
);
122 if ( scroll
+input_x
< MAX_LEN
123 && (flen
< 0 || scroll
+input_x
< flen
)
125 if (!instr
[scroll
+input_x
])
126 instr
[scroll
+input_x
] = ' ';
127 if (input_x
== box_width
-1) {
129 redraw_field(dialog
, box_y
, box_x
, flen
, box_width
, instr
, input_x
, scroll
, attr
, old_attr
, FALSE
, attr_mask
);
132 wmove(dialog
, box_y
, input_x
+ box_x
);
133 waddch(dialog
, instr
[scroll
+input_x
]);
137 beep(); /* Alarm user about overflow */
143 if (input_x
|| scroll
) {
145 memmove(instr
+scroll
+input_x
-1, instr
+scroll
+input_x
, i
-(scroll
+input_x
)+1);
147 int oldscroll
= scroll
;
148 scroll
= scroll
< box_width
-1 ? 0 : scroll
-(box_width
-1);
149 input_x
= oldscroll
- 1 - scroll
;
152 redraw_field(dialog
, box_y
, box_x
, flen
, box_width
, instr
, input_x
, scroll
, attr
, old_attr
, FALSE
, attr_mask
);
158 for (i
= strlen(instr
) - 1; i
>= scroll
+ input_x
&& instr
[i
] == ' '; i
--)
165 memmove(instr
+scroll
+input_x
, instr
+scroll
+input_x
+1, i
-(scroll
+input_x
));
166 redraw_field(dialog
, box_y
, box_x
, flen
, box_width
, instr
, input_x
, scroll
, attr
, old_attr
, FALSE
, attr_mask
);
169 if (CCEQ(key
, erase_char
))
171 if (CCEQ(key
, kill_char
))
173 if (key
< 0x100 && isprint(key
)) {
174 for (i
= strlen(instr
) - 1; i
>= scroll
+ input_x
&& instr
[i
] == ' '; i
--)
177 if (i
< MAX_LEN
&& (flen
< 0 || scroll
+input_x
< flen
)) {
178 if (flen
< 0 || i
< flen
)
179 memmove(instr
+scroll
+input_x
+1, instr
+scroll
+input_x
, i
-(scroll
+input_x
));
180 instr
[scroll
+input_x
] = key
;
181 if (input_x
== box_width
-1 && (flen
< 0 || i
< flen
))
185 redraw_field(dialog
, box_y
, box_x
, flen
, box_width
, instr
, input_x
, scroll
, attr
, old_attr
, FALSE
, attr_mask
);
187 beep(); /* Alarm user about overflow */
193 redraw_field(dialog
, box_y
, box_x
, flen
, box_width
, instr
, input_x
, scroll
, attr
, old_attr
, TRUE
, attr_mask
);
195 strcpy(result
, instr
);
200 redraw_field(WINDOW
*dialog
, int box_y
, int box_x
, int flen
, int box_width
, unsigned char instr
[], int input_x
, int scroll
, chtype attr
, chtype old_attr
, int fexit
, int attr_mask
)
204 wattrset(dialog
, fexit
? old_attr
: attr
);
205 wmove(dialog
, box_y
, box_x
);
206 fix_len
= flen
>= 0 ? MIN(flen
-scroll
,box_width
) : box_width
;
207 for (i
= 0; i
< fix_len
; i
++)
208 waddch(dialog
, instr
[scroll
+i
] ? ((attr_mask
& DITEM_NO_ECHO
) ? '*' : instr
[scroll
+i
]) : ' ');
209 wattrset(dialog
, old_attr
);
210 for ( ; i
< box_width
; i
++)
211 waddch(dialog
, instr
[scroll
+i
] ? ((attr_mask
& DITEM_NO_ECHO
) ? '*' : instr
[scroll
+i
]) : ' ');
212 wmove(dialog
, box_y
, input_x
+ box_x
);