#include "form.priv.h"
-MODULE_ID("$Id: frm_driver.c,v 1.93 2009/10/24 23:23:32 tom Exp $")
+MODULE_ID("$Id: frm_driver.c,v 1.96 2009/12/12 23:19:29 tom Exp $")
/*----------------------------------------------------------------------------
This is the core module of the form library. It contains the majority
/*---------------------------------------------------------------------------
| Facility : libnform
-| Function : static void Window_To_Buffer(
+| Function : void _nc_get_fieldbuffer(
| WINDOW * win,
-| FIELD * field)
+| FIELD * field,
+| FIELD_CELL * buf)
|
| Description : Copy the content of the window into the buffer.
| The multiple lines of a window are simply
|
| Return Values : -
+--------------------------------------------------------------------------*/
-static void
-Window_To_Buffer(WINDOW *win, FIELD *field)
+NCURSES_EXPORT(void)
+_nc_get_fieldbuffer(FORM *form, FIELD *field, FIELD_CELL *buf)
{
int pad;
int len = 0;
FIELD_CELL *p;
int row, height;
+ WINDOW *win;
+
+ assert(form && field && buf);
- assert(win && field && field->buf);
+ win = form->w;
+ assert(win);
pad = field->pad;
- p = field->buf;
+ p = buf;
height = getmaxy(win);
for (row = 0; (row < height) && (row < field->drows); row++)
}
}
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static void Window_To_Buffer(
+| FORM * form,
+| FIELD * field)
+|
+| Description : Copy the content of the window into the buffer.
+| The multiple lines of a window are simply
+| concatenated into the buffer. Pad characters in
+| the window will be replaced by blanks in the buffer.
+|
+| Return Values : -
++--------------------------------------------------------------------------*/
+static void
+Window_To_Buffer(FORM *form, FIELD *field)
+{
+ _nc_get_fieldbuffer(form, field, field->buf);
+}
+
/*---------------------------------------------------------------------------
| Facility : libnform
| Function : static void Synchronize_Buffer(FORM * form)
{
form->status &= ~_WINDOW_MODIFIED;
form->status |= _FCHECK_REQUIRED;
- Window_To_Buffer(form->w, form->current);
+ Window_To_Buffer(form, form->current);
wmove(form->w, form->currow, form->curcol);
}
}
/*---------------------------------------------------------------------------
| Facility : libnform
-| Function : static bool Check_Char(
+| Function : static bool Check_Char(FORM *form,
+| FIELD *field,
| FIELDTYPE * typ,
| int ch,
| TypeArgument *argp)
| FALSE - Character is invalid
+--------------------------------------------------------------------------*/
static bool
-Check_Char(FIELDTYPE *typ, int ch, TypeArgument *argp)
+Check_Char(FORM *form,
+ FIELD *field,
+ FIELDTYPE *typ,
+ int ch,
+ TypeArgument *argp)
{
if (typ)
{
{
assert(argp);
return (
- Check_Char(typ->left, ch, argp->left) ||
- Check_Char(typ->right, ch, argp->right));
+ Check_Char(form, field, typ->left, ch, argp->left) ||
+ Check_Char(form, field, typ->right, ch, argp->right));
}
else
{
+#if NCURSES_INTEROP_FUNCS
+ if (typ->charcheck.occheck)
+ {
+ if (typ->status & _GENERIC)
+ return typ->charcheck.gccheck(ch, form, field, (void *)argp);
+ else
+ return typ->charcheck.occheck(ch, (void *)argp);
+ }
+#else
if (typ->ccheck)
return typ->ccheck(ch, (void *)argp);
+#endif
}
}
return (!iscntrl(UChar(ch)) ? TRUE : FALSE);
if (form)
{
- if (form->current == field)
- {
- field->opts = oldopts;
- returnCode(E_CURRENT);
- }
-
if (form->status & _POSTED)
{
+ if (form->current == field)
+ {
+ field->opts = oldopts;
+ returnCode(E_CURRENT);
+ }
if ((form->curpage == field->page))
{
if (changed_opts & O_VISIBLE)
{
if (Justification_Allowed(field))
{
- Window_To_Buffer(form->w, field);
+ Window_To_Buffer(form, field);
werase(form->w);
Perform_Justification(field, form->w);
wsyncup(form->w);
return E_SYSTEM_ERROR;
}
bp = Address_Of_Current_Row_In_Buffer(form);
- Window_To_Buffer(form->w, field);
+ Window_To_Buffer(form, field);
split = After_Last_Whitespace_Character(bp, field->dcols);
/* split points to the first character of the sequence to be brought
on the next line */
if (result != E_OK)
{
DeleteChar(form);
- Window_To_Buffer(form->w, field);
+ Window_To_Buffer(form, field);
result = E_REQUEST_DENIED;
}
}
int result = E_REQUEST_DENIED;
T((T_CALLED("FE_Insert_Character(%p)"), (void *)form));
- if (Check_Char(field->type, (int)C_BLANK, (TypeArgument *)(field->arg)))
+ if (Check_Char(form, field, field->type, (int)C_BLANK,
+ (TypeArgument *)(field->arg)))
{
bool There_Is_Room = Is_There_Room_For_A_Char_In_Line(form);
int result = E_REQUEST_DENIED;
T((T_CALLED("FE_Insert_Line(%p)"), (void *)form));
- if (Check_Char(field->type, (int)C_BLANK, (TypeArgument *)(field->arg)))
+ if (Check_Char(form, field,
+ field->type, (int)C_BLANK, (TypeArgument *)(field->arg)))
{
bool Maybe_Done = (form->currow != (field->drows - 1)) &&
Is_There_Room_For_A_Line(form);
/*---------------------------------------------------------------------------
| Facility : libnform
-| Function : static bool Next_Choice(
+| Function : static bool Next_Choice(FORM * form,
| FIELDTYPE * typ,
| FIELD * field,
| TypeArgument *argp)
| FALSE - couldn't retrieve next choice
+--------------------------------------------------------------------------*/
static bool
-Next_Choice(FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
+Next_Choice(FORM *form, FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
{
if (!typ || !(typ->status & _HAS_CHOICE))
return FALSE;
{
assert(argp);
return (
- Next_Choice(typ->left, field, argp->left) ||
- Next_Choice(typ->right, field, argp->right));
+ Next_Choice(form, typ->left, field, argp->left) ||
+ Next_Choice(form, typ->right, field, argp->right));
}
else
{
+#if NCURSES_INTEROP_FUNCS
+ assert(typ->enum_next.onext);
+ if (typ->status & _GENERIC)
+ return typ->enum_next.gnext(form, field, (void *)argp);
+ else
+ return typ->enum_next.onext(field, (void *)argp);
+#else
assert(typ->next);
return typ->next(field, (void *)argp);
+#endif
}
}
/*---------------------------------------------------------------------------
| Facility : libnform
-| Function : static bool Previous_Choice(
+| Function : static bool Previous_Choice(FORM * form,
| FIELDTYPE * typ,
| FIELD * field,
| TypeArgument *argp)
| FALSE - couldn't retrieve previous choice
+--------------------------------------------------------------------------*/
static bool
-Previous_Choice(FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
+Previous_Choice(FORM *form, FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
{
if (!typ || !(typ->status & _HAS_CHOICE))
return FALSE;
{
assert(argp);
return (
- Previous_Choice(typ->left, field, argp->left) ||
- Previous_Choice(typ->right, field, argp->right));
+ Previous_Choice(form, typ->left, field, argp->left) ||
+ Previous_Choice(form, typ->right, field, argp->right));
}
else
{
+#if NCURSES_INTEROP_FUNCS
+ assert(typ->enum_prev.oprev);
+ if (typ->status & _GENERIC)
+ return typ->enum_prev.gprev(form, field, (void *)argp);
+ else
+ return typ->enum_prev.oprev(field, (void *)argp);
+#else
assert(typ->prev);
return typ->prev(field, (void *)argp);
+#endif
}
}
/*----------------------------------------------------------------------------
T((T_CALLED("CR_Next_Choice(%p)"), (void *)form));
Synchronize_Buffer(form);
- returnCode((Next_Choice(field->type, field, (TypeArgument *)(field->arg)))
+ returnCode((Next_Choice(form, field->type, field, (TypeArgument *)(field->arg)))
? E_OK
: E_REQUEST_DENIED);
}
T((T_CALLED("CR_Previous_Choice(%p)"), (void *)form));
Synchronize_Buffer(form);
- returnCode((Previous_Choice(field->type, field, (TypeArgument *)(field->arg)))
+ returnCode((Previous_Choice(form, field->type, field, (TypeArgument *)(field->arg)))
? E_OK
: E_REQUEST_DENIED);
}
/*---------------------------------------------------------------------------
| Facility : libnform
-| Function : static bool Check_Field(
+| Function : static bool Check_Field(FORM* form,
| FIELDTYPE * typ,
| FIELD * field,
| TypeArgument * argp)
| FALSE - field is invalid.
+--------------------------------------------------------------------------*/
static bool
-Check_Field(FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
+Check_Field(FORM *form, FIELDTYPE *typ, FIELD *field, TypeArgument *argp)
{
if (typ)
{
{
assert(argp);
return (
- Check_Field(typ->left, field, argp->left) ||
- Check_Field(typ->right, field, argp->right));
+ Check_Field(form, typ->left, field, argp->left) ||
+ Check_Field(form, typ->right, field, argp->right));
}
else
{
+#if NCURSES_INTEROP_FUNCS
+ if (typ->fieldcheck.ofcheck)
+ {
+ if (typ->status & _GENERIC)
+ return typ->fieldcheck.gfcheck(form, field, (void *)argp);
+ else
+ return typ->fieldcheck.ofcheck(field, (void *)argp);
+ }
+#else
if (typ->fcheck)
return typ->fcheck(field, (void *)argp);
+#endif
}
}
return TRUE;
if ((form->status & _FCHECK_REQUIRED) ||
(!(field->opts & O_PASSOK)))
{
- if (!Check_Field(field->type, field, (TypeArgument *)(field->arg)))
+ if (!Check_Field(form, field->type, field, (TypeArgument *)(field->arg)))
return FALSE;
form->status &= ~_FCHECK_REQUIRED;
field->status |= _CHANGED;
else if (KEY_MOUSE == c)
{
MEVENT event;
- WINDOW *win = form->win ? form->win : stdscr;
+ WINDOW *win = form->win ? form->win : StdScreen(Get_Form_Screen(form));
WINDOW *sub = form->sub ? form->sub : win;
getmouse(&event);
if (!iscntrl(UChar(c)))
#else
if (isprint(UChar(c)) &&
- Check_Char(form->current->type, c,
+ Check_Char(form, form->current, form->current->type, c,
(TypeArgument *)(form->current->arg)))
#endif
res = Data_Entry(form, c);
* and other special cases that we really do not want to handle here.
*/
#if NCURSES_EXT_FUNCS
- if (wresize(field->working, field->drows, field->dcols) == ERR)
+ if (wresize(field->working, 1, Buffer_Length(field) + 1) == ERR)
#endif
{
delwin(field->working);
- field->working = newpad(field->drows, field->dcols);
+ field->working = newpad(1, Buffer_Length(field) + 1);
}
len = Buffer_Length(field);
wclear(field->working);
{
for (i = 0; i < (unsigned)field->drows; ++i)
{
- mvwin_wchnstr(field->working, i, 0,
+ mvwin_wchnstr(field->working, 0, i * field->dcols,
widevalue + (i * field->dcols),
field->dcols);
}
/* determine the number of bytes needed to store the expanded string */
for (n = 0; n < size; ++n)
{
- if (!isWidecExt(data[n]))
+ if (!isWidecExt(data[n]) && data[n].chars[0] != L'\0')
{
mbstate_t state;
size_t next;
free(field->expanded[buffer]);
field->expanded[buffer] = typeMalloc(char, need + 1);
- /* expand the multibyte data */
+ /*
+ * Expand the multibyte data.
+ *
+ * It may also be multi-column data. In that case, the data for a row
+ * may be null-padded to align to the dcols/drows layout (or it may
+ * contain embedded wide-character extensions). Change the null-padding
+ * to blanks as needed.
+ */
if ((result = field->expanded[buffer]) != 0)
{
wclear(field->working);
- mvwadd_wchnstr(field->working, 0, 0, data, size);
- mvwinnstr(field->working, 0, 0, result, (int)need);
+ wmove(field->working, 0, 0);
+ for (n = 0; n < size; ++n)
+ {
+ if (!isWidecExt(data[n]) && data[n].chars[0] != L'\0')
+ wadd_wch(field->working, &data[n]);
+ }
+ wmove(field->working, 0, 0);
+ winnstr(field->working, result, (int)need);
}
#else
result = Address_Of_Nth_Buffer(field, buffer);