1 /****************************************************************************
2 * Copyright 2018-2019,2020 Thomas E. Dickey *
3 * Copyright 1998-2016,2017 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Juergen Pfeifer, 1995,1997 *
32 ****************************************************************************/
34 #include "form.priv.h"
36 MODULE_ID("$Id: frm_driver.c,v 1.133 2020/12/12 00:36:42 tom Exp $")
38 /*----------------------------------------------------------------------------
39 This is the core module of the form library. It contains the majority
40 of the driver routines as well as the form_driver function.
42 Essentially this module is nearly the whole library. This is because
43 all the functions in this module depends on some others in the module,
44 so it makes no sense to split them into separate files because they
45 will always be linked together. The only acceptable concern is turnaround
46 time for this module, but now we have all Pentiums or RISCs, so what!
48 The driver routines are grouped into nine generic categories:
50 a) Page Navigation ( all functions prefixed by PN_ )
51 The current page of the form is left and some new page is
53 b) Inter-Field Navigation ( all functions prefixed by FN_ )
54 The current field of the form is left and some new field is
56 c) Intra-Field Navigation ( all functions prefixed by IFN_ )
57 The current position in the current field is changed.
58 d) Vertical Scrolling ( all functions prefixed by VSC_ )
59 Essentially this is a specialization of Intra-Field navigation.
60 It has to check for a multi-line field.
61 e) Horizontal Scrolling ( all functions prefixed by HSC_ )
62 Essentially this is a specialization of Intra-Field navigation.
63 It has to check for a single-line field.
64 f) Field Editing ( all functions prefixed by FE_ )
65 The content of the current field is changed
66 g) Edit Mode requests ( all functions prefixed by EM_ )
67 Switching between insert and overlay mode
68 h) Field-Validation requests ( all functions prefixed by FV_ )
69 Perform verifications of the field.
70 i) Choice requests ( all functions prefixed by CR_ )
71 Requests to enumerate possible field values
72 --------------------------------------------------------------------------*/
74 /*----------------------------------------------------------------------------
75 Some remarks on the placements of assert() macros :
76 I use them only on "strategic" places, i.e. top level entries where
77 I want to make sure that things are set correctly. Throughout subordinate
78 routines I omit them mostly.
79 --------------------------------------------------------------------------*/
82 Some options that may effect compatibility in behavior to SVr4 forms,
83 but they are here to allow a more intuitive and user friendly behavior of
84 our form implementation. This doesn't affect the API, so we feel it is
87 The initial implementation tries to stay very close with the behavior
88 of the original SVr4 implementation, although in some areas it is quite
89 clear that this isn't the most appropriate way. As far as possible this
90 sources will allow you to build a forms lib that behaves quite similar
91 to SVr4, but now and in the future we will give you better options.
92 Perhaps at some time we will make this configurable at runtime.
95 /* Implement a more user-friendly previous/next word behavior */
96 #define FRIENDLY_PREV_NEXT_WORD (1)
97 /* Fix the wrong behavior for forms with all fields inactive */
98 #define FIX_FORM_INACTIVE_BUG (1)
99 /* Allow dynamic field growth also when navigating past the end */
100 #define GROW_IF_NAVIGATE (1)
102 #if USE_WIDEC_SUPPORT
103 #define myADDNSTR(w, s, n) wide_waddnstr(w, s, n)
104 #define myINSNSTR(w, s, n) wide_winsnstr(w, s, n)
105 #define myINNSTR(w, s, n) wide_winnstr(w, s, n)
106 #define myWCWIDTH(w, y, x) cell_width(w, y, x)
108 #define myADDNSTR(w, s, n) waddnstr(w, s, n)
109 #define myINSNSTR(w, s, n) winsnstr(w, s, n)
110 #define myINNSTR(w, s, n) winnstr(w, s, n)
111 #define myWCWIDTH(w, y, x) 1
114 /*----------------------------------------------------------------------------
115 Forward references to some internally used static functions
116 --------------------------------------------------------------------------*/
117 static int Inter_Field_Navigation(int (*const fct) (FORM *), FORM *form);
118 static int FN_Next_Field(FORM *form);
119 static int FN_Previous_Field(FORM *form);
120 static int FE_New_Line(FORM *);
121 static int FE_Delete_Previous(FORM *);
123 /*----------------------------------------------------------------------------
126 Some Remarks on that: I use the convention to use UPPERCASE for constants
127 defined by Macros. If I provide a macro as a kind of inline routine to
128 provide some logic, I use my Upper_Lower case style.
129 --------------------------------------------------------------------------*/
131 /* Calculate the position of a single row in a field buffer */
132 #define Position_Of_Row_In_Buffer(field,row) ((row)*(field)->dcols)
134 /* Calculate start address for the field's buffer# N */
135 #define Address_Of_Nth_Buffer(field,N) \
136 ((field)->buf + (N)*(1+Buffer_Length(field)))
138 /* Calculate the start address of the row in the field's specified buffer# N */
139 #define Address_Of_Row_In_Nth_Buffer(field,N,row) \
140 (Address_Of_Nth_Buffer(field,N) + Position_Of_Row_In_Buffer(field,row))
142 /* Calculate the start address of the row in the field's primary buffer */
143 #define Address_Of_Row_In_Buffer(field,row) \
144 Address_Of_Row_In_Nth_Buffer(field,0,row)
146 /* Calculate the start address of the row in the form's current field
148 #define Address_Of_Current_Row_In_Nth_Buffer(form,N) \
149 Address_Of_Row_In_Nth_Buffer((form)->current,N,(form)->currow)
151 /* Calculate the start address of the row in the form's current field
153 #define Address_Of_Current_Row_In_Buffer(form) \
154 Address_Of_Current_Row_In_Nth_Buffer(form,0)
156 /* Calculate the address of the cursor in the form's current field
158 #define Address_Of_Current_Position_In_Nth_Buffer(form,N) \
159 (Address_Of_Current_Row_In_Nth_Buffer(form,N) + (form)->curcol)
161 /* Calculate the address of the cursor in the form's current field
163 #define Address_Of_Current_Position_In_Buffer(form) \
164 Address_Of_Current_Position_In_Nth_Buffer(form,0)
166 /* Logic to decide whether or not a field is actually a field with
167 vertical or horizontal scrolling */
168 #define Is_Scroll_Field(field) \
169 (((field)->drows > (field)->rows) || \
170 ((field)->dcols > (field)->cols))
172 /* Logic to decide whether or not a field needs to have an individual window
173 instead of a derived window because it contains invisible parts.
174 This is true for non-public fields and for scrollable fields. */
175 #define Has_Invisible_Parts(field) \
176 (!(Field_Has_Option(field, O_PUBLIC)) || \
177 Is_Scroll_Field(field))
179 /* Logic to decide whether or not a field needs justification */
180 #define Justification_Allowed(field) \
181 (((field)->just != NO_JUSTIFICATION) && \
182 (Single_Line_Field(field)) && \
183 ((Field_Has_Option(field, O_STATIC) && \
184 ((field)->dcols == (field)->cols)) || \
185 Field_Has_Option(field, O_DYNAMIC_JUSTIFY)))
187 /* Logic to determine whether or not a dynamic field may still grow */
188 #define Growable(field) ((field)->status & _MAY_GROW)
190 /* Macro to set the attributes for a field's window */
191 #define Set_Field_Window_Attributes(field,win) \
192 ( wbkgdset((win),(chtype)((chtype)((field)->pad) | (field)->back)), \
193 (void) wattrset((win), (int)(field)->fore) )
195 /* Logic to decide whether or not a field really appears on the form */
196 #define Field_Really_Appears(field) \
198 (field->form->status & _POSTED) &&\
199 (Field_Has_Option(field, O_VISIBLE)) &&\
200 (field->page == field->form->curpage))
202 /* Logic to determine whether or not we are on the first position in the
204 #define First_Position_In_Current_Field(form) \
205 (((form)->currow==0) && ((form)->curcol==0))
207 #define Minimum(a,b) (((a)<=(b)) ? (a) : (b))
208 #define Maximum(a,b) (((a)>=(b)) ? (a) : (b))
210 /*----------------------------------------------------------------------------
212 --------------------------------------------------------------------------*/
213 static FIELD_CELL myBLANK = BLANK;
214 static FIELD_CELL myZEROS;
218 check_pos(FORM *form, int lineno)
224 getyx(form->w, y, x);
225 if (y != form->currow || x != form->curcol)
227 T(("CHECKPOS %s@%d have position %d,%d vs want %d,%d",
230 form->currow, form->curcol));
234 #define CHECKPOS(form) check_pos(form, __LINE__)
236 #define CHECKPOS(form) /* nothing */
239 /*----------------------------------------------------------------------------
240 Wide-character special functions
241 --------------------------------------------------------------------------*/
242 #if USE_WIDEC_SUPPORT
243 /* add like waddnstr, but using cchar_t* rather than char*
246 wide_waddnstr(WINDOW *w, const cchar_t *s, int n)
252 if ((rc = wadd_wch(w, s)) != OK)
259 /* insert like winsnstr, but using cchar_t* rather than char*
261 * X/Open Curses has no close equivalent; inserts are done only with wchar_t
265 wide_winsnstr(WINDOW *w, const cchar_t *s, int n)
273 if ((code = wins_wch(w, s++)) != OK)
275 if ((code = wmove(w, y, x + 1)) != OK)
281 /* retrieve like winnstr, but using cchar_t*, rather than char*.
283 * X/Open Curses' closest equivalent, win_wchnstr(), is inconsistent with
284 * winnstr(), since it returns OK rather than the number of items transferred.
287 wide_winnstr(WINDOW *w, cchar_t *s, int n)
291 win_wchnstr(w, s, n);
293 * This function is used to extract the text only from the window.
294 * Strip attributes and color from the string so they will not be added
295 * back when copying the string to the window.
297 for (x = 0; x < n; ++x)
299 RemAttr(s[x], A_ATTRIBUTES);
306 * Returns the column of the base of the given cell.
309 cell_base(WINDOW *win, int y, int x)
313 while (LEGALYX(win, y, x))
315 cchar_t *data = &(win->_line[y].text[x]);
317 if (isWidecBase(CHDEREF(data)) || !isWidecExt(CHDEREF(data)))
328 * Returns the number of columns needed for the given cell in a window.
331 cell_width(WINDOW *win, int y, int x)
335 if (LEGALYX(win, y, x))
337 cchar_t *data = &(win->_line[y].text[x]);
339 if (isWidecExt(CHDEREF(data)))
341 /* recur, providing the number of columns to the next character */
342 result = cell_width(win, y, x - 1);
346 result = wcwidth(CharOf(CHDEREF(data)));
353 * There is no wide-character function such as wdel_wch(), so we must find
354 * all of the cells that comprise a multi-column character and delete them
358 delete_char(FORM *form)
360 int cells = cell_width(form->w, form->currow, form->curcol);
362 form->curcol = cell_base(form->w, form->currow, form->curcol);
363 wmove(form->w, form->currow, form->curcol);
369 #define DeleteChar(form) delete_char(form)
371 #define DeleteChar(form) \
372 wmove((form)->w, (form)->currow, (form)->curcol), \
376 /*---------------------------------------------------------------------------
377 | Facility : libnform
378 | Function : static char *Get_Start_Of_Data(char * buf, int blen)
380 | Description : Return pointer to first non-blank position in buffer.
381 | If buffer is empty return pointer to buffer itself.
383 | Return Values : Pointer to first non-blank position in buffer
384 +--------------------------------------------------------------------------*/
385 NCURSES_INLINE static FIELD_CELL *
386 Get_Start_Of_Data(FIELD_CELL *buf, int blen)
389 FIELD_CELL *end = &buf[blen];
391 assert(buf && blen >= 0);
392 while ((p < end) && ISBLANK(*p))
394 return ((p == end) ? buf : p);
397 /*---------------------------------------------------------------------------
398 | Facility : libnform
399 | Function : static char *After_End_Of_Data(char * buf, int blen)
401 | Description : Return pointer after last non-blank position in buffer.
402 | If buffer is empty, return pointer to buffer itself.
404 | Return Values : Pointer to position after last non-blank position in
406 +--------------------------------------------------------------------------*/
407 NCURSES_INLINE static FIELD_CELL *
408 After_End_Of_Data(FIELD_CELL *buf, int blen)
410 FIELD_CELL *p = &buf[blen];
412 assert(buf && blen >= 0);
413 while ((p > buf) && ISBLANK(p[-1]))
418 /*---------------------------------------------------------------------------
419 | Facility : libnform
420 | Function : static char *Get_First_Whitespace_Character(
421 | char * buf, int blen)
423 | Description : Position to the first whitespace character.
425 | Return Values : Pointer to first whitespace character in buffer.
426 +--------------------------------------------------------------------------*/
427 NCURSES_INLINE static FIELD_CELL *
428 Get_First_Whitespace_Character(FIELD_CELL *buf, int blen)
431 FIELD_CELL *end = &p[blen];
433 assert(buf && blen >= 0);
434 while ((p < end) && !ISBLANK(*p))
436 return ((p == end) ? buf : p);
439 /*---------------------------------------------------------------------------
440 | Facility : libnform
441 | Function : static char *After_Last_Whitespace_Character(
442 | char * buf, int blen)
444 | Description : Get the position after the last whitespace character.
446 | Return Values : Pointer to position after last whitespace character in
448 +--------------------------------------------------------------------------*/
449 NCURSES_INLINE static FIELD_CELL *
450 After_Last_Whitespace_Character(FIELD_CELL *buf, int blen)
452 FIELD_CELL *p = &buf[blen];
454 assert(buf && blen >= 0);
455 while ((p > buf) && !ISBLANK(p[-1]))
460 /* Set this to 1 to use the div_t version. This is a good idea if your
461 compiler has an intrinsic div() support. Unfortunately GNU-C has it
463 N.B.: This only works if form->curcol follows immediately form->currow
464 and both are of type int.
466 #define USE_DIV_T (0)
468 /*---------------------------------------------------------------------------
469 | Facility : libnform
470 | Function : static void Adjust_Cursor_Position(
471 | FORM * form, const char * pos)
473 | Description : Set current row and column of the form to values
474 | corresponding to the buffer position.
477 +--------------------------------------------------------------------------*/
478 NCURSES_INLINE static void
479 Adjust_Cursor_Position(FORM *form, const FIELD_CELL *pos)
484 field = form->current;
485 assert(pos >= field->buf && field->dcols > 0);
486 idx = (int)(pos - field->buf);
488 *((div_t *) & (form->currow)) = div(idx, field->dcols);
490 form->currow = idx / field->dcols;
491 form->curcol = idx - field->cols * form->currow;
493 if (field->drows < form->currow)
497 /*---------------------------------------------------------------------------
498 | Facility : libnform
499 | Function : static void Buffer_To_Window(
500 | const FIELD * field,
503 | Description : Copy the buffer to the window. If it is a multi-line
504 | field, the buffer is split to the lines of the
505 | window without any editing.
508 +--------------------------------------------------------------------------*/
510 Buffer_To_Window(const FIELD *field, WINDOW *win)
518 assert(win && field);
521 width = getmaxx(win);
522 height = getmaxy(win);
524 for (row = 0, pBuffer = field->buf;
526 row++, pBuffer += width)
528 if ((len = (int)(After_End_Of_Data(pBuffer, width) - pBuffer)) > 0)
531 myADDNSTR(win, pBuffer, len);
537 /*---------------------------------------------------------------------------
538 | Facility : libnform
539 | Function : void _nc_get_fieldbuffer(
544 | Description : Copy the content of the window into the buffer.
545 | The multiple lines of a window are simply
546 | concatenated into the buffer. Pad characters in
547 | the window will be replaced by blanks in the buffer.
550 +--------------------------------------------------------------------------*/
552 _nc_get_fieldbuffer(FORM *form, FIELD *field, FIELD_CELL *buf)
560 assert(form && field && buf);
567 height = getmaxy(win);
569 for (row = 0; (row < height) && (row < field->drows); row++)
572 len += myINNSTR(win, p + len, field->dcols);
576 /* replace visual padding character by blanks in buffer */
581 for (i = 0; i < len; i++, p++)
583 if ((unsigned long)CharOf(*p) == ChCharOf(pad)
584 #if USE_WIDEC_SUPPORT
593 /*---------------------------------------------------------------------------
594 | Facility : libnform
595 | Function : static void Window_To_Buffer(
599 | Description : Copy the content of the window into the buffer.
600 | The multiple lines of a window are simply
601 | concatenated into the buffer. Pad characters in
602 | the window will be replaced by blanks in the buffer.
605 +--------------------------------------------------------------------------*/
607 Window_To_Buffer(FORM *form, FIELD *field)
609 _nc_get_fieldbuffer(form, field, field->buf);
612 /*---------------------------------------------------------------------------
613 | Facility : libnform
614 | Function : static void Synchronize_Buffer(FORM * form)
616 | Description : If there was a change, copy the content of the
617 | window into the buffer, so the buffer is synchronized
618 | with the windows content. We have to indicate that the
619 | buffer needs validation due to the change.
622 +--------------------------------------------------------------------------*/
623 NCURSES_INLINE static void
624 Synchronize_Buffer(FORM *form)
626 if (form->status & _WINDOW_MODIFIED)
628 ClrStatus(form, _WINDOW_MODIFIED);
629 SetStatus(form, _FCHECK_REQUIRED);
630 Window_To_Buffer(form, form->current);
631 wmove(form->w, form->currow, form->curcol);
635 /*---------------------------------------------------------------------------
636 | Facility : libnform
637 | Function : static bool Field_Grown( FIELD *field, int amount)
639 | Description : This function is called for growable dynamic fields
640 | only. It has to increase the buffers and to allocate
641 | a new window for this field.
642 | This function has the side effect to set a new
643 | field-buffer pointer, the dcols and drows values
644 | as well as a new current Window for the field.
646 | Return Values : TRUE - field successfully increased
647 | FALSE - there was some error
648 +--------------------------------------------------------------------------*/
650 Field_Grown(FIELD *field, int amount)
654 if (field && Growable(field))
656 bool single_line_field = Single_Line_Field(field);
657 int old_buflen = Buffer_Length(field);
659 int old_dcols = field->dcols;
660 int old_drows = field->drows;
661 FIELD_CELL *oldbuf = field->buf;
665 FORM *form = field->form;
666 bool need_visual_update = ((form != (FORM *)0) &&
667 (form->status & _POSTED) &&
668 (form->current == field));
670 if (need_visual_update)
671 Synchronize_Buffer(form);
673 if (single_line_field)
675 growth = field->cols * amount;
677 growth = Minimum(field->maxgrow - field->dcols, growth);
678 field->dcols += growth;
679 if (field->dcols == field->maxgrow)
680 ClrStatus(field, _MAY_GROW);
684 growth = (field->rows + field->nrow) * amount;
686 growth = Minimum(field->maxgrow - field->drows, growth);
687 field->drows += growth;
688 if (field->drows == field->maxgrow)
689 ClrStatus(field, _MAY_GROW);
691 /* drows, dcols changed, so we get really the new buffer length */
692 new_buflen = Buffer_Length(field);
693 newbuf = (FIELD_CELL *)malloc(Total_Buffer_Size(field));
696 /* restore to previous state */
697 field->dcols = old_dcols;
698 field->drows = old_drows;
699 if ((single_line_field && (field->dcols != field->maxgrow)) ||
700 (!single_line_field && (field->drows != field->maxgrow)))
701 SetStatus(field, _MAY_GROW);
705 /* Copy all the buffers. This is the reason why we can't just use
712 result = TRUE; /* allow sharing of recovery on failure */
714 T((T_CREATE("fieldcell %p"), (void *)newbuf));
716 for (i = 0; i <= field->nbuf; i++)
718 new_bp = Address_Of_Nth_Buffer(field, i);
719 old_bp = oldbuf + i * (1 + old_buflen);
720 for (j = 0; j < old_buflen; ++j)
721 new_bp[j] = old_bp[j];
722 while (j < new_buflen)
723 new_bp[j++] = myBLANK;
724 new_bp[new_buflen] = myZEROS;
727 #if USE_WIDEC_SUPPORT && NCURSES_EXT_FUNCS
728 if (wresize(field->working, 1, Buffer_Length(field) + 1) == ERR)
732 if (need_visual_update && result)
734 WINDOW *new_window = newpad(field->drows, field->dcols);
738 assert(form != (FORM *)0);
741 form->w = new_window;
742 Set_Field_Window_Attributes(field, form->w);
744 Buffer_To_Window(field, form->w);
746 wmove(form->w, form->currow, form->curcol);
755 /* reflect changes in linked fields */
756 if (field != field->link)
760 for (linked_field = field->link;
761 linked_field != field;
762 linked_field = linked_field->link)
764 linked_field->buf = field->buf;
765 linked_field->drows = field->drows;
766 linked_field->dcols = field->dcols;
772 /* restore old state */
773 field->dcols = old_dcols;
774 field->drows = old_drows;
776 if ((single_line_field &&
777 (field->dcols != field->maxgrow)) ||
778 (!single_line_field &&
779 (field->drows != field->maxgrow)))
780 SetStatus(field, _MAY_GROW);
788 #ifdef NCURSES_MOUSE_VERSION
789 /*---------------------------------------------------------------------------
790 | Facility : libnform
791 | Function : int Field_encloses(FIELD *field, int ry, int rx)
793 | Description : Check if the given coordinates lie within the given field.
795 | Return Values : E_OK - success
796 | E_BAD_ARGUMENT - invalid form pointer
797 | E_SYSTEM_ERROR - form has no current field or
799 +--------------------------------------------------------------------------*/
801 Field_encloses(FIELD *field, int ry, int rx)
803 T((T_CALLED("Field_encloses(%p)"), (void *)field));
806 && (field->frow + field->rows) > ry
808 && (field->fcol + field->cols) > rx)
812 RETURN(E_INVALID_FIELD);
816 /*---------------------------------------------------------------------------
817 | Facility : libnform
818 | Function : int _nc_Position_Form_Cursor(FORM * form)
820 | Description : Position the cursor in the window for the current
821 | field to be in sync. with the currow and curcol
824 | Return Values : E_OK - success
825 | E_BAD_ARGUMENT - invalid form pointer
826 | E_SYSTEM_ERROR - form has no current field or
828 +--------------------------------------------------------------------------*/
830 _nc_Position_Form_Cursor(FORM *form)
836 return (E_BAD_ARGUMENT);
838 if (!form->w || !form->current)
839 return (E_SYSTEM_ERROR);
841 field = form->current;
842 formwin = Get_Form_Window(form);
844 wmove(form->w, form->currow, form->curcol);
845 if (Has_Invisible_Parts(field))
847 /* in this case fieldwin isn't derived from formwin, so we have
848 to move the cursor in formwin by hand... */
850 field->frow + form->currow - form->toprow,
851 field->fcol + form->curcol - form->begincol);
859 /*---------------------------------------------------------------------------
860 | Facility : libnform
861 | Function : int _nc_Refresh_Current_Field(FORM * form)
863 | Description : Propagate the changes in the field's window to the
864 | window of the form.
866 | Return Values : E_OK - on success
867 | E_BAD_ARGUMENT - invalid form pointer
868 | E_SYSTEM_ERROR - general error
869 +--------------------------------------------------------------------------*/
870 static bool move_after_insert = TRUE;
872 _nc_Refresh_Current_Field(FORM *form)
878 T((T_CALLED("_nc_Refresh_Current_Field(%p)"), (void *)form));
881 RETURN(E_BAD_ARGUMENT);
883 if (!form->w || !form->current)
884 RETURN(E_SYSTEM_ERROR);
886 field = form->current;
887 formwin = Get_Form_Window(form);
889 is_public = Field_Has_Option(field, O_PUBLIC);
891 if (Is_Scroll_Field(field))
893 /* Again, in this case the fieldwin isn't derived from formwin,
894 so we have to perform a copy operation. */
895 if (Single_Line_Field(field))
897 /* horizontal scrolling */
898 if (form->curcol < form->begincol)
899 form->begincol = form->curcol;
902 if (form->curcol >= (form->begincol + field->cols))
903 form->begincol = form->curcol - field->cols
904 + (move_after_insert ? 1 : 0);
914 field->cols + field->fcol - 1,
919 /* A multi-line, i.e. vertical scrolling field */
920 int row_after_bottom, first_modified_row, first_unmodified_row;
922 if (field->drows > field->rows)
924 row_after_bottom = form->toprow + field->rows;
925 if (form->currow < form->toprow)
927 form->toprow = form->currow;
928 SetStatus(field, _NEWTOP);
930 if (form->currow >= row_after_bottom)
932 form->toprow = form->currow - field->rows + 1;
933 SetStatus(field, _NEWTOP);
935 if (field->status & _NEWTOP)
937 /* means we have to copy whole range */
938 first_modified_row = form->toprow;
939 first_unmodified_row = first_modified_row + field->rows;
940 ClrStatus(field, _NEWTOP);
944 /* we try to optimize : finding the range of touched
946 first_modified_row = form->toprow;
947 while (first_modified_row < row_after_bottom)
949 if (is_linetouched(form->w, first_modified_row))
951 first_modified_row++;
953 first_unmodified_row = first_modified_row;
954 while (first_unmodified_row < row_after_bottom)
956 if (!is_linetouched(form->w, first_unmodified_row))
958 first_unmodified_row++;
964 first_modified_row = form->toprow;
965 first_unmodified_row = first_modified_row + field->rows;
967 if (first_unmodified_row != first_modified_row && is_public)
972 field->frow + first_modified_row - form->toprow,
974 field->frow + first_unmodified_row - form->toprow - 1,
975 field->cols + field->fcol - 1,
983 /* if the field-window is simply a derived window, i.e. contains no
984 * invisible parts, the whole thing is trivial
990 returnCode(_nc_Position_Form_Cursor(form));
993 /*---------------------------------------------------------------------------
994 | Facility : libnform
995 | Function : static void Perform_Justification(
999 | Description : Output field with requested justification
1002 +--------------------------------------------------------------------------*/
1004 Perform_Justification(FIELD *field, WINDOW *win)
1010 bp = (Field_Has_Option(field, O_NO_LEFT_STRIP)
1012 : Get_Start_Of_Data(field->buf, Buffer_Length(field)));
1013 len = (int)(After_End_Of_Data(field->buf, Buffer_Length(field)) - bp);
1017 assert(win && (field->drows == 1));
1019 if (field->cols - len >= 0)
1020 switch (field->just)
1024 case JUSTIFY_CENTER:
1025 col = (field->cols - len) / 2;
1028 col = field->cols - len;
1035 myADDNSTR(win, bp, len);
1039 /*---------------------------------------------------------------------------
1040 | Facility : libnform
1041 | Function : static void Undo_Justification(
1045 | Description : Display field without any justification, i.e.
1049 +--------------------------------------------------------------------------*/
1051 Undo_Justification(FIELD *field, WINDOW *win)
1059 bp = (Field_Has_Option(field, O_NO_LEFT_STRIP)
1061 : Get_Start_Of_Data(field->buf, Buffer_Length(field)));
1062 len = (int)(After_End_Of_Data(field->buf, Buffer_Length(field)) - bp);
1068 myADDNSTR(win, bp, len);
1073 /*---------------------------------------------------------------------------
1074 | Facility : libnform
1075 | Function : static bool Check_Char(FORM *form,
1079 | TypeArgument *argp)
1081 | Description : Perform a single character check for character ch
1082 | according to the fieldtype instance.
1084 | Return Values : TRUE - Character is valid
1085 | FALSE - Character is invalid
1086 +--------------------------------------------------------------------------*/
1088 Check_Char(FORM *form,
1096 if (typ->status & _LINKED_TYPE)
1100 Check_Char(form, field, typ->left, ch, argp->left) ||
1101 Check_Char(form, field, typ->right, ch, argp->right));
1105 #if NCURSES_INTEROP_FUNCS
1106 if (typ->charcheck.occheck)
1108 if (typ->status & _GENERIC)
1109 return typ->charcheck.gccheck(ch, form, field, (void *)argp);
1111 return typ->charcheck.occheck(ch, (void *)argp);
1115 return typ->ccheck(ch, (void *)argp);
1119 return (!iscntrl(UChar(ch)) ? TRUE : FALSE);
1122 /*---------------------------------------------------------------------------
1123 | Facility : libnform
1124 | Function : static int Display_Or_Erase_Field(
1128 | Description : Create a subwindow for the field and display the
1129 | buffer contents (apply justification if required)
1130 | or simply erase the field.
1132 | Return Values : E_OK - on success
1133 | E_SYSTEM_ERROR - some error (typical no memory)
1134 +--------------------------------------------------------------------------*/
1136 Display_Or_Erase_Field(FIELD *field, bool bEraseFlag)
1142 return E_SYSTEM_ERROR;
1144 fwin = Get_Form_Window(field->form);
1146 field->rows, field->cols, field->frow, field->fcol);
1149 return E_SYSTEM_ERROR;
1152 if (Field_Has_Option(field, O_VISIBLE))
1154 Set_Field_Window_Attributes(field, win);
1158 (void)wattrset(win, (int)WINDOW_ATTRS(fwin));
1165 if (Field_Has_Option(field, O_PUBLIC))
1167 if (Justification_Allowed(field))
1168 Perform_Justification(field, win);
1170 Buffer_To_Window(field, win);
1172 ClrStatus(field, _NEWTOP);
1179 /* Macros to preset the bEraseFlag */
1180 #define Display_Field(field) Display_Or_Erase_Field(field,FALSE)
1181 #define Erase_Field(field) Display_Or_Erase_Field(field,TRUE)
1183 /*---------------------------------------------------------------------------
1184 | Facility : libnform
1185 | Function : static int Synchronize_Field(FIELD * field)
1187 | Description : Synchronize the windows content with the value in
1190 | Return Values : E_OK - success
1191 | E_BAD_ARGUMENT - invalid field pointer
1192 | E_SYSTEM_ERROR - some severe basic error
1193 +--------------------------------------------------------------------------*/
1195 Synchronize_Field(FIELD *field)
1201 return (E_BAD_ARGUMENT);
1203 if (((form = field->form) != (FORM *)0)
1204 && Field_Really_Appears(field))
1206 if (field == form->current)
1208 form->currow = form->curcol = form->toprow = form->begincol = 0;
1211 if ((Field_Has_Option(field, O_PUBLIC)) && Justification_Allowed(field))
1212 Undo_Justification(field, form->w);
1214 Buffer_To_Window(field, form->w);
1216 SetStatus(field, _NEWTOP);
1217 res = _nc_Refresh_Current_Field(form);
1220 res = Display_Field(field);
1222 SetStatus(field, _CHANGED);
1226 /*---------------------------------------------------------------------------
1227 | Facility : libnform
1228 | Function : static int Synchronize_Linked_Fields(FIELD * field)
1230 | Description : Propagate the Synchronize_Field function to all linked
1231 | fields. The first error that occurs in the sequence
1232 | of updates is the return value.
1234 | Return Values : E_OK - success
1235 | E_BAD_ARGUMENT - invalid field pointer
1236 | E_SYSTEM_ERROR - some severe basic error
1237 +--------------------------------------------------------------------------*/
1239 Synchronize_Linked_Fields(FIELD *field)
1241 FIELD *linked_field;
1246 return (E_BAD_ARGUMENT);
1249 return (E_SYSTEM_ERROR);
1251 for (linked_field = field->link;
1252 (linked_field != field) && (linked_field != 0);
1253 linked_field = linked_field->link)
1255 if (((syncres = Synchronize_Field(linked_field)) != E_OK) &&
1262 /*---------------------------------------------------------------------------
1263 | Facility : libnform
1264 | Function : int _nc_Synchronize_Attributes(FIELD * field)
1266 | Description : If a field's visual attributes have changed, this
1267 | routine is called to propagate those changes to the
1270 | Return Values : E_OK - success
1271 | E_BAD_ARGUMENT - invalid field pointer
1272 | E_SYSTEM_ERROR - some severe basic error
1273 +--------------------------------------------------------------------------*/
1275 _nc_Synchronize_Attributes(FIELD *field)
1281 T((T_CALLED("_nc_Synchronize_Attributes(%p)"), (void *)field));
1284 returnCode(E_BAD_ARGUMENT);
1286 CHECKPOS(field->form);
1287 if (((form = field->form) != (FORM *)0)
1288 && Field_Really_Appears(field))
1290 if (form->current == field)
1292 Synchronize_Buffer(form);
1293 Set_Field_Window_Attributes(field, form->w);
1295 wmove(form->w, form->currow, form->curcol);
1297 if (Field_Has_Option(field, O_PUBLIC))
1299 if (Justification_Allowed(field))
1300 Undo_Justification(field, form->w);
1302 Buffer_To_Window(field, form->w);
1306 formwin = Get_Form_Window(form);
1307 copywin(form->w, formwin,
1309 field->frow, field->fcol,
1310 field->frow + field->rows - 1,
1311 field->fcol + field->cols - 1, 0);
1313 Buffer_To_Window(field, form->w);
1314 SetStatus(field, _NEWTOP); /* fake refresh to paint all */
1315 _nc_Refresh_Current_Field(form);
1320 res = Display_Field(field);
1327 /*---------------------------------------------------------------------------
1328 | Facility : libnform
1329 | Function : int _nc_Synchronize_Options(FIELD * field,
1330 | Field_Options newopts)
1332 | Description : If a field's options have changed, this routine is
1333 | called to propagate these changes to the screen and
1334 | to really change the behavior of the field.
1336 | Return Values : E_OK - success
1337 | E_BAD_ARGUMENT - invalid field pointer
1338 | E_CURRENT - field is the current one
1339 | E_SYSTEM_ERROR - some severe basic error
1340 +--------------------------------------------------------------------------*/
1342 _nc_Synchronize_Options(FIELD *field, Field_Options newopts)
1344 Field_Options oldopts;
1345 Field_Options changed_opts;
1349 T((T_CALLED("_nc_Synchronize_Options(%p,%#x)"), (void *)field, newopts));
1352 returnCode(E_BAD_ARGUMENT);
1354 oldopts = field->opts;
1355 changed_opts = oldopts ^ newopts;
1356 field->opts = newopts;
1361 if (form->status & _POSTED)
1363 if (form->current == field)
1365 field->opts = oldopts;
1366 returnCode(E_CURRENT);
1368 if (form->curpage == field->page)
1370 if ((unsigned)changed_opts & O_VISIBLE)
1372 if ((unsigned)newopts & O_VISIBLE)
1373 res = Display_Field(field);
1375 res = Erase_Field(field);
1379 if (((unsigned)changed_opts & O_PUBLIC) &&
1380 ((unsigned)newopts & O_VISIBLE))
1381 res = Display_Field(field);
1387 if ((unsigned)changed_opts & O_STATIC)
1389 bool single_line_field = Single_Line_Field(field);
1392 if ((unsigned)newopts & O_STATIC)
1394 /* the field becomes now static */
1395 ClrStatus(field, _MAY_GROW);
1396 /* if actually we have no hidden columns, justification may
1398 if (single_line_field &&
1399 (field->cols == field->dcols) &&
1400 (field->just != NO_JUSTIFICATION) &&
1401 Field_Really_Appears(field))
1403 res2 = Display_Field(field);
1408 /* field is no longer static */
1409 if ((field->maxgrow == 0) ||
1410 (single_line_field && (field->dcols < field->maxgrow)) ||
1411 (!single_line_field && (field->drows < field->maxgrow)))
1413 SetStatus(field, _MAY_GROW);
1414 /* a field with justification now changes its behavior,
1415 so we must redisplay it */
1416 if (single_line_field &&
1417 (field->just != NO_JUSTIFICATION) &&
1418 Field_Really_Appears(field))
1420 res2 = Display_Field(field);
1432 * Removes the focus from the current field of the form.
1435 _nc_Unset_Current_Field(FORM *form)
1437 FIELD *field = form->current;
1439 _nc_Refresh_Current_Field(form);
1440 if (Field_Has_Option(field, O_PUBLIC))
1442 if (field->drows > field->rows)
1444 if (form->toprow == 0)
1445 ClrStatus(field, _NEWTOP);
1447 SetStatus(field, _NEWTOP);
1451 if (Justification_Allowed(field))
1453 Window_To_Buffer(form, field);
1455 Perform_Justification(field, form->w);
1456 if (Field_Has_Option(field, O_DYNAMIC_JUSTIFY) &&
1457 (form->w->_parent == 0))
1460 Get_Form_Window(form),
1466 field->cols + field->fcol - 1,
1468 wsyncup(Get_Form_Window(form));
1478 form->w = (WINDOW *)0;
1482 /*---------------------------------------------------------------------------
1483 | Facility : libnform
1484 | Function : int _nc_Set_Current_Field(FORM * form,
1487 | Description : Make the newfield the new current field.
1489 | Return Values : E_OK - success
1490 | E_BAD_ARGUMENT - invalid form or field pointer
1491 | E_SYSTEM_ERROR - some severe basic error
1492 | E_NOT_CONNECTED - no fields are connected to the form
1493 +--------------------------------------------------------------------------*/
1495 _nc_Set_Current_Field(FORM *form, FIELD *newfield)
1500 T((T_CALLED("_nc_Set_Current_Field(%p,%p)"), (void *)form, (void *)newfield));
1502 if (!form || !newfield || (newfield->form != form))
1503 returnCode(E_BAD_ARGUMENT);
1505 if ((form->status & _IN_DRIVER))
1506 returnCode(E_BAD_STATE);
1509 returnCode(E_NOT_CONNECTED);
1511 field = form->current;
1513 if ((field != newfield) ||
1514 !(form->status & _POSTED))
1516 if (field && (form->w) &&
1517 (Field_Has_Option(field, O_VISIBLE)) &&
1518 (field->form->curpage == field->page))
1519 _nc_Unset_Current_Field(form);
1523 if (Has_Invisible_Parts(field))
1524 new_window = newpad(field->drows, field->dcols);
1526 new_window = derwin(Get_Form_Window(form),
1527 field->rows, field->cols, field->frow, field->fcol);
1530 returnCode(E_SYSTEM_ERROR);
1532 form->current = field;
1536 form->w = new_window;
1538 ClrStatus(form, _WINDOW_MODIFIED);
1539 Set_Field_Window_Attributes(field, form->w);
1541 if (Has_Invisible_Parts(field))
1544 Buffer_To_Window(field, form->w);
1548 if (Justification_Allowed(field))
1551 Undo_Justification(field, form->w);
1556 untouchwin(form->w);
1559 form->currow = form->curcol = form->toprow = form->begincol = 0;
1563 /*----------------------------------------------------------------------------
1564 Intra-Field Navigation routines
1565 --------------------------------------------------------------------------*/
1567 /*---------------------------------------------------------------------------
1568 | Facility : libnform
1569 | Function : static int IFN_Next_Character(FORM * form)
1571 | Description : Move to the next character in the field. In a multi-line
1572 | field this wraps at the end of the line.
1574 | Return Values : E_OK - success
1575 | E_REQUEST_DENIED - at the rightmost position
1576 +--------------------------------------------------------------------------*/
1578 IFN_Next_Character(FORM *form)
1580 FIELD *field = form->current;
1581 int step = myWCWIDTH(form->w, form->currow, form->curcol);
1583 T((T_CALLED("IFN_Next_Character(%p)"), (void *)form));
1584 if ((form->curcol += step) == field->dcols)
1586 if ((++(form->currow)) == field->drows)
1588 #if GROW_IF_NAVIGATE
1589 if (!Single_Line_Field(field) && Field_Grown(field, 1))
1596 #if GROW_IF_NAVIGATE
1597 if (Single_Line_Field(field) && Field_Grown(field, 1))
1600 form->curcol -= step;
1601 returnCode(E_REQUEST_DENIED);
1608 /*---------------------------------------------------------------------------
1609 | Facility : libnform
1610 | Function : static int IFN_Previous_Character(FORM * form)
1612 | Description : Move to the previous character in the field. In a
1613 | multi-line field this wraps and the beginning of the
1616 | Return Values : E_OK - success
1617 | E_REQUEST_DENIED - at the leftmost position
1618 +--------------------------------------------------------------------------*/
1620 IFN_Previous_Character(FORM *form)
1622 int amount = myWCWIDTH(form->w, form->currow, form->curcol - 1);
1623 int oldcol = form->curcol;
1625 T((T_CALLED("IFN_Previous_Character(%p)"), (void *)form));
1626 if ((form->curcol -= amount) < 0)
1628 if ((--(form->currow)) < 0)
1631 form->curcol = oldcol;
1632 returnCode(E_REQUEST_DENIED);
1634 form->curcol = form->current->dcols - 1;
1639 /*---------------------------------------------------------------------------
1640 | Facility : libnform
1641 | Function : static int IFN_Next_Line(FORM * form)
1643 | Description : Move to the beginning of the next line in the field
1645 | Return Values : E_OK - success
1646 | E_REQUEST_DENIED - at the last line
1647 +--------------------------------------------------------------------------*/
1649 IFN_Next_Line(FORM *form)
1651 FIELD *field = form->current;
1653 T((T_CALLED("IFN_Next_Line(%p)"), (void *)form));
1654 if ((++(form->currow)) == field->drows)
1656 #if GROW_IF_NAVIGATE
1657 if (!Single_Line_Field(field) && Field_Grown(field, 1))
1661 returnCode(E_REQUEST_DENIED);
1667 /*---------------------------------------------------------------------------
1668 | Facility : libnform
1669 | Function : static int IFN_Previous_Line(FORM * form)
1671 | Description : Move to the beginning of the previous line in the field
1673 | Return Values : E_OK - success
1674 | E_REQUEST_DENIED - at the first line
1675 +--------------------------------------------------------------------------*/
1677 IFN_Previous_Line(FORM *form)
1679 T((T_CALLED("IFN_Previous_Line(%p)"), (void *)form));
1680 if ((--(form->currow)) < 0)
1683 returnCode(E_REQUEST_DENIED);
1689 /*---------------------------------------------------------------------------
1690 | Facility : libnform
1691 | Function : static int IFN_Next_Word(FORM * form)
1693 | Description : Move to the beginning of the next word in the field.
1695 | Return Values : E_OK - success
1696 | E_REQUEST_DENIED - there is no next word
1697 +--------------------------------------------------------------------------*/
1699 IFN_Next_Word(FORM *form)
1701 FIELD *field = form->current;
1702 FIELD_CELL *bp = Address_Of_Current_Position_In_Buffer(form);
1706 T((T_CALLED("IFN_Next_Word(%p)"), (void *)form));
1708 /* We really need access to the data, so we have to synchronize */
1709 Synchronize_Buffer(form);
1711 /* Go to the first whitespace after the current position (including
1712 current position). This is then the starting point to look for the
1713 next non-blank data */
1714 s = Get_First_Whitespace_Character(bp, Buffer_Length(field) -
1715 (int)(bp - field->buf));
1717 /* Find the start of the next word */
1718 t = Get_Start_Of_Data(s, Buffer_Length(field) -
1719 (int)(s - field->buf));
1720 #if !FRIENDLY_PREV_NEXT_WORD
1722 returnCode(E_REQUEST_DENIED);
1726 Adjust_Cursor_Position(form, t);
1731 /*---------------------------------------------------------------------------
1732 | Facility : libnform
1733 | Function : static int IFN_Previous_Word(FORM * form)
1735 | Description : Move to the beginning of the previous word in the field.
1737 | Return Values : E_OK - success
1738 | E_REQUEST_DENIED - there is no previous word
1739 +--------------------------------------------------------------------------*/
1741 IFN_Previous_Word(FORM *form)
1743 FIELD *field = form->current;
1744 FIELD_CELL *bp = Address_Of_Current_Position_In_Buffer(form);
1749 T((T_CALLED("IFN_Previous_Word(%p)"), (void *)form));
1751 /* We really need access to the data, so we have to synchronize */
1752 Synchronize_Buffer(form);
1754 s = After_End_Of_Data(field->buf, (int)(bp - field->buf));
1755 /* s points now right after the last non-blank in the buffer before bp.
1756 If bp was in a word, s equals bp. In this case we must find the last
1757 whitespace in the buffer before bp and repeat the game to really find
1758 the previous word! */
1762 /* And next call now goes backward to look for the last whitespace
1763 before that, pointing right after this, so it points to the begin
1764 of the previous word.
1766 t = After_Last_Whitespace_Character(field->buf, (int)(s - field->buf));
1767 #if !FRIENDLY_PREV_NEXT_WORD
1769 returnCode(E_REQUEST_DENIED);
1773 /* and do it again, replacing bp by t */
1774 s = After_End_Of_Data(field->buf, (int)(t - field->buf));
1775 t = After_Last_Whitespace_Character(field->buf, (int)(s - field->buf));
1776 #if !FRIENDLY_PREV_NEXT_WORD
1778 returnCode(E_REQUEST_DENIED);
1781 Adjust_Cursor_Position(form, t);
1785 /*---------------------------------------------------------------------------
1786 | Facility : libnform
1787 | Function : static int IFN_Beginning_Of_Field(FORM * form)
1789 | Description : Place the cursor at the first non-pad character in
1792 | Return Values : E_OK - success
1793 +--------------------------------------------------------------------------*/
1795 IFN_Beginning_Of_Field(FORM *form)
1797 FIELD *field = form->current;
1799 T((T_CALLED("IFN_Beginning_Of_Field(%p)"), (void *)form));
1800 Synchronize_Buffer(form);
1801 Adjust_Cursor_Position(form,
1802 Get_Start_Of_Data(field->buf, Buffer_Length(field)));
1806 /*---------------------------------------------------------------------------
1807 | Facility : libnform
1808 | Function : static int IFN_End_Of_Field(FORM * form)
1810 | Description : Place the cursor after the last non-pad character in
1811 | the field. If the field occupies the last position in
1812 | the buffer, the cursor is positioned on the last
1815 | Return Values : E_OK - success
1816 +--------------------------------------------------------------------------*/
1818 IFN_End_Of_Field(FORM *form)
1820 FIELD *field = form->current;
1823 T((T_CALLED("IFN_End_Of_Field(%p)"), (void *)form));
1824 Synchronize_Buffer(form);
1825 pos = After_End_Of_Data(field->buf, Buffer_Length(field));
1826 if (pos == (field->buf + Buffer_Length(field)))
1828 Adjust_Cursor_Position(form, pos);
1832 /*---------------------------------------------------------------------------
1833 | Facility : libnform
1834 | Function : static int IFN_Beginning_Of_Line(FORM * form)
1836 | Description : Place the cursor on the first non-pad character in
1837 | the current line of the field.
1839 | Return Values : E_OK - success
1840 +--------------------------------------------------------------------------*/
1842 IFN_Beginning_Of_Line(FORM *form)
1844 FIELD *field = form->current;
1846 T((T_CALLED("IFN_Beginning_Of_Line(%p)"), (void *)form));
1847 Synchronize_Buffer(form);
1848 Adjust_Cursor_Position(form,
1849 Get_Start_Of_Data(Address_Of_Current_Row_In_Buffer(form),
1854 /*---------------------------------------------------------------------------
1855 | Facility : libnform
1856 | Function : static int IFN_End_Of_Line(FORM * form)
1858 | Description : Place the cursor after the last non-pad character in the
1859 | current line of the field. If the field occupies the
1860 | last column in the line, the cursor is positioned on the
1861 | last character of the line.
1863 | Return Values : E_OK - success
1864 +--------------------------------------------------------------------------*/
1866 IFN_End_Of_Line(FORM *form)
1868 FIELD *field = form->current;
1872 T((T_CALLED("IFN_End_Of_Line(%p)"), (void *)form));
1873 Synchronize_Buffer(form);
1874 bp = Address_Of_Current_Row_In_Buffer(form);
1875 pos = After_End_Of_Data(bp, field->dcols);
1876 if (pos == (bp + field->dcols))
1878 Adjust_Cursor_Position(form, pos);
1882 /*---------------------------------------------------------------------------
1883 | Facility : libnform
1884 | Function : static int IFN_Left_Character(FORM * form)
1886 | Description : Move one character to the left in the current line.
1887 | This doesn't cycle.
1889 | Return Values : E_OK - success
1890 | E_REQUEST_DENIED - already in first column
1891 +--------------------------------------------------------------------------*/
1893 IFN_Left_Character(FORM *form)
1895 int amount = myWCWIDTH(form->w, form->currow, form->curcol - 1);
1896 int oldcol = form->curcol;
1898 T((T_CALLED("IFN_Left_Character(%p)"), (void *)form));
1899 if ((form->curcol -= amount) < 0)
1901 form->curcol = oldcol;
1902 returnCode(E_REQUEST_DENIED);
1907 /*---------------------------------------------------------------------------
1908 | Facility : libnform
1909 | Function : static int IFN_Right_Character(FORM * form)
1911 | Description : Move one character to the right in the current line.
1912 | This doesn't cycle.
1914 | Return Values : E_OK - success
1915 | E_REQUEST_DENIED - already in last column
1916 +--------------------------------------------------------------------------*/
1918 IFN_Right_Character(FORM *form)
1920 int amount = myWCWIDTH(form->w, form->currow, form->curcol);
1921 int oldcol = form->curcol;
1923 T((T_CALLED("IFN_Right_Character(%p)"), (void *)form));
1924 if ((form->curcol += amount) >= form->current->dcols)
1926 #if GROW_IF_NAVIGATE
1927 FIELD *field = form->current;
1929 if (Single_Line_Field(field) && Field_Grown(field, 1))
1932 form->curcol = oldcol;
1933 returnCode(E_REQUEST_DENIED);
1938 /*---------------------------------------------------------------------------
1939 | Facility : libnform
1940 | Function : static int IFN_Up_Character(FORM * form)
1942 | Description : Move one line up. This doesn't cycle through the lines
1945 | Return Values : E_OK - success
1946 | E_REQUEST_DENIED - already in last column
1947 +--------------------------------------------------------------------------*/
1949 IFN_Up_Character(FORM *form)
1951 T((T_CALLED("IFN_Up_Character(%p)"), (void *)form));
1952 if ((--(form->currow)) < 0)
1955 returnCode(E_REQUEST_DENIED);
1960 /*---------------------------------------------------------------------------
1961 | Facility : libnform
1962 | Function : static int IFN_Down_Character(FORM * form)
1964 | Description : Move one line down. This doesn't cycle through the
1965 | lines of the field.
1967 | Return Values : E_OK - success
1968 | E_REQUEST_DENIED - already in last column
1969 +--------------------------------------------------------------------------*/
1971 IFN_Down_Character(FORM *form)
1973 FIELD *field = form->current;
1975 T((T_CALLED("IFN_Down_Character(%p)"), (void *)form));
1976 if ((++(form->currow)) == field->drows)
1978 #if GROW_IF_NAVIGATE
1979 if (!Single_Line_Field(field) && Field_Grown(field, 1))
1983 returnCode(E_REQUEST_DENIED);
1987 /*----------------------------------------------------------------------------
1988 END of Intra-Field Navigation routines
1989 --------------------------------------------------------------------------*/
1991 /*----------------------------------------------------------------------------
1992 Vertical scrolling helper routines
1993 --------------------------------------------------------------------------*/
1995 /*---------------------------------------------------------------------------
1996 | Facility : libnform
1997 | Function : static int VSC_Generic(FORM *form, int nlines)
1999 | Description : Scroll multi-line field forward (nlines>0) or
2000 | backward (nlines<0) this many lines.
2002 | Return Values : E_OK - success
2003 | E_REQUEST_DENIED - can't scroll
2004 +--------------------------------------------------------------------------*/
2006 VSC_Generic(FORM *form, int nlines)
2008 FIELD *field = form->current;
2009 int res = E_REQUEST_DENIED;
2010 int rows_to_go = (nlines > 0 ? nlines : -nlines);
2014 if ((rows_to_go + form->toprow) > (field->drows - field->rows))
2015 rows_to_go = (field->drows - field->rows - form->toprow);
2019 form->currow += rows_to_go;
2020 form->toprow += rows_to_go;
2026 if (rows_to_go > form->toprow)
2027 rows_to_go = form->toprow;
2031 form->currow -= rows_to_go;
2032 form->toprow -= rows_to_go;
2038 /*----------------------------------------------------------------------------
2039 End of Vertical scrolling helper routines
2040 --------------------------------------------------------------------------*/
2042 /*----------------------------------------------------------------------------
2043 Vertical scrolling routines
2044 --------------------------------------------------------------------------*/
2046 /*---------------------------------------------------------------------------
2047 | Facility : libnform
2048 | Function : static int Vertical_Scrolling(
2049 | int (* const fct) (FORM *),
2052 | Description : Performs the generic vertical scrolling routines.
2053 | This has to check for a multi-line field and to set
2054 | the _NEWTOP flag if scrolling really occurred.
2056 | Return Values : Propagated error code from low-level driver calls
2057 +--------------------------------------------------------------------------*/
2059 Vertical_Scrolling(int (*const fct) (FORM *), FORM *form)
2061 int res = E_REQUEST_DENIED;
2063 if (!Single_Line_Field(form->current))
2067 SetStatus(form->current, _NEWTOP);
2072 /*---------------------------------------------------------------------------
2073 | Facility : libnform
2074 | Function : static int VSC_Scroll_Line_Forward(FORM * form)
2076 | Description : Scroll multi-line field forward a line
2078 | Return Values : E_OK - success
2079 | E_REQUEST_DENIED - no data ahead
2080 +--------------------------------------------------------------------------*/
2082 VSC_Scroll_Line_Forward(FORM *form)
2084 T((T_CALLED("VSC_Scroll_Line_Forward(%p)"), (void *)form));
2085 returnCode(VSC_Generic(form, 1));
2088 /*---------------------------------------------------------------------------
2089 | Facility : libnform
2090 | Function : static int VSC_Scroll_Line_Backward(FORM * form)
2092 | Description : Scroll multi-line field backward a line
2094 | Return Values : E_OK - success
2095 | E_REQUEST_DENIED - no data behind
2096 +--------------------------------------------------------------------------*/
2098 VSC_Scroll_Line_Backward(FORM *form)
2100 T((T_CALLED("VSC_Scroll_Line_Backward(%p)"), (void *)form));
2101 returnCode(VSC_Generic(form, -1));
2104 /*---------------------------------------------------------------------------
2105 | Facility : libnform
2106 | Function : static int VSC_Scroll_Page_Forward(FORM * form)
2108 | Description : Scroll a multi-line field forward a page
2110 | Return Values : E_OK - success
2111 | E_REQUEST_DENIED - no data ahead
2112 +--------------------------------------------------------------------------*/
2114 VSC_Scroll_Page_Forward(FORM *form)
2116 T((T_CALLED("VSC_Scroll_Page_Forward(%p)"), (void *)form));
2117 returnCode(VSC_Generic(form, form->current->rows));
2120 /*---------------------------------------------------------------------------
2121 | Facility : libnform
2122 | Function : static int VSC_Scroll_Half_Page_Forward(FORM * form)
2124 | Description : Scroll a multi-line field forward half a page
2126 | Return Values : E_OK - success
2127 | E_REQUEST_DENIED - no data ahead
2128 +--------------------------------------------------------------------------*/
2130 VSC_Scroll_Half_Page_Forward(FORM *form)
2132 T((T_CALLED("VSC_Scroll_Half_Page_Forward(%p)"), (void *)form));
2133 returnCode(VSC_Generic(form, (form->current->rows + 1) / 2));
2136 /*---------------------------------------------------------------------------
2137 | Facility : libnform
2138 | Function : static int VSC_Scroll_Page_Backward(FORM * form)
2140 | Description : Scroll a multi-line field backward a page
2142 | Return Values : E_OK - success
2143 | E_REQUEST_DENIED - no data behind
2144 +--------------------------------------------------------------------------*/
2146 VSC_Scroll_Page_Backward(FORM *form)
2148 T((T_CALLED("VSC_Scroll_Page_Backward(%p)"), (void *)form));
2149 returnCode(VSC_Generic(form, -(form->current->rows)));
2152 /*---------------------------------------------------------------------------
2153 | Facility : libnform
2154 | Function : static int VSC_Scroll_Half_Page_Backward(FORM * form)
2156 | Description : Scroll a multi-line field backward half a page
2158 | Return Values : E_OK - success
2159 | E_REQUEST_DENIED - no data behind
2160 +--------------------------------------------------------------------------*/
2162 VSC_Scroll_Half_Page_Backward(FORM *form)
2164 T((T_CALLED("VSC_Scroll_Half_Page_Backward(%p)"), (void *)form));
2165 returnCode(VSC_Generic(form, -((form->current->rows + 1) / 2)));
2167 /*----------------------------------------------------------------------------
2168 End of Vertical scrolling routines
2169 --------------------------------------------------------------------------*/
2171 /*----------------------------------------------------------------------------
2172 Horizontal scrolling helper routines
2173 --------------------------------------------------------------------------*/
2175 /*---------------------------------------------------------------------------
2176 | Facility : libnform
2177 | Function : static int HSC_Generic(FORM *form, int ncolumns)
2179 | Description : Scroll single-line field forward (ncolumns>0) or
2180 | backward (ncolumns<0) this many columns.
2182 | Return Values : E_OK - success
2183 | E_REQUEST_DENIED - can't scroll
2184 +--------------------------------------------------------------------------*/
2186 HSC_Generic(FORM *form, int ncolumns)
2188 FIELD *field = form->current;
2189 int res = E_REQUEST_DENIED;
2190 int cols_to_go = (ncolumns > 0 ? ncolumns : -ncolumns);
2194 if ((cols_to_go + form->begincol) > (field->dcols - field->cols))
2195 cols_to_go = field->dcols - field->cols - form->begincol;
2199 form->curcol += cols_to_go;
2200 form->begincol += cols_to_go;
2206 if (cols_to_go > form->begincol)
2207 cols_to_go = form->begincol;
2211 form->curcol -= cols_to_go;
2212 form->begincol -= cols_to_go;
2218 /*----------------------------------------------------------------------------
2219 End of Horizontal scrolling helper routines
2220 --------------------------------------------------------------------------*/
2222 /*----------------------------------------------------------------------------
2223 Horizontal scrolling routines
2224 --------------------------------------------------------------------------*/
2226 /*---------------------------------------------------------------------------
2227 | Facility : libnform
2228 | Function : static int Horizontal_Scrolling(
2229 | int (* const fct) (FORM *),
2232 | Description : Performs the generic horizontal scrolling routines.
2233 | This has to check for a single-line field.
2235 | Return Values : Propagated error code from low-level driver calls
2236 +--------------------------------------------------------------------------*/
2238 Horizontal_Scrolling(int (*const fct) (FORM *), FORM *form)
2240 if (Single_Line_Field(form->current))
2243 return (E_REQUEST_DENIED);
2246 /*---------------------------------------------------------------------------
2247 | Facility : libnform
2248 | Function : static int HSC_Scroll_Char_Forward(FORM * form)
2250 | Description : Scroll single-line field forward a character
2252 | Return Values : E_OK - success
2253 | E_REQUEST_DENIED - no data ahead
2254 +--------------------------------------------------------------------------*/
2256 HSC_Scroll_Char_Forward(FORM *form)
2258 T((T_CALLED("HSC_Scroll_Char_Forward(%p)"), (void *)form));
2259 returnCode(HSC_Generic(form, 1));
2262 /*---------------------------------------------------------------------------
2263 | Facility : libnform
2264 | Function : static int HSC_Scroll_Char_Backward(FORM * form)
2266 | Description : Scroll single-line field backward a character
2268 | Return Values : E_OK - success
2269 | E_REQUEST_DENIED - no data behind
2270 +--------------------------------------------------------------------------*/
2272 HSC_Scroll_Char_Backward(FORM *form)
2274 T((T_CALLED("HSC_Scroll_Char_Backward(%p)"), (void *)form));
2275 returnCode(HSC_Generic(form, -1));
2278 /*---------------------------------------------------------------------------
2279 | Facility : libnform
2280 | Function : static int HSC_Horizontal_Line_Forward(FORM* form)
2282 | Description : Scroll single-line field forward a line
2284 | Return Values : E_OK - success
2285 | E_REQUEST_DENIED - no data ahead
2286 +--------------------------------------------------------------------------*/
2288 HSC_Horizontal_Line_Forward(FORM *form)
2290 T((T_CALLED("HSC_Horizontal_Line_Forward(%p)"), (void *)form));
2291 returnCode(HSC_Generic(form, form->current->cols));
2294 /*---------------------------------------------------------------------------
2295 | Facility : libnform
2296 | Function : static int HSC_Horizontal_Half_Line_Forward(FORM* form)
2298 | Description : Scroll single-line field forward half a line
2300 | Return Values : E_OK - success
2301 | E_REQUEST_DENIED - no data ahead
2302 +--------------------------------------------------------------------------*/
2304 HSC_Horizontal_Half_Line_Forward(FORM *form)
2306 T((T_CALLED("HSC_Horizontal_Half_Line_Forward(%p)"), (void *)form));
2307 returnCode(HSC_Generic(form, (form->current->cols + 1) / 2));
2310 /*---------------------------------------------------------------------------
2311 | Facility : libnform
2312 | Function : static int HSC_Horizontal_Line_Backward(FORM* form)
2314 | Description : Scroll single-line field backward a line
2316 | Return Values : E_OK - success
2317 | E_REQUEST_DENIED - no data behind
2318 +--------------------------------------------------------------------------*/
2320 HSC_Horizontal_Line_Backward(FORM *form)
2322 T((T_CALLED("HSC_Horizontal_Line_Backward(%p)"), (void *)form));
2323 returnCode(HSC_Generic(form, -(form->current->cols)));
2326 /*---------------------------------------------------------------------------
2327 | Facility : libnform
2328 | Function : static int HSC_Horizontal_Half_Line_Backward(FORM* form)
2330 | Description : Scroll single-line field backward half a line
2332 | Return Values : E_OK - success
2333 | E_REQUEST_DENIED - no data behind
2334 +--------------------------------------------------------------------------*/
2336 HSC_Horizontal_Half_Line_Backward(FORM *form)
2338 T((T_CALLED("HSC_Horizontal_Half_Line_Backward(%p)"), (void *)form));
2339 returnCode(HSC_Generic(form, -((form->current->cols + 1) / 2)));
2342 /*----------------------------------------------------------------------------
2343 End of Horizontal scrolling routines
2344 --------------------------------------------------------------------------*/
2346 /*----------------------------------------------------------------------------
2347 Helper routines for Field Editing
2348 --------------------------------------------------------------------------*/
2350 /*---------------------------------------------------------------------------
2351 | Facility : libnform
2352 | Function : static bool Is_There_Room_For_A_Line(FORM * form)
2354 | Description : Check whether or not there is enough room in the
2355 | buffer to enter a whole line.
2357 | Return Values : TRUE - there is enough space
2358 | FALSE - there is not enough space
2359 +--------------------------------------------------------------------------*/
2360 NCURSES_INLINE static bool
2361 Is_There_Room_For_A_Line(FORM *form)
2363 FIELD *field = form->current;
2364 FIELD_CELL *begin_of_last_line, *s;
2366 Synchronize_Buffer(form);
2367 begin_of_last_line = Address_Of_Row_In_Buffer(field, (field->drows - 1));
2368 s = After_End_Of_Data(begin_of_last_line, field->dcols);
2369 return ((s == begin_of_last_line) ? TRUE : FALSE);
2372 /*---------------------------------------------------------------------------
2373 | Facility : libnform
2374 | Function : static bool Is_There_Room_For_A_Char_In_Line(FORM * form)
2376 | Description : Checks whether or not there is room for a new character
2377 | in the current line.
2379 | Return Values : TRUE - there is room
2380 | FALSE - there is not enough room (line full)
2381 +--------------------------------------------------------------------------*/
2382 NCURSES_INLINE static bool
2383 Is_There_Room_For_A_Char_In_Line(FORM *form)
2385 int last_char_in_line;
2387 wmove(form->w, form->currow, form->current->dcols - 1);
2388 last_char_in_line = (int)(winch(form->w) & A_CHARTEXT);
2389 wmove(form->w, form->currow, form->curcol);
2390 return (((last_char_in_line == form->current->pad) ||
2391 is_blank(last_char_in_line)) ? TRUE : FALSE);
2394 #define There_Is_No_Room_For_A_Char_In_Line(f) \
2395 !Is_There_Room_For_A_Char_In_Line(f)
2397 /*---------------------------------------------------------------------------
2398 | Facility : libnform
2399 | Function : static int Insert_String(
2405 | Description : Insert the 'len' characters beginning at pointer 'txt'
2406 | into the 'row' of the 'form'. The insertion occurs
2407 | on the beginning of the row, all other characters are
2408 | moved to the right. After the text a pad character will
2409 | be inserted to separate the text from the rest. If
2410 | necessary the insertion moves characters on the next
2411 | line to make place for the requested insertion string.
2413 | Return Values : E_OK - success
2414 | E_REQUEST_DENIED -
2415 | E_SYSTEM_ERROR - system error
2416 +--------------------------------------------------------------------------*/
2418 Insert_String(FORM *form, int row, FIELD_CELL *txt, int len)
2420 FIELD *field = form->current;
2421 FIELD_CELL *bp = Address_Of_Row_In_Buffer(field, row);
2422 int datalen = (int)(After_End_Of_Data(bp, field->dcols) - bp);
2423 int freelen = field->dcols - datalen;
2424 int requiredlen = len + 1;
2426 int result = E_REQUEST_DENIED;
2428 if (freelen >= requiredlen)
2430 wmove(form->w, row, 0);
2431 myINSNSTR(form->w, txt, len);
2432 wmove(form->w, row, len);
2433 myINSNSTR(form->w, &myBLANK, 1);
2438 /* we have to move characters on the next line. If we are on the
2439 last line this may work, if the field is growable */
2440 if ((row == (field->drows - 1)) && Growable(field))
2442 if (!Field_Grown(field, 1))
2443 return (E_SYSTEM_ERROR);
2444 /* !!!Side-Effect : might be changed due to growth!!! */
2445 bp = Address_Of_Row_In_Buffer(field, row);
2448 if (row < (field->drows - 1))
2451 After_Last_Whitespace_Character(bp,
2452 (int)(Get_Start_Of_Data(bp
2457 /* split points now to the first character of the portion of the
2458 line that must be moved to the next line */
2459 datalen = (int)(split - bp); /* + freelen has to stay on this line */
2460 freelen = field->dcols - (datalen + freelen); /* for the next line */
2462 if ((result = Insert_String(form, row + 1, split, freelen)) == E_OK)
2464 wmove(form->w, row, datalen);
2466 wmove(form->w, row, 0);
2467 myINSNSTR(form->w, txt, len);
2468 wmove(form->w, row, len);
2469 myINSNSTR(form->w, &myBLANK, 1);
2477 /*---------------------------------------------------------------------------
2478 | Facility : libnform
2479 | Function : static int Wrapping_Not_Necessary_Or_Wrapping_Ok(
2482 | Description : If a character has been entered into a field, it may
2483 | be that wrapping has to occur. This routine checks
2484 | whether or not wrapping is required and if so, performs
2487 | Return Values : E_OK - no wrapping required or wrapping
2489 | E_REQUEST_DENIED -
2490 | E_SYSTEM_ERROR - some system error
2491 +--------------------------------------------------------------------------*/
2493 Wrapping_Not_Necessary_Or_Wrapping_Ok(FORM *form)
2495 FIELD *field = form->current;
2496 int result = E_REQUEST_DENIED;
2497 bool Last_Row = ((field->drows - 1) == form->currow);
2499 if ((Field_Has_Option(field, O_WRAP)) && /* wrapping wanted */
2500 (!Single_Line_Field(field)) && /* must be multi-line */
2501 (There_Is_No_Room_For_A_Char_In_Line(form)) && /* line is full */
2502 (!Last_Row || Growable(field))) /* there are more lines */
2506 int chars_to_be_wrapped;
2507 int chars_to_remain_on_line;
2511 /* the above logic already ensures, that in this case the field
2513 if (!Field_Grown(field, 1))
2514 return E_SYSTEM_ERROR;
2516 bp = Address_Of_Current_Row_In_Buffer(form);
2517 Window_To_Buffer(form, field);
2518 split = After_Last_Whitespace_Character(bp, field->dcols);
2519 /* split points to the first character of the sequence to be brought
2521 chars_to_remain_on_line = (int)(split - bp);
2522 chars_to_be_wrapped = field->dcols - chars_to_remain_on_line;
2523 if (chars_to_remain_on_line > 0)
2525 if ((result = Insert_String(form, form->currow + 1, split,
2526 chars_to_be_wrapped)) == E_OK)
2528 wmove(form->w, form->currow, chars_to_remain_on_line);
2530 if (form->curcol >= chars_to_remain_on_line)
2533 form->curcol -= chars_to_remain_on_line;
2543 Window_To_Buffer(form, field);
2544 result = E_REQUEST_DENIED;
2548 result = E_OK; /* wrapping was not necessary */
2552 /*----------------------------------------------------------------------------
2553 Field Editing routines
2554 --------------------------------------------------------------------------*/
2556 /*---------------------------------------------------------------------------
2557 | Facility : libnform
2558 | Function : static int Field_Editing(
2559 | int (* const fct) (FORM *),
2562 | Description : Generic routine for field editing requests. The driver
2563 | routines are only called for editable fields, the
2564 | _WINDOW_MODIFIED flag is set if editing occurred.
2565 | This is somewhat special due to the overload semantics
2566 | of the NEW_LINE and DEL_PREV requests.
2568 | Return Values : Error code from low level drivers.
2569 +--------------------------------------------------------------------------*/
2571 Field_Editing(int (*const fct) (FORM *), FORM *form)
2573 int res = E_REQUEST_DENIED;
2575 /* We have to deal here with the specific case of the overloaded
2576 behavior of New_Line and Delete_Previous requests.
2577 They may end up in navigational requests if we are on the first
2578 character in a field. But navigation is also allowed on non-
2581 if ((fct == FE_Delete_Previous) &&
2582 ((unsigned)form->opts & O_BS_OVERLOAD) &&
2583 First_Position_In_Current_Field(form))
2585 res = Inter_Field_Navigation(FN_Previous_Field, form);
2589 if (fct == FE_New_Line)
2591 if (((unsigned)form->opts & O_NL_OVERLOAD) &&
2592 First_Position_In_Current_Field(form))
2594 res = Inter_Field_Navigation(FN_Next_Field, form);
2597 /* FE_New_Line deals itself with the _WINDOW_MODIFIED flag */
2602 /* From now on, everything must be editable */
2603 if ((unsigned)form->current->opts & O_EDIT)
2607 SetStatus(form, _WINDOW_MODIFIED);
2614 /*---------------------------------------------------------------------------
2615 | Facility : libnform
2616 | Function : static int FE_New_Line(FORM * form)
2618 | Description : Perform a new line request. This is rather complex
2619 | compared to other routines in this code due to the
2620 | rather difficult to understand description in the
2623 | Return Values : E_OK - success
2624 | E_REQUEST_DENIED - new line not allowed
2625 | E_SYSTEM_ERROR - system error
2626 +--------------------------------------------------------------------------*/
2628 FE_New_Line(FORM *form)
2630 FIELD *field = form->current;
2632 bool Last_Row = ((field->drows - 1) == form->currow);
2634 T((T_CALLED("FE_New_Line(%p)"), (void *)form));
2635 if (form->status & _OVLMODE)
2638 (!(Growable(field) && !Single_Line_Field(field))))
2640 if (!((unsigned)form->opts & O_NL_OVERLOAD))
2641 returnCode(E_REQUEST_DENIED);
2642 wmove(form->w, form->currow, form->curcol);
2644 /* we have to set this here, although it is also
2645 handled in the generic routine. The reason is,
2646 that FN_Next_Field may fail, but the form is
2647 definitively changed */
2648 SetStatus(form, _WINDOW_MODIFIED);
2649 returnCode(Inter_Field_Navigation(FN_Next_Field, form));
2653 if (Last_Row && !Field_Grown(field, 1))
2655 /* N.B.: due to the logic in the 'if', LastRow==TRUE
2656 means here that the field is growable and not
2657 a single-line field */
2658 returnCode(E_SYSTEM_ERROR);
2660 wmove(form->w, form->currow, form->curcol);
2664 SetStatus(form, _WINDOW_MODIFIED);
2672 !(Growable(field) && !Single_Line_Field(field)))
2674 if (!((unsigned)form->opts & O_NL_OVERLOAD))
2675 returnCode(E_REQUEST_DENIED);
2676 returnCode(Inter_Field_Navigation(FN_Next_Field, form));
2680 bool May_Do_It = !Last_Row && Is_There_Room_For_A_Line(form);
2682 if (!(May_Do_It || Growable(field)))
2683 returnCode(E_REQUEST_DENIED);
2684 if (!May_Do_It && !Field_Grown(field, 1))
2685 returnCode(E_SYSTEM_ERROR);
2687 bp = Address_Of_Current_Position_In_Buffer(form);
2688 t = After_End_Of_Data(bp, field->dcols - form->curcol);
2689 wmove(form->w, form->currow, form->curcol);
2693 wmove(form->w, form->currow, form->curcol);
2695 myADDNSTR(form->w, bp, (int)(t - bp));
2696 SetStatus(form, _WINDOW_MODIFIED);
2702 /*---------------------------------------------------------------------------
2703 | Facility : libnform
2704 | Function : static int FE_Insert_Character(FORM * form)
2706 | Description : Insert blank character at the cursor position
2708 | Return Values : E_OK
2710 +--------------------------------------------------------------------------*/
2712 FE_Insert_Character(FORM *form)
2714 FIELD *field = form->current;
2715 int result = E_REQUEST_DENIED;
2717 T((T_CALLED("FE_Insert_Character(%p)"), (void *)form));
2718 if (Check_Char(form, field, field->type, (int)C_BLANK,
2719 (TypeArgument *)(field->arg)))
2721 bool There_Is_Room = Is_There_Room_For_A_Char_In_Line(form);
2723 if (There_Is_Room ||
2724 ((Single_Line_Field(field) && Growable(field))))
2726 if (!There_Is_Room && !Field_Grown(field, 1))
2727 result = E_SYSTEM_ERROR;
2730 winsch(form->w, (chtype)C_BLANK);
2731 result = Wrapping_Not_Necessary_Or_Wrapping_Ok(form);
2738 /*---------------------------------------------------------------------------
2739 | Facility : libnform
2740 | Function : static int FE_Insert_Line(FORM * form)
2742 | Description : Insert a blank line at the cursor position
2744 | Return Values : E_OK - success
2745 | E_REQUEST_DENIED - line can not be inserted
2746 +--------------------------------------------------------------------------*/
2748 FE_Insert_Line(FORM *form)
2750 FIELD *field = form->current;
2751 int result = E_REQUEST_DENIED;
2753 T((T_CALLED("FE_Insert_Line(%p)"), (void *)form));
2754 if (Check_Char(form, field,
2755 field->type, (int)C_BLANK, (TypeArgument *)(field->arg)))
2757 bool Maybe_Done = (form->currow != (field->drows - 1)) &&
2758 Is_There_Room_For_A_Line(form);
2760 if (!Single_Line_Field(field) &&
2761 (Maybe_Done || Growable(field)))
2763 if (!Maybe_Done && !Field_Grown(field, 1))
2764 result = E_SYSTEM_ERROR;
2776 /*---------------------------------------------------------------------------
2777 | Facility : libnform
2778 | Function : static int FE_Delete_Character(FORM * form)
2780 | Description : Delete character at the cursor position
2782 | Return Values : E_OK - success
2783 +--------------------------------------------------------------------------*/
2785 FE_Delete_Character(FORM *form)
2787 T((T_CALLED("FE_Delete_Character(%p)"), (void *)form));
2792 /*---------------------------------------------------------------------------
2793 | Facility : libnform
2794 | Function : static int FE_Delete_Previous(FORM * form)
2796 | Description : Delete character before cursor. Again this is a rather
2797 | difficult piece compared to others due to the overloading
2798 | semantics of backspace.
2799 | N.B.: The case of overloaded BS on first field position
2800 | is already handled in the generic routine.
2802 | Return Values : E_OK - success
2803 | E_REQUEST_DENIED - Character can't be deleted
2804 +--------------------------------------------------------------------------*/
2806 FE_Delete_Previous(FORM *form)
2808 FIELD *field = form->current;
2810 T((T_CALLED("FE_Delete_Previous(%p)"), (void *)form));
2811 if (First_Position_In_Current_Field(form))
2812 returnCode(E_REQUEST_DENIED);
2814 if ((--(form->curcol)) < 0)
2816 FIELD_CELL *this_line, *prev_line, *prev_end, *this_end;
2817 int this_row = form->currow;
2820 if (form->status & _OVLMODE)
2821 returnCode(E_REQUEST_DENIED);
2823 prev_line = Address_Of_Row_In_Buffer(field, (form->currow - 1));
2824 this_line = Address_Of_Row_In_Buffer(field, (form->currow));
2825 Synchronize_Buffer(form);
2826 prev_end = After_End_Of_Data(prev_line, field->dcols);
2827 this_end = After_End_Of_Data(this_line, field->dcols);
2828 if ((int)(this_end - this_line) >
2829 (field->cols - (int)(prev_end - prev_line)))
2830 returnCode(E_REQUEST_DENIED);
2831 wmove(form->w, form->currow, form->curcol);
2833 Adjust_Cursor_Position(form, prev_end);
2835 * If we did not really move to the previous line, help the user a
2836 * little. It is however a little inconsistent. Normally, when
2837 * backspacing around the point where text wraps to a new line in a
2838 * multi-line form, we absorb one keystroke for the wrapping point. That
2839 * is consistent with SVr4 forms. However, SVr4 does not allow typing
2840 * into the last column of the field, and requires the user to enter a
2841 * newline to move to the next line. Therefore it can consistently eat
2842 * that keystroke. Since ncurses allows the last column, it wraps
2843 * automatically (given the proper options). But we cannot eat the
2844 * keystroke to back over the wrapping point, since that would put the
2845 * cursor past the end of the form field. In this case, just delete the
2846 * character at the end of the field.
2848 if (form->currow == this_row && this_row > 0)
2851 form->curcol = field->dcols - 1;
2856 wmove(form->w, form->currow, form->curcol);
2857 myADDNSTR(form->w, this_line, (int)(this_end - this_line));
2867 /*---------------------------------------------------------------------------
2868 | Facility : libnform
2869 | Function : static int FE_Delete_Line(FORM * form)
2871 | Description : Delete line at cursor position.
2873 | Return Values : E_OK - success
2874 +--------------------------------------------------------------------------*/
2876 FE_Delete_Line(FORM *form)
2878 T((T_CALLED("FE_Delete_Line(%p)"), (void *)form));
2884 /*---------------------------------------------------------------------------
2885 | Facility : libnform
2886 | Function : static int FE_Delete_Word(FORM * form)
2888 | Description : Delete word at cursor position
2890 | Return Values : E_OK - success
2891 | E_REQUEST_DENIED - failure
2892 +--------------------------------------------------------------------------*/
2894 FE_Delete_Word(FORM *form)
2896 FIELD *field = form->current;
2897 FIELD_CELL *bp = Address_Of_Current_Row_In_Buffer(form);
2898 FIELD_CELL *ep = bp + field->dcols;
2899 FIELD_CELL *cp = bp + form->curcol;
2902 T((T_CALLED("FE_Delete_Word(%p)"), (void *)form));
2903 Synchronize_Buffer(form);
2905 returnCode(E_REQUEST_DENIED); /* not in word */
2907 /* move cursor to begin of word and erase to end of screen-line */
2908 Adjust_Cursor_Position(form,
2909 After_Last_Whitespace_Character(bp, form->curcol));
2910 wmove(form->w, form->currow, form->curcol);
2913 /* skip over word in buffer */
2914 s = Get_First_Whitespace_Character(cp, (int)(ep - cp));
2915 /* to begin of next word */
2916 s = Get_Start_Of_Data(s, (int)(ep - s));
2917 if ((s != cp) && !ISBLANK(*s))
2919 /* copy remaining line to window */
2920 myADDNSTR(form->w, s, (int)(s - After_End_Of_Data(s, (int)(ep - s))));
2925 /*---------------------------------------------------------------------------
2926 | Facility : libnform
2927 | Function : static int FE_Clear_To_End_Of_Line(FORM * form)
2929 | Description : Clear to end of current line.
2931 | Return Values : E_OK - success
2932 +--------------------------------------------------------------------------*/
2934 FE_Clear_To_End_Of_Line(FORM *form)
2936 T((T_CALLED("FE_Clear_To_End_Of_Line(%p)"), (void *)form));
2937 wmove(form->w, form->currow, form->curcol);
2942 /*---------------------------------------------------------------------------
2943 | Facility : libnform
2944 | Function : static int FE_Clear_To_End_Of_Field(FORM * form)
2946 | Description : Clear to end of field.
2948 | Return Values : E_OK - success
2949 +--------------------------------------------------------------------------*/
2951 FE_Clear_To_End_Of_Field(FORM *form)
2953 T((T_CALLED("FE_Clear_To_End_Of_Field(%p)"), (void *)form));
2954 wmove(form->w, form->currow, form->curcol);
2959 /*---------------------------------------------------------------------------
2960 | Facility : libnform
2961 | Function : static int FE_Clear_Field(FORM * form)
2963 | Description : Clear entire field.
2965 | Return Values : E_OK - success
2966 +--------------------------------------------------------------------------*/
2968 FE_Clear_Field(FORM *form)
2970 T((T_CALLED("FE_Clear_Field(%p)"), (void *)form));
2971 form->currow = form->curcol = 0;
2975 /*----------------------------------------------------------------------------
2976 END of Field Editing routines
2977 --------------------------------------------------------------------------*/
2979 /*----------------------------------------------------------------------------
2981 --------------------------------------------------------------------------*/
2983 /*---------------------------------------------------------------------------
2984 | Facility : libnform
2985 | Function : static int EM_Overlay_Mode(FORM * form)
2987 | Description : Switch to overlay mode.
2989 | Return Values : E_OK - success
2990 +--------------------------------------------------------------------------*/
2992 EM_Overlay_Mode(FORM *form)
2994 T((T_CALLED("EM_Overlay_Mode(%p)"), (void *)form));
2995 SetStatus(form, _OVLMODE);
2999 /*---------------------------------------------------------------------------
3000 | Facility : libnform
3001 | Function : static int EM_Insert_Mode(FORM * form)
3003 | Description : Switch to insert mode
3005 | Return Values : E_OK - success
3006 +--------------------------------------------------------------------------*/
3008 EM_Insert_Mode(FORM *form)
3010 T((T_CALLED("EM_Insert_Mode(%p)"), (void *)form));
3011 ClrStatus(form, _OVLMODE);
3015 /*----------------------------------------------------------------------------
3016 END of Edit Mode routines
3017 --------------------------------------------------------------------------*/
3019 /*----------------------------------------------------------------------------
3020 Helper routines for Choice Requests
3021 --------------------------------------------------------------------------*/
3023 /*---------------------------------------------------------------------------
3024 | Facility : libnform
3025 | Function : static bool Next_Choice(FORM * form,
3028 | TypeArgument *argp)
3030 | Description : Get the next field choice. For linked types this is
3033 | Return Values : TRUE - next choice successfully retrieved
3034 | FALSE - couldn't retrieve next choice
3035 +--------------------------------------------------------------------------*/
3037 Next_Choice(FORM *form, FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
3039 if (!typ || !(typ->status & _HAS_CHOICE))
3042 if (typ->status & _LINKED_TYPE)
3046 Next_Choice(form, typ->left, field, argp->left) ||
3047 Next_Choice(form, typ->right, field, argp->right));
3051 #if NCURSES_INTEROP_FUNCS
3052 assert(typ->enum_next.onext);
3053 if (typ->status & _GENERIC)
3054 return typ->enum_next.gnext(form, field, (void *)argp);
3056 return typ->enum_next.onext(field, (void *)argp);
3059 return typ->next(field, (void *)argp);
3064 /*---------------------------------------------------------------------------
3065 | Facility : libnform
3066 | Function : static bool Previous_Choice(FORM * form,
3069 | TypeArgument *argp)
3071 | Description : Get the previous field choice. For linked types this
3072 | is done recursively.
3074 | Return Values : TRUE - previous choice successfully retrieved
3075 | FALSE - couldn't retrieve previous choice
3076 +--------------------------------------------------------------------------*/
3078 Previous_Choice(FORM *form, FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
3080 if (!typ || !(typ->status & _HAS_CHOICE))
3083 if (typ->status & _LINKED_TYPE)
3087 Previous_Choice(form, typ->left, field, argp->left) ||
3088 Previous_Choice(form, typ->right, field, argp->right));
3092 #if NCURSES_INTEROP_FUNCS
3093 assert(typ->enum_prev.oprev);
3094 if (typ->status & _GENERIC)
3095 return typ->enum_prev.gprev(form, field, (void *)argp);
3097 return typ->enum_prev.oprev(field, (void *)argp);
3100 return typ->prev(field, (void *)argp);
3104 /*----------------------------------------------------------------------------
3105 End of Helper routines for Choice Requests
3106 --------------------------------------------------------------------------*/
3108 /*----------------------------------------------------------------------------
3109 Routines for Choice Requests
3110 --------------------------------------------------------------------------*/
3112 /*---------------------------------------------------------------------------
3113 | Facility : libnform
3114 | Function : static int CR_Next_Choice(FORM * form)
3116 | Description : Get the next field choice.
3118 | Return Values : E_OK - success
3119 | E_REQUEST_DENIED - next choice couldn't be retrieved
3120 +--------------------------------------------------------------------------*/
3122 CR_Next_Choice(FORM *form)
3124 FIELD *field = form->current;
3126 T((T_CALLED("CR_Next_Choice(%p)"), (void *)form));
3127 Synchronize_Buffer(form);
3128 returnCode((Next_Choice(form, field->type, field, (TypeArgument *)(field->arg)))
3130 : E_REQUEST_DENIED);
3133 /*---------------------------------------------------------------------------
3134 | Facility : libnform
3135 | Function : static int CR_Previous_Choice(FORM * form)
3137 | Description : Get the previous field choice.
3139 | Return Values : E_OK - success
3140 | E_REQUEST_DENIED - prev. choice couldn't be retrieved
3141 +--------------------------------------------------------------------------*/
3143 CR_Previous_Choice(FORM *form)
3145 FIELD *field = form->current;
3147 T((T_CALLED("CR_Previous_Choice(%p)"), (void *)form));
3148 Synchronize_Buffer(form);
3149 returnCode((Previous_Choice(form, field->type, field, (TypeArgument *)(field->arg)))
3151 : E_REQUEST_DENIED);
3153 /*----------------------------------------------------------------------------
3154 End of Routines for Choice Requests
3155 --------------------------------------------------------------------------*/
3157 /*----------------------------------------------------------------------------
3158 Helper routines for Field Validations.
3159 --------------------------------------------------------------------------*/
3161 /*---------------------------------------------------------------------------
3162 | Facility : libnform
3163 | Function : static bool Check_Field(FORM* form,
3166 | TypeArgument * argp)
3168 | Description : Check the field according to its fieldtype and its
3169 | actual arguments. For linked fieldtypes this is done
3172 | Return Values : TRUE - field is valid
3173 | FALSE - field is invalid.
3174 +--------------------------------------------------------------------------*/
3176 Check_Field(FORM *form, FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
3180 if (Field_Has_Option(field, O_NULLOK))
3182 FIELD_CELL *bp = field->buf;
3185 while (ISBLANK(*bp))
3189 if (CharOf(*bp) == 0)
3193 if (typ->status & _LINKED_TYPE)
3197 Check_Field(form, typ->left, field, argp->left) ||
3198 Check_Field(form, typ->right, field, argp->right));
3202 #if NCURSES_INTEROP_FUNCS
3203 if (typ->fieldcheck.ofcheck)
3205 if (typ->status & _GENERIC)
3206 return typ->fieldcheck.gfcheck(form, field, (void *)argp);
3208 return typ->fieldcheck.ofcheck(field, (void *)argp);
3212 return typ->fcheck(field, (void *)argp);
3219 /*---------------------------------------------------------------------------
3220 | Facility : libnform
3221 | Function : bool _nc_Internal_Validation(FORM * form )
3223 | Description : Validate the current field of the form.
3225 | Return Values : TRUE - field is valid
3226 | FALSE - field is invalid
3227 +--------------------------------------------------------------------------*/
3229 _nc_Internal_Validation(FORM *form)
3233 field = form->current;
3235 Synchronize_Buffer(form);
3236 if ((form->status & _FCHECK_REQUIRED) ||
3237 (!(Field_Has_Option(field, O_PASSOK))))
3239 if (!Check_Field(form, field->type, field, (TypeArgument *)(field->arg)))
3241 ClrStatus(form, _FCHECK_REQUIRED);
3242 SetStatus(field, _CHANGED);
3243 Synchronize_Linked_Fields(field);
3247 /*----------------------------------------------------------------------------
3248 End of Helper routines for Field Validations.
3249 --------------------------------------------------------------------------*/
3251 /*----------------------------------------------------------------------------
3252 Routines for Field Validation.
3253 --------------------------------------------------------------------------*/
3255 /*---------------------------------------------------------------------------
3256 | Facility : libnform
3257 | Function : static int FV_Validation(FORM * form)
3259 | Description : Validate the current field of the form.
3261 | Return Values : E_OK - field valid
3262 | E_INVALID_FIELD - field not valid
3263 +--------------------------------------------------------------------------*/
3265 FV_Validation(FORM *form)
3267 T((T_CALLED("FV_Validation(%p)"), (void *)form));
3268 if (_nc_Internal_Validation(form))
3271 returnCode(E_INVALID_FIELD);
3273 /*----------------------------------------------------------------------------
3274 End of routines for Field Validation.
3275 --------------------------------------------------------------------------*/
3277 /*----------------------------------------------------------------------------
3278 Helper routines for Inter-Field Navigation
3279 --------------------------------------------------------------------------*/
3281 /*---------------------------------------------------------------------------
3282 | Facility : libnform
3283 | Function : static FIELD *Next_Field_On_Page(FIELD * field)
3285 | Description : Get the next field after the given field on the current
3286 | page. The order of fields is the one defined by the
3287 | field's array. Only visible and active fields are
3290 | Return Values : Pointer to the next field.
3291 +--------------------------------------------------------------------------*/
3292 NCURSES_INLINE static FIELD *
3293 Next_Field_On_Page(FIELD *field)
3295 FORM *form = field->form;
3296 FIELD **field_on_page = &form->field[field->index];
3297 FIELD **first_on_page = &form->field[form->page[form->curpage].pmin];
3298 FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
3303 (field_on_page == last_on_page) ? first_on_page : field_on_page + 1;
3304 if (Field_Is_Selectable(*field_on_page))
3307 while (field != (*field_on_page));
3308 return (*field_on_page);
3311 /*---------------------------------------------------------------------------
3312 | Facility : libnform
3313 | Function : FIELD* _nc_First_Active_Field(FORM * form)
3315 | Description : Get the first active field on the current page,
3316 | if there are such. If there are none, get the first
3317 | visible field on the page. If there are also none,
3318 | we return the first field on page and hope the best.
3320 | Return Values : Pointer to calculated field.
3321 +--------------------------------------------------------------------------*/
3322 FORM_EXPORT(FIELD *)
3323 _nc_First_Active_Field(FORM *form)
3325 FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
3326 FIELD *proposed = Next_Field_On_Page(*last_on_page);
3328 if (proposed == *last_on_page)
3330 /* there might be the special situation, where there is no
3331 active and visible field on the current page. We then select
3332 the first visible field on this readonly page
3334 if (Field_Is_Not_Selectable(proposed))
3336 FIELD **field = &form->field[proposed->index];
3337 FIELD **first = &form->field[form->page[form->curpage].pmin];
3341 field = (field == last_on_page) ? first : field + 1;
3342 if (Field_Has_Option(*field, O_VISIBLE))
3345 while (proposed != (*field));
3349 if ((proposed == *last_on_page) &&
3350 !((unsigned)proposed->opts & O_VISIBLE))
3352 /* This means, there is also no visible field on the page.
3353 So we propose the first one and hope the very best...
3354 Some very clever user has designed a readonly and invisible
3364 /*---------------------------------------------------------------------------
3365 | Facility : libnform
3366 | Function : static FIELD *Previous_Field_On_Page(FIELD * field)
3368 | Description : Get the previous field before the given field on the
3369 | current page. The order of fields is the one defined by
3370 | the field's array. Only visible and active fields are
3373 | Return Values : Pointer to the previous field.
3374 +--------------------------------------------------------------------------*/
3375 NCURSES_INLINE static FIELD *
3376 Previous_Field_On_Page(FIELD *field)
3378 FORM *form = field->form;
3379 FIELD **field_on_page = &form->field[field->index];
3380 FIELD **first_on_page = &form->field[form->page[form->curpage].pmin];
3381 FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
3386 (field_on_page == first_on_page) ? last_on_page : field_on_page - 1;
3387 if (Field_Is_Selectable(*field_on_page))
3390 while (field != (*field_on_page));
3392 return (*field_on_page);
3395 /*---------------------------------------------------------------------------
3396 | Facility : libnform
3397 | Function : static FIELD *Sorted_Next_Field(FIELD * field)
3399 | Description : Get the next field after the given field on the current
3400 | page. The order of fields is the one defined by the
3401 | (row,column) geometry, rows are major.
3403 | Return Values : Pointer to the next field.
3404 +--------------------------------------------------------------------------*/
3405 NCURSES_INLINE static FIELD *
3406 Sorted_Next_Field(FIELD *field)
3408 FIELD *field_on_page = field;
3412 field_on_page = field_on_page->snext;
3413 if (Field_Is_Selectable(field_on_page))
3416 while (field_on_page != field);
3418 return (field_on_page);
3421 /*---------------------------------------------------------------------------
3422 | Facility : libnform
3423 | Function : static FIELD *Sorted_Previous_Field(FIELD * field)
3425 | Description : Get the previous field before the given field on the
3426 | current page. The order of fields is the one defined
3427 | by the (row,column) geometry, rows are major.
3429 | Return Values : Pointer to the previous field.
3430 +--------------------------------------------------------------------------*/
3431 NCURSES_INLINE static FIELD *
3432 Sorted_Previous_Field(FIELD *field)
3434 FIELD *field_on_page = field;
3438 field_on_page = field_on_page->sprev;
3439 if (Field_Is_Selectable(field_on_page))
3442 while (field_on_page != field);
3444 return (field_on_page);
3447 /*---------------------------------------------------------------------------
3448 | Facility : libnform
3449 | Function : static FIELD *Left_Neighbor_Field(FIELD * field)
3451 | Description : Get the left neighbor of the field on the same line
3452 | and the same page. Cycles through the line.
3454 | Return Values : Pointer to left neighbor field.
3455 +--------------------------------------------------------------------------*/
3456 NCURSES_INLINE static FIELD *
3457 Left_Neighbor_Field(FIELD *field)
3459 FIELD *field_on_page = field;
3461 /* For a field that has really a left neighbor, the while clause
3462 immediately fails and the loop is left, positioned at the right
3463 neighbor. Otherwise we cycle backwards through the sorted field list
3464 until we enter the same line (from the right end).
3468 field_on_page = Sorted_Previous_Field(field_on_page);
3470 while (field_on_page->frow != field->frow);
3472 return (field_on_page);
3475 /*---------------------------------------------------------------------------
3476 | Facility : libnform
3477 | Function : static FIELD *Right_Neighbor_Field(FIELD * field)
3479 | Description : Get the right neighbor of the field on the same line
3480 | and the same page.
3482 | Return Values : Pointer to right neighbor field.
3483 +--------------------------------------------------------------------------*/
3484 NCURSES_INLINE static FIELD *
3485 Right_Neighbor_Field(FIELD *field)
3487 FIELD *field_on_page = field;
3489 /* See the comments on Left_Neighbor_Field to understand how it works */
3492 field_on_page = Sorted_Next_Field(field_on_page);
3494 while (field_on_page->frow != field->frow);
3496 return (field_on_page);
3499 /*---------------------------------------------------------------------------
3500 | Facility : libnform
3501 | Function : static FIELD *Upper_Neighbor_Field(FIELD * field)
3503 | Description : Because of the row-major nature of sorting the fields,
3504 | it is more difficult to define what the upper neighbor
3505 | field really means. We define that it must be on a
3506 | 'previous' line (cyclic order!) and is the rightmost
3507 | field lying on the left side of the given field. If
3508 | this set is empty, we take the first field on the line.
3510 | Return Values : Pointer to the upper neighbor field.
3511 +--------------------------------------------------------------------------*/
3513 Upper_Neighbor_Field(FIELD *field)
3515 FIELD *field_on_page = field;
3516 int frow = field->frow;
3517 int fcol = field->fcol;
3519 /* Walk back to the 'previous' line. The second term in the while clause
3520 just guarantees that we stop if we cycled through the line because
3521 there might be no 'previous' line if the page has just one line.
3525 field_on_page = Sorted_Previous_Field(field_on_page);
3527 while (field_on_page->frow == frow && field_on_page->fcol != fcol);
3529 if (field_on_page->frow != frow)
3531 /* We really found a 'previous' line. We are positioned at the
3532 rightmost field on this line */
3533 frow = field_on_page->frow;
3535 /* We walk to the left as long as we are really right of the
3537 while (field_on_page->frow == frow && field_on_page->fcol > fcol)
3538 field_on_page = Sorted_Previous_Field(field_on_page);
3540 /* If we wrapped, just go to the right which is the first field on
3542 if (field_on_page->frow != frow)
3543 field_on_page = Sorted_Next_Field(field_on_page);
3546 return (field_on_page);
3549 /*---------------------------------------------------------------------------
3550 | Facility : libnform
3551 | Function : static FIELD *Down_Neighbor_Field(FIELD * field)
3553 | Description : Because of the row-major nature of sorting the fields,
3554 | it's more difficult to define what the down neighbor
3555 | field really means. We define that it must be on a
3556 | 'next' line (cyclic order!) and is the leftmost
3557 | field laying on the right side of the given field. If
3558 | this set is empty, we take the last field on the line.
3560 | Return Values : Pointer to the upper neighbor field.
3561 +--------------------------------------------------------------------------*/
3563 Down_Neighbor_Field(FIELD *field)
3565 FIELD *field_on_page = field;
3566 int frow = field->frow;
3567 int fcol = field->fcol;
3569 /* Walk forward to the 'next' line. The second term in the while clause
3570 just guarantees that we stop if we cycled through the line because
3571 there might be no 'next' line if the page has just one line.
3575 field_on_page = Sorted_Next_Field(field_on_page);
3577 while (field_on_page->frow == frow && field_on_page->fcol != fcol);
3579 if (field_on_page->frow != frow)
3581 /* We really found a 'next' line. We are positioned at the rightmost
3582 field on this line */
3583 frow = field_on_page->frow;
3585 /* We walk to the right as long as we are really left of the
3587 while (field_on_page->frow == frow && field_on_page->fcol < fcol)
3588 field_on_page = Sorted_Next_Field(field_on_page);
3590 /* If we wrapped, just go to the left which is the last field on
3592 if (field_on_page->frow != frow)
3593 field_on_page = Sorted_Previous_Field(field_on_page);
3596 return (field_on_page);
3599 /*----------------------------------------------------------------------------
3600 Inter-Field Navigation routines
3601 --------------------------------------------------------------------------*/
3603 /*---------------------------------------------------------------------------
3604 | Facility : libnform
3605 | Function : static int Inter_Field_Navigation(
3606 | int (* const fct) (FORM *),
3609 | Description : Generic behavior for changing the current field, the
3610 | field is left and a new field is entered. So the field
3611 | must be validated and the field init/term hooks must
3614 | Return Values : E_OK - success
3615 | E_INVALID_FIELD - field is invalid
3616 | some other - error from subordinate call
3617 +--------------------------------------------------------------------------*/
3619 Inter_Field_Navigation(int (*const fct) (FORM *), FORM *form)
3623 if (!_nc_Internal_Validation(form))
3624 res = E_INVALID_FIELD;
3627 Call_Hook(form, fieldterm);
3629 Call_Hook(form, fieldinit);
3634 /*---------------------------------------------------------------------------
3635 | Facility : libnform
3636 | Function : static int FN_Next_Field(FORM * form)
3638 | Description : Move to the next field on the current page of the form
3640 | Return Values : E_OK - success
3641 | != E_OK - error from subordinate call
3642 +--------------------------------------------------------------------------*/
3644 FN_Next_Field(FORM *form)
3646 T((T_CALLED("FN_Next_Field(%p)"), (void *)form));
3647 returnCode(_nc_Set_Current_Field(form,
3648 Next_Field_On_Page(form->current)));
3651 /*---------------------------------------------------------------------------
3652 | Facility : libnform
3653 | Function : static int FN_Previous_Field(FORM * form)
3655 | Description : Move to the previous field on the current page of the
3658 | Return Values : E_OK - success
3659 | != E_OK - error from subordinate call
3660 +--------------------------------------------------------------------------*/
3662 FN_Previous_Field(FORM *form)
3664 T((T_CALLED("FN_Previous_Field(%p)"), (void *)form));
3665 returnCode(_nc_Set_Current_Field(form,
3666 Previous_Field_On_Page(form->current)));
3669 /*---------------------------------------------------------------------------
3670 | Facility : libnform
3671 | Function : static int FN_First_Field(FORM * form)
3673 | Description : Move to the first field on the current page of the form
3675 | Return Values : E_OK - success
3676 | != E_OK - error from subordinate call
3677 +--------------------------------------------------------------------------*/
3679 FN_First_Field(FORM *form)
3681 T((T_CALLED("FN_First_Field(%p)"), (void *)form));
3682 returnCode(_nc_Set_Current_Field(form,
3683 Next_Field_On_Page(form->field[form->page[form->curpage].pmax])));
3686 /*---------------------------------------------------------------------------
3687 | Facility : libnform
3688 | Function : static int FN_Last_Field(FORM * form)
3690 | Description : Move to the last field on the current page of the form
3692 | Return Values : E_OK - success
3693 | != E_OK - error from subordinate call
3694 +--------------------------------------------------------------------------*/
3696 FN_Last_Field(FORM *form)
3698 T((T_CALLED("FN_Last_Field(%p)"), (void *)form));
3700 _nc_Set_Current_Field(form,
3701 Previous_Field_On_Page(form->field[form->page[form->curpage].pmin])));
3704 /*---------------------------------------------------------------------------
3705 | Facility : libnform
3706 | Function : static int FN_Sorted_Next_Field(FORM * form)
3708 | Description : Move to the sorted next field on the current page
3711 | Return Values : E_OK - success
3712 | != E_OK - error from subordinate call