/****************************************************************************
- * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
#include "form.priv.h"
-MODULE_ID("$Id: frm_driver.c,v 1.114 2014/07/26 20:46:51 tom Exp $")
+MODULE_ID("$Id: frm_driver.c,v 1.123 2017/09/09 22:35:49 tom Exp $")
/*----------------------------------------------------------------------------
This is the core module of the form library. It contains the majority
#define GROW_IF_NAVIGATE (1)
#if USE_WIDEC_SUPPORT
-#define myADDNSTR(w, s, n) wadd_wchnstr(w, s, n)
-#define myINSNSTR(w, s, n) wins_wchnstr(w, s, n)
-#define myINNSTR(w, s, n) fix_wchnstr(w, s, n)
+#define myADDNSTR(w, s, n) wide_waddnstr(w, s, n)
+#define myINSNSTR(w, s, n) wide_winsnstr(w, s, n)
+#define myINNSTR(w, s, n) wide_winnstr(w, s, n)
#define myWCWIDTH(w, y, x) cell_width(w, y, x)
#else
#define myADDNSTR(w, s, n) waddnstr(w, s, n)
Wide-character special functions
--------------------------------------------------------------------------*/
#if USE_WIDEC_SUPPORT
-/* like winsnstr */
+/* add like waddnstr, but using cchar_t* rather than char*
+ */
static int
-wins_wchnstr(WINDOW *w, cchar_t *s, int n)
+wide_waddnstr(WINDOW *w, const cchar_t *s, int n)
+{
+ int rc = OK;
+
+ while (n-- > 0)
+ {
+ if ((rc = wadd_wch(w, s)) != OK)
+ break;
+ ++s;
+ }
+ return rc;
+}
+
+/* insert like winsnstr, but using cchar_t* rather than char*
+ *
+ * X/Open Curses has no close equivalent; inserts are done only with wchar_t
+ * strings.
+ */
+static int
+wide_winsnstr(WINDOW *w, const cchar_t *s, int n)
{
int code = ERR;
int y, x;
return code;
}
-/* win_wchnstr is inconsistent with winnstr, since it returns OK rather than
- * the number of items transferred.
+/* retrieve like winnstr, but using cchar_t*, rather than char*.
+ *
+ * X/Open Curses' closest equivalent, win_wchnstr(), is inconsistent with
+ * winnstr(), since it returns OK rather than the number of items transferred.
*/
static int
-fix_wchnstr(WINDOW *w, cchar_t *s, int n)
+wide_winnstr(WINDOW *w, cchar_t *s, int n)
{
int x;
int len;
int col = 0;
- bp = Get_Start_Of_Data(field->buf, Buffer_Length(field));
+ bp = (Field_Has_Option(field, O_NO_LEFT_STRIP)
+ ? field->buf
+ : Get_Start_Of_Data(field->buf, Buffer_Length(field)));
len = (int)(After_End_Of_Data(field->buf, Buffer_Length(field)) - bp);
if (len > 0)
Undo_Justification(FIELD *field, WINDOW *win)
{
FIELD_CELL *bp;
+ int y, x;
int len;
- bp = Get_Start_Of_Data(field->buf, Buffer_Length(field));
+ getyx(win, y, x);
+
+ bp = (Field_Has_Option(field, O_NO_LEFT_STRIP)
+ ? field->buf
+ : Get_Start_Of_Data(field->buf, Buffer_Length(field)));
len = (int)(After_End_Of_Data(field->buf, Buffer_Length(field)) - bp);
if (len > 0)
wmove(win, 0, 0);
myADDNSTR(win, bp, len);
}
+ wmove(win, y, x);
}
/*---------------------------------------------------------------------------
copywin(form->w, formwin,
0, 0,
field->frow, field->fcol,
- field->rows - 1, field->cols - 1, 0);
+ field->frow + field->rows - 1,
+ field->fcol + field->cols - 1, 0);
wsyncup(formwin);
Buffer_To_Window(field, form->w);
SetStatus(field, _NEWTOP); /* fake refresh to paint all */
returnCode(res);
}
+/*
+ * Removes the focus from the current field of the form.
+ */
+void
+_nc_Unset_Current_Field(FORM *form)
+{
+ FIELD *field = form->current;
+
+ _nc_Refresh_Current_Field(form);
+ if (Field_Has_Option(field, O_PUBLIC))
+ {
+ if (field->drows > field->rows)
+ {
+ if (form->toprow == 0)
+ ClrStatus(field, _NEWTOP);
+ else
+ SetStatus(field, _NEWTOP);
+ }
+ else
+ {
+ if (Justification_Allowed(field))
+ {
+ Window_To_Buffer(form, field);
+ werase(form->w);
+ Perform_Justification(field, form->w);
+ if (Field_Has_Option(field, O_DYNAMIC_JUSTIFY) &&
+ (form->w->_parent == 0))
+ {
+ copywin(form->w,
+ Get_Form_Window(form),
+ 0,
+ 0,
+ field->frow,
+ field->fcol,
+ field->frow,
+ field->cols + field->fcol - 1,
+ 0);
+ wsyncup(Get_Form_Window(form));
+ }
+ else
+ {
+ wsyncup(form->w);
+ }
+ }
+ }
+ }
+ delwin(form->w);
+ form->w = (WINDOW *)0;
+ form->current = 0;
+}
+
/*---------------------------------------------------------------------------
| Facility : libnform
| Function : int _nc_Set_Current_Field(FORM * form,
T((T_CALLED("_nc_Set_Current_Field(%p,%p)"), (void *)form, (void *)newfield));
- if (!form || !newfield || !form->current || (newfield->form != form))
+ if (!form || !newfield || (newfield->form != form))
returnCode(E_BAD_ARGUMENT);
if ((form->status & _IN_DRIVER))
if ((field != newfield) ||
!(form->status & _POSTED))
{
- if ((form->w) &&
+ if (field && (form->w) &&
(Field_Has_Option(field, O_VISIBLE)) &&
(field->form->curpage == field->page))
- {
- _nc_Refresh_Current_Field(form);
- if (Field_Has_Option(field, O_PUBLIC))
- {
- if (field->drows > field->rows)
- {
- if (form->toprow == 0)
- ClrStatus(field, _NEWTOP);
- else
- SetStatus(field, _NEWTOP);
- }
- else
- {
- if (Justification_Allowed(field))
- {
- Window_To_Buffer(form, field);
- werase(form->w);
- Perform_Justification(field, form->w);
- if (Field_Has_Option(field, O_DYNAMIC_JUSTIFY) &&
- (form->w->_parent == 0))
- {
- copywin(form->w,
- Get_Form_Window(form),
- 0,
- 0,
- field->frow,
- field->fcol,
- field->frow,
- field->cols + field->fcol - 1,
- 0);
- wsyncup(Get_Form_Window(form));
- }
- else
- {
- wsyncup(form->w);
- }
- }
- }
- }
- delwin(form->w);
- form->w = (WINDOW *)0;
- }
+ _nc_Unset_Current_Field(form);
field = newfield;
cchar_t temp_ch;
given[0] = c;
- given[1] = 1;
+ given[1] = 0;
setcchar(&temp_ch, given, 0, 0, (void *)0);
if ((Field_Has_Option(field, O_BLANK)) &&
First_Position_In_Current_Field(form) &&
{
if (pass)
{
- result[need] = source[passed];
+ result[need] = (wchar_t)source[passed];
}
++need;
++passed;