]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
Listbox changes, newtBell()
authorsopwith <sopwith>
Fri, 15 Aug 1997 04:36:26 +0000 (04:36 +0000)
committersopwith <sopwith>
Fri, 15 Aug 1997 04:36:26 +0000 (04:36 +0000)
listbox.c
newt.c
newt.h

index 23258d928f15648a7e33c6324b4b03dbeca01d92..a116307be68b3da412c2f12c15e383b97e95edf6 100644 (file)
--- a/listbox.c
+++ b/listbox.c
@@ -146,7 +146,8 @@ void * newtListboxGetCurrent(newtComponent co) {
        return NULL;
 }
 
-void newtListboxSelectItem(newtComponent co, int item)
+void newtListboxSelectItem(newtComponent co, int item,
+       enum newtFlagsSense sense)
 {
     struct listbox * li = co->data;
     int i;
@@ -156,11 +157,18 @@ void newtListboxSelectItem(newtComponent co, int item)
        i++, iitem = iitem->next);
 
     if (iitem) {
-       if(iitem->isSelected)
+       if(iitem->isSelected && sense != NEWT_FLAGS_SET)
            li->numSelected--;
-       else
+       else if(!iitem->isSelected && sense != NEWT_FLAGS_RESET)
            li->numSelected++;
-       iitem->isSelected = !iitem->isSelected;
+       switch(sense) {
+               case NEWT_FLAGS_RESET:
+                       iitem->isSelected = 0; break;
+               case NEWT_FLAGS_SET:
+                       iitem->isSelected = 1; break;
+               case NEWT_FLAGS_TOGGLE:
+                       iitem->isSelected = !iitem->isSelected;
+       }
     }
     listboxDraw(co);
 }
@@ -173,7 +181,7 @@ void newtListboxClearSelection(newtComponent co)
     for(item = li->boxItems; item != NULL;
        item = item->next)
        item->isSelected = 0;
-    
+    li->numSelected = 0;
     listboxDraw(co);
 }
 
@@ -214,7 +222,7 @@ void newtListboxSetText(newtComponent co, int num, char * text) {
        item->key = strdup(text);
     }
     if (li->userHasSetWidth == 0
-       && strlen(text) > li->curWidth) {
+       && strlen(text) > (size_t)li->curWidth) {
        co->width = li->curWidth = strlen(text);
        if (li->sb)
            li->sb->left = co->left + co->width + 2;
@@ -252,7 +260,7 @@ int newtListboxAddEntry(newtComponent co, char * text, void * data) {
     }
 
     if (li->userHasSetWidth == 0
-       && text && (strlen(text) > li->curWidth))
+       && text && (strlen(text) > (size_t)li->curWidth))
        li->curWidth = strlen(text) ;
 
     item->key = strdup(text); item->data = data; item->next = NULL;
@@ -299,7 +307,7 @@ int newtListboxInsertEntry(newtComponent co, char * text, void * data,
     }
 
     if (li->userHasSetWidth == 0
-       && text && (strlen(text) > li->curWidth))
+       && text && (strlen(text) > (size_t)li->curWidth))
        li->curWidth = strlen(text);
 
     item->key = strdup(text?text:"(null)"); item->data = data;
@@ -474,7 +482,25 @@ static struct eventResult listboxEvent(newtComponent co, struct event ev) {
        switch(ev.u.key) {
          case ' ':
            if(!(li->flags & NEWT_FLAG_MULTIPLE)) break;
-           newtListboxSelectItem(co, li->currItem);
+           newtListboxSelectItem(co, li->currItem, NEWT_FLAGS_TOGGLE);
+           er.result = ER_SWALLOWED;
+           /* We don't break here, because it is cool to be able to
+              hold space to select a bunch of items in a list at once */
+
+         case NEWT_KEY_DOWN:
+           if(li->numItems <= 0) break;
+           if(li->currItem < li->numItems - 1) {
+               li->currItem++;
+               if(li->currItem > (li->startShowItem + co->height - 1)) {
+                   li->startShowItem = li->currItem - co->height + 1;
+                   if(li->startShowItem + co->height > li->numItems)
+                       li->startShowItem = li->numItems - co->height;
+               }
+               if(li->sb)
+                   newtScrollbarSet(li->sb, li->currItem + 1, li->numItems);
+               listboxDraw(co);
+           }
+           if(co->callback) co->callback(co, co->callbackData);
            er.result = ER_SWALLOWED;
            break;
 
@@ -498,23 +524,6 @@ static struct eventResult listboxEvent(newtComponent co, struct event ev) {
            er.result = ER_SWALLOWED;
            break;
 
-         case NEWT_KEY_DOWN:
-           if(li->numItems <= 0) break;
-           if(li->currItem < li->numItems - 1) {
-               li->currItem++;
-               if(li->currItem > (li->startShowItem + co->height - 1)) {
-                   li->startShowItem = li->currItem - co->height + 1;
-                   if(li->startShowItem + co->height > li->numItems)
-                       li->startShowItem = li->numItems - co->height;
-               }
-               if(li->sb)
-                   newtScrollbarSet(li->sb, li->currItem + 1, li->numItems);
-               listboxDraw(co);
-           }
-           if(co->callback) co->callback(co, co->callbackData);
-           er.result = ER_SWALLOWED;
-           break;
-
          case NEWT_KEY_PGUP:
            if(li->numItems <= 0) break;
            li->startShowItem -= co->height - 1;
diff --git a/newt.c b/newt.c
index ab0c360cc5a546135fbb2679593798728afa90ae..ee948650d17d853059e8f616dcf89d7113e38f93 100644 (file)
--- a/newt.c
+++ b/newt.c
@@ -566,7 +566,15 @@ int newtSetFlags(int oldFlags, int newFlags, enum newtFlagsSense sense) {
       case NEWT_FLAGS_RESET:
        return oldFlags & (~newFlags); 
 
+      case NEWT_FLAGS_TOGGLE:
+       return oldFlags ^ newFlags;
+
       default:
        return oldFlags;
     }
 }
+
+void newtBell(void)
+{
+       SLtt_beep();
+}
diff --git a/newt.h b/newt.h
index d0dc528e6a256268ac1770ded2f1e479144da7d5..8136b24b33deefa0b202a01316936da155029061 100644 (file)
--- a/newt.h
+++ b/newt.h
@@ -54,7 +54,7 @@ struct newtColors {
     char * selListboxFg, * selListboxBg;
 };
 
-enum newtFlagsSense { NEWT_FLAGS_SET, NEWT_FLAGS_RESET };
+enum newtFlagsSense { NEWT_FLAGS_SET, NEWT_FLAGS_RESET, NEWT_FLAGS_TOGGLE };
 
 #define NEWT_FLAG_RETURNEXIT   (1 << 0)
 #define NEWT_FLAG_HIDDEN       (1 << 1)
@@ -65,6 +65,7 @@ enum newtFlagsSense { NEWT_FLAGS_SET, NEWT_FLAGS_RESET };
 #define NEWT_FLAG_WRAP         (1 << 6)
 #define NEWT_FLAG_NOF12                (1 << 7)
 #define NEWT_FLAG_MULTIPLE      (1 << 8)
+#define NEWT_FLAG_SELECTED     (1 << 9)
 
 /* Backwards compatibility */
 #define NEWT_LISTBOX_RETURNEXIT NEWT_FLAG_RETURNEXIT
@@ -103,6 +104,7 @@ void newtPushHelpLine(char * text);
 void newtRedrawHelpLine(void);
 void newtPopHelpLine(void);
 void newtDrawRootText(int row, int col, char * text);
+void newtBell(void);
 
 /* Components */
 
@@ -139,6 +141,9 @@ void newtListboxClear(newtComponent co); /* removes all entries from listbox */
 void newtListboxGetEntry(newtComponent co, int num, char **text, void **data);
 void **newtListboxGetSelection(newtComponent co);
 void newtListboxClearSelection(newtComponent co);
+void newtListboxSelectItem(newtComponent co, int item,
+       enum newtFlagsSense sense);
+
     
 newtComponent newtTextbox(int left, int top, int with, int height, int flags);
 void newtTextboxSetText(newtComponent co, const char * text);