ncurses 5.9 - patch 20111224
[ncurses.git] / form / frm_driver.c
index e919163edecb9a04e127893d77be961d6abeb467..f335ed2611c2a7ce8578d37ecc80dfbca1190a0c 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2011 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.94 2009/11/07 19:54:03 tom Exp $")
+MODULE_ID("$Id: frm_driver.c,v 1.99 2011/09/17 22:12:10 tom Exp $")
 
 /*----------------------------------------------------------------------------
   This is the core module of the form library. It contains the majority
@@ -1326,7 +1326,7 @@ _nc_Synchronize_Options(FIELD *field, Field_Options newopts)
              field->opts = oldopts;
              returnCode(E_CURRENT);
            }
-         if ((form->curpage == field->page))
+         if (form->curpage == field->page)
            {
              if (changed_opts & O_VISIBLE)
                {
@@ -4417,7 +4417,9 @@ set_field_buffer(FIELD *field, int buffer, const char *value)
                                                     * field->cols))))
            RETURN(E_SYSTEM_ERROR);
 
+#if !USE_WIDEC_SUPPORT
          len = vlen;
+#endif
        }
     }
 
@@ -4430,15 +4432,15 @@ set_field_buffer(FIELD *field, int buffer, const char *value)
    * 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);
-  mvwaddstr(field->working, 0, 0, value);
+  (void)mvwaddstr(field->working, 0, 0, value);
 
   if ((widevalue = typeCalloc(FIELD_CELL, len + 1)) == 0)
     {
@@ -4448,9 +4450,9 @@ set_field_buffer(FIELD *field, int buffer, const char *value)
     {
       for (i = 0; i < (unsigned)field->drows; ++i)
        {
-         mvwin_wchnstr(field->working, i, 0,
-                       widevalue + (i * field->dcols),
-                       field->dcols);
+         (void)mvwin_wchnstr(field->working, 0, i * field->dcols,
+                             widevalue + (i * field->dcols),
+                             field->dcols);
        }
       for (i = 0; i < len; ++i)
        {
@@ -4517,7 +4519,7 @@ field_buffer(const FIELD *field, int buffer)
       /* 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;
@@ -4534,12 +4536,25 @@ field_buffer(const FIELD *field, int buffer)
        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);