* authorization. *
****************************************************************************/
/*
- * $Id: edit_field.c,v 1.17 2011/01/15 18:15:11 tom Exp $
+ * $Id: edit_field.c,v 1.21 2013/06/08 21:38:12 tom Exp $
*
* A wrapper for form_driver() which keeps track of the user's editing changes
- * for each field, and makes the result available as a null-terminated string
- * in field_buffer(field,1).
+ * for each field, and makes the resulting length available as a
+ * null-terminated string in field_buffer(field,1).
*
* Thomas Dickey - 2003/4/26.
*/
static void
inactive_field(FIELD * f)
{
- FieldAttrs *ptr = (FieldAttrs *) field_userptr(f);
- set_field_back(f, ptr->background);
+ set_field_back(f, field_attrs(f)->background);
+}
+
+FieldAttrs *
+field_attrs(FIELD * f)
+{
+ return (FieldAttrs *) field_userptr(f);
+}
+
+static int
+buffer_length(FIELD * f)
+{
+ return field_attrs(f)->row_lengths[0];
+}
+
+static void
+set_buffer_length(FIELD * f, int length)
+{
+ field_attrs(f)->row_lengths[0] = length;
+}
+
+/*
+ * The userptr is used in edit_field.c's inactive_field(), as well as for
+ * keeping track of the actual lengths of lines in a multiline field.
+ */
+void
+init_edit_field(FIELD * f, char *value)
+{
+ FieldAttrs *ptr = field_attrs(f);
+ if (ptr == 0) {
+ int rows, cols, frow, fcol, nrow, nbuf;
+
+ ptr = typeCalloc(FieldAttrs, 1);
+ ptr->background = field_back(f);
+ if (field_info(f, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK) {
+ ptr->row_count = nrow;
+ ptr->row_lengths = typeCalloc(int, (size_t) nrow + 1);
+ }
+ }
+ set_field_userptr(f, (void *) ptr);
+ set_field_buffer(f, 0, value); /* will be formatted */
+ set_field_buffer(f, 1, value); /* will be unformatted */
+ set_buffer_length(f, (int) strlen(value));
}
int
int status;
FIELD *before;
unsigned n;
- char lengths[80];
int length;
- char *buffer;
int before_row;
int before_col;
int before_off = offset_in_field(form);
if (status == E_OK) {
bool modified = TRUE;
- length = 0;
- if ((buffer = field_buffer(before, 1)) != 0)
- length = atoi(buffer);
+ length = buffer_length(before);
if (length < before_off)
length = before_off;
switch (*result) {
< MIN_FORM_COMMAND)
++length;
- sprintf(lengths, "%d", length);
- set_field_buffer(before, 1, lengths);
+ set_buffer_length(before, length);
}
if (current_field(form) != before)