1 /****************************************************************************
2 * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Juergen Pfeifer, 1995,1997 *
31 ****************************************************************************/
33 #include "form.priv.h"
35 MODULE_ID("$Id: frm_driver.c,v 1.82 2007/06/02 22:59:24 tom Exp $")
37 /*----------------------------------------------------------------------------
38 This is the core module of the form library. It contains the majority
39 of the driver routines as well as the form_driver function.
41 Essentially this module is nearly the whole library. This is because
42 all the functions in this module depends on some others in the module,
43 so it makes no sense to split them into separate files because they
44 will always be linked together. The only acceptable concern is turnaround
45 time for this module, but now we have all Pentiums or RISCs, so what!
47 The driver routines are grouped into nine generic categories:
49 a) Page Navigation ( all functions prefixed by PN_ )
50 The current page of the form is left and some new page is
52 b) Inter-Field Navigation ( all functions prefixed by FN_ )
53 The current field of the form is left and some new field is
55 c) Intra-Field Navigation ( all functions prefixed by IFN_ )
56 The current position in the current field is changed.
57 d) Vertical Scrolling ( all functions prefixed by VSC_ )
58 Essentially this is a specialization of Intra-Field navigation.
59 It has to check for a multi-line field.
60 e) Horizontal Scrolling ( all functions prefixed by HSC_ )
61 Essentially this is a specialization of Intra-Field navigation.
62 It has to check for a single-line field.
63 f) Field Editing ( all functions prefixed by FE_ )
64 The content of the current field is changed
65 g) Edit Mode requests ( all functions prefixed by EM_ )
66 Switching between insert and overlay mode
67 h) Field-Validation requests ( all functions prefixed by FV_ )
68 Perform verifications of the field.
69 i) Choice requests ( all functions prefixed by CR_ )
70 Requests to enumerate possible field values
71 --------------------------------------------------------------------------*/
73 /*----------------------------------------------------------------------------
74 Some remarks on the placements of assert() macros :
75 I use them only on "strategic" places, i.e. top level entries where
76 I want to make sure that things are set correctly. Throughout subordinate
77 routines I omit them mostly.
78 --------------------------------------------------------------------------*/
81 Some options that may effect compatibility in behavior to SVr4 forms,
82 but they are here to allow a more intuitive and user friendly behavior of
83 our form implementation. This doesn't affect the API, so we feel it is
86 The initial implementation tries to stay very close with the behavior
87 of the original SVr4 implementation, although in some areas it is quite
88 clear that this isn't the most appropriate way. As far as possible this
89 sources will allow you to build a forms lib that behaves quite similar
90 to SVr4, but now and in the future we will give you better options.
91 Perhaps at some time we will make this configurable at runtime.
94 /* Implement a more user-friendly previous/next word behavior */
95 #define FRIENDLY_PREV_NEXT_WORD (1)
96 /* Fix the wrong behavior for forms with all fields inactive */
97 #define FIX_FORM_INACTIVE_BUG (1)
98 /* Allow dynamic field growth also when navigating past the end */
99 #define GROW_IF_NAVIGATE (1)
101 #if USE_WIDEC_SUPPORT
102 #define myADDNSTR(w, s, n) wadd_wchnstr(w, s, n)
103 #define myINSNSTR(w, s, n) wins_wchnstr(w, s, n)
104 #define myINNSTR(w, s, n) fix_wchnstr(w, s, n)
105 #define myWCWIDTH(w, y, x) cell_width(w, y, x)
107 #define myADDNSTR(w, s, n) waddnstr(w, s, n)
108 #define myINSNSTR(w, s, n) winsnstr(w, s, n)
109 #define myINNSTR(w, s, n) winnstr(w, s, n)
110 #define myWCWIDTH(w, y, x) 1
113 /*----------------------------------------------------------------------------
114 Forward references to some internally used static functions
115 --------------------------------------------------------------------------*/
116 static int Inter_Field_Navigation(int (*const fct) (FORM *), FORM *form);
117 static int FN_Next_Field(FORM *form);
118 static int FN_Previous_Field(FORM *form);
119 static int FE_New_Line(FORM *);
120 static int FE_Delete_Previous(FORM *);
122 /*----------------------------------------------------------------------------
125 Some Remarks on that: I use the convention to use UPPERCASE for constants
126 defined by Macros. If I provide a macro as a kind of inline routine to
127 provide some logic, I use my Upper_Lower case style.
128 --------------------------------------------------------------------------*/
130 /* Calculate the position of a single row in a field buffer */
131 #define Position_Of_Row_In_Buffer(field,row) ((row)*(field)->dcols)
133 /* Calculate start address for the fields buffer# N */
134 #define Address_Of_Nth_Buffer(field,N) \
135 ((field)->buf + (N)*(1+Buffer_Length(field)))
137 /* Calculate the start address of the row in the fields specified buffer# N */
138 #define Address_Of_Row_In_Nth_Buffer(field,N,row) \
139 (Address_Of_Nth_Buffer(field,N) + Position_Of_Row_In_Buffer(field,row))
141 /* Calculate the start address of the row in the fields primary buffer */
142 #define Address_Of_Row_In_Buffer(field,row) \
143 Address_Of_Row_In_Nth_Buffer(field,0,row)
145 /* Calculate the start address of the row in the forms current field
147 #define Address_Of_Current_Row_In_Nth_Buffer(form,N) \
148 Address_Of_Row_In_Nth_Buffer((form)->current,N,(form)->currow)
150 /* Calculate the start address of the row in the forms current field
152 #define Address_Of_Current_Row_In_Buffer(form) \
153 Address_Of_Current_Row_In_Nth_Buffer(form,0)
155 /* Calculate the address of the cursor in the forms current field
157 #define Address_Of_Current_Position_In_Nth_Buffer(form,N) \
158 (Address_Of_Current_Row_In_Nth_Buffer(form,N) + (form)->curcol)
160 /* Calculate the address of the cursor in the forms current field
162 #define Address_Of_Current_Position_In_Buffer(form) \
163 Address_Of_Current_Position_In_Nth_Buffer(form,0)
165 /* Logic to decide whether or not a field is actually a field with
166 vertical or horizontal scrolling */
167 #define Is_Scroll_Field(field) \
168 (((field)->drows > (field)->rows) || \
169 ((field)->dcols > (field)->cols))
171 /* Logic to decide whether or not a field needs to have an individual window
172 instead of a derived window because it contains invisible parts.
173 This is true for non-public fields and for scrollable fields. */
174 #define Has_Invisible_Parts(field) \
175 (!((field)->opts & O_PUBLIC) || \
176 Is_Scroll_Field(field))
178 /* Logic to decide whether or not a field needs justification */
179 #define Justification_Allowed(field) \
180 (((field)->just != NO_JUSTIFICATION) && \
181 (Single_Line_Field(field)) && \
182 (((field)->dcols == (field)->cols) && \
183 ((field)->opts & O_STATIC)) )
185 /* Logic to determine whether or not a dynamic field may still grow */
186 #define Growable(field) ((field)->status & _MAY_GROW)
188 /* Macro to set the attributes for a fields window */
189 #define Set_Field_Window_Attributes(field,win) \
190 ( wbkgdset((win),(chtype)((field)->pad | (field)->back)), \
191 wattrset((win),(field)->fore) )
193 /* Logic to decide whether or not a field really appears on the form */
194 #define Field_Really_Appears(field) \
196 (field->form->status & _POSTED) &&\
197 (field->opts & O_VISIBLE) &&\
198 (field->page == field->form->curpage))
200 /* Logic to determine whether or not we are on the first position in the
202 #define First_Position_In_Current_Field(form) \
203 (((form)->currow==0) && ((form)->curcol==0))
205 #define Minimum(a,b) (((a)<=(b)) ? (a) : (b))
206 #define Maximum(a,b) (((a)>=(b)) ? (a) : (b))
208 /*----------------------------------------------------------------------------
210 --------------------------------------------------------------------------*/
211 static FIELD_CELL myBLANK = BLANK;
212 static FIELD_CELL myZEROS;
216 check_pos(FORM *form, int lineno)
222 getyx(form->w, y, x);
223 if (y != form->currow || x != form->curcol)
225 T(("CHECKPOS %s@%d have position %d,%d vs want %d,%d",
228 form->currow, form->curcol));
232 #define CHECKPOS(form) check_pos(form, __LINE__)
234 #define CHECKPOS(form) /* nothing */
237 /*----------------------------------------------------------------------------
238 Wide-character special functions
239 --------------------------------------------------------------------------*/
240 #if USE_WIDEC_SUPPORT
243 wins_wchnstr(WINDOW *w, cchar_t *s, int n)
251 if ((code = wins_wch(w, s++)) != OK)
253 if ((code = wmove(w, y, x + 1)) != OK)
259 /* win_wchnstr is inconsistent with winnstr, since it returns OK rather than
260 * the number of items transferred.
263 fix_wchnstr(WINDOW *w, cchar_t *s, int n)
267 win_wchnstr(w, s, n);
269 * This function is used to extract the text only from the window.
270 * Strip attributes and color from the string so they will not be added
271 * back when copying the string to the window.
273 for (x = 0; x < n; ++x)
275 RemAttr(s[x], A_ATTRIBUTES);
282 * Returns the column of the base of the given cell.
285 cell_base(WINDOW *win, int y, int x)
289 while (LEGALYX(win, y, x))
291 cchar_t *data = &(win->_line[y].text[x]);
293 if (isWidecBase(CHDEREF(data)) || !isWidecExt(CHDEREF(data)))
304 * Returns the number of columns needed for the given cell in a window.
307 cell_width(WINDOW *win, int y, int x)
311 if (LEGALYX(win, y, x))
313 cchar_t *data = &(win->_line[y].text[x]);
315 if (isWidecExt(CHDEREF(data)))
317 /* recur, providing the number of columns to the next character */
318 result = cell_width(win, y, x - 1);
322 result = wcwidth(CharOf(CHDEREF(data)));
329 * There is no wide-character function such as wdel_wch(), so we must find
330 * all of the cells that comprise a multi-column character and delete them
334 delete_char(FORM *form)
336 int cells = cell_width(form->w, form->currow, form->curcol);
338 form->curcol = cell_base(form->w, form->currow, form->curcol);
339 wmove(form->w, form->currow, form->curcol);
345 #define DeleteChar(form) delete_char(form)
347 #define DeleteChar(form) \
348 wmove((form)->w, (form)->currow, (form)->curcol), \
352 /*---------------------------------------------------------------------------
353 | Facility : libnform
354 | Function : static char *Get_Start_Of_Data(char * buf, int blen)
356 | Description : Return pointer to first non-blank position in buffer.
357 | If buffer is empty return pointer to buffer itself.
359 | Return Values : Pointer to first non-blank position in buffer
360 +--------------------------------------------------------------------------*/
361 NCURSES_INLINE static FIELD_CELL *
362 Get_Start_Of_Data(FIELD_CELL *buf, int blen)
365 FIELD_CELL *end = &buf[blen];
367 assert(buf && blen >= 0);
368 while ((p < end) && ISBLANK(*p))
370 return ((p == end) ? buf : p);
373 /*---------------------------------------------------------------------------
374 | Facility : libnform
375 | Function : static char *After_End_Of_Data(char * buf, int blen)
377 | Description : Return pointer after last non-blank position in buffer.
378 | If buffer is empty, return pointer to buffer itself.
380 | Return Values : Pointer to position after last non-blank position in
382 +--------------------------------------------------------------------------*/
383 NCURSES_INLINE static FIELD_CELL *
384 After_End_Of_Data(FIELD_CELL *buf, int blen)
386 FIELD_CELL *p = &buf[blen];
388 assert(buf && blen >= 0);
389 while ((p > buf) && ISBLANK(p[-1]))
394 /*---------------------------------------------------------------------------
395 | Facility : libnform
396 | Function : static char *Get_First_Whitespace_Character(
397 | char * buf, int blen)
399 | Description : Position to the first whitespace character.
401 | Return Values : Pointer to first whitespace character in buffer.
402 +--------------------------------------------------------------------------*/
403 NCURSES_INLINE static FIELD_CELL *
404 Get_First_Whitespace_Character(FIELD_CELL *buf, int blen)
407 FIELD_CELL *end = &p[blen];
409 assert(buf && blen >= 0);
410 while ((p < end) && !ISBLANK(*p))
412 return ((p == end) ? buf : p);
415 /*---------------------------------------------------------------------------
416 | Facility : libnform
417 | Function : static char *After_Last_Whitespace_Character(
418 | char * buf, int blen)
420 | Description : Get the position after the last whitespace character.
422 | Return Values : Pointer to position after last whitespace character in
424 +--------------------------------------------------------------------------*/
425 NCURSES_INLINE static FIELD_CELL *
426 After_Last_Whitespace_Character(FIELD_CELL *buf, int blen)
428 FIELD_CELL *p = &buf[blen];
430 assert(buf && blen >= 0);
431 while ((p > buf) && !ISBLANK(p[-1]))
436 /* Set this to 1 to use the div_t version. This is a good idea if your
437 compiler has an intrinsic div() support. Unfortunately GNU-C has it
439 N.B.: This only works if form->curcol follows immediately form->currow
440 and both are of type int.
442 #define USE_DIV_T (0)
444 /*---------------------------------------------------------------------------
445 | Facility : libnform
446 | Function : static void Adjust_Cursor_Position(
447 | FORM * form, const char * pos)
449 | Description : Set current row and column of the form to values
450 | corresponding to the buffer position.
453 +--------------------------------------------------------------------------*/
454 NCURSES_INLINE static void
455 Adjust_Cursor_Position(FORM *form, const FIELD_CELL *pos)
460 field = form->current;
461 assert(pos >= field->buf && field->dcols > 0);
462 idx = (int)(pos - field->buf);
464 *((div_t *) & (form->currow)) = div(idx, field->dcols);
466 form->currow = idx / field->dcols;
467 form->curcol = idx - field->cols * form->currow;
469 if (field->drows < form->currow)
473 /*---------------------------------------------------------------------------
474 | Facility : libnform
475 | Function : static void Buffer_To_Window(
476 | const FIELD * field,
479 | Description : Copy the buffer to the window. If it is a multi-line
480 | field, the buffer is split to the lines of the
481 | window without any editing.
484 +--------------------------------------------------------------------------*/
486 Buffer_To_Window(const FIELD *field, WINDOW *win)
494 assert(win && field);
497 width = getmaxx(win);
498 height = getmaxy(win);
500 for (row = 0, pBuffer = field->buf;
502 row++, pBuffer += width)
504 if ((len = (int)(After_End_Of_Data(pBuffer, width) - pBuffer)) > 0)
507 myADDNSTR(win, pBuffer, len);
513 /*---------------------------------------------------------------------------
514 | Facility : libnform
515 | Function : static void Window_To_Buffer(
519 | Description : Copy the content of the window into the buffer.
520 | The multiple lines of a window are simply
521 | concatenated into the buffer. Pad characters in
522 | the window will be replaced by blanks in the buffer.
525 +--------------------------------------------------------------------------*/
527 Window_To_Buffer(WINDOW *win, FIELD *field)
534 assert(win && field && field->buf);
538 height = getmaxy(win);
540 for (row = 0; (row < height) && (row < field->drows); row++)
543 len += myINNSTR(win, p + len, field->dcols);
547 /* replace visual padding character by blanks in buffer */
552 for (i = 0; i < len; i++, p++)
554 if ((unsigned long)CharOf(*p) == ChCharOf(pad)
555 #if USE_WIDEC_SUPPORT
564 /*---------------------------------------------------------------------------
565 | Facility : libnform
566 | Function : static void Synchronize_Buffer(FORM * form)
568 | Description : If there was a change, copy the content of the
569 | window into the buffer, so the buffer is synchronized
570 | with the windows content. We have to indicate that the
571 | buffer needs validation due to the change.
574 +--------------------------------------------------------------------------*/
575 NCURSES_INLINE static void
576 Synchronize_Buffer(FORM *form)
578 if (form->status & _WINDOW_MODIFIED)
580 form->status &= ~_WINDOW_MODIFIED;
581 form->status |= _FCHECK_REQUIRED;
582 Window_To_Buffer(form->w, form->current);
583 wmove(form->w, form->currow, form->curcol);
587 /*---------------------------------------------------------------------------
588 | Facility : libnform
589 | Function : static bool Field_Grown( FIELD *field, int amount)
591 | Description : This function is called for growable dynamic fields
592 | only. It has to increase the buffers and to allocate
593 | a new window for this field.
594 | This function has the side effect to set a new
595 | field-buffer pointer, the dcols and drows values
596 | as well as a new current Window for the field.
598 | Return Values : TRUE - field successfully increased
599 | FALSE - there was some error
600 +--------------------------------------------------------------------------*/
602 Field_Grown(FIELD *field, int amount)
606 if (field && Growable(field))
608 bool single_line_field = Single_Line_Field(field);
609 int old_buflen = Buffer_Length(field);
611 int old_dcols = field->dcols;
612 int old_drows = field->drows;
613 FIELD_CELL *oldbuf = field->buf;
617 FORM *form = field->form;
618 bool need_visual_update = ((form != (FORM *)0) &&
619 (form->status & _POSTED) &&
620 (form->current == field));
622 if (need_visual_update)
623 Synchronize_Buffer(form);
625 if (single_line_field)
627 growth = field->cols * amount;
629 growth = Minimum(field->maxgrow - field->dcols, growth);
630 field->dcols += growth;
631 if (field->dcols == field->maxgrow)
632 field->status &= ~_MAY_GROW;
636 growth = (field->rows + field->nrow) * amount;
638 growth = Minimum(field->maxgrow - field->drows, growth);
639 field->drows += growth;
640 if (field->drows == field->maxgrow)
641 field->status &= ~_MAY_GROW;
643 /* drows, dcols changed, so we get really the new buffer length */
644 new_buflen = Buffer_Length(field);
645 newbuf = (FIELD_CELL *)malloc(Total_Buffer_Size(field));
648 /* restore to previous state */
649 field->dcols = old_dcols;
650 field->drows = old_drows;
651 if ((single_line_field && (field->dcols != field->maxgrow)) ||
652 (!single_line_field && (field->drows != field->maxgrow)))
653 field->status |= _MAY_GROW;
657 /* Copy all the buffers. This is the reason why we can't just use
664 result = TRUE; /* allow sharing of recovery on failure */
666 T((T_CREATE("fieldcell %p"), newbuf));
668 for (i = 0; i <= field->nbuf; i++)
670 new_bp = Address_Of_Nth_Buffer(field, i);
671 old_bp = oldbuf + i * (1 + old_buflen);
672 for (j = 0; j < old_buflen; ++j)
673 new_bp[j] = old_bp[j];
674 while (j < new_buflen)
675 new_bp[j++] = myBLANK;
676 new_bp[new_buflen] = myZEROS;
679 #if USE_WIDEC_SUPPORT
680 if (wresize(field->working, 1, Buffer_Length(field) + 1) == ERR)
684 if (need_visual_update && result)
686 WINDOW *new_window = newpad(field->drows, field->dcols);
690 assert(form != (FORM *)0);
693 form->w = new_window;
694 Set_Field_Window_Attributes(field, form->w);
696 Buffer_To_Window(field, form->w);
698 wmove(form->w, form->currow, form->curcol);
707 /* reflect changes in linked fields */
708 if (field != field->link)
712 for (linked_field = field->link;
713 linked_field != field;
714 linked_field = linked_field->link)
716 linked_field->buf = field->buf;
717 linked_field->drows = field->drows;
718 linked_field->dcols = field->dcols;
724 /* restore old state */
725 field->dcols = old_dcols;
726 field->drows = old_drows;
728 if ((single_line_field &&
729 (field->dcols != field->maxgrow)) ||
730 (!single_line_field &&
731 (field->drows != field->maxgrow)))
732 field->status |= _MAY_GROW;
740 #ifdef NCURSES_MOUSE_VERSION
741 /*---------------------------------------------------------------------------
742 | Facility : libnform
743 | Function : int Field_encloses(FIELD *field, int ry, int rx)
745 | Description : Check if the given coordinates lie within the given field.
747 | Return Values : E_OK - success
748 | E_BAD_ARGUMENT - invalid form pointer
749 | E_SYSTEM_ERROR - form has no current field or
751 +--------------------------------------------------------------------------*/
753 Field_encloses(FIELD *field, int ry, int rx)
755 T((T_CALLED("Field_encloses(%p)"), field));
758 && (field->frow + field->rows) > ry
760 && (field->fcol + field->cols) > rx)
764 RETURN(E_INVALID_FIELD);
768 /*---------------------------------------------------------------------------
769 | Facility : libnform
770 | Function : int _nc_Position_Form_Cursor(FORM * form)
772 | Description : Position the cursor in the window for the current
773 | field to be in sync. with the currow and curcol
776 | Return Values : E_OK - success
777 | E_BAD_ARGUMENT - invalid form pointer
778 | E_SYSTEM_ERROR - form has no current field or
780 +--------------------------------------------------------------------------*/
782 _nc_Position_Form_Cursor(FORM *form)
788 return (E_BAD_ARGUMENT);
790 if (!form->w || !form->current)
791 return (E_SYSTEM_ERROR);
793 field = form->current;
794 formwin = Get_Form_Window(form);
796 wmove(form->w, form->currow, form->curcol);
797 if (Has_Invisible_Parts(field))
799 /* in this case fieldwin isn't derived from formwin, so we have
800 to move the cursor in formwin by hand... */
802 field->frow + form->currow - form->toprow,
803 field->fcol + form->curcol - form->begincol);
811 /*---------------------------------------------------------------------------
812 | Facility : libnform
813 | Function : int _nc_Refresh_Current_Field(FORM * form)
815 | Description : Propagate the changes in the fields window to the
816 | window of the form.
818 | Return Values : E_OK - on success
819 | E_BAD_ARGUMENT - invalid form pointer
820 | E_SYSTEM_ERROR - general error
821 +--------------------------------------------------------------------------*/
823 _nc_Refresh_Current_Field(FORM *form)
828 T((T_CALLED("_nc_Refresh_Current_Field(%p)"), form));
831 RETURN(E_BAD_ARGUMENT);
833 if (!form->w || !form->current)
834 RETURN(E_SYSTEM_ERROR);
836 field = form->current;
837 formwin = Get_Form_Window(form);
839 if (field->opts & O_PUBLIC)
841 if (Is_Scroll_Field(field))
843 /* Again, in this case the fieldwin isn't derived from formwin,
844 so we have to perform a copy operation. */
845 if (Single_Line_Field(field))
847 /* horizontal scrolling */
848 if (form->curcol < form->begincol)
849 form->begincol = form->curcol;
852 if (form->curcol >= (form->begincol + field->cols))
853 form->begincol = form->curcol - field->cols + 1;
862 field->cols + field->fcol - 1,
867 /* A multi-line, i.e. vertical scrolling field */
868 int row_after_bottom, first_modified_row, first_unmodified_row;
870 if (field->drows > field->rows)
872 row_after_bottom = form->toprow + field->rows;
873 if (form->currow < form->toprow)
875 form->toprow = form->currow;
876 field->status |= _NEWTOP;
878 if (form->currow >= row_after_bottom)
880 form->toprow = form->currow - field->rows + 1;
881 field->status |= _NEWTOP;
883 if (field->status & _NEWTOP)
885 /* means we have to copy whole range */
886 first_modified_row = form->toprow;
887 first_unmodified_row = first_modified_row + field->rows;
888 field->status &= ~_NEWTOP;
892 /* we try to optimize : finding the range of touched
894 first_modified_row = form->toprow;
895 while (first_modified_row < row_after_bottom)
897 if (is_linetouched(form->w, first_modified_row))
899 first_modified_row++;
901 first_unmodified_row = first_modified_row;
902 while (first_unmodified_row < row_after_bottom)
904 if (!is_linetouched(form->w, first_unmodified_row))
906 first_unmodified_row++;
912 first_modified_row = form->toprow;
913 first_unmodified_row = first_modified_row + field->rows;
915 if (first_unmodified_row != first_modified_row)
920 field->frow + first_modified_row - form->toprow,
922 field->frow + first_unmodified_row - form->toprow - 1,
923 field->cols + field->fcol - 1,
930 /* if the field-window is simply a derived window, i.e. contains no
931 * invisible parts, the whole thing is trivial
937 returnCode(_nc_Position_Form_Cursor(form));
940 /*---------------------------------------------------------------------------
941 | Facility : libnform
942 | Function : static void Perform_Justification(
946 | Description : Output field with requested justification
949 +--------------------------------------------------------------------------*/
951 Perform_Justification(FIELD *field, WINDOW *win)
957 bp = Get_Start_Of_Data(field->buf, Buffer_Length(field));
958 len = (int)(After_End_Of_Data(field->buf, Buffer_Length(field)) - bp);
962 assert(win && (field->drows == 1) && (field->dcols == field->cols));
969 col = (field->cols - len) / 2;
972 col = field->cols - len;
979 myADDNSTR(win, bp, len);
983 /*---------------------------------------------------------------------------
984 | Facility : libnform
985 | Function : static void Undo_Justification(
989 | Description : Display field without any justification, i.e.
993 +--------------------------------------------------------------------------*/
995 Undo_Justification(FIELD *field, WINDOW *win)
1000 bp = Get_Start_Of_Data(field->buf, Buffer_Length(field));
1001 len = (int)(After_End_Of_Data(field->buf, Buffer_Length(field)) - bp);
1007 myADDNSTR(win, bp, len);
1011 /*---------------------------------------------------------------------------
1012 | Facility : libnform
1013 | Function : static bool Check_Char(
1016 | TypeArgument *argp)
1018 | Description : Perform a single character check for character ch
1019 | according to the fieldtype instance.
1021 | Return Values : TRUE - Character is valid
1022 | FALSE - Character is invalid
1023 +--------------------------------------------------------------------------*/
1025 Check_Char(FIELDTYPE *typ, int ch, TypeArgument *argp)
1029 if (typ->status & _LINKED_TYPE)
1033 Check_Char(typ->left, ch, argp->left) ||
1034 Check_Char(typ->right, ch, argp->right));
1039 return typ->ccheck(ch, (void *)argp);
1042 return (!iscntrl(UChar(ch)) ? TRUE : FALSE);
1045 /*---------------------------------------------------------------------------
1046 | Facility : libnform
1047 | Function : static int Display_Or_Erase_Field(
1051 | Description : Create a subwindow for the field and display the
1052 | buffer contents (apply justification if required)
1053 | or simply erase the field.
1055 | Return Values : E_OK - on success
1056 | E_SYSTEM_ERROR - some error (typical no memory)
1057 +--------------------------------------------------------------------------*/
1059 Display_Or_Erase_Field(FIELD *field, bool bEraseFlag)
1065 return E_SYSTEM_ERROR;
1067 fwin = Get_Form_Window(field->form);
1069 field->rows, field->cols, field->frow, field->fcol);
1072 return E_SYSTEM_ERROR;
1075 if (field->opts & O_VISIBLE)
1076 Set_Field_Window_Attributes(field, win);
1078 wattrset(win, WINDOW_ATTRS(fwin));
1084 if (field->opts & O_PUBLIC)
1086 if (Justification_Allowed(field))
1087 Perform_Justification(field, win);
1089 Buffer_To_Window(field, win);
1091 field->status &= ~_NEWTOP;
1098 /* Macros to preset the bEraseFlag */
1099 #define Display_Field(field) Display_Or_Erase_Field(field,FALSE)
1100 #define Erase_Field(field) Display_Or_Erase_Field(field,TRUE)
1102 /*---------------------------------------------------------------------------
1103 | Facility : libnform
1104 | Function : static int Synchronize_Field(FIELD * field)
1106 | Description : Synchronize the windows content with the value in
1109 | Return Values : E_OK - success
1110 | E_BAD_ARGUMENT - invalid field pointer
1111 | E_SYSTEM_ERROR - some severe basic error
1112 +--------------------------------------------------------------------------*/
1114 Synchronize_Field(FIELD *field)
1120 return (E_BAD_ARGUMENT);
1122 if (((form = field->form) != (FORM *)0)
1123 && Field_Really_Appears(field))
1125 if (field == form->current)
1127 form->currow = form->curcol = form->toprow = form->begincol = 0;
1130 if ((field->opts & O_PUBLIC) && Justification_Allowed(field))
1131 Undo_Justification(field, form->w);
1133 Buffer_To_Window(field, form->w);
1135 field->status |= _NEWTOP;
1136 res = _nc_Refresh_Current_Field(form);
1139 res = Display_Field(field);
1141 field->status |= _CHANGED;
1145 /*---------------------------------------------------------------------------
1146 | Facility : libnform
1147 | Function : static int Synchronize_Linked_Fields(FIELD * field)
1149 | Description : Propagate the Synchronize_Field function to all linked
1150 | fields. The first error that occurs in the sequence
1151 | of updates is the return value.
1153 | Return Values : E_OK - success
1154 | E_BAD_ARGUMENT - invalid field pointer
1155 | E_SYSTEM_ERROR - some severe basic error
1156 +--------------------------------------------------------------------------*/
1158 Synchronize_Linked_Fields(FIELD *field)
1160 FIELD *linked_field;
1165 return (E_BAD_ARGUMENT);
1168 return (E_SYSTEM_ERROR);
1170 for (linked_field = field->link;
1171 linked_field != field;
1172 linked_field = linked_field->link)
1174 if (((syncres = Synchronize_Field(linked_field)) != E_OK) &&
1181 /*---------------------------------------------------------------------------
1182 | Facility : libnform
1183 | Function : int _nc_Synchronize_Attributes(FIELD * field)
1185 | Description : If a fields visual attributes have changed, this
1186 | routine is called to propagate those changes to the
1189 | Return Values : E_OK - success
1190 | E_BAD_ARGUMENT - invalid field pointer
1191 | E_SYSTEM_ERROR - some severe basic error
1192 +--------------------------------------------------------------------------*/
1194 _nc_Synchronize_Attributes(FIELD *field)
1200 T((T_CALLED("_nc_Synchronize_Attributes(%p)"), field));
1203 returnCode(E_BAD_ARGUMENT);
1205 CHECKPOS(field->form);
1206 if (((form = field->form) != (FORM *)0)
1207 && Field_Really_Appears(field))
1209 if (form->current == field)
1211 Synchronize_Buffer(form);
1212 Set_Field_Window_Attributes(field, form->w);
1214 wmove(form->w, form->currow, form->curcol);
1216 if (field->opts & O_PUBLIC)
1218 if (Justification_Allowed(field))
1219 Undo_Justification(field, form->w);
1221 Buffer_To_Window(field, form->w);
1225 formwin = Get_Form_Window(form);
1226 copywin(form->w, formwin,
1228 field->frow, field->fcol,
1229 field->rows - 1, field->cols - 1, 0);
1231 Buffer_To_Window(field, form->w);
1232 field->status |= _NEWTOP; /* fake refresh to paint all */
1233 _nc_Refresh_Current_Field(form);
1238 res = Display_Field(field);
1245 /*---------------------------------------------------------------------------
1246 | Facility : libnform
1247 | Function : int _nc_Synchronize_Options(FIELD * field,
1248 | Field_Options newopts)
1250 | Description : If a fields options have changed, this routine is
1251 | called to propagate these changes to the screen and
1252 | to really change the behavior of the field.
1254 | Return Values : E_OK - success
1255 | E_BAD_ARGUMENT - invalid field pointer
1256 | E_CURRENT - field is the current one
1257 | E_SYSTEM_ERROR - some severe basic error
1258 +--------------------------------------------------------------------------*/
1260 _nc_Synchronize_Options(FIELD *field, Field_Options newopts)
1262 Field_Options oldopts;
1263 Field_Options changed_opts;
1267 T((T_CALLED("_nc_Synchronize_Options(%p,%#x)"), field, newopts));
1270 returnCode(E_BAD_ARGUMENT);
1272 oldopts = field->opts;
1273 changed_opts = oldopts ^ newopts;
1274 field->opts = newopts;
1279 if (form->current == field)
1281 field->opts = oldopts;
1282 returnCode(E_CURRENT);
1285 if (form->status & _POSTED)
1287 if ((form->curpage == field->page))
1289 if (changed_opts & O_VISIBLE)
1291 if (newopts & O_VISIBLE)
1292 res = Display_Field(field);
1294 res = Erase_Field(field);
1298 if ((changed_opts & O_PUBLIC) &&
1299 (newopts & O_VISIBLE))
1300 res = Display_Field(field);
1306 if (changed_opts & O_STATIC)
1308 bool single_line_field = Single_Line_Field(field);
1311 if (newopts & O_STATIC)
1313 /* the field becomes now static */
1314 field->status &= ~_MAY_GROW;
1315 /* if actually we have no hidden columns, justification may
1317 if (single_line_field &&
1318 (field->cols == field->dcols) &&
1319 (field->just != NO_JUSTIFICATION) &&
1320 Field_Really_Appears(field))
1322 res2 = Display_Field(field);
1327 /* field is no longer static */
1328 if ((field->maxgrow == 0) ||
1329 (single_line_field && (field->dcols < field->maxgrow)) ||
1330 (!single_line_field && (field->drows < field->maxgrow)))
1332 field->status |= _MAY_GROW;
1333 /* a field with justification now changes its behavior,
1334 so we must redisplay it */
1335 if (single_line_field &&
1336 (field->just != NO_JUSTIFICATION) &&
1337 Field_Really_Appears(field))
1339 res2 = Display_Field(field);
1350 /*---------------------------------------------------------------------------
1351 | Facility : libnform
1352 | Function : int _nc_Set_Current_Field(FORM * form,
1355 | Description : Make the newfield the new current field.
1357 | Return Values : E_OK - success
1358 | E_BAD_ARGUMENT - invalid form or field pointer
1359 | E_SYSTEM_ERROR - some severe basic error
1360 | E_NOT_CONNECTED - no fields are connected to the form
1361 +--------------------------------------------------------------------------*/
1363 _nc_Set_Current_Field(FORM *form, FIELD *newfield)
1368 T((T_CALLED("_nc_Set_Current_Field(%p,%p)"), form, newfield));
1370 if (!form || !newfield || !form->current || (newfield->form != form))
1371 returnCode(E_BAD_ARGUMENT);
1373 if ((form->status & _IN_DRIVER))
1374 returnCode(E_BAD_STATE);
1377 returnCode(E_NOT_CONNECTED);
1379 field = form->current;
1381 if ((field != newfield) ||
1382 !(form->status & _POSTED))
1385 (field->opts & O_VISIBLE) &&
1386 (field->form->curpage == field->page))
1388 _nc_Refresh_Current_Field(form);
1389 if (field->opts & O_PUBLIC)
1391 if (field->drows > field->rows)
1393 if (form->toprow == 0)
1394 field->status &= ~_NEWTOP;
1396 field->status |= _NEWTOP;
1400 if (Justification_Allowed(field))
1402 Window_To_Buffer(form->w, field);
1404 Perform_Justification(field, form->w);
1410 form->w = (WINDOW *)0;
1415 if (Has_Invisible_Parts(field))
1416 new_window = newpad(field->drows, field->dcols);
1418 new_window = derwin(Get_Form_Window(form),
1419 field->rows, field->cols, field->frow, field->fcol);
1422 returnCode(E_SYSTEM_ERROR);
1424 form->current = field;
1428 form->w = new_window;
1430 form->status &= ~_WINDOW_MODIFIED;
1431 Set_Field_Window_Attributes(field, form->w);
1433 if (Has_Invisible_Parts(field))
1436 Buffer_To_Window(field, form->w);
1440 if (Justification_Allowed(field))
1443 Undo_Justification(field, form->w);
1448 untouchwin(form->w);
1451 form->currow = form->curcol = form->toprow = form->begincol = 0;
1455 /*----------------------------------------------------------------------------
1456 Intra-Field Navigation routines
1457 --------------------------------------------------------------------------*/
1459 /*---------------------------------------------------------------------------
1460 | Facility : libnform
1461 | Function : static int IFN_Next_Character(FORM * form)
1463 | Description : Move to the next character in the field. In a multi-line
1464 | field this wraps at the end of the line.
1466 | Return Values : E_OK - success
1467 | E_REQUEST_DENIED - at the rightmost position
1468 +--------------------------------------------------------------------------*/
1470 IFN_Next_Character(FORM *form)
1472 FIELD *field = form->current;
1473 int step = myWCWIDTH(form->w, form->currow, form->curcol);
1475 T((T_CALLED("IFN_Next_Character(%p)"), form));
1476 if ((form->curcol += step) == field->dcols)
1478 if ((++(form->currow)) == field->drows)
1480 #if GROW_IF_NAVIGATE
1481 if (!Single_Line_Field(field) && Field_Grown(field, 1))
1488 #if GROW_IF_NAVIGATE
1489 if (Single_Line_Field(field) && Field_Grown(field, 1))
1492 form->curcol -= step;
1493 returnCode(E_REQUEST_DENIED);
1500 /*---------------------------------------------------------------------------
1501 | Facility : libnform
1502 | Function : static int IFN_Previous_Character(FORM * form)
1504 | Description : Move to the previous character in the field. In a
1505 | multi-line field this wraps and the beginning of the
1508 | Return Values : E_OK - success
1509 | E_REQUEST_DENIED - at the leftmost position
1510 +--------------------------------------------------------------------------*/
1512 IFN_Previous_Character(FORM *form)
1514 int amount = myWCWIDTH(form->w, form->currow, form->curcol - 1);
1515 int oldcol = form->curcol;
1517 T((T_CALLED("IFN_Previous_Character(%p)"), form));
1518 if ((form->curcol -= amount) < 0)
1520 if ((--(form->currow)) < 0)
1523 form->curcol = oldcol;
1524 returnCode(E_REQUEST_DENIED);
1526 form->curcol = form->current->dcols - 1;
1531 /*---------------------------------------------------------------------------
1532 | Facility : libnform
1533 | Function : static int IFN_Next_Line(FORM * form)
1535 | Description : Move to the beginning of the next line in the field
1537 | Return Values : E_OK - success
1538 | E_REQUEST_DENIED - at the last line
1539 +--------------------------------------------------------------------------*/
1541 IFN_Next_Line(FORM *form)
1543 FIELD *field = form->current;
1545 T((T_CALLED("IFN_Next_Line(%p)"), form));
1546 if ((++(form->currow)) == field->drows)
1548 #if GROW_IF_NAVIGATE
1549 if (!Single_Line_Field(field) && Field_Grown(field, 1))
1553 returnCode(E_REQUEST_DENIED);
1559 /*---------------------------------------------------------------------------
1560 | Facility : libnform
1561 | Function : static int IFN_Previous_Line(FORM * form)
1563 | Description : Move to the beginning of the previous line in the field
1565 | Return Values : E_OK - success
1566 | E_REQUEST_DENIED - at the first line
1567 +--------------------------------------------------------------------------*/
1569 IFN_Previous_Line(FORM *form)
1571 T((T_CALLED("IFN_Previous_Line(%p)"), form));
1572 if ((--(form->currow)) < 0)
1575 returnCode(E_REQUEST_DENIED);
1581 /*---------------------------------------------------------------------------
1582 | Facility : libnform
1583 | Function : static int IFN_Next_Word(FORM * form)
1585 | Description : Move to the beginning of the next word in the field.
1587 | Return Values : E_OK - success
1588 | E_REQUEST_DENIED - there is no next word
1589 +--------------------------------------------------------------------------*/
1591 IFN_Next_Word(FORM *form)
1593 FIELD *field = form->current;
1594 FIELD_CELL *bp = Address_Of_Current_Position_In_Buffer(form);
1598 T((T_CALLED("IFN_Next_Word(%p)"), form));
1600 /* We really need access to the data, so we have to synchronize */
1601 Synchronize_Buffer(form);
1603 /* Go to the first whitespace after the current position (including
1604 current position). This is then the starting point to look for the
1605 next non-blank data */
1606 s = Get_First_Whitespace_Character(bp, Buffer_Length(field) -
1607 (int)(bp - field->buf));
1609 /* Find the start of the next word */
1610 t = Get_Start_Of_Data(s, Buffer_Length(field) -
1611 (int)(s - field->buf));
1612 #if !FRIENDLY_PREV_NEXT_WORD
1614 returnCode(E_REQUEST_DENIED);
1618 Adjust_Cursor_Position(form, t);
1623 /*---------------------------------------------------------------------------
1624 | Facility : libnform
1625 | Function : static int IFN_Previous_Word(FORM * form)
1627 | Description : Move to the beginning of the previous word in the field.
1629 | Return Values : E_OK - success
1630 | E_REQUEST_DENIED - there is no previous word
1631 +--------------------------------------------------------------------------*/
1633 IFN_Previous_Word(FORM *form)
1635 FIELD *field = form->current;
1636 FIELD_CELL *bp = Address_Of_Current_Position_In_Buffer(form);
1641 T((T_CALLED("IFN_Previous_Word(%p)"), form));
1643 /* We really need access to the data, so we have to synchronize */
1644 Synchronize_Buffer(form);
1646 s = After_End_Of_Data(field->buf, (int)(bp - field->buf));
1647 /* s points now right after the last non-blank in the buffer before bp.
1648 If bp was in a word, s equals bp. In this case we must find the last
1649 whitespace in the buffer before bp and repeat the game to really find
1650 the previous word! */
1654 /* And next call now goes backward to look for the last whitespace
1655 before that, pointing right after this, so it points to the begin
1656 of the previous word.
1658 t = After_Last_Whitespace_Character(field->buf, (int)(s - field->buf));
1659 #if !FRIENDLY_PREV_NEXT_WORD
1661 returnCode(E_REQUEST_DENIED);
1665 /* and do it again, replacing bp by t */
1666 s = After_End_Of_Data(field->buf, (int)(t - field->buf));
1667 t = After_Last_Whitespace_Character(field->buf, (int)(s - field->buf));
1668 #if !FRIENDLY_PREV_NEXT_WORD
1670 returnCode(E_REQUEST_DENIED);
1673 Adjust_Cursor_Position(form, t);
1677 /*---------------------------------------------------------------------------
1678 | Facility : libnform
1679 | Function : static int IFN_Beginning_Of_Field(FORM * form)
1681 | Description : Place the cursor at the first non-pad character in
1684 | Return Values : E_OK - success
1685 +--------------------------------------------------------------------------*/
1687 IFN_Beginning_Of_Field(FORM *form)
1689 FIELD *field = form->current;
1691 T((T_CALLED("IFN_Beginning_Of_Field(%p)"), form));
1692 Synchronize_Buffer(form);
1693 Adjust_Cursor_Position(form,
1694 Get_Start_Of_Data(field->buf, Buffer_Length(field)));
1698 /*---------------------------------------------------------------------------
1699 | Facility : libnform
1700 | Function : static int IFN_End_Of_Field(FORM * form)
1702 | Description : Place the cursor after the last non-pad character in
1703 | the field. If the field occupies the last position in
1704 | the buffer, the cursor is positioned on the last
1707 | Return Values : E_OK - success
1708 +--------------------------------------------------------------------------*/
1710 IFN_End_Of_Field(FORM *form)
1712 FIELD *field = form->current;
1715 T((T_CALLED("IFN_End_Of_Field(%p)"), form));
1716 Synchronize_Buffer(form);
1717 pos = After_End_Of_Data(field->buf, Buffer_Length(field));
1718 if (pos == (field->buf + Buffer_Length(field)))
1720 Adjust_Cursor_Position(form, pos);
1724 /*---------------------------------------------------------------------------
1725 | Facility : libnform
1726 | Function : static int IFN_Beginning_Of_Line(FORM * form)
1728 | Description : Place the cursor on the first non-pad character in
1729 | the current line of the field.
1731 | Return Values : E_OK - success
1732 +--------------------------------------------------------------------------*/
1734 IFN_Beginning_Of_Line(FORM *form)
1736 FIELD *field = form->current;
1738 T((T_CALLED("IFN_Beginning_Of_Line(%p)"), form));
1739 Synchronize_Buffer(form);
1740 Adjust_Cursor_Position(form,
1741 Get_Start_Of_Data(Address_Of_Current_Row_In_Buffer(form),
1746 /*---------------------------------------------------------------------------
1747 | Facility : libnform
1748 | Function : static int IFN_End_Of_Line(FORM * form)
1750 | Description : Place the cursor after the last non-pad character in the
1751 | current line of the field. If the field occupies the
1752 | last column in the line, the cursor is positioned on the
1753 | last character of the line.
1755 | Return Values : E_OK - success
1756 +--------------------------------------------------------------------------*/
1758 IFN_End_Of_Line(FORM *form)
1760 FIELD *field = form->current;
1764 T((T_CALLED("IFN_End_Of_Line(%p)"), form));
1765 Synchronize_Buffer(form);
1766 bp = Address_Of_Current_Row_In_Buffer(form);
1767 pos = After_End_Of_Data(bp, field->dcols);
1768 if (pos == (bp + field->dcols))
1770 Adjust_Cursor_Position(form, pos);
1774 /*---------------------------------------------------------------------------
1775 | Facility : libnform
1776 | Function : static int IFN_Left_Character(FORM * form)
1778 | Description : Move one character to the left in the current line.
1779 | This doesn't cycle.
1781 | Return Values : E_OK - success
1782 | E_REQUEST_DENIED - already in first column
1783 +--------------------------------------------------------------------------*/
1785 IFN_Left_Character(FORM *form)
1787 int amount = myWCWIDTH(form->w, form->currow, form->curcol - 1);
1788 int oldcol = form->curcol;
1790 T((T_CALLED("IFN_Left_Character(%p)"), form));
1791 if ((form->curcol -= amount) < 0)
1793 form->curcol = oldcol;
1794 returnCode(E_REQUEST_DENIED);
1799 /*---------------------------------------------------------------------------
1800 | Facility : libnform
1801 | Function : static int IFN_Right_Character(FORM * form)
1803 | Description : Move one character to the right in the current line.
1804 | This doesn't cycle.
1806 | Return Values : E_OK - success
1807 | E_REQUEST_DENIED - already in last column
1808 +--------------------------------------------------------------------------*/
1810 IFN_Right_Character(FORM *form)
1812 int amount = myWCWIDTH(form->w, form->currow, form->curcol);
1813 int oldcol = form->curcol;
1815 T((T_CALLED("IFN_Right_Character(%p)"), form));
1816 if ((form->curcol += amount) >= form->current->dcols)
1818 #if GROW_IF_NAVIGATE
1819 FIELD *field = form->current;
1821 if (Single_Line_Field(field) && Field_Grown(field, 1))
1824 form->curcol = oldcol;
1825 returnCode(E_REQUEST_DENIED);
1830 /*---------------------------------------------------------------------------
1831 | Facility : libnform
1832 | Function : static int IFN_Up_Character(FORM * form)
1834 | Description : Move one line up. This doesn't cycle through the lines
1837 | Return Values : E_OK - success
1838 | E_REQUEST_DENIED - already in last column
1839 +--------------------------------------------------------------------------*/
1841 IFN_Up_Character(FORM *form)
1843 T((T_CALLED("IFN_Up_Character(%p)"), form));
1844 if ((--(form->currow)) < 0)
1847 returnCode(E_REQUEST_DENIED);
1852 /*---------------------------------------------------------------------------
1853 | Facility : libnform
1854 | Function : static int IFN_Down_Character(FORM * form)
1856 | Description : Move one line down. This doesn't cycle through the
1857 | lines of the field.
1859 | Return Values : E_OK - success
1860 | E_REQUEST_DENIED - already in last column
1861 +--------------------------------------------------------------------------*/
1863 IFN_Down_Character(FORM *form)
1865 FIELD *field = form->current;
1867 T((T_CALLED("IFN_Down_Character(%p)"), form));
1868 if ((++(form->currow)) == field->drows)
1870 #if GROW_IF_NAVIGATE
1871 if (!Single_Line_Field(field) && Field_Grown(field, 1))
1875 returnCode(E_REQUEST_DENIED);
1879 /*----------------------------------------------------------------------------
1880 END of Intra-Field Navigation routines
1881 --------------------------------------------------------------------------*/
1883 /*----------------------------------------------------------------------------
1884 Vertical scrolling helper routines
1885 --------------------------------------------------------------------------*/
1887 /*---------------------------------------------------------------------------
1888 | Facility : libnform
1889 | Function : static int VSC_Generic(FORM *form, int nlines)
1891 | Description : Scroll multi-line field forward (nlines>0) or
1892 | backward (nlines<0) this many lines.
1894 | Return Values : E_OK - success
1895 | E_REQUEST_DENIED - can't scroll
1896 +--------------------------------------------------------------------------*/
1898 VSC_Generic(FORM *form, int nlines)
1900 FIELD *field = form->current;
1901 int res = E_REQUEST_DENIED;
1902 int rows_to_go = (nlines > 0 ? nlines : -nlines);
1906 if ((rows_to_go + form->toprow) > (field->drows - field->rows))
1907 rows_to_go = (field->drows - field->rows - form->toprow);
1911 form->currow += rows_to_go;
1912 form->toprow += rows_to_go;
1918 if (rows_to_go > form->toprow)
1919 rows_to_go = form->toprow;
1923 form->currow -= rows_to_go;
1924 form->toprow -= rows_to_go;
1930 /*----------------------------------------------------------------------------
1931 End of Vertical scrolling helper routines
1932 --------------------------------------------------------------------------*/
1934 /*----------------------------------------------------------------------------
1935 Vertical scrolling routines
1936 --------------------------------------------------------------------------*/
1938 /*---------------------------------------------------------------------------
1939 | Facility : libnform
1940 | Function : static int Vertical_Scrolling(
1941 | int (* const fct) (FORM *),
1944 | Description : Performs the generic vertical scrolling routines.
1945 | This has to check for a multi-line field and to set
1946 | the _NEWTOP flag if scrolling really occurred.
1948 | Return Values : Propagated error code from low-level driver calls
1949 +--------------------------------------------------------------------------*/
1951 Vertical_Scrolling(int (*const fct) (FORM *), FORM *form)
1953 int res = E_REQUEST_DENIED;
1955 if (!Single_Line_Field(form->current))
1959 form->current->status |= _NEWTOP;
1964 /*---------------------------------------------------------------------------
1965 | Facility : libnform
1966 | Function : static int VSC_Scroll_Line_Forward(FORM * form)
1968 | Description : Scroll multi-line field forward a line
1970 | Return Values : E_OK - success
1971 | E_REQUEST_DENIED - no data ahead
1972 +--------------------------------------------------------------------------*/
1974 VSC_Scroll_Line_Forward(FORM *form)
1976 T((T_CALLED("VSC_Scroll_Line_Forward(%p)"), form));
1977 returnCode(VSC_Generic(form, 1));
1980 /*---------------------------------------------------------------------------
1981 | Facility : libnform
1982 | Function : static int VSC_Scroll_Line_Backward(FORM * form)
1984 | Description : Scroll multi-line field backward a line
1986 | Return Values : E_OK - success
1987 | E_REQUEST_DENIED - no data behind
1988 +--------------------------------------------------------------------------*/
1990 VSC_Scroll_Line_Backward(FORM *form)
1992 T((T_CALLED("VSC_Scroll_Line_Backward(%p)"), form));
1993 returnCode(VSC_Generic(form, -1));
1996 /*---------------------------------------------------------------------------
1997 | Facility : libnform
1998 | Function : static int VSC_Scroll_Page_Forward(FORM * form)
2000 | Description : Scroll a multi-line field forward a page
2002 | Return Values : E_OK - success
2003 | E_REQUEST_DENIED - no data ahead
2004 +--------------------------------------------------------------------------*/
2006 VSC_Scroll_Page_Forward(FORM *form)
2008 T((T_CALLED("VSC_Scroll_Page_Forward(%p)"), form));
2009 returnCode(VSC_Generic(form, form->current->rows));
2012 /*---------------------------------------------------------------------------
2013 | Facility : libnform
2014 | Function : static int VSC_Scroll_Half_Page_Forward(FORM * form)
2016 | Description : Scroll a multi-line field forward half a page
2018 | Return Values : E_OK - success
2019 | E_REQUEST_DENIED - no data ahead
2020 +--------------------------------------------------------------------------*/
2022 VSC_Scroll_Half_Page_Forward(FORM *form)
2024 T((T_CALLED("VSC_Scroll_Half_Page_Forward(%p)"), form));
2025 returnCode(VSC_Generic(form, (form->current->rows + 1) / 2));
2028 /*---------------------------------------------------------------------------
2029 | Facility : libnform
2030 | Function : static int VSC_Scroll_Page_Backward(FORM * form)
2032 | Description : Scroll a multi-line field backward a page
2034 | Return Values : E_OK - success
2035 | E_REQUEST_DENIED - no data behind
2036 +--------------------------------------------------------------------------*/
2038 VSC_Scroll_Page_Backward(FORM *form)
2040 T((T_CALLED("VSC_Scroll_Page_Backward(%p)"), form));
2041 returnCode(VSC_Generic(form, -(form->current->rows)));
2044 /*---------------------------------------------------------------------------
2045 | Facility : libnform
2046 | Function : static int VSC_Scroll_Half_Page_Backward(FORM * form)
2048 | Description : Scroll a multi-line field backward half a page
2050 | Return Values : E_OK - success
2051 | E_REQUEST_DENIED - no data behind
2052 +--------------------------------------------------------------------------*/
2054 VSC_Scroll_Half_Page_Backward(FORM *form)
2056 T((T_CALLED("VSC_Scroll_Half_Page_Backward(%p)"), form));
2057 returnCode(VSC_Generic(form, -((form->current->rows + 1) / 2)));
2059 /*----------------------------------------------------------------------------
2060 End of Vertical scrolling routines
2061 --------------------------------------------------------------------------*/
2063 /*----------------------------------------------------------------------------
2064 Horizontal scrolling helper routines
2065 --------------------------------------------------------------------------*/
2067 /*---------------------------------------------------------------------------
2068 | Facility : libnform
2069 | Function : static int HSC_Generic(FORM *form, int ncolumns)
2071 | Description : Scroll single-line field forward (ncolumns>0) or
2072 | backward (ncolumns<0) this many columns.
2074 | Return Values : E_OK - success
2075 | E_REQUEST_DENIED - can't scroll
2076 +--------------------------------------------------------------------------*/
2078 HSC_Generic(FORM *form, int ncolumns)
2080 FIELD *field = form->current;
2081 int res = E_REQUEST_DENIED;
2082 int cols_to_go = (ncolumns > 0 ? ncolumns : -ncolumns);
2086 if ((cols_to_go + form->begincol) > (field->dcols - field->cols))
2087 cols_to_go = field->dcols - field->cols - form->begincol;
2091 form->curcol += cols_to_go;
2092 form->begincol += cols_to_go;
2098 if (cols_to_go > form->begincol)
2099 cols_to_go = form->begincol;
2103 form->curcol -= cols_to_go;
2104 form->begincol -= cols_to_go;
2110 /*----------------------------------------------------------------------------
2111 End of Horizontal scrolling helper routines
2112 --------------------------------------------------------------------------*/
2114 /*----------------------------------------------------------------------------
2115 Horizontal scrolling routines
2116 --------------------------------------------------------------------------*/
2118 /*---------------------------------------------------------------------------
2119 | Facility : libnform
2120 | Function : static int Horizontal_Scrolling(
2121 | int (* const fct) (FORM *),
2124 | Description : Performs the generic horizontal scrolling routines.
2125 | This has to check for a single-line field.
2127 | Return Values : Propagated error code from low-level driver calls
2128 +--------------------------------------------------------------------------*/
2130 Horizontal_Scrolling(int (*const fct) (FORM *), FORM *form)
2132 if (Single_Line_Field(form->current))
2135 return (E_REQUEST_DENIED);
2138 /*---------------------------------------------------------------------------
2139 | Facility : libnform
2140 | Function : static int HSC_Scroll_Char_Forward(FORM * form)
2142 | Description : Scroll single-line field forward a character
2144 | Return Values : E_OK - success
2145 | E_REQUEST_DENIED - no data ahead
2146 +--------------------------------------------------------------------------*/
2148 HSC_Scroll_Char_Forward(FORM *form)
2150 T((T_CALLED("HSC_Scroll_Char_Forward(%p)"), form));
2151 returnCode(HSC_Generic(form, 1));
2154 /*---------------------------------------------------------------------------
2155 | Facility : libnform
2156 | Function : static int HSC_Scroll_Char_Backward(FORM * form)
2158 | Description : Scroll single-line field backward a character
2160 | Return Values : E_OK - success
2161 | E_REQUEST_DENIED - no data behind
2162 +--------------------------------------------------------------------------*/
2164 HSC_Scroll_Char_Backward(FORM *form)
2166 T((T_CALLED("HSC_Scroll_Char_Backward(%p)"), form));
2167 returnCode(HSC_Generic(form, -1));
2170 /*---------------------------------------------------------------------------
2171 | Facility : libnform
2172 | Function : static int HSC_Horizontal_Line_Forward(FORM* form)
2174 | Description : Scroll single-line field forward a line
2176 | Return Values : E_OK - success
2177 | E_REQUEST_DENIED - no data ahead
2178 +--------------------------------------------------------------------------*/
2180 HSC_Horizontal_Line_Forward(FORM *form)
2182 T((T_CALLED("HSC_Horizontal_Line_Forward(%p)"), form));
2183 returnCode(HSC_Generic(form, form->current->cols));
2186 /*---------------------------------------------------------------------------
2187 | Facility : libnform
2188 | Function : static int HSC_Horizontal_Half_Line_Forward(FORM* form)
2190 | Description : Scroll single-line field forward half a line
2192 | Return Values : E_OK - success
2193 | E_REQUEST_DENIED - no data ahead
2194 +--------------------------------------------------------------------------*/
2196 HSC_Horizontal_Half_Line_Forward(FORM *form)
2198 T((T_CALLED("HSC_Horizontal_Half_Line_Forward(%p)"), form));
2199 returnCode(HSC_Generic(form, (form->current->cols + 1) / 2));
2202 /*---------------------------------------------------------------------------
2203 | Facility : libnform
2204 | Function : static int HSC_Horizontal_Line_Backward(FORM* form)
2206 | Description : Scroll single-line field backward a line
2208 | Return Values : E_OK - success
2209 | E_REQUEST_DENIED - no data behind
2210 +--------------------------------------------------------------------------*/
2212 HSC_Horizontal_Line_Backward(FORM *form)
2214 T((T_CALLED("HSC_Horizontal_Line_Backward(%p)"), form));
2215 returnCode(HSC_Generic(form, -(form->current->cols)));
2218 /*---------------------------------------------------------------------------
2219 | Facility : libnform
2220 | Function : static int HSC_Horizontal_Half_Line_Backward(FORM* form)
2222 | Description : Scroll single-line field backward half a line
2224 | Return Values : E_OK - success
2225 | E_REQUEST_DENIED - no data behind
2226 +--------------------------------------------------------------------------*/
2228 HSC_Horizontal_Half_Line_Backward(FORM *form)
2230 T((T_CALLED("HSC_Horizontal_Half_Line_Backward(%p)"), form));
2231 returnCode(HSC_Generic(form, -((form->current->cols + 1) / 2)));
2234 /*----------------------------------------------------------------------------
2235 End of Horizontal scrolling routines
2236 --------------------------------------------------------------------------*/
2238 /*----------------------------------------------------------------------------
2239 Helper routines for Field Editing
2240 --------------------------------------------------------------------------*/
2242 /*---------------------------------------------------------------------------
2243 | Facility : libnform
2244 | Function : static bool Is_There_Room_For_A_Line(FORM * form)
2246 | Description : Check whether or not there is enough room in the
2247 | buffer to enter a whole line.
2249 | Return Values : TRUE - there is enough space
2250 | FALSE - there is not enough space
2251 +--------------------------------------------------------------------------*/
2252 NCURSES_INLINE static bool
2253 Is_There_Room_For_A_Line(FORM *form)
2255 FIELD *field = form->current;
2256 FIELD_CELL *begin_of_last_line, *s;
2258 Synchronize_Buffer(form);
2259 begin_of_last_line = Address_Of_Row_In_Buffer(field, (field->drows - 1));
2260 s = After_End_Of_Data(begin_of_last_line, field->dcols);
2261 return ((s == begin_of_last_line) ? TRUE : FALSE);
2264 /*---------------------------------------------------------------------------
2265 | Facility : libnform
2266 | Function : static bool Is_There_Room_For_A_Char_In_Line(FORM * form)
2268 | Description : Checks whether or not there is room for a new character
2269 | in the current line.
2271 | Return Values : TRUE - there is room
2272 | FALSE - there is not enough room (line full)
2273 +--------------------------------------------------------------------------*/
2274 NCURSES_INLINE static bool
2275 Is_There_Room_For_A_Char_In_Line(FORM *form)
2277 int last_char_in_line;
2279 wmove(form->w, form->currow, form->current->dcols - 1);
2280 last_char_in_line = (int)(winch(form->w) & A_CHARTEXT);
2281 wmove(form->w, form->currow, form->curcol);
2282 return (((last_char_in_line == form->current->pad) ||
2283 is_blank(last_char_in_line)) ? TRUE : FALSE);
2286 #define There_Is_No_Room_For_A_Char_In_Line(f) \
2287 !Is_There_Room_For_A_Char_In_Line(f)
2289 /*---------------------------------------------------------------------------
2290 | Facility : libnform
2291 | Function : static int Insert_String(
2297 | Description : Insert the 'len' characters beginning at pointer 'txt'
2298 | into the 'row' of the 'form'. The insertion occurs
2299 | on the beginning of the row, all other characters are
2300 | moved to the right. After the text a pad character will
2301 | be inserted to separate the text from the rest. If
2302 | necessary the insertion moves characters on the next
2303 | line to make place for the requested insertion string.
2305 | Return Values : E_OK - success
2306 | E_REQUEST_DENIED -
2307 | E_SYSTEM_ERROR - system error
2308 +--------------------------------------------------------------------------*/
2310 Insert_String(FORM *form, int row, FIELD_CELL *txt, int len)
2312 FIELD *field = form->current;
2313 FIELD_CELL *bp = Address_Of_Row_In_Buffer(field, row);
2314 int datalen = (int)(After_End_Of_Data(bp, field->dcols) - bp);
2315 int freelen = field->dcols - datalen;
2316 int requiredlen = len + 1;
2318 int result = E_REQUEST_DENIED;
2320 if (freelen >= requiredlen)
2322 wmove(form->w, row, 0);
2323 myINSNSTR(form->w, txt, len);
2324 wmove(form->w, row, len);
2325 myINSNSTR(form->w, &myBLANK, 1);
2330 /* we have to move characters on the next line. If we are on the
2331 last line this may work, if the field is growable */
2332 if ((row == (field->drows - 1)) && Growable(field))
2334 if (!Field_Grown(field, 1))
2335 return (E_SYSTEM_ERROR);
2336 /* !!!Side-Effect : might be changed due to growth!!! */
2337 bp = Address_Of_Row_In_Buffer(field, row);
2340 if (row < (field->drows - 1))
2343 After_Last_Whitespace_Character(bp,
2344 (int)(Get_Start_Of_Data(bp
2349 /* split points now to the first character of the portion of the
2350 line that must be moved to the next line */
2351 datalen = (int)(split - bp); /* + freelen has to stay on this line */
2352 freelen = field->dcols - (datalen + freelen); /* for the next line */
2354 if ((result = Insert_String(form, row + 1, split, freelen)) == E_OK)
2356 wmove(form->w, row, datalen);
2358 wmove(form->w, row, 0);
2359 myINSNSTR(form->w, txt, len);
2360 wmove(form->w, row, len);
2361 myINSNSTR(form->w, &myBLANK, 1);
2369 /*---------------------------------------------------------------------------
2370 | Facility : libnform
2371 | Function : static int Wrapping_Not_Necessary_Or_Wrapping_Ok(
2374 | Description : If a character has been entered into a field, it may
2375 | be that wrapping has to occur. This routine checks
2376 | whether or not wrapping is required and if so, performs
2379 | Return Values : E_OK - no wrapping required or wrapping
2381 | E_REQUEST_DENIED -
2382 | E_SYSTEM_ERROR - some system error
2383 +--------------------------------------------------------------------------*/
2385 Wrapping_Not_Necessary_Or_Wrapping_Ok(FORM *form)
2387 FIELD *field = form->current;
2388 int result = E_REQUEST_DENIED;
2389 bool Last_Row = ((field->drows - 1) == form->currow);
2391 if ((field->opts & O_WRAP) && /* wrapping wanted */
2392 (!Single_Line_Field(field)) && /* must be multi-line */
2393 (There_Is_No_Room_For_A_Char_In_Line(form)) && /* line is full */
2394 (!Last_Row || Growable(field))) /* there are more lines */
2398 int chars_to_be_wrapped;
2399 int chars_to_remain_on_line;
2403 /* the above logic already ensures, that in this case the field
2405 if (!Field_Grown(field, 1))
2406 return E_SYSTEM_ERROR;
2408 bp = Address_Of_Current_Row_In_Buffer(form);
2409 Window_To_Buffer(form->w, field);
2410 split = After_Last_Whitespace_Character(bp, field->dcols);
2411 /* split points to the first character of the sequence to be brought
2413 chars_to_remain_on_line = (int)(split - bp);
2414 chars_to_be_wrapped = field->dcols - chars_to_remain_on_line;
2415 if (chars_to_remain_on_line > 0)
2417 if ((result = Insert_String(form, form->currow + 1, split,
2418 chars_to_be_wrapped)) == E_OK)
2420 wmove(form->w, form->currow, chars_to_remain_on_line);
2422 if (form->curcol >= chars_to_remain_on_line)
2425 form->curcol -= chars_to_remain_on_line;
2435 Window_To_Buffer(form->w, field);
2436 result = E_REQUEST_DENIED;
2440 result = E_OK; /* wrapping was not necessary */
2444 /*----------------------------------------------------------------------------
2445 Field Editing routines
2446 --------------------------------------------------------------------------*/
2448 /*---------------------------------------------------------------------------
2449 | Facility : libnform
2450 | Function : static int Field_Editing(
2451 | int (* const fct) (FORM *),
2454 | Description : Generic routine for field editing requests. The driver
2455 | routines are only called for editable fields, the
2456 | _WINDOW_MODIFIED flag is set if editing occurred.
2457 | This is somewhat special due to the overload semantics
2458 | of the NEW_LINE and DEL_PREV requests.
2460 | Return Values : Error code from low level drivers.
2461 +--------------------------------------------------------------------------*/
2463 Field_Editing(int (*const fct) (FORM *), FORM *form)
2465 int res = E_REQUEST_DENIED;
2467 /* We have to deal here with the specific case of the overloaded
2468 behavior of New_Line and Delete_Previous requests.
2469 They may end up in navigational requests if we are on the first
2470 character in a field. But navigation is also allowed on non-
2473 if ((fct == FE_Delete_Previous) &&
2474 (form->opts & O_BS_OVERLOAD) &&
2475 First_Position_In_Current_Field(form))
2477 res = Inter_Field_Navigation(FN_Previous_Field, form);
2481 if (fct == FE_New_Line)
2483 if ((form->opts & O_NL_OVERLOAD) &&
2484 First_Position_In_Current_Field(form))
2486 res = Inter_Field_Navigation(FN_Next_Field, form);
2489 /* FE_New_Line deals itself with the _WINDOW_MODIFIED flag */
2494 /* From now on, everything must be editable */
2495 if (form->current->opts & O_EDIT)
2499 form->status |= _WINDOW_MODIFIED;
2506 /*---------------------------------------------------------------------------
2507 | Facility : libnform
2508 | Function : static int FE_New_Line(FORM * form)
2510 | Description : Perform a new line request. This is rather complex
2511 | compared to other routines in this code due to the
2512 | rather difficult to understand description in the
2515 | Return Values : E_OK - success
2516 | E_REQUEST_DENIED - new line not allowed
2517 | E_SYSTEM_ERROR - system error
2518 +--------------------------------------------------------------------------*/
2520 FE_New_Line(FORM *form)
2522 FIELD *field = form->current;
2524 bool Last_Row = ((field->drows - 1) == form->currow);
2526 T((T_CALLED("FE_New_Line(%p)"), form));
2527 if (form->status & _OVLMODE)
2530 (!(Growable(field) && !Single_Line_Field(field))))
2532 if (!(form->opts & O_NL_OVERLOAD))
2533 returnCode(E_REQUEST_DENIED);
2534 wmove(form->w, form->currow, form->curcol);
2536 /* we have to set this here, although it is also
2537 handled in the generic routine. The reason is,
2538 that FN_Next_Field may fail, but the form is
2539 definitively changed */
2540 form->status |= _WINDOW_MODIFIED;
2541 returnCode(Inter_Field_Navigation(FN_Next_Field, form));
2545 if (Last_Row && !Field_Grown(field, 1))
2547 /* N.B.: due to the logic in the 'if', LastRow==TRUE
2548 means here that the field is growable and not
2549 a single-line field */
2550 returnCode(E_SYSTEM_ERROR);
2552 wmove(form->w, form->currow, form->curcol);
2556 form->status |= _WINDOW_MODIFIED;
2564 !(Growable(field) && !Single_Line_Field(field)))
2566 if (!(form->opts & O_NL_OVERLOAD))
2567 returnCode(E_REQUEST_DENIED);
2568 returnCode(Inter_Field_Navigation(FN_Next_Field, form));
2572 bool May_Do_It = !Last_Row && Is_There_Room_For_A_Line(form);
2574 if (!(May_Do_It || Growable(field)))
2575 returnCode(E_REQUEST_DENIED);
2576 if (!May_Do_It && !Field_Grown(field, 1))
2577 returnCode(E_SYSTEM_ERROR);
2579 bp = Address_Of_Current_Position_In_Buffer(form);
2580 t = After_End_Of_Data(bp, field->dcols - form->curcol);
2581 wmove(form->w, form->currow, form->curcol);
2585 wmove(form->w, form->currow, form->curcol);
2587 myADDNSTR(form->w, bp, (int)(t - bp));
2588 form->status |= _WINDOW_MODIFIED;
2594 /*---------------------------------------------------------------------------
2595 | Facility : libnform
2596 | Function : static int FE_Insert_Character(FORM * form)
2598 | Description : Insert blank character at the cursor position
2600 | Return Values : E_OK
2602 +--------------------------------------------------------------------------*/
2604 FE_Insert_Character(FORM *form)
2606 FIELD *field = form->current;
2607 int result = E_REQUEST_DENIED;
2609 T((T_CALLED("FE_Insert_Character(%p)"), form));
2610 if (Check_Char(field->type, (int)C_BLANK, (TypeArgument *)(field->arg)))
2612 bool There_Is_Room = Is_There_Room_For_A_Char_In_Line(form);
2614 if (There_Is_Room ||
2615 ((Single_Line_Field(field) && Growable(field))))
2617 if (!There_Is_Room && !Field_Grown(field, 1))
2618 result = E_SYSTEM_ERROR;
2621 winsch(form->w, (chtype)C_BLANK);
2622 result = Wrapping_Not_Necessary_Or_Wrapping_Ok(form);
2629 /*---------------------------------------------------------------------------
2630 | Facility : libnform
2631 | Function : static int FE_Insert_Line(FORM * form)
2633 | Description : Insert a blank line at the cursor position
2635 | Return Values : E_OK - success
2636 | E_REQUEST_DENIED - line can not be inserted
2637 +--------------------------------------------------------------------------*/
2639 FE_Insert_Line(FORM *form)
2641 FIELD *field = form->current;
2642 int result = E_REQUEST_DENIED;
2644 T((T_CALLED("FE_Insert_Line(%p)"), form));
2645 if (Check_Char(field->type, (int)C_BLANK, (TypeArgument *)(field->arg)))
2647 bool Maybe_Done = (form->currow != (field->drows - 1)) &&
2648 Is_There_Room_For_A_Line(form);
2650 if (!Single_Line_Field(field) &&
2651 (Maybe_Done || Growable(field)))
2653 if (!Maybe_Done && !Field_Grown(field, 1))
2654 result = E_SYSTEM_ERROR;
2666 /*---------------------------------------------------------------------------
2667 | Facility : libnform
2668 | Function : static int FE_Delete_Character(FORM * form)
2670 | Description : Delete character at the cursor position
2672 | Return Values : E_OK - success
2673 +--------------------------------------------------------------------------*/
2675 FE_Delete_Character(FORM *form)
2677 T((T_CALLED("FE_Delete_Character(%p)"), form));
2682 /*---------------------------------------------------------------------------
2683 | Facility : libnform
2684 | Function : static int FE_Delete_Previous(FORM * form)
2686 | Description : Delete character before cursor. Again this is a rather
2687 | difficult piece compared to others due to the overloading
2688 | semantics of backspace.
2689 | N.B.: The case of overloaded BS on first field position
2690 | is already handled in the generic routine.
2692 | Return Values : E_OK - success
2693 | E_REQUEST_DENIED - Character can't be deleted
2694 +--------------------------------------------------------------------------*/
2696 FE_Delete_Previous(FORM *form)
2698 FIELD *field = form->current;
2700 T((T_CALLED("FE_Delete_Previous(%p)"), form));
2701 if (First_Position_In_Current_Field(form))
2702 returnCode(E_REQUEST_DENIED);
2704 if ((--(form->curcol)) < 0)
2706 FIELD_CELL *this_line, *prev_line, *prev_end, *this_end;
2707 int this_row = form->currow;
2710 if (form->status & _OVLMODE)
2711 returnCode(E_REQUEST_DENIED);
2713 prev_line = Address_Of_Row_In_Buffer(field, (form->currow - 1));
2714 this_line = Address_Of_Row_In_Buffer(field, (form->currow));
2715 Synchronize_Buffer(form);
2716 prev_end = After_End_Of_Data(prev_line, field->dcols);
2717 this_end = After_End_Of_Data(this_line, field->dcols);
2718 if ((int)(this_end - this_line) >
2719 (field->cols - (int)(prev_end - prev_line)))
2720 returnCode(E_REQUEST_DENIED);
2721 wmove(form->w, form->currow, form->curcol);
2723 Adjust_Cursor_Position(form, prev_end);
2725 * If we did not really move to the previous line, help the user a
2726 * little. It is however a little inconsistent. Normally, when
2727 * backspacing around the point where text wraps to a new line in a
2728 * multi-line form, we absorb one keystroke for the wrapping point. That
2729 * is consistent with SVr4 forms. However, SVr4 does not allow typing
2730 * into the last column of the field, and requires the user to enter a
2731 * newline to move to the next line. Therefore it can consistently eat
2732 * that keystroke. Since ncurses allows the last column, it wraps
2733 * automatically (given the proper options). But we cannot eat the
2734 * keystroke to back over the wrapping point, since that would put the
2735 * cursor past the end of the form field. In this case, just delete the
2736 * character at the end of the field.
2738 if (form->currow == this_row && this_row > 0)
2741 form->curcol = field->dcols - 1;
2746 wmove(form->w, form->currow, form->curcol);
2747 myADDNSTR(form->w, this_line, (int)(this_end - this_line));
2757 /*---------------------------------------------------------------------------
2758 | Facility : libnform
2759 | Function : static int FE_Delete_Line(FORM * form)
2761 | Description : Delete line at cursor position.
2763 | Return Values : E_OK - success
2764 +--------------------------------------------------------------------------*/
2766 FE_Delete_Line(FORM *form)
2768 T((T_CALLED("FE_Delete_Line(%p)"), form));
2774 /*---------------------------------------------------------------------------
2775 | Facility : libnform
2776 | Function : static int FE_Delete_Word(FORM * form)
2778 | Description : Delete word at cursor position
2780 | Return Values : E_OK - success
2781 | E_REQUEST_DENIED - failure
2782 +--------------------------------------------------------------------------*/
2784 FE_Delete_Word(FORM *form)
2786 FIELD *field = form->current;
2787 FIELD_CELL *bp = Address_Of_Current_Row_In_Buffer(form);
2788 FIELD_CELL *ep = bp + field->dcols;
2789 FIELD_CELL *cp = bp + form->curcol;
2792 T((T_CALLED("FE_Delete_Word(%p)"), form));
2793 Synchronize_Buffer(form);
2795 returnCode(E_REQUEST_DENIED); /* not in word */
2797 /* move cursor to begin of word and erase to end of screen-line */
2798 Adjust_Cursor_Position(form,
2799 After_Last_Whitespace_Character(bp, form->curcol));
2800 wmove(form->w, form->currow, form->curcol);
2803 /* skip over word in buffer */
2804 s = Get_First_Whitespace_Character(cp, (int)(ep - cp));
2805 /* to begin of next word */
2806 s = Get_Start_Of_Data(s, (int)(ep - s));
2807 if ((s != cp) && !ISBLANK(*s))
2809 /* copy remaining line to window */
2810 myADDNSTR(form->w, s, (int)(s - After_End_Of_Data(s, (int)(ep - s))));
2815 /*---------------------------------------------------------------------------
2816 | Facility : libnform
2817 | Function : static int FE_Clear_To_End_Of_Line(FORM * form)
2819 | Description : Clear to end of current line.
2821 | Return Values : E_OK - success
2822 +--------------------------------------------------------------------------*/
2824 FE_Clear_To_End_Of_Line(FORM *form)
2826 T((T_CALLED("FE_Clear_To_End_Of_Line(%p)"), form));
2827 wmove(form->w, form->currow, form->curcol);
2832 /*---------------------------------------------------------------------------
2833 | Facility : libnform
2834 | Function : static int FE_Clear_To_End_Of_Field(FORM * form)
2836 | Description : Clear to end of field.
2838 | Return Values : E_OK - success
2839 +--------------------------------------------------------------------------*/
2841 FE_Clear_To_End_Of_Field(FORM *form)
2843 T((T_CALLED("FE_Clear_To_End_Of_Field(%p)"), form));
2844 wmove(form->w, form->currow, form->curcol);
2849 /*---------------------------------------------------------------------------
2850 | Facility : libnform
2851 | Function : static int FE_Clear_Field(FORM * form)
2853 | Description : Clear entire field.
2855 | Return Values : E_OK - success
2856 +--------------------------------------------------------------------------*/
2858 FE_Clear_Field(FORM *form)
2860 T((T_CALLED("FE_Clear_Field(%p)"), form));
2861 form->currow = form->curcol = 0;
2865 /*----------------------------------------------------------------------------
2866 END of Field Editing routines
2867 --------------------------------------------------------------------------*/
2869 /*----------------------------------------------------------------------------
2871 --------------------------------------------------------------------------*/
2873 /*---------------------------------------------------------------------------
2874 | Facility : libnform
2875 | Function : static int EM_Overlay_Mode(FORM * form)
2877 | Description : Switch to overlay mode.
2879 | Return Values : E_OK - success
2880 +--------------------------------------------------------------------------*/
2882 EM_Overlay_Mode(FORM *form)
2884 T((T_CALLED("EM_Overlay_Mode(%p)"), form));
2885 form->status |= _OVLMODE;
2889 /*---------------------------------------------------------------------------
2890 | Facility : libnform
2891 | Function : static int EM_Insert_Mode(FORM * form)
2893 | Description : Switch to insert mode
2895 | Return Values : E_OK - success
2896 +--------------------------------------------------------------------------*/
2898 EM_Insert_Mode(FORM *form)
2900 T((T_CALLED("EM_Insert_Mode(%p)"), form));
2901 form->status &= ~_OVLMODE;
2905 /*----------------------------------------------------------------------------
2906 END of Edit Mode routines
2907 --------------------------------------------------------------------------*/
2909 /*----------------------------------------------------------------------------
2910 Helper routines for Choice Requests
2911 --------------------------------------------------------------------------*/
2913 /*---------------------------------------------------------------------------
2914 | Facility : libnform
2915 | Function : static bool Next_Choice(
2918 | TypeArgument *argp)
2920 | Description : Get the next field choice. For linked types this is
2923 | Return Values : TRUE - next choice successfully retrieved
2924 | FALSE - couldn't retrieve next choice
2925 +--------------------------------------------------------------------------*/
2927 Next_Choice(FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
2929 if (!typ || !(typ->status & _HAS_CHOICE))
2932 if (typ->status & _LINKED_TYPE)
2936 Next_Choice(typ->left, field, argp->left) ||
2937 Next_Choice(typ->right, field, argp->right));
2942 return typ->next(field, (void *)argp);
2946 /*---------------------------------------------------------------------------
2947 | Facility : libnform
2948 | Function : static bool Previous_Choice(
2951 | TypeArgument *argp)
2953 | Description : Get the previous field choice. For linked types this
2954 | is done recursively.
2956 | Return Values : TRUE - previous choice successfully retrieved
2957 | FALSE - couldn't retrieve previous choice
2958 +--------------------------------------------------------------------------*/
2960 Previous_Choice(FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
2962 if (!typ || !(typ->status & _HAS_CHOICE))
2965 if (typ->status & _LINKED_TYPE)
2969 Previous_Choice(typ->left, field, argp->left) ||
2970 Previous_Choice(typ->right, field, argp->right));
2975 return typ->prev(field, (void *)argp);
2978 /*----------------------------------------------------------------------------
2979 End of Helper routines for Choice Requests
2980 --------------------------------------------------------------------------*/
2982 /*----------------------------------------------------------------------------
2983 Routines for Choice Requests
2984 --------------------------------------------------------------------------*/
2986 /*---------------------------------------------------------------------------
2987 | Facility : libnform
2988 | Function : static int CR_Next_Choice(FORM * form)
2990 | Description : Get the next field choice.
2992 | Return Values : E_OK - success
2993 | E_REQUEST_DENIED - next choice couldn't be retrieved
2994 +--------------------------------------------------------------------------*/
2996 CR_Next_Choice(FORM *form)
2998 FIELD *field = form->current;
3000 T((T_CALLED("CR_Next_Choice(%p)"), form));
3001 Synchronize_Buffer(form);
3002 returnCode((Next_Choice(field->type, field, (TypeArgument *)(field->arg)))
3004 : E_REQUEST_DENIED);
3007 /*---------------------------------------------------------------------------
3008 | Facility : libnform
3009 | Function : static int CR_Previous_Choice(FORM * form)
3011 | Description : Get the previous field choice.
3013 | Return Values : E_OK - success
3014 | E_REQUEST_DENIED - prev. choice couldn't be retrieved
3015 +--------------------------------------------------------------------------*/
3017 CR_Previous_Choice(FORM *form)
3019 FIELD *field = form->current;
3021 T((T_CALLED("CR_Previous_Choice(%p)"), form));
3022 Synchronize_Buffer(form);
3023 returnCode((Previous_Choice(field->type, field, (TypeArgument *)(field->arg)))
3025 : E_REQUEST_DENIED);
3027 /*----------------------------------------------------------------------------
3028 End of Routines for Choice Requests
3029 --------------------------------------------------------------------------*/
3031 /*----------------------------------------------------------------------------
3032 Helper routines for Field Validations.
3033 --------------------------------------------------------------------------*/
3035 /*---------------------------------------------------------------------------
3036 | Facility : libnform
3037 | Function : static bool Check_Field(
3040 | TypeArgument * argp)
3042 | Description : Check the field according to its fieldtype and its
3043 | actual arguments. For linked fieldtypes this is done
3046 | Return Values : TRUE - field is valid
3047 | FALSE - field is invalid.
3048 +--------------------------------------------------------------------------*/
3050 Check_Field(FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
3054 if (field->opts & O_NULLOK)
3056 FIELD_CELL *bp = field->buf;
3059 while (ISBLANK(*bp))
3063 if (CharOf(*bp) == 0)
3067 if (typ->status & _LINKED_TYPE)
3071 Check_Field(typ->left, field, argp->left) ||
3072 Check_Field(typ->right, field, argp->right));
3077 return typ->fcheck(field, (void *)argp);
3083 /*---------------------------------------------------------------------------
3084 | Facility : libnform
3085 | Function : bool _nc_Internal_Validation(FORM * form )
3087 | Description : Validate the current field of the form.
3089 | Return Values : TRUE - field is valid
3090 | FALSE - field is invalid
3091 +--------------------------------------------------------------------------*/
3092 NCURSES_EXPORT(bool)
3093 _nc_Internal_Validation(FORM *form)
3097 field = form->current;
3099 Synchronize_Buffer(form);
3100 if ((form->status & _FCHECK_REQUIRED) ||
3101 (!(field->opts & O_PASSOK)))
3103 if (!Check_Field(field->type, field, (TypeArgument *)(field->arg)))
3105 form->status &= ~_FCHECK_REQUIRED;
3106 field->status |= _CHANGED;
3107 Synchronize_Linked_Fields(field);
3111 /*----------------------------------------------------------------------------
3112 End of Helper routines for Field Validations.
3113 --------------------------------------------------------------------------*/
3115 /*----------------------------------------------------------------------------
3116 Routines for Field Validation.
3117 --------------------------------------------------------------------------*/
3119 /*---------------------------------------------------------------------------
3120 | Facility : libnform
3121 | Function : static int FV_Validation(FORM * form)
3123 | Description : Validate the current field of the form.
3125 | Return Values : E_OK - field valid
3126 | E_INVALID_FIELD - field not valid
3127 +--------------------------------------------------------------------------*/
3129 FV_Validation(FORM *form)
3131 T((T_CALLED("FV_Validation(%p)"), form));
3132 if (_nc_Internal_Validation(form))
3135 returnCode(E_INVALID_FIELD);
3137 /*----------------------------------------------------------------------------
3138 End of routines for Field Validation.
3139 --------------------------------------------------------------------------*/
3141 /*----------------------------------------------------------------------------
3142 Helper routines for Inter-Field Navigation
3143 --------------------------------------------------------------------------*/
3145 /*---------------------------------------------------------------------------
3146 | Facility : libnform
3147 | Function : static FIELD *Next_Field_On_Page(FIELD * field)
3149 | Description : Get the next field after the given field on the current
3150 | page. The order of fields is the one defined by the
3151 | fields array. Only visible and active fields are
3154 | Return Values : Pointer to the next field.
3155 +--------------------------------------------------------------------------*/
3156 NCURSES_INLINE static FIELD *
3157 Next_Field_On_Page(FIELD *field)
3159 FORM *form = field->form;
3160 FIELD **field_on_page = &form->field[field->index];
3161 FIELD **first_on_page = &form->field[form->page[form->curpage].pmin];
3162 FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
3167 (field_on_page == last_on_page) ? first_on_page : field_on_page + 1;
3168 if (Field_Is_Selectable(*field_on_page))
3171 while (field != (*field_on_page));
3172 return (*field_on_page);
3175 /*---------------------------------------------------------------------------
3176 | Facility : libnform
3177 | Function : FIELD* _nc_First_Active_Field(FORM * form)
3179 | Description : Get the first active field on the current page,
3180 | if there are such. If there are none, get the first
3181 | visible field on the page. If there are also none,
3182 | we return the first field on page and hope the best.
3184 | Return Values : Pointer to calculated field.
3185 +--------------------------------------------------------------------------*/
3186 NCURSES_EXPORT(FIELD *)
3187 _nc_First_Active_Field(FORM *form)
3189 FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
3190 FIELD *proposed = Next_Field_On_Page(*last_on_page);
3192 if (proposed == *last_on_page)
3194 /* there might be the special situation, where there is no
3195 active and visible field on the current page. We then select
3196 the first visible field on this readonly page
3198 if (Field_Is_Not_Selectable(proposed))
3200 FIELD **field = &form->field[proposed->index];
3201 FIELD **first = &form->field[form->page[form->curpage].pmin];
3205 field = (field == last_on_page) ? first : field + 1;
3206 if (((*field)->opts & O_VISIBLE))
3209 while (proposed != (*field));
3213 if ((proposed == *last_on_page) && !(proposed->opts & O_VISIBLE))
3215 /* This means, there is also no visible field on the page.
3216 So we propose the first one and hope the very best...
3217 Some very clever user has designed a readonly and invisible
3227 /*---------------------------------------------------------------------------
3228 | Facility : libnform
3229 | Function : static FIELD *Previous_Field_On_Page(FIELD * field)
3231 | Description : Get the previous field before the given field on the
3232 | current page. The order of fields is the one defined by
3233 | the fields array. Only visible and active fields are
3236 | Return Values : Pointer to the previous field.
3237 +--------------------------------------------------------------------------*/
3238 NCURSES_INLINE static FIELD *
3239 Previous_Field_On_Page(FIELD *field)
3241 FORM *form = field->form;
3242 FIELD **field_on_page = &form->field[field->index];
3243 FIELD **first_on_page = &form->field[form->page[form->curpage].pmin];
3244 FIELD **last_on_page = &form->field[form->page[form->curpage].pmax];
3249 (field_on_page == first_on_page) ? last_on_page : field_on_page - 1;
3250 if (Field_Is_Selectable(*field_on_page))
3253 while (field != (*field_on_page));
3255 return (*field_on_page);
3258 /*---------------------------------------------------------------------------
3259 | Facility : libnform
3260 | Function : static FIELD *Sorted_Next_Field(FIELD * field)
3262 | Description : Get the next field after the given field on the current
3263 | page. The order of fields is the one defined by the
3264 | (row,column) geometry, rows are major.
3266 | Return Values : Pointer to the next field.
3267 +--------------------------------------------------------------------------*/
3268 NCURSES_INLINE static FIELD *
3269 Sorted_Next_Field(FIELD *field)
3271 FIELD *field_on_page = field;
3275 field_on_page = field_on_page->snext;
3276 if (Field_Is_Selectable(field_on_page))
3279 while (field_on_page != field);
3281 return (field_on_page);
3284 /*---------------------------------------------------------------------------
3285 | Facility : libnform
3286 | Function : static FIELD *Sorted_Previous_Field(FIELD * field)
3288 | Description : Get the previous field before the given field on the
3289 | current page. The order of fields is the one defined
3290 | by the (row,column) geometry, rows are major.
3292 | Return Values : Pointer to the previous field.
3293 +--------------------------------------------------------------------------*/
3294 NCURSES_INLINE static FIELD *
3295 Sorted_Previous_Field(FIELD *field)
3297 FIELD *field_on_page = field;
3301 field_on_page = field_on_page->sprev;
3302 if (Field_Is_Selectable(field_on_page))
3305 while (field_on_page != field);
3307 return (field_on_page);
3310 /*---------------------------------------------------------------------------
3311 | Facility : libnform
3312 | Function : static FIELD *Left_Neighbor_Field(FIELD * field)
3314 | Description : Get the left neighbor of the field on the same line
3315 | and the same page. Cycles through the line.
3317 | Return Values : Pointer to left neighbor field.
3318 +--------------------------------------------------------------------------*/
3319 NCURSES_INLINE static FIELD *
3320 Left_Neighbor_Field(FIELD *field)
3322 FIELD *field_on_page = field;
3324 /* For a field that has really a left neighbor, the while clause
3325 immediately fails and the loop is left, positioned at the right
3326 neighbor. Otherwise we cycle backwards through the sorted field list
3327 until we enter the same line (from the right end).
3331 field_on_page = Sorted_Previous_Field(field_on_page);
3333 while (field_on_page->frow != field->frow);
3335 return (field_on_page);
3338 /*---------------------------------------------------------------------------
3339 | Facility : libnform
3340 | Function : static FIELD *Right_Neighbor_Field(FIELD * field)
3342 | Description : Get the right neighbor of the field on the same line
3343 | and the same page.
3345 | Return Values : Pointer to right neighbor field.
3346 +--------------------------------------------------------------------------*/
3347 NCURSES_INLINE static FIELD *
3348 Right_Neighbor_Field(FIELD *field)
3350 FIELD *field_on_page = field;
3352 /* See the comments on Left_Neighbor_Field to understand how it works */
3355 field_on_page = Sorted_Next_Field(field_on_page);
3357 while (field_on_page->frow != field->frow);
3359 return (field_on_page);
3362 /*---------------------------------------------------------------------------
3363 | Facility : libnform
3364 | Function : static FIELD *Upper_Neighbor_Field(FIELD * field)
3366 | Description : Because of the row-major nature of sorting the fields,
3367 | it is more difficult to define whats the upper neighbor
3368 | field really means. We define that it must be on a
3369 | 'previous' line (cyclic order!) and is the rightmost
3370 | field laying on the left side of the given field. If
3371 | this set is empty, we take the first field on the line.
3373 | Return Values : Pointer to the upper neighbor field.
3374 +--------------------------------------------------------------------------*/
3376 Upper_Neighbor_Field(FIELD *field)
3378 FIELD *field_on_page = field;
3379 int frow = field->frow;
3380 int fcol = field->fcol;
3382 /* Walk back to the 'previous' line. The second term in the while clause
3383 just guarantees that we stop if we cycled through the line because
3384 there might be no 'previous' line if the page has just one line.
3388 field_on_page = Sorted_Previous_Field(field_on_page);
3390 while (field_on_page->frow == frow && field_on_page->fcol != fcol);
3392 if (field_on_page->frow != frow)
3394 /* We really found a 'previous' line. We are positioned at the
3395 rightmost field on this line */
3396 frow = field_on_page->frow;
3398 /* We walk to the left as long as we are really right of the
3400 while (field_on_page->frow == frow && field_on_page->fcol > fcol)
3401 field_on_page = Sorted_Previous_Field(field_on_page);
3403 /* If we wrapped, just go to the right which is the first field on
3405 if (field_on_page->frow != frow)
3406 field_on_page = Sorted_Next_Field(field_on_page);
3409 return (field_on_page);
3412 /*---------------------------------------------------------------------------
3413 | Facility : libnform
3414 | Function : static FIELD *Down_Neighbor_Field(FIELD * field)
3416 | Description : Because of the row-major nature of sorting the fields,
3417 | its more difficult to define whats the down neighbor
3418 | field really means. We define that it must be on a
3419 | 'next' line (cyclic order!) and is the leftmost
3420 | field laying on the right side of the given field. If
3421 | this set is empty, we take the last field on the line.
3423 | Return Values : Pointer to the upper neighbor field.
3424 +--------------------------------------------------------------------------*/
3426 Down_Neighbor_Field(FIELD *field)
3428 FIELD *field_on_page = field;
3429 int frow = field->frow;
3430 int fcol = field->fcol;
3432 /* Walk forward to the 'next' line. The second term in the while clause
3433 just guarantees that we stop if we cycled through the line because
3434 there might be no 'next' line if the page has just one line.
3438 field_on_page = Sorted_Next_Field(field_on_page);
3440 while (field_on_page->frow == frow && field_on_page->fcol != fcol);
3442 if (field_on_page->frow != frow)
3444 /* We really found a 'next' line. We are positioned at the rightmost
3445 field on this line */
3446 frow = field_on_page->frow;
3448 /* We walk to the right as long as we are really left of the
3450 while (field_on_page->frow == frow && field_on_page->fcol < fcol)
3451 field_on_page = Sorted_Next_Field(field_on_page);
3453 /* If we wrapped, just go to the left which is the last field on
3455 if (field_on_page->frow != frow)
3456 field_on_page = Sorted_Previous_Field(field_on_page);
3459 return (field_on_page);
3462 /*----------------------------------------------------------------------------
3463 Inter-Field Navigation routines
3464 --------------------------------------------------------------------------*/
3466 /*---------------------------------------------------------------------------
3467 | Facility : libnform
3468 | Function : static int Inter_Field_Navigation(
3469 | int (* const fct) (FORM *),
3472 | Description : Generic behavior for changing the current field, the
3473 | field is left and a new field is entered. So the field
3474 | must be validated and the field init/term hooks must
3477 | Return Values : E_OK - success
3478 | E_INVALID_FIELD - field is invalid
3479 | some other - error from subordinate call
3480 +--------------------------------------------------------------------------*/
3482 Inter_Field_Navigation(int (*const fct) (FORM *), FORM *form)
3486 if (!_nc_Internal_Validation(form))
3487 res = E_INVALID_FIELD;
3490 Call_Hook(form, fieldterm);
3492 Call_Hook(form, fieldinit);
3497 /*---------------------------------------------------------------------------
3498 | Facility : libnform
3499 | Function : static int FN_Next_Field(FORM * form)
3501 | Description : Move to the next field on the current page of the form
3503 | Return Values : E_OK - success
3504 | != E_OK - error from subordinate call
3505 +--------------------------------------------------------------------------*/
3507 FN_Next_Field(FORM *form)
3509 T((T_CALLED("FN_Next_Field(%p)"), form));
3510 returnCode(_nc_Set_Current_Field(form,
3511 Next_Field_On_Page(form->current)));
3514 /*---------------------------------------------------------------------------
3515 | Facility : libnform
3516 | Function : static int FN_Previous_Field(FORM * form)
3518 | Description : Move to the previous field on the current page of the
3521 | Return Values : E_OK - success
3522 | != E_OK - error from subordinate call
3523 +--------------------------------------------------------------------------*/
3525 FN_Previous_Field(FORM *form)
3527 T((T_CALLED("FN_Previous_Field(%p)"), form));
3528 returnCode(_nc_Set_Current_Field(form,
3529 Previous_Field_On_Page(form->current)));
3532 /*---------------------------------------------------------------------------
3533 | Facility : libnform
3534 | Function : static int FN_First_Field(FORM * form)
3536 | Description : Move to the first field on the current page of the form
3538 | Return Values : E_OK - success
3539 | != E_OK - error from subordinate call
3540 +--------------------------------------------------------------------------*/
3542 FN_First_Field(FORM *form)
3544 T((T_CALLED("FN_First_Field(%p)"), form));
3545 returnCode(_nc_Set_Current_Field(form,
3546 Next_Field_On_Page(form->field[form->page[form->curpage].pmax])));
3549 /*---------------------------------------------------------------------------
3550 | Facility : libnform
3551 | Function : static int FN_Last_Field(FORM * form)
3553 | Description : Move to the last field on the current page of the form
3555 | Return Values : E_OK - success
3556 | != E_OK - error from subordinate call
3557 +--------------------------------------------------------------------------*/
3559 FN_Last_Field(FORM *form)
3561 T((T_CALLED("FN_Last_Field(%p)"), form));
3563 _nc_Set_Current_Field(form,
3564 Previous_Field_On_Page(form->field[form->page[form->curpage].pmin])));
3567 /*---------------------------------------------------------------------------
3568 | Facility : libnform
3569 | Function : static int FN_Sorted_Next_Field(FORM * form)
3571 | Description : Move to the sorted next field on the current page
3574 | Return Values : E_OK - success
3575 | != E_OK - error from subordinate call
3576 +--------------------------------------------------------------------------*/
3578 FN_Sorted_Next_Field(FORM *form)
3580 T((T_CALLED("FN_Sorted_Next_Field(%p)"), form));
3581 returnCode(_nc_Set_Current_Field(form,
3582 Sorted_Next_Field(form->current)));
3585 /*---------------------------------------------------------------------------
3586 | Facility : libnform
3587 | Function : static int FN_Sorted_Previous_Field(FORM * form)
3589 | Description : Move to the sorted previous field on the current page
3592 | Return Values : E_OK - success
3593 | != E_OK - error from subordinate call
3594 +--------------------------------------------------------------------------*/
3596 FN_Sorted_Previous_Field(FORM *form)
3598 T((T_CALLED("FN_Sorted_Previous_Field(%p)"), form));
3599 returnCode(_nc_Set_Current_Field(form,
3600 Sorted_Previous_Field(form->current)));
3603 /*---------------------------------------------------------------------------
3604 | Facility : libnform
3605 | Function : static int FN_Sorted_First_Field(FORM * form)
3607 | Description : Move to the sorted first field on the current page
3610 | Return Values : E_OK - success
3611 | != E_OK - error from subordinate call
3612 +--------------------------------------------------------------------------*/
3614 FN_Sorted_First_Field(FORM *form)
3616 T((T_CALLED("FN_Sorted_First_Field(%p)"), form));
3617 returnCode(_nc_Set_Current_Field(form,
3618 Sorted_Next_Field(form->field[form->page[form->curpage].smax])));
3621 /*---------------------------------------------------------------------------
3622 | Facility : libnform
3623 | Function : static int FN_Sorted_Last_Field(FORM * form)
3625 | Description : Move to the sorted last field on the current page
3628 | Return Values : E_OK - success
3629 | != E_OK - error from subordinate call
3630 +--------------------------------------------------------------------------*/
3632 FN_Sorted_Last_Field(FORM *form)
3634 T((T_CALLED("FN_Sorted_Last_Field(%p)"), form));
3635 returnCode(_nc_Set_Current_Field(form,
3636 Sorted_Previous_Field(form->field[form->page[form->curpage].smin])));
3639 /*---------------------------------------------------------------------------
3640 | Facility : libnform
3641 | Function : static int FN_Left_Field(FORM * form)
3643 | Description : Get the field on the left of the current field on the
3644 | same line and the same page. Cycles through the line.
3646 | Return Values : E_OK - success
3647 | != E_OK - error from subordinate call
3648 +--------------------------------------------------------------------------*/
3650 FN_Left_Field(FORM *form)
3652 T((T_CALLED("FN_Left_Field(%p)"), form));
3653 returnCode(_nc_Set_Current_Field(form,
3654 Left_Neighbor_Field(form->current)));
3657 /*---------------------------------------------------------------------------
3658 | Facility : libnform
3659 | Function : static int FN_Right_Field(FORM * form)
3661 | Description : Get the field on the right of the current field on the
3662 | same line and the same page. Cycles through the line.
3664 | Return Values : E_OK - success
3665 | != E_OK - error from subordinate call
3666 +--------------------------------------------------------------------------*/
3668 FN_Right_Field(FORM *form)
3670 T((T_CALLED("FN_Right_Field(%p)"), form));
3671 returnCode(_nc_Set_Current_Field(form,
3672 Right_Neighbor_Field(form->current)));
3675 /*---------------------------------------------------------------------------
3676 | Facility : libnform
3677 | Function : static int FN_Up_Field(FORM * form)
3679 | Description : Get the upper neighbor of the current field. This
3680 | cycles through the page. See the comments of the
3681 | Upper_Neighbor_Field function to understand how
3682 | 'upper' is defined.
3684 | Return Values : E_OK - success
3685 | != E_OK - error from subordinate call
3686 +--------------------------------------------------------------------------*/
3688 FN_Up_Field(FORM *form)
3690 T((T_CALLED("FN_Up_Field(%p)"), form));
3691 returnCode(_nc_Set_Current_Field(form,
3692 Upper_Neighbor_Field(form->current)));
3695 /*---------------------------------------------------------------------------
3696 | Facility : libnform
3697 | Function : static int FN_Down_Field(FORM * form)
3699 | Description : Get the down neighbor of the current field. This
3700 | cycles through the page. See the comments of the
3701 | Down_Neighbor_Field function to understand how
3702 | 'down' is defined.
3704 | Return Values : E_OK - success
3705 | != E_OK - error from subordinate call
3706 +--------------------------------------------------------------------------*/
3708 FN_Down_Field(FORM *form)
3710 T((T_CALLED("FN_Down_Field(%p)"), form));
3711 returnCode(_nc_Set_Current_Field(form,
3712 Down_Neighbor_Field(form->current)));
3714 /*----------------------------------------------------------------------------
3715 END of Field Navigation routines
3716 --------------------------------------------------------------------------*/
3718 /*----------------------------------------------------------------------------
3719 Helper routines for Page Navigation
3720 --------------------------------------------------------------------------*/
3722 /*---------------------------------------------------------------------------
3723 | Facility : libnform
3724 | Function : int _nc_Set_Form_Page(FORM * form,
3728 | Description : Make the given page number the current page and make
3729 | the given field the current field on the page. If
3730 | for the field NULL is given, make the first field on
3731 | the page the current field. The routine acts only
3732 | if the requested page is not the current page.
3734 | Return Values : E_OK - success
3735 | != E_OK - error from subordinate call
3736 | E_BAD_ARGUMENT - invalid field pointer
3737 | E_SYSTEM_ERROR - some severe basic error
3738 +--------------------------------------------------------------------------*/
3740 _nc_Set_Form_Page(FORM *form, int page, FIELD *field)
3744 if ((form->curpage != page))
3746 FIELD *last_field, *field_on_page;
3748 werase(Get_Form_Window(form));
3749 form->curpage = page;
3750 last_field = field_on_page = form->field[form->page[page].smin];
3753 if (field_on_page->opts & O_VISIBLE)
3754 if ((res = Display_Field(field_on_page)) != E_OK)
3756 field_on_page = field_on_page->snext;
3758 while (field_on_page != last_field);
3761 res = _nc_Set_Current_Field(form, field);
3763 /* N.B.: we don't encapsulate this by Inter_Field_Navigation(),
3764 because this is already executed in a page navigation
3765 context that contains field navigation
3767 res = FN_First_Field(form);
3772 /*---------------------------------------------------------------------------
3773 | Facility : libnform
3774 | Function : static int Next_Page_Number(const FORM * form)
3776 | Description : Calculate the page number following the current page
3777 | number. This cycles if the highest page number is
3780 | Return Values : The next page number
3781 +--------------------------------------------------------------------------*/
3782 NCURSES_INLINE static int
3783 Next_Page_Number(const FORM *form)
3785 return (form->curpage + 1) % form->maxpage;
3788 /*---------------------------------------------------------------------------
3789 | Facility : libnform
3790 | Function : static int Previous_Page_Number(const FORM * form)
3792 | Description : Calculate the page number before the current page
3793 | number. This cycles if the first page number is
3796 | Return Values : The previous page number
3797 +--------------------------------------------------------------------------*/
3798 NCURSES_INLINE static int
3799 Previous_Page_Number(const FORM *form)
3801 return (form->curpage != 0 ? form->curpage - 1 : form->maxpage - 1);
3804 /*----------------------------------------------------------------------------
3805 Page Navigation routines
3806 --------------------------------------------------------------------------*/
3808 /*---------------------------------------------------------------------------
3809 | Facility : libnform
3810 | Function : static int Page_Navigation(
3811 | int (* const fct) (FORM *),
3814 | Description : Generic behavior for changing a page. This means
3815 | that the field is left and a new field is entered.
3816 | So the field must be validated and the field init/term
3817 | hooks must be called. Because also the page is changed,
3818 | the forms init/term hooks must be called also.
3820 | Return Values : E_OK - success
3821 | E_INVALID_FIELD - field is invalid
3822 | some other - error from subordinate call
3823 +--------------------------------------------------------------------------*/
3825 Page_Navigation(int (*const fct) (FORM *), FORM *form)
3829 if (!_nc_Internal_Validation(form))
3830 res = E_INVALID_FIELD;
3833 Call_Hook(form, fieldterm);
3834 Call_Hook(form, formterm);
3836 Call_Hook(form, forminit);
3837 Call_Hook(form, fieldinit);
3842 /*---------------------------------------------------------------------------
3843 | Facility : libnform
3844 | Function : static int PN_Next_Page(FORM * form)
3846 | Description : Move to the next page of the form
3848 | Return Values : E_OK - success
3849 | != E_OK - error from subordinate call
3850 +--------------------------------------------------------------------------*/
3852 PN_Next_Page(FORM *form)
3854 T((T_CALLED("PN_Next_Page(%p)"), form));
3855 returnCode(_nc_Set_Form_Page(form, Next_Page_Number(form), (FIELD *)0));
3858 /*---------------------------------------------------------------------------
3859 | Facility : libnform
3860 | Function : static int PN_Previous_Page(FORM * form)
3862 | Description : Move to the previous page of the form
3864 | Return Values : E_OK - success
3865 | != E_OK - error from subordinate call
3866 +--------------------------------------------------------------------------*/
3868 PN_Previous_Page(FORM *form)
3870 T((T_CALLED("PN_Previous_Page(%p)"), form));
3871 returnCode(_nc_Set_Form_Page(form, Previous_Page_Number(form), (FIELD *)0));
3874 /*---------------------------------------------------------------------------
3875 | Facility : libnform
3876 | Function : static int PN_First_Page(FORM * form)
3878 | Description : Move to the first page of the form
3880 | Return Values : E_OK - success
3881 | != E_OK - error from subordinate call
3882 +--------------------------------------------------------------------------*/
3884 PN_First_Page(FORM *form)
3886 T((T_CALLED("PN_First_Page(%p)"), form));
3887 returnCode(_nc_Set_Form_Page(form, 0, (FIELD *)0));
3890 /*---------------------------------------------------------------------------
3891 | Facility : libnform
3892 | Function : static int PN_Last_Page(FORM * form)
3894 | Description : Move to the last page of the form
3896 | Return Values : E_OK - success
3897 | != E_OK - error from subordinate call
3898 +--------------------------------------------------------------------------*/
3900 PN_Last_Page(FORM *form)
3902 T((T_CALLED("PN_Last_Page(%p)"), form));
3903 returnCode(_nc_Set_Form_Page(form, form->maxpage - 1, (FIELD *)0));
3906 /*----------------------------------------------------------------------------
3907 END of Field Navigation routines
3908 --------------------------------------------------------------------------*/
3910 /*----------------------------------------------------------------------------
3911 Helper routines for the core form driver.
3912 --------------------------------------------------------------------------*/
3914 /*---------------------------------------------------------------------------
3915 | Facility : libnform
3916 | Function : static int Data_Entry(FORM * form,int c)
3918 | Description : Enter character c into at the current position of the
3919 | current field of the form.
3921 | Return Values : E_OK - success
3922 | E_REQUEST_DENIED - driver could not process the request
3924 +--------------------------------------------------------------------------*/
3926 Data_Entry(FORM *form, int c)
3928 FIELD *field = form->current;
3929 int result = E_REQUEST_DENIED;
3931 T((T_CALLED("Data_Entry(%p,%s)"), form, _tracechtype((chtype)c)));
3932 if ((field->opts & O_EDIT)
3933 #if FIX_FORM_INACTIVE_BUG
3934 && (field->opts & O_ACTIVE)
3938 if ((field->opts & O_BLANK) &&
3939 First_Position_In_Current_Field(form) &&
3940 !(form->status & _FCHECK_REQUIRED) &&
3941 !(form->status & _WINDOW_MODIFIED))
3944 if (form->status & _OVLMODE)
3946 waddch(form->w, (chtype)c);
3951 bool There_Is_Room = Is_There_Room_For_A_Char_In_Line(form);
3953 if (!(There_Is_Room ||
3954 ((Single_Line_Field(field) && Growable(field)))))
3955 RETURN(E_REQUEST_DENIED);
3957 if (!There_Is_Room && !Field_Grown(field, 1))
3958 RETURN(E_SYSTEM_ERROR);
3960 winsch(form->w, (chtype)c);
3963 if ((result = Wrapping_Not_Necessary_Or_Wrapping_Ok(form)) == E_OK)
3965 bool End_Of_Field = (((field->drows - 1) == form->currow) &&
3966 ((field->dcols - 1) == form->curcol));
3968 form->status |= _WINDOW_MODIFIED;
3969 if (End_Of_Field && !Growable(field) && (field->opts & O_AUTOSKIP))
3970 result = Inter_Field_Navigation(FN_Next_Field, form);
3973 if (End_Of_Field && Growable(field) && !Field_Grown(field, 1))
3974 result = E_SYSTEM_ERROR;
3977 #if USE_WIDEC_SUPPORT
3979 * We have just added a byte to the form field. It may have
3980 * been part of a multibyte character. If it was, the
3981 * addch_used field is nonzero and we should not try to move
3984 if (WINDOW_EXT(form->w, addch_used) == 0)
3985 IFN_Next_Character(form);
3987 IFN_Next_Character(form);
3997 /* Structure to describe the binding of a request code to a function.
3998 The member keycode codes the request value as well as the generic
3999 routine to use for the request. The code for the generic routine
4000 is coded in the upper 16 Bits while the request code is coded in
4003 In terms of C++ you might think of a request as a class with a
4004 virtual method "perform". The different types of request are
4005 derived from this base class and overload (or not) the base class
4006 implementation of perform.
4010 int keycode; /* must be at least 32 bit: hi:mode, lo: key */
4011 int (*cmd) (FORM *); /* low level driver routine for this key */
4015 /* You may see this is the class-id of the request type class */
4016 #define ID_PN (0x00000000) /* Page navigation */
4017 #define ID_FN (0x00010000) /* Inter-Field navigation */
4018 #define ID_IFN (0x00020000) /* Intra-Field navigation */
4019 #define ID_VSC (0x00030000) /* Vertical Scrolling */
4020 #define ID_HSC (0x00040000) /* Horizontal Scrolling */
4021 #define ID_FE (0x00050000) /* Field Editing */
4022 #define ID_EM (0x00060000) /* Edit Mode */
4023 #define ID_FV (0x00070000) /* Field Validation */
4024 #define ID_CH (0x00080000) /* Choice */
4025 #define ID_Mask (0xffff0000)
4026 #define Key_Mask (0x0000ffff)
4027 #define ID_Shft (16)
4029 /* This array holds all the Binding Infos */
4031 static const Binding_Info bindings[MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1] =
4033 { REQ_NEXT_PAGE |ID_PN ,PN_Next_Page},
4034 { REQ_PREV_PAGE |ID_PN ,PN_Previous_Page},
4035 { REQ_FIRST_PAGE |ID_PN ,PN_First_Page},
4036 { REQ_LAST_PAGE |ID_PN ,PN_Last_Page},
4038 { REQ_NEXT_FIELD |ID_FN ,FN_Next_Field},
4039 { REQ_PREV_FIELD |ID_FN ,FN_Previous_Field},
4040 { REQ_FIRST_FIELD |ID_FN ,FN_First_Field},
4041 { REQ_LAST_FIELD |ID_FN ,FN_Last_Field},
4042 { REQ_SNEXT_FIELD |ID_FN ,FN_Sorted_Next_Field},
4043 { REQ_SPREV_FIELD |ID_FN ,FN_Sorted_Previous_Field},
4044 { REQ_SFIRST_FIELD |ID_FN ,FN_Sorted_First_Field},
4045 { REQ_SLAST_FIELD |ID_FN ,FN_Sorted_Last_Field},
4046 { REQ_LEFT_FIELD |ID_FN ,FN_Left_Field},
4047 { REQ_RIGHT_FIELD |ID_FN ,FN_Right_Field},
4048 { REQ_UP_FIELD |ID_FN ,FN_Up_Field},
4049 { REQ_DOWN_FIELD |ID_FN ,FN_Down_Field},
4051 { REQ_NEXT_CHAR |ID_IFN ,IFN_Next_Character},
4052 { REQ_PREV_CHAR |ID_IFN ,IFN_Previous_Character},
4053 { REQ_NEXT_LINE |ID_IFN ,IFN_Next_Line},
4054 { REQ_PREV_LINE |ID_IFN ,IFN_Previous_Line},
4055 { REQ_NEXT_WORD |ID_IFN ,IFN_Next_Word},
4056 { REQ_PREV_WORD |ID_IFN ,IFN_Previous_Word},
4057 { REQ_BEG_FIELD |ID_IFN ,IFN_Beginning_Of_Field},
4058 { REQ_END_FIELD |ID_IFN ,IFN_End_Of_Field},
4059 { REQ_BEG_LINE |ID_IFN ,IFN_Beginning_Of_Line},
4060 { REQ_END_LINE |ID_IFN ,IFN_End_Of_Line},
4061 { REQ_LEFT_CHAR |ID_IFN ,IFN_Left_Character},
4062 { REQ_RIGHT_CHAR |ID_IFN ,IFN_Right_Character},
4063 { REQ_UP_CHAR |ID_IFN ,IFN_Up_Character},
4064 { REQ_DOWN_CHAR |ID_IFN ,IFN_Down_Character},
4066 { REQ_NEW_LINE |ID_FE ,FE_New_Line},
4067 { REQ_INS_CHAR |ID_FE ,FE_Insert_Character},
4068 { REQ_INS_LINE |ID_FE ,FE_Insert_Line},
4069 { REQ_DEL_CHAR |ID_FE ,FE_Delete_Character},
4070 { REQ_DEL_PREV |ID_FE ,FE_Delete_Previous},
4071 { REQ_DEL_LINE |ID_FE ,FE_Delete_Line},
4072 { REQ_DEL_WORD |ID_FE ,FE_Delete_Word},
4073 { REQ_CLR_EOL |ID_FE ,FE_Clear_To_End_Of_Line},
4074 { REQ_CLR_EOF |ID_FE ,FE_Clear_To_End_Of_Field},
4075 { REQ_CLR_FIELD |ID_FE ,FE_Clear_Field},
4077 { REQ_OVL_MODE |ID_EM ,EM_Overlay_Mode},
4078 { REQ_INS_MODE |ID_EM ,EM_Insert_Mode},
4080 { REQ_SCR_FLINE |ID_VSC ,VSC_Scroll_Line_Forward},
4081 { REQ_SCR_BLINE |ID_VSC ,VSC_Scroll_Line_Backward},
4082 { REQ_SCR_FPAGE |ID_VSC ,VSC_Scroll_Page_Forward},
4083 { REQ_SCR_BPAGE |ID_VSC ,VSC_Scroll_Page_Backward},
4084 { REQ_SCR_FHPAGE |ID_VSC ,VSC_Scroll_Half_Page_Forward},
4085 { REQ_SCR_BHPAGE |ID_VSC ,VSC_Scroll_Half_Page_Backward},
4087 { REQ_SCR_FCHAR |ID_HSC ,HSC_Scroll_Char_Forward},
4088 { REQ_SCR_BCHAR |ID_HSC ,HSC_Scroll_Char_Backward},
4089 { REQ_SCR_HFLINE |ID_HSC ,HSC_Horizontal_Line_Forward},
4090 { REQ_SCR_HBLINE |ID_HSC ,HSC_Horizontal_Line_Backward},
4091 { REQ_SCR_HFHALF |ID_HSC ,HSC_Horizontal_Half_Line_Forward},
4092 { REQ_SCR_HBHALF |ID_HSC ,HSC_Horizontal_Half_Line_Backward},
4094 { REQ_VALIDATION |ID_FV ,FV_Validation},
4096 { REQ_NEXT_CHOICE |ID_CH ,CR_Next_Choice},
4097 { REQ_PREV_CHOICE |ID_CH ,CR_Previous_Choice}
4101 /*---------------------------------------------------------------------------
4102 | Facility : libnform
4103 | Function : int form_driver(FORM * form,int c)
4105 | Description : This is the workhorse of the forms system. It checks
4106 | to determine whether the character c is a request or
4107 | data. If it is a request, the form driver executes
4108 | the request and returns the result. If it is data
4109 | (printable character), it enters the data into the
4110 | current position in the current field. If it is not
4111 | recognized, the form driver assumes it is an application
4112 | defined command and returns E_UNKNOWN_COMMAND.
4113 | Application defined command should be defined relative
4114 | to MAX_FORM_COMMAND, the maximum value of a request.
4116 | Return Values : E_OK - success
4117 | E_SYSTEM_ERROR - system error
4118 | E_BAD_ARGUMENT - an argument is incorrect
4119 | E_NOT_POSTED - form is not posted
4120 | E_INVALID_FIELD - field contents are invalid
4121 | E_BAD_STATE - called from inside a hook routine
4122 | E_REQUEST_DENIED - request failed
4123 | E_NOT_CONNECTED - no fields are connected to the form
4124 | E_UNKNOWN_COMMAND - command not known
4125 +--------------------------------------------------------------------------*/
4127 form_driver(FORM *form, int c)
4129 const Binding_Info *BI = (Binding_Info *) 0;
4130 int res = E_UNKNOWN_COMMAND;
4132 T((T_CALLED("form_driver(%p,%d)"), form, c));
4135 RETURN(E_BAD_ARGUMENT);
4138 RETURN(E_NOT_CONNECTED);
4142 if (c == FIRST_ACTIVE_MAGIC)
4144 form->current = _nc_First_Active_Field(form);
4148 assert(form->current &&
4149 form->current->buf &&
4150 (form->current->form == form)
4153 if (form->status & _IN_DRIVER)
4154 RETURN(E_BAD_STATE);
4156 if (!(form->status & _POSTED))
4157 RETURN(E_NOT_POSTED);
4159 if ((c >= MIN_FORM_COMMAND && c <= MAX_FORM_COMMAND) &&
4160 ((bindings[c - MIN_FORM_COMMAND].keycode & Key_Mask) == c))
4161 BI = &(bindings[c - MIN_FORM_COMMAND]);
4165 typedef int (*Generic_Method) (int (*const) (FORM *), FORM *);
4166 static const Generic_Method Generic_Methods[] =
4168 Page_Navigation, /* overloaded to call field&form hooks */
4169 Inter_Field_Navigation, /* overloaded to call field hooks */
4170 NULL, /* Intra-Field is generic */
4171 Vertical_Scrolling, /* Overloaded to check multi-line */
4172 Horizontal_Scrolling, /* Overloaded to check single-line */
4173 Field_Editing, /* Overloaded to mark modification */
4174 NULL, /* Edit Mode is generic */
4175 NULL, /* Field Validation is generic */
4176 NULL /* Choice Request is generic */
4178 size_t nMethods = (sizeof(Generic_Methods) / sizeof(Generic_Methods[0]));
4179 size_t method = ((BI->keycode & ID_Mask) >> ID_Shft) & 0xffff;
4181 if ((method >= nMethods) || !(BI->cmd))
4182 res = E_SYSTEM_ERROR;
4185 Generic_Method fct = Generic_Methods[method];
4188 res = fct(BI->cmd, form);
4190 res = (BI->cmd) (form);
4193 #ifdef NCURSES_MOUSE_VERSION
4194 else if (KEY_MOUSE == c)
4197 WINDOW *win = form->win ? form->win : stdscr;
4198 WINDOW *sub = form->sub ? form->sub : win;
4201 if ((event.bstate & (BUTTON1_CLICKED |
4202 BUTTON1_DOUBLE_CLICKED |
4203 BUTTON1_TRIPLE_CLICKED))
4204 && wenclose(win, event.y, event.x))
4205 { /* we react only if the click was in the userwin, that means
4206 * inside the form display area or at the decoration window.
4208 int ry = event.y, rx = event.x; /* screen coordinates */
4210 res = E_REQUEST_DENIED;
4211 if (mouse_trafo(&ry, &rx, FALSE))
4212 { /* rx, ry are now "curses" coordinates */
4213 if (ry < sub->_begy)
4214 { /* we clicked above the display region; this is
4215 * interpreted as "scroll up" request
4217 if (event.bstate & BUTTON1_CLICKED)
4218 res = form_driver(form, REQ_PREV_FIELD);
4219 else if (event.bstate & BUTTON1_DOUBLE_CLICKED)
4220 res = form_driver(form, REQ_PREV_PAGE);
4221 else if (event.bstate & BUTTON1_TRIPLE_CLICKED)
4222 res = form_driver(form, REQ_FIRST_FIELD);
4224 else if (ry > sub->_begy + sub->_maxy)
4225 { /* we clicked below the display region; this is
4226 * interpreted as "scroll down" request
4228 if (event.bstate & BUTTON1_CLICKED)
4229 res = form_driver(form, REQ_NEXT_FIELD);
4230 else if (event.bstate & BUTTON1_DOUBLE_CLICKED)
4231 res = form_driver(form, REQ_NEXT_PAGE);
4232 else if (event.bstate & BUTTON1_TRIPLE_CLICKED)
4233 res = form_driver(form, REQ_LAST_FIELD);
4235 else if (wenclose(sub, event.y, event.x))
4236 { /* Inside the area we try to find the hit item */
4241 if (wmouse_trafo(sub, &ry, &rx, FALSE))
4243 int min_field = form->page[form->curpage].pmin;
4244 int max_field = form->page[form->curpage].pmax;
4246 for (i = min_field; i <= max_field; ++i)
4248 FIELD *field = form->field[i];
4250 if (Field_Is_Selectable(field)
4251 && Field_encloses(field, ry, rx) == E_OK)
4253 res = _nc_Set_Current_Field(form, field);
4255 res = _nc_Position_Form_Cursor(form);
4257 && (event.bstate & BUTTON1_DOUBLE_CLICKED))
4258 res = E_UNKNOWN_COMMAND;
4267 res = E_REQUEST_DENIED;
4269 #endif /* NCURSES_MOUSE_VERSION */
4270 else if (!(c & (~(int)MAX_REGULAR_CHARACTER)))
4273 * If we're using 8-bit characters, iscntrl+isprint cover the whole set.
4274 * But with multibyte characters, there is a third possibility, i.e.,
4275 * parts of characters that build up into printable characters which are
4276 * not considered printable.
4278 * FIXME: the wide-character branch should also use Check_Char().
4280 #if USE_WIDEC_SUPPORT
4281 if (!iscntrl(UChar(c)))
4283 if (isprint(UChar(c)) &&
4284 Check_Char(form->current->type, c,
4285 (TypeArgument *)(form->current->arg)))
4287 res = Data_Entry(form, c);
4289 _nc_Refresh_Current_Field(form);
4293 /*----------------------------------------------------------------------------
4294 Field-Buffer manipulation routines.
4295 The effects of setting a buffer are tightly coupled to the core of the form
4296 driver logic. This is especially true in the case of growable fields.
4297 So I don't separate this into a separate module.
4298 --------------------------------------------------------------------------*/
4300 /*---------------------------------------------------------------------------
4301 | Facility : libnform
4302 | Function : int set_field_buffer(FIELD *field,
4303 | int buffer, char *value)
4305 | Description : Set the given buffer of the field to the given value.
4306 | Buffer 0 stores the displayed content of the field.
4307 | For dynamic fields this may grow the fieldbuffers if
4308 | the length of the value exceeds the current buffer
4309 | length. For buffer 0 only printable values are allowed.
4310 | For static fields, the value needs not to be zero ter-
4311 | minated. It is copied up to the length of the buffer.
4313 | Return Values : E_OK - success
4314 | E_BAD_ARGUMENT - invalid argument
4315 | E_SYSTEM_ERROR - system error
4316 +--------------------------------------------------------------------------*/
4318 set_field_buffer(FIELD *field, int buffer, const char *value)