Lines Matching refs:FIELD
91 _formi_do_char_validation(FIELD *field, FIELDTYPE *type, char c, int *ret_val);
93 _formi_do_validation(FIELD *field, FIELDTYPE *type, int *ret_val);
95 _formi_join_line(FIELD *field, _FORMI_FIELD_LINES **rowp, int direction);
97 _formi_hscroll_back(FIELD *field, _FORMI_FIELD_LINES *row, unsigned int amt);
99 _formi_hscroll_fwd(FIELD *field, _FORMI_FIELD_LINES *row, unsigned int amt);
101 _formi_scroll_back(FIELD *field, unsigned int amt);
103 _formi_scroll_fwd(FIELD *field, unsigned int amt);
105 _formi_set_cursor_xpos(FIELD *field, int no_scroll);
109 split_line(FIELD *field, bool hard_split, unsigned pos,
112 check_field_size(FIELD *field);
120 tab_fit_window(FIELD *field, unsigned int pos, unsigned int window);
122 add_to_free(FIELD *field, _FORMI_FIELD_LINES *line);
124 adjust_ypos(FIELD *field, _FORMI_FIELD_LINES *line);
132 * field. This may be as simple as just changing the ypos (if at all) but
133 * may encompass resetting the start_line of the field to place the line
134 * at the bottom of the field. The field is assumed to be a multi-line one.
137 adjust_ypos(FIELD *field, _FORMI_FIELD_LINES *line)
143 rs = field->alines;
149 field->cursor_ypos = ypos;
150 field->start_line = field->alines;
151 if (ypos > (field->rows - 1)) {
153 * cur_line off the end of the field,
156 field->cursor_ypos = field->rows - 1;
157 ypos = ypos - (field->rows - 1);
160 field->start_line = field->start_line->next;
167 * Delete the given row and add it to the free list of the given field.
170 add_to_free(FIELD *field, _FORMI_FIELD_LINES *line)
182 field->alines = line->next;
183 field->alines->prev = NULL;
185 if (field->cur_line == saved)
186 field->cur_line = field->alines;
187 if (field->start_line == saved)
188 field->start_line = saved;
192 if (field->cur_line == saved)
193 field->cur_line = saved->prev;
194 if (field->start_line == saved)
195 field->cur_line = saved->prev;
199 if (field->cur_line == saved)
200 field->cur_line = saved->prev;
201 if (field->start_line == saved)
202 field->start_line = saved;
205 saved->next = field->free;
206 field->free = saved;
282 * Initialise the row offset for a field, depending on the type of
283 * field it is and the type of justification used. The justification
288 _formi_init_field_xpos(FIELD *field)
291 if (((field->opts & O_STATIC) != O_STATIC) ||
292 ((field->rows + field->nrows) != 1)) {
293 field->cursor_xpos = 0;
297 switch (field->justification) {
299 field->cursor_xpos = field->cols - 1;
303 field->cursor_xpos = (field->cols - 1) / 2;
307 field->cursor_xpos = 0;
336 * Check the sizing of the field, if the maximum size is set for a
337 * dynamic field then check that the number of rows or columns does
339 * columns is made on the basis of how many rows are in the field -
346 check_field_size(FIELD *field)
348 if ((field->opts & O_STATIC) != O_STATIC) {
349 /* dynamic field */
350 if (field->max == 0) /* unlimited */
353 if (field->rows == 1) {
354 return (field->alines->length < field->max);
356 return (field->row_count <= field->max);
359 if ((field->rows + field->nrows) == 1) {
360 return (field->alines->length <= field->cols);
362 return (field->row_count <= (field->rows
363 + field->nrows));
369 * Set the form's current field to the first valid field on the page.
375 FIELD *cur;
389 /* then scan for a field we can use */
405 * Set the field to the next active and visible field, the fields are
407 * use_sorted is TRUE then the sorted field list will be traversed instead
408 * of using the field index.
413 FIELD *cur;
495 * Word wrap the contents of the field's buffer 0 if this is allowed.
501 _formi_wrap_field(FIELD *field, _FORMI_FIELD_LINES *loc)
509 if ((field->opts & O_STATIC) == O_STATIC) {
510 if ((field->rows + field->nrows) == 1) {
513 width = field->cols;
516 if ((field->drows + field->nrows) == 1) {
521 * hueristic - if a dynamic field has more than one line
522 * on the screen then the field grows rows, otherwise
523 * it grows columns, effectively a single line field.
526 if (field->rows > 1) {
527 width = field->cols;
535 /* if we are not at the top of the field then back up one
543 saved_xpos = field->row_xpos;
544 saved_cur_xpos = field->cursor_xpos;
545 saved_ypos = field->cursor_ypos;
546 saved_row_count = field->row_count;
571 if (row == field->start_line)
573 if (row == field->cur_line)
602 if (_formi_join_line(field, &row,
613 * the field border lies when the tabs are expanded.
620 pos = tab_fit_len(row, field->cols);
624 ((field->opts & O_WRAP) == O_WRAP)) {
645 row->expanded <= field->cols)
658 if (split_line(field, FALSE, pos, &row) != E_OK) {
668 if ((((field->opts & O_STATIC) == O_STATIC) &&
669 field->row_count > (field->rows + field->nrows)) ||
670 ((field->max != 0) && (field->row_count > field->max))) {
676 field->alines = row_backup;
682 field->row_xpos = saved_xpos;
683 field->cursor_xpos = saved_cur_xpos;
684 field->cursor_ypos = saved_ypos;
685 field->row_count = saved_row_count;
686 field->start_line = saved_start_line;
687 field->cur_line = saved_cur_line;
706 _formi_join_line(FIELD *field, _FORMI_FIELD_LINES **rowp, int direction)
714 __func__, row, field->row_count);
756 if (field->cur_line == row->next) {
757 field->cur_line = row;
758 field->row_xpos += old_len;
759 field->cursor_xpos =
761 field->row_xpos);
762 if (field->cursor_xpos > 0)
763 field->cursor_xpos--;
765 if (field->cursor_ypos > 0)
766 field->cursor_ypos--;
768 if (field->start_line->prev != NULL)
769 field->start_line =
770 field->start_line->prev;
775 add_to_free(field, row->next);
825 if (field->cur_line == row) {
826 field->cur_line = saved;
827 field->row_xpos += old_len;
828 field->cursor_xpos =
830 field->row_xpos);
831 if (field->cursor_xpos > 0)
832 field->cursor_xpos--;
835 add_to_free(field, row);
845 * Work out where the line lies in the field in relation to
847 * the field until we hit the row we just worked on.
849 saved = field->start_line;
859 if (field->cursor_ypos > count) {
860 field->cursor_ypos--;
863 field->row_count--;
866 /* wrap the field if required, if this fails undo the change */
868 if (_formi_wrap_field(field, row) != E_OK) {
882 split_line(FIELD *field, bool hard_split, unsigned pos,
899 if (field->free != NULL) {
900 new_line = field->free;
901 field->free = new_line->next;
902 if (field->free != NULL)
903 field->free->prev = NULL;
964 if ((field->cur_line == row) && (field->row_xpos >= pos)) {
965 field->cur_line = new_line;
966 field->row_xpos -= pos;
967 field->cursor_xpos =
969 field->row_xpos);
970 if (field->cursor_xpos > 0)
971 field->cursor_xpos--;
973 field->cursor_ypos++;
974 if (field->cursor_ypos >= field->rows) {
975 if (field->start_line->next != NULL) {
976 field->start_line = field->start_line->next;
977 field->cursor_ypos = field->rows - 1;
980 assert(field->start_line->next == NULL);
1012 _formi_dbg_printf("row_count = %d\n", field->row_count + 1);
1014 field->row_count++;
1084 * Return the index of the top left most field of the two given fields.
1108 * Return the index to the field that is the bottom-right-most of the
1135 * joined (without wrapping) until either the end of the field or the
1139 find_eow(FIELD *cur, unsigned int offset, bool do_join,
1306 * Scroll the field forward the given number of lines.
1309 _formi_scroll_fwd(FIELD *field, unsigned int amt)
1314 end_row = field->start_line;
1315 /* walk the line structs forward to find the bottom of the field */
1316 count = field->rows - 1;
1331 * last line in the field.
1336 field->start_line = field->start_line->next;
1342 * Scroll the field backward the given number of lines.
1345 _formi_scroll_back(FIELD *field, unsigned int amt)
1350 if (field->start_line->prev == NULL)
1355 * the number of lines done or we reach the top of the field.
1358 while ((count > 0) && (field->start_line->prev != NULL)) {
1360 field->start_line = field->start_line->prev;
1365 * Scroll the field forward the given number of characters.
1368 _formi_hscroll_fwd(FIELD *field, _FORMI_FIELD_LINES *row, int unsigned amt)
1376 end = field->start_char + field->cols + amt - 1;
1380 scroll_amt = end - field->start_char - field->cols + 1;
1386 * the field and finally fix up the start_char. This
1390 end = field->start_char + field->row_xpos + amt;
1396 field->start_char + amt,
1397 field->start_char + field->row_xpos + amt);
1404 while ((expanded <= field->cols)
1411 > field->cols)
1424 scroll_amt = tab_fit_window(field, end, field->cols);
1425 if (scroll_amt < field->start_char)
1428 scroll_amt -= field->start_char;
1433 field->start_char += scroll_amt;
1434 field->cursor_xpos =
1436 field->start_char,
1437 field->row_xpos
1438 + field->start_char) - 1;
1443 * Scroll the field backward the given number of characters.
1446 _formi_hscroll_back(FIELD *field, _FORMI_FIELD_LINES *row, unsigned int amt)
1448 field->start_char -= min(field->start_char, amt);
1449 field->cursor_xpos =
1450 _formi_tab_expanded_length(row->string, field->start_char,
1451 field->row_xpos
1452 + field->start_char) - 1;
1453 if (field->cursor_xpos >= field->cols) {
1454 field->row_xpos = 0;
1455 field->cursor_xpos = 0;
1498 * Completely redraw the field of the given form.
1501 _formi_redraw_field(FORM *form, int field)
1506 FIELD *cur;
1512 cur = form->fields[field];
1702 * in the field.
1745 * Add the character c at the position pos in buffer 0 of the given field
1748 _formi_add_char(FIELD *field, unsigned int pos, char c)
1755 row = field->cur_line;
1770 if (_formi_validate_char(field, c) != E_OK) {
1776 if ((c == '\t') && (field->cols <= 8)) {
1777 _formi_dbg_printf("%s: field too small for a tab\n", __func__);
1783 field->cursor_xpos, field->row_xpos, field->start_char);
1787 _formi_dbg_printf("%s: buf0_status=%d\n", __func__, field->buf0_status);
1788 if (((field->opts & O_BLANK) == O_BLANK) &&
1789 (field->buf0_status == FALSE) &&
1790 ((field->row_xpos + field->start_char) == 0)) {
1791 row = field->alines;
1797 add_to_free(field, temp);
1805 field->start_char = 0;
1806 field->start_line = row;
1807 field->cur_line = row;
1808 field->row_count = 1;
1809 field->row_xpos = 0;
1810 field->cursor_ypos = 0;
1813 _formi_init_field_xpos(field);
1817 if ((field->overlay == 0)
1818 || ((field->overlay == 1) && (pos >= row->length))) {
1819 /* first check if the field can have more chars...*/
1820 if (check_field_size(field) == FALSE)
1834 if ((field->overlay == 0) && (row->length > pos)) {
1844 * if we are at the end of the field.
1850 * OR if we are at the end of the field in overlay mode.
1852 if ((field->overlay == 0)
1853 || ((field->overlay == 1) && (pos >= row->length))) {
1861 /* wrap the field, if needed */
1862 status = _formi_wrap_field(field, row);
1864 row = field->cur_line;
1865 pos = field->row_xpos;
1869 * max field size - this can happen if the field is re-wrapped
1872 if ((status != E_OK) || (check_field_size(field) == FALSE)) {
1873 if ((field->overlay == 0)
1874 || ((field->overlay == 1)
1885 } else if (field->overlay == 1) {
1892 _formi_wrap_field(field, row);
1902 field->buf0_status = TRUE;
1903 field->row_xpos++;
1904 if ((field->rows + field->nrows) == 1) {
1905 status = _formi_set_cursor_xpos(field, FALSE);
1907 field->cursor_xpos =
1909 row->string, 0, field->row_xpos - 1);
1913 * the bottom right corner of the field we
1914 * need to scroll the field one line so the
1916 * field.
1918 if ((field->cursor_xpos >= field->cols) &&
1919 (field->cursor_ypos == (field->rows - 1))) {
1920 field->cursor_ypos--;
1921 field->start_line = field->start_line->next;
1926 assert((field->cursor_xpos <= field->cols)
1927 && (field->cursor_ypos < 400000));
1930 field->cursor_xpos, field->row_xpos, field->start_char);
1934 field->cursor_ypos, field->start_line);
1936 _formi_dbg_printf("%s: buf0_status=%d\n", __func__, field->buf0_status);
1945 field. Justification is only applied
1949 _formi_set_cursor_xpos(FIELD *field, int noscroll)
1953 just = field->justification;
1954 pos = field->start_char + field->row_xpos;
1958 pos, field->start_char, field->row_xpos, field->cursor_xpos);
1964 if (((field->rows + field->nrows) != 1) ||
1965 ((field->opts & O_STATIC) != O_STATIC))
1970 field->cursor_xpos = field->cols - 1
1972 field->cur_line->string, 0,
1973 field->cur_line->length - 1)
1975 field->cur_line->string, 0,
1976 field->row_xpos);
1980 field->cursor_xpos = ((field->cols - 1)
1982 field->cur_line->string, 0,
1983 field->cur_line->length - 1) + 1) / 2
1984 + _formi_tab_expanded_length(field->cur_line->string,
1985 0, field->row_xpos);
1987 if (field->cursor_xpos > (field->cols - 1))
1988 field->cursor_xpos = (field->cols - 1);
1992 field->cursor_xpos = _formi_tab_expanded_length(
1993 field->cur_line->string,
1994 field->start_char,
1995 field->row_xpos + field->start_char);
1996 if ((field->cursor_xpos <= (field->cols - 1)) &&
1997 ((field->start_char + field->row_xpos)
1998 < field->cur_line->length))
1999 field->cursor_xpos--;
2001 if (field->cursor_xpos > (field->cols - 1)) {
2002 if ((field->opts & O_STATIC) == O_STATIC) {
2003 field->start_char = 0;
2005 if (field->row_xpos
2006 == (field->cur_line->length - 1)) {
2007 field->cursor_xpos = field->cols - 1;
2009 field->cursor_xpos =
2011 field->cur_line->string,
2012 field->start_char,
2013 field->row_xpos
2014 + field->start_char
2019 field->start_char =
2021 field,
2022 field->start_char
2023 + field->row_xpos,
2024 field->cols);
2025 field->row_xpos = pos
2026 - field->start_char;
2027 field->cursor_xpos =
2029 field->cur_line->string,
2030 field->start_char,
2031 field->row_xpos
2032 + field->start_char - 1);
2034 field->cursor_xpos = (field->cols - 1);
2044 pos, field->start_char, field->row_xpos, field->cursor_xpos);
2049 * Manipulate the text in a field, this takes the given form and performs
2050 * the passed driver command on the current text field. Returns 1 if the
2051 * text field was modified.
2056 FIELD *cur;
2105 /* for a dynamic field allow an offset of one more
2108 * cursor is at the end of the field.
2173 * reached the LHS of the field, so just check this
2238 * the next_line request excepting that the field is not
2239 * scrolled if the cursor is at the bottom of the field.
2240 * Check to see if the cursor is at the bottom of the field
2282 * the prev_line request excepting the field is not
2284 * field, if it is deny the request otherwise fall
2337 /* single line field */
2348 /* multiline field */
2380 /* single line field */
2392 /* multiline field */
2507 * re-wrap the field. The hard return
2530 * in the field.
2554 * recalculate tabs for a single line field, multiline
2555 * fields will do this when the field is wrapped.
2638 * If we are a multiline field then check if
2641 * the field.
2728 /* multiline field */
2941 _formi_validate_char(FIELD *field, char c)
2945 if (field->type == NULL)
2949 _formi_do_char_validation(field, field->type, c, &ret_val);
2957 * routines. If the field is ok then update ret_val to E_OK otherwise
2961 _formi_do_char_validation(FIELD *field, FIELDTYPE *type, char c, int *ret_val)
2964 _formi_do_char_validation(field, type->link->next, c, ret_val);
2965 _formi_do_char_validation(field, type->link->prev, c, ret_val);
2971 field->args) == TRUE)
2978 * Validate the current field. If the field validation returns success then
2985 FIELD *cur;
2996 * Sync the buffer if it has been modified so the field
3017 /* check if we have a null field, depending on the nullok flag
3027 /* check if an unmodified field is ok */
3035 /* if there is no type then just accept the field */
3046 * Perform the validation of the field, invoke all field_type validation
3047 * routines. If the field is ok then update ret_val to E_OK otherwise
3051 _formi_do_validation(FIELD *field, FIELDTYPE *type, int *ret_val)
3054 _formi_do_validation(field, type->link->next, ret_val);
3055 _formi_do_validation(field, type->link->prev, ret_val);
3060 if (type->field_check(field, field_buffer(field, 0))
3068 * Select the next/previous choice for the field, the driver command
3076 FIELD *field;
3083 field = form->fields[form->cur_field];
3084 type = field->type;
3091 return type->next_choice(field,
3092 field_buffer(field, 0));
3098 return type->prev_choice(field,
3099 field_buffer(field, 0));
3108 * previous current field as the current field may have been updated by
3140 * Compare function for the field sorting
3146 const FIELD *a, *b;
3149 a = *(const FIELD **) __UNCONST(one);
3150 b = *(const FIELD **) __UNCONST(two);
3180 FIELD **sort_area;
3190 qsort(sort_area, (size_t) form->field_count, sizeof(FIELD *),
3206 FIELD *cur, *above, *below;
3220 /* set up the first field as the current... */
3224 /* find the first field on the next row if any */
3362 * Calculate the tab stops on a given line in the field and set up
3366 * make manipulating the field (scrolling and so on) easier to handle.
3430 * results - it is really only required for a single row field.
3433 tab_fit_window(FIELD *field, unsigned int pos, unsigned int window)
3439 ts = field->alines->tabs;
3446 if (field->alines->length < window)
3449 return field->alines->length - window + 1;
3464 if (field->alines->string[i] == '\t') {
3488 * field.
3527 * Sync the field line structures with the contents of buffer 0 for that
3528 * field. We do this by walking all the line structures and concatenating
3532 _formi_sync_buffer(FIELD *field)
3538 if (field->alines == NULL)
3541 if (field->alines->string == NULL)
3546 * this could happen if the field just contains hard returns.
3552 line = field->alines;
3573 if (field->buffers[0].string != NULL)
3574 free(field->buffers[0].string);
3575 field->buffers[0].allocated = length;
3576 field->buffers[0].length = length - 1;
3577 field->buffers[0].string = nstr;