]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
- fix counting of items in checkboxtree
authormlichvar <mlichvar>
Thu, 12 Apr 2007 16:57:33 +0000 (16:57 +0000)
committermlichvar <mlichvar>
Thu, 12 Apr 2007 16:57:33 +0000 (16:57 +0000)
checkboxtree.c
newt.spec

index 05f11e52fbeabb1b5c332712a8a16c3a56e32e70..290a2e575633d037ef81cacd5b6b09dcec9ea342 100644 (file)
@@ -38,8 +38,7 @@ static void ctMapped(newtComponent co, int isMapped);
 static struct items * findItem(struct items * items, const void * data);
 static void buildFlatList(newtComponent co);
 static void doBuildFlatList(struct CheckboxTree * ct, struct items * item);
-enum countWhat { COUNT_EXPOSED=0, COUNT_SELECTED=1 };
-static int countItems(struct items * item, enum countWhat justExposed);
+static int countItems(struct items * item, int what);
 static inline void updateWidth(newtComponent co, struct CheckboxTree * ct,
                                int maxField);
 
@@ -60,13 +59,14 @@ static inline void updateWidth(newtComponent co, struct CheckboxTree * ct,
        ct->sb->left = co->left + co->width - 1;
 }
 
-static int countItems(struct items * item, enum countWhat what) {
+static int countItems(struct items * item, int what) {
     int count = 0;
 
     while (item) {
-        if ((!item->branch && item->selected == what) || (what == COUNT_EXPOSED))
+       if (what < 0 || !item->branch && (what > 0 && item->selected == what
+                   || what == 0 && item->selected))
            count++;
-       if (item->branch || (what == COUNT_EXPOSED && item->selected))
+       if (item->branch && (what >= 0 || what < 0 && item->selected))
            count += countItems(item->branch, what);
        item = item->next;
     }
@@ -88,7 +88,7 @@ static void buildFlatList(newtComponent co) {
     struct CheckboxTree * ct = co->data;
 
     if (ct->flatList) free(ct->flatList);
-    ct->flatCount = countItems(ct->itemlist, COUNT_EXPOSED);
+    ct->flatCount = countItems(ct->itemlist, -1);
 
     ct->flatList = malloc(sizeof(*ct->flatList) * (ct->flatCount+1));
     ct->flatCount = 0;
@@ -273,7 +273,7 @@ static struct items * findItem(struct items * items, const void * data) {
 
 static void listSelected(struct items * items, int * num, const void ** list, int seqindex) {
     while (items) {
-           if ((seqindex ? items->selected==seqindex : items->selected) && !items->branch)
+       if ((seqindex ? items->selected==seqindex : items->selected) && !items->branch)
            list[(*num)++] = (void *) items->data;
        if (items->branch)
            listSelected(items->branch, num, list, seqindex);
@@ -312,7 +312,7 @@ const void ** newtCheckboxTreeGetMultiSelection(newtComponent co, int *numitems,
            seqindex = 0;
     }
 
-    *numitems = countItems(ct->itemlist, (seqindex ? seqindex : COUNT_SELECTED));
+    *numitems = countItems(ct->itemlist, seqindex);
     if (!*numitems) return NULL;
     
     retval = malloc(*numitems * sizeof(void *));
index 341ca94394aca3348ed4379d3396f2ce825b7248..c05ac6b700ff35dd45a6a1be2257d5a8c4bfa5ff 100644 (file)
--- a/newt.spec
+++ b/newt.spec
@@ -89,6 +89,7 @@ rm -rf $RPM_BUILD_ROOT
 
 %changelog
 - fix cursor positioning when setting entry or checkbox flags
+- fix counting of items in checkboxtree
 - fix entry scrolling (#234829)
 - fix multibyte character handling in entry