1 /****************************************************************************
2 * Copyright (c) 1998-2008,2009 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.90 2009/08/29 19:02:25 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 (void) 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 && NCURSES_EXT_FUNCS
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 #ifdef NCURSES_MOUSE_VERSION
741 /*---------------------------------------------------------------------------
742 | Facility : libnform
743 | Function : int Field_encloses(FIELD *field, int ry, int rx)
745 | Description : Check if the given coordinates lie within the given field.
747 | Return Values : E_OK - success
748 | E_BAD_ARGUMENT - invalid form pointer
749 | E_SYSTEM_ERROR - form has no current field or
751 +--------------------------------------------------------------------------*/
753 Field_encloses(FIELD *field, int ry, int rx)
755 T((T_CALLED("Field_encloses(%p)"), field));
758 && (field->frow + field->rows) > ry
760 && (field->fcol + field->cols) > rx)
764 RETURN(E_INVALID_FIELD);
768 /*---------------------------------------------------------------------------
769 | Facility : libnform
770 | Function : int _nc_Position_Form_Cursor(FORM * form)
772 | Description : Position the cursor in the window for the current
773 | field to be in sync. with the currow and curcol
776 | Return Values : E_OK - success
777 | E_BAD_ARGUMENT - invalid form pointer
778 | E_SYSTEM_ERROR - form has no current field or
780 +--------------------------------------------------------------------------*/
782 _nc_Position_Form_Cursor(FORM *form)
788 return (E_BAD_ARGUMENT);
790 if (!form->w || !form->current)
791 return (E_SYSTEM_ERROR);
793 field = form->current;
794 formwin = Get_Form_Window(form);
796 wmove(form->w, form->currow, form->curcol);
797 if (Has_Invisible_Parts(field))
799 /* in this case fieldwin isn't derived from formwin, so we have
800 to move the cursor in formwin by hand... */
802 field->frow + form->currow - form->toprow,
803 field->fcol + form->curcol - form->begincol);
811 /*---------------------------------------------------------------------------
812 | Facility : libnform
813 | Function : int _nc_Refresh_Current_Field(FORM * form)
815 | Description : Propagate the changes in the fields window to the
816 | window of the form.
818 | Return Values : E_OK - on success
819 | E_BAD_ARGUMENT - invalid form pointer
820 | E_SYSTEM_ERROR - general error
821 +--------------------------------------------------------------------------*/
823 _nc_Refresh_Current_Field(FORM *form)
828 T((T_CALLED("_nc_Refresh_Current_Field(%p)"), form));
831 RETURN(E_BAD_ARGUMENT);
833 if (!form->w || !form->current)
834 RETURN(E_SYSTEM_ERROR);
836 field = form->current;
837 formwin = Get_Form_Window(form);
839 if (field->opts & O_PUBLIC)
841 if (Is_Scroll_Field(field))
843 /* Again, in this case the fieldwin isn't derived from formwin,
844 so we have to perform a copy operation. */
845 if (Single_Line_Field(field))
847 /* horizontal scrolling */
848 if (form->curcol < form->begincol)
849 form->begincol = form->curcol;
852 if (form->curcol >= (form->begincol + field->cols))
853 form->begincol = form->curcol - field->cols + 1;
862 field->cols + field->fcol - 1,
867 /* A multi-line, i.e. vertical scrolling field */
868 int row_after_bottom, first_modified_row, first_unmodified_row;
870 if (field->drows > field->rows)
872 row_after_bottom = form->toprow + field->rows;
873 if (form->currow < form->toprow)
875 form->toprow = form->currow;
876 field->status |= _NEWTOP;
878 if (form->currow >= row_after_bottom)
880 form->toprow = form->currow - field->rows + 1;
881 field->status |= _NEWTOP;
883 if (field->status & _NEWTOP)
885 /* means we have to copy whole range */
886 first_modified_row = form->toprow;
887 first_unmodified_row = first_modified_row + field->rows;
888 field->status &= ~_NEWTOP;
892 /* we try to optimize : finding the range of touched
894 first_modified_row = form->toprow;
895 while (first_modified_row < row_after_bottom)
897 if (is_linetouched(form->w, first_modified_row))
899 first_modified_row++;
901 first_unmodified_row = first_modified_row;
902 while (first_unmodified_row < row_after_bottom)
904 if (!is_linetouched(form->w, first_unmodified_row))
906 first_unmodified_row++;
912 first_modified_row = form->toprow;
913 first_unmodified_row = first_modified_row + field->rows;
915 if (first_unmodified_row != first_modified_row)
920 field->frow + first_modified_row - form->toprow,
922 field->frow + first_unmodified_row - form->toprow - 1,
923 field->cols + field->fcol - 1,
930 /* if the field-window is simply a derived window, i.e. contains no
931 * invisible parts, the whole thing is trivial
937 returnCode(_nc_Position_Form_Cursor(form));
940 /*---------------------------------------------------------------------------
941 | Facility : libnform
942 | Function : static void Perform_Justification(
946 | Description : Output field with requested justification
949 +--------------------------------------------------------------------------*/
951 Perform_Justification(FIELD *field, WINDOW *win)
957 bp = Get_Start_Of_Data(field->buf, Buffer_Length(field));
958 len = (int)(After_End_Of_Data(field->buf, Buffer_Length(field)) - bp);
962 assert(win && (field->drows == 1) && (field->dcols == field->cols));
969 col = (field->cols - len) / 2;
972 col = field->cols - len;
979 myADDNSTR(win, bp, len);
983 /*---------------------------------------------------------------------------
984 | Facility : libnform
985 | Function : static void Undo_Justification(
989 | Description : Display field without any justification, i.e.
993 +--------------------------------------------------------------------------*/
995 Undo_Justification(FIELD *field, WINDOW *win)
1000 bp = Get_Start_Of_Data(field->buf, Buffer_Length(field));
1001 len = (int)(After_End_Of_Data(field->buf, Buffer_Length(field)) - bp);
1007 myADDNSTR(win, bp, len);
1011 /*---------------------------------------------------------------------------
1012 | Facility : libnform
1013 | Function : static bool Check_Char(
1016 | TypeArgument *argp)
1018 | Description : Perform a single character check for character ch
1019 | according to the fieldtype instance.
1021 | Return Values : TRUE - Character is valid
1022 | FALSE - Character is invalid
1023 +--------------------------------------------------------------------------*/
1025 Check_Char(FIELDTYPE *typ, int ch, TypeArgument *argp)
1029 if (typ->status & _LINKED_TYPE)
1033 Check_Char(typ->left, ch, argp->left) ||
1034 Check_Char(typ->right, ch, argp->right));
1039 return typ->ccheck(ch, (void *)argp);
1042 return (!iscntrl(UChar(ch)) ? TRUE : FALSE);
1045 /*---------------------------------------------------------------------------
1046 | Facility : libnform
1047 | Function : static int Display_Or_Erase_Field(
1051 | Description : Create a subwindow for the field and display the
1052 | buffer contents (apply justification if required)
1053 | or simply erase the field.
1055 | Return Values : E_OK - on success
1056 | E_SYSTEM_ERROR - some error (typical no memory)
1057 +--------------------------------------------------------------------------*/
1059 Display_Or_Erase_Field(FIELD *field, bool bEraseFlag)
1065 return E_SYSTEM_ERROR;
1067 fwin = Get_Form_Window(field->form);
1069 field->rows, field->cols, field->frow, field->fcol);
1072 return E_SYSTEM_ERROR;
1075 if (field->opts & O_VISIBLE)
1077 Set_Field_Window_Attributes(field, win);
1081 (void)wattrset(win, WINDOW_ATTRS(fwin));
1088 if (field->opts & O_PUBLIC)
1090 if (Justification_Allowed(field))
1091 Perform_Justification(field, win);
1093 Buffer_To_Window(field, win);
1095 field->status &= ~_NEWTOP;
1102 /* Macros to preset the bEraseFlag */
1103 #define Display_Field(field) Display_Or_Erase_Field(field,FALSE)
1104 #define Erase_Field(field) Display_Or_Erase_Field(field,TRUE)
1106 /*---------------------------------------------------------------------------
1107 | Facility : libnform
1108 | Function : static int Synchronize_Field(FIELD * field)
1110 | Description : Synchronize the windows content with the value in
1113 | Return Values : E_OK - success
1114 | E_BAD_ARGUMENT - invalid field pointer
1115 | E_SYSTEM_ERROR - some severe basic error
1116 +--------------------------------------------------------------------------*/
1118 Synchronize_Field(FIELD *field)
1124 return (E_BAD_ARGUMENT);
1126 if (((form = field->form) != (FORM *)0)
1127 && Field_Really_Appears(field))
1129 if (field == form->current)
1131 form->currow = form->curcol = form->toprow = form->begincol = 0;
1134 if ((field->opts & O_PUBLIC) && Justification_Allowed(field))
1135 Undo_Justification(field, form->w);
1137 Buffer_To_Window(field, form->w);
1139 field->status |= _NEWTOP;
1140 res = _nc_Refresh_Current_Field(form);
1143 res = Display_Field(field);
1145 field->status |= _CHANGED;
1149 /*---------------------------------------------------------------------------
1150 | Facility : libnform
1151 | Function : static int Synchronize_Linked_Fields(FIELD * field)
1153 | Description : Propagate the Synchronize_Field function to all linked
1154 | fields. The first error that occurs in the sequence
1155 | of updates is the return value.
1157 | Return Values : E_OK - success
1158 | E_BAD_ARGUMENT - invalid field pointer
1159 | E_SYSTEM_ERROR - some severe basic error
1160 +--------------------------------------------------------------------------*/
1162 Synchronize_Linked_Fields(FIELD *field)
1164 FIELD *linked_field;
1169 return (E_BAD_ARGUMENT);
1172 return (E_SYSTEM_ERROR);
1174 for (linked_field = field->link;
1175 linked_field != field;
1176 linked_field = linked_field->link)
1178 if (((syncres = Synchronize_Field(linked_field)) != E_OK) &&
1185 /*---------------------------------------------------------------------------
1186 | Facility : libnform
1187 | Function : int _nc_Synchronize_Attributes(FIELD * field)
1189 | Description : If a fields visual attributes have changed, this
1190 | routine is called to propagate those changes to the
1193 | Return Values : E_OK - success
1194 | E_BAD_ARGUMENT - invalid field pointer
1195 | E_SYSTEM_ERROR - some severe basic error
1196 +--------------------------------------------------------------------------*/
1198 _nc_Synchronize_Attributes(FIELD *field)
1204 T((T_CALLED("_nc_Synchronize_Attributes(%p)"), field));
1207 returnCode(E_BAD_ARGUMENT);
1209 CHECKPOS(field->form);
1210 if (((form = field->form) != (FORM *)0)
1211 && Field_Really_Appears(field))
1213 if (form->current == field)
1215 Synchronize_Buffer(form);
1216 Set_Field_Window_Attributes(field, form->w);
1218 wmove(form->w, form->currow, form->curcol);
1220 if (field->opts & O_PUBLIC)
1222 if (Justification_Allowed(field))
1223 Undo_Justification(field, form->w);
1225 Buffer_To_Window(field, form->w);
1229 formwin = Get_Form_Window(form);
1230 copywin(form->w, formwin,
1232 field->frow, field->fcol,
1233 field->rows - 1, field->cols - 1, 0);
1235 Buffer_To_Window(field, form->w);
1236 field->status |= _NEWTOP; /* fake refresh to paint all */
1237 _nc_Refresh_Current_Field(form);
1242 res = Display_Field(field);
1249 /*---------------------------------------------------------------------------
1250 | Facility : libnform
1251 | Function : int _nc_Synchronize_Options(FIELD * field,
1252 | Field_Options newopts)
1254 | Description : If a fields options have changed, this routine is
1255 | called to propagate these changes to the screen and
1256 | to really change the behavior of the field.
1258 | Return Values : E_OK - success
1259 | E_BAD_ARGUMENT - invalid field pointer
1260 | E_CURRENT - field is the current one
1261 | E_SYSTEM_ERROR - some severe basic error
1262 +--------------------------------------------------------------------------*/
1264 _nc_Synchronize_Options(FIELD *field, Field_Options newopts)
1266 Field_Options oldopts;
1267 Field_Options changed_opts;
1271 T((T_CALLED("_nc_Synchronize_Options(%p,%#x)"), field, newopts));
1274 returnCode(E_BAD_ARGUMENT);
1276 oldopts = field->opts;
1277 changed_opts = oldopts ^ newopts;
1278 field->opts = newopts;
1283 if (form->current == field)
1285 field->opts = oldopts;
1286 returnCode(E_CURRENT);
1289 if (form->status & _POSTED)
1291 if ((form->curpage == field->page))
1293 if (changed_opts & O_VISIBLE)
1295 if (newopts & O_VISIBLE)
1296 res = Display_Field(field);
1298 res = Erase_Field(field);
1302 if ((changed_opts & O_PUBLIC) &&
1303 (newopts & O_VISIBLE))
1304 res = Display_Field(field);
1310 if (changed_opts & O_STATIC)
1312 bool single_line_field = Single_Line_Field(field);
1315 if (newopts & O_STATIC)
1317 /* the field becomes now static */
1318 field->status &= ~_MAY_GROW;
1319 /* if actually we have no hidden columns, justification may
1321 if (single_line_field &&
1322 (field->cols == field->dcols) &&
1323 (field->just != NO_JUSTIFICATION) &&
1324 Field_Really_Appears(field))
1326 res2 = Display_Field(field);
1331 /* field is no longer static */
1332 if ((field->maxgrow == 0) ||
1333 (single_line_field && (field->dcols < field->maxgrow)) ||
1334 (!single_line_field && (field->drows < field->maxgrow)))
1336 field->status |= _MAY_GROW;
1337 /* a field with justification now changes its behavior,
1338 so we must redisplay it */
1339 if (single_line_field &&
1340 (field->just != NO_JUSTIFICATION) &&
1341 Field_Really_Appears(field))
1343 res2 = Display_Field(field);
1354 /*---------------------------------------------------------------------------
1355 | Facility : libnform
1356 | Function : int _nc_Set_Current_Field(FORM * form,
1359 | Description : Make the newfield the new current field.
1361 | Return Values : E_OK - success
1362 | E_BAD_ARGUMENT - invalid form or field pointer
1363 | E_SYSTEM_ERROR - some severe basic error
1364 | E_NOT_CONNECTED - no fields are connected to the form
1365 +--------------------------------------------------------------------------*/
1367 _nc_Set_Current_Field(FORM *form, FIELD *newfield)
1372 T((T_CALLED("_nc_Set_Current_Field(%p,%p)"), form, newfield));
1374 if (!form || !newfield || !form->current || (newfield->form != form))
1375 returnCode(E_BAD_ARGUMENT);
1377 if ((form->status & _IN_DRIVER))
1378 returnCode(E_BAD_STATE);
1381 returnCode(E_NOT_CONNECTED);
1383 field = form->current;
1385 if ((field != newfield) ||
1386 !(form->status & _POSTED))
1389 (field->opts & O_VISIBLE) &&
1390 (field->form->curpage == field->page))
1392 _nc_Refresh_Current_Field(form);
1393 if (field->opts & O_PUBLIC)
1395 if (field->drows > field->rows)
1397 if (form->toprow == 0)
1398 field->status &= ~_NEWTOP;
1400 field->status |= _NEWTOP;
1404 if (Justification_Allowed(field))
1406 Window_To_Buffer(form->w, field);
1408 Perform_Justification(field, form->w);
1414 form->w = (WINDOW *)0;
1419 if (Has_Invisible_Parts(field))
1420 new_window = newpad(field->drows, field->dcols);
1422 new_window = derwin(Get_Form_Window(form),
1423 field->rows, field->cols, field->frow, field->fcol);
1426 returnCode(E_SYSTEM_ERROR);
1428 form->current = field;
1432 form->w = new_window;
1434 form->status &= ~_WINDOW_MODIFIED;
1435 Set_Field_Window_Attributes(field, form->w);
1437 if (Has_Invisible_Parts(field))
1440 Buffer_To_Window(field, form->w);
1444 if (Justification_Allowed(field))
1447 Undo_Justification(field, form->w);
1452 untouchwin(form->w);
1455 form->currow = form->curcol = form->toprow = form->begincol = 0;
1459 /*----------------------------------------------------------------------------
1460 Intra-Field Navigation routines
1461 --------------------------------------------------------------------------*/
1463 /*---------------------------------------------------------------------------
1464 | Facility : libnform
1465 | Function : static int IFN_Next_Character(FORM * form)
1467 | Description : Move to the next character in the field. In a multi-line
1468 | field this wraps at the end of the line.
1470 | Return Values : E_OK - success
1471 | E_REQUEST_DENIED - at the rightmost position
1472 +--------------------------------------------------------------------------*/
1474 IFN_Next_Character(FORM *form)
1476 FIELD *field = form->current;
1477 int step = myWCWIDTH(form->w, form->currow, form->curcol);
1479 T((T_CALLED("IFN_Next_Character(%p)"), form));
1480 if ((form->curcol += step) == field->dcols)
1482 if ((++(form->currow)) == field->drows)
1484 #if GROW_IF_NAVIGATE
1485 if (!Single_Line_Field(field) && Field_Grown(field, 1))
1492 #if GROW_IF_NAVIGATE
1493 if (Single_Line_Field(field) && Field_Grown(field, 1))
1496 form->curcol -= step;
1497 returnCode(E_REQUEST_DENIED);
1504 /*---------------------------------------------------------------------------
1505 | Facility : libnform
1506 | Function : static int IFN_Previous_Character(FORM * form)
1508 | Description : Move to the previous character in the field. In a
1509 | multi-line field this wraps and the beginning of the
1512 | Return Values : E_OK - success
1513 | E_REQUEST_DENIED - at the leftmost position
1514 +--------------------------------------------------------------------------*/
1516 IFN_Previous_Character(FORM *form)
1518 int amount = myWCWIDTH(form->w, form->currow, form->curcol - 1);
1519 int oldcol = form->curcol;
1521 T((T_CALLED("IFN_Previous_Character(%p)"), form));
1522 if ((form->curcol -= amount) < 0)
1524 if ((--(form->currow)) < 0)
1527 form->curcol = oldcol;
1528 returnCode(E_REQUEST_DENIED);
1530 form->curcol = form->current->dcols - 1;
1535 /*---------------------------------------------------------------------------
1536 | Facility : libnform
1537 | Function : static int IFN_Next_Line(FORM * form)
1539 | Description : Move to the beginning of the next line in the field
1541 | Return Values : E_OK - success
1542 | E_REQUEST_DENIED - at the last line
1543 +--------------------------------------------------------------------------*/
1545 IFN_Next_Line(FORM *form)
1547 FIELD *field = form->current;
1549 T((T_CALLED("IFN_Next_Line(%p)"), form));
1550 if ((++(form->currow)) == field->drows)
1552 #if GROW_IF_NAVIGATE
1553 if (!Single_Line_Field(field) && Field_Grown(field, 1))
1557 returnCode(E_REQUEST_DENIED);
1563 /*---------------------------------------------------------------------------
1564 | Facility : libnform
1565 | Function : static int IFN_Previous_Line(FORM * form)
1567 | Description : Move to the beginning of the previous line in the field
1569 | Return Values : E_OK - success
1570 | E_REQUEST_DENIED - at the first line
1571 +--------------------------------------------------------------------------*/
1573 IFN_Previous_Line(FORM *form)
1575 T((T_CALLED("IFN_Previous_Line(%p)"), form));
1576 if ((--(form->currow)) < 0)
1579 returnCode(E_REQUEST_DENIED);
1585 /*---------------------------------------------------------------------------
1586 | Facility : libnform
1587 | Function : static int IFN_Next_Word(FORM * form)
1589 | Description : Move to the beginning of the next word in the field.
1591 | Return Values : E_OK - success
1592 | E_REQUEST_DENIED - there is no next word
1593 +--------------------------------------------------------------------------*/
1595 IFN_Next_Word(FORM *form)
1597 FIELD *field = form->current;
1598 FIELD_CELL *bp = Address_Of_Current_Position_In_Buffer(form);
1602 T((T_CALLED("IFN_Next_Word(%p)"), form));
1604 /* We really need access to the data, so we have to synchronize */
1605 Synchronize_Buffer(form);
1607 /* Go to the first whitespace after the current position (including
1608 current position). This is then the starting point to look for the
1609 next non-blank data */
1610 s = Get_First_Whitespace_Character(bp, Buffer_Length(field) -
1611 (int)(bp - field->buf));
1613 /* Find the start of the next word */
1614 t = Get_Start_Of_Data(s, Buffer_Length(field) -
1615 (int)(s - field->buf));
1616 #if !FRIENDLY_PREV_NEXT_WORD
1618 returnCode(E_REQUEST_DENIED);
1622 Adjust_Cursor_Position(form, t);
1627 /*---------------------------------------------------------------------------
1628 | Facility : libnform
1629 | Function : static int IFN_Previous_Word(FORM * form)
1631 | Description : Move to the beginning of the previous word in the field.
1633 | Return Values : E_OK - success
1634 | E_REQUEST_DENIED - there is no previous word
1635 +--------------------------------------------------------------------------*/
1637 IFN_Previous_Word(FORM *form)
1639 FIELD *field = form->current;
1640 FIELD_CELL *bp = Address_Of_Current_Position_In_Buffer(form);
1645 T((T_CALLED("IFN_Previous_Word(%p)"), form));
1647 /* We really need access to the data, so we have to synchronize */
1648 Synchronize_Buffer(form);
1650 s = After_End_Of_Data(field->buf, (int)(bp - field->buf));
1651 /* s points now right after the last non-blank in the buffer before bp.
1652 If bp was in a word, s equals bp. In this case we must find the last
1653 whitespace in the buffer before bp and repeat the game to really find
1654 the previous word! */
1658 /* And next call now goes backward to look for the last whitespace
1659 before that, pointing right after this, so it points to the begin
1660 of the previous word.
1662 t = After_Last_Whitespace_Character(field->buf, (int)(s - field->buf));
1663 #if !FRIENDLY_PREV_NEXT_WORD
1665 returnCode(E_REQUEST_DENIED);
1669 /* and do it again, replacing bp by t */
1670 s = After_End_Of_Data(field->buf, (int)(t - field->buf));
1671 t = After_Last_Whitespace_Character(field->buf, (int)(s - field->buf));
1672 #if !FRIENDLY_PREV_NEXT_WORD
1674 returnCode(E_REQUEST_DENIED);
1677 Adjust_Cursor_Position(form, t);
1681 /*---------------------------------------------------------------------------
1682 | Facility : libnform
1683 | Function : static int IFN_Beginning_Of_Field(FORM * form)
1685 | Description : Place the cursor at the first non-pad character in
1688 | Return Values : E_OK - success
1689 +--------------------------------------------------------------------------*/
1691 IFN_Beginning_Of_Field(FORM *form)
1693 FIELD *field = form->current;
1695 T((T_CALLED("IFN_Beginning_Of_Field(%p)"), form));
1696 Synchronize_Buffer(form);
1697 Adjust_Cursor_Position(form,
1698 Get_Start_Of_Data(field->buf, Buffer_Length(field)));
1702 /*---------------------------------------------------------------------------
1703 | Facility : libnform
1704 | Function : static int IFN_End_Of_Field(FORM * form)
1706 | Description : Place the cursor after the last non-pad character in
1707 | the field. If the field occupies the last position in
1708 | the buffer, the cursor is positioned on the last
1711 | Return Values : E_OK - success
1712 +--------------------------------------------------------------------------*/
1714 IFN_End_Of_Field(FORM *form)
1716 FIELD *field = form->current;
1719 T((T_CALLED("IFN_End_Of_Field(%p)"), form));
1720 Synchronize_Buffer(form);
1721 pos = After_End_Of_Data(field->buf, Buffer_Length(field));
1722 if (pos == (field->buf + Buffer_Length(field)))
1724 Adjust_Cursor_Position(form, pos);
1728 /*---------------------------------------------------------------------------
1729 | Facility : libnform
1730 | Function : static int IFN_Beginning_Of_Line(FORM * form)
1732 | Description : Place the cursor on the first non-pad character in
1733 | the current line of the field.
1735 | Return Values : E_OK - success
1736 +--------------------------------------------------------------------------*/
1738 IFN_Beginning_Of_Line(FORM *form)
1740 FIELD *field = form->current;
1742 T((T_CALLED("IFN_Beginning_Of_Line(%p)"), form));
1743 Synchronize_Buffer(form);
1744 Adjust_Cursor_Position(form,
1745 Get_Start_Of_Data(Address_Of_Current_Row_In_Buffer(form),
1750 /*---------------------------------------------------------------------------
1751 | Facility : libnform
1752 | Function : static int IFN_End_Of_Line(FORM * form)
1754 | Description : Place the cursor after the last non-pad character in the
1755 | current line of the field. If the field occupies the
1756 | last column in the line, the cursor is positioned on the
1757 | last character of the line.
1759 | Return Values : E_OK - success
1760 +--------------------------------------------------------------------------*/
1762 IFN_End_Of_Line(FORM *form)
1764 FIELD *field = form->current;
1768 T((T_CALLED("IFN_End_Of_Line(%p)"), form));
1769 Synchronize_Buffer(form);
1770 bp = Address_Of_Current_Row_In_Buffer(form);
1771 pos = After_End_Of_Data(bp, field->dcols);
1772 if (pos == (bp + field->dcols))
1774 Adjust_Cursor_Position(form, pos);
1778 /*---------------------------------------------------------------------------
1779 | Facility : libnform
1780 | Function : static int IFN_Left_Character(FORM * form)
1782 | Description : Move one character to the left in the current line.
1783 | This doesn't cycle.
1785 | Return Values : E_OK - success
1786 | E_REQUEST_DENIED - already in first column
1787 +--------------------------------------------------------------------------*/
1789 IFN_Left_Character(FORM *form)
1791 int amount = myWCWIDTH(form->w, form->currow, form->curcol - 1);
1792 int oldcol = form->curcol;
1794 T((T_CALLED("IFN_Left_Character(%p)"), form));
1795 if ((form->curcol -= amount) < 0)
1797 form->curcol = oldcol;
1798 returnCode(E_REQUEST_DENIED);
1803 /*---------------------------------------------------------------------------
1804 | Facility : libnform
1805 | Function : static int IFN_Right_Character(FORM * form)
1807 | Description : Move one character to the right in the current line.
1808 | This doesn't cycle.
1810 | Return Values : E_OK - success
1811 | E_REQUEST_DENIED - already in last column
1812 +--------------------------------------------------------------------------*/
1814 IFN_Right_Character(FORM *form)
1816 int amount = myWCWIDTH(form->w, form->currow, form->curcol);
1817 int oldcol = form->curcol;
1819 T((T_CALLED("IFN_Right_Character(%p)"), form));
1820 if ((form->curcol += amount) >= form->current->dcols)
1822 #if GROW_IF_NAVIGATE
1823 FIELD *field = form->current;
1825 if (Single_Line_Field(field) && Field_Grown(field, 1))
1828 form->curcol = oldcol;
1829 returnCode(E_REQUEST_DENIED);
1834 /*---------------------------------------------------------------------------
1835 | Facility : libnform
1836 | Function : static int IFN_Up_Character(FORM * form)
1838 | Description : Move one line up. This doesn't cycle through the lines
1841 | Return Values : E_OK - success
1842 | E_REQUEST_DENIED - already in last column
1843 +--------------------------------------------------------------------------*/
1845 IFN_Up_Character(FORM *form)
1847 T((T_CALLED("IFN_Up_Character(%p)"), form));
1848 if ((--(form->currow)) < 0)
1851 returnCode(E_REQUEST_DENIED);
1856 /*---------------------------------------------------------------------------
1857 | Facility : libnform
1858 | Function : static int IFN_Down_Character(FORM * form)
1860 | Description : Move one line down. This doesn't cycle through the
1861 | lines of the field.
1863 | Return Values : E_OK - success
1864 | E_REQUEST_DENIED - already in last column
1865 +--------------------------------------------------------------------------*/
1867 IFN_Down_Character(FORM *form)
1869 FIELD *field = form->current;
1871 T((T_CALLED("IFN_Down_Character(%p)"), form));
1872 if ((++(form->currow)) == field->drows)
1874 #if GROW_IF_NAVIGATE
1875 if (!Single_Line_Field(field) && Field_Grown(field, 1))
1879 returnCode(E_REQUEST_DENIED);
1883 /*----------------------------------------------------------------------------
1884 END of Intra-Field Navigation routines
1885 --------------------------------------------------------------------------*/
1887 /*----------------------------------------------------------------------------
1888 Vertical scrolling helper routines
1889 --------------------------------------------------------------------------*/
1891 /*---------------------------------------------------------------------------
1892 | Facility : libnform
1893 | Function : static int VSC_Generic(FORM *form, int nlines)
1895 | Description : Scroll multi-line field forward (nlines>0) or
1896 | backward (nlines<0) this many lines.
1898 | Return Values : E_OK - success
1899 | E_REQUEST_DENIED - can't scroll
1900 +--------------------------------------------------------------------------*/
1902 VSC_Generic(FORM *form, int nlines)
1904 FIELD *field = form->current;
1905 int res = E_REQUEST_DENIED;
1906 int rows_to_go = (nlines > 0 ? nlines : -nlines);
1910 if ((rows_to_go + form->toprow) > (field->drows - field->rows))
1911 rows_to_go = (field->drows - field->rows - form->toprow);
1915 form->currow += rows_to_go;
1916 form->toprow += rows_to_go;
1922 if (rows_to_go > form->toprow)
1923 rows_to_go = form->toprow;
1927 form->currow -= rows_to_go;
1928 form->toprow -= rows_to_go;
1934 /*----------------------------------------------------------------------------
1935 End of Vertical scrolling helper routines
1936 --------------------------------------------------------------------------*/
1938 /*----------------------------------------------------------------------------
1939 Vertical scrolling routines
1940 --------------------------------------------------------------------------*/
1942 /*---------------------------------------------------------------------------
1943 | Facility : libnform
1944 | Function : static int Vertical_Scrolling(
1945 | int (* const fct) (FORM *),
1948 | Description : Performs the generic vertical scrolling routines.
1949 | This has to check for a multi-line field and to set
1950 | the _NEWTOP flag if scrolling really occurred.
1952 | Return Values : Propagated error code from low-level driver calls
1953 +--------------------------------------------------------------------------*/
1955 Vertical_Scrolling(int (*const fct) (FORM *), FORM *form)
1957 int res = E_REQUEST_DENIED;
1959 if (!Single_Line_Field(form->current))
1963 form->current->status |= _NEWTOP;
1968 /*---------------------------------------------------------------------------
1969 | Facility : libnform
1970 | Function : static int VSC_Scroll_Line_Forward(FORM * form)
1972 | Description : Scroll multi-line field forward a line
1974 | Return Values : E_OK - success
1975 | E_REQUEST_DENIED - no data ahead
1976 +--------------------------------------------------------------------------*/
1978 VSC_Scroll_Line_Forward(FORM *form)
1980 T((T_CALLED("VSC_Scroll_Line_Forward(%p)"), form));
1981 returnCode(VSC_Generic(form, 1));
1984 /*---------------------------------------------------------------------------
1985 | Facility : libnform
1986 | Function : static int VSC_Scroll_Line_Backward(FORM * form)
1988 | Description : Scroll multi-line field backward a line
1990 | Return Values : E_OK - success
1991 | E_REQUEST_DENIED - no data behind
1992 +--------------------------------------------------------------------------*/
1994 VSC_Scroll_Line_Backward(FORM *form)
1996 T((T_CALLED("VSC_Scroll_Line_Backward(%p)"), form));
1997 returnCode(VSC_Generic(form, -1));
2000 /*---------------------------------------------------------------------------
2001 | Facility : libnform
2002 | Function : static int VSC_Scroll_Page_Forward(FORM * form)
2004 | Description : Scroll a multi-line field forward a page
2006 | Return Values : E_OK - success
2007 | E_REQUEST_DENIED - no data ahead
2008 +--------------------------------------------------------------------------*/
2010 VSC_Scroll_Page_Forward(FORM *form)
2012 T((T_CALLED("VSC_Scroll_Page_Forward(%p)"), form));
2013 returnCode(VSC_Generic(form, form->current->rows));
2016 /*---------------------------------------------------------------------------
2017 | Facility : libnform
2018 | Function : static int VSC_Scroll_Half_Page_Forward(FORM * form)
2020 | Description : Scroll a multi-line field forward half a page
2022 | Return Values : E_OK - success
2023 | E_REQUEST_DENIED - no data ahead
2024 +--------------------------------------------------------------------------*/
2026 VSC_Scroll_Half_Page_Forward(FORM *form)
2028 T((T_CALLED("VSC_Scroll_Half_Page_Forward(%p)"), form));
2029 returnCode(VSC_Generic(form, (form->current->rows + 1) / 2));
2032 /*---------------------------------------------------------------------------
2033 | Facility : libnform
2034 | Function : static int VSC_Scroll_Page_Backward(FORM * form)
2036 | Description : Scroll a multi-line field backward a page
2038 | Return Values : E_OK - success
2039 | E_REQUEST_DENIED - no data behind
2040 +--------------------------------------------------------------------------*/
2042 VSC_Scroll_Page_Backward(FORM *form)
2044 T((T_CALLED("VSC_Scroll_Page_Backward(%p)"), form));
2045 returnCode(VSC_Generic(form, -(form->current->rows)));
2048 /*---------------------------------------------------------------------------
2049 | Facility : libnform
2050 | Function : static int VSC_Scroll_Half_Page_Backward(FORM * form)
2052 | Description : Scroll a multi-line field backward half a page
2054 | Return Values : E_OK - success
2055 | E_REQUEST_DENIED - no data behind
2056 +--------------------------------------------------------------------------*/
2058 VSC_Scroll_Half_Page_Backward(FORM *form)
2060 T((T_CALLED("VSC_Scroll_Half_Page_Backward(%p)"), form));
2061 returnCode(VSC_Generic(form, -((form->current->rows + 1) / 2)));
2063 /*----------------------------------------------------------------------------
2064 End of Vertical scrolling routines
2065 --------------------------------------------------------------------------*/
2067 /*----------------------------------------------------------------------------
2068 Horizontal scrolling helper routines
2069 --------------------------------------------------------------------------*/
2071 /*---------------------------------------------------------------------------
2072 | Facility : libnform
2073 | Function : static int HSC_Generic(FORM *form, int ncolumns)
2075 | Description : Scroll single-line field forward (ncolumns>0) or
2076 | backward (ncolumns<0) this many columns.
2078 | Return Values : E_OK - success
2079 | E_REQUEST_DENIED - can't scroll
2080 +--------------------------------------------------------------------------*/
2082 HSC_Generic(FORM *form, int ncolumns)
2084 FIELD *field = form->current;
2085 int res = E_REQUEST_DENIED;
2086 int cols_to_go = (ncolumns > 0 ? ncolumns : -ncolumns);
2090 if ((cols_to_go + form->begincol) > (field->dcols - field->cols))
2091 cols_to_go = field->dcols - field->cols - form->begincol;
2095 form->curcol += cols_to_go;
2096 form->begincol += cols_to_go;
2102 if (cols_to_go > form->begincol)
2103 cols_to_go = form->begincol;
2107 form->curcol -= cols_to_go;
2108 form->begincol -= cols_to_go;
2114 /*----------------------------------------------------------------------------
2115 End of Horizontal scrolling helper routines
2116 --------------------------------------------------------------------------*/
2118 /*----------------------------------------------------------------------------
2119 Horizontal scrolling routines
2120 --------------------------------------------------------------------------*/
2122 /*---------------------------------------------------------------------------
2123 | Facility : libnform
2124 | Function : static int Horizontal_Scrolling(
2125 | int (* const fct) (FORM *),
2128 | Description : Performs the generic horizontal scrolling routines.
2129 | This has to check for a single-line field.
2131 | Return Values : Propagated error code from low-level driver calls
2132 +--------------------------------------------------------------------------*/
2134 Horizontal_Scrolling(int (*const fct) (FORM *), FORM *form)
2136 if (Single_Line_Field(form->current))
2139 return (E_REQUEST_DENIED);
2142 /*---------------------------------------------------------------------------
2143 | Facility : libnform
2144 | Function : static int HSC_Scroll_Char_Forward(FORM * form)
2146 | Description : Scroll single-line field forward a character
2148 | Return Values : E_OK - success
2149 | E_REQUEST_DENIED - no data ahead
2150 +--------------------------------------------------------------------------*/
2152 HSC_Scroll_Char_Forward(FORM *form)
2154 T((T_CALLED("HSC_Scroll_Char_Forward(%p)"), form));
2155 returnCode(HSC_Generic(form, 1));
2158 /*---------------------------------------------------------------------------
2159 | Facility : libnform
2160 | Function : static int HSC_Scroll_Char_Backward(FORM * form)
2162 | Description : Scroll single-line field backward a character
2164 | Return Values : E_OK - success
2165 | E_REQUEST_DENIED - no data behind
2166 +--------------------------------------------------------------------------*/
2168 HSC_Scroll_Char_Backward(FORM *form)
2170 T((T_CALLED("HSC_Scroll_Char_Backward(%p)"), form));
2171 returnCode(HSC_Generic(form, -1));
2174 /*---------------------------------------------------------------------------
2175 | Facility : libnform
2176 | Function : static int HSC_Horizontal_Line_Forward(FORM* form)
2178 | Description : Scroll single-line field forward a line
2180 | Return Values : E_OK - success
2181 | E_REQUEST_DENIED - no data ahead
2182 +--------------------------------------------------------------------------*/
2184 HSC_Horizontal_Line_Forward(FORM *form)
2186 T((T_CALLED("HSC_Horizontal_Line_Forward(%p)"), form));
2187 returnCode(HSC_Generic(form, form->current->cols));
2190 /*---------------------------------------------------------------------------
2191 | Facility : libnform
2192 | Function : static int HSC_Horizontal_Half_Line_Forward(FORM* form)
2194 | Description : Scroll single-line field forward half a line
2196 | Return Values : E_OK - success
2197 | E_REQUEST_DENIED - no data ahead
2198 +--------------------------------------------------------------------------*/
2200 HSC_Horizontal_Half_Line_Forward(FORM *form)
2202 T((T_CALLED("HSC_Horizontal_Half_Line_Forward(%p)"), form));
2203 returnCode(HSC_Generic(form, (form->current->cols + 1) / 2));
2206 /*---------------------------------------------------------------------------
2207 | Facility : libnform
2208 | Function : static int HSC_Horizontal_Line_Backward(FORM* form)
2210 | Description : Scroll single-line field backward a line
2212 | Return Values : E_OK - success
2213 | E_REQUEST_DENIED - no data behind
2214 +--------------------------------------------------------------------------*/
2216 HSC_Horizontal_Line_Backward(FORM *form)
2218 T((T_CALLED("HSC_Horizontal_Line_Backward(%p)"), form));
2219 returnCode(HSC_Generic(form, -(form->current->cols)));
2222 /*---------------------------------------------------------------------------
2223 | Facility : libnform
2224 | Function : static int HSC_Horizontal_Half_Line_Backward(FORM* form)
2226 | Description : Scroll single-line field backward half a line
2228 | Return Values : E_OK - success
2229 | E_REQUEST_DENIED - no data behind
2230 +--------------------------------------------------------------------------*/
2232 HSC_Horizontal_Half_Line_Backward(FORM *form)
2234 T((T_CALLED("HSC_Horizontal_Half_Line_Backward(%p)"), form));
2235 returnCode(HSC_Generic(form, -((form->current->cols + 1) / 2)));
2238 /*----------------------------------------------------------------------------
2239 End of Horizontal scrolling routines
2240 --------------------------------------------------------------------------*/
2242 /*----------------------------------------------------------------------------
2243 Helper routines for Field Editing
2244 --------------------------------------------------------------------------*/
2246 /*---------------------------------------------------------------------------
2247 | Facility : libnform
2248 | Function : static bool Is_There_Room_For_A_Line(FORM * form)
2250 | Description : Check whether or not there is enough room in the
2251 | buffer to enter a whole line.
2253 | Return Values : TRUE - there is enough space
2254 | FALSE - there is not enough space
2255 +--------------------------------------------------------------------------*/
2256 NCURSES_INLINE static bool
2257 Is_There_Room_For_A_Line(FORM *form)
2259 FIELD *field = form->current;
2260 FIELD_CELL *begin_of_last_line, *s;
2262 Synchronize_Buffer(form);
2263 begin_of_last_line = Address_Of_Row_In_Buffer(field, (field->drows - 1));
2264 s = After_End_Of_Data(begin_of_last_line, field->dcols);
2265 return ((s == begin_of_last_line) ? TRUE : FALSE);
2268 /*---------------------------------------------------------------------------
2269 | Facility : libnform
2270 | Function : static bool Is_There_Room_For_A_Char_In_Line(FORM * form)
2272 | Description : Checks whether or not there is room for a new character
2273 | in the current line.
2275 | Return Values : TRUE - there is room
2276 | FALSE - there is not enough room (line full)
2277 +--------------------------------------------------------------------------*/
2278 NCURSES_INLINE static bool
2279 Is_There_Room_For_A_Char_In_Line(FORM *form)
2281 int last_char_in_line;
2283 wmove(form->w, form->currow, form->current->dcols - 1);
2284 last_char_in_line = (int)(winch(form->w) & A_CHARTEXT);
2285 wmove(form->w, form->currow, form->curcol);
2286 return (((last_char_in_line == form->current->pad) ||
2287 is_blank(last_char_in_line)) ? TRUE : FALSE);
2290 #define There_Is_No_Room_For_A_Char_In_Line(f) \
2291 !Is_There_Room_For_A_Char_In_Line(f)
2293 /*---------------------------------------------------------------------------
2294 | Facility : libnform
2295 | Function : static int Insert_String(
2301 | Description : Insert the 'len' characters beginning at pointer 'txt'
2302 | into the 'row' of the 'form'. The insertion occurs
2303 | on the beginning of the row, all other characters are
2304 | moved to the right. After the text a pad character will
2305 | be inserted to separate the text from the rest. If
2306 | necessary the insertion moves characters on the next
2307 | line to make place for the requested insertion string.
2309 | Return Values : E_OK - success
2310 | E_REQUEST_DENIED -
2311 | E_SYSTEM_ERROR - system error
2312 +--------------------------------------------------------------------------*/
2314 Insert_String(FORM *form, int row, FIELD_CELL *txt, int len)
2316 FIELD *field = form->current;
2317 FIELD_CELL *bp = Address_Of_Row_In_Buffer(field, row);
2318 int datalen = (int)(After_End_Of_Data(bp, field->dcols) - bp);
2319 int freelen = field->dcols - datalen;
2320 int requiredlen = len + 1;
2322 int result = E_REQUEST_DENIED;
2324 if (freelen >= requiredlen)
2326 wmove(form->w, row, 0);
2327 myINSNSTR(form->w, txt, len);
2328 wmove(form->w, row, len);
2329 myINSNSTR(form->w, &myBLANK, 1);
2334 /* we have to move characters on the next line. If we are on the
2335 last line this may work, if the field is growable */
2336 if ((row == (field->drows - 1)) && Growable(field))
2338 if (!Field_Grown(field, 1))
2339 return (E_SYSTEM_ERROR);
2340 /* !!!Side-Effect : might be changed due to growth!!! */
2341 bp = Address_Of_Row_In_Buffer(field, row);
2344 if (row < (field->drows - 1))
2347 After_Last_Whitespace_Character(bp,
2348 (int)(Get_Start_Of_Data(bp
2353 /* split points now to the first character of the portion of the
2354 line that must be moved to the next line */
2355 datalen = (int)(split - bp); /* + freelen has to stay on this line */
2356 freelen = field->dcols - (datalen + freelen); /* for the next line */
2358 if ((result = Insert_String(form, row + 1, split, freelen)) == E_OK)
2360 wmove(form->w, row, datalen);
2362 wmove(form->w, row, 0);
2363 myINSNSTR(form->w, txt, len);
2364 wmove(form->w, row, len);
2365 myINSNSTR(form->w, &myBLANK, 1);
2373 /*---------------------------------------------------------------------------
2374 | Facility : libnform
2375 | Function : static int Wrapping_Not_Necessary_Or_Wrapping_Ok(
2378 | Description : If a character has been entered into a field, it may
2379 | be that wrapping has to occur. This routine checks
2380 | whether or not wrapping is required and if so, performs
2383 | Return Values : E_OK - no wrapping required or wrapping
2385 | E_REQUEST_DENIED -
2386 | E_SYSTEM_ERROR - some system error
2387 +--------------------------------------------------------------------------*/
2389 Wrapping_Not_Necessary_Or_Wrapping_Ok(FORM *form)
2391 FIELD *field = form->current;
2392 int result = E_REQUEST_DENIED;
2393 bool Last_Row = ((field->drows - 1) == form->currow);
2395 if ((field->opts & O_WRAP) && /* wrapping wanted */
2396 (!Single_Line_Field(field)) && /* must be multi-line */
2397 (There_Is_No_Room_For_A_Char_In_Line(form)) && /* line is full */
2398 (!Last_Row || Growable(field))) /* there are more lines */
2402 int chars_to_be_wrapped;
2403 int chars_to_remain_on_line;
2407 /* the above logic already ensures, that in this case the field
2409 if (!Field_Grown(field, 1))
2410 return E_SYSTEM_ERROR;
2412 bp = Address_Of_Current_Row_In_Buffer(form);
2413 Window_To_Buffer(form->w, field);
2414 split = After_Last_Whitespace_Character(bp, field->dcols);
2415 /* split points to the first character of the sequence to be brought
2417 chars_to_remain_on_line = (int)(split - bp);
2418 chars_to_be_wrapped = field->dcols - chars_to_remain_on_line;
2419 if (chars_to_remain_on_line > 0)
2421 if ((result = Insert_String(form, form->currow + 1, split,
2422 chars_to_be_wrapped)) == E_OK)
2424 wmove(form->w, form->currow, chars_to_remain_on_line);
2426 if (form->curcol >= chars_to_remain_on_line)
2429 form->curcol -= chars_to_remain_on_line;
2439 Window_To_Buffer(form->w, field);
2440 result = E_REQUEST_DENIED;
2444 result = E_OK; /* wrapping was not necessary */
2448 /*----------------------------------------------------------------------------
2449 Field Editing routines
2450 --------------------------------------------------------------------------*/
2452 /*---------------------------------------------------------------------------
2453 | Facility : libnform
2454 | Function : static int Field_Editing(
2455 | int (* const fct) (FORM *),
2458 | Description : Generic routine for field editing requests. The driver
2459 | routines are only called for editable fields, the
2460 | _WINDOW_MODIFIED flag is set if editing occurred.
2461 | This is somewhat special due to the overload semantics
2462 | of the NEW_LINE and DEL_PREV requests.
2464 | Return Values : Error code from low level drivers.
2465 +--------------------------------------------------------------------------*/
2467 Field_Editing(int (*const fct) (FORM *), FORM *form)
2469 int res = E_REQUEST_DENIED;
2471 /* We have to deal here with the specific case of the overloaded
2472 behavior of New_Line and Delete_Previous requests.
2473 They may end up in navigational requests if we are on the first
2474 character in a field. But navigation is also allowed on non-
2477 if ((fct == FE_Delete_Previous) &&
2478 (form->opts & O_BS_OVERLOAD) &&
2479 First_Position_In_Current_Field(form))
2481 res = Inter_Field_Navigation(FN_Previous_Field, form);
2485 if (fct == FE_New_Line)
2487 if ((form->opts & O_NL_OVERLOAD) &&
2488 First_Position_In_Current_Field(form))
2490 res = Inter_Field_Navigation(FN_Next_Field, form);
2493 /* FE_New_Line deals itself with the _WINDOW_MODIFIED flag */
2498 /* From now on, everything must be editable */
2499 if (form->current->opts & O_EDIT)
2503 form->status |= _WINDOW_MODIFIED;
2510 /*---------------------------------------------------------------------------
2511 | Facility : libnform
2512 | Function : static int FE_New_Line(FORM * form)
2514 | Description : Perform a new line request. This is rather complex
2515 | compared to other routines in this code due to the
2516 | rather difficult to understand description in the
2519 | Return Values : E_OK - success
2520 | E_REQUEST_DENIED - new line not allowed
2521 | E_SYSTEM_ERROR - system error
2522 +--------------------------------------------------------------------------*/
2524 FE_New_Line(FORM *form)
2526 FIELD *field = form->current;
2528 bool Last_Row = ((field->drows - 1) == form->currow);
2530 T((T_CALLED("FE_New_Line(%p)"), form));
2531 if (form->status & _OVLMODE)
2534 (!(Growable(field) && !Single_Line_Field(field))))
2536 if (!(form->opts & O_NL_OVERLOAD))
2537 returnCode(E_REQUEST_DENIED);
2538 wmove(form->w, form->currow, form->curcol);
2540 /* we have to set this here, although it is also
2541 handled in the generic routine. The reason is,
2542 that FN_Next_Field may fail, but the form is
2543 definitively changed */
2544 form->status |= _WINDOW_MODIFIED;
2545 returnCode(Inter_Field_Navigation(FN_Next_Field, form));
2549 if (Last_Row && !Field_Grown(field, 1))
2551 /* N.B.: due to the logic in the 'if', LastRow==TRUE
2552 means here that the field is growable and not
2553 a single-line field */
2554 returnCode(E_SYSTEM_ERROR);
2556 wmove(form->w, form->currow, form->curcol);
2560 form->status |= _WINDOW_MODIFIED;
2568 !(Growable(field) && !Single_Line_Field(field)))
2570 if (!(form->opts & O_NL_OVERLOAD))
2571 returnCode(E_REQUEST_DENIED);
2572 returnCode(Inter_Field_Navigation(FN_Next_Field, form));
2576 bool May_Do_It = !Last_Row && Is_There_Room_For_A_Line(form);
2578 if (!(May_Do_It || Growable(field)))
2579 returnCode(E_REQUEST_DENIED);
2580 if (!May_Do_It && !Field_Grown(field, 1))
2581 returnCode(E_SYSTEM_ERROR);
2583 bp = Address_Of_Current_Position_In_Buffer(form);
2584 t = After_End_Of_Data(bp, field->dcols - form->curcol);
2585 wmove(form->w, form->currow, form->curcol);
2589 wmove(form->w, form->currow, form->curcol);
2591 myADDNSTR(form->w, bp, (int)(t - bp));
2592 form->status |= _WINDOW_MODIFIED;
2598 /*---------------------------------------------------------------------------
2599 | Facility : libnform
2600 | Function : static int FE_Insert_Character(FORM * form)
2602 | Description : Insert blank character at the cursor position
2604 | Return Values : E_OK
2606 +--------------------------------------------------------------------------*/
2608 FE_Insert_Character(FORM *form)
2610 FIELD *field = form->current;
2611 int result = E_REQUEST_DENIED;
2613 T((T_CALLED("FE_Insert_Character(%p)"), form));
2614 if (Check_Char(field->type, (int)C_BLANK, (TypeArgument *)(field->arg)))
2616 bool There_Is_Room = Is_There_Room_For_A_Char_In_Line(form);
2618 if (There_Is_Room ||
2619 ((Single_Line_Field(field) && Growable(field))))
2621 if (!There_Is_Room && !Field_Grown(field, 1))
2622 result = E_SYSTEM_ERROR;
2625 winsch(form->w, (chtype)C_BLANK);
2626 result = Wrapping_Not_Necessary_Or_Wrapping_Ok(form);
2633 /*---------------------------------------------------------------------------
2634 | Facility : libnform
2635 | Function : static int FE_Insert_Line(FORM * form)
2637 | Description : Insert a blank line at the cursor position
2639 | Return Values : E_OK - success
2640 | E_REQUEST_DENIED - line can not be inserted
2641 +--------------------------------------------------------------------------*/
2643 FE_Insert_Line(FORM *form)
2645 FIELD *field = form->current;
2646 int result = E_REQUEST_DENIED;
2648 T((T_CALLED("FE_Insert_Line(%p)"), form));
2649 if (Check_Char(field->type, (int)C_BLANK, (TypeArgument *)(field->arg)))
2651 bool Maybe_Done = (form->currow != (field->drows - 1)) &&
2652 Is_There_Room_For_A_Line(form);
2654 if (!Single_Line_Field(field) &&
2655 (Maybe_Done || Growable(field)))
2657 if (!Maybe_Done && !Field_Grown(field, 1))
2658 result = E_SYSTEM_ERROR;
2670 /*---------------------------------------------------------------------------
2671 | Facility : libnform
2672 | Function : static int FE_Delete_Character(FORM * form)
2674 | Description : Delete character at the cursor position
2676 | Return Values : E_OK - success
2677 +--------------------------------------------------------------------------*/
2679 FE_Delete_Character(FORM *form)
2681 T((T_CALLED("FE_Delete_Character(%p)"), form));
2686 /*---------------------------------------------------------------------------
2687 | Facility : libnform
2688 | Function : static int FE_Delete_Previous(FORM * form)
2690 | Description : Delete character before cursor. Again this is a rather
2691 | difficult piece compared to others due to the overloading
2692 | semantics of backspace.
2693 | N.B.: The case of overloaded BS on first field position
2694 | is already handled in the generic routine.
2696 | Return Values : E_OK - success
2697 | E_REQUEST_DENIED - Character can't be deleted
2698 +--------------------------------------------------------------------------*/
2700 FE_Delete_Previous(FORM *form)
2702 FIELD *field = form->current;
2704 T((T_CALLED("FE_Delete_Previous(%p)"), form));
2705 if (First_Position_In_Current_Field(form))
2706 returnCode(E_REQUEST_DENIED);
2708 if ((--(form->curcol)) < 0)
2710 FIELD_CELL *this_line, *prev_line, *prev_end, *this_end;
2711 int this_row = form->currow;
2714 if (form->status & _OVLMODE)
2715 returnCode(E_REQUEST_DENIED);
2717 prev_line = Address_Of_Row_In_Buffer(field, (form->currow - 1));
2718 this_line = Address_Of_Row_In_Buffer(field, (form->currow));
2719 Synchronize_Buffer(form);
2720 prev_end = After_End_Of_Data(prev_line, field->dcols);
2721 this_end = After_End_Of_Data(this_line, field->dcols);
2722 if ((int)(this_end - this_line) >
2723 (field->cols - (int)(prev_end - prev_line)))
2724 returnCode(E_REQUEST_DENIED);
2725 wmove(form->w, form->currow, form->curcol);
2727 Adjust_Cursor_Position(form, prev_end);
2729 * If we did not really move to the previous line, help the user a
2730 * little. It is however a little inconsistent. Normally, when
2731 * backspacing around the point where text wraps to a new line in a
2732 * multi-line form, we absorb one keystroke for the wrapping point. That
2733 * is consistent with SVr4 forms. However, SVr4 does not allow typing
2734 * into the last column of the field, and requires the user to enter a
2735 * newline to move to the next line. Therefore it can consistently eat
2736 * that keystroke. Since ncurses allows the last column, it wraps
2737 * automatically (given the proper options). But we cannot eat the
2738 * keystroke to back over the wrapping point, since that would put the
2739 * cursor past the end of the form field. In this case, just delete the
2740 * character at the end of the field.
2742 if (form->currow == this_row && this_row > 0)
2745 form->curcol = field->dcols - 1;
2750 wmove(form->w, form->currow, form->curcol);
2751 myADDNSTR(form->w, this_line, (int)(this_end - this_line));
2761 /*---------------------------------------------------------------------------
2762 | Facility : libnform
2763 | Function : static int FE_Delete_Line(FORM * form)
2765 | Description : Delete line at cursor position.
2767 | Return Values : E_OK - success
2768 +--------------------------------------------------------------------------*/
2770 FE_Delete_Line(FORM *form)
2772 T((T_CALLED("FE_Delete_Line(%p)"), form));
2778 /*---------------------------------------------------------------------------
2779 | Facility : libnform
2780 | Function : static int FE_Delete_Word(FORM * form)
2782 | Description : Delete word at cursor position
2784 | Return Values : E_OK - success
2785 | E_REQUEST_DENIED - failure
2786 +--------------------------------------------------------------------------*/
2788 FE_Delete_Word(FORM *form)
2790 FIELD *field = form->current;
2791 FIELD_CELL *bp = Address_Of_Current_Row_In_Buffer(form);
2792 FIELD_CELL *ep = bp + field->dcols;
2793 FIELD_CELL *cp = bp + form->curcol;
2796 T((T_CALLED("FE_Delete_Word(%p)"), form));
2797 Synchronize_Buffer(form);
2799 returnCode(E_REQUEST_DENIED); /* not in word */
2801 /* move cursor to begin of word and erase to end of screen-line */
2802 Adjust_Cursor_Position(form,
2803 After_Last_Whitespace_Character(bp, form->curcol));
2804 wmove(form->w, form->currow, form->curcol);
2807 /* skip over word in buffer */
2808 s = Get_First_Whitespace_Character(cp, (int)(ep - cp));
2809 /* to begin of next word */
2810 s = Get_Start_Of_Data(s, (int)(ep - s));
2811 if ((s != cp) && !ISBLANK(*s))
2813 /* copy remaining line to window */
2814 myADDNSTR(form->w, s, (int)(s - After_End_Of_Data(s, (int)(ep - s))));
2819 /*---------------------------------------------------------------------------
2820 | Facility : libnform
2821 | Function : static int FE_Clear_To_End_Of_Line(FORM * form)
2823 | Description : Clear to end of current line.
2825 | Return Values : E_OK - success
2826 +--------------------------------------------------------------------------*/
2828 FE_Clear_To_End_Of_Line(FORM *form)
2830 T((T_CALLED("FE_Clear_To_End_Of_Line(%p)"), form));
2831 wmove(form->w, form->currow, form->curcol);
2836 /*---------------------------------------------------------------------------
2837 | Facility : libnform
2838 | Function : static int FE_Clear_To_End_Of_Field(FORM * form)
2840 | Description : Clear to end of field.
2842 | Return Values : E_OK - success
2843 +--------------------------------------------------------------------------*/
2845 FE_Clear_To_End_Of_Field(FORM *form)
2847 T((T_CALLED("FE_Clear_To_End_Of_Field(%p)"), form));
2848 wmove(form->w, form->currow, form->curcol);
2853 /*---------------------------------------------------------------------------
2854 | Facility : libnform
2855 | Function : static int FE_Clear_Field(FORM * form)
2857 | Description : Clear entire field.
2859 | Return Values : E_OK - success
2860 +--------------------------------------------------------------------------*/
2862 FE_Clear_Field(FORM *form)
2864 T((T_CALLED("FE_Clear_Field(%p)"), form));
2865 form->currow = form->curcol = 0;
2869 /*----------------------------------------------------------------------------
2870 END of Field Editing routines
2871 --------------------------------------------------------------------------*/
2873 /*----------------------------------------------------------------------------
2875 --------------------------------------------------------------------------*/
2877 /*---------------------------------------------------------------------------
2878 | Facility : libnform
2879 | Function : static int EM_Overlay_Mode(FORM * form)
2881 | Description : Switch to overlay mode.
2883 | Return Values : E_OK - success
2884 +--------------------------------------------------------------------------*/
2886 EM_Overlay_Mode(FORM *form)
2888 T((T_CALLED("EM_Overlay_Mode(%p)"), form));
2889 form->status |= _OVLMODE;
2893 /*---------------------------------------------------------------------------
2894 | Facility : libnform
2895 | Function : static int EM_Insert_Mode(FORM * form)
2897 | Description : Switch to insert mode
2899 | Return Values : E_OK - success
2900 +--------------------------------------------------------------------------*/
2902 EM_Insert_Mode(FORM *form)
2904 T((T_CALLED("EM_Insert_Mode(%p)"), form));
2905 form->status &= ~_OVLMODE;
2909 /*----------------------------------------------------------------------------
2910 END of Edit Mode routines
2911 --------------------------------------------------------------------------*/
2913 /*----------------------------------------------------------------------------
2914 Helper routines for Choice Requests
2915 --------------------------------------------------------------------------*/
2917 /*---------------------------------------------------------------------------
2918 | Facility : libnform
2919 | Function : static bool Next_Choice(
2922 | TypeArgument *argp)
2924 | Description : Get the next field choice. For linked types this is
2927 | Return Values : TRUE - next choice successfully retrieved
2928 | FALSE - couldn't retrieve next choice
2929 +--------------------------------------------------------------------------*/
2931 Next_Choice(FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
2933 if (!typ || !(typ->status & _HAS_CHOICE))
2936 if (typ->status & _LINKED_TYPE)
2940 Next_Choice(typ->left, field, argp->left) ||
2941 Next_Choice(typ->right, field, argp->right));
2946 return typ->next(field, (void *)argp);
2950 /*---------------------------------------------------------------------------
2951 | Facility : libnform
2952 | Function : static bool Previous_Choice(
2955 | TypeArgument *argp)
2957 | Description : Get the previous field choice. For linked types this
2958 | is done recursively.
2960 | Return Values : TRUE - previous choice successfully retrieved
2961 | FALSE - couldn't retrieve previous choice
2962 +--------------------------------------------------------------------------*/
2964 Previous_Choice(FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
2966 if (!typ || !(typ->status & _HAS_CHOICE))
2969 if (typ->status & _LINKED_TYPE)
2973 Previous_Choice(typ->left, field, argp->left) ||
2974 Previous_Choice(typ->right, field, argp->right));
2979 return typ->prev(field, (void *)argp);
2982 /*----------------------------------------------------------------------------
2983 End of Helper routines for Choice Requests
2984 --------------------------------------------------------------------------*/
2986 /*----------------------------------------------------------------------------
2987 Routines for Choice Requests
2988 --------------------------------------------------------------------------*/
2990 /*---------------------------------------------------------------------------
2991 | Facility : libnform
2992 | Function : static int CR_Next_Choice(FORM * form)
2994 | Description : Get the next field choice.
2996 | Return Values : E_OK - success
2997 | E_REQUEST_DENIED - next choice couldn't be retrieved
2998 +--------------------------------------------------------------------------*/
3000 CR_Next_Choice(FORM *form)
3002 FIELD *field = form->current;
3004 T((T_CALLED("CR_Next_Choice(%p)"), form));
3005 Synchronize_Buffer(form);
3006 returnCode((Next_Choice(field->type, field, (TypeArgument *)(field->arg)))
3008 : E_REQUEST_DENIED);
3011 /*---------------------------------------------------------------------------
3012 | Facility : libnform
3013 | Function : static int CR_Previous_Choice(FORM * form)
3015 | Description : Get the previous field choice.
3017 | Return Values : E_OK - success
3018 | E_REQUEST_DENIED - prev. choice couldn't be retrieved
3019 +--------------------------------------------------------------------------*/
3021 CR_Previous_Choice(FORM *form)
3023 FIELD *field = form->current;
3025 T((T_CALLED("CR_Previous_Choice(%p)"), form));
3026 Synchronize_Buffer(form);
3027 returnCode((Previous_Choice(field->type, field, (TypeArgument *)(field->arg)))
3029 : E_REQUEST_DENIED);
3031 /*----------------------------------------------------------------------------
3032 End of Routines for Choice Requests
3033 --------------------------------------------------------------------------*/
3035 /*----------------------------------------------------------------------------
3036 Helper routines for Field Validations.
3037 --------------------------------------------------------------------------*/
3039 /*---------------------------------------------------------------------------
3040 | Facility : libnform
3041 | Function : static bool Check_Field(
3044 | TypeArgument * argp)
3046 | Description : Check the field according to its fieldtype and its
3047 | actual arguments. For linked fieldtypes this is done
3050 | Return Values : TRUE - field is valid
3051 | FALSE - field is invalid.
3052 +--------------------------------------------------------------------------*/
3054 Check_Field(FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
3058 if (field->opts & O_NULLOK)
3060 FIELD_CELL *bp = field->buf;
3063 while (ISBLANK(*bp))
3067 if (CharOf(*bp) == 0)
3071 if (typ->status & _LINKED_TYPE)
3075 Check_Field(typ->left, field, argp->left) ||
3076 Check_Field(typ->right, field, argp->right));
3081 return typ->fcheck(field, (void *)argp);
3087 /*---------------------------------------------------------------------------
3088 | Facility : libnform
3089 | Function : bool _nc_Internal_Validation(FORM * form )
3091 | Description : Validate the current field of the form.
3093 | Return Values : TRUE - field is valid
3094 | FALSE - field is invalid
3095 +--------------------------------------------------------------------------*/
3096 NCURSES_EXPORT(bool)
3097 _nc_Internal_Validation(FORM *form)
3101 field = form->current;
3103 Synchronize_Buffer(form);
3104 if ((form->status & _FCHECK_REQUIRED) ||
3105 (!(field->opts & O_PASSOK)))
3107 if (!Check_Field(field->type, field, (TypeArgument *)(field->arg)))
3109 form->status &= ~_FCHECK_REQUIRED;
3110 field->status |= _CHANGED;
3111 Synchronize_Linked_Fields(field);
3115 /*----------------------------------------------------------------------------
3116 End of Helper routines for Field Validations.
3117 --------------------------------------------------------------------------*/
3119 /*----------------------------------------------------------------------------
3120 Routines for Field Validation.
3121 --------------------------------------------------------------------------*/
3123 /*---------------------------------------------------------------------------
3124 | Facility : libnform
3125 | Function : static int FV_Validation(FORM * form)
3127 | Description : Validate the current field of the form.
3129 | Return Values : E_OK - field valid
3130 | E_INVALID_FIELD - field not valid
3131 +--------------------------------------------------------------------------*/
3133 FV_Validation(FORM *form)
3135 T((T_CALLED("FV_Validation(%p)"), form));
3136 if (_nc_Internal_Validation(form))
3139 returnCode(E_INVALID_FIELD);
3141 /*----------------------------------------------------------------------------
3142 End of routines for Field Validation.
3143 --------------------------------------------------------------------------*/
3145 /*----------------------------------------------------------------------------
3146 Helper routines for Inter-Field Navigation
3147 --------------------------------------------------------------------------*/
3149 /*---------------------------------------------------------------------------
3150 | Facility : libnform
3151 | Function : static FIELD *Next_Field_On_Page(FIELD * field)
3153 | Description : Get the next field after the given field on the current
3154 | page. The order of fields is the one defined by the
3155 | fields array. Only visible and active fields are
3158 | Return Values : Pointer to the next field.
3159 +--------------------------------------------------------------------------*/
3160 NCURSES_INLINE static FIELD *
3161 Next_Field_On_Page(FIELD *field)
3163 FORM *form = field->form;
3164 FIELD **field_on_page = &form->field[field->index];
3165 FIELD **first_on_page = &form->field[form->page[form->curpage].pmin];
3166 FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
3171 (field_on_page == last_on_page) ? first_on_page : field_on_page + 1;
3172 if (Field_Is_Selectable(*field_on_page))
3175 while (field != (*field_on_page));
3176 return (*field_on_page);
3179 /*---------------------------------------------------------------------------
3180 | Facility : libnform
3181 | Function : FIELD* _nc_First_Active_Field(FORM * form)
3183 | Description : Get the first active field on the current page,
3184 | if there are such. If there are none, get the first
3185 | visible field on the page. If there are also none,
3186 | we return the first field on page and hope the best.
3188 | Return Values : Pointer to calculated field.
3189 +--------------------------------------------------------------------------*/
3190 NCURSES_EXPORT(FIELD *)
3191 _nc_First_Active_Field(FORM *form)
3193 FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
3194 FIELD *proposed = Next_Field_On_Page(*last_on_page);
3196 if (proposed == *last_on_page)
3198 /* there might be the special situation, where there is no
3199 active and visible field on the current page. We then select
3200 the first visible field on this readonly page
3202 if (Field_Is_Not_Selectable(proposed))
3204 FIELD **field = &form->field[proposed->index];
3205 FIELD **first = &form->field[form->page[form->curpage].pmin];
3209 field = (field == last_on_page) ? first : field + 1;
3210 if (((*field)->opts & O_VISIBLE))
3213 while (proposed != (*field));
3217 if ((proposed == *last_on_page) && !(proposed->opts & O_VISIBLE))
3219 /* This means, there is also no visible field on the page.
3220 So we propose the first one and hope the very best...
3221 Some very clever user has designed a readonly and invisible
3231 /*---------------------------------------------------------------------------
3232 | Facility : libnform
3233 | Function : static FIELD *Previous_Field_On_Page(FIELD * field)
3235 | Description : Get the previous field before the given field on the
3236 | current page. The order of fields is the one defined by
3237 | the fields array. Only visible and active fields are
3240 | Return Values : Pointer to the previous field.
3241 +--------------------------------------------------------------------------*/
3242 NCURSES_INLINE static FIELD *
3243 Previous_Field_On_Page(FIELD *field)
3245 FORM *form = field->form;
3246 FIELD **field_on_page = &form->field[field->index];
3247 FIELD **first_on_page = &form->field[form->page[form->curpage].pmin];
3248 FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
3253 (field_on_page == first_on_page) ? last_on_page : field_on_page - 1;
3254 if (Field_Is_Selectable(*field_on_page))
3257 while (field != (*field_on_page));
3259 return (*field_on_page);
3262 /*---------------------------------------------------------------------------
3263 | Facility : libnform
3264 | Function : static FIELD *Sorted_Next_Field(FIELD * field)
3266 | Description : Get the next field after the given field on the current
3267 | page. The order of fields is the one defined by the
3268 | (row,column) geometry, rows are major.
3270 | Return Values : Pointer to the next field.
3271 +--------------------------------------------------------------------------*/
3272 NCURSES_INLINE static FIELD *
3273 Sorted_Next_Field(FIELD *field)
3275 FIELD *field_on_page = field;
3279 field_on_page = field_on_page->snext;
3280 if (Field_Is_Selectable(field_on_page))
3283 while (field_on_page != field);
3285 return (field_on_page);
3288 /*---------------------------------------------------------------------------
3289 | Facility : libnform
3290 | Function : static FIELD *Sorted_Previous_Field(FIELD * field)
3292 | Description : Get the previous field before the given field on the
3293 | current page. The order of fields is the one defined
3294 | by the (row,column) geometry, rows are major.
3296 | Return Values : Pointer to the previous field.
3297 +--------------------------------------------------------------------------*/
3298 NCURSES_INLINE static FIELD *
3299 Sorted_Previous_Field(FIELD *field)
3301 FIELD *field_on_page = field;
3305 field_on_page = field_on_page->sprev;
3306 if (Field_Is_Selectable(field_on_page))
3309 while (field_on_page != field);
3311 return (field_on_page);
3314 /*---------------------------------------------------------------------------
3315 | Facility : libnform
3316 | Function : static FIELD *Left_Neighbor_Field(FIELD * field)
3318 | Description : Get the left neighbor of the field on the same line
3319 | and the same page. Cycles through the line.
3321 | Return Values : Pointer to left neighbor field.
3322 +--------------------------------------------------------------------------*/
3323 NCURSES_INLINE static FIELD *
3324 Left_Neighbor_Field(FIELD *field)
3326 FIELD *field_on_page = field;
3328 /* For a field that has really a left neighbor, the while clause
3329 immediately fails and the loop is left, positioned at the right
3330 neighbor. Otherwise we cycle backwards through the sorted field list
3331 until we enter the same line (from the right end).
3335 field_on_page = Sorted_Previous_Field(field_on_page);
3337 while (field_on_page->frow != field->frow);
3339 return (field_on_page);
3342 /*---------------------------------------------------------------------------
3343 | Facility : libnform
3344 | Function : static FIELD *Right_Neighbor_Field(FIELD * field)
3346 | Description : Get the right neighbor of the field on the same line
3347 | and the same page.
3349 | Return Values : Pointer to right neighbor field.
3350 +--------------------------------------------------------------------------*/
3351 NCURSES_INLINE static FIELD *
3352 Right_Neighbor_Field(FIELD *field)
3354 FIELD *field_on_page = field;
3356 /* See the comments on Left_Neighbor_Field to understand how it works */
3359 field_on_page = Sorted_Next_Field(field_on_page);
3361 while (field_on_page->frow != field->frow);
3363 return (field_on_page);
3366 /*---------------------------------------------------------------------------
3367 | Facility : libnform
3368 | Function : static FIELD *Upper_Neighbor_Field(FIELD * field)
3370 | Description : Because of the row-major nature of sorting the fields,
3371 | it is more difficult to define whats the upper neighbor
3372 | field really means. We define that it must be on a
3373 | 'previous' line (cyclic order!) and is the rightmost
3374 | field laying on the left side of the given field. If
3375 | this set is empty, we take the first field on the line.
3377 | Return Values : Pointer to the upper neighbor field.
3378 +--------------------------------------------------------------------------*/
3380 Upper_Neighbor_Field(FIELD *field)
3382 FIELD *field_on_page = field;
3383 int frow = field->frow;
3384 int fcol = field->fcol;
3386 /* Walk back to the 'previous' line. The second term in the while clause
3387 just guarantees that we stop if we cycled through the line because
3388 there might be no 'previous' line if the page has just one line.
3392 field_on_page = Sorted_Previous_Field(field_on_page);
3394 while (field_on_page->frow == frow && field_on_page->fcol != fcol);
3396 if (field_on_page->frow != frow)
3398 /* We really found a 'previous' line. We are positioned at the
3399 rightmost field on this line */
3400 frow = field_on_page->frow;
3402 /* We walk to the left as long as we are really right of the
3404 while (field_on_page->frow == frow && field_on_page->fcol > fcol)
3405 field_on_page = Sorted_Previous_Field(field_on_page);
3407 /* If we wrapped, just go to the right which is the first field on
3409 if (field_on_page->frow != frow)
3410 field_on_page = Sorted_Next_Field(field_on_page);
3413 return (field_on_page);
3416 /*---------------------------------------------------------------------------
3417 | Facility : libnform
3418 | Function : static FIELD *Down_Neighbor_Field(FIELD * field)
3420 | Description : Because of the row-major nature of sorting the fields,
3421 | its more difficult to define whats the down neighbor
3422 | field really means. We define that it must be on a
3423 | 'next' line (cyclic order!) and is the leftmost
3424 | field laying on the right side of the given field. If
3425 | this set is empty, we take the last field on the line.
3427 | Return Values : Pointer to the upper neighbor field.
3428 +--------------------------------------------------------------------------*/
3430 Down_Neighbor_Field(FIELD *field)
3432 FIELD *field_on_page = field;
3433 int frow = field->frow;
3434 int fcol = field->fcol;
3436 /* Walk forward to the 'next' line. The second term in the while clause
3437 just guarantees that we stop if we cycled through the line because
3438 there might be no 'next' line if the page has just one line.
3442 field_on_page = Sorted_Next_Field(field_on_page);
3444 while (field_on_page->frow == frow && field_on_page->fcol != fcol);
3446 if (field_on_page->frow != frow)
3448 /* We really found a 'next' line. We are positioned at the rightmost
3449 field on this line */
3450 frow = field_on_page->frow;
3452 /* We walk to the right as long as we are really left of the
3454 while (field_on_page->frow == frow && field_on_page->fcol < fcol)
3455 field_on_page = Sorted_Next_Field(field_on_page);
3457 /* If we wrapped, just go to the left which is the last field on
3459 if (field_on_page->frow != frow)
3460 field_on_page = Sorted_Previous_Field(field_on_page);
3463 return (field_on_page);
3466 /*----------------------------------------------------------------------------
3467 Inter-Field Navigation routines
3468 --------------------------------------------------------------------------*/
3470 /*---------------------------------------------------------------------------
3471 | Facility : libnform
3472 | Function : static int Inter_Field_Navigation(
3473 | int (* const fct) (FORM *),
3476 | Description : Generic behavior for changing the current field, the
3477 | field is left and a new field is entered. So the field
3478 | must be validated and the field init/term hooks must
3481 | Return Values : E_OK - success
3482 | E_INVALID_FIELD - field is invalid
3483 | some other - error from subordinate call
3484 +--------------------------------------------------------------------------*/
3486 Inter_Field_Navigation(int (*const fct) (FORM *), FORM *form)
3490 if (!_nc_Internal_Validation(form))
3491 res = E_INVALID_FIELD;
3494 Call_Hook(form, fieldterm);
3496 Call_Hook(form, fieldinit);
3501 /*---------------------------------------------------------------------------
3502 | Facility : libnform
3503 | Function : static int FN_Next_Field(FORM * form)
3505 | Description : Move to the next field on the current page of the form
3507 | Return Values : E_OK - success
3508 | != E_OK - error from subordinate call
3509 +--------------------------------------------------------------------------*/
3511 FN_Next_Field(FORM *form)
3513 T((T_CALLED("FN_Next_Field(%p)"), form));
3514 returnCode(_nc_Set_Current_Field(form,
3515 Next_Field_On_Page(form->current)));
3518 /*---------------------------------------------------------------------------
3519 | Facility : libnform
3520 | Function : static int FN_Previous_Field(FORM * form)
3522 | Description : Move to the previous field on the current page of the
3525 | Return Values : E_OK - success
3526 | != E_OK - error from subordinate call
3527 +--------------------------------------------------------------------------*/
3529 FN_Previous_Field(FORM *form)
3531 T((T_CALLED("FN_Previous_Field(%p)"), form));
3532 returnCode(_nc_Set_Current_Field(form,
3533 Previous_Field_On_Page(form->current)));
3536 /*---------------------------------------------------------------------------
3537 | Facility : libnform
3538 | Function : static int FN_First_Field(FORM * form)
3540 | Description : Move to the first field on the current page of the form
3542 | Return Values : E_OK - success
3543 | != E_OK - error from subordinate call
3544 +--------------------------------------------------------------------------*/
3546 FN_First_Field(FORM *form)
3548 T((T_CALLED("FN_First_Field(%p)"), form));
3549 returnCode(_nc_Set_Current_Field(form,
3550 Next_Field_On_Page(form->field[form->page[form->curpage].pmax])));
3553 /*---------------------------------------------------------------------------
3554 | Facility : libnform
3555 | Function : static int FN_Last_Field(FORM * form)
3557 | Description : Move to the last field on the current page of the form
3559 | Return Values : E_OK - success
3560 | != E_OK - error from subordinate call
3561 +--------------------------------------------------------------------------*/
3563 FN_Last_Field(FORM *form)
3565 T((T_CALLED("FN_Last_Field(%p)"), form));
3567 _nc_Set_Current_Field(form,
3568 Previous_Field_On_Page(form->field[form->page[form->curpage].pmin])));
3571 /*---------------------------------------------------------------------------
3572 | Facility : libnform
3573 | Function : static int FN_Sorted_Next_Field(FORM * form)
3575 | Description : Move to the sorted next field on the current page
3578 | Return Values : E_OK - success
3579 | != E_OK - error from subordinate call
3580 +--------------------------------------------------------------------------*/
3582 FN_Sorted_Next_Field(FORM *form)
3584 T((T_CALLED("FN_Sorted_Next_Field(%p)"), form));
3585 returnCode(_nc_Set_Current_Field(form,
3586 Sorted_Next_Field(form->current)));
3589 /*---------------------------------------------------------------------------
3590 | Facility : libnform
3591 | Function : static int FN_Sorted_Previous_Field(FORM * form)
3593 | Description : Move to the sorted previous field on the current page
3596 | Return Values : E_OK - success
3597 | != E_OK - error from subordinate call
3598 +--------------------------------------------------------------------------*/
3600 FN_Sorted_Previous_Field(FORM *form)
3602 T((T_CALLED("FN_Sorted_Previous_Field(%p)"), form));
3603 returnCode(_nc_Set_Current_Field(form,
3604 Sorted_Previous_Field(form->current)));
3607 /*---------------------------------------------------------------------------
3608 | Facility : libnform
3609 | Function : static int FN_Sorted_First_Field(FORM * form)
3611 | Description : Move to the sorted first field on the current page
3614 | Return Values : E_OK - success
3615 | != E_OK - error from subordinate call
3616 +--------------------------------------------------------------------------*/
3618 FN_Sorted_First_Field(FORM *form)
3620 T((T_CALLED("FN_Sorted_First_Field(%p)"), form));
3621 returnCode(_nc_Set_Current_Field(form,
3622 Sorted_Next_Field(form->field[form->page[form->curpage].smax])));
3625 /*---------------------------------------------------------------------------
3626 | Facility : libnform
3627 | Function : static int FN_Sorted_Last_Field(FORM * form)
3629 | Description : Move to the sorted last field on the current page
3632 | Return Values : E_OK - success
3633 | != E_OK - error from subordinate call
3634 +--------------------------------------------------------------------------*/
3636 FN_Sorted_Last_Field(FORM *form)
3638 T((T_CALLED("FN_Sorted_Last_Field(%p)"), form));
3639 returnCode(_nc_Set_Current_Field(form,
3640 Sorted_Previous_Field(form->field[form->page[form->curpage].smin])));
3643 /*---------------------------------------------------------------------------
3644 | Facility : libnform
3645 | Function : static int FN_Left_Field(FORM * form)
3647 | Description : Get the field on the left of the current field on the
3648 | same line and the same page. Cycles through the line.
3650 | Return Values : E_OK - success
3651 | != E_OK - error from subordinate call
3652 +--------------------------------------------------------------------------*/
3654 FN_Left_Field(FORM *form)
3656 T((T_CALLED("FN_Left_Field(%p)"), form));
3657 returnCode(_nc_Set_Current_Field(form,
3658 Left_Neighbor_Field(form->current)));
3661 /*---------------------------------------------------------------------------
3662 | Facility : libnform
3663 | Function : static int FN_Right_Field(FORM * form)
3665 | Description : Get the field on the right of the current field on the
3666 | same line and the same page. Cycles through the line.
3668 | Return Values : E_OK - success
3669 | != E_OK - error from subordinate call
3670 +--------------------------------------------------------------------------*/
3672 FN_Right_Field(FORM *form)
3674 T((T_CALLED("FN_Right_Field(%p)"), form));
3675 returnCode(_nc_Set_Current_Field(form,
3676 Right_Neighbor_Field(form->current)));
3679 /*---------------------------------------------------------------------------
3680 | Facility : libnform
3681 | Function : static int FN_Up_Field(FORM * form)
3683 | Description : Get the upper neighbor of the current field. This
3684 | cycles through the page. See the comments of the
3685 | Upper_Neighbor_Field function to understand how
3686 | 'upper' is defined.
3688 | Return Values : E_OK - success
3689 | != E_OK - error from subordinate call
3690 +--------------------------------------------------------------------------*/
3692 FN_Up_Field(FORM *form)
3694 T((T_CALLED("FN_Up_Field(%p)"), form));
3695 returnCode(_nc_Set_Current_Field(form,
3696 Upper_Neighbor_Field(form->current)));
3699 /*---------------------------------------------------------------------------
3700 | Facility : libnform
3701 | Function : static int FN_Down_Field(FORM * form)
3703 | Description : Get the down neighbor of the current field. This
3704 | cycles through the page. See the comments of the
3705 | Down_Neighbor_Field function to understand how