From: sopwith Date: Fri, 15 Aug 1997 04:36:26 +0000 (+0000) Subject: Listbox changes, newtBell() X-Git-Tag: r0-12~48 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=69bf2308fe421cb2f2857df7febe0f403ade6357;p=thirdparty%2Fnewt.git Listbox changes, newtBell() --- diff --git a/listbox.c b/listbox.c index 23258d9..a116307 100644 --- 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 ab0c360..ee94865 100644 --- 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 d0dc528..8136b24 100644 --- 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);