1 /****************************************************************************
2 * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Juergen Pfeifer, 1995,1997 *
31 ****************************************************************************/
33 #include "form.priv.h"
35 MODULE_ID("$Id: frm_driver.c,v 1.78 2007/02/04 00:28:38 tom Exp $")
37 /*----------------------------------------------------------------------------
38 This is the core module of the form library. It contains the majority
39 of the driver routines as well as the form_driver function.
41 Essentially this module is nearly the whole library. This is because
42 all the functions in this module depends on some others in the module,
43 so it makes no sense to split them into separate files because they
44 will always be linked together. The only acceptable concern is turnaround
45 time for this module, but now we have all Pentiums or RISCs, so what!
47 The driver routines are grouped into nine generic categories:
49 a) Page Navigation ( all functions prefixed by PN_ )
50 The current page of the form is left and some new page is
52 b) Inter-Field Navigation ( all functions prefixed by FN_ )
53 The current field of the form is left and some new field is
55 c) Intra-Field Navigation ( all functions prefixed by IFN_ )
56 The current position in the current field is changed.
57 d) Vertical Scrolling ( all functions prefixed by VSC_ )
58 Essentially this is a specialization of Intra-Field navigation.
59 It has to check for a multi-line field.
60 e) Horizontal Scrolling ( all functions prefixed by HSC_ )
61 Essentially this is a specialization of Intra-Field navigation.
62 It has to check for a single-line field.
63 f) Field Editing ( all functions prefixed by FE_ )
64 The content of the current field is changed
65 g) Edit Mode requests ( all functions prefixed by EM_ )
66 Switching between insert and overlay mode
67 h) Field-Validation requests ( all functions prefixed by FV_ )
68 Perform verifications of the field.
69 i) Choice requests ( all functions prefixed by CR_ )
70 Requests to enumerate possible field values
71 --------------------------------------------------------------------------*/
73 /*----------------------------------------------------------------------------
74 Some remarks on the placements of assert() macros :
75 I use them only on "strategic" places, i.e. top level entries where
76 I want to make sure that things are set correctly. Throughout subordinate
77 routines I omit them mostly.
78 --------------------------------------------------------------------------*/
81 Some options that may effect compatibility in behavior to SVr4 forms,
82 but they are here to allow a more intuitive and user friendly behavior of
83 our form implementation. This doesn't affect the API, so we feel it is
86 The initial implementation tries to stay very close with the behavior
87 of the original SVr4 implementation, although in some areas it is quite
88 clear that this isn't the most appropriate way. As far as possible this
89 sources will allow you to build a forms lib that behaves quite similar
90 to SVr4, but now and in the future we will give you better options.
91 Perhaps at some time we will make this configurable at runtime.
94 /* Implement a more user-friendly previous/next word behavior */
95 #define FRIENDLY_PREV_NEXT_WORD (1)
96 /* Fix the wrong behavior for forms with all fields inactive */
97 #define FIX_FORM_INACTIVE_BUG (1)
98 /* Allow dynamic field growth also when navigating past the end */
99 #define GROW_IF_NAVIGATE (1)
101 #if USE_WIDEC_SUPPORT
102 #define myADDNSTR(w, s, n) wadd_wchnstr(w, s, n)
103 #define myINSNSTR(w, s, n) wins_wchnstr(w, s, n)
104 #define myINNSTR(w, s, n) fix_wchnstr(w, s, n)
105 #define myWCWIDTH(w, y, x) cell_width(w, y, x)
107 #define myADDNSTR(w, s, n) waddnstr(w, s, n)
108 #define myINSNSTR(w, s, n) winsnstr(w, s, n)
109 #define myINNSTR(w, s, n) winnstr(w, s, n)
110 #define myWCWIDTH(w, y, x) 1
113 /*----------------------------------------------------------------------------
114 Forward references to some internally used static functions
115 --------------------------------------------------------------------------*/
116 static int Inter_Field_Navigation(int (*const fct) (FORM *), FORM *form);
117 static int FN_Next_Field(FORM *form);
118 static int FN_Previous_Field(FORM *form);
119 static int FE_New_Line(FORM *);
120 static int FE_Delete_Previous(FORM *);
122 /*----------------------------------------------------------------------------
125 Some Remarks on that: I use the convention to use UPPERCASE for constants
126 defined by Macros. If I provide a macro as a kind of inline routine to
127 provide some logic, I use my Upper_Lower case style.
128 --------------------------------------------------------------------------*/
130 /* Calculate the position of a single row in a field buffer */
131 #define Position_Of_Row_In_Buffer(field,row) ((row)*(field)->dcols)
133 /* Calculate start address for the fields buffer# N */
134 #define Address_Of_Nth_Buffer(field,N) \
135 ((field)->buf + (N)*(1+Buffer_Length(field)))
137 /* Calculate the start address of the row in the fields specified buffer# N */
138 #define Address_Of_Row_In_Nth_Buffer(field,N,row) \
139 (Address_Of_Nth_Buffer(field,N) + Position_Of_Row_In_Buffer(field,row))
141 /* Calculate the start address of the row in the fields primary buffer */
142 #define Address_Of_Row_In_Buffer(field,row) \
143 Address_Of_Row_In_Nth_Buffer(field,0,row)
145 /* Calculate the start address of the row in the forms current field
147 #define Address_Of_Current_Row_In_Nth_Buffer(form,N) \
148 Address_Of_Row_In_Nth_Buffer((form)->current,N,(form)->currow)
150 /* Calculate the start address of the row in the forms current field
152 #define Address_Of_Current_Row_In_Buffer(form) \
153 Address_Of_Current_Row_In_Nth_Buffer(form,0)
155 /* Calculate the address of the cursor in the forms current field
157 #define Address_Of_Current_Position_In_Nth_Buffer(form,N) \
158 (Address_Of_Current_Row_In_Nth_Buffer(form,N) + (form)->curcol)
160 /* Calculate the address of the cursor in the forms current field
162 #define Address_Of_Current_Position_In_Buffer(form) \
163 Address_Of_Current_Position_In_Nth_Buffer(form,0)
165 /* Logic to decide whether or not a field is actually a field with
166 vertical or horizontal scrolling */
167 #define Is_Scroll_Field(field) \
168 (((field)->drows > (field)->rows) || \
169 ((field)->dcols > (field)->cols))
171 /* Logic to decide whether or not a field needs to have an individual window
172 instead of a derived window because it contains invisible parts.
173 This is true for non-public fields and for scrollable fields. */
174 #define Has_Invisible_Parts(field) \
175 (!((field)->opts & O_PUBLIC) || \
176 Is_Scroll_Field(field))
178 /* Logic to decide whether or not a field needs justification */
179 #define Justification_Allowed(field) \
180 (((field)->just != NO_JUSTIFICATION) && \
181 (Single_Line_Field(field)) && \
182 (((field)->dcols == (field)->cols) && \
183 ((field)->opts & O_STATIC)) )
185 /* Logic to determine whether or not a dynamic field may still grow */
186 #define Growable(field) ((field)->status & _MAY_GROW)
188 /* Macro to set the attributes for a fields window */
189 #define Set_Field_Window_Attributes(field,win) \
190 ( wbkgdset((win),(chtype)((field)->pad | (field)->back)), \
191 wattrset((win),(field)->fore) )
193 /* Logic to decide whether or not a field really appears on the form */
194 #define Field_Really_Appears(field) \
196 (field->form->status & _POSTED) &&\
197 (field->opts & O_VISIBLE) &&\
198 (field->page == field->form->curpage))
200 /* Logic to determine whether or not we are on the first position in the
202 #define First_Position_In_Current_Field(form) \
203 (((form)->currow==0) && ((form)->curcol==0))
205 #define Minimum(a,b) (((a)<=(b)) ? (a) : (b))
206 #define Maximum(a,b) (((a)>=(b)) ? (a) : (b))
208 /*----------------------------------------------------------------------------
210 --------------------------------------------------------------------------*/
211 static FIELD_CELL myBLANK = BLANK;
212 static FIELD_CELL myZEROS;
216 check_pos(FORM *form, int lineno)
222 getyx(form->w, y, x);
223 if (y != form->currow || x != form->curcol)
225 T(("CHECKPOS %s@%d have position %d,%d vs want %d,%d",
228 form->currow, form->curcol));
232 #define CHECKPOS(form) check_pos(form, __LINE__)
234 #define CHECKPOS(form) /* nothing */
237 /*----------------------------------------------------------------------------
238 Wide-character special functions
239 --------------------------------------------------------------------------*/
240 #if USE_WIDEC_SUPPORT
243 wins_wchnstr(WINDOW *w, cchar_t *s, int n)
251 if ((code = wins_wch(w, s++)) != OK)
253 if ((code = wmove(w, y, x + 1)) != OK)
259 /* win_wchnstr is inconsistent with winnstr, since it returns OK rather than
260 * the number of items transferred.
263 fix_wchnstr(WINDOW *w, cchar_t *s, int n)
267 win_wchnstr(w, s, n);
269 * This function is used to extract the text only from the window.
270 * Strip attributes and color from the string so they will not be added
271 * back when copying the string to the window.
273 for (x = 0; x < n; ++x)
275 RemAttr(s[x], A_ATTRIBUTES);
282 * Returns the column of the base of the given cell.
285 cell_base(WINDOW *win, int y, int x)
289 while (LEGALYX(win, y, x))
291 cchar_t *data = &(win->_line[y].text[x]);
293 if (isWidecBase(CHDEREF(data)) || !isWidecExt(CHDEREF(data)))
304 * Returns the number of columns needed for the given cell in a window.
307 cell_width(WINDOW *win, int y, int x)
311 if (LEGALYX(win, y, x))
313 cchar_t *data = &(win->_line[y].text[x]);
315 if (isWidecExt(CHDEREF(data)))
317 /* recur, providing the number of columns to the next character */
318 result = cell_width(win, y, x - 1);
322 result = wcwidth(CharOf(CHDEREF(data)));
329 * There is no wide-character function such as wdel_wch(), so we must find
330 * all of the cells that comprise a multi-column character and delete them
334 delete_char(FORM *form)
336 int cells = cell_width(form->w, form->currow, form->curcol);
338 form->curcol = cell_base(form->w, form->currow, form->curcol);
339 wmove(form->w, form->currow, form->curcol);
345 #define DeleteChar(form) delete_char(form)
347 #define DeleteChar(form) \
348 wmove((form)->w, (form)->currow, (form)->curcol), \
352 /*---------------------------------------------------------------------------
353 | Facility : libnform
354 | Function : static char *Get_Start_Of_Data(char * buf, int blen)
356 | Description : Return pointer to first non-blank position in buffer.
357 | If buffer is empty return pointer to buffer itself.
359 | Return Values : Pointer to first non-blank position in buffer
360 +--------------------------------------------------------------------------*/
361 NCURSES_INLINE static FIELD_CELL *
362 Get_Start_Of_Data(FIELD_CELL *buf, int blen)
365 FIELD_CELL *end = &buf[blen];
367 assert(buf && blen >= 0);
368 while ((p < end) && ISBLANK(*p))
370 return ((p == end) ? buf : p);
373 /*---------------------------------------------------------------------------
374 | Facility : libnform
375 | Function : static char *After_End_Of_Data(char * buf, int blen)
377 | Description : Return pointer after last non-blank position in buffer.
378 | If buffer is empty, return pointer to buffer itself.
380 | Return Values : Pointer to position after last non-blank position in
382 +--------------------------------------------------------------------------*/
383 NCURSES_INLINE static FIELD_CELL *
384 After_End_Of_Data(FIELD_CELL *buf, int blen)
386 FIELD_CELL *p = &buf[blen];
388 assert(buf && blen >= 0);
389 while ((p > buf) && ISBLANK(p[-1]))
394 /*---------------------------------------------------------------------------
395 | Facility : libnform
396 | Function : static char *Get_First_Whitespace_Character(
397 | char * buf, int blen)
399 | Description : Position to the first whitespace character.
401 | Return Values : Pointer to first whitespace character in buffer.
402 +--------------------------------------------------------------------------*/
403 NCURSES_INLINE static FIELD_CELL *
404 Get_First_Whitespace_Character(FIELD_CELL *buf, int blen)
407 FIELD_CELL *end = &p[blen];
409 assert(buf && blen >= 0);
410 while ((p < end) && !ISBLANK(*p))
412 return ((p == end) ? buf : p);
415 /*---------------------------------------------------------------------------
416 | Facility : libnform
417 | Function : static char *After_Last_Whitespace_Character(
418 | char * buf, int blen)
420 | Description : Get the position after the last whitespace character.
422 | Return Values : Pointer to position after last whitespace character in
424 +--------------------------------------------------------------------------*/
425 NCURSES_INLINE static FIELD_CELL *
426 After_Last_Whitespace_Character(FIELD_CELL *buf, int blen)
428 FIELD_CELL *p = &buf[blen];
430 assert(buf && blen >= 0);
431 while ((p > buf) && !ISBLANK(p[-1]))
436 /* Set this to 1 to use the div_t version. This is a good idea if your
437 compiler has an intrinsic div() support. Unfortunately GNU-C has it
439 N.B.: This only works if form->curcol follows immediately form->currow
440 and both are of type int.
442 #define USE_DIV_T (0)
444 /*---------------------------------------------------------------------------
445 | Facility : libnform
446 | Function : static void Adjust_Cursor_Position(
447 | FORM * form, const char * pos)
449 | Description : Set current row and column of the form to values
450 | corresponding to the buffer position.
453 +--------------------------------------------------------------------------*/
454 NCURSES_INLINE static void
455 Adjust_Cursor_Position(FORM *form, const FIELD_CELL *pos)
460 field = form->current;
461 assert(pos >= field->buf && field->dcols > 0);
462 idx = (int)(pos - field->buf);
464 *((div_t *) & (form->currow)) = div(idx, field->dcols);
466 form->currow = idx / field->dcols;
467 form->curcol = idx - field->cols * form->currow;
469 if (field->drows < form->currow)
473 /*---------------------------------------------------------------------------
474 | Facility : libnform
475 | Function : static void Buffer_To_Window(
476 | const FIELD * field,
479 | Description : Copy the buffer to the window. If it is a multi-line
480 | field, the buffer is split to the lines of the
481 | window without any editing.
484 +--------------------------------------------------------------------------*/
486 Buffer_To_Window(const FIELD *field, WINDOW *win)
494 assert(win && field);
497 width = getmaxx(win);
498 height = getmaxy(win);
500 for (row = 0, pBuffer = field->buf;
502 row++, pBuffer += width)
504 if ((len = (int)(After_End_Of_Data(pBuffer, width) - pBuffer)) > 0)
507 myADDNSTR(win, pBuffer, len);
513 /*---------------------------------------------------------------------------
514 | Facility : libnform
515 | Function : static void Window_To_Buffer(
519 | Description : Copy the content of the window into the buffer.
520 | The multiple lines of a window are simply
521 | concatenated into the buffer. Pad characters in
522 | the window will be replaced by blanks in the buffer.
525 +--------------------------------------------------------------------------*/
527 Window_To_Buffer(WINDOW *win, FIELD *field)
534 assert(win && field && field->buf);
538 height = getmaxy(win);
540 for (row = 0; (row < height) && (row < field->drows); row++)
543 len += myINNSTR(win, p + len, field->dcols);
547 /* replace visual padding character by blanks in buffer */
552 for (i = 0; i < len; i++, p++)
554 if ((unsigned long)CharOf(*p) == ChCharOf(pad)
555 #if USE_WIDEC_SUPPORT
564 /*---------------------------------------------------------------------------
565 | Facility : libnform
566 | Function : static void Synchronize_Buffer(FORM * form)
568 | Description : If there was a change, copy the content of the
569 | window into the buffer, so the buffer is synchronized
570 | with the windows content. We have to indicate that the
571 | buffer needs validation due to the change.
574 +--------------------------------------------------------------------------*/
575 NCURSES_INLINE static void
576 Synchronize_Buffer(FORM *form)
578 if (form->status & _WINDOW_MODIFIED)
580 form->status &= ~_WINDOW_MODIFIED;
581 form->status |= _FCHECK_REQUIRED;
582 Window_To_Buffer(form->w, form->current);
583 wmove(form->w, form->currow, form->curcol);
587 /*---------------------------------------------------------------------------
588 | Facility : libnform
589 | Function : static bool Field_Grown( FIELD *field, int amount)
591 | Description : This function is called for growable dynamic fields
592 | only. It has to increase the buffers and to allocate
593 | a new window for this field.
594 | This function has the side effect to set a new
595 | field-buffer pointer, the dcols and drows values
596 | as well as a new current Window for the field.
598 | Return Values : TRUE - field successfully increased
599 | FALSE - there was some error
600 +--------------------------------------------------------------------------*/
602 Field_Grown(FIELD *field, int amount)
606 if (field && Growable(field))
608 bool single_line_field = Single_Line_Field(field);
609 int old_buflen = Buffer_Length(field);
611 int old_dcols = field->dcols;
612 int old_drows = field->drows;
613 FIELD_CELL *oldbuf = field->buf;
617 FORM *form = field->form;
618 bool need_visual_update = ((form != (FORM *)0) &&
619 (form->status & _POSTED) &&
620 (form->current == field));
622 if (need_visual_update)
623 Synchronize_Buffer(form);
625 if (single_line_field)
627 growth = field->cols * amount;
629 growth = Minimum(field->maxgrow - field->dcols, growth);
630 field->dcols += growth;
631 if (field->dcols == field->maxgrow)
632 field->status &= ~_MAY_GROW;
636 growth = (field->rows + field->nrow) * amount;
638 growth = Minimum(field->maxgrow - field->drows, growth);
639 field->drows += growth;
640 if (field->drows == field->maxgrow)
641 field->status &= ~_MAY_GROW;
643 /* drows, dcols changed, so we get really the new buffer length */
644 new_buflen = Buffer_Length(field);
645 newbuf = (FIELD_CELL *)malloc(Total_Buffer_Size(field));
648 /* restore to previous state */
649 field->dcols = old_dcols;
650 field->drows = old_drows;
651 if ((single_line_field && (field->dcols != field->maxgrow)) ||
652 (!single_line_field && (field->drows != field->maxgrow)))
653 field->status |= _MAY_GROW;
657 /* Copy all the buffers. This is the reason why we can't just use
664 result = TRUE; /* allow sharing of recovery on failure */
666 T((T_CREATE("fieldcell %p"), newbuf));
668 for (i = 0; i <= field->nbuf; i++)
670 new_bp = Address_Of_Nth_Buffer(field, i);
671 old_bp = oldbuf + i * (1 + old_buflen);
672 for (j = 0; j < old_buflen; ++j)
673 new_bp[j] = old_bp[j];
674 while (j < new_buflen)
675 new_bp[j++] = myBLANK;
676 new_bp[new_buflen] = myZEROS;
679 #if USE_WIDEC_SUPPORT
680 if (wresize(field->working, 1, Buffer_Length(field) + 1) == ERR)
684 if (need_visual_update && result)
686 WINDOW *new_window = newpad(field->drows, field->dcols);
690 assert(form != (FORM *)0);
693 form->w = new_window;
694 Set_Field_Window_Attributes(field, form->w);
696 Buffer_To_Window(field, form->w);
698 wmove(form->w, form->currow, form->curcol);
707 /* reflect changes in linked fields */
708 if (field != field->link)
712 for (linked_field = field->link;
713 linked_field != field;
714 linked_field = linked_field->link)
716 linked_field->buf = field->buf;
717 linked_field->drows = field->drows;
718 linked_field->dcols = field->dcols;
724 /* restore old state */
725 field->dcols = old_dcols;
726 field->drows = old_drows;
728 if ((single_line_field &&
729 (field->dcols != field->maxgrow)) ||
730 (!single_line_field &&
731 (field->drows != field->maxgrow)))
732 field->status |= _MAY_GROW;
740 /*---------------------------------------------------------------------------
741 | Facility : libnform
742 | Function : int _nc_Position_Form_Cursor(FORM * form)
744 | Description : Position the cursor in the window for the current
745 | field to be in sync. with the currow and curcol
748 | Return Values : E_OK - success
749 | E_BAD_ARGUMENT - invalid form pointer
750 | E_SYSTEM_ERROR - form has no current field or
752 +--------------------------------------------------------------------------*/
754 _nc_Position_Form_Cursor(FORM *form)
760 return (E_BAD_ARGUMENT);
762 if (!form->w || !form->current)
763 return (E_SYSTEM_ERROR);
765 field = form->current;
766 formwin = Get_Form_Window(form);
768 wmove(form->w, form->currow, form->curcol);
769 if (Has_Invisible_Parts(field))
771 /* in this case fieldwin isn't derived from formwin, so we have
772 to move the cursor in formwin by hand... */
774 field->frow + form->currow - form->toprow,
775 field->fcol + form->curcol - form->begincol);
783 /*---------------------------------------------------------------------------
784 | Facility : libnform
785 | Function : int _nc_Refresh_Current_Field(FORM * form)
787 | Description : Propagate the changes in the fields window to the
788 | window of the form.
790 | Return Values : E_OK - on success
791 | E_BAD_ARGUMENT - invalid form pointer
792 | E_SYSTEM_ERROR - general error
793 +--------------------------------------------------------------------------*/
795 _nc_Refresh_Current_Field(FORM *form)
800 T((T_CALLED("_nc_Refresh_Current_Field(%p)"), form));
803 RETURN(E_BAD_ARGUMENT);
805 if (!form->w || !form->current)
806 RETURN(E_SYSTEM_ERROR);
808 field = form->current;
809 formwin = Get_Form_Window(form);
811 if (field->opts & O_PUBLIC)
813 if (Is_Scroll_Field(field))
815 /* Again, in this case the fieldwin isn't derived from formwin,
816 so we have to perform a copy operation. */
817 if (Single_Line_Field(field))
819 /* horizontal scrolling */
820 if (form->curcol < form->begincol)
821 form->begincol = form->curcol;
824 if (form->curcol >= (form->begincol + field->cols))
825 form->begincol = form->curcol - field->cols + 1;
834 field->cols + field->fcol - 1,
839 /* A multi-line, i.e. vertical scrolling field */
840 int row_after_bottom, first_modified_row, first_unmodified_row;
842 if (field->drows > field->rows)
844 row_after_bottom = form->toprow + field->rows;
845 if (form->currow < form->toprow)
847 form->toprow = form->currow;
848 field->status |= _NEWTOP;
850 if (form->currow >= row_after_bottom)
852 form->toprow = form->currow - field->rows + 1;
853 field->status |= _NEWTOP;
855 if (field->status & _NEWTOP)
857 /* means we have to copy whole range */
858 first_modified_row = form->toprow;
859 first_unmodified_row = first_modified_row + field->rows;
860 field->status &= ~_NEWTOP;
864 /* we try to optimize : finding the range of touched
866 first_modified_row = form->toprow;
867 while (first_modified_row < row_after_bottom)
869 if (is_linetouched(form->w, first_modified_row))
871 first_modified_row++;
873 first_unmodified_row = first_modified_row;
874 while (first_unmodified_row < row_after_bottom)
876 if (!is_linetouched(form->w, first_unmodified_row))
878 first_unmodified_row++;
884 first_modified_row = form->toprow;
885 first_unmodified_row = first_modified_row + field->rows;
887 if (first_unmodified_row != first_modified_row)
892 field->frow + first_modified_row - form->toprow,
894 field->frow + first_unmodified_row - form->toprow - 1,
895 field->cols + field->fcol - 1,
902 /* if the field-window is simply a derived window, i.e. contains no
903 * invisible parts, the whole thing is trivial
909 returnCode(_nc_Position_Form_Cursor(form));
912 /*---------------------------------------------------------------------------
913 | Facility : libnform
914 | Function : static void Perform_Justification(
918 | Description : Output field with requested justification
921 +--------------------------------------------------------------------------*/
923 Perform_Justification(FIELD *field, WINDOW *win)
929 bp = Get_Start_Of_Data(field->buf, Buffer_Length(field));
930 len = (int)(After_End_Of_Data(field->buf, Buffer_Length(field)) - bp);
934 assert(win && (field->drows == 1) && (field->dcols == field->cols));
941 col = (field->cols - len) / 2;
944 col = field->cols - len;
951 myADDNSTR(win, bp, len);
955 /*---------------------------------------------------------------------------
956 | Facility : libnform
957 | Function : static void Undo_Justification(
961 | Description : Display field without any justification, i.e.
965 +--------------------------------------------------------------------------*/
967 Undo_Justification(FIELD *field, WINDOW *win)
972 bp = Get_Start_Of_Data(field->buf, Buffer_Length(field));
973 len = (int)(After_End_Of_Data(field->buf, Buffer_Length(field)) - bp);
979 myADDNSTR(win, bp, len);
983 /*---------------------------------------------------------------------------
984 | Facility : libnform
985 | Function : static bool Check_Char(
988 | TypeArgument *argp)
990 | Description : Perform a single character check for character ch
991 | according to the fieldtype instance.
993 | Return Values : TRUE - Character is valid
994 | FALSE - Character is invalid
995 +--------------------------------------------------------------------------*/
997 Check_Char(FIELDTYPE *typ, int ch, TypeArgument *argp)
1001 if (typ->status & _LINKED_TYPE)
1005 Check_Char(typ->left, ch, argp->left) ||
1006 Check_Char(typ->right, ch, argp->right));
1011 return typ->ccheck(ch, (void *)argp);
1014 return (!iscntrl(UChar(ch)) ? TRUE : FALSE);
1017 /*---------------------------------------------------------------------------
1018 | Facility : libnform
1019 | Function : static int Display_Or_Erase_Field(
1023 | Description : Create a subwindow for the field and display the
1024 | buffer contents (apply justification if required)
1025 | or simply erase the field.
1027 | Return Values : E_OK - on success
1028 | E_SYSTEM_ERROR - some error (typical no memory)
1029 +--------------------------------------------------------------------------*/
1031 Display_Or_Erase_Field(FIELD *field, bool bEraseFlag)
1037 return E_SYSTEM_ERROR;
1039 fwin = Get_Form_Window(field->form);
1041 field->rows, field->cols, field->frow, field->fcol);
1044 return E_SYSTEM_ERROR;
1047 if (field->opts & O_VISIBLE)
1048 Set_Field_Window_Attributes(field, win);
1050 wattrset(win, WINDOW_ATTRS(fwin));
1056 if (field->opts & O_PUBLIC)
1058 if (Justification_Allowed(field))
1059 Perform_Justification(field, win);
1061 Buffer_To_Window(field, win);
1063 field->status &= ~_NEWTOP;
1070 /* Macros to preset the bEraseFlag */
1071 #define Display_Field(field) Display_Or_Erase_Field(field,FALSE)
1072 #define Erase_Field(field) Display_Or_Erase_Field(field,TRUE)
1074 /*---------------------------------------------------------------------------
1075 | Facility : libnform
1076 | Function : static int Synchronize_Field(FIELD * field)
1078 | Description : Synchronize the windows content with the value in
1081 | Return Values : E_OK - success
1082 | E_BAD_ARGUMENT - invalid field pointer
1083 | E_SYSTEM_ERROR - some severe basic error
1084 +--------------------------------------------------------------------------*/
1086 Synchronize_Field(FIELD *field)
1092 return (E_BAD_ARGUMENT);
1094 if (((form = field->form) != (FORM *)0)
1095 && Field_Really_Appears(field))
1097 if (field == form->current)
1099 form->currow = form->curcol = form->toprow = form->begincol = 0;
1102 if ((field->opts & O_PUBLIC) && Justification_Allowed(field))
1103 Undo_Justification(field, form->w);
1105 Buffer_To_Window(field, form->w);
1107 field->status |= _NEWTOP;
1108 res = _nc_Refresh_Current_Field(form);
1111 res = Display_Field(field);
1113 field->status |= _CHANGED;
1117 /*---------------------------------------------------------------------------
1118 | Facility : libnform
1119 | Function : static int Synchronize_Linked_Fields(FIELD * field)
1121 | Description : Propagate the Synchronize_Field function to all linked
1122 | fields. The first error that occurs in the sequence
1123 | of updates is the return value.
1125 | Return Values : E_OK - success
1126 | E_BAD_ARGUMENT - invalid field pointer
1127 | E_SYSTEM_ERROR - some severe basic error
1128 +--------------------------------------------------------------------------*/
1130 Synchronize_Linked_Fields(FIELD *field)
1132 FIELD *linked_field;
1137 return (E_BAD_ARGUMENT);
1140 return (E_SYSTEM_ERROR);
1142 for (linked_field = field->link;
1143 linked_field != field;
1144 linked_field = linked_field->link)
1146 if (((syncres = Synchronize_Field(linked_field)) != E_OK) &&
1153 /*---------------------------------------------------------------------------
1154 | Facility : libnform
1155 | Function : int _nc_Synchronize_Attributes(FIELD * field)
1157 | Description : If a fields visual attributes have changed, this
1158 | routine is called to propagate those changes to the
1161 | Return Values : E_OK - success
1162 | E_BAD_ARGUMENT - invalid field pointer
1163 | E_SYSTEM_ERROR - some severe basic error
1164 +--------------------------------------------------------------------------*/
1166 _nc_Synchronize_Attributes(FIELD *field)
1172 T((T_CALLED("_nc_Synchronize_Attributes(%p)"), field));
1175 returnCode(E_BAD_ARGUMENT);
1177 CHECKPOS(field->form);
1178 if (((form = field->form) != (FORM *)0)
1179 && Field_Really_Appears(field))
1181 if (form->current == field)
1183 Synchronize_Buffer(form);
1184 Set_Field_Window_Attributes(field, form->w);
1186 wmove(form->w, form->currow, form->curcol);
1188 if (field->opts & O_PUBLIC)
1190 if (Justification_Allowed(field))
1191 Undo_Justification(field, form->w);
1193 Buffer_To_Window(field, form->w);
1197 formwin = Get_Form_Window(form);
1198 copywin(form->w, formwin,
1200 field->frow, field->fcol,
1201 field->rows - 1, field->cols - 1, 0);
1203 Buffer_To_Window(field, form->w);
1204 field->status |= _NEWTOP; /* fake refresh to paint all */
1205 _nc_Refresh_Current_Field(form);
1210 res = Display_Field(field);
1217 /*---------------------------------------------------------------------------
1218 | Facility : libnform
1219 | Function : int _nc_Synchronize_Options(FIELD * field,
1220 | Field_Options newopts)
1222 | Description : If a fields options have changed, this routine is
1223 | called to propagate these changes to the screen and
1224 | to really change the behavior of the field.
1226 | Return Values : E_OK - success
1227 | E_BAD_ARGUMENT - invalid field pointer
1228 | E_CURRENT - field is the current one
1229 | E_SYSTEM_ERROR - some severe basic error
1230 +--------------------------------------------------------------------------*/
1232 _nc_Synchronize_Options(FIELD *field, Field_Options newopts)
1234 Field_Options oldopts;
1235 Field_Options changed_opts;
1239 T((T_CALLED("_nc_Synchronize_Options(%p,%#x)"), field, newopts));
1242 returnCode(E_BAD_ARGUMENT);
1244 oldopts = field->opts;
1245 changed_opts = oldopts ^ newopts;
1246 field->opts = newopts;
1251 if (form->current == field)
1253 field->opts = oldopts;
1254 returnCode(E_CURRENT);
1257 if (form->status & _POSTED)
1259 if ((form->curpage == field->page))
1261 if (changed_opts & O_VISIBLE)
1263 if (newopts & O_VISIBLE)
1264 res = Display_Field(field);
1266 res = Erase_Field(field);
1270 if ((changed_opts & O_PUBLIC) &&
1271 (newopts & O_VISIBLE))
1272 res = Display_Field(field);
1278 if (changed_opts & O_STATIC)
1280 bool single_line_field = Single_Line_Field(field);
1283 if (newopts & O_STATIC)
1285 /* the field becomes now static */
1286 field->status &= ~_MAY_GROW;
1287 /* if actually we have no hidden columns, justification may
1289 if (single_line_field &&
1290 (field->cols == field->dcols) &&
1291 (field->just != NO_JUSTIFICATION) &&
1292 Field_Really_Appears(field))
1294 res2 = Display_Field(field);
1299 /* field is no longer static */
1300 if ((field->maxgrow == 0) ||
1301 (single_line_field && (field->dcols < field->maxgrow)) ||
1302 (!single_line_field && (field->drows < field->maxgrow)))
1304 field->status |= _MAY_GROW;
1305 /* a field with justification now changes its behavior,
1306 so we must redisplay it */
1307 if (single_line_field &&
1308 (field->just != NO_JUSTIFICATION) &&
1309 Field_Really_Appears(field))
1311 res2 = Display_Field(field);
1322 /*---------------------------------------------------------------------------
1323 | Facility : libnform
1324 | Function : int _nc_Set_Current_Field(FORM * form,
1327 | Description : Make the newfield the new current field.
1329 | Return Values : E_OK - success
1330 | E_BAD_ARGUMENT - invalid form or field pointer
1331 | E_SYSTEM_ERROR - some severe basic error
1332 | E_NOT_CONNECTED - no fields are connected to the form
1333 +--------------------------------------------------------------------------*/
1335 _nc_Set_Current_Field(FORM *form, FIELD *newfield)
1340 T((T_CALLED("_nc_Set_Current_Field(%p,%p)"), form, newfield));
1342 if (!form || !newfield || !form->current || (newfield->form != form))
1343 returnCode(E_BAD_ARGUMENT);
1345 if ((form->status & _IN_DRIVER))
1346 returnCode(E_BAD_STATE);
1349 returnCode(E_NOT_CONNECTED);
1351 field = form->current;
1353 if ((field != newfield) ||
1354 !(form->status & _POSTED))
1357 (field->opts & O_VISIBLE) &&
1358 (field->form->curpage == field->page))
1360 _nc_Refresh_Current_Field(form);
1361 if (field->opts & O_PUBLIC)
1363 if (field->drows > field->rows)
1365 if (form->toprow == 0)
1366 field->status &= ~_NEWTOP;
1368 field->status |= _NEWTOP;
1372 if (Justification_Allowed(field))
1374 Window_To_Buffer(form->w, field);
1376 Perform_Justification(field, form->w);
1382 form->w = (WINDOW *)0;
1387 if (Has_Invisible_Parts(field))
1388 new_window = newpad(field->drows, field->dcols);
1390 new_window = derwin(Get_Form_Window(form),
1391 field->rows, field->cols, field->frow, field->fcol);
1394 returnCode(E_SYSTEM_ERROR);
1396 form->current = field;
1400 form->w = new_window;
1402 form->status &= ~_WINDOW_MODIFIED;
1403 Set_Field_Window_Attributes(field, form->w);
1405 if (Has_Invisible_Parts(field))
1408 Buffer_To_Window(field, form->w);
1412 if (Justification_Allowed(field))
1415 Undo_Justification(field, form->w);
1420 untouchwin(form->w);
1423 form->currow = form->curcol = form->toprow = form->begincol = 0;
1427 /*----------------------------------------------------------------------------
1428 Intra-Field Navigation routines
1429 --------------------------------------------------------------------------*/
1431 /*---------------------------------------------------------------------------
1432 | Facility : libnform
1433 | Function : static int IFN_Next_Character(FORM * form)
1435 | Description : Move to the next character in the field. In a multi-line
1436 | field this wraps at the end of the line.
1438 | Return Values : E_OK - success
1439 | E_REQUEST_DENIED - at the rightmost position
1440 +--------------------------------------------------------------------------*/
1442 IFN_Next_Character(FORM *form)
1444 FIELD *field = form->current;
1445 int step = myWCWIDTH(form->w, form->currow, form->curcol);
1447 T((T_CALLED("IFN_Next_Character(%p)"), form));
1448 if ((form->curcol += step) == field->dcols)
1450 if ((++(form->currow)) == field->drows)
1452 #if GROW_IF_NAVIGATE
1453 if (!Single_Line_Field(field) && Field_Grown(field, 1))
1460 #if GROW_IF_NAVIGATE
1461 if (Single_Line_Field(field) && Field_Grown(field, 1))
1464 form->curcol -= step;
1465 returnCode(E_REQUEST_DENIED);
1472 /*---------------------------------------------------------------------------
1473 | Facility : libnform
1474 | Function : static int IFN_Previous_Character(FORM * form)
1476 | Description : Move to the previous character in the field. In a
1477 | multi-line field this wraps and the beginning of the
1480 | Return Values : E_OK - success
1481 | E_REQUEST_DENIED - at the leftmost position
1482 +--------------------------------------------------------------------------*/
1484 IFN_Previous_Character(FORM *form)
1486 int amount = myWCWIDTH(form->w, form->currow, form->curcol - 1);
1487 int oldcol = form->curcol;
1489 T((T_CALLED("IFN_Previous_Character(%p)"), form));
1490 if ((form->curcol -= amount) < 0)
1492 if ((--(form->currow)) < 0)
1495 form->curcol = oldcol;
1496 returnCode(E_REQUEST_DENIED);
1498 form->curcol = form->current->dcols - 1;
1503 /*---------------------------------------------------------------------------
1504 | Facility : libnform
1505 | Function : static int IFN_Next_Line(FORM * form)
1507 | Description : Move to the beginning of the next line in the field
1509 | Return Values : E_OK - success
1510 | E_REQUEST_DENIED - at the last line
1511 +--------------------------------------------------------------------------*/
1513 IFN_Next_Line(FORM *form)
1515 FIELD *field = form->current;
1517 T((T_CALLED("IFN_Next_Line(%p)"), form));
1518 if ((++(form->currow)) == field->drows)
1520 #if GROW_IF_NAVIGATE
1521 if (!Single_Line_Field(field) && Field_Grown(field, 1))
1525 returnCode(E_REQUEST_DENIED);
1531 /*---------------------------------------------------------------------------
1532 | Facility : libnform
1533 | Function : static int IFN_Previous_Line(FORM * form)
1535 | Description : Move to the beginning of the previous line in the field
1537 | Return Values : E_OK - success
1538 | E_REQUEST_DENIED - at the first line
1539 +--------------------------------------------------------------------------*/
1541 IFN_Previous_Line(FORM *form)
1543 T((T_CALLED("IFN_Previous_Line(%p)"), form));
1544 if ((--(form->currow)) < 0)
1547 returnCode(E_REQUEST_DENIED);
1553 /*---------------------------------------------------------------------------
1554 | Facility : libnform
1555 | Function : static int IFN_Next_Word(FORM * form)
1557 | Description : Move to the beginning of the next word in the field.
1559 | Return Values : E_OK - success
1560 | E_REQUEST_DENIED - there is no next word
1561 +--------------------------------------------------------------------------*/
1563 IFN_Next_Word(FORM *form)
1565 FIELD *field = form->current;
1566 FIELD_CELL *bp = Address_Of_Current_Position_In_Buffer(form);
1570 T((T_CALLED("IFN_Next_Word(%p)"), form));
1572 /* We really need access to the data, so we have to synchronize */
1573 Synchronize_Buffer(form);
1575 /* Go to the first whitespace after the current position (including
1576 current position). This is then the starting point to look for the
1577 next non-blank data */
1578 s = Get_First_Whitespace_Character(bp, Buffer_Length(field) -
1579 (int)(bp - field->buf));
1581 /* Find the start of the next word */
1582 t = Get_Start_Of_Data(s, Buffer_Length(field) -
1583 (int)(s - field->buf));
1584 #if !FRIENDLY_PREV_NEXT_WORD
1586 returnCode(E_REQUEST_DENIED);
1590 Adjust_Cursor_Position(form, t);
1595 /*---------------------------------------------------------------------------
1596 | Facility : libnform
1597 | Function : static int IFN_Previous_Word(FORM * form)
1599 | Description : Move to the beginning of the previous word in the field.
1601 | Return Values : E_OK - success
1602 | E_REQUEST_DENIED - there is no previous word
1603 +--------------------------------------------------------------------------*/
1605 IFN_Previous_Word(FORM *form)
1607 FIELD *field = form->current;
1608 FIELD_CELL *bp = Address_Of_Current_Position_In_Buffer(form);
1613 T((T_CALLED("IFN_Previous_Word(%p)"), form));
1615 /* We really need access to the data, so we have to synchronize */
1616 Synchronize_Buffer(form);
1618 s = After_End_Of_Data(field->buf, (int)(bp - field->buf));
1619 /* s points now right after the last non-blank in the buffer before bp.
1620 If bp was in a word, s equals bp. In this case we must find the last
1621 whitespace in the buffer before bp and repeat the game to really find
1622 the previous word! */
1626 /* And next call now goes backward to look for the last whitespace
1627 before that, pointing right after this, so it points to the begin
1628 of the previous word.
1630 t = After_Last_Whitespace_Character(field->buf, (int)(s - field->buf));
1631 #if !FRIENDLY_PREV_NEXT_WORD
1633 returnCode(E_REQUEST_DENIED);
1637 /* and do it again, replacing bp by t */
1638 s = After_End_Of_Data(field->buf, (int)(t - field->buf));
1639 t = After_Last_Whitespace_Character(field->buf, (int)(s - field->buf));
1640 #if !FRIENDLY_PREV_NEXT_WORD
1642 returnCode(E_REQUEST_DENIED);
1645 Adjust_Cursor_Position(form, t);
1649 /*---------------------------------------------------------------------------
1650 | Facility : libnform
1651 | Function : static int IFN_Beginning_Of_Field(FORM * form)
1653 | Description : Place the cursor at the first non-pad character in
1656 | Return Values : E_OK - success
1657 +--------------------------------------------------------------------------*/
1659 IFN_Beginning_Of_Field(FORM *form)
1661 FIELD *field = form->current;
1663 T((T_CALLED("IFN_Beginning_Of_Field(%p)"), form));
1664 Synchronize_Buffer(form);
1665 Adjust_Cursor_Position(form,
1666 Get_Start_Of_Data(field->buf, Buffer_Length(field)));
1670 /*---------------------------------------------------------------------------
1671 | Facility : libnform
1672 | Function : static int IFN_End_Of_Field(FORM * form)
1674 | Description : Place the cursor after the last non-pad character in
1675 | the field. If the field occupies the last position in
1676 | the buffer, the cursor is positioned on the last
1679 | Return Values : E_OK - success
1680 +--------------------------------------------------------------------------*/
1682 IFN_End_Of_Field(FORM *form)
1684 FIELD *field = form->current;
1687 T((T_CALLED("IFN_End_Of_Field(%p)"), form));
1688 Synchronize_Buffer(form);
1689 pos = After_End_Of_Data(field->buf, Buffer_Length(field));
1690 if (pos == (field->buf + Buffer_Length(field)))
1692 Adjust_Cursor_Position(form, pos);
1696 /*---------------------------------------------------------------------------
1697 | Facility : libnform
1698 | Function : static int IFN_Beginning_Of_Line(FORM * form)
1700 | Description : Place the cursor on the first non-pad character in
1701 | the current line of the field.
1703 | Return Values : E_OK - success
1704 +--------------------------------------------------------------------------*/
1706 IFN_Beginning_Of_Line(FORM *form)
1708 FIELD *field = form->current;
1710 T((T_CALLED("IFN_Beginning_Of_Line(%p)"), form));
1711 Synchronize_Buffer(form);
1712 Adjust_Cursor_Position(form,
1713 Get_Start_Of_Data(Address_Of_Current_Row_In_Buffer(form),
1718 /*---------------------------------------------------------------------------
1719 | Facility : libnform
1720 | Function : static int IFN_End_Of_Line(FORM * form)
1722 | Description : Place the cursor after the last non-pad character in the
1723 | current line of the field. If the field occupies the
1724 | last column in the line, the cursor is positioned on the
1725 | last character of the line.
1727 | Return Values : E_OK - success
1728 +--------------------------------------------------------------------------*/
1730 IFN_End_Of_Line(FORM *form)
1732 FIELD *field = form->current;
1736 T((T_CALLED("IFN_End_Of_Line(%p)"), form));
1737 Synchronize_Buffer(form);
1738 bp = Address_Of_Current_Row_In_Buffer(form);
1739 pos = After_End_Of_Data(bp, field->dcols);
1740 if (pos == (bp + field->dcols))
1742 Adjust_Cursor_Position(form, pos);
1746 /*---------------------------------------------------------------------------
1747 | Facility : libnform
1748 | Function : static int IFN_Left_Character(FORM * form)
1750 | Description : Move one character to the left in the current line.
1751 | This doesn't cycle.
1753 | Return Values : E_OK - success
1754 | E_REQUEST_DENIED - already in first column
1755 +--------------------------------------------------------------------------*/
1757 IFN_Left_Character(FORM *form)
1759 int amount = myWCWIDTH(form->w, form->currow, form->curcol - 1);
1760 int oldcol = form->curcol;
1762 T((T_CALLED("IFN_Left_Character(%p)"), form));
1763 if ((form->curcol -= amount) < 0)
1765 form->curcol = oldcol;
1766 returnCode(E_REQUEST_DENIED);
1771 /*---------------------------------------------------------------------------
1772 | Facility : libnform
1773 | Function : static int IFN_Right_Character(FORM * form)
1775 | Description : Move one character to the right in the current line.
1776 | This doesn't cycle.
1778 | Return Values : E_OK - success
1779 | E_REQUEST_DENIED - already in last column
1780 +--------------------------------------------------------------------------*/
1782 IFN_Right_Character(FORM *form)
1784 int amount = myWCWIDTH(form->w, form->currow, form->curcol);
1785 int oldcol = form->curcol;
1787 T((T_CALLED("IFN_Right_Character(%p)"), form));
1788 if ((form->curcol += amount) >= form->current->dcols)
1790 #if GROW_IF_NAVIGATE
1791 FIELD *field = form->current;
1793 if (Single_Line_Field(field) && Field_Grown(field, 1))
1796 form->curcol = oldcol;
1797 returnCode(E_REQUEST_DENIED);
1802 /*---------------------------------------------------------------------------
1803 | Facility : libnform
1804 | Function : static int IFN_Up_Character(FORM * form)
1806 | Description : Move one line up. This doesn't cycle through the lines
1809 | Return Values : E_OK - success
1810 | E_REQUEST_DENIED - already in last column
1811 +--------------------------------------------------------------------------*/
1813 IFN_Up_Character(FORM *form)
1815 T((T_CALLED("IFN_Up_Character(%p)"), form));
1816 if ((--(form->currow)) < 0)
1819 returnCode(E_REQUEST_DENIED);
1824 /*---------------------------------------------------------------------------
1825 | Facility : libnform
1826 | Function : static int IFN_Down_Character(FORM * form)
1828 | Description : Move one line down. This doesn't cycle through the
1829 | lines of the field.
1831 | Return Values : E_OK - success
1832 | E_REQUEST_DENIED - already in last column
1833 +--------------------------------------------------------------------------*/
1835 IFN_Down_Character(FORM *form)
1837 FIELD *field = form->current;
1839 T((T_CALLED("IFN_Down_Character(%p)"), form));
1840 if ((++(form->currow)) == field->drows)
1842 #if GROW_IF_NAVIGATE
1843 if (!Single_Line_Field(field) && Field_Grown(field, 1))
1847 returnCode(E_REQUEST_DENIED);
1851 /*----------------------------------------------------------------------------
1852 END of Intra-Field Navigation routines
1853 --------------------------------------------------------------------------*/
1855 /*----------------------------------------------------------------------------
1856 Vertical scrolling helper routines
1857 --------------------------------------------------------------------------*/
1859 /*---------------------------------------------------------------------------
1860 | Facility : libnform
1861 | Function : static int VSC_Generic(FORM *form, int nlines)
1863 | Description : Scroll multi-line field forward (nlines>0) or
1864 | backward (nlines<0) this many lines.
1866 | Return Values : E_OK - success
1867 | E_REQUEST_DENIED - can't scroll
1868 +--------------------------------------------------------------------------*/
1870 VSC_Generic(FORM *form, int nlines)
1872 FIELD *field = form->current;
1873 int res = E_REQUEST_DENIED;
1874 int rows_to_go = (nlines > 0 ? nlines : -nlines);
1878 if ((rows_to_go + form->toprow) > (field->drows - field->rows))
1879 rows_to_go = (field->drows - field->rows - form->toprow);
1883 form->currow += rows_to_go;
1884 form->toprow += rows_to_go;
1890 if (rows_to_go > form->toprow)
1891 rows_to_go = form->toprow;
1895 form->currow -= rows_to_go;
1896 form->toprow -= rows_to_go;
1902 /*----------------------------------------------------------------------------
1903 End of Vertical scrolling helper routines
1904 --------------------------------------------------------------------------*/
1906 /*----------------------------------------------------------------------------
1907 Vertical scrolling routines
1908 --------------------------------------------------------------------------*/
1910 /*---------------------------------------------------------------------------
1911 | Facility : libnform
1912 | Function : static int Vertical_Scrolling(
1913 | int (* const fct) (FORM *),
1916 | Description : Performs the generic vertical scrolling routines.
1917 | This has to check for a multi-line field and to set
1918 | the _NEWTOP flag if scrolling really occurred.
1920 | Return Values : Propagated error code from low-level driver calls
1921 +--------------------------------------------------------------------------*/
1923 Vertical_Scrolling(int (*const fct) (FORM *), FORM *form)
1925 int res = E_REQUEST_DENIED;
1927 if (!Single_Line_Field(form->current))
1931 form->current->status |= _NEWTOP;
1936 /*---------------------------------------------------------------------------
1937 | Facility : libnform
1938 | Function : static int VSC_Scroll_Line_Forward(FORM * form)
1940 | Description : Scroll multi-line field forward a line
1942 | Return Values : E_OK - success
1943 | E_REQUEST_DENIED - no data ahead
1944 +--------------------------------------------------------------------------*/
1946 VSC_Scroll_Line_Forward(FORM *form)
1948 T((T_CALLED("VSC_Scroll_Line_Forward(%p)"), form));
1949 returnCode(VSC_Generic(form, 1));
1952 /*---------------------------------------------------------------------------
1953 | Facility : libnform
1954 | Function : static int VSC_Scroll_Line_Backward(FORM * form)
1956 | Description : Scroll multi-line field backward a line
1958 | Return Values : E_OK - success
1959 | E_REQUEST_DENIED - no data behind
1960 +--------------------------------------------------------------------------*/
1962 VSC_Scroll_Line_Backward(FORM *form)
1964 T((T_CALLED("VSC_Scroll_Line_Backward(%p)"), form));
1965 returnCode(VSC_Generic(form, -1));
1968 /*---------------------------------------------------------------------------
1969 | Facility : libnform
1970 | Function : static int VSC_Scroll_Page_Forward(FORM * form)
1972 | Description : Scroll a multi-line field forward a page
1974 | Return Values : E_OK - success
1975 | E_REQUEST_DENIED - no data ahead
1976 +--------------------------------------------------------------------------*/
1978 VSC_Scroll_Page_Forward(FORM *form)
1980 T((T_CALLED("VSC_Scroll_Page_Forward(%p)"), form));
1981 returnCode(VSC_Generic(form, form->current->rows));
1984 /*---------------------------------------------------------------------------
1985 | Facility : libnform
1986 | Function : static int VSC_Scroll_Half_Page_Forward(FORM * form)
1988 | Description : Scroll a multi-line field forward half a page
1990 | Return Values : E_OK - success
1991 | E_REQUEST_DENIED - no data ahead
1992 +--------------------------------------------------------------------------*/
1994 VSC_Scroll_Half_Page_Forward(FORM *form)
1996 T((T_CALLED("VSC_Scroll_Half_Page_Forward(%p)"), form));
1997 returnCode(VSC_Generic(form, (form->current->rows + 1) / 2));
2000 /*---------------------------------------------------------------------------
2001 | Facility : libnform
2002 | Function : static int VSC_Scroll_Page_Backward(FORM * form)
2004 | Description : Scroll a multi-line field backward a page
2006 | Return Values : E_OK - success
2007 | E_REQUEST_DENIED - no data behind
2008 +--------------------------------------------------------------------------*/
2010 VSC_Scroll_Page_Backward(FORM *form)
2012 T((T_CALLED("VSC_Scroll_Page_Backward(%p)"), form));
2013 returnCode(VSC_Generic(form, -(form->current->rows)));
2016 /*---------------------------------------------------------------------------
2017 | Facility : libnform
2018 | Function : static int VSC_Scroll_Half_Page_Backward(FORM * form)
2020 | Description : Scroll a multi-line field backward half a page
2022 | Return Values : E_OK - success
2023 | E_REQUEST_DENIED - no data behind
2024 +--------------------------------------------------------------------------*/
2026 VSC_Scroll_Half_Page_Backward(FORM *form)
2028 T((T_CALLED("VSC_Scroll_Half_Page_Backward(%p)"), form));
2029 returnCode(VSC_Generic(form, -((form->current->rows + 1) / 2)));
2031 /*----------------------------------------------------------------------------
2032 End of Vertical scrolling routines
2033 --------------------------------------------------------------------------*/
2035 /*----------------------------------------------------------------------------
2036 Horizontal scrolling helper routines
2037 --------------------------------------------------------------------------*/
2039 /*---------------------------------------------------------------------------
2040 | Facility : libnform
2041 | Function : static int HSC_Generic(FORM *form, int ncolumns)
2043 | Description : Scroll single-line field forward (ncolumns>0) or
2044 | backward (ncolumns<0) this many columns.
2046 | Return Values : E_OK - success
2047 | E_REQUEST_DENIED - can't scroll
2048 +--------------------------------------------------------------------------*/
2050 HSC_Generic(FORM *form, int ncolumns)
2052 FIELD *field = form->current;
2053 int res = E_REQUEST_DENIED;
2054 int cols_to_go = (ncolumns > 0 ? ncolumns : -ncolumns);
2058 if ((cols_to_go + form->begincol) > (field->dcols - field->cols))
2059 cols_to_go = field->dcols - field->cols - form->begincol;
2063 form->curcol += cols_to_go;
2064 form->begincol += cols_to_go;
2070 if (cols_to_go > form->begincol)
2071 cols_to_go = form->begincol;
2075 form->curcol -= cols_to_go;
2076 form->begincol -= cols_to_go;
2082 /*----------------------------------------------------------------------------
2083 End of Horizontal scrolling helper routines
2084 --------------------------------------------------------------------------*/
2086 /*----------------------------------------------------------------------------
2087 Horizontal scrolling routines
2088 --------------------------------------------------------------------------*/
2090 /*---------------------------------------------------------------------------
2091 | Facility : libnform
2092 | Function : static int Horizontal_Scrolling(
2093 | int (* const fct) (FORM *),
2096 | Description : Performs the generic horizontal scrolling routines.
2097 | This has to check for a single-line field.
2099 | Return Values : Propagated error code from low-level driver calls
2100 +--------------------------------------------------------------------------*/
2102 Horizontal_Scrolling(int (*const fct) (FORM *), FORM *form)
2104 if (Single_Line_Field(form->current))
2107 return (E_REQUEST_DENIED);
2110 /*---------------------------------------------------------------------------
2111 | Facility : libnform
2112 | Function : static int HSC_Scroll_Char_Forward(FORM * form)
2114 | Description : Scroll single-line field forward a character
2116 | Return Values : E_OK - success
2117 | E_REQUEST_DENIED - no data ahead
2118 +--------------------------------------------------------------------------*/
2120 HSC_Scroll_Char_Forward(FORM *form)
2122 T((T_CALLED("HSC_Scroll_Char_Forward(%p)"), form));
2123 returnCode(HSC_Generic(form, 1));
2126 /*---------------------------------------------------------------------------
2127 | Facility : libnform
2128 | Function : static int HSC_Scroll_Char_Backward(FORM * form)
2130 | Description : Scroll single-line field backward a character
2132 | Return Values : E_OK - success
2133 | E_REQUEST_DENIED - no data behind
2134 +--------------------------------------------------------------------------*/
2136 HSC_Scroll_Char_Backward(FORM *form)
2138 T((T_CALLED("HSC_Scroll_Char_Backward(%p)"), form));
2139 returnCode(HSC_Generic(form, -1));
2142 /*---------------------------------------------------------------------------
2143 | Facility : libnform
2144 | Function : static int HSC_Horizontal_Line_Forward(FORM* form)
2146 | Description : Scroll single-line field forward a line
2148 | Return Values : E_OK - success
2149 | E_REQUEST_DENIED - no data ahead
2150 +--------------------------------------------------------------------------*/
2152 HSC_Horizontal_Line_Forward(FORM *form)
2154 T((T_CALLED("HSC_Horizontal_Line_Forward(%p)"), form));
2155 returnCode(HSC_Generic(form, form->current->cols));
2158 /*---------------------------------------------------------------------------
2159 | Facility : libnform
2160 | Function : static int HSC_Horizontal_Half_Line_Forward(FORM* form)
2162 | Description : Scroll single-line field forward half a line
2164 | Return Values : E_OK - success
2165 | E_REQUEST_DENIED - no data ahead
2166 +--------------------------------------------------------------------------*/
2168 HSC_Horizontal_Half_Line_Forward(FORM *form)
2170 T((T_CALLED("HSC_Horizontal_Half_Line_Forward(%p)"), form));
2171 returnCode(HSC_Generic(form, (form->current->cols + 1) / 2));
2174 /*---------------------------------------------------------------------------
2175 | Facility : libnform
2176 | Function : static int HSC_Horizontal_Line_Backward(FORM* form)
2178 | Description : Scroll single-line field backward a line
2180 | Return Values : E_OK - success
2181 | E_REQUEST_DENIED - no data behind
2182 +--------------------------------------------------------------------------*/
2184 HSC_Horizontal_Line_Backward(FORM *form)
2186 T((T_CALLED("HSC_Horizontal_Line_Backward(%p)"), form));
2187 returnCode(HSC_Generic(form, -(form->current->cols)));
2190 /*---------------------------------------------------------------------------
2191 | Facility : libnform
2192 | Function : static int HSC_Horizontal_Half_Line_Backward(FORM* form)
2194 | Description : Scroll single-line field backward half a line
2196 | Return Values : E_OK - success
2197 | E_REQUEST_DENIED - no data behind
2198 +--------------------------------------------------------------------------*/
2200 HSC_Horizontal_Half_Line_Backward(FORM *form)
2202 T((T_CALLED("HSC_Horizontal_Half_Line_Backward(%p)"), form));
2203 returnCode(HSC_Generic(form, -((form->current->cols + 1) / 2)));
2206 /*----------------------------------------------------------------------------
2207 End of Horizontal scrolling routines
2208 --------------------------------------------------------------------------*/
2210 /*----------------------------------------------------------------------------
2211 Helper routines for Field Editing
2212 --------------------------------------------------------------------------*/
2214 /*---------------------------------------------------------------------------
2215 | Facility : libnform
2216 | Function : static bool Is_There_Room_For_A_Line(FORM * form)
2218 | Description : Check whether or not there is enough room in the
2219 | buffer to enter a whole line.
2221 | Return Values : TRUE - there is enough space
2222 | FALSE - there is not enough space
2223 +--------------------------------------------------------------------------*/
2224 NCURSES_INLINE static bool
2225 Is_There_Room_For_A_Line(FORM *form)
2227 FIELD *field = form->current;
2228 FIELD_CELL *begin_of_last_line, *s;
2230 Synchronize_Buffer(form);
2231 begin_of_last_line = Address_Of_Row_In_Buffer(field, (field->drows - 1));
2232 s = After_End_Of_Data(begin_of_last_line, field->dcols);
2233 return ((s == begin_of_last_line) ? TRUE : FALSE);
2236 /*---------------------------------------------------------------------------
2237 | Facility : libnform
2238 | Function : static bool Is_There_Room_For_A_Char_In_Line(FORM * form)
2240 | Description : Checks whether or not there is room for a new character
2241 | in the current line.
2243 | Return Values : TRUE - there is room
2244 | FALSE - there is not enough room (line full)
2245 +--------------------------------------------------------------------------*/
2246 NCURSES_INLINE static bool
2247 Is_There_Room_For_A_Char_In_Line(FORM *form)
2249 int last_char_in_line;
2251 wmove(form->w, form->currow, form->current->dcols - 1);
2252 last_char_in_line = (int)(winch(form->w) & A_CHARTEXT);
2253 wmove(form->w, form->currow, form->curcol);
2254 return (((last_char_in_line == form->current->pad) ||
2255 is_blank(last_char_in_line)) ? TRUE : FALSE);
2258 #define There_Is_No_Room_For_A_Char_In_Line(f) \
2259 !Is_There_Room_For_A_Char_In_Line(f)
2261 /*---------------------------------------------------------------------------
2262 | Facility : libnform
2263 | Function : static int Insert_String(
2269 | Description : Insert the 'len' characters beginning at pointer 'txt'
2270 | into the 'row' of the 'form'. The insertion occurs
2271 | on the beginning of the row, all other characters are
2272 | moved to the right. After the text a pad character will
2273 | be inserted to separate the text from the rest. If
2274 | necessary the insertion moves characters on the next
2275 | line to make place for the requested insertion string.
2277 | Return Values : E_OK - success
2278 | E_REQUEST_DENIED -
2279 | E_SYSTEM_ERROR - system error
2280 +--------------------------------------------------------------------------*/
2282 Insert_String(FORM *form, int row, FIELD_CELL *txt, int len)
2284 FIELD *field = form->current;
2285 FIELD_CELL *bp = Address_Of_Row_In_Buffer(field, row);
2286 int datalen = (int)(After_End_Of_Data(bp, field->dcols) - bp);
2287 int freelen = field->dcols - datalen;
2288 int requiredlen = len + 1;
2290 int result = E_REQUEST_DENIED;
2292 if (freelen >= requiredlen)
2294 wmove(form->w, row, 0);
2295 myINSNSTR(form->w, txt, len);
2296 wmove(form->w, row, len);
2297 myINSNSTR(form->w, &myBLANK, 1);
2302 /* we have to move characters on the next line. If we are on the
2303 last line this may work, if the field is growable */
2304 if ((row == (field->drows - 1)) && Growable(field))
2306 if (!Field_Grown(field, 1))
2307 return (E_SYSTEM_ERROR);
2308 /* !!!Side-Effect : might be changed due to growth!!! */
2309 bp = Address_Of_Row_In_Buffer(field, row);
2312 if (row < (field->drows - 1))
2315 After_Last_Whitespace_Character(bp,
2316 (int)(Get_Start_Of_Data(bp
2321 /* split points now to the first character of the portion of the
2322 line that must be moved to the next line */
2323 datalen = (int)(split - bp); /* + freelen has to stay on this line */
2324 freelen = field->dcols - (datalen + freelen); /* for the next line */
2326 if ((result = Insert_String(form, row + 1, split, freelen)) == E_OK)
2328 wmove(form->w, row, datalen);
2330 wmove(form->w, row, 0);
2331 myINSNSTR(form->w, txt, len);
2332 wmove(form->w, row, len);
2333 myINSNSTR(form->w, &myBLANK, 1);
2341 /*---------------------------------------------------------------------------
2342 | Facility : libnform
2343 | Function : static int Wrapping_Not_Necessary_Or_Wrapping_Ok(
2346 | Description : If a character has been entered into a field, it may
2347 | be that wrapping has to occur. This routine checks
2348 | whether or not wrapping is required and if so, performs
2351 | Return Values : E_OK - no wrapping required or wrapping
2353 | E_REQUEST_DENIED -
2354 | E_SYSTEM_ERROR - some system error
2355 +--------------------------------------------------------------------------*/
2357 Wrapping_Not_Necessary_Or_Wrapping_Ok(FORM *form)
2359 FIELD *field = form->current;
2360 int result = E_REQUEST_DENIED;
2361 bool Last_Row = ((field->drows - 1) == form->currow);
2363 if ((field->opts & O_WRAP) && /* wrapping wanted */
2364 (!Single_Line_Field(field)) && /* must be multi-line */
2365 (There_Is_No_Room_For_A_Char_In_Line(form)) && /* line is full */
2366 (!Last_Row || Growable(field))) /* there are more lines */
2370 int chars_to_be_wrapped;
2371 int chars_to_remain_on_line;
2375 /* the above logic already ensures, that in this case the field
2377 if (!Field_Grown(field, 1))
2378 return E_SYSTEM_ERROR;
2380 bp = Address_Of_Current_Row_In_Buffer(form);
2381 Window_To_Buffer(form->w, field);
2382 split = After_Last_Whitespace_Character(bp, field->dcols);
2383 /* split points to the first character of the sequence to be brought
2385 chars_to_remain_on_line = (int)(split - bp);
2386 chars_to_be_wrapped = field->dcols - chars_to_remain_on_line;
2387 if (chars_to_remain_on_line > 0)
2389 if ((result = Insert_String(form, form->currow + 1, split,
2390 chars_to_be_wrapped)) == E_OK)
2392 wmove(form->w, form->currow, chars_to_remain_on_line);
2394 if (form->curcol >= chars_to_remain_on_line)
2397 form->curcol -= chars_to_remain_on_line;
2407 Window_To_Buffer(form->w, field);
2408 result = E_REQUEST_DENIED;
2412 result = E_OK; /* wrapping was not necessary */
2416 /*----------------------------------------------------------------------------
2417 Field Editing routines
2418 --------------------------------------------------------------------------*/
2420 /*---------------------------------------------------------------------------
2421 | Facility : libnform
2422 | Function : static int Field_Editing(
2423 | int (* const fct) (FORM *),
2426 | Description : Generic routine for field editing requests. The driver
2427 | routines are only called for editable fields, the
2428 | _WINDOW_MODIFIED flag is set if editing occurred.
2429 | This is somewhat special due to the overload semantics
2430 | of the NEW_LINE and DEL_PREV requests.
2432 | Return Values : Error code from low level drivers.
2433 +--------------------------------------------------------------------------*/
2435 Field_Editing(int (*const fct) (FORM *), FORM *form)
2437 int res = E_REQUEST_DENIED;
2439 /* We have to deal here with the specific case of the overloaded
2440 behavior of New_Line and Delete_Previous requests.
2441 They may end up in navigational requests if we are on the first
2442 character in a field. But navigation is also allowed on non-
2445 if ((fct == FE_Delete_Previous) &&
2446 (form->opts & O_BS_OVERLOAD) &&
2447 First_Position_In_Current_Field(form))
2449 res = Inter_Field_Navigation(FN_Previous_Field, form);
2453 if (fct == FE_New_Line)
2455 if ((form->opts & O_NL_OVERLOAD) &&
2456 First_Position_In_Current_Field(form))
2458 res = Inter_Field_Navigation(FN_Next_Field, form);
2461 /* FE_New_Line deals itself with the _WINDOW_MODIFIED flag */
2466 /* From now on, everything must be editable */
2467 if (form->current->opts & O_EDIT)
2471 form->status |= _WINDOW_MODIFIED;
2478 /*---------------------------------------------------------------------------
2479 | Facility : libnform
2480 | Function : static int FE_New_Line(FORM * form)
2482 | Description : Perform a new line request. This is rather complex
2483 | compared to other routines in this code due to the
2484 | rather difficult to understand description in the
2487 | Return Values : E_OK - success
2488 | E_REQUEST_DENIED - new line not allowed
2489 | E_SYSTEM_ERROR - system error
2490 +--------------------------------------------------------------------------*/
2492 FE_New_Line(FORM *form)
2494 FIELD *field = form->current;
2496 bool Last_Row = ((field->drows - 1) == form->currow);
2498 T((T_CALLED("FE_New_Line(%p)"), form));
2499 if (form->status & _OVLMODE)
2502 (!(Growable(field) && !Single_Line_Field(field))))
2504 if (!(form->opts & O_NL_OVERLOAD))
2505 returnCode(E_REQUEST_DENIED);
2506 wmove(form->w, form->currow, form->curcol);
2508 /* we have to set this here, although it is also
2509 handled in the generic routine. The reason is,
2510 that FN_Next_Field may fail, but the form is
2511 definitively changed */
2512 form->status |= _WINDOW_MODIFIED;
2513 returnCode(Inter_Field_Navigation(FN_Next_Field, form));
2517 if (Last_Row && !Field_Grown(field, 1))
2519 /* N.B.: due to the logic in the 'if', LastRow==TRUE
2520 means here that the field is growable and not
2521 a single-line field */
2522 returnCode(E_SYSTEM_ERROR);
2524 wmove(form->w, form->currow, form->curcol);
2528 form->status |= _WINDOW_MODIFIED;
2536 !(Growable(field) && !Single_Line_Field(field)))
2538 if (!(form->opts & O_NL_OVERLOAD))
2539 returnCode(E_REQUEST_DENIED);
2540 returnCode(Inter_Field_Navigation(FN_Next_Field, form));
2544 bool May_Do_It = !Last_Row && Is_There_Room_For_A_Line(form);
2546 if (!(May_Do_It || Growable(field)))
2547 returnCode(E_REQUEST_DENIED);
2548 if (!May_Do_It && !Field_Grown(field, 1))
2549 returnCode(E_SYSTEM_ERROR);
2551 bp = Address_Of_Current_Position_In_Buffer(form);
2552 t = After_End_Of_Data(bp, field->dcols - form->curcol);
2553 wmove(form->w, form->currow, form->curcol);
2557 wmove(form->w, form->currow, form->curcol);
2559 myADDNSTR(form->w, bp, (int)(t - bp));
2560 form->status |= _WINDOW_MODIFIED;
2566 /*---------------------------------------------------------------------------
2567 | Facility : libnform
2568 | Function : static int FE_Insert_Character(FORM * form)
2570 | Description : Insert blank character at the cursor position
2572 | Return Values : E_OK
2574 +--------------------------------------------------------------------------*/
2576 FE_Insert_Character(FORM *form)
2578 FIELD *field = form->current;
2579 int result = E_REQUEST_DENIED;
2581 T((T_CALLED("FE_Insert_Character(%p)"), form));
2582 if (Check_Char(field->type, (int)C_BLANK, (TypeArgument *)(field->arg)))
2584 bool There_Is_Room = Is_There_Room_For_A_Char_In_Line(form);
2586 if (There_Is_Room ||
2587 ((Single_Line_Field(field) && Growable(field))))
2589 if (!There_Is_Room && !Field_Grown(field, 1))
2590 result = E_SYSTEM_ERROR;
2593 winsch(form->w, (chtype)C_BLANK);
2594 result = Wrapping_Not_Necessary_Or_Wrapping_Ok(form);
2601 /*---------------------------------------------------------------------------
2602 | Facility : libnform
2603 | Function : static int FE_Insert_Line(FORM * form)
2605 | Description : Insert a blank line at the cursor position
2607 | Return Values : E_OK - success
2608 | E_REQUEST_DENIED - line can not be inserted
2609 +--------------------------------------------------------------------------*/
2611 FE_Insert_Line(FORM *form)
2613 FIELD *field = form->current;
2614 int result = E_REQUEST_DENIED;
2616 T((T_CALLED("FE_Insert_Line(%p)"), form));
2617 if (Check_Char(field->type, (int)C_BLANK, (TypeArgument *)(field->arg)))
2619 bool Maybe_Done = (form->currow != (field->drows - 1)) &&
2620 Is_There_Room_For_A_Line(form);
2622 if (!Single_Line_Field(field) &&
2623 (Maybe_Done || Growable(field)))
2625 if (!Maybe_Done && !Field_Grown(field, 1))
2626 result = E_SYSTEM_ERROR;
2638 /*---------------------------------------------------------------------------
2639 | Facility : libnform
2640 | Function : static int FE_Delete_Character(FORM * form)
2642 | Description : Delete character at the cursor position
2644 | Return Values : E_OK - success
2645 +--------------------------------------------------------------------------*/
2647 FE_Delete_Character(FORM *form)
2649 T((T_CALLED("FE_Delete_Character(%p)"), form));
2654 /*---------------------------------------------------------------------------
2655 | Facility : libnform
2656 | Function : static int FE_Delete_Previous(FORM * form)
2658 | Description : Delete character before cursor. Again this is a rather
2659 | difficult piece compared to others due to the overloading
2660 | semantics of backspace.
2661 | N.B.: The case of overloaded BS on first field position
2662 | is already handled in the generic routine.
2664 | Return Values : E_OK - success
2665 | E_REQUEST_DENIED - Character can't be deleted
2666 +--------------------------------------------------------------------------*/
2668 FE_Delete_Previous(FORM *form)
2670 FIELD *field = form->current;
2672 T((T_CALLED("FE_Delete_Previous(%p)"), form));
2673 if (First_Position_In_Current_Field(form))
2674 returnCode(E_REQUEST_DENIED);
2676 if ((--(form->curcol)) < 0)
2678 FIELD_CELL *this_line, *prev_line, *prev_end, *this_end;
2679 int this_row = form->currow;
2682 if (form->status & _OVLMODE)
2683 returnCode(E_REQUEST_DENIED);
2685 prev_line = Address_Of_Row_In_Buffer(field, (form->currow - 1));
2686 this_line = Address_Of_Row_In_Buffer(field, (form->currow));
2687 Synchronize_Buffer(form);
2688 prev_end = After_End_Of_Data(prev_line, field->dcols);
2689 this_end = After_End_Of_Data(this_line, field->dcols);
2690 if ((int)(this_end - this_line) >
2691 (field->cols - (int)(prev_end - prev_line)))
2692 returnCode(E_REQUEST_DENIED);
2693 wmove(form->w, form->currow, form->curcol);
2695 Adjust_Cursor_Position(form, prev_end);
2697 * If we did not really move to the previous line, help the user a
2698 * little. It is however a little inconsistent. Normally, when
2699 * backspacing around the point where text wraps to a new line in a
2700 * multi-line form, we absorb one keystroke for the wrapping point. That
2701 * is consistent with SVr4 forms. However, SVr4 does not allow typing
2702 * into the last column of the field, and requires the user to enter a
2703 * newline to move to the next line. Therefore it can consistently eat
2704 * that keystroke. Since ncurses allows the last column, it wraps
2705 * automatically (given the proper options). But we cannot eat the
2706 * keystroke to back over the wrapping point, since that would put the
2707 * cursor past the end of the form field. In this case, just delete the
2708 * character at the end of the field.
2710 if (form->currow == this_row && this_row > 0)
2713 form->curcol = field->dcols - 1;
2718 wmove(form->w, form->currow, form->curcol);
2719 myADDNSTR(form->w, this_line, (int)(this_end - this_line));
2729 /*---------------------------------------------------------------------------
2730 | Facility : libnform
2731 | Function : static int FE_Delete_Line(FORM * form)
2733 | Description : Delete line at cursor position.
2735 | Return Values : E_OK - success
2736 +--------------------------------------------------------------------------*/
2738 FE_Delete_Line(FORM *form)
2740 T((T_CALLED("FE_Delete_Line(%p)"), form));
2746 /*---------------------------------------------------------------------------
2747 | Facility : libnform
2748 | Function : static int FE_Delete_Word(FORM * form)
2750 | Description : Delete word at cursor position
2752 | Return Values : E_OK - success
2753 | E_REQUEST_DENIED - failure
2754 +--------------------------------------------------------------------------*/
2756 FE_Delete_Word(FORM *form)
2758 FIELD *field = form->current;
2759 FIELD_CELL *bp = Address_Of_Current_Row_In_Buffer(form);
2760 FIELD_CELL *ep = bp + field->dcols;
2761 FIELD_CELL *cp = bp + form->curcol;
2764 T((T_CALLED("FE_Delete_Word(%p)"), form));
2765 Synchronize_Buffer(form);
2767 returnCode(E_REQUEST_DENIED); /* not in word */
2769 /* move cursor to begin of word and erase to end of screen-line */
2770 Adjust_Cursor_Position(form,
2771 After_Last_Whitespace_Character(bp, form->curcol));
2772 wmove(form->w, form->currow, form->curcol);
2775 /* skip over word in buffer */
2776 s = Get_First_Whitespace_Character(cp, (int)(ep - cp));
2777 /* to begin of next word */
2778 s = Get_Start_Of_Data(s, (int)(ep - s));
2779 if ((s != cp) && !ISBLANK(*s))
2781 /* copy remaining line to window */
2782 myADDNSTR(form->w, s, (int)(s - After_End_Of_Data(s, (int)(ep - s))));
2787 /*---------------------------------------------------------------------------
2788 | Facility : libnform
2789 | Function : static int FE_Clear_To_End_Of_Line(FORM * form)
2791 | Description : Clear to end of current line.
2793 | Return Values : E_OK - success
2794 +--------------------------------------------------------------------------*/
2796 FE_Clear_To_End_Of_Line(FORM *form)
2798 T((T_CALLED("FE_Clear_To_End_Of_Line(%p)"), form));
2799 wmove(form->w, form->currow, form->curcol);
2804 /*---------------------------------------------------------------------------
2805 | Facility : libnform
2806 | Function : static int FE_Clear_To_End_Of_Field(FORM * form)
2808 | Description : Clear to end of field.
2810 | Return Values : E_OK - success
2811 +--------------------------------------------------------------------------*/
2813 FE_Clear_To_End_Of_Field(FORM *form)
2815 T((T_CALLED("FE_Clear_To_End_Of_Field(%p)"), form));
2816 wmove(form->w, form->currow, form->curcol);
2821 /*---------------------------------------------------------------------------
2822 | Facility : libnform
2823 | Function : static int FE_Clear_Field(FORM * form)
2825 | Description : Clear entire field.
2827 | Return Values : E_OK - success
2828 +--------------------------------------------------------------------------*/
2830 FE_Clear_Field(FORM *form)
2832 T((T_CALLED("FE_Clear_Field(%p)"), form));
2833 form->currow = form->curcol = 0;
2837 /*----------------------------------------------------------------------------
2838 END of Field Editing routines
2839 --------------------------------------------------------------------------*/
2841 /*----------------------------------------------------------------------------
2843 --------------------------------------------------------------------------*/
2845 /*---------------------------------------------------------------------------
2846 | Facility : libnform
2847 | Function : static int EM_Overlay_Mode(FORM * form)
2849 | Description : Switch to overlay mode.
2851 | Return Values : E_OK - success
2852 +--------------------------------------------------------------------------*/
2854 EM_Overlay_Mode(FORM *form)
2856 T((T_CALLED("EM_Overlay_Mode(%p)"), form));
2857 form->status |= _OVLMODE;
2861 /*---------------------------------------------------------------------------
2862 | Facility : libnform
2863 | Function : static int EM_Insert_Mode(FORM * form)
2865 | Description : Switch to insert mode
2867 | Return Values : E_OK - success
2868 +--------------------------------------------------------------------------*/
2870 EM_Insert_Mode(FORM *form)
2872 T((T_CALLED("EM_Insert_Mode(%p)"), form));
2873 form->status &= ~_OVLMODE;
2877 /*----------------------------------------------------------------------------
2878 END of Edit Mode routines
2879 --------------------------------------------------------------------------*/
2881 /*----------------------------------------------------------------------------
2882 Helper routines for Choice Requests
2883 --------------------------------------------------------------------------*/
2885 /*---------------------------------------------------------------------------
2886 | Facility : libnform
2887 | Function : static bool Next_Choice(
2890 | TypeArgument *argp)
2892 | Description : Get the next field choice. For linked types this is
2895 | Return Values : TRUE - next choice successfully retrieved
2896 | FALSE - couldn't retrieve next choice
2897 +--------------------------------------------------------------------------*/
2899 Next_Choice(FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
2901 if (!typ || !(typ->status & _HAS_CHOICE))
2904 if (typ->status & _LINKED_TYPE)
2908 Next_Choice(typ->left, field, argp->left) ||
2909 Next_Choice(typ->right, field, argp->right));
2914 return typ->next(field, (void *)argp);
2918 /*---------------------------------------------------------------------------
2919 | Facility : libnform
2920 | Function : static bool Previous_Choice(
2923 | TypeArgument *argp)
2925 | Description : Get the previous field choice. For linked types this
2926 | is done recursively.
2928 | Return Values : TRUE - previous choice successfully retrieved
2929 | FALSE - couldn't retrieve previous choice
2930 +--------------------------------------------------------------------------*/
2932 Previous_Choice(FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
2934 if (!typ || !(typ->status & _HAS_CHOICE))
2937 if (typ->status & _LINKED_TYPE)
2941 Previous_Choice(typ->left, field, argp->left) ||
2942 Previous_Choice(typ->right, field, argp->right));
2947 return typ->prev(field, (void *)argp);
2950 /*----------------------------------------------------------------------------
2951 End of Helper routines for Choice Requests
2952 --------------------------------------------------------------------------*/
2954 /*----------------------------------------------------------------------------
2955 Routines for Choice Requests
2956 --------------------------------------------------------------------------*/
2958 /*---------------------------------------------------------------------------
2959 | Facility : libnform
2960 | Function : static int CR_Next_Choice(FORM * form)
2962 | Description : Get the next field choice.
2964 | Return Values : E_OK - success
2965 | E_REQUEST_DENIED - next choice couldn't be retrieved
2966 +--------------------------------------------------------------------------*/
2968 CR_Next_Choice(FORM *form)
2970 FIELD *field = form->current;
2972 T((T_CALLED("CR_Next_Choice(%p)"), form));
2973 Synchronize_Buffer(form);
2974 returnCode((Next_Choice(field->type, field, (TypeArgument *)(field->arg)))
2976 : E_REQUEST_DENIED);
2979 /*---------------------------------------------------------------------------
2980 | Facility : libnform
2981 | Function : static int CR_Previous_Choice(FORM * form)
2983 | Description : Get the previous field choice.
2985 | Return Values : E_OK - success
2986 | E_REQUEST_DENIED - prev. choice couldn't be retrieved
2987 +--------------------------------------------------------------------------*/
2989 CR_Previous_Choice(FORM *form)
2991 FIELD *field = form->current;
2993 T((T_CALLED("CR_Previous_Choice(%p)"), form));
2994 Synchronize_Buffer(form);
2995 returnCode((Previous_Choice(field->type, field, (TypeArgument *)(field->arg)))
2997 : E_REQUEST_DENIED);
2999 /*----------------------------------------------------------------------------
3000 End of Routines for Choice Requests
3001 --------------------------------------------------------------------------*/
3003 /*----------------------------------------------------------------------------
3004 Helper routines for Field Validations.
3005 --------------------------------------------------------------------------*/
3007 /*---------------------------------------------------------------------------
3008 | Facility : libnform
3009 | Function : static bool Check_Field(
3012 | TypeArgument * argp)
3014 | Description : Check the field according to its fieldtype and its
3015 | actual arguments. For linked fieldtypes this is done
3018 | Return Values : TRUE - field is valid
3019 | FALSE - field is invalid.
3020 +--------------------------------------------------------------------------*/
3022 Check_Field(FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
3026 if (field->opts & O_NULLOK)
3028 FIELD_CELL *bp = field->buf;
3031 while (ISBLANK(*bp))
3035 if (CharOf(*bp) == 0)
3039 if (typ->status & _LINKED_TYPE)
3043 Check_Field(typ->left, field, argp->left) ||
3044 Check_Field(typ->right, field, argp->right));
3049 return typ->fcheck(field, (void *)argp);
3055 /*---------------------------------------------------------------------------
3056 | Facility : libnform
3057 | Function : bool _nc_Internal_Validation(FORM * form )
3059 | Description : Validate the current field of the form.
3061 | Return Values : TRUE - field is valid
3062 | FALSE - field is invalid
3063 +--------------------------------------------------------------------------*/
3064 NCURSES_EXPORT(bool)
3065 _nc_Internal_Validation(FORM *form)
3069 field = form->current;
3071 Synchronize_Buffer(form);
3072 if ((form->status & _FCHECK_REQUIRED) ||
3073 (!(field->opts & O_PASSOK)))
3075 if (!Check_Field(field->type, field, (TypeArgument *)(field->arg)))
3077 form->status &= ~_FCHECK_REQUIRED;
3078 field->status |= _CHANGED;
3079 Synchronize_Linked_Fields(field);
3083 /*----------------------------------------------------------------------------
3084 End of Helper routines for Field Validations.
3085 --------------------------------------------------------------------------*/
3087 /*----------------------------------------------------------------------------
3088 Routines for Field Validation.
3089 --------------------------------------------------------------------------*/
3091 /*---------------------------------------------------------------------------
3092 | Facility : libnform
3093 | Function : static int FV_Validation(FORM * form)
3095 | Description : Validate the current field of the form.
3097 | Return Values : E_OK - field valid
3098 | E_INVALID_FIELD - field not valid
3099 +--------------------------------------------------------------------------*/
3101 FV_Validation(FORM *form)
3103 T((T_CALLED("FV_Validation(%p)"), form));
3104 if (_nc_Internal_Validation(form))
3107 returnCode(E_INVALID_FIELD);
3109 /*----------------------------------------------------------------------------
3110 End of routines for Field Validation.
3111 --------------------------------------------------------------------------*/
3113 /*----------------------------------------------------------------------------
3114 Helper routines for Inter-Field Navigation
3115 --------------------------------------------------------------------------*/
3117 /*---------------------------------------------------------------------------
3118 | Facility : libnform
3119 | Function : static FIELD *Next_Field_On_Page(FIELD * field)
3121 | Description : Get the next field after the given field on the current
3122 | page. The order of fields is the one defined by the
3123 | fields array. Only visible and active fields are
3126 | Return Values : Pointer to the next field.
3127 +--------------------------------------------------------------------------*/
3128 NCURSES_INLINE static FIELD *
3129 Next_Field_On_Page(FIELD *field)
3131 FORM *form = field->form;
3132 FIELD **field_on_page = &form->field[field->index];
3133 FIELD **first_on_page = &form->field[form->page[form->curpage].pmin];
3134 FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
3139 (field_on_page == last_on_page) ? first_on_page : field_on_page + 1;
3140 if (Field_Is_Selectable(*field_on_page))
3143 while (field != (*field_on_page));
3144 return (*field_on_page);
3147 /*---------------------------------------------------------------------------
3148 | Facility : libnform
3149 | Function : FIELD* _nc_First_Active_Field(FORM * form)
3151 | Description : Get the first active field on the current page,
3152 | if there are such. If there are none, get the first
3153 | visible field on the page. If there are also none,
3154 | we return the first field on page and hope the best.
3156 | Return Values : Pointer to calculated field.
3157 +--------------------------------------------------------------------------*/
3158 NCURSES_EXPORT(FIELD *)
3159 _nc_First_Active_Field(FORM *form)
3161 FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
3162 FIELD *proposed = Next_Field_On_Page(*last_on_page);
3164 if (proposed == *last_on_page)
3166 /* there might be the special situation, where there is no
3167 active and visible field on the current page. We then select
3168 the first visible field on this readonly page
3170 if (Field_Is_Not_Selectable(proposed))
3172 FIELD **field = &form->field[proposed->index];
3173 FIELD **first = &form->field[form->page[form->curpage].pmin];
3177 field = (field == last_on_page) ? first : field + 1;
3178 if (((*field)->opts & O_VISIBLE))
3181 while (proposed != (*field));
3185 if ((proposed == *last_on_page) && !(proposed->opts & O_VISIBLE))
3187 /* This means, there is also no visible field on the page.
3188 So we propose the first one and hope the very best...
3189 Some very clever user has designed a readonly and invisible
3199 /*---------------------------------------------------------------------------
3200 | Facility : libnform
3201 | Function : static FIELD *Previous_Field_On_Page(FIELD * field)
3203 | Description : Get the previous field before the given field on the
3204 | current page. The order of fields is the one defined by
3205 | the fields array. Only visible and active fields are
3208 | Return Values : Pointer to the previous field.
3209 +--------------------------------------------------------------------------*/
3210 NCURSES_INLINE static FIELD *
3211 Previous_Field_On_Page(FIELD *field)
3213 FORM *form = field->form;
3214 FIELD **field_on_page = &form->field[field->index];
3215 FIELD **first_on_page = &form->field[form->page[form->curpage].pmin];
3216 FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
3221 (field_on_page == first_on_page) ? last_on_page : field_on_page - 1;
3222 if (Field_Is_Selectable(*field_on_page))
3225 while (field != (*field_on_page));
3227 return (*field_on_page);
3230 /*---------------------------------------------------------------------------
3231 | Facility : libnform
3232 | Function : static FIELD *Sorted_Next_Field(FIELD * field)
3234 | Description : Get the next field after the given field on the current
3235 | page. The order of fields is the one defined by the
3236 | (row,column) geometry, rows are major.
3238 | Return Values : Pointer to the next field.
3239 +--------------------------------------------------------------------------*/
3240 NCURSES_INLINE static FIELD *
3241 Sorted_Next_Field(FIELD *field)
3243 FIELD *field_on_page = field;
3247 field_on_page = field_on_page->snext;
3248 if (Field_Is_Selectable(field_on_page))
3251 while (field_on_page != field);
3253 return (field_on_page);
3256 /*---------------------------------------------------------------------------
3257 | Facility : libnform
3258 | Function : static FIELD *Sorted_Previous_Field(FIELD * field)
3260 | Description : Get the previous field before the given field on the
3261 | current page. The order of fields is the one defined
3262 | by the (row,column) geometry, rows are major.
3264 | Return Values : Pointer to the previous field.
3265 +--------------------------------------------------------------------------*/
3266 NCURSES_INLINE static FIELD *
3267 Sorted_Previous_Field(FIELD *field)
3269 FIELD *field_on_page = field;
3273 field_on_page = field_on_page->sprev;
3274 if (Field_Is_Selectable(field_on_page))
3277 while (field_on_page != field);
3279 return (field_on_page);
3282 /*---------------------------------------------------------------------------
3283 | Facility : libnform
3284 | Function : static FIELD *Left_Neighbor_Field(FIELD * field)
3286 | Description : Get the left neighbor of the field on the same line
3287 | and the same page. Cycles through the line.
3289 | Return Values : Pointer to left neighbor field.
3290 +--------------------------------------------------------------------------*/
3291 NCURSES_INLINE static FIELD *
3292 Left_Neighbor_Field(FIELD *field)
3294 FIELD *field_on_page = field;
3296 /* For a field that has really a left neighbor, the while clause
3297 immediately fails and the loop is left, positioned at the right
3298 neighbor. Otherwise we cycle backwards through the sorted field list
3299 until we enter the same line (from the right end).
3303 field_on_page = Sorted_Previous_Field(field_on_page);
3305 while (field_on_page->frow != field->frow);
3307 return (field_on_page);
3310 /*---------------------------------------------------------------------------
3311 | Facility : libnform
3312 | Function : static FIELD *Right_Neighbor_Field(FIELD * field)
3314 | Description : Get the right neighbor of the field on the same line
3315 | and the same page.
3317 | Return Values : Pointer to right neighbor field.
3318 +--------------------------------------------------------------------------*/
3319 NCURSES_INLINE static FIELD *
3320 Right_Neighbor_Field(FIELD *field)
3322 FIELD *field_on_page = field;
3324 /* See the comments on Left_Neighbor_Field to understand how it works */
3327 field_on_page = Sorted_Next_Field(field_on_page);
3329 while (field_on_page->frow != field->frow);
3331 return (field_on_page);
3334 /*---------------------------------------------------------------------------
3335 | Facility : libnform
3336 | Function : static FIELD *Upper_Neighbor_Field(FIELD * field)
3338 | Description : Because of the row-major nature of sorting the fields,
3339 | it is more difficult to define whats the upper neighbor
3340 | field really means. We define that it must be on a
3341 | 'previous' line (cyclic order!) and is the rightmost
3342 | field laying on the left side of the given field. If
3343 | this set is empty, we take the first field on the line.
3345 | Return Values : Pointer to the upper neighbor field.
3346 +--------------------------------------------------------------------------*/
3348 Upper_Neighbor_Field(FIELD *field)
3350 FIELD *field_on_page = field;
3351 int frow = field->frow;
3352 int fcol = field->fcol;
3354 /* Walk back to the 'previous' line. The second term in the while clause
3355 just guarantees that we stop if we cycled through the line because
3356 there might be no 'previous' line if the page has just one line.
3360 field_on_page = Sorted_Previous_Field(field_on_page);
3362 while (field_on_page->frow == frow && field_on_page->fcol != fcol);
3364 if (field_on_page->frow != frow)
3366 /* We really found a 'previous' line. We are positioned at the
3367 rightmost field on this line */
3368 frow = field_on_page->frow;
3370 /* We walk to the left as long as we are really right of the
3372 while (field_on_page->frow == frow && field_on_page->fcol > fcol)
3373 field_on_page = Sorted_Previous_Field(field_on_page);
3375 /* If we wrapped, just go to the right which is the first field on
3377 if (field_on_page->frow != frow)
3378 field_on_page = Sorted_Next_Field(field_on_page);
3381 return (field_on_page);
3384 /*---------------------------------------------------------------------------
3385 | Facility : libnform
3386 | Function : static FIELD *Down_Neighbor_Field(FIELD * field)
3388 | Description : Because of the row-major nature of sorting the fields,
3389 | its more difficult to define whats the down neighbor
3390 | field really means. We define that it must be on a
3391 | 'next' line (cyclic order!) and is the leftmost
3392 | field laying on the right side of the given field. If
3393 | this set is empty, we take the last field on the line.
3395 | Return Values : Pointer to the upper neighbor field.
3396 +--------------------------------------------------------------------------*/
3398 Down_Neighbor_Field(FIELD *field)
3400 FIELD *field_on_page = field;
3401 int frow = field->frow;
3402 int fcol = field->fcol;
3404 /* Walk forward to the 'next' line. The second term in the while clause
3405 just guarantees that we stop if we cycled through the line because
3406 there might be no 'next' line if the page has just one line.
3410 field_on_page = Sorted_Next_Field(field_on_page);
3412 while (field_on_page->frow == frow && field_on_page->fcol != fcol);
3414 if (field_on_page->frow != frow)
3416 /* We really found a 'next' line. We are positioned at the rightmost
3417 field on this line */
3418 frow = field_on_page->frow;
3420 /* We walk to the right as long as we are really left of the
3422 while (field_on_page->frow == frow && field_on_page->fcol < fcol)
3423 field_on_page = Sorted_Next_Field(field_on_page);
3425 /* If we wrapped, just go to the left which is the last field on
3427 if (field_on_page->frow != frow)
3428 field_on_page = Sorted_Previous_Field(field_on_page);
3431 return (field_on_page);
3434 /*----------------------------------------------------------------------------
3435 Inter-Field Navigation routines
3436 --------------------------------------------------------------------------*/
3438 /*---------------------------------------------------------------------------
3439 | Facility : libnform
3440 | Function : static int Inter_Field_Navigation(
3441 | int (* const fct) (FORM *),
3444 | Description : Generic behavior for changing the current field, the
3445 | field is left and a new field is entered. So the field
3446 | must be validated and the field init/term hooks must
3449 | Return Values : E_OK - success
3450 | E_INVALID_FIELD - field is invalid
3451 | some other - error from subordinate call
3452 +--------------------------------------------------------------------------*/
3454 Inter_Field_Navigation(int (*const fct) (FORM *), FORM *form)
3458 if (!_nc_Internal_Validation(form))
3459 res = E_INVALID_FIELD;
3462 Call_Hook(form, fieldterm);
3464 Call_Hook(form, fieldinit);
3469 /*---------------------------------------------------------------------------
3470 | Facility : libnform
3471 | Function : static int FN_Next_Field(FORM * form)
3473 | Description : Move to the next field on the current page of the form
3475 | Return Values : E_OK - success
3476 | != E_OK - error from subordinate call
3477 +--------------------------------------------------------------------------*/
3479 FN_Next_Field(FORM *form)
3481 T((T_CALLED("FN_Next_Field(%p)"), form));
3482 returnCode(_nc_Set_Current_Field(form,
3483 Next_Field_On_Page(form->current)));
3486 /*---------------------------------------------------------------------------
3487 | Facility : libnform
3488 | Function : static int FN_Previous_Field(FORM * form)
3490 | Description : Move to the previous field on the current page of the
3493 | Return Values : E_OK - success
3494 | != E_OK - error from subordinate call
3495 +--------------------------------------------------------------------------*/
3497 FN_Previous_Field(FORM *form)
3499 T((T_CALLED("FN_Previous_Field(%p)"), form));
3500 returnCode(_nc_Set_Current_Field(form,
3501 Previous_Field_On_Page(form->current)));
3504 /*---------------------------------------------------------------------------
3505 | Facility : libnform
3506 | Function : static int FN_First_Field(FORM * form)
3508 | Description : Move to the first field on the current page of the form
3510 | Return Values : E_OK - success
3511 | != E_OK - error from subordinate call
3512 +--------------------------------------------------------------------------*/
3514 FN_First_Field(FORM *form)
3516 T((T_CALLED("FN_First_Field(%p)"), form));
3517 returnCode(_nc_Set_Current_Field(form,
3518 Next_Field_On_Page(form->field[form->page[form->curpage].pmax])));
3521 /*---------------------------------------------------------------------------
3522 | Facility : libnform
3523 | Function : static int FN_Last_Field(FORM * form)
3525 | Description : Move to the last field on the current page of the form
3527 | Return Values : E_OK - success
3528 | != E_OK - error from subordinate call
3529 +--------------------------------------------------------------------------*/
3531 FN_Last_Field(FORM *form)
3533 T((T_CALLED("FN_Last_Field(%p)"), form));
3535 _nc_Set_Current_Field(form,
3536 Previous_Field_On_Page(form->field[form->page[form->curpage].pmin])));
3539 /*---------------------------------------------------------------------------
3540 | Facility : libnform
3541 | Function : static int FN_Sorted_Next_Field(FORM * form)
3543 | Description : Move to the sorted next field on the current page
3546 | Return Values : E_OK - success
3547 | != E_OK - error from subordinate call
3548 +--------------------------------------------------------------------------*/
3550 FN_Sorted_Next_Field(FORM *form)
3552 T((T_CALLED("FN_Sorted_Next_Field(%p)"), form));
3553 returnCode(_nc_Set_Current_Field(form,
3554 Sorted_Next_Field(form->current)));
3557 /*---------------------------------------------------------------------------
3558 | Facility : libnform
3559 | Function : static int FN_Sorted_Previous_Field(FORM * form)
3561 | Description : Move to the sorted previous field on the current page
3564 | Return Values : E_OK - success
3565 | != E_OK - error from subordinate call
3566 +--------------------------------------------------------------------------*/
3568 FN_Sorted_Previous_Field(FORM *form)
3570 T((T_CALLED("FN_Sorted_Previous_Field(%p)"), form));
3571 returnCode(_nc_Set_Current_Field(form,
3572 Sorted_Previous_Field(form->current)));
3575 /*---------------------------------------------------------------------------
3576 | Facility : libnform
3577 | Function : static int FN_Sorted_First_Field(FORM * form)
3579 | Description : Move to the sorted first field on the current page
3582 | Return Values : E_OK - success
3583 | != E_OK - error from subordinate call
3584 +--------------------------------------------------------------------------*/
3586 FN_Sorted_First_Field(FORM *form)
3588 T((T_CALLED("FN_Sorted_First_Field(%p)"), form));
3589 returnCode(_nc_Set_Current_Field(form,
3590 Sorted_Next_Field(form->field[form->page[form->curpage].smax])));
3593 /*---------------------------------------------------------------------------
3594 | Facility : libnform
3595 | Function : static int FN_Sorted_Last_Field(FORM * form)
3597 | Description : Move to the sorted last field on the current page
3600 | Return Values : E_OK - success
3601 | != E_OK - error from subordinate call
3602 +--------------------------------------------------------------------------*/
3604 FN_Sorted_Last_Field(FORM *form)
3606 T((T_CALLED("FN_Sorted_Last_Field(%p)"), form));
3607 returnCode(_nc_Set_Current_Field(form,
3608 Sorted_Previous_Field(form->field[form->page[form->curpage].smin])));
3611 /*---------------------------------------------------------------------------
3612 | Facility : libnform
3613 | Function : static int FN_Left_Field(FORM * form)
3615 | Description : Get the field on the left of the current field on the
3616 | same line and the same page. Cycles through the line.
3618 | Return Values : E_OK - success
3619 | != E_OK - error from subordinate call
3620 +--------------------------------------------------------------------------*/
3622 FN_Left_Field(FORM *form)
3624 T((T_CALLED("FN_Left_Field(%p)"), form));
3625 returnCode(_nc_Set_Current_Field(form,
3626 Left_Neighbor_Field(form->current)));
3629 /*---------------------------------------------------------------------------
3630 | Facility : libnform
3631 | Function : static int FN_Right_Field(FORM * form)
3633 | Description : Get the field on the right of the current field on the
3634 | same line and the same page. Cycles through the line.
3636 | Return Values : E_OK - success
3637 | != E_OK - error from subordinate call
3638 +--------------------------------------------------------------------------*/
3640 FN_Right_Field(FORM *form)
3642 T((T_CALLED("FN_Right_Field(%p)"), form));
3643 returnCode(_nc_Set_Current_Field(form,
3644 Right_Neighbor_Field(form->current)));
3647 /*---------------------------------------------------------------------------
3648 | Facility : libnform
3649 | Function : static int FN_Up_Field(FORM * form)
3651 | Description : Get the upper neighbor of the current field. This
3652 | cycles through the page. See the comments of the
3653 | Upper_Neighbor_Field function to understand how
3654 | 'upper' is defined.
3656 | Return Values : E_OK - success
3657 | != E_OK - error from subordinate call
3658 +--------------------------------------------------------------------------*/
3660 FN_Up_Field(FORM *form)
3662 T((T_CALLED("FN_Up_Field(%p)"), form));
3663 returnCode(_nc_Set_Current_Field(form,
3664 Upper_Neighbor_Field(form->current)));
3667 /*---------------------------------------------------------------------------
3668 | Facility : libnform
3669 | Function : static int FN_Down_Field(FORM * form)
3671 | Description : Get the down neighbor of the current field. This
3672 | cycles through the page. See the comments of the
3673 | Down_Neighbor_Field function to understand how
3674 | 'down' is defined.
3676 | Return Values : E_OK - success
3677 | != E_OK - error from subordinate call
3678 +--------------------------------------------------------------------------*/
3680 FN_Down_Field(FORM *form)
3682 T((T_CALLED("FN_Down_Field(%p)"), form));
3683 returnCode(_nc_Set_Current_Field(form,
3684 Down_Neighbor_Field(form->current)));
3686 /*----------------------------------------------------------------------------
3687 END of Field Navigation routines
3688 --------------------------------------------------------------------------*/
3690 /*----------------------------------------------------------------------------
3691 Helper routines for Page Navigation
3692 --------------------------------------------------------------------------*/
3694 /*---------------------------------------------------------------------------
3695 | Facility : libnform
3696 | Function : int _nc_Set_Form_Page(FORM * form,
3700 | Description : Make the given page number the current page and make
3701 | the given field the current field on&n