]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
allow minimal textbox width 1
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 23 Sep 2009 14:06:54 +0000 (16:06 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 23 Sep 2009 14:06:54 +0000 (16:06 +0200)
textbox.c

index f6f89d9b0457313ff3ee4967e248a8540597e831..6429062f1fa39c5a7c75a3ab1ac7dc43b3657396 100644 (file)
--- a/textbox.c
+++ b/textbox.c
@@ -95,7 +95,8 @@ newtComponent newtTextbox(int left, int top, int width, int height, int flags) {
     tb = malloc(sizeof(*tb));
     co->data = tb;
 
-    if (width < 2) width = 2;
+    if (width < 1)
+       width = 1;
 
     co->ops = &textboxOps;
 
@@ -174,8 +175,12 @@ static void doReflow(const char * text, char ** resultPtr, int width,
     mbstate_t ps;
 
     if (resultPtr) {
-       /* use width - 1 for double width characters that won't fit at end of line */
-       result = malloc(strlen(text) + (strlen(text) / (width - 1)) + 2);
+       if (width > 1) {
+           /* use width - 1 for double width characters
+              that won't fit at end of line */
+           result = malloc(strlen(text) + (strlen(text) / (width - 1)) + 2);
+       } else
+           result = malloc(strlen(text) * 2 + 2);
        *result = '\0';
     }
        
@@ -266,6 +271,9 @@ char * newtReflowText(char * text, int width, int flexDown, int flexUp,
     int minbad, minbadwidth, howbad;
     char * expandedText;
 
+    if (width < 1)
+       width = 1;
+
     expandedText = expandTabs(text);
 
     if (flexDown || flexUp) {
@@ -275,7 +283,7 @@ char * newtReflowText(char * text, int width, int flexDown, int flexUp,
        minbad = -1;
        minbadwidth = width;
 
-       for (i = min; i <= max; i++) {
+       for (i = min; i >= 1 && i <= max; i++) {
            doReflow(expandedText, NULL, i, &howbad, NULL);
 
            if (minbad == -1 || howbad < minbad) {