/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020-2021,2022 Thomas E. Dickey *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* authorization. *
****************************************************************************/
/*
- * $Id: move_field.c,v 1.6 2020/03/28 17:43:03 tom Exp $
+ * $Id: move_field.c,v 1.13 2022/05/21 20:59:46 tom Exp $
*
* Demonstrate move_field().
*/
static char empty[] = "";
static FIELD *all_fields[100];
-
/* *INDENT-OFF* */
static struct {
int code;
werase(w);
wrefresh(w);
delwin(s);
- delwin(w);
}
static FieldAttrs *
int status;
FIELD *before;
unsigned n;
- int length;
int before_row;
int before_col;
int before_off = offset_in_field(form);
if (status == E_OK) {
bool modified = TRUE;
+ int length = buffer_length(before);
- length = buffer_length(before);
if (length < before_off)
length = before_off;
switch (*result) {
static FIELD **
copy_fields(FIELD **source, size_t length)
{
- FIELD **target = calloc(length + 1, sizeof(FIELD *));
+ FIELD **target = typeCalloc(FIELD *, length + 1);
memcpy(target, source, length * sizeof(FIELD *));
return target;
}
getyx(stdscr, currow, curcol);
mvprintw(LINES - 1, 0,
"Field at [%d,%d]. Press %s to quit moving.",
- getbegy(sub) + field->frow,
- getbegx(sub) + field->fcol,
+ getbegy(sub) + form_field_row(field),
+ getbegx(sub) + form_field_col(field),
keyname(DO_DEMO));
clrtobot();
move(currow, curcol);
{
int count = field_count(form);
FIELD *my_field = current_field(form);
+ FIELD **old_fields = form_fields(form);
- if (count > 0 && my_field != NULL) {
+ if (count > 0 && old_fields != NULL && my_field != NULL) {
size_t needed = (size_t) count;
- FIELD **old_fields = copy_fields(form_fields(form), needed);
- FIELD **new_fields = copy_fields(form_fields(form), needed);
- int ch;
+ FIELD **new_fields = copy_fields(old_fields, needed);
- if (old_fields != NULL && new_fields != NULL) {
+ if (new_fields != NULL) {
bool found = FALSE;
+ int ch;
/* TODO: move the label too, in parallel with the editing field */
getyx(stdscr, currow, curcol);
show_status(form, my_field);
- ch = '?';
while ((ch = wgetch(form_win(form))) != DO_DEMO) {
- int field_y = my_field->frow;
- int field_x = my_field->fcol;
+ int field_y = form_field_row(my_field);
+ int field_x = form_field_col(my_field);
switch (ch) {
case 'h':