1 /****************************************************************************
2 * Copyright (c) 1998-2009,2010 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.98 2010/05/01 21:11:43 tom Exp $")
37 /*----------------------------------------------------------------------------
38 This is the core module of the form library. It contains the majority
39 of the driver routines as well as the form_driver function.
41 Essentially this module is nearly the whole library. This is because
42 all the functions in this module depends on some others in the module,
43 so it makes no sense to split them into separate files because they
44 will always be linked together. The only acceptable concern is turnaround
45 time for this module, but now we have all Pentiums or RISCs, so what!
47 The driver routines are grouped into nine generic categories:
49 a) Page Navigation ( all functions prefixed by PN_ )
50 The current page of the form is left and some new page is
52 b) Inter-Field Navigation ( all functions prefixed by FN_ )
53 The current field of the form is left and some new field is
55 c) Intra-Field Navigation ( all functions prefixed by IFN_ )
56 The current position in the current field is changed.
57 d) Vertical Scrolling ( all functions prefixed by VSC_ )
58 Essentially this is a specialization of Intra-Field navigation.
59 It has to check for a multi-line field.
60 e) Horizontal Scrolling ( all functions prefixed by HSC_ )
61 Essentially this is a specialization of Intra-Field navigation.
62 It has to check for a single-line field.
63 f) Field Editing ( all functions prefixed by FE_ )
64 The content of the current field is changed
65 g) Edit Mode requests ( all functions prefixed by EM_ )
66 Switching between insert and overlay mode
67 h) Field-Validation requests ( all functions prefixed by FV_ )
68 Perform verifications of the field.
69 i) Choice requests ( all functions prefixed by CR_ )
70 Requests to enumerate possible field values
71 --------------------------------------------------------------------------*/
73 /*----------------------------------------------------------------------------
74 Some remarks on the placements of assert() macros :
75 I use them only on "strategic" places, i.e. top level entries where
76 I want to make sure that things are set correctly. Throughout subordinate
77 routines I omit them mostly.
78 --------------------------------------------------------------------------*/
81 Some options that may effect compatibility in behavior to SVr4 forms,
82 but they are here to allow a more intuitive and user friendly behavior of
83 our form implementation. This doesn't affect the API, so we feel it is
86 The initial implementation tries to stay very close with the behavior
87 of the original SVr4 implementation, although in some areas it is quite
88 clear that this isn't the most appropriate way. As far as possible this
89 sources will allow you to build a forms lib that behaves quite similar
90 to SVr4, but now and in the future we will give you better options.
91 Perhaps at some time we will make this configurable at runtime.
94 /* Implement a more user-friendly previous/next word behavior */
95 #define FRIENDLY_PREV_NEXT_WORD (1)
96 /* Fix the wrong behavior for forms with all fields inactive */
97 #define FIX_FORM_INACTIVE_BUG (1)
98 /* Allow dynamic field growth also when navigating past the end */
99 #define GROW_IF_NAVIGATE (1)
101 #if USE_WIDEC_SUPPORT
102 #define myADDNSTR(w, s, n) wadd_wchnstr(w, s, n)
103 #define myINSNSTR(w, s, n) wins_wchnstr(w, s, n)
104 #define myINNSTR(w, s, n) fix_wchnstr(w, s, n)
105 #define myWCWIDTH(w, y, x) cell_width(w, y, x)
107 #define myADDNSTR(w, s, n) waddnstr(w, s, n)
108 #define myINSNSTR(w, s, n) winsnstr(w, s, n)
109 #define myINNSTR(w, s, n) winnstr(w, s, n)
110 #define myWCWIDTH(w, y, x) 1
113 /*----------------------------------------------------------------------------
114 Forward references to some internally used static functions
115 --------------------------------------------------------------------------*/
116 static int Inter_Field_Navigation(int (*const fct
) (FORM
*), FORM
*form
);
117 static int FN_Next_Field(FORM
*form
);
118 static int FN_Previous_Field(FORM
*form
);
119 static int FE_New_Line(FORM
*);
120 static int FE_Delete_Previous(FORM
*);
122 /*----------------------------------------------------------------------------
125 Some Remarks on that: I use the convention to use UPPERCASE for constants
126 defined by Macros. If I provide a macro as a kind of inline routine to
127 provide some logic, I use my Upper_Lower case style.
128 --------------------------------------------------------------------------*/
130 /* Calculate the position of a single row in a field buffer */
131 #define Position_Of_Row_In_Buffer(field,row) ((row)*(field)->dcols)
133 /* Calculate start address for the fields buffer# N */
134 #define Address_Of_Nth_Buffer(field,N) \
135 ((field)->buf + (N)*(1+Buffer_Length(field)))
137 /* Calculate the start address of the row in the fields specified buffer# N */
138 #define Address_Of_Row_In_Nth_Buffer(field,N,row) \
139 (Address_Of_Nth_Buffer(field,N) + Position_Of_Row_In_Buffer(field,row))
141 /* Calculate the start address of the row in the fields primary buffer */
142 #define Address_Of_Row_In_Buffer(field,row) \
143 Address_Of_Row_In_Nth_Buffer(field,0,row)
145 /* Calculate the start address of the row in the forms current field
147 #define Address_Of_Current_Row_In_Nth_Buffer(form,N) \
148 Address_Of_Row_In_Nth_Buffer((form)->current,N,(form)->currow)
150 /* Calculate the start address of the row in the forms current field
152 #define Address_Of_Current_Row_In_Buffer(form) \
153 Address_Of_Current_Row_In_Nth_Buffer(form,0)
155 /* Calculate the address of the cursor in the forms current field
157 #define Address_Of_Current_Position_In_Nth_Buffer(form,N) \
158 (Address_Of_Current_Row_In_Nth_Buffer(form,N) + (form)->curcol)
160 /* Calculate the address of the cursor in the forms current field
162 #define Address_Of_Current_Position_In_Buffer(form) \
163 Address_Of_Current_Position_In_Nth_Buffer(form,0)
165 /* Logic to decide whether or not a field is actually a field with
166 vertical or horizontal scrolling */
167 #define Is_Scroll_Field(field) \
168 (((field)->drows > (field)->rows) || \
169 ((field)->dcols > (field)->cols))
171 /* Logic to decide whether or not a field needs to have an individual window
172 instead of a derived window because it contains invisible parts.
173 This is true for non-public fields and for scrollable fields. */
174 #define Has_Invisible_Parts(field) \
175 (!((field)->opts & O_PUBLIC) || \
176 Is_Scroll_Field(field))
178 /* Logic to decide whether or not a field needs justification */
179 #define Justification_Allowed(field) \
180 (((field)->just != NO_JUSTIFICATION) && \
181 (Single_Line_Field(field)) && \
182 (((field)->dcols == (field)->cols) && \
183 ((field)->opts & O_STATIC)) )
185 /* Logic to determine whether or not a dynamic field may still grow */
186 #define Growable(field) ((field)->status & _MAY_GROW)
188 /* Macro to set the attributes for a fields window */
189 #define Set_Field_Window_Attributes(field,win) \
190 ( wbkgdset((win),(chtype)((field)->pad | (field)->back)), \
191 (void) wattrset((win),(field)->fore) )
193 /* Logic to decide whether or not a field really appears on the form */
194 #define Field_Really_Appears(field) \
196 (field->form->status & _POSTED) &&\
197 (field->opts & O_VISIBLE) &&\
198 (field->page == field->form->curpage))
200 /* Logic to determine whether or not we are on the first position in the
202 #define First_Position_In_Current_Field(form) \
203 (((form)->currow == 0) && ((form)->curcol == 0))
205 #define Minimum(a,b) (((a)<=(b)) ? (a) : (b))
206 #define Maximum(a,b) (((a)>=(b)) ? (a) : (b))
208 /*----------------------------------------------------------------------------
210 --------------------------------------------------------------------------*/
211 static FIELD_CELL myBLANK
= BLANK
;
212 static FIELD_CELL myZEROS
;
216 check_pos(FORM
*form
, int lineno
)
222 getyx(form
->w
, y
, x
);
223 if (y
!= form
->currow
|| x
!= form
->curcol
)
225 T(("CHECKPOS %s@%d have position %d,%d vs want %d,%d",
228 form
->currow
, form
->curcol
));
232 #define CHECKPOS(form) check_pos(form, __LINE__)
234 #define CHECKPOS(form) /* nothing */
237 /*----------------------------------------------------------------------------
238 Wide-character special functions
239 --------------------------------------------------------------------------*/
240 #if USE_WIDEC_SUPPORT
243 wins_wchnstr(WINDOW
*w
, cchar_t
*s
, int n
)
251 if ((code
= wins_wch(w
, s
++)) != OK
)
253 if ((code
= wmove(w
, y
, x
+ 1)) != OK
)
259 /* win_wchnstr is inconsistent with winnstr, since it returns OK rather than
260 * the number of items transferred.
263 fix_wchnstr(WINDOW
*w
, cchar_t
*s
, int n
)
267 win_wchnstr(w
, s
, n
);
269 * This function is used to extract the text only from the window.
270 * Strip attributes and color from the string so they will not be added
271 * back when copying the string to the window.
273 for (x
= 0; x
< n
; ++x
)
275 RemAttr(s
[x
], A_ATTRIBUTES
);
282 * Returns the column of the base of the given cell.
285 cell_base(WINDOW
*win
, int y
, int x
)
289 while (LEGALYX(win
, y
, x
))
291 cchar_t
*data
= &(win
->_line
[y
].text
[x
]);
293 if (isWidecBase(CHDEREF(data
)) || !isWidecExt(CHDEREF(data
)))
304 * Returns the number of columns needed for the given cell in a window.
307 cell_width(WINDOW
*win
, int y
, int x
)
311 if (LEGALYX(win
, y
, x
))
313 cchar_t
*data
= &(win
->_line
[y
].text
[x
]);
315 if (isWidecExt(CHDEREF(data
)))
317 /* recur, providing the number of columns to the next character */
318 result
= cell_width(win
, y
, x
- 1);
322 result
= wcwidth(CharOf(CHDEREF(data
)));
329 * There is no wide-character function such as wdel_wch(), so we must find
330 * all of the cells that comprise a multi-column character and delete them
334 delete_char(FORM
*form
)
336 int cells
= cell_width(form
->w
, form
->currow
, form
->curcol
);
338 form
->curcol
= cell_base(form
->w
, form
->currow
, form
->curcol
);
339 wmove(form
->w
, form
->currow
, form
->curcol
);
345 #define DeleteChar(form) delete_char(form)
347 #define DeleteChar(form) \
348 wmove((form)->w, (form)->currow, (form)->curcol), \
352 /*---------------------------------------------------------------------------
353 | Facility : libnform
354 | Function : static char *Get_Start_Of_Data(char * buf, int blen)
356 | Description : Return pointer to first non-blank position in buffer.
357 | If buffer is empty return pointer to buffer itself.
359 | Return Values : Pointer to first non-blank position in buffer
360 +--------------------------------------------------------------------------*/
361 NCURSES_INLINE
static FIELD_CELL
*
362 Get_Start_Of_Data(FIELD_CELL
*buf
, int blen
)
365 FIELD_CELL
*end
= &buf
[blen
];
367 assert(buf
&& blen
>= 0);
368 while ((p
< end
) && ISBLANK(*p
))
370 return ((p
== end
) ? buf
: p
);
373 /*---------------------------------------------------------------------------
374 | Facility : libnform
375 | Function : static char *After_End_Of_Data(char * buf, int blen)
377 | Description : Return pointer after last non-blank position in buffer.
378 | If buffer is empty, return pointer to buffer itself.
380 | Return Values : Pointer to position after last non-blank position in
382 +--------------------------------------------------------------------------*/
383 NCURSES_INLINE
static FIELD_CELL
*
384 After_End_Of_Data(FIELD_CELL
*buf
, int blen
)
386 FIELD_CELL
*p
= &buf
[blen
];
388 assert(buf
&& blen
>= 0);
389 while ((p
> buf
) && ISBLANK(p
[-1]))
394 /*---------------------------------------------------------------------------
395 | Facility : libnform
396 | Function : static char *Get_First_Whitespace_Character(
397 | char * buf, int blen)
399 | Description : Position to the first whitespace character.
401 | Return Values : Pointer to first whitespace character in buffer.
402 +--------------------------------------------------------------------------*/
403 NCURSES_INLINE
static FIELD_CELL
*
404 Get_First_Whitespace_Character(FIELD_CELL
*buf
, int blen
)
407 FIELD_CELL
*end
= &p
[blen
];
409 assert(buf
&& blen
>= 0);
410 while ((p
< end
) && !ISBLANK(*p
))
412 return ((p
== end
) ? buf
: p
);
415 /*---------------------------------------------------------------------------
416 | Facility : libnform
417 | Function : static char *After_Last_Whitespace_Character(
418 | char * buf, int blen)
420 | Description : Get the position after the last whitespace character.
422 | Return Values : Pointer to position after last whitespace character in
424 +--------------------------------------------------------------------------*/
425 NCURSES_INLINE
static FIELD_CELL
*
426 After_Last_Whitespace_Character(FIELD_CELL
*buf
, int blen
)
428 FIELD_CELL
*p
= &buf
[blen
];
430 assert(buf
&& blen
>= 0);
431 while ((p
> buf
) && !ISBLANK(p
[-1]))
436 /* Set this to 1 to use the div_t version. This is a good idea if your
437 compiler has an intrinsic div() support. Unfortunately GNU-C has it
439 N.B.: This only works if form->curcol follows immediately form->currow
440 and both are of type int.
442 #define USE_DIV_T (0)
444 /*---------------------------------------------------------------------------
445 | Facility : libnform
446 | Function : static void Adjust_Cursor_Position(
447 | FORM * form, const char * pos)
449 | Description : Set current row and column of the form to values
450 | corresponding to the buffer position.
453 +--------------------------------------------------------------------------*/
454 NCURSES_INLINE
static void
455 Adjust_Cursor_Position(FORM
*form
, const FIELD_CELL
*pos
)
460 field
= form
->current
;
461 assert(pos
>= field
->buf
&& field
->dcols
> 0);
462 idx
= (int)(pos
- field
->buf
);
464 *((div_t *) & (form
->currow
)) = div(idx
, field
->dcols
);
466 form
->currow
= idx
/ field
->dcols
;
467 form
->curcol
= idx
- field
->cols
* form
->currow
;
469 if (field
->drows
< form
->currow
)
473 /*---------------------------------------------------------------------------
474 | Facility : libnform
475 | Function : static void Buffer_To_Window(
476 | const FIELD * field,
479 | Description : Copy the buffer to the window. If it is a multi-line
480 | field, the buffer is split to the lines of the
481 | window without any editing.
484 +--------------------------------------------------------------------------*/
486 Buffer_To_Window(const FIELD
*field
, WINDOW
*win
)
494 assert(win
&& field
);
497 width
= getmaxx(win
);
498 height
= getmaxy(win
);
500 for (row
= 0, pBuffer
= field
->buf
;
502 row
++, pBuffer
+= width
)
504 if ((len
= (int)(After_End_Of_Data(pBuffer
, width
) - pBuffer
)) > 0)
507 myADDNSTR(win
, pBuffer
, len
);
513 /*---------------------------------------------------------------------------
514 | Facility : libnform
515 | Function : void _nc_get_fieldbuffer(
520 | Description : Copy the content of the window into the buffer.
521 | The multiple lines of a window are simply
522 | concatenated into the buffer. Pad characters in
523 | the window will be replaced by blanks in the buffer.
526 +--------------------------------------------------------------------------*/
528 _nc_get_fieldbuffer(FORM
*form
, FIELD
*field
, FIELD_CELL
*buf
)
536 assert(form
&& field
&& buf
);
543 height
= getmaxy(win
);
545 for (row
= 0; (row
< height
) && (row
< field
->drows
); row
++)
548 len
+= myINNSTR(win
, p
+ len
, field
->dcols
);
552 /* replace visual padding character by blanks in buffer */
557 for (i
= 0; i
< len
; i
++, p
++)
559 if ((unsigned long)CharOf(*p
) == ChCharOf(pad
)
560 #if USE_WIDEC_SUPPORT
569 /*---------------------------------------------------------------------------
570 | Facility : libnform
571 | Function : static void Window_To_Buffer(
575 | Description : Copy the content of the window into the buffer.
576 | The multiple lines of a window are simply
577 | concatenated into the buffer. Pad characters in
578 | the window will be replaced by blanks in the buffer.
581 +--------------------------------------------------------------------------*/
583 Window_To_Buffer(FORM
*form
, FIELD
*field
)
585 _nc_get_fieldbuffer(form
, field
, field
->buf
);
588 /*---------------------------------------------------------------------------
589 | Facility : libnform
590 | Function : static void Synchronize_Buffer(FORM * form)
592 | Description : If there was a change, copy the content of the
593 | window into the buffer, so the buffer is synchronized
594 | with the windows content. We have to indicate that the
595 | buffer needs validation due to the change.
598 +--------------------------------------------------------------------------*/
599 NCURSES_INLINE
static void
600 Synchronize_Buffer(FORM
*form
)
602 if (form
->status
& _WINDOW_MODIFIED
)
604 form
->status
&= ~_WINDOW_MODIFIED
;
605 form
->status
|= _FCHECK_REQUIRED
;
606 Window_To_Buffer(form
, form
->current
);
607 wmove(form
->w
, form
->currow
, form
->curcol
);
611 /*---------------------------------------------------------------------------
612 | Facility : libnform
613 | Function : static bool Field_Grown( FIELD *field, int amount)
615 | Description : This function is called for growable dynamic fields
616 | only. It has to increase the buffers and to allocate
617 | a new window for this field.
618 | This function has the side effect to set a new
619 | field-buffer pointer, the dcols and drows values
620 | as well as a new current Window for the field.
622 | Return Values : TRUE - field successfully increased
623 | FALSE - there was some error
624 +--------------------------------------------------------------------------*/
626 Field_Grown(FIELD
*field
, int amount
)
630 if (field
&& Growable(field
))
632 bool single_line_field
= Single_Line_Field(field
);
633 int old_buflen
= Buffer_Length(field
);
635 int old_dcols
= field
->dcols
;
636 int old_drows
= field
->drows
;
637 FIELD_CELL
*oldbuf
= field
->buf
;
641 FORM
*form
= field
->form
;
642 bool need_visual_update
= ((form
!= (FORM
*)0) &&
643 (form
->status
& _POSTED
) &&
644 (form
->current
== field
));
646 if (need_visual_update
)
647 Synchronize_Buffer(form
);
649 if (single_line_field
)
651 growth
= field
->cols
* amount
;
653 growth
= Minimum(field
->maxgrow
- field
->dcols
, growth
);
654 field
->dcols
+= growth
;
655 if (field
->dcols
== field
->maxgrow
)
656 field
->status
&= ~_MAY_GROW
;
660 growth
= (field
->rows
+ field
->nrow
) * amount
;
662 growth
= Minimum(field
->maxgrow
- field
->drows
, growth
);
663 field
->drows
+= growth
;
664 if (field
->drows
== field
->maxgrow
)
665 field
->status
&= ~_MAY_GROW
;
667 /* drows, dcols changed, so we get really the new buffer length */
668 new_buflen
= Buffer_Length(field
);
669 newbuf
= (FIELD_CELL
*)malloc(Total_Buffer_Size(field
));
672 /* restore to previous state */
673 field
->dcols
= old_dcols
;
674 field
->drows
= old_drows
;
675 if ((single_line_field
&& (field
->dcols
!= field
->maxgrow
)) ||
676 (!single_line_field
&& (field
->drows
!= field
->maxgrow
)))
677 field
->status
|= _MAY_GROW
;
681 /* Copy all the buffers. This is the reason why we can't just use
688 result
= TRUE
; /* allow sharing of recovery on failure */
690 T((T_CREATE("fieldcell %p"), (void *)newbuf
));
692 for (i
= 0; i
<= field
->nbuf
; i
++)
694 new_bp
= Address_Of_Nth_Buffer(field
, i
);
695 old_bp
= oldbuf
+ i
* (1 + old_buflen
);
696 for (j
= 0; j
< old_buflen
; ++j
)
697 new_bp
[j
] = old_bp
[j
];
698 while (j
< new_buflen
)
699 new_bp
[j
++] = myBLANK
;
700 new_bp
[new_buflen
] = myZEROS
;
703 #if USE_WIDEC_SUPPORT && NCURSES_EXT_FUNCS
704 if (wresize(field
->working
, 1, Buffer_Length(field
) + 1) == ERR
)
708 if (need_visual_update
&& result
)
710 WINDOW
*new_window
= newpad(field
->drows
, field
->dcols
);
714 assert(form
!= (FORM
*)0);
717 form
->w
= new_window
;
718 Set_Field_Window_Attributes(field
, form
->w
);
720 Buffer_To_Window(field
, form
->w
);
722 wmove(form
->w
, form
->currow
, form
->curcol
);
731 /* reflect changes in linked fields */
732 if (field
!= field
->link
)
736 for (linked_field
= field
->link
;
737 linked_field
!= field
;
738 linked_field
= linked_field
->link
)
740 linked_field
->buf
= field
->buf
;
741 linked_field
->drows
= field
->drows
;
742 linked_field
->dcols
= field
->dcols
;
748 /* restore old state */
749 field
->dcols
= old_dcols
;
750 field
->drows
= old_drows
;
752 if ((single_line_field
&&
753 (field
->dcols
!= field
->maxgrow
)) ||
754 (!single_line_field
&&
755 (field
->drows
!= field
->maxgrow
)))
756 field
->status
|= _MAY_GROW
;
764 #ifdef NCURSES_MOUSE_VERSION
765 /*---------------------------------------------------------------------------
766 | Facility : libnform
767 | Function : int Field_encloses(FIELD *field, int ry, int rx)
769 | Description : Check if the given coordinates lie within the given field.
771 | Return Values : E_OK - success
772 | E_BAD_ARGUMENT - invalid form pointer
773 | E_SYSTEM_ERROR - form has no current field or
775 +--------------------------------------------------------------------------*/
777 Field_encloses(FIELD
*field
, int ry
, int rx
)
779 T((T_CALLED("Field_encloses(%p)"), (void *)field
));
782 && (field
->frow
+ field
->rows
) > ry
784 && (field
->fcol
+ field
->cols
) > rx
)
788 RETURN(E_INVALID_FIELD
);
792 /*---------------------------------------------------------------------------
793 | Facility : libnform
794 | Function : int _nc_Position_Form_Cursor(FORM * form)
796 | Description : Position the cursor in the window for the current
797 | field to be in sync. with the currow and curcol
800 | Return Values : E_OK - success
801 | E_BAD_ARGUMENT - invalid form pointer
802 | E_SYSTEM_ERROR - form has no current field or
804 +--------------------------------------------------------------------------*/
806 _nc_Position_Form_Cursor(FORM
*form
)
812 return (E_BAD_ARGUMENT
);
814 if (!form
->w
|| !form
->current
)
815 return (E_SYSTEM_ERROR
);
817 field
= form
->current
;
818 formwin
= Get_Form_Window(form
);
820 wmove(form
->w
, form
->currow
, form
->curcol
);
821 if (Has_Invisible_Parts(field
))
823 /* in this case fieldwin isn't derived from formwin, so we have
824 to move the cursor in formwin by hand... */
826 field
->frow
+ form
->currow
- form
->toprow
,
827 field
->fcol
+ form
->curcol
- form
->begincol
);
835 /*---------------------------------------------------------------------------
836 | Facility : libnform
837 | Function : int _nc_Refresh_Current_Field(FORM * form)
839 | Description : Propagate the changes in the fields window to the
840 | window of the form.
842 | Return Values : E_OK - on success
843 | E_BAD_ARGUMENT - invalid form pointer
844 | E_SYSTEM_ERROR - general error
845 +--------------------------------------------------------------------------*/
847 _nc_Refresh_Current_Field(FORM
*form
)
852 T((T_CALLED("_nc_Refresh_Current_Field(%p)"), (void *)form
));
855 RETURN(E_BAD_ARGUMENT
);
857 if (!form
->w
|| !form
->current
)
858 RETURN(E_SYSTEM_ERROR
);
860 field
= form
->current
;
861 formwin
= Get_Form_Window(form
);
863 if (field
->opts
& O_PUBLIC
)
865 if (Is_Scroll_Field(field
))
867 /* Again, in this case the fieldwin isn't derived from formwin,
868 so we have to perform a copy operation. */
869 if (Single_Line_Field(field
))
871 /* horizontal scrolling */
872 if (form
->curcol
< form
->begincol
)
873 form
->begincol
= form
->curcol
;
876 if (form
->curcol
>= (form
->begincol
+ field
->cols
))
877 form
->begincol
= form
->curcol
- field
->cols
+ 1;
886 field
->cols
+ field
->fcol
- 1,
891 /* A multi-line, i.e. vertical scrolling field */
892 int row_after_bottom
, first_modified_row
, first_unmodified_row
;
894 if (field
->drows
> field
->rows
)
896 row_after_bottom
= form
->toprow
+ field
->rows
;
897 if (form
->currow
< form
->toprow
)
899 form
->toprow
= form
->currow
;
900 field
->status
|= _NEWTOP
;
902 if (form
->currow
>= row_after_bottom
)
904 form
->toprow
= form
->currow
- field
->rows
+ 1;
905 field
->status
|= _NEWTOP
;
907 if (field
->status
& _NEWTOP
)
909 /* means we have to copy whole range */
910 first_modified_row
= form
->toprow
;
911 first_unmodified_row
= first_modified_row
+ field
->rows
;
912 field
->status
&= ~_NEWTOP
;
916 /* we try to optimize : finding the range of touched
918 first_modified_row
= form
->toprow
;
919 while (first_modified_row
< row_after_bottom
)
921 if (is_linetouched(form
->w
, first_modified_row
))
923 first_modified_row
++;
925 first_unmodified_row
= first_modified_row
;
926 while (first_unmodified_row
< row_after_bottom
)
928 if (!is_linetouched(form
->w
, first_unmodified_row
))
930 first_unmodified_row
++;
936 first_modified_row
= form
->toprow
;
937 first_unmodified_row
= first_modified_row
+ field
->rows
;
939 if (first_unmodified_row
!= first_modified_row
)
944 field
->frow
+ first_modified_row
- form
->toprow
,
946 field
->frow
+ first_unmodified_row
- form
->toprow
- 1,
947 field
->cols
+ field
->fcol
- 1,
954 /* if the field-window is simply a derived window, i.e. contains no
955 * invisible parts, the whole thing is trivial
961 returnCode(_nc_Position_Form_Cursor(form
));
964 /*---------------------------------------------------------------------------
965 | Facility : libnform
966 | Function : static void Perform_Justification(
970 | Description : Output field with requested justification
973 +--------------------------------------------------------------------------*/
975 Perform_Justification(FIELD
*field
, WINDOW
*win
)
981 bp
= Get_Start_Of_Data(field
->buf
, Buffer_Length(field
));
982 len
= (int)(After_End_Of_Data(field
->buf
, Buffer_Length(field
)) - bp
);
986 assert(win
&& (field
->drows
== 1) && (field
->dcols
== field
->cols
));
993 col
= (field
->cols
- len
) / 2;
996 col
= field
->cols
- len
;
1003 myADDNSTR(win
, bp
, len
);
1007 /*---------------------------------------------------------------------------
1008 | Facility : libnform
1009 | Function : static void Undo_Justification(
1013 | Description : Display field without any justification, i.e.
1017 +--------------------------------------------------------------------------*/
1019 Undo_Justification(FIELD
*field
, WINDOW
*win
)
1024 bp
= Get_Start_Of_Data(field
->buf
, Buffer_Length(field
));
1025 len
= (int)(After_End_Of_Data(field
->buf
, Buffer_Length(field
)) - bp
);
1031 myADDNSTR(win
, bp
, len
);
1035 /*---------------------------------------------------------------------------
1036 | Facility : libnform
1037 | Function : static bool Check_Char(FORM *form,
1041 | TypeArgument *argp)
1043 | Description : Perform a single character check for character ch
1044 | according to the fieldtype instance.
1046 | Return Values : TRUE - Character is valid
1047 | FALSE - Character is invalid
1048 +--------------------------------------------------------------------------*/
1050 Check_Char(FORM
*form
,
1058 if (typ
->status
& _LINKED_TYPE
)
1062 Check_Char(form
, field
, typ
->left
, ch
, argp
->left
) ||
1063 Check_Char(form
, field
, typ
->right
, ch
, argp
->right
));
1067 #if NCURSES_INTEROP_FUNCS
1068 if (typ
->charcheck
.occheck
)
1070 if (typ
->status
& _GENERIC
)
1071 return typ
->charcheck
.gccheck(ch
, form
, field
, (void *)argp
);
1073 return typ
->charcheck
.occheck(ch
, (void *)argp
);
1077 return typ
->ccheck(ch
, (void *)argp
);
1081 return (!iscntrl(UChar(ch
)) ? TRUE
: FALSE
);
1084 /*---------------------------------------------------------------------------
1085 | Facility : libnform
1086 | Function : static int Display_Or_Erase_Field(
1090 | Description : Create a subwindow for the field and display the
1091 | buffer contents (apply justification if required)
1092 | or simply erase the field.
1094 | Return Values : E_OK - on success
1095 | E_SYSTEM_ERROR - some error (typical no memory)
1096 +--------------------------------------------------------------------------*/
1098 Display_Or_Erase_Field(FIELD
*field
, bool bEraseFlag
)
1104 return E_SYSTEM_ERROR
;
1106 fwin
= Get_Form_Window(field
->form
);
1108 field
->rows
, field
->cols
, field
->frow
, field
->fcol
);
1111 return E_SYSTEM_ERROR
;
1114 if (field
->opts
& O_VISIBLE
)
1116 Set_Field_Window_Attributes(field
, win
);
1120 (void)wattrset(win
, WINDOW_ATTRS(fwin
));
1127 if (field
->opts
& O_PUBLIC
)
1129 if (Justification_Allowed(field
))
1130 Perform_Justification(field
, win
);
1132 Buffer_To_Window(field
, win
);
1134 field
->status
&= ~_NEWTOP
;
1141 /* Macros to preset the bEraseFlag */
1142 #define Display_Field(field) Display_Or_Erase_Field(field,FALSE)
1143 #define Erase_Field(field) Display_Or_Erase_Field(field,TRUE)
1145 /*---------------------------------------------------------------------------
1146 | Facility : libnform
1147 | Function : static int Synchronize_Field(FIELD * field)
1149 | Description : Synchronize the windows content with the value in
1152 | Return Values : E_OK - success
1153 | E_BAD_ARGUMENT - invalid field pointer
1154 | E_SYSTEM_ERROR - some severe basic error
1155 +--------------------------------------------------------------------------*/
1157 Synchronize_Field(FIELD
*field
)
1163 return (E_BAD_ARGUMENT
);
1165 if (((form
= field
->form
) != (FORM
*)0)
1166 && Field_Really_Appears(field
))
1168 if (field
== form
->current
)
1170 form
->currow
= form
->curcol
= form
->toprow
= form
->begincol
= 0;
1173 if ((field
->opts
& O_PUBLIC
) && Justification_Allowed(field
))
1174 Undo_Justification(field
, form
->w
);
1176 Buffer_To_Window(field
, form
->w
);
1178 field
->status
|= _NEWTOP
;
1179 res
= _nc_Refresh_Current_Field(form
);
1182 res
= Display_Field(field
);
1184 field
->status
|= _CHANGED
;
1188 /*---------------------------------------------------------------------------
1189 | Facility : libnform
1190 | Function : static int Synchronize_Linked_Fields(FIELD * field)
1192 | Description : Propagate the Synchronize_Field function to all linked
1193 | fields. The first error that occurs in the sequence
1194 | of updates is the return value.
1196 | Return Values : E_OK - success
1197 | E_BAD_ARGUMENT - invalid field pointer
1198 | E_SYSTEM_ERROR - some severe basic error
1199 +--------------------------------------------------------------------------*/
1201 Synchronize_Linked_Fields(FIELD
*field
)
1203 FIELD
*linked_field
;
1208 return (E_BAD_ARGUMENT
);
1211 return (E_SYSTEM_ERROR
);
1213 for (linked_field
= field
->link
;
1214 linked_field
!= field
;
1215 linked_field
= linked_field
->link
)
1217 if (((syncres
= Synchronize_Field(linked_field
)) != E_OK
) &&
1224 /*---------------------------------------------------------------------------
1225 | Facility : libnform
1226 | Function : int _nc_Synchronize_Attributes(FIELD * field)
1228 | Description : If a fields visual attributes have changed, this
1229 | routine is called to propagate those changes to the
1232 | Return Values : E_OK - success
1233 | E_BAD_ARGUMENT - invalid field pointer
1234 | E_SYSTEM_ERROR - some severe basic error
1235 +--------------------------------------------------------------------------*/
1237 _nc_Synchronize_Attributes(FIELD
*field
)
1243 T((T_CALLED("_nc_Synchronize_Attributes(%p)"), (void *)field
));
1246 returnCode(E_BAD_ARGUMENT
);
1248 CHECKPOS(field
->form
);
1249 if (((form
= field
->form
) != (FORM
*)0)
1250 && Field_Really_Appears(field
))
1252 if (form
->current
== field
)
1254 Synchronize_Buffer(form
);
1255 Set_Field_Window_Attributes(field
, form
->w
);
1257 wmove(form
->w
, form
->currow
, form
->curcol
);
1259 if (field
->opts
& O_PUBLIC
)
1261 if (Justification_Allowed(field
))
1262 Undo_Justification(field
, form
->w
);
1264 Buffer_To_Window(field
, form
->w
);
1268 formwin
= Get_Form_Window(form
);
1269 copywin(form
->w
, formwin
,
1271 field
->frow
, field
->fcol
,
1272 field
->rows
- 1, field
->cols
- 1, 0);
1274 Buffer_To_Window(field
, form
->w
);
1275 field
->status
|= _NEWTOP
; /* fake refresh to paint all */
1276 _nc_Refresh_Current_Field(form
);
1281 res
= Display_Field(field
);
1288 /*---------------------------------------------------------------------------
1289 | Facility : libnform
1290 | Function : int _nc_Synchronize_Options(FIELD * field,
1291 | Field_Options newopts)
1293 | Description : If a fields options have changed, this routine is
1294 | called to propagate these changes to the screen and
1295 | to really change the behavior of the field.
1297 | Return Values : E_OK - success
1298 | E_BAD_ARGUMENT - invalid field pointer
1299 | E_CURRENT - field is the current one
1300 | E_SYSTEM_ERROR - some severe basic error
1301 +--------------------------------------------------------------------------*/
1303 _nc_Synchronize_Options(FIELD
*field
, Field_Options newopts
)
1305 Field_Options oldopts
;
1306 Field_Options changed_opts
;
1310 T((T_CALLED("_nc_Synchronize_Options(%p,%#x)"), (void *)field
, newopts
));
1313 returnCode(E_BAD_ARGUMENT
);
1315 oldopts
= field
->opts
;
1316 changed_opts
= oldopts
^ newopts
;
1317 field
->opts
= newopts
;
1322 if (form
->status
& _POSTED
)
1324 if (form
->current
== field
)
1326 field
->opts
= oldopts
;
1327 returnCode(E_CURRENT
);
1329 if (form
->curpage
== field
->page
)
1331 if (changed_opts
& O_VISIBLE
)
1333 if (newopts
& O_VISIBLE
)
1334 res
= Display_Field(field
);
1336 res
= Erase_Field(field
);
1340 if ((changed_opts
& O_PUBLIC
) &&
1341 (newopts
& O_VISIBLE
))
1342 res
= Display_Field(field
);
1348 if (changed_opts
& O_STATIC
)
1350 bool single_line_field
= Single_Line_Field(field
);
1353 if (newopts
& O_STATIC
)
1355 /* the field becomes now static */
1356 field
->status
&= ~_MAY_GROW
;
1357 /* if actually we have no hidden columns, justification may
1359 if (single_line_field
&&
1360 (field
->cols
== field
->dcols
) &&
1361 (field
->just
!= NO_JUSTIFICATION
) &&
1362 Field_Really_Appears(field
))
1364 res2
= Display_Field(field
);
1369 /* field is no longer static */
1370 if ((field
->maxgrow
== 0) ||
1371 (single_line_field
&& (field
->dcols
< field
->maxgrow
)) ||
1372 (!single_line_field
&& (field
->drows
< field
->maxgrow
)))
1374 field
->status
|= _MAY_GROW
;
1375 /* a field with justification now changes its behavior,
1376 so we must redisplay it */
1377 if (single_line_field
&&
1378 (field
->just
!= NO_JUSTIFICATION
) &&
1379 Field_Really_Appears(field
))
1381 res2
= Display_Field(field
);
1392 /*---------------------------------------------------------------------------
1393 | Facility : libnform
1394 | Function : int _nc_Set_Current_Field(FORM * form,
1397 | Description : Make the newfield the new current field.
1399 | Return Values : E_OK - success
1400 | E_BAD_ARGUMENT - invalid form or field pointer
1401 | E_SYSTEM_ERROR - some severe basic error
1402 | E_NOT_CONNECTED - no fields are connected to the form
1403 +--------------------------------------------------------------------------*/
1405 _nc_Set_Current_Field(FORM
*form
, FIELD
*newfield
)
1410 T((T_CALLED("_nc_Set_Current_Field(%p,%p)"), (void *)form
, (void *)newfield
));
1412 if (!form
|| !newfield
|| !form
->current
|| (newfield
->form
!= form
))
1413 returnCode(E_BAD_ARGUMENT
);
1415 if ((form
->status
& _IN_DRIVER
))
1416 returnCode(E_BAD_STATE
);
1419 returnCode(E_NOT_CONNECTED
);
1421 field
= form
->current
;
1423 if ((field
!= newfield
) ||
1424 !(form
->status
& _POSTED
))
1427 (field
->opts
& O_VISIBLE
) &&
1428 (field
->form
->curpage
== field
->page
))
1430 _nc_Refresh_Current_Field(form
);
1431 if (field
->opts
& O_PUBLIC
)
1433 if (field
->drows
> field
->rows
)
1435 if (form
->toprow
== 0)
1436 field
->status
&= ~_NEWTOP
;
1438 field
->status
|= _NEWTOP
;
1442 if (Justification_Allowed(field
))
1444 Window_To_Buffer(form
, field
);
1446 Perform_Justification(field
, form
->w
);
1452 form
->w
= (WINDOW
*)0;
1457 if (Has_Invisible_Parts(field
))
1458 new_window
= newpad(field
->drows
, field
->dcols
);
1460 new_window
= derwin(Get_Form_Window(form
),
1461 field
->rows
, field
->cols
, field
->frow
, field
->fcol
);
1464 returnCode(E_SYSTEM_ERROR
);
1466 form
->current
= field
;
1470 form
->w
= new_window
;
1472 form
->status
&= ~_WINDOW_MODIFIED
;
1473 Set_Field_Window_Attributes(field
, form
->w
);
1475 if (Has_Invisible_Parts(field
))
1478 Buffer_To_Window(field
, form
->w
);
1482 if (Justification_Allowed(field
))
1485 Undo_Justification(field
, form
->w
);
1490 untouchwin(form
->w
);
1493 form
->currow
= form
->curcol
= form
->toprow
= form
->begincol
= 0;
1497 /*----------------------------------------------------------------------------
1498 Intra-Field Navigation routines
1499 --------------------------------------------------------------------------*/
1501 /*---------------------------------------------------------------------------
1502 | Facility : libnform
1503 | Function : static int IFN_Next_Character(FORM * form)
1505 | Description : Move to the next character in the field. In a multi-line
1506 | field this wraps at the end of the line.
1508 | Return Values : E_OK - success
1509 | E_REQUEST_DENIED - at the rightmost position
1510 +--------------------------------------------------------------------------*/
1512 IFN_Next_Character(FORM
*form
)
1514 FIELD
*field
= form
->current
;
1515 int step
= myWCWIDTH(form
->w
, form
->currow
, form
->curcol
);
1517 T((T_CALLED("IFN_Next_Character(%p)"), (void *)form
));
1518 if ((form
->curcol
+= step
) == field
->dcols
)
1520 if ((++(form
->currow
)) == field
->drows
)
1522 #if GROW_IF_NAVIGATE
1523 if (!Single_Line_Field(field
) && Field_Grown(field
, 1))
1530 #if GROW_IF_NAVIGATE
1531 if (Single_Line_Field(field
) && Field_Grown(field
, 1))
1534 form
->curcol
-= step
;
1535 returnCode(E_REQUEST_DENIED
);
1542 /*---------------------------------------------------------------------------
1543 | Facility : libnform
1544 | Function : static int IFN_Previous_Character(FORM * form)
1546 | Description : Move to the previous character in the field. In a
1547 | multi-line field this wraps and the beginning of the
1550 | Return Values : E_OK - success
1551 | E_REQUEST_DENIED - at the leftmost position
1552 +--------------------------------------------------------------------------*/
1554 IFN_Previous_Character(FORM
*form
)
1556 int amount
= myWCWIDTH(form
->w
, form
->currow
, form
->curcol
- 1);
1557 int oldcol
= form
->curcol
;
1559 T((T_CALLED("IFN_Previous_Character(%p)"), (void *)form
));
1560 if ((form
->curcol
-= amount
) < 0)
1562 if ((--(form
->currow
)) < 0)
1565 form
->curcol
= oldcol
;
1566 returnCode(E_REQUEST_DENIED
);
1568 form
->curcol
= form
->current
->dcols
- 1;
1573 /*---------------------------------------------------------------------------
1574 | Facility : libnform
1575 | Function : static int IFN_Next_Line(FORM * form)
1577 | Description : Move to the beginning of the next line in the field
1579 | Return Values : E_OK - success
1580 | E_REQUEST_DENIED - at the last line
1581 +--------------------------------------------------------------------------*/
1583 IFN_Next_Line(FORM
*form
)
1585 FIELD
*field
= form
->current
;
1587 T((T_CALLED("IFN_Next_Line(%p)"), (void *)form
));
1588 if ((++(form
->currow
)) == field
->drows
)
1590 #if GROW_IF_NAVIGATE
1591 if (!Single_Line_Field(field
) && Field_Grown(field
, 1))
1595 returnCode(E_REQUEST_DENIED
);
1601 /*---------------------------------------------------------------------------
1602 | Facility : libnform
1603 | Function : static int IFN_Previous_Line(FORM * form)
1605 | Description : Move to the beginning of the previous line in the field
1607 | Return Values : E_OK - success
1608 | E_REQUEST_DENIED - at the first line
1609 +--------------------------------------------------------------------------*/
1611 IFN_Previous_Line(FORM
*form
)
1613 T((T_CALLED("IFN_Previous_Line(%p)"), (void *)form
));
1614 if ((--(form
->currow
)) < 0)
1617 returnCode(E_REQUEST_DENIED
);
1623 /*---------------------------------------------------------------------------
1624 | Facility : libnform
1625 | Function : static int IFN_Next_Word(FORM * form)
1627 | Description : Move to the beginning of the next word in the field.
1629 | Return Values : E_OK - success
1630 | E_REQUEST_DENIED - there is no next word
1631 +--------------------------------------------------------------------------*/
1633 IFN_Next_Word(FORM
*form
)
1635 FIELD
*field
= form
->current
;
1636 FIELD_CELL
*bp
= Address_Of_Current_Position_In_Buffer(form
);
1640 T((T_CALLED("IFN_Next_Word(%p)"), (void *)form
));
1642 /* We really need access to the data, so we have to synchronize */
1643 Synchronize_Buffer(form
);
1645 /* Go to the first whitespace after the current position (including
1646 current position). This is then the starting point to look for the
1647 next non-blank data */
1648 s
= Get_First_Whitespace_Character(bp
, Buffer_Length(field
) -
1649 (int)(bp
- field
->buf
));
1651 /* Find the start of the next word */
1652 t
= Get_Start_Of_Data(s
, Buffer_Length(field
) -
1653 (int)(s
- field
->buf
));
1654 #if !FRIENDLY_PREV_NEXT_WORD
1656 returnCode(E_REQUEST_DENIED
);
1660 Adjust_Cursor_Position(form
, t
);
1665 /*---------------------------------------------------------------------------
1666 | Facility : libnform
1667 | Function : static int IFN_Previous_Word(FORM * form)
1669 | Description : Move to the beginning of the previous word in the field.
1671 | Return Values : E_OK - success
1672 | E_REQUEST_DENIED - there is no previous word
1673 +--------------------------------------------------------------------------*/
1675 IFN_Previous_Word(FORM
*form
)
1677 FIELD
*field
= form
->current
;
1678 FIELD_CELL
*bp
= Address_Of_Current_Position_In_Buffer(form
);
1683 T((T_CALLED("IFN_Previous_Word(%p)"), (void *)form
));
1685 /* We really need access to the data, so we have to synchronize */
1686 Synchronize_Buffer(form
);
1688 s
= After_End_Of_Data(field
->buf
, (int)(bp
- field
->buf
));
1689 /* s points now right after the last non-blank in the buffer before bp.
1690 If bp was in a word, s equals bp. In this case we must find the last
1691 whitespace in the buffer before bp and repeat the game to really find
1692 the previous word! */
1696 /* And next call now goes backward to look for the last whitespace
1697 before that, pointing right after this, so it points to the begin
1698 of the previous word.
1700 t
= After_Last_Whitespace_Character(field
->buf
, (int)(s
- field
->buf
));
1701 #if !FRIENDLY_PREV_NEXT_WORD
1703 returnCode(E_REQUEST_DENIED
);
1707 /* and do it again, replacing bp by t */
1708 s
= After_End_Of_Data(field
->buf
, (int)(t
- field
->buf
));
1709 t
= After_Last_Whitespace_Character(field
->buf
, (int)(s
- field
->buf
));
1710 #if !FRIENDLY_PREV_NEXT_WORD
1712 returnCode(E_REQUEST_DENIED
);
1715 Adjust_Cursor_Position(form
, t
);
1719 /*---------------------------------------------------------------------------
1720 | Facility : libnform
1721 | Function : static int IFN_Beginning_Of_Field(FORM * form)
1723 | Description : Place the cursor at the first non-pad character in
1726 | Return Values : E_OK - success
1727 +--------------------------------------------------------------------------*/
1729 IFN_Beginning_Of_Field(FORM
*form
)
1731 FIELD
*field
= form
->current
;
1733 T((T_CALLED("IFN_Beginning_Of_Field(%p)"), (void *)form
));
1734 Synchronize_Buffer(form
);
1735 Adjust_Cursor_Position(form
,
1736 Get_Start_Of_Data(field
->buf
, Buffer_Length(field
)));
1740 /*---------------------------------------------------------------------------
1741 | Facility : libnform
1742 | Function : static int IFN_End_Of_Field(FORM * form)
1744 | Description : Place the cursor after the last non-pad character in
1745 | the field. If the field occupies the last position in
1746 | the buffer, the cursor is positioned on the last
1749 | Return Values : E_OK - success
1750 +--------------------------------------------------------------------------*/
1752 IFN_End_Of_Field(FORM
*form
)
1754 FIELD
*field
= form
->current
;
1757 T((T_CALLED("IFN_End_Of_Field(%p)"), (void *)form
));
1758 Synchronize_Buffer(form
);
1759 pos
= After_End_Of_Data(field
->buf
, Buffer_Length(field
));
1760 if (pos
== (field
->buf
+ Buffer_Length(field
)))
1762 Adjust_Cursor_Position(form
, pos
);
1766 /*---------------------------------------------------------------------------
1767 | Facility : libnform
1768 | Function : static int IFN_Beginning_Of_Line(FORM * form)
1770 | Description : Place the cursor on the first non-pad character in
1771 | the current line of the field.
1773 | Return Values : E_OK - success
1774 +--------------------------------------------------------------------------*/
1776 IFN_Beginning_Of_Line(FORM
*form
)
1778 FIELD
*field
= form
->current
;
1780 T((T_CALLED("IFN_Beginning_Of_Line(%p)"), (void *)form
));
1781 Synchronize_Buffer(form
);
1782 Adjust_Cursor_Position(form
,
1783 Get_Start_Of_Data(Address_Of_Current_Row_In_Buffer(form
),
1788 /*---------------------------------------------------------------------------
1789 | Facility : libnform
1790 | Function : static int IFN_End_Of_Line(FORM * form)
1792 | Description : Place the cursor after the last non-pad character in the
1793 | current line of the field. If the field occupies the
1794 | last column in the line, the cursor is positioned on the
1795 | last character of the line.
1797 | Return Values : E_OK - success
1798 +--------------------------------------------------------------------------*/
1800 IFN_End_Of_Line(FORM
*form
)
1802 FIELD
*field
= form
->current
;
1806 T((T_CALLED("IFN_End_Of_Line(%p)"), (void *)form
));
1807 Synchronize_Buffer(form
);
1808 bp
= Address_Of_Current_Row_In_Buffer(form
);
1809 pos
= After_End_Of_Data(bp
, field
->dcols
);
1810 if (pos
== (bp
+ field
->dcols
))
1812 Adjust_Cursor_Position(form
, pos
);
1816 /*---------------------------------------------------------------------------
1817 | Facility : libnform
1818 | Function : static int IFN_Left_Character(FORM * form)
1820 | Description : Move one character to the left in the current line.
1821 | This doesn't cycle.
1823 | Return Values : E_OK - success
1824 | E_REQUEST_DENIED - already in first column
1825 +--------------------------------------------------------------------------*/
1827 IFN_Left_Character(FORM
*form
)
1829 int amount
= myWCWIDTH(form
->w
, form
->currow
, form
->curcol
- 1);
1830 int oldcol
= form
->curcol
;
1832 T((T_CALLED("IFN_Left_Character(%p)"), (void *)form
));
1833 if ((form
->curcol
-= amount
) < 0)
1835 form
->curcol
= oldcol
;
1836 returnCode(E_REQUEST_DENIED
);
1841 /*---------------------------------------------------------------------------
1842 | Facility : libnform
1843 | Function : static int IFN_Right_Character(FORM * form)
1845 | Description : Move one character to the right in the current line.
1846 | This doesn't cycle.
1848 | Return Values : E_OK - success
1849 | E_REQUEST_DENIED - already in last column
1850 +--------------------------------------------------------------------------*/
1852 IFN_Right_Character(FORM
*form
)
1854 int amount
= myWCWIDTH(form
->w
, form
->currow
, form
->curcol
);
1855 int oldcol
= form
->curcol
;
1857 T((T_CALLED("IFN_Right_Character(%p)"), (void *)form
));
1858 if ((form
->curcol
+= amount
) >= form
->current
->dcols
)
1860 #if GROW_IF_NAVIGATE
1861 FIELD
*field
= form
->current
;
1863 if (Single_Line_Field(field
) && Field_Grown(field
, 1))
1866 form
->curcol
= oldcol
;
1867 returnCode(E_REQUEST_DENIED
);
1872 /*---------------------------------------------------------------------------
1873 | Facility : libnform
1874 | Function : static int IFN_Up_Character(FORM * form)
1876 | Description : Move one line up. This doesn't cycle through the lines
1879 | Return Values : E_OK - success
1880 | E_REQUEST_DENIED - already in last column
1881 +--------------------------------------------------------------------------*/
1883 IFN_Up_Character(FORM
*form
)
1885 T((T_CALLED("IFN_Up_Character(%p)"), (void *)form
));
1886 if ((--(form
->currow
)) < 0)
1889 returnCode(E_REQUEST_DENIED
);
1894 /*---------------------------------------------------------------------------
1895 | Facility : libnform
1896 | Function : static int IFN_Down_Character(FORM * form)
1898 | Description : Move one line down. This doesn't cycle through the
1899 | lines of the field.
1901 | Return Values : E_OK - success
1902 | E_REQUEST_DENIED - already in last column
1903 +--------------------------------------------------------------------------*/
1905 IFN_Down_Character(FORM
*form
)
1907 FIELD
*field
= form
->current
;
1909 T((T_CALLED("IFN_Down_Character(%p)"), (void *)form
));
1910 if ((++(form
->currow
)) == field
->drows
)
1912 #if GROW_IF_NAVIGATE
1913 if (!Single_Line_Field(field
) && Field_Grown(field
, 1))
1917 returnCode(E_REQUEST_DENIED
);
1921 /*----------------------------------------------------------------------------
1922 END of Intra-Field Navigation routines
1923 --------------------------------------------------------------------------*/
1925 /*----------------------------------------------------------------------------
1926 Vertical scrolling helper routines
1927 --------------------------------------------------------------------------*/
1929 /*---------------------------------------------------------------------------
1930 | Facility : libnform
1931 | Function : static int VSC_Generic(FORM *form, int nlines)
1933 | Description : Scroll multi-line field forward (nlines>0) or
1934 | backward (nlines<0) this many lines.
1936 | Return Values : E_OK - success
1937 | E_REQUEST_DENIED - can't scroll
1938 +--------------------------------------------------------------------------*/
1940 VSC_Generic(FORM
*form
, int nlines
)
1942 FIELD
*field
= form
->current
;
1943 int res
= E_REQUEST_DENIED
;
1944 int rows_to_go
= (nlines
> 0 ? nlines
: -nlines
);
1948 if ((rows_to_go
+ form
->toprow
) > (field
->drows
- field
->rows
))
1949 rows_to_go
= (field
->drows
- field
->rows
- form
->toprow
);
1953 form
->currow
+= rows_to_go
;
1954 form
->toprow
+= rows_to_go
;
1960 if (rows_to_go
> form
->toprow
)
1961 rows_to_go
= form
->toprow
;
1965 form
->currow
-= rows_to_go
;
1966 form
->toprow
-= rows_to_go
;
1972 /*----------------------------------------------------------------------------
1973 End of Vertical scrolling helper routines
1974 --------------------------------------------------------------------------*/
1976 /*----------------------------------------------------------------------------
1977 Vertical scrolling routines
1978 --------------------------------------------------------------------------*/
1980 /*---------------------------------------------------------------------------
1981 | Facility : libnform
1982 | Function : static int Vertical_Scrolling(
1983 | int (* const fct) (FORM *),
1986 | Description : Performs the generic vertical scrolling routines.
1987 | This has to check for a multi-line field and to set
1988 | the _NEWTOP flag if scrolling really occurred.
1990 | Return Values : Propagated error code from low-level driver calls
1991 +--------------------------------------------------------------------------*/
1993 Vertical_Scrolling(int (*const fct
) (FORM
*), FORM
*form
)
1995 int res
= E_REQUEST_DENIED
;
1997 if (!Single_Line_Field(form
->current
))
2001 form
->current
->status
|= _NEWTOP
;
2006 /*---------------------------------------------------------------------------
2007 | Facility : libnform
2008 | Function : static int VSC_Scroll_Line_Forward(FORM * form)
2010 | Description : Scroll multi-line field forward a line
2012 | Return Values : E_OK - success
2013 | E_REQUEST_DENIED - no data ahead
2014 +--------------------------------------------------------------------------*/
2016 VSC_Scroll_Line_Forward(FORM
*form
)
2018 T((T_CALLED("VSC_Scroll_Line_Forward(%p)"), (void *)form
));
2019 returnCode(VSC_Generic(form
, 1));
2022 /*---------------------------------------------------------------------------
2023 | Facility : libnform
2024 | Function : static int VSC_Scroll_Line_Backward(FORM * form)
2026 | Description : Scroll multi-line field backward a line
2028 | Return Values : E_OK - success
2029 | E_REQUEST_DENIED - no data behind
2030 +--------------------------------------------------------------------------*/
2032 VSC_Scroll_Line_Backward(FORM
*form
)
2034 T((T_CALLED("VSC_Scroll_Line_Backward(%p)"), (void *)form
));
2035 returnCode(VSC_Generic(form
, -1));
2038 /*---------------------------------------------------------------------------
2039 | Facility : libnform
2040 | Function : static int VSC_Scroll_Page_Forward(FORM * form)
2042 | Description : Scroll a multi-line field forward a page
2044 | Return Values : E_OK - success
2045 | E_REQUEST_DENIED - no data ahead
2046 +--------------------------------------------------------------------------*/
2048 VSC_Scroll_Page_Forward(FORM
*form
)
2050 T((T_CALLED("VSC_Scroll_Page_Forward(%p)"), (void *)form
));
2051 returnCode(VSC_Generic(form
, form
->current
->rows
));
2054 /*---------------------------------------------------------------------------
2055 | Facility : libnform
2056 | Function : static int VSC_Scroll_Half_Page_Forward(FORM * form)
2058 | Description : Scroll a multi-line field forward half a page
2060 | Return Values : E_OK - success
2061 | E_REQUEST_DENIED - no data ahead
2062 +--------------------------------------------------------------------------*/
2064 VSC_Scroll_Half_Page_Forward(FORM
*form
)
2066 T((T_CALLED("VSC_Scroll_Half_Page_Forward(%p)"), (void *)form
));
2067 returnCode(VSC_Generic(form
, (form
->current
->rows
+ 1) / 2));
2070 /*---------------------------------------------------------------------------
2071 | Facility : libnform
2072 | Function : static int VSC_Scroll_Page_Backward(FORM * form)
2074 | Description : Scroll a multi-line field backward a page
2076 | Return Values : E_OK - success
2077 | E_REQUEST_DENIED - no data behind
2078 +--------------------------------------------------------------------------*/
2080 VSC_Scroll_Page_Backward(FORM
*form
)
2082 T((T_CALLED("VSC_Scroll_Page_Backward(%p)"), (void *)form
));
2083 returnCode(VSC_Generic(form
, -(form
->current
->rows
)));
2086 /*---------------------------------------------------------------------------
2087 | Facility : libnform
2088 | Function : static int VSC_Scroll_Half_Page_Backward(FORM * form)
2090 | Description : Scroll a multi-line field backward half a page
2092 | Return Values : E_OK - success
2093 | E_REQUEST_DENIED - no data behind
2094 +--------------------------------------------------------------------------*/
2096 VSC_Scroll_Half_Page_Backward(FORM
*form
)
2098 T((T_CALLED("VSC_Scroll_Half_Page_Backward(%p)"), (void *)form
));
2099 returnCode(VSC_Generic(form
, -((form
->current
->rows
+ 1) / 2)));
2101 /*----------------------------------------------------------------------------
2102 End of Vertical scrolling routines
2103 --------------------------------------------------------------------------*/
2105 /*----------------------------------------------------------------------------
2106 Horizontal scrolling helper routines
2107 --------------------------------------------------------------------------*/
2109 /*---------------------------------------------------------------------------
2110 | Facility : libnform
2111 | Function : static int HSC_Generic(FORM *form, int ncolumns)
2113 | Description : Scroll single-line field forward (ncolumns>0) or
2114 | backward (ncolumns<0) this many columns.
2116 | Return Values : E_OK - success
2117 | E_REQUEST_DENIED - can't scroll
2118 +--------------------------------------------------------------------------*/
2120 HSC_Generic(FORM
*form
, int ncolumns
)
2122 FIELD
*field
= form
->current
;
2123 int res
= E_REQUEST_DENIED
;
2124 int cols_to_go
= (ncolumns
> 0 ? ncolumns
: -ncolumns
);
2128 if ((cols_to_go
+ form
->begincol
) > (field
->dcols
- field
->cols
))
2129 cols_to_go
= field
->dcols
- field
->cols
- form
->begincol
;
2133 form
->curcol
+= cols_to_go
;
2134 form
->begincol
+= cols_to_go
;
2140 if (cols_to_go
> form
->begincol
)
2141 cols_to_go
= form
->begincol
;
2145 form
->curcol
-= cols_to_go
;
2146 form
->begincol
-= cols_to_go
;
2152 /*----------------------------------------------------------------------------
2153 End of Horizontal scrolling helper routines
2154 --------------------------------------------------------------------------*/
2156 /*----------------------------------------------------------------------------
2157 Horizontal scrolling routines
2158 --------------------------------------------------------------------------*/
2160 /*---------------------------------------------------------------------------
2161 | Facility : libnform
2162 | Function : static int Horizontal_Scrolling(
2163 | int (* const fct) (FORM *),
2166 | Description : Performs the generic horizontal scrolling routines.
2167 | This has to check for a single-line field.
2169 | Return Values : Propagated error code from low-level driver calls
2170 +--------------------------------------------------------------------------*/
2172 Horizontal_Scrolling(int (*const fct
) (FORM
*), FORM
*form
)
2174 if (Single_Line_Field(form
->current
))
2177 return (E_REQUEST_DENIED
);
2180 /*---------------------------------------------------------------------------
2181 | Facility : libnform
2182 | Function : static int HSC_Scroll_Char_Forward(FORM * form)
2184 | Description : Scroll single-line field forward a character
2186 | Return Values : E_OK - success
2187 | E_REQUEST_DENIED - no data ahead
2188 +--------------------------------------------------------------------------*/
2190 HSC_Scroll_Char_Forward(FORM
*form
)
2192 T((T_CALLED("HSC_Scroll_Char_Forward(%p)"), (void *)form
));
2193 returnCode(HSC_Generic(form
, 1));
2196 /*---------------------------------------------------------------------------
2197 | Facility : libnform
2198 | Function : static int HSC_Scroll_Char_Backward(FORM * form)
2200 | Description : Scroll single-line field backward a character
2202 | Return Values : E_OK - success
2203 | E_REQUEST_DENIED - no data behind
2204 +--------------------------------------------------------------------------*/
2206 HSC_Scroll_Char_Backward(FORM
*form
)
2208 T((T_CALLED("HSC_Scroll_Char_Backward(%p)"), (void *)form
));
2209 returnCode(HSC_Generic(form
, -1));
2212 /*---------------------------------------------------------------------------
2213 | Facility : libnform
2214 | Function : static int HSC_Horizontal_Line_Forward(FORM* form)
2216 | Description : Scroll single-line field forward a line
2218 | Return Values : E_OK - success
2219 | E_REQUEST_DENIED - no data ahead
2220 +--------------------------------------------------------------------------*/
2222 HSC_Horizontal_Line_Forward(FORM
*form
)
2224 T((T_CALLED("HSC_Horizontal_Line_Forward(%p)"), (void *)form
));
2225 returnCode(HSC_Generic(form
, form
->current
->cols
));
2228 /*---------------------------------------------------------------------------
2229 | Facility : libnform
2230 | Function : static int HSC_Horizontal_Half_Line_Forward(FORM* form)
2232 | Description : Scroll single-line field forward half a line
2234 | Return Values : E_OK - success
2235 | E_REQUEST_DENIED - no data ahead
2236 +--------------------------------------------------------------------------*/
2238 HSC_Horizontal_Half_Line_Forward(FORM
*form
)
2240 T((T_CALLED("HSC_Horizontal_Half_Line_Forward(%p)"), (void *)form
));
2241 returnCode(HSC_Generic(form
, (form
->current
->cols
+ 1) / 2));
2244 /*---------------------------------------------------------------------------
2245 | Facility : libnform
2246 | Function : static int HSC_Horizontal_Line_Backward(FORM* form)
2248 | Description : Scroll single-line field backward a line
2250 | Return Values : E_OK - success
2251 | E_REQUEST_DENIED - no data behind
2252 +--------------------------------------------------------------------------*/
2254 HSC_Horizontal_Line_Backward(FORM
*form
)
2256 T((T_CALLED("HSC_Horizontal_Line_Backward(%p)"), (void *)form
));
2257 returnCode(HSC_Generic(form
, -(form
->current
->cols
)));
2260 /*---------------------------------------------------------------------------
2261 | Facility : libnform
2262 | Function : static int HSC_Horizontal_Half_Line_Backward(FORM* form)
2264 | Description : Scroll single-line field backward half a line
2266 | Return Values : E_OK - success
2267 | E_REQUEST_DENIED - no data behind
2268 +--------------------------------------------------------------------------*/
2270 HSC_Horizontal_Half_Line_Backward(FORM
*form
)
2272 T((T_CALLED("HSC_Horizontal_Half_Line_Backward(%p)"), (void *)form
));
2273 returnCode(HSC_Generic(form
, -((form
->current
->cols
+ 1) / 2)));
2276 /*----------------------------------------------------------------------------
2277 End of Horizontal scrolling routines
2278 --------------------------------------------------------------------------*/
2280 /*----------------------------------------------------------------------------
2281 Helper routines for Field Editing
2282 --------------------------------------------------------------------------*/
2284 /*---------------------------------------------------------------------------
2285 | Facility : libnform
2286 | Function : static bool Is_There_Room_For_A_Line(FORM * form)
2288 | Description : Check whether or not there is enough room in the
2289 | buffer to enter a whole line.
2291 | Return Values : TRUE - there is enough space
2292 | FALSE - there is not enough space
2293 +--------------------------------------------------------------------------*/
2294 NCURSES_INLINE
static bool
2295 Is_There_Room_For_A_Line(FORM
*form
)
2297 FIELD
*field
= form
->current
;
2298 FIELD_CELL
*begin_of_last_line
, *s
;
2300 Synchronize_Buffer(form
);
2301 begin_of_last_line
= Address_Of_Row_In_Buffer(field
, (field
->drows
- 1));
2302 s
= After_End_Of_Data(begin_of_last_line
, field
->dcols
);
2303 return ((s
== begin_of_last_line
) ? TRUE
: FALSE
);
2306 /*---------------------------------------------------------------------------
2307 | Facility : libnform
2308 | Function : static bool Is_There_Room_For_A_Char_In_Line(FORM * form)
2310 | Description : Checks whether or not there is room for a new character
2311 | in the current line.
2313 | Return Values : TRUE - there is room
2314 | FALSE - there is not enough room (line full)
2315 +--------------------------------------------------------------------------*/
2316 NCURSES_INLINE
static bool
2317 Is_There_Room_For_A_Char_In_Line(FORM
*form
)
2319 int last_char_in_line
;
2321 wmove(form
->w
, form
->currow
, form
->current
->dcols
- 1);
2322 last_char_in_line
= (int)(winch(form
->w
) & A_CHARTEXT
);
2323 wmove(form
->w
, form
->currow
, form
->curcol
);
2324 return (((last_char_in_line
== form
->current
->pad
) ||
2325 is_blank(last_char_in_line
)) ? TRUE
: FALSE
);
2328 #define There_Is_No_Room_For_A_Char_In_Line(f) \
2329 !Is_There_Room_For_A_Char_In_Line(f)
2331 /*---------------------------------------------------------------------------
2332 | Facility : libnform
2333 | Function : static int Insert_String(
2339 | Description : Insert the 'len' characters beginning at pointer 'txt'
2340 | into the 'row' of the 'form'. The insertion occurs
2341 | on the beginning of the row, all other characters are
2342 | moved to the right. After the text a pad character will
2343 | be inserted to separate the text from the rest. If
2344 | necessary the insertion moves characters on the next
2345 | line to make place for the requested insertion string.
2347 | Return Values : E_OK - success
2348 | E_REQUEST_DENIED -
2349 | E_SYSTEM_ERROR - system error
2350 +--------------------------------------------------------------------------*/
2352 Insert_String(FORM
*form
, int row
, FIELD_CELL
*txt
, int len
)
2354 FIELD
*field
= form
->current
;
2355 FIELD_CELL
*bp
= Address_Of_Row_In_Buffer(field
, row
);
2356 int datalen
= (int)(After_End_Of_Data(bp
, field
->dcols
) - bp
);
2357 int freelen
= field
->dcols
- datalen
;
2358 int requiredlen
= len
+ 1;
2360 int result
= E_REQUEST_DENIED
;
2362 if (freelen
>= requiredlen
)
2364 wmove(form
->w
, row
, 0);
2365 myINSNSTR(form
->w
, txt
, len
);
2366 wmove(form
->w
, row
, len
);
2367 myINSNSTR(form
->w
, &myBLANK
, 1);
2372 /* we have to move characters on the next line. If we are on the
2373 last line this may work, if the field is growable */
2374 if ((row
== (field
->drows
- 1)) && Growable(field
))
2376 if (!Field_Grown(field
, 1))
2377 return (E_SYSTEM_ERROR
);
2378 /* !!!Side-Effect : might be changed due to growth!!! */
2379 bp
= Address_Of_Row_In_Buffer(field
, row
);
2382 if (row
< (field
->drows
- 1))
2385 After_Last_Whitespace_Character(bp
,
2386 (int)(Get_Start_Of_Data(bp
2391 /* split points now to the first character of the portion of the
2392 line that must be moved to the next line */
2393 datalen
= (int)(split
- bp
); /* + freelen has to stay on this line */
2394 freelen
= field
->dcols
- (datalen
+ freelen
); /* for the next line */
2396 if ((result
= Insert_String(form
, row
+ 1, split
, freelen
)) == E_OK
)
2398 wmove(form
->w
, row
, datalen
);
2400 wmove(form
->w
, row
, 0);
2401 myINSNSTR(form
->w
, txt
, len
);
2402 wmove(form
->w
, row
, len
);
2403 myINSNSTR(form
->w
, &myBLANK
, 1);
2411 /*---------------------------------------------------------------------------
2412 | Facility : libnform
2413 | Function : static int Wrapping_Not_Necessary_Or_Wrapping_Ok(
2416 | Description : If a character has been entered into a field, it may
2417 | be that wrapping has to occur. This routine checks
2418 | whether or not wrapping is required and if so, performs
2421 | Return Values : E_OK - no wrapping required or wrapping
2423 | E_REQUEST_DENIED -
2424 | E_SYSTEM_ERROR - some system error
2425 +--------------------------------------------------------------------------*/
2427 Wrapping_Not_Necessary_Or_Wrapping_Ok(FORM
*form
)
2429 FIELD
*field
= form
->current
;
2430 int result
= E_REQUEST_DENIED
;
2431 bool Last_Row
= ((field
->drows
- 1) == form
->currow
);
2433 if ((field
->opts
& O_WRAP
) && /* wrapping wanted */
2434 (!Single_Line_Field(field
)) && /* must be multi-line */
2435 (There_Is_No_Room_For_A_Char_In_Line(form
)) && /* line is full */
2436 (!Last_Row
|| Growable(field
))) /* there are more lines */
2440 int chars_to_be_wrapped
;
2441 int chars_to_remain_on_line
;
2445 /* the above logic already ensures, that in this case the field
2447 if (!Field_Grown(field
, 1))
2448 return E_SYSTEM_ERROR
;
2450 bp
= Address_Of_Current_Row_In_Buffer(form
);
2451 Window_To_Buffer(form
, field
);
2452 split
= After_Last_Whitespace_Character(bp
, field
->dcols
);
2453 /* split points to the first character of the sequence to be brought
2455 chars_to_remain_on_line
= (int)(split
- bp
);
2456 chars_to_be_wrapped
= field
->dcols
- chars_to_remain_on_line
;
2457 if (chars_to_remain_on_line
> 0)
2459 if ((result
= Insert_String(form
, form
->currow
+ 1, split
,
2460 chars_to_be_wrapped
)) == E_OK
)
2462 wmove(form
->w
, form
->currow
, chars_to_remain_on_line
);
2464 if (form
->curcol
>= chars_to_remain_on_line
)
2467 form
->curcol
-= chars_to_remain_on_line
;
2477 Window_To_Buffer(form
, field
);
2478 result
= E_REQUEST_DENIED
;
2482 result
= E_OK
; /* wrapping was not necessary */
2486 /*----------------------------------------------------------------------------
2487 Field Editing routines
2488 --------------------------------------------------------------------------*/
2490 /*---------------------------------------------------------------------------
2491 | Facility : libnform
2492 | Function : static int Field_Editing(
2493 | int (* const fct) (FORM *),
2496 | Description : Generic routine for field editing requests. The driver
2497 | routines are only called for editable fields, the
2498 | _WINDOW_MODIFIED flag is set if editing occurred.
2499 | This is somewhat special due to the overload semantics
2500 | of the NEW_LINE and DEL_PREV requests.
2502 | Return Values : Error code from low level drivers.
2503 +--------------------------------------------------------------------------*/
2505 Field_Editing(int (*const fct
) (FORM
*), FORM
*form
)
2507 int res
= E_REQUEST_DENIED
;
2509 /* We have to deal here with the specific case of the overloaded
2510 behavior of New_Line and Delete_Previous requests.
2511 They may end up in navigational requests if we are on the first
2512 character in a field. But navigation is also allowed on non-
2515 if ((fct
== FE_Delete_Previous
) &&
2516 (form
->opts
& O_BS_OVERLOAD
) &&
2517 First_Position_In_Current_Field(form
))
2519 res
= Inter_Field_Navigation(FN_Previous_Field
, form
);
2523 if (fct
== FE_New_Line
)
2525 if ((form
->opts
& O_NL_OVERLOAD
) &&
2526 First_Position_In_Current_Field(form
))
2528 res
= Inter_Field_Navigation(FN_Next_Field
, form
);
2531 /* FE_New_Line deals itself with the _WINDOW_MODIFIED flag */
2536 /* From now on, everything must be editable */
2537 if (form
->current
->opts
& O_EDIT
)
2541 form
->status
|= _WINDOW_MODIFIED
;
2548 /*---------------------------------------------------------------------------
2549 | Facility : libnform
2550 | Function : static int FE_New_Line(FORM * form)
2552 | Description : Perform a new line request. This is rather complex
2553 | compared to other routines in this code due to the
2554 | rather difficult to understand description in the
2557 | Return Values : E_OK - success
2558 | E_REQUEST_DENIED - new line not allowed
2559 | E_SYSTEM_ERROR - system error
2560 +--------------------------------------------------------------------------*/
2562 FE_New_Line(FORM
*form
)
2564 FIELD
*field
= form
->current
;
2566 bool Last_Row
= ((field
->drows
- 1) == form
->currow
);
2568 T((T_CALLED("FE_New_Line(%p)"), (void *)form
));
2569 if (form
->status
& _OVLMODE
)
2572 (!(Growable(field
) && !Single_Line_Field(field
))))
2574 if (!(form
->opts
& O_NL_OVERLOAD
))
2575 returnCode(E_REQUEST_DENIED
);
2576 wmove(form
->w
, form
->currow
, form
->curcol
);
2578 /* we have to set this here, although it is also
2579 handled in the generic routine. The reason is,
2580 that FN_Next_Field may fail, but the form is
2581 definitively changed */
2582 form
->status
|= _WINDOW_MODIFIED
;
2583 returnCode(Inter_Field_Navigation(FN_Next_Field
, form
));
2587 if (Last_Row
&& !Field_Grown(field
, 1))
2589 /* N.B.: due to the logic in the 'if', LastRow == TRUE
2590 means here that the field is growable and not
2591 a single-line field */
2592 returnCode(E_SYSTEM_ERROR
);
2594 wmove(form
->w
, form
->currow
, form
->curcol
);
2598 form
->status
|= _WINDOW_MODIFIED
;
2606 !(Growable(field
) && !Single_Line_Field(field
)))
2608 if (!(form
->opts
& O_NL_OVERLOAD
))
2609 returnCode(E_REQUEST_DENIED
);
2610 returnCode(Inter_Field_Navigation(FN_Next_Field
, form
));
2614 bool May_Do_It
= !Last_Row
&& Is_There_Room_For_A_Line(form
);
2616 if (!(May_Do_It
|| Growable(field
)))
2617 returnCode(E_REQUEST_DENIED
);
2618 if (!May_Do_It
&& !Field_Grown(field
, 1))
2619 returnCode(E_SYSTEM_ERROR
);
2621 bp
= Address_Of_Current_Position_In_Buffer(form
);
2622 t
= After_End_Of_Data(bp
, field
->dcols
- form
->curcol
);
2623 wmove(form
->w
, form
->currow
, form
->curcol
);
2627 wmove(form
->w
, form
->currow
, form
->curcol
);
2629 myADDNSTR(form
->w
, bp
, (int)(t
- bp
));
2630 form
->status
|= _WINDOW_MODIFIED
;
2636 /*---------------------------------------------------------------------------
2637 | Facility : libnform
2638 | Function : static int FE_Insert_Character(FORM * form)
2640 | Description : Insert blank character at the cursor position
2642 | Return Values : E_OK
2644 +--------------------------------------------------------------------------*/
2646 FE_Insert_Character(FORM
*form
)
2648 FIELD
*field
= form
->current
;
2649 int result
= E_REQUEST_DENIED
;
2651 T((T_CALLED("FE_Insert_Character(%p)"), (void *)form
));
2652 if (Check_Char(form
, field
, field
->type
, (int)C_BLANK
,
2653 (TypeArgument
*)(field
->arg
)))
2655 bool There_Is_Room
= Is_There_Room_For_A_Char_In_Line(form
);
2657 if (There_Is_Room
||
2658 ((Single_Line_Field(field
) && Growable(field
))))
2660 if (!There_Is_Room
&& !Field_Grown(field
, 1))
2661 result
= E_SYSTEM_ERROR
;
2664 winsch(form
->w
, (chtype
)C_BLANK
);
2665 result
= Wrapping_Not_Necessary_Or_Wrapping_Ok(form
);
2672 /*---------------------------------------------------------------------------
2673 | Facility : libnform
2674 | Function : static int FE_Insert_Line(FORM * form)
2676 | Description : Insert a blank line at the cursor position
2678 | Return Values : E_OK - success
2679 | E_REQUEST_DENIED - line can not be inserted
2680 +--------------------------------------------------------------------------*/
2682 FE_Insert_Line(FORM
*form
)
2684 FIELD
*field
= form
->current
;
2685 int result
= E_REQUEST_DENIED
;
2687 T((T_CALLED("FE_Insert_Line(%p)"), (void *)form
));
2688 if (Check_Char(form
, field
,
2689 field
->type
, (int)C_BLANK
, (TypeArgument
*)(field
->arg
)))
2691 bool Maybe_Done
= (form
->currow
!= (field
->drows
- 1)) &&
2692 Is_There_Room_For_A_Line(form
);
2694 if (!Single_Line_Field(field
) &&
2695 (Maybe_Done
|| Growable(field
)))
2697 if (!Maybe_Done
&& !Field_Grown(field
, 1))
2698 result
= E_SYSTEM_ERROR
;
2710 /*---------------------------------------------------------------------------
2711 | Facility : libnform
2712 | Function : static int FE_Delete_Character(FORM * form)
2714 | Description : Delete character at the cursor position
2716 | Return Values : E_OK - success
2717 +--------------------------------------------------------------------------*/
2719 FE_Delete_Character(FORM
*form
)
2721 T((T_CALLED("FE_Delete_Character(%p)"), (void *)form
));
2726 /*---------------------------------------------------------------------------
2727 | Facility : libnform
2728 | Function : static int FE_Delete_Previous(FORM * form)
2730 | Description : Delete character before cursor. Again this is a rather
2731 | difficult piece compared to others due to the overloading
2732 | semantics of backspace.
2733 | N.B.: The case of overloaded BS on first field position
2734 | is already handled in the generic routine.
2736 | Return Values : E_OK - success
2737 | E_REQUEST_DENIED - Character can't be deleted
2738 +--------------------------------------------------------------------------*/
2740 FE_Delete_Previous(FORM
*form
)
2742 FIELD
*field
= form
->current
;
2744 T((T_CALLED("FE_Delete_Previous(%p)"), (void *)form
));
2745 if (First_Position_In_Current_Field(form
))
2746 returnCode(E_REQUEST_DENIED
);
2748 if ((--(form
->curcol
)) < 0)
2750 FIELD_CELL
*this_line
, *prev_line
, *prev_end
, *this_end
;
2751 int this_row
= form
->currow
;
2754 if (form
->status
& _OVLMODE
)
2755 returnCode(E_REQUEST_DENIED
);
2757 prev_line
= Address_Of_Row_In_Buffer(field
, (form
->currow
- 1));
2758 this_line
= Address_Of_Row_In_Buffer(field
, (form
->currow
));
2759 Synchronize_Buffer(form
);
2760 prev_end
= After_End_Of_Data(prev_line
, field
->dcols
);
2761 this_end
= After_End_Of_Data(this_line
, field
->dcols
);
2762 if ((int)(this_end
- this_line
) >
2763 (field
->cols
- (int)(prev_end
- prev_line
)))
2764 returnCode(E_REQUEST_DENIED
);
2765 wmove(form
->w
, form
->currow
, form
->curcol
);
2767 Adjust_Cursor_Position(form
, prev_end
);
2769 * If we did not really move to the previous line, help the user a
2770 * little. It is however a little inconsistent. Normally, when
2771 * backspacing around the point where text wraps to a new line in a
2772 * multi-line form, we absorb one keystroke for the wrapping point. That
2773 * is consistent with SVr4 forms. However, SVr4 does not allow typing
2774 * into the last column of the field, and requires the user to enter a
2775 * newline to move to the next line. Therefore it can consistently eat
2776 * that keystroke. Since ncurses allows the last column, it wraps
2777 * automatically (given the proper options). But we cannot eat the
2778 * keystroke to back over the wrapping point, since that would put the
2779 * cursor past the end of the form field. In this case, just delete the
2780 * character at the end of the field.
2782 if (form
->currow
== this_row
&& this_row
> 0)
2785 form
->curcol
= field
->dcols
- 1;
2790 wmove(form
->w
, form
->currow
, form
->curcol
);
2791 myADDNSTR(form
->w
, this_line
, (int)(this_end
- this_line
));
2801 /*---------------------------------------------------------------------------
2802 | Facility : libnform
2803 | Function : static int FE_Delete_Line(FORM * form)
2805 | Description : Delete line at cursor position.
2807 | Return Values : E_OK - success
2808 +--------------------------------------------------------------------------*/
2810 FE_Delete_Line(FORM
*form
)
2812 T((T_CALLED("FE_Delete_Line(%p)"), (void *)form
));
2818 /*---------------------------------------------------------------------------
2819 | Facility : libnform
2820 | Function : static int FE_Delete_Word(FORM * form)
2822 | Description : Delete word at cursor position
2824 | Return Values : E_OK - success
2825 | E_REQUEST_DENIED - failure
2826 +--------------------------------------------------------------------------*/
2828 FE_Delete_Word(FORM
*form
)
2830 FIELD
*field
= form
->current
;
2831 FIELD_CELL
*bp
= Address_Of_Current_Row_In_Buffer(form
);
2832 FIELD_CELL
*ep
= bp
+ field
->dcols
;
2833 FIELD_CELL
*cp
= bp
+ form
->curcol
;
2836 T((T_CALLED("FE_Delete_Word(%p)"), (void *)form
));
2837 Synchronize_Buffer(form
);
2839 returnCode(E_REQUEST_DENIED
); /* not in word */
2841 /* move cursor to begin of word and erase to end of screen-line */
2842 Adjust_Cursor_Position(form
,
2843 After_Last_Whitespace_Character(bp
, form
->curcol
));
2844 wmove(form
->w
, form
->currow
, form
->curcol
);
2847 /* skip over word in buffer */
2848 s
= Get_First_Whitespace_Character(cp
, (int)(ep
- cp
));
2849 /* to begin of next word */
2850 s
= Get_Start_Of_Data(s
, (int)(ep
- s
));
2851 if ((s
!= cp
) && !ISBLANK(*s
))
2853 /* copy remaining line to window */
2854 myADDNSTR(form
->w
, s
, (int)(s
- After_End_Of_Data(s
, (int)(ep
- s
))));
2859 /*---------------------------------------------------------------------------
2860 | Facility : libnform
2861 | Function : static int FE_Clear_To_End_Of_Line(FORM * form)
2863 | Description : Clear to end of current line.
2865 | Return Values : E_OK - success
2866 +--------------------------------------------------------------------------*/
2868 FE_Clear_To_End_Of_Line(FORM
*form
)
2870 T((T_CALLED("FE_Clear_To_End_Of_Line(%p)"), (void *)form
));
2871 wmove(form
->w
, form
->currow
, form
->curcol
);
2876 /*---------------------------------------------------------------------------
2877 | Facility : libnform
2878 | Function : static int FE_Clear_To_End_Of_Field(FORM * form)
2880 | Description : Clear to end of field.
2882 | Return Values : E_OK - success
2883 +--------------------------------------------------------------------------*/
2885 FE_Clear_To_End_Of_Field(FORM
*form
)
2887 T((T_CALLED("FE_Clear_To_End_Of_Field(%p)"), (void *)form
));
2888 wmove(form
->w
, form
->currow
, form
->curcol
);
2893 /*---------------------------------------------------------------------------
2894 | Facility : libnform
2895 | Function : static int FE_Clear_Field(FORM * form)
2897 | Description : Clear entire field.
2899 | Return Values : E_OK - success
2900 +--------------------------------------------------------------------------*/
2902 FE_Clear_Field(FORM
*form
)
2904 T((T_CALLED("FE_Clear_Field(%p)"), (void *)form
));
2905 form
->currow
= form
->curcol
= 0;
2909 /*----------------------------------------------------------------------------
2910 END of Field Editing routines
2911 --------------------------------------------------------------------------*/
2913 /*----------------------------------------------------------------------------
2915 --------------------------------------------------------------------------*/
2917 /*---------------------------------------------------------------------------
2918 | Facility : libnform
2919 | Function : static int EM_Overlay_Mode(FORM * form)
2921 | Description : Switch to overlay mode.
2923 | Return Values : E_OK - success
2924 +--------------------------------------------------------------------------*/
2926 EM_Overlay_Mode(FORM
*form
)
2928 T((T_CALLED("EM_Overlay_Mode(%p)"), (void *)form
));
2929 form
->status
|= _OVLMODE
;
2933 /*---------------------------------------------------------------------------
2934 | Facility : libnform
2935 | Function : static int EM_Insert_Mode(FORM * form)
2937 | Description : Switch to insert mode
2939 | Return Values : E_OK - success
2940 +--------------------------------------------------------------------------*/
2942 EM_Insert_Mode(FORM
*form
)
2944 T((T_CALLED("EM_Insert_Mode(%p)"), (void *)form
));
2945 form
->status
&= ~_OVLMODE
;
2949 /*----------------------------------------------------------------------------
2950 END of Edit Mode routines
2951 --------------------------------------------------------------------------*/
2953 /*----------------------------------------------------------------------------
2954 Helper routines for Choice Requests
2955 --------------------------------------------------------------------------*/
2957 /*---------------------------------------------------------------------------
2958 | Facility : libnform
2959 | Function : static bool Next_Choice(FORM * form,
2962 | TypeArgument *argp)
2964 | Description : Get the next field choice. For linked types this is
2967 | Return Values : TRUE - next choice successfully retrieved
2968 | FALSE - couldn't retrieve next choice
2969 +--------------------------------------------------------------------------*/
2971 Next_Choice(FORM
*form
, FIELDTYPE
*typ
, FIELD
*field
, TypeArgument
*argp
)
2973 if (!typ
|| !(typ
->status
& _HAS_CHOICE
))
2976 if (typ
->status
& _LINKED_TYPE
)
2980 Next_Choice(form
, typ
->left
, field
, argp
->left
) ||
2981 Next_Choice(form
, typ
->right
, field
, argp
->right
));
2985 #if NCURSES_INTEROP_FUNCS
2986 assert(typ
->enum_next
.onext
);
2987 if (typ
->status
& _GENERIC
)
2988 return typ
->enum_next
.gnext(form
, field
, (void *)argp
);
2990 return typ
->enum_next
.onext(field
, (void *)argp
);
2993 return typ
->next(field
, (void *)argp
);
2998 /*---------------------------------------------------------------------------
2999 | Facility : libnform
3000 | Function : static bool Previous_Choice(FORM * form,
3003 | TypeArgument *argp)
3005 | Description : Get the previous field choice. For linked types this
3006 | is done recursively.
3008 | Return Values : TRUE - previous choice successfully retrieved
3009 | FALSE - couldn't retrieve previous choice
3010 +--------------------------------------------------------------------------*/
3012 Previous_Choice(FORM
*form
, FIELDTYPE
*typ
, FIELD
*field
, TypeArgument
*argp
)
3014 if (!typ
|| !(typ
->status
& _HAS_CHOICE
))
3017 if (typ
->status
& _LINKED_TYPE
)
3021 Previous_Choice(form
, typ
->left
, field
, argp
->left
) ||
3022 Previous_Choice(form
, typ
->right
, field
, argp
->right
));
3026 #if NCURSES_INTEROP_FUNCS
3027 assert(typ
->enum_prev
.oprev
);
3028 if (typ
->status
& _GENERIC
)
3029 return typ
->enum_prev
.gprev(form
, field
, (void *)argp
);
3031 return typ
->enum_prev
.oprev(field
, (void *)argp
);
3034 return typ
->prev(field
, (void *)argp
);
3038 /*----------------------------------------------------------------------------
3039 End of Helper routines for Choice Requests
3040 --------------------------------------------------------------------------*/
3042 /*----------------------------------------------------------------------------
3043 Routines for Choice Requests
3044 --------------------------------------------------------------------------*/
3046 /*---------------------------------------------------------------------------
3047 | Facility : libnform
3048 | Function : static int CR_Next_Choice(FORM * form)
3050 | Description : Get the next field choice.
3052 | Return Values : E_OK - success
3053 | E_REQUEST_DENIED - next choice couldn't be retrieved
3054 +--------------------------------------------------------------------------*/
3056 CR_Next_Choice(FORM
*form
)
3058 FIELD
*field
= form
->current
;
3060 T((T_CALLED("CR_Next_Choice(%p)"), (void *)form
));
3061 Synchronize_Buffer(form
);
3062 returnCode((Next_Choice(form
, field
->type
, field
, (TypeArgument
*)(field
->arg
)))
3064 : E_REQUEST_DENIED
);
3067 /*---------------------------------------------------------------------------
3068 | Facility : libnform
3069 | Function : static int CR_Previous_Choice(FORM * form)
3071 | Description : Get the previous field choice.
3073 | Return Values : E_OK - success
3074 | E_REQUEST_DENIED - prev. choice couldn't be retrieved
3075 +--------------------------------------------------------------------------*/
3077 CR_Previous_Choice(FORM
*form
)
3079 FIELD
*field
= form
->current
;
3081 T((T_CALLED("CR_Previous_Choice(%p)"), (void *)form
));
3082 Synchronize_Buffer(form
);
3083 returnCode((Previous_Choice(form
, field
->type
, field
, (TypeArgument
*)(field
->arg
)))
3085 : E_REQUEST_DENIED
);
3087 /*----------------------------------------------------------------------------
3088 End of Routines for Choice Requests
3089 --------------------------------------------------------------------------*/
3091 /*----------------------------------------------------------------------------
3092 Helper routines for Field Validations.
3093 --------------------------------------------------------------------------*/
3095 /*---------------------------------------------------------------------------
3096 | Facility : libnform
3097 | Function : static bool Check_Field(FORM* form,
3100 | TypeArgument * argp)
3102 | Description : Check the field according to its fieldtype and its
3103 | actual arguments. For linked fieldtypes this is done
3106 | Return Values : TRUE - field is valid
3107 | FALSE - field is invalid.
3108 +--------------------------------------------------------------------------*/
3110 Check_Field(FORM
*form
, FIELDTYPE
*typ
, FIELD
*field
, TypeArgument
*argp
)
3114 if (field
->opts
& O_NULLOK
)
3116 FIELD_CELL
*bp
= field
->buf
;
3119 while (ISBLANK(*bp
))
3123 if (CharOf(*bp
) == 0)
3127 if (typ
->status
& _LINKED_TYPE
)
3131 Check_Field(form
, typ
->left
, field
, argp
->left
) ||
3132 Check_Field(form
, typ
->right
, field
, argp
->right
));
3136 #if NCURSES_INTEROP_FUNCS
3137 if (typ
->fieldcheck
.ofcheck
)
3139 if (typ
->status
& _GENERIC
)
3140 return typ
->fieldcheck
.gfcheck(form
, field
, (void *)argp
);
3142 return typ
->fieldcheck
.ofcheck(field
, (void *)argp
);
3146 return typ
->fcheck(field
, (void *)argp
);
3153 /*---------------------------------------------------------------------------
3154 | Facility : libnform
3155 | Function : bool _nc_Internal_Validation(FORM * form )
3157 | Description : Validate the current field of the form.
3159 | Return Values : TRUE - field is valid
3160 | FALSE - field is invalid
3161 +--------------------------------------------------------------------------*/
3162 NCURSES_EXPORT(bool)
3163 _nc_Internal_Validation(FORM
*form
)
3167 field
= form
->current
;
3169 Synchronize_Buffer(form
);
3170 if ((form
->status
& _FCHECK_REQUIRED
) ||
3171 (!(field
->opts
& O_PASSOK
)))
3173 if (!Check_Field(form
, field
->type
, field
, (TypeArgument
*)(field
->arg
)))
3175 form
->status
&= ~_FCHECK_REQUIRED
;
3176 field
->status
|= _CHANGED
;
3177 Synchronize_Linked_Fields(field
);
3181 /*----------------------------------------------------------------------------
3182 End of Helper routines for Field Validations.
3183 --------------------------------------------------------------------------*/
3185 /*----------------------------------------------------------------------------
3186 Routines for Field Validation.
3187 --------------------------------------------------------------------------*/
3189 /*---------------------------------------------------------------------------
3190 | Facility : libnform
3191 | Function : static int FV_Validation(FORM * form)
3193 | Description : Validate the current field of the form.
3195 | Return Values : E_OK - field valid
3196 | E_INVALID_FIELD - field not valid
3197 +--------------------------------------------------------------------------*/
3199 FV_Validation(FORM
*form
)
3201 T((T_CALLED("FV_Validation(%p)"), (void *)form
));
3202 if (_nc_Internal_Validation(form
))
3205 returnCode(E_INVALID_FIELD
);
3207 /*----------------------------------------------------------------------------
3208 End of routines for Field Validation.
3209 --------------------------------------------------------------------------*/
3211 /*----------------------------------------------------------------------------
3212 Helper routines for Inter-Field Navigation
3213 --------------------------------------------------------------------------*/
3215 /*---------------------------------------------------------------------------
3216 | Facility : libnform
3217 | Function : static FIELD *Next_Field_On_Page(FIELD * field)
3219 | Description : Get the next field after the given field on the current
3220 | page. The order of fields is the one defined by the
3221 | fields array. Only visible and active fields are
3224 | Return Values : Pointer to the next field.
3225 +--------------------------------------------------------------------------*/
3226 NCURSES_INLINE
static FIELD
*
3227 Next_Field_On_Page(FIELD
*field
)
3229 FORM
*form
= field
->form
;
3230 FIELD
**field_on_page
= &form
->field
[field
->index
];
3231 FIELD
**first_on_page
= &form
->field
[form
->page
[form
->curpage
].pmin
];
3232 FIELD
**last_on_page
= &form
->field
[form
->page
[form
->curpage
].pmax
];
3237 (field_on_page
== last_on_page
) ? first_on_page
: field_on_page
+ 1;
3238 if (Field_Is_Selectable(*field_on_page
))
3241 while (field
!= (*field_on_page
));
3242 return (*field_on_page
);
3245 /*---------------------------------------------------------------------------
3246 | Facility : libnform
3247 | Function : FIELD* _nc_First_Active_Field(FORM * form)
3249 | Description : Get the first active field on the current page,
3250 | if there are such. If there are none, get the first
3251 | visible field on the page. If there are also none,
3252 | we return the first field on page and hope the best.
3254 | Return Values : Pointer to calculated field.
3255 +--------------------------------------------------------------------------*/
3256 NCURSES_EXPORT(FIELD
*)
3257 _nc_First_Active_Field(FORM
*form
)
3259 FIELD
**last_on_page
= &form
->field
[form
->page
[form
->curpage
].pmax
];
3260 FIELD
*proposed
= Next_Field_On_Page(*last_on_page
);
3262 if (proposed
== *last_on_page
)
3264 /* there might be the special situation, where there is no
3265 active and visible field on the current page. We then select
3266 the first visible field on this readonly page
3268 if (Field_Is_Not_Selectable(proposed
))
3270 FIELD
**field
= &form
->field
[proposed
->index
];
3271 FIELD
**first
= &form
->field
[form
->page
[form
->curpage
].pmin
];
3275 field
= (field
== last_on_page
) ? first
: field
+ 1;
3276 if (((*field
)->opts
& O_VISIBLE
))
3279 while (proposed
!= (*field
));
3283 if ((proposed
== *last_on_page
) && !(proposed
->opts
& O_VISIBLE
))
3285 /* This means, there is also no visible field on the page.
3286 So we propose the first one and hope the very best...
3287 Some very clever user has designed a readonly and invisible
3297 /*---------------------------------------------------------------------------
3298 | Facility : libnform
3299 | Function : static FIELD *Previous_Field_On_Page(FIELD * field)
3301 | Description : Get the previous field before the given field on the
3302 | current page. The order of fields is the one defined by
3303 | the fields array. Only visible and active fields are
3306 | Return Values : Pointer to the previous field.
3307 +--------------------------------------------------------------------------*/
3308 NCURSES_INLINE
static FIELD
*
3309 Previous_Field_On_Page(FIELD
*field
)
3311 FORM
*form
= field
->form
;
3312 FIELD
**field_on_page
= &form
->field
[field
->index
];
3313 FIELD
**first_on_page
= &form
->field
[form
->page
[form
->curpage
].pmin
];
3314 FIELD
**last_on_page
= &form
->field
[form
->page
[form
->curpage
].pmax
];
3319 (field_on_page
== first_on_page
) ? last_on_page
: field_on_page
- 1;
3320 if (Field_Is_Selectable(*field_on_page
))
3323 while (field
!= (*field_on_page
));
3325 return (*field_on_page
);
3328 /*---------------------------------------------------------------------------
3329 | Facility : libnform
3330 | Function : static FIELD *Sorted_Next_Field(FIELD * field)
3332 | Description : Get the next field after the given field on the current
3333 | page. The order of fields is the one defined by the
3334 | (row,column) geometry, rows are major.
3336 | Return Values : Pointer to the next field.
3337 +--------------------------------------------------------------------------*/
3338 NCURSES_INLINE
static FIELD
*
3339 Sorted_Next_Field(FIELD
*field
)
3341 FIELD
*field_on_page
= field
;
3345 field_on_page
= field_on_page
->snext
;
3346 if (Field_Is_Selectable(field_on_page
))
3349 while (field_on_page
!= field
);
3351 return (field_on_page
);
3354 /*---------------------------------------------------------------------------
3355 | Facility : libnform
3356 | Function : static FIELD *Sorted_Previous_Field(FIELD * field)
3358 | Description : Get the previous field before the given field on the
3359 | current page. The order of fields is the one defined
3360 | by the (row,column) geometry, rows are major.
3362 | Return Values : Pointer to the previous field.
3363 +--------------------------------------------------------------------------*/
3364 NCURSES_INLINE
static FIELD
*
3365 Sorted_Previous_Field(FIELD
*field
)
3367 FIELD
*field_on_page
= field
;
3371 field_on_page
= field_on_page
->sprev
;
3372 if (Field_Is_Selectable(field_on_page
))
3375 while (field_on_page
!= field
);
3377 return (field_on_page
);
3380 /*---------------------------------------------------------------------------
3381 | Facility : libnform
3382 | Function : static FIELD *Left_Neighbor_Field(FIELD * field)
3384 | Description : Get the left neighbor of the field on the same line
3385 | and the same page. Cycles through the line.
3387 | Return Values : Pointer to left neighbor field.
3388 +--------------------------------------------------------------------------*/
3389 NCURSES_INLINE
static FIELD
*
3390 Left_Neighbor_Field(FIELD
*field
)
3392 FIELD
*field_on_page
= field
;
3394 /* For a field that has really a left neighbor, the while clause
3395 immediately fails and the loop is left, positioned at the right
3396 neighbor. Otherwise we cycle backwards through the sorted field list
3397 until we enter the same line (from the right end).
3401 field_on_page
= Sorted_Previous_Field(field_on_page
);
3403 while (field_on_page
->frow
!= field
->frow
);
3405 return (field_on_page
);
3408 /*---------------------------------------------------------------------------
3409 | Facility : libnform
3410 | Function : static FIELD *Right_Neighbor_Field(FIELD * field)
3412 | Description : Get the right neighbor of the field on the same line
3413 | and the same page.
3415 | Return Values : Pointer to right neighbor field.
3416 +--------------------------------------------------------------------------*/
3417 NCURSES_INLINE
static FIELD
*
3418 Right_Neighbor_Field(FIELD
*field
)
3420 FIELD
*field_on_page
= field
;
3422 /* See the comments on Left_Neighbor_Field to understand how it works */
3425 field_on_page
= Sorted_Next_Field(field_on_page
);
3427 while (field_on_page
->frow
!= field
->frow
);
3429 return (field_on_page
);
3432 /*---------------------------------------------------------------------------
3433 | Facility : libnform
3434 | Function : static FIELD *Upper_Neighbor_Field(FIELD * field)
3436 | Description : Because of the row-major nature of sorting the fields,
3437 | it is more difficult to define whats the upper neighbor
3438 | field really means. We define that it must be on a
3439 | 'previous' line (cyclic order!) and is the rightmost
3440 | field laying on the left side of the given field. If
3441 | this set is empty, we take the first field on the line.
3443 | Return Values : Pointer to the upper neighbor field.
3444 +--------------------------------------------------------------------------*/
3446 Upper_Neighbor_Field(FIELD
*field
)
3448 FIELD
*field_on_page
= field
;
3449 int frow
= field
->frow
;
3450 int fcol
= field
->fcol
;
3452 /* Walk back to the 'previous' line. The second term in the while clause
3453 just guarantees that we stop if we cycled through the line because
3454 there might be no 'previous' line if the page has just one line.
3458 field_on_page
= Sorted_Previous_Field(field_on_page
);
3460 while (field_on_page
->frow
== frow
&& field_on_page
->fcol
!= fcol
);
3462 if (field_on_page
->frow
!= frow
)
3464 /* We really found a 'previous' line. We are positioned at the
3465 rightmost field on this line */
3466 frow
= field_on_page
->frow
;
3468 /* We walk to the left as long as we are really right of the
3470 while (field_on_page
->frow
== frow
&& field_on_page
->fcol
> fcol
)
3471 field_on_page
= Sorted_Previous_Field(field_on_page
);
3473 /* If we wrapped, just go to the right which is the first field on
3475 if (field_on_page
->frow
!= frow
)
3476 field_on_page
= Sorted_Next_Field(field_on_page
);
3479 return (field_on_page
);
3482 /*---------------------------------------------------------------------------
3483 | Facility : libnform
3484 | Function : static FIELD *Down_Neighbor_Field(FIELD * field)
3486 | Description : Because of the row-major nature of sorting the fields,
3487 | its more difficult to define whats the down neighbor
3488 | field really means. We define that it must be on a
3489 | 'next' line (cyclic order!) and is the leftmost
3490 | field laying on the right side of the given field. If
3491 | this set is empty, we take the last field on the line.
3493 | Return Values : Pointer to the upper neighbor field.
3494 +--------------------------------------------------------------------------*/
3496 Down_Neighbor_Field(FIELD
*field
)
3498 FIELD
*field_on_page
= field
;
3499 int frow
= field
->frow
;
3500 int fcol
= field
->fcol
;
3502 /* Walk forward to the 'next' line. The second term in the while clause
3503 just guarantees that we stop if we cycled through the line because
3504 there might be no 'next' line if the page has just one line.
3508 field_on_page
= Sorted_Next_Field(field_on_page
);
3510 while (field_on_page
->frow
== frow
&& field_on_page
->fcol
!= fcol
);
3512 if (field_on_page
->frow
!= frow
)
3514 /* We really found a 'next' line. We are positioned at the rightmost
3515 field on this line */
3516 frow
= field_on_page
->frow
;
3518 /* We walk to the right as long as we are really left of the
3520 while (field_on_page
->frow
== frow
&& field_on_page
->fcol
< fcol
)
3521 field_on_page
= Sorted_Next_Field(field_on_page
);
3523 /* If we wrapped, just go to the left which is the last field on
3525 if (field_on_page
->frow
!= frow
)
3526 field_on_page
= Sorted_Previous_Field(field_on_page
);
3529 return (field_on_page
);
3532 /*----------------------------------------------------------------------------
3533 Inter-Field Navigation routines
3534 --------------------------------------------------------------------------*/
3536 /*---------------------------------------------------------------------------
3537 | Facility : libnform
3538 | Function : static int Inter_Field_Navigation(
3539 | int (* const fct) (FORM *),
3542 | Description : Generic behavior for changing the current field, the
3543 | field is left and a new field is entered. So the field
3544 | must be validated and the field init/term hooks must
3547 | Return Values : E_OK - success
3548 | E_INVALID_FIELD - field is invalid
3549 | some other - error from subordinate call
3550 +--------------------------------------------------------------------------*/
3552 Inter_Field_Navigation(int (*const fct
) (FORM
*), FORM
*form
)
3556 if (!_nc_Internal_Validation(form
))
3557 res
= E_INVALID_FIELD
;
3560 Call_Hook(form
, fieldterm
);
3562 Call_Hook(form
, fieldinit
);
3567 /*---------------------------------------------------------------------------
3568 | Facility : libnform
3569 | Function : static int FN_Next_Field(FORM * form)
3571 | Description : Move to the next field on the current page of the form
3573 | Return Values : E_OK - success
3574 | != E_OK - error from subordinate call
3575 +--------------------------------------------------------------------------*/
3577 FN_Next_Field(FORM
*form
)
3579 T((T_CALLED("FN_Next_Field(%p)"), (void *)form
));
3580 returnCode(_nc_Set_Current_Field(form
,
3581 Next_Field_On_Page(form
->current
)));
3584 /*---------------------------------------------------------------------------
3585 | Facility : libnform
3586 | Function : static int FN_Previous_Field(FORM * form)
3588 | Description : Move to the previous field on the current page of the
3591 | Return Values : E_OK - success
3592 | != E_OK - error from subordinate call
3593 +--------------------------------------------------------------------------*/
3595 FN_Previous_Field(FORM
*form
)
3597 T((T_CALLED("FN_Previous_Field(%p)"), (void *)form
));
3598 returnCode(_nc_Set_Current_Field(form
,
3599 Previous_Field_On_Page(form
->current
)));
3602 /*---------------------------------------------------------------------------
3603 | Facility : libnform
3604 | Function : static int FN_First_Field(FORM * form)
3606 | Description : Move to the first field on the current page of the form
3608 | Return Values : E_OK - success
3609 | != E_OK - error from subordinate call
3610 +--------------------------------------------------------------------------*/
3612 FN_First_Field(FORM
*form
)
3614 T((T_CALLED("FN_First_Field(%p)"), (void *)form
));
3615 returnCode(_nc_Set_Current_Field(form
,
3616 Next_Field_On_Page(form
->field
[form
->page
[form
->curpage
].pmax
])));
3619 /*---------------------------------------------------------------------------
3620 | Facility : libnform
3621 | Function : static int FN_Last_Field(FORM * form)
3623 | Description : Move to the last field on the current page of the form
3625 | Return Values : E_OK - success
3626 | != E_OK - error from subordinate call
3627 +--------------------------------------------------------------------------*/
3629 FN_Last_Field(FORM
*form
)
3631 T((T_CALLED("FN_Last_Field(%p)"), (void *)form
));
3633 _nc_Set_Current_Field(form
,
3634 Previous_Field_On_Page(form
->field
[form
->page
[form
->curpage
].pmin
])));
3637 /*---------------------------------------------------------------------------
3638 | Facility : libnform
3639 | Function : static int FN_Sorted_Next_Field(FORM * form)
3641 | Description : Move to the sorted next field on the current page
3644 | Return Values : E_OK - success
3645 | != E_OK - error from subordinate call
3646 +--------------------------------------------------------------------------*/
3648 FN_Sorted_Next_Field(FORM
*form
)
3650 T((T_CALLED("FN_Sorted_Next_Field(%p)"), (void *)form
));
3651 returnCode(_nc_Set_Current_Field(form
,
3652 Sorted_Next_Field(form
->current
)));
3655 /*---------------------------------------------------------------------------
3656 | Facility : libnform
3657 | Function : static int FN_Sorted_Previous_Field(FORM * form)
3659 | Description : Move to the sorted previous field on the current page
3662 | Return Values : E_OK - success
3663 | != E_OK - error from subordinate call
3664 +--------------------------------------------------------------------------*/
3666 FN_Sorted_Previous_Field(FORM
*form
)
3668 T((T_CALLED("FN_Sorted_Previous_Field(%p)"), (void *)form
));
3669 returnCode(_nc_Set_Current_Field(form
,
3670 Sorted_Previous_Field(form
->current
)));
3673 /*---------------------------------------------------------------------------
3674 | Facility : libnform
3675 | Function : static int FN_Sorted_First_Field(FORM * form)
3677 | Description : Move to the sorted first field on the current page
3680 | Return Values : E_OK - success
3681 | != E_OK - error from subordinate call
3682 +--------------------------------------------------------------------------*/
3684 FN_Sorted_First_Field(FORM
*form
)
3686 T((T_CALLED("FN_Sorted_First_Field(%p)"), (void *)form
));
3687 returnCode(_nc_Set_Current_Field(form
,
3688 Sorted_Next_Field(form
->field
[form
->page
[form
->curpage
].smax
])));
3691 /*---------------------------------------------------------------------------
3692 | Facility : libnform
3693 | Function : static int FN_Sorted_Last_Field(FORM * form)
3695 | Description : Move to the sorted last field on the current page
3698 | Return Values : E_OK - success
3699 | != E_OK - error from subordinate call
3700 +--------------------------------------------------------------------------*/
3702 FN_Sorted_Last_Field(FORM
*form
)
3704 T((T_CALLED("FN_Sorted_Last_Field(%p)"), (void *)form
));
3705 returnCode(_nc_Set_Current_Field(form
,
3706 Sorted_Previous_Field(form
->field
[form
->page
[form
->curpage
].smin
])));
3709 /*---------------------------------------------------------------------------
3710 | Facility : libnform
3711 | Function : static int FN_Left_Field(FORM * form)
3713 | Description : Get the field on the left of the current field on the
3714 | same line and the same page. Cycles through the line.
3716 | Return Values : E_OK - success
3717 | != E_OK - error from subordinate call
3718 +--------------------------------------------------------------------------*/
3720 FN_Left_Field(FORM
*form
)
3722 T((T_CALLED("FN_Left_Field(%p)"), (void *)form
));
3723 returnCode(_nc_Set_Current_Field(form
,
3724 Left_Neighbor_Field(form
->current
)));
3727 /*---------------------------------------------------------------------------
3728 | Facility : libnform
3729 | Function : static int FN_Right_Field(FORM * form)
3731 | Description : Get the field on the right of the current field on the
3732 | same line and the same page. Cycles through the line.
3734 | Return Values : E_OK - success
3735 | != E_OK - error from subordinate call
3736 +--------------------------------------------------------------------------*/
3738 FN_Right_Field(FORM
*form
)
3740 T((T_CALLED("FN_Right_Field(%p)"), (void *)form
));
3741 returnCode(_nc_Set_Current_Field(form
,
3742 Right_Neighbor_Field(form
->current
)));
3745 /*---------------------------------------------------------------------------
3746 | Facility : libnform
3747 | Function : static int FN_Up_Field(FORM * form)
3749 | Description : Get the upper neighbor of the current field. This
3750 | cycles through the page. See the comments of the
3751 | Upper_Neighbor_Field function to understand how
3752 | 'upper' is defined.
3754 | Return Values : E_OK - success
3755 | != E_OK - error from subordinate call
3756 +--------------------------------------------------------------------------*/
3758 FN_Up_Field(FORM
*form
)
3760 T((T_CALLED("FN_Up_Field(%p)"), (void *)form
));
3761 returnCode(_nc_Set_Current_Field(form
,
3762 Upper_Neighbor_Field(form
->current
)));
3765 /*---------------------------------------------------------------------------
3766 | Facility : libnform
3767 | Function : static int FN_Down_Field(FORM * form)
3769 | Description : Get the down neighbor of the current field. This
3770 | cycles through the page. See the comments of the
3771 | Down_Neighbor_Field function to understand how
3772 | 'down' is defined.
3774 | Return Values : E_OK - success
3775 | != E_OK - error from subordinate call
3776 +--------------------------------------------------------------------------*/
3778 FN_Down_Field(FORM
*form
)
3780 T((T_CALLED("FN_Down_Field(%p)"), (void *)form
));
3781 returnCode(_nc_Set_Current_Field(form
,
3782 Down_Neighbor_Field(form
->current
)));
3784 /*----------------------------------------------------------------------------
3785 END of Field Navigation routines
3786 --------------------------------------------------------------------------*/
3788 /*----------------------------------------------------------------------------
3789 Helper routines for Page Navigation
3790 --------------------------------------------------------------------------*/
3792 /*---------------------------------------------------------------------------
3793 | Facility : libnform
3794 | Function : int _nc_Set_Form_Page(FORM * form,
3798 | Description : Make the given page number the current page and make
3799 | the given field the current field on the page. If
3800 | for the field NULL is given, make the first field on
3801 | the page the current field. The routine acts only
3802 | if the requested page is not the current page.
3804 | Return Values : E_OK - success
3805 | != E_OK - error from subordinate call
3806 | E_BAD_ARGUMENT - invalid field pointer
3807 | E_SYSTEM_ERROR - some severe basic error
3808 +--------------------------------------------------------------------------*/
3810 _nc_Set_Form_Page(FORM
*form
, int page
, FIELD
*field
)
3814 if ((form
->curpage
!= page
))
3816 FIELD
*last_field
, *field_on_page
;
3818 werase(Get_Form_Window(form
));
3819 form
->curpage
= page
;
3820 last_field
= field_on_page
= form
->field
[form
->page
[page
].smin
];
3823 if (field_on_page
->opts
& O_VISIBLE
)
3824 if ((res
= Display_Field(field_on_page
)) != E_OK
)
3826 field_on_page
= field_on_page
->snext
;
3828 while (field_on_page
!= last_field
);
3831 res
= _nc_Set_Current_Field(form
, field
);
3833 /* N.B.: we don't encapsulate this by Inter_Field_Navigation(),
3834 because this is already executed in a page navigation
3835 context that contains field navigation
3837 res
= FN_First_Field(form
);
3842 /*---------------------------------------------------------------------------
3843 | Facility : libnform
3844 | Function : static int Next_Page_Number(const FORM * form)
3846 | Description : Calculate the page number following the current page
3847 | number. This cycles if the highest page number is
3850 | Return Values : The next page number
3851 +--------------------------------------------------------------------------*/
3852 NCURSES_INLINE
static int
3853 Next_Page_Number(const FORM
*form
)
3855 return (form
->curpage
+ 1) % form
->maxpage
;
3858 /*---------------------------------------------------------------------------
3859 | Facility : libnform
3860 | Function : static int Previous_Page_Number(const FORM * form)
3862 | Description : Calculate the page number before the current page
3863 | number. This cycles if the first page number is
3866 | Return Values : The previous page number
3867 +--------------------------------------------------------------------------*/
3868 NCURSES_INLINE
static int
3869 Previous_Page_Number(const FORM
*form
)
3871 return (form
->curpage
!= 0 ? form
->curpage
- 1 : form
->maxpage
- 1);
3874 /*----------------------------------------------------------------------------
3875 Page Navigation routines
3876 --------------------------------------------------------------------------*/
3878 /*---------------------------------------------------------------------------
3879 | Facility : libnform
3880 | Function : static int Page_Navigation(
3881 | int (* const fct) (FORM *),
3884 | Description : Generic behavior for changing a page. This means
3885 | that the field is left and a new field is entered.
3886 | So the field must be validated and the field init/term
3887 | hooks must be called. Because also the page is changed,
3888 | the forms init/term hooks must be called also.
3890 | Return Values : E_OK - success
3891 | E_INVALID_FIELD - field is invalid
3892 | some other - error from subordinate call
3893 +--------------------------------------------------------------------------*/
3895 Page_Navigation(int (*const fct
) (FORM
*), FORM
*form
)
3899 if (!_nc_Internal_Validation(form
))
3900 res
= E_INVALID_FIELD
;
3903 Call_Hook(form
, fieldterm
);
3904 Call_Hook(form
, formterm
);
3906 Call_Hook(form
, forminit
);
3907 Call_Hook(form
, fieldinit
);
3912 /*---------------------------------------------------------------------------
3913 | Facility : libnform
3914 | Function : static int PN_Next_Page(FORM * form)
3916 | Description : Move to the next page of the form
3918 | Return Values : E_OK - success
3919 | != E_OK - error from subordinate call
3920 +--------------------------------------------------------------------------*/
3922 PN_Next_Page(FORM
*form
)
3924 T((T_CALLED("PN_Next_Page(%p)"), (void *)form
));
3925 returnCode(_nc_Set_Form_Page(form
, Next_Page_Number(form
), (FIELD
*)0));
3928 /*---------------------------------------------------------------------------
3929 | Facility : libnform
3930 | Function : static int PN_Previous_Page(FORM * form)
3932 | Description : Move to the previous page of the form
3934 | Return Values : E_OK - success
3935 | != E_OK - error from subordinate call
3936 +--------------------------------------------------------------------------*/
3938 PN_Previous_Page(FORM
*form
)
3940 T((T_CALLED("PN_Previous_Page(%p)"), (void *)form
));
3941 returnCode(_nc_Set_Form_Page(form
, Previous_Page_Number(form
), (FIELD
*)0));
3944 /*---------------------------------------------------------------------------
3945 | Facility : libnform
3946 | Function : static int PN_First_Page(FORM * form)
3948 | Description : Move to the first page of the form
3950 | Return Values : E_OK - success
3951 | != E_OK - error from subordinate call
3952 +--------------------------------------------------------------------------*/
3954 PN_First_Page(FORM
*form
)
3956 T((T_CALLED("PN_First_Page(%p)"), (void *)form
));
3957 returnCode(_nc_Set_Form_Page(form
, 0, (FIELD
*)0));
3960 /*---------------------------------------------------------------------------
3961 | Facility : libnform
3962 | Function : static int PN_Last_Page(FORM * form)
3964 | Description : Move to the last page of the form
3966 | Return Values : E_OK - success
3967 | != E_OK - error from subordinate call
3968 +--------------------------------------------------------------------------*/
3970 PN_Last_Page(FORM
*form
)
3972 T((T_CALLED("PN_Last_Page(%p)"), (void *)form
));
3973 returnCode(_nc_Set_Form_Page(form
, form
->maxpage
- 1, (FIELD
*)0));
3976 /*----------------------------------------------------------------------------
3977 END of Field Navigation routines
3978 --------------------------------------------------------------------------*/
3980 /*----------------------------------------------------------------------------
3981 Helper routines for the core form driver.
3982 --------------------------------------------------------------------------*/
3984 /*---------------------------------------------------------------------------
3985 | Facility : libnform
3986 | Function : static int Data_Entry(FORM * form,int c)
3988 | Description : Enter character c into at the current position of the
3989 | current field of the form.
3991 | Return Values : E_OK - success
3992 | E_REQUEST_DENIED - driver could not process the request
3994 +--------------------------------------------------------------------------*/
3996 Data_Entry(FORM
*form
, int c
)
3998 FIELD
*field
= form
->current
;
3999 int result
= E_REQUEST_DENIED
;
4001 T((T_CALLED("Data_Entry(%p,%s)"), (void *)form
, _tracechtype((chtype
)c
)));
4002 if ((field
->opts
& O_EDIT
)
4003 #if FIX_FORM_INACTIVE_BUG
4004 && (field
->opts
& O_ACTIVE
)
4008 if ((field
->opts
& O_BLANK
) &&
4009 First_Position_In_Current_Field(form
) &&
4010 !(form
->status
& _FCHECK_REQUIRED
) &&
4011 !(form
->status
& _WINDOW_MODIFIED
))
4014 if (form
->status
& _OVLMODE
)
4016 waddch(form
->w
, (chtype
)c
);
4021 bool There_Is_Room
= Is_There_Room_For_A_Char_In_Line(form
);
4023 if (!(There_Is_Room
||
4024 ((Single_Line_Field(field
) && Growable(field
)))))
4025 RETURN(E_REQUEST_DENIED
);
4027 if (!There_Is_Room
&& !Field_Grown(field
, 1))
4028 RETURN(E_SYSTEM_ERROR
);
4030 winsch(form
->w
, (chtype
)c
);
4033 if ((result
= Wrapping_Not_Necessary_Or_Wrapping_Ok(form
)) == E_OK
)
4035 bool End_Of_Field
= (((field
->drows
- 1) == form
->currow
) &&
4036 ((field
->dcols
- 1) == form
->curcol
));
4038 form
->status
|= _WINDOW_MODIFIED
;
4039 if (End_Of_Field
&& !Growable(field
) && (field
->opts
& O_AUTOSKIP
))
4040 result
= Inter_Field_Navigation(FN_Next_Field
, form
);
4043 if (End_Of_Field
&& Growable(field
) && !Field_Grown(field
, 1))
4044 result
= E_SYSTEM_ERROR
;
4047 #if USE_WIDEC_SUPPORT
4049 * We have just added a byte to the form field. It may have
4050 * been part of a multibyte character. If it was, the
4051 * addch_used field is nonzero and we should not try to move
4054 if (WINDOW_EXT(form
->w
, addch_used
) == 0)
4055 IFN_Next_Character(form
);
4057 IFN_Next_Character(form
);
4067 /* Structure to describe the binding of a request code to a function.
4068 The member keycode codes the request value as well as the generic
4069 routine to use for the request. The code for the generic routine
4070 is coded in the upper 16 Bits while the request code is coded in
4073 In terms of C++ you might think of a request as a class with a
4074 virtual method "perform". The different types of request are
4075 derived from this base class and overload (or not) the base class
4076 implementation of perform.
4080 int keycode
; /* must be at least 32 bit: hi:mode, lo: key */
4081 int (*cmd
) (FORM
*); /* low level driver routine for this key */
4085 /* You may see this is the class-id of the request type class */
4086 #define ID_PN (0x00000000) /* Page navigation */
4087 #define ID_FN (0x00010000) /* Inter-Field navigation */
4088 #define ID_IFN (0x00020000) /* Intra-Field navigation */
4089 #define ID_VSC (0x00030000) /* Vertical Scrolling */
4090 #define ID_HSC (0x00040000) /* Horizontal Scrolling */
4091 #define ID_FE (0x00050000) /* Field Editing */
4092 #define ID_EM (0x00060000) /* Edit Mode */
4093 #define ID_FV (0x00070000) /* Field Validation */
4094 #define ID_CH (0x00080000) /* Choice */
4095 #define ID_Mask (0xffff0000)
4096 #define Key_Mask (0x0000ffff)
4097 #define ID_Shft (16)
4099 /* This array holds all the Binding Infos */
4101 static const Binding_Info bindings
[MAX_FORM_COMMAND
- MIN_FORM_COMMAND
+ 1] =
4103 { REQ_NEXT_PAGE
|ID_PN
,PN_Next_Page
},
4104 { REQ_PREV_PAGE
|ID_PN
,PN_Previous_Page
},
4105 { REQ_FIRST_PAGE
|ID_PN
,PN_First_Page
},
4106 { REQ_LAST_PAGE
|ID_PN
,PN_Last_Page
},
4108 { REQ_NEXT_FIELD
|ID_FN
,FN_Next_Field
},
4109 { REQ_PREV_FIELD
|ID_FN
,FN_Previous_Field
},
4110 { REQ_FIRST_FIELD
|ID_FN
,FN_First_Field
},
4111 { REQ_LAST_FIELD
|ID_FN
,FN_Last_Field
},
4112 { REQ_SNEXT_FIELD
|ID_FN
,FN_Sorted_Next_Field
},
4113 { REQ_SPREV_FIELD
|ID_FN
,FN_Sorted_Previous_Field
},
4114 { REQ_SFIRST_FIELD
|ID_FN
,FN_Sorted_First_Field
},
4115 { REQ_SLAST_FIELD
|ID_FN
,FN_Sorted_Last_Field
},
4116 { REQ_LEFT_FIELD
|ID_FN
,FN_Left_Field
},
4117 { REQ_RIGHT_FIELD
|ID_FN
,FN_Right_Field
},
4118 { REQ_UP_FIELD
|ID_FN
,FN_Up_Field
},
4119 { REQ_DOWN_FIELD
|ID_FN
,FN_Down_Field
},
4121 { REQ_NEXT_CHAR
|ID_IFN
,IFN_Next_Character
},
4122 { REQ_PREV_CHAR
|ID_IFN
,IFN_Previous_Character
},
4123 { REQ_NEXT_LINE
|ID_IFN
,IFN_Next_Line
},
4124 { REQ_PREV_LINE
|ID_IFN
,IFN_Previous_Line
},
4125 { REQ_NEXT_WORD
|ID_IFN
,IFN_Next_Word
},
4126 { REQ_PREV_WORD
|ID_IFN
,IFN_Previous_Word
},
4127 { REQ_BEG_FIELD
|ID_IFN
,IFN_Beginning_Of_Field
},
4128 { REQ_END_FIELD
|ID_IFN
,IFN_End_Of_Field
},
4129 { REQ_BEG_LINE
|ID_IFN
,IFN_Beginning_Of_Line
},
4130 { REQ_END_LINE
|ID_IFN
,IFN_End_Of_Line
},
4131 { REQ_LEFT_CHAR
|ID_IFN
,IFN_Left_Character
},
4132 { REQ_RIGHT_CHAR
|ID_IFN
,IFN_Right_Character
},
4133 { REQ_UP_CHAR
|ID_IFN
,IFN_Up_Character
},
4134 { REQ_DOWN_CHAR
|ID_IFN
,IFN_Down_Character
},
4136 { REQ_NEW_LINE
|ID_FE
,FE_New_Line
},
4137 { REQ_INS_CHAR
|ID_FE
,FE_Insert_Character
},
4138 { REQ_INS_LINE
|ID_FE
,FE_Insert_Line
},
4139 { REQ_DEL_CHAR
|ID_FE
,FE_Delete_Character
},
4140 { REQ_DEL_PREV
|ID_FE
,FE_Delete_Previous
},
4141 { REQ_DEL_LINE
|ID_FE
,FE_Delete_Line
},
4142 { REQ_DEL_WORD
|ID_FE
,FE_Delete_Word
},
4143 { REQ_CLR_EOL
|ID_FE
,FE_Clear_To_End_Of_Line
},
4144 { REQ_CLR_EOF
|ID_FE
,FE_Clear_To_End_Of_Field
},
4145 { REQ_CLR_FIELD
|ID_FE
,FE_Clear_Field
},
4147 { REQ_OVL_MODE
|ID_EM
,EM_Overlay_Mode
},
4148 { REQ_INS_MODE
|ID_EM
,EM_Insert_Mode
},
4150 { REQ_SCR_FLINE
|ID_VSC
,VSC_Scroll_Line_Forward
},
4151 { REQ_SCR_BLINE
|ID_VSC
,VSC_Scroll_Line_Backward
},
4152 { REQ_SCR_FPAGE
|ID_VSC
,VSC_Scroll_Page_Forward
},
4153 { REQ_SCR_BPAGE
|ID_VSC
,VSC_Scroll_Page_Backward
},
4154 { REQ_SCR_FHPAGE
|ID_VSC
,VSC_Scroll_Half_Page_Forward
},
4155 { REQ_SCR_BHPAGE
|ID_VSC
,VSC_Scroll_Half_Page_Backward
},
4157 { REQ_SCR_FCHAR
|ID_HSC
,HSC_Scroll_Char_Forward
},
4158 { REQ_SCR_BCHAR
|ID_HSC
,HSC_Scroll_Char_Backward
},
4159 { REQ_SCR_HFLINE
|ID_HSC
,HSC_Horizontal_Line_Forward
},
4160 { REQ_SCR_HBLINE
|ID_HSC
,HSC_Horizontal_Line_Backward
},
4161 { REQ_SCR_HFHALF
|ID_HSC
,HSC_Horizontal_Half_Line_Forward
},
4162 { REQ_SCR_HBHALF
|ID_HSC
,HSC_Horizontal_Half_Line_Backward
},
4164 { REQ_VALIDATION
|ID_FV
,FV_Validation
},
4166 { REQ_NEXT_CHOICE
|ID_CH
,CR_Next_Choice
},
4167 { REQ_PREV_CHOICE
|ID_CH
,CR_Previous_Choice
}
4171 /*---------------------------------------------------------------------------
4172 | Facility : libnform
4173 | Function : int form_driver(FORM * form,int c)
4175 | Description : This is the workhorse of the forms system. It checks
4176 | to determine whether the character c is a request or
4177 | data. If it is a request, the form driver executes
4178 | the request and returns the result. If it is data
4179 | (printable character), it enters the data into the
4180 | current position in the current field. If it is not
4181 | recognized, the form driver assumes it is an application
4182 | defined command and returns E_UNKNOWN_COMMAND.
4183 | Application defined command should be defined relative
4184 | to MAX_FORM_COMMAND, the maximum value of a request.
4186 | Return Values : E_OK - success
4187 | E_SYSTEM_ERROR - system error
4188 | E_BAD_ARGUMENT - an argument is incorrect
4189 | E_NOT_POSTED - form is not posted
4190 | E_INVALID_FIELD - field contents are invalid
4191 | E_BAD_STATE - called from inside a hook routine
4192 | E_REQUEST_DENIED - request failed
4193 | E_NOT_CONNECTED - no fields are connected to the form
4194 | E_UNKNOWN_COMMAND - command not known
4195 +--------------------------------------------------------------------------*/
4197 form_driver(FORM
*form
, int c
)
4199 const Binding_Info
*BI
= (Binding_Info
*) 0;
4200 int res
= E_UNKNOWN_COMMAND
;
4202 T((T_CALLED("form_driver(%p,%d)"), (void *)form
, c
));
4205 RETURN(E_BAD_ARGUMENT
);
4208 RETURN(E_NOT_CONNECTED
);
4212 if (c
== FIRST_ACTIVE_MAGIC
)
4214 form
->current
= _nc_First_Active_Field(form
);
4218 assert(form
->current
&&
4219 form
->current
->buf
&&
4220 (form
->current
->form
== form
)
4223 if (form
->status
& _IN_DRIVER
)
4224 RETURN(E_BAD_STATE
);
4226 if (!(form
->status
& _POSTED
))
4227 RETURN(E_NOT_POSTED
);
4229 if ((c
>= MIN_FORM_COMMAND
&& c
<= MAX_FORM_COMMAND
) &&
4230 ((bindings
[c
- MIN_FORM_COMMAND
].keycode
& Key_Mask
) == c
))
4231 BI
= &(bindings
[c
- MIN_FORM_COMMAND
]);
4235 typedef int (*Generic_Method
) (int (*const) (FORM
*), FORM
*);
4236 static const Generic_Method Generic_Methods
[] =
4238 Page_Navigation
, /* overloaded to call field&form hooks */
4239 Inter_Field_Navigation
, /* overloaded to call field hooks */
4240 NULL
, /* Intra-Field is generic */
4241 Vertical_Scrolling
, /* Overloaded to check multi-line */
4242 Horizontal_Scrolling
, /* Overloaded to check single-line */
4243 Field_Editing
, /* Overloaded to mark modification */
4244 NULL
, /* Edit Mode is generic */
4245 NULL
, /* Field Validation is generic */
4246 NULL
/* Choice Request is generic */
4248 size_t nMethods
= (sizeof(Generic_Methods
) / sizeof(Generic_Methods
[0]));
4249 size_t method
= (BI
->keycode
>> ID_Shft
) & 0xffff; /* see ID_Mask */
4251 if ((method
>= nMethods
) || !(BI
->cmd
))
4252 res
= E_SYSTEM_ERROR
;
4255 Generic_Method fct
= Generic_Methods
[method
];
4258 res
= fct(BI
->cmd
, form
);
4260 res
= (BI
->cmd
) (form
);
4263 #ifdef NCURSES_MOUSE_VERSION
4264 else if (KEY_MOUSE
== c
)
4267 WINDOW
*win
= form
->win
? form
->win
: StdScreen(Get_Form_Screen(form
));
4268 WINDOW
*sub
= form
->sub
? form
->sub
: win
;
4271 if ((event
.bstate
& (BUTTON1_CLICKED
|
4272 BUTTON1_DOUBLE_CLICKED
|
4273 BUTTON1_TRIPLE_CLICKED
))
4274 && wenclose(win
, event
.y
, event
.x
))
4275 { /* we react only if the click was in the userwin, that means
4276 * inside the form display area or at the decoration window.
4278 int ry
= event
.y
, rx
= event
.x
; /* screen coordinates */
4280 res
= E_REQUEST_DENIED
;
4281 if (mouse_trafo(&ry
, &rx
, FALSE
))
4282 { /* rx, ry are now "curses" coordinates */
4283 if (ry
< sub
->_begy
)
4284 { /* we clicked above the display region; this is
4285 * interpreted as "scroll up" request
4287 if (event
.bstate
& BUTTON1_CLICKED
)
4288 res
= form_driver(form
, REQ_PREV_FIELD
);
4289 else if (event
.bstate
& BUTTON1_DOUBLE_CLICKED
)
4290 res
= form_driver(form
, REQ_PREV_PAGE
);
4291 else if (event
.bstate
& BUTTON1_TRIPLE_CLICKED
)
4292 res
= form_driver(form
, REQ_FIRST_FIELD
);
4294 else if (ry
> sub
->_begy
+ sub
->_maxy
)
4295 { /* we clicked below the display region; this is
4296 * interpreted as "scroll down" request
4298 if (event
.bstate
& BUTTON1_CLICKED
)
4299 res
= form_driver(form
, REQ_NEXT_FIELD
);
4300 else if (event
.bstate
& BUTTON1_DOUBLE_CLICKED
)
4301 res
= form_driver(form
, REQ_NEXT_PAGE
);
4302 else if (event
.bstate
& BUTTON1_TRIPLE_CLICKED
)
4303 res
= form_driver(form
, REQ_LAST_FIELD
);
4305 else if (wenclose(sub
, event
.y
, event
.x
))
4306 { /* Inside the area we try to find the hit item */
4311 if (wmouse_trafo(sub
, &ry
, &rx
, FALSE
))
4313 int min_field
= form
->page
[form
->curpage
].pmin
;
4314 int max_field
= form
->page
[form
->curpage
].pmax
;
4316 for (i
= min_field
; i
<= max_field
; ++i
)
4318 FIELD
*field
= form
->field
[i
];
4320 if (Field_Is_Selectable(field
)
4321 && Field_encloses(field
, ry
, rx
) == E_OK
)
4323 res
= _nc_Set_Current_Field(form
, field
);
4325 res
= _nc_Position_Form_Cursor(form
);
4327 && (event
.bstate
& BUTTON1_DOUBLE_CLICKED
))
4328 res
= E_UNKNOWN_COMMAND
;
4337 res
= E_REQUEST_DENIED
;
4339 #endif /* NCURSES_MOUSE_VERSION */
4340 else if (!(c
& (~(int)MAX_REGULAR_CHARACTER
)))
4343 * If we're using 8-bit characters, iscntrl+isprint cover the whole set.
4344 * But with multibyte characters, there is a third possibility, i.e.,
4345 * parts of characters that build up into printable characters which are
4346 * not considered printable.
4348 * FIXME: the wide-character branch should also use Check_Char().
4350 #if USE_WIDEC_SUPPORT
4351 if (!iscntrl(UChar(c
)))
4353 if (isprint(UChar(c
)) &&
4354 Check_Char(form
, form
->current
, form
->current
->type
, c
,
4355 (TypeArgument
*)(form
->current
->arg
)))
4357 res
= Data_Entry(form
, c
);
4359 _nc_Refresh_Current_Field(form
);
4363 /*----------------------------------------------------------------------------
4364 Field-Buffer manipulation routines.
4365 The effects of setting a buffer are tightly coupled to the core of the form
4366 driver logic. This is especially true in the case of growable fields.
4367 So I don't separate this into a separate module.
4368 --------------------------------------------------------------------------*/
4370 /*---------------------------------------------------------------------------
4371 | Facility : libnform
4372 | Function : int set_field_buffer(FIELD *field,
4373 | int buffer, char *value)
4375 | Description : Set the given buffer of the field to the given value.
4376 | Buffer 0 stores the displayed content of the field.
4377 | For dynamic fields this may grow the fieldbuffers if
4378 | the length of the value exceeds the current buffer
4379 | length. For buffer 0 only printable values are allowed.
4380 | For static fields, the value needs not to be zero ter-
4381 | minated. It is copied up to the length of the buffer.
4383 | Return Values : E_OK - success
4384 | E_BAD_ARGUMENT - invalid argument
4385 | E_SYSTEM_ERROR - system error
4386 +--------------------------------------------------------------------------*/
4388 set_field_buffer(FIELD
*field
, int buffer
, const char *value
)
4395 #if USE_WIDEC_SUPPORT
4396 FIELD_CELL
*widevalue
= 0;
4399 T((T_CALLED("set_field_buffer(%p,%d,%s)"), (void *)field
, buffer
, _nc_visbuf(value
)));
4401 if (!field
|| !value
|| ((buffer
< 0) || (buffer
> field
->nbuf
)))
4402 RETURN(E_BAD_ARGUMENT
);
4404 len
= Buffer_Length(field
);
4406 if (Growable(field
))
4408 /* for a growable field we must assume zero terminated strings, because
4409 somehow we have to detect the length of what should be copied.
4411 unsigned int vlen
= strlen(value
);
4415 if (!Field_Grown(field
,
4416 (int)(1 + (vlen
- len
) / ((field
->rows
+ field
->nrow
)
4418 RETURN(E_SYSTEM_ERROR
);
4420 #if !USE_WIDEC_SUPPORT
4426 p
= Address_Of_Nth_Buffer(field
, buffer
);
4428 #if USE_WIDEC_SUPPORT
4430 * Use addstr's logic for converting a string to an array of cchar_t's.
4431 * There should be a better way, but this handles nonspacing characters
4432 * and other special cases that we really do not want to handle here.
4434 #if NCURSES_EXT_FUNCS
4435 if (wresize(field
->working
, 1, Buffer_Length(field
) + 1) == ERR
)
4438 delwin(field
->working
);
4439 field
->working
= newpad(1, Buffer_Length(field
) + 1);
4441 len
= Buffer_Length(field
);
4442 wclear(field
->working
);
4443 (void)mvwaddstr(field
->working
, 0, 0, value
);
4445 if ((widevalue
= typeCalloc(FIELD_CELL
, len
+ 1)) == 0)
4447 RETURN(E_SYSTEM_ERROR
);
4451 for (i
= 0; i
< (unsigned)field
->drows
; ++i
)
4453 (void)mvwin_wchnstr(field
->working
, 0, i
* field
->dcols
,
4454 widevalue
+ (i
* field
->dcols
),
4457 for (i
= 0; i
< len
; ++i
)
4459 if (CharEq(myZEROS
, widevalue
[i
]))
4465 p
[i
] = widevalue
[i
];
4470 for (i
= 0; i
< len
; ++i
)
4472 if (value
[i
] == '\0')
4486 if (((syncres
= Synchronize_Field(field
)) != E_OK
) &&
4489 if (((syncres
= Synchronize_Linked_Fields(field
)) != E_OK
) &&
4496 /*---------------------------------------------------------------------------
4497 | Facility : libnform
4498 | Function : char *field_buffer(const FIELD *field,int buffer)
4500 | Description : Return the address of the buffer for the field.
4502 | Return Values : Pointer to buffer or NULL if arguments were invalid.
4503 +--------------------------------------------------------------------------*/
4504 NCURSES_EXPORT(char *)
4505 field_buffer(const FIELD
*field
, int buffer
)
4509 T((T_CALLED("field_buffer(%p,%d)"), (const void *)field
, buffer
));
4511 if (field
&& (buffer
>= 0) && (buffer
<= field
->nbuf
))
4513 #if USE_WIDEC_SUPPORT
4514 FIELD_CELL
*data
= Address_Of_Nth_Buffer(field
, buffer
);
4516 int size
= Buffer_Length(field
);
4519 /* determine the number of bytes needed to store the expanded string */
4520 for (n
= 0; n
< size
; ++n
)
4522 if (!isWidecExt(data
[n
]) && data
[n
].chars
[0] != L
'\0')
4528 next
= _nc_wcrtomb(0, data
[n
].chars
[0], &state
);
4529 if (!isEILSEQ(next
))
4534 /* allocate a place to store the expanded string */
4535 if (field
->expanded
[buffer
] != 0)
4536 free(field
->expanded
[buffer
]);
4537 field
->expanded
[buffer
] = typeMalloc(char, need
+ 1);
4540 * Expand the multibyte data.
4542 * It may also be multi-column data. In that case, the data for a row
4543 * may be null-padded to align to the dcols/drows layout (or it may
4544 * contain embedded wide-character extensions). Change the null-padding
4545 * to blanks as needed.
4547 if ((result
= field
->expanded
[buffer
]) != 0)
4549 wclear(field
->working
);
4550 wmove(field
->working
, 0, 0);
4551 for (n
= 0; n
< size
; ++n
)
4553 if (!isWidecExt(data
[n
]) && data
[n
].chars
[0] != L
'\0')
4554 wadd_wch(field
->working
, &data
[n
]);
4556 wmove(field
->working
, 0, 0);
4557 winnstr(field
->working
, result
, (int)need
);
4560 result
= Address_Of_Nth_Buffer(field
, buffer
);
4566 #if USE_WIDEC_SUPPORT
4568 /*---------------------------------------------------------------------------
4569 | Convert a multibyte string to a wide-character string. The result must be
4570 | freed by the caller.
4571 +--------------------------------------------------------------------------*/
4572 NCURSES_EXPORT(wchar_t *)
4573 _nc_Widen_String(char *source
, int *lengthp
)
4575 wchar_t *result
= 0;
4577 size_t given
= strlen(source
);
4582 #ifndef state_unused
4586 for (pass
= 0; pass
< 2; ++pass
)
4591 while (passed
< given
)
4595 for (tries
= 1, status
= 0; tries
<= (given
- passed
); ++tries
)
4597 int save
= source
[passed
+ tries
];
4599 source
[passed
+ tries
] = 0;
4600 reset_mbytes(state
);
4601 status
= check_mbytes(wch
, source
+ passed
, tries
, state
);
4602 source
[passed
+ tries
] = (char)save
;
4623 result
[need
] = source
[passed
];
4634 result
= typeCalloc(wchar_t, need
);
4646 /* frm_driver.c ends here */