Lines Matching refs:form
1 /* $NetBSD: form.c,v 1.17 2021/04/13 13:13:04 christos Exp $ */
33 __RCSID("$NetBSD: form.c,v 1.17 2021/04/13 13:13:04 christos Exp $");
37 #include <form.h>
42 FORM _formi_default_form = {
44 FALSE, /* the form is posted */
46 NULL, /* window for the form */
47 NULL, /* subwindow for the form */
50 0, /* options for the form */
51 NULL, /* function called when form posted and
53 NULL, /* function called when form is unposted and
55 NULL, /* function called when form posted and after
57 NULL, /* function called when form unposted and
61 0, /* current page of form */
62 0, /* number of pages in the form */
66 NULL /* array of fields attached to this form. */
70 * Set the window associated with the form
73 set_form_win(FORM *form, WINDOW *win)
75 if (form == NULL) {
79 if (form->posted == TRUE)
82 form->win = win;
83 form->scrwin = win;
91 * Return the window used by the given form
94 form_win(FORM *form)
96 if (form == NULL)
99 return form->win;
103 * Set the subwindow for the form.
106 set_form_sub(FORM *form, WINDOW *window)
108 if (form == NULL) {
112 if (form->posted == TRUE)
115 form->subwin = window;
116 form->scrwin = window;
124 * Return the subwindow for the given form.
127 form_sub(FORM *form)
129 if (form == NULL)
132 return form->subwin;
136 * Return the minimum size required to contain the form.
139 scale_form(FORM *form, int *rows, int *cols)
143 if ((form->fields == NULL) || (form->fields[0] == NULL))
149 for (i = 0; i < form->field_count; i++) {
150 temp = form->fields[i]->form_row + form->fields[i]->rows;
152 temp = form->fields[i]->form_col + form->fields[i]->cols;
163 * Set the user defined pointer for the form given.
166 set_form_userptr(FORM *form, void *ptr)
168 if (form == NULL)
171 form->userptr = ptr;
177 * Return the user defined pointer associated with the given form.
180 form_userptr(FORM *form)
183 if (form == NULL)
186 return form->userptr;
190 * Set the form options to the given ones.
193 set_form_opts(FORM *form, Form_Options options)
195 if (form == NULL)
198 form->opts = options;
204 * Turn the given options on for the form.
207 form_opts_on(FORM *form, Form_Options options)
209 if (form == NULL)
212 form->opts |= options;
218 * Turn the given options off for the form.
221 form_opts_off(FORM *form, Form_Options options)
223 if (form == NULL)
226 form->opts &= ~options;
233 * Return the options set for the given form.
236 form_opts(FORM *form)
238 if (form == NULL)
241 return form->opts;
245 * Set the form init function for the given form
248 set_form_init(FORM *form, Form_Hook func)
250 if (form == NULL)
253 form->form_init = func;
259 * Return the init function associated with the given form.
262 form_init(FORM *form)
264 if (form == NULL)
267 return form->form_init;
271 * Set the function to be called on form termination.
274 set_form_term(FORM *form, Form_Hook function)
276 if (form == NULL)
279 form->form_term = function;
288 form_term(FORM *form)
291 if (form == NULL)
294 return form->form_term;
299 * Attach the given fields to the form.
302 set_form_fields(FORM *form, FIELD **fields)
306 if (form == NULL)
309 if (form->posted == TRUE)
317 (fields[num_fields]->parent != form))
323 if (form->fields != NULL) {
324 for (i = 0; i < form->field_count; i++) {
325 form->fields[i]->parent = NULL;
326 form->fields[i]->index = -1;
331 if (form->page_starts != NULL)
332 free(form->page_starts);
334 form->field_count = num_fields;
336 /* now connect the new fields to the form */
338 fields[i]->parent = form;
346 form->fields = fields;
347 form->cur_field = 0;
348 form->max_page = maxpg;
349 if ((status = _formi_find_pages(form)) != E_OK)
353 _formi_sort_fields(form);
354 _formi_stitch_fields(form);
360 * Return the fields attached to the form given.
363 form_fields(FORM *form)
365 if (form == NULL)
368 return form->fields;
372 * Return the number of fields attached to the given form.
375 field_count(FORM *form)
377 if (form == NULL)
380 return form->field_count;
401 * Set the page of the form to the given page.
404 set_form_page(FORM *form, int page)
406 if (form == NULL)
409 if (form->in_init == TRUE)
412 if (page > form->max_page)
415 form->page = page;
420 * Return the maximum page of the form.
423 form_max_page(FORM *form)
425 if (form == NULL)
428 return form->max_page;
432 * Return the current page of the form.
435 form_page(FORM *form)
437 if (form == NULL)
440 return form->page;
447 set_current_field(FORM *form, FIELD *field)
449 if (form == NULL)
452 if (form->in_init == TRUE)
458 if ((field->parent == NULL) || (field->parent != form))
459 return E_INVALID_FIELD; /* field is not of this form */
461 form->cur_field = field->index;
468 * Return the current field of the given form.
471 current_field(FORM *form)
473 if (form == NULL)
476 if (form->fields == NULL)
479 return form->fields[form->cur_field];
483 * Allocate a new form with the given fields.
485 FORM *
488 FORM *new;
511 * Free the given form.
514 free_form(FORM *form)
518 if (form == NULL)
521 if (form->posted == TRUE)
524 for (i = 0; i < form->field_count; i++) {
525 /* detach all the fields from the form */
526 form->fields[i]->parent = NULL;
527 form->fields[i]->index = -1;
530 free(form);
536 * Tell if the current field of the form has offscreen data ahead
539 data_ahead(FORM *form)
543 if ((form == NULL) || (form->fields == NULL)
544 || (form->fields[0] == NULL))
547 cur = form->fields[form->cur_field];
557 * Tell if current field of the form has offscreen data behind
560 data_behind(FORM *form)
564 if ((form == NULL) || (form->fields == NULL)
565 || (form->fields[0] == NULL))
568 cur = form->fields[form->cur_field];
577 * Position the form cursor.
580 pos_form_cursor(FORM *form)
585 if ((form == NULL) || (form->fields == NULL) ||
586 (form->fields[0] == NULL))
589 if (form->posted != 1)
592 cur = form->fields[form->cur_field];
608 wmove(form->scrwin, row, col);