]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - form/frm_driver.c
ncurses 5.7 - patch 20090418
[ncurses.git] / form / frm_driver.c
index 2499f4da9218fd5e7957fc3fc77c2f5a4eef8816..e5db6cbca8ff98358aeafb15aa0e73284744a099 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2007,2008 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            *
@@ -32,7 +32,7 @@
 
 #include "form.priv.h"
 
-MODULE_ID("$Id: frm_driver.c,v 1.82 2007/06/02 22:59:24 tom Exp $")
+MODULE_ID("$Id: frm_driver.c,v 1.89 2008/12/06 23:08:12 tom Exp $")
 
 /*----------------------------------------------------------------------------
   This is the core module of the form library. It contains the majority
@@ -676,7 +676,7 @@ Field_Grown(FIELD *field, int amount)
              new_bp[new_buflen] = myZEROS;
            }
 
-#if USE_WIDEC_SUPPORT
+#if USE_WIDEC_SUPPORT && NCURSES_EXT_FUNCS
          if (wresize(field->working, 1, Buffer_Length(field) + 1) == ERR)
            result = FALSE;
 #endif
@@ -4176,7 +4176,7 @@ form_driver(FORM *form, int c)
        NULL                    /* Choice Request is generic           */
       };
       size_t nMethods = (sizeof(Generic_Methods) / sizeof(Generic_Methods[0]));
-      size_t method = ((BI->keycode & ID_Mask) >> ID_Shft) & 0xffff;
+      size_t method = (BI->keycode >> ID_Shft) & 0xffff;       /* see ID_Mask */
 
       if ((method >= nMethods) || !(BI->cmd))
        res = E_SYSTEM_ERROR;
@@ -4333,15 +4333,6 @@ set_field_buffer(FIELD *field, int buffer, const char *value)
 
   len = Buffer_Length(field);
 
-  if (buffer == 0)
-    {
-      for (i = 0; (value[i] != '\0') && (i < len); ++i)
-       {
-         if (iscntrl(UChar(value[i])))
-           RETURN(E_BAD_ARGUMENT);
-       }
-    }
-
   if (Growable(field))
     {
       /* for a growable field we must assume zero terminated strings, because
@@ -4356,14 +4347,6 @@ set_field_buffer(FIELD *field, int buffer, const char *value)
                                                     * field->cols))))
            RETURN(E_SYSTEM_ERROR);
 
-         /* in this case we also have to check, whether or not the remaining
-            characters in value are also printable for buffer 0. */
-         if (buffer == 0)
-           {
-             for (i = len; i < vlen; i++)
-               if (iscntrl(UChar(value[i])))
-                 RETURN(E_BAD_ARGUMENT);
-           }
          len = vlen;
        }
     }
@@ -4376,16 +4359,29 @@ set_field_buffer(FIELD *field, int buffer, const char *value)
    * There should be a better way, but this handles nonspacing characters
    * 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)
+#endif
+    {
+      delwin(field->working);
+      field->working = newpad(field->drows, field->dcols);
+    }
+  len = Buffer_Length(field);
   wclear(field->working);
   mvwaddstr(field->working, 0, 0, value);
 
-  if ((widevalue = (FIELD_CELL *)calloc(len + 1, sizeof(FIELD_CELL))) == 0)
+  if ((widevalue = typeCalloc(FIELD_CELL, len + 1)) == 0)
     {
       RETURN(E_SYSTEM_ERROR);
     }
   else
     {
-      mvwin_wchnstr(field->working, 0, 0, widevalue, (int)len);
+      for (i = 0; i < (unsigned)field->drows; ++i)
+       {
+         mvwin_wchnstr(field->working, i, 0,
+                       widevalue + (i * field->dcols),
+                       field->dcols);
+       }
       for (i = 0; i < len; ++i)
        {
          if (CharEq(myZEROS, widevalue[i]))
@@ -4459,10 +4455,7 @@ field_buffer(const FIELD *field, int buffer)
              init_mb(state);
              next = _nc_wcrtomb(0, data[n].chars[0], &state);
              if (!isEILSEQ(next))
-               {
-                 if (next != 0)
-                   need += next;
-               }
+               need += next;
            }
        }
 
@@ -4476,7 +4469,7 @@ field_buffer(const FIELD *field, int buffer)
        {
          wclear(field->working);
          mvwadd_wchnstr(field->working, 0, 0, data, size);
-         mvwinnstr(field->working, 0, 0, result, (int)need + 1);
+         mvwinnstr(field->working, 0, 0, result, (int)need);
        }
 #else
       result = Address_Of_Nth_Buffer(field, buffer);