From: mlichvar Date: Fri, 15 Sep 2006 13:31:56 +0000 (+0000) Subject: - make textbox with scrollbar focusable (#83203) X-Git-Tag: r0-52-3~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9fc6a6b0e060b1dbd25593a557336daf06d51aac;p=thirdparty%2Fnewt.git - make textbox with scrollbar focusable (#83203) - handle listbox and checkboxtree focus better (#186053) - unfocus when displaying help --- diff --git a/checkboxtree.c b/checkboxtree.c index 6ce9695..bfdde5f 100644 --- a/checkboxtree.c +++ b/checkboxtree.c @@ -25,6 +25,7 @@ struct CheckboxTree { int sbAdjust; int curWidth; int userHasSetWidth; + int isActive; char * seq; char * result; }; @@ -341,6 +342,7 @@ newtComponent newtCheckboxTreeMulti(int left, int top, int height, char *seq, in co->width = 0; co->isMapped = 0; ct->curWidth = 0; + ct->isActive = 0; ct->userHasSetWidth = 0; ct->itemlist = NULL; ct->firstItem = NULL; @@ -462,12 +464,7 @@ static void ctDraw(newtComponent co) { while (*item && i < co->height) { newtGotorc(co->top + i, co->left); - if (*item == *ct->currItem) { - SLsmg_set_color(NEWT_COLORSET_ACTLISTBOX); - currRow = co->top + i; - } else - SLsmg_set_color(NEWT_COLORSET_LISTBOX); - + SLsmg_set_color(NEWT_COLORSET_LISTBOX); for (j = 0; j < (*item)->depth; j++) SLsmg_write_string(" "); @@ -479,7 +476,7 @@ static void ctDraw(newtComponent co) { } else { if (ct->flags & NEWT_CHECKBOXTREE_HIDE_BOX) { if ((*item)->selected) - SLsmg_set_color(NEWT_COLORSET_ACTLISTBOX); + SLsmg_set_color(NEWT_COLORSET_SELLISTBOX); SLsmg_write_string(" "); } else { char tmp[5]; @@ -487,12 +484,15 @@ static void ctDraw(newtComponent co) { SLsmg_write_string(tmp); } } + if (*item == *ct->currItem) { + SLsmg_set_color(ct->isActive ? + NEWT_COLORSET_ACTSELLISTBOX : NEWT_COLORSET_ACTLISTBOX); + currRow = co->top + i; + } SLsmg_write_nstring((*item)->text, co->width - 4 - (3 * (*item)->depth)); - SLsmg_set_color(NEWT_COLORSET_LISTBOX); - item++; i++; } @@ -688,11 +688,13 @@ struct eventResult ctEvent(newtComponent co, struct event ev) { break; case EV_FOCUS: + ct->isActive = 1; ctDraw(co); er.result = ER_SWALLOWED; break; case EV_UNFOCUS: + ct->isActive = 0; ctDraw(co); er.result = ER_SWALLOWED; break; diff --git a/form.c b/form.c index 63188ea..054a0c6 100644 --- a/form.c +++ b/form.c @@ -1027,8 +1027,17 @@ void newtFormRun(newtComponent co, struct newtExitStruct * es) { } } - if (key == NEWT_KEY_F1 && form->helpTag && form->helpCb) + if (key == NEWT_KEY_F1 && form->helpTag && form->helpCb) { + if (form->currComp != -1) { + ev.event = EV_UNFOCUS; + sendEvent(form->elements[form->currComp].co, ev); + } form->helpCb(co, form->helpTag); + if (form->currComp != -1) { + ev.event = EV_FOCUS; + sendEvent(form->elements[form->currComp].co, ev); + } + } if (!done) { ev.event = EV_KEYPRESS; diff --git a/listbox.c b/listbox.c index a895737..3ab7c4f 100644 --- a/listbox.c +++ b/listbox.c @@ -518,7 +518,7 @@ static void listboxDraw(newtComponent co) newtGotorc(co->top + i + li->bdyAdjust, co->left + li->bdxAdjust); if(j + i == li->currItem) { - if(item->isSelected) + if(li->isActive) SLsmg_set_color(NEWT_COLORSET_ACTSELLISTBOX); else SLsmg_set_color(NEWT_COLORSET_ACTLISTBOX); @@ -529,6 +529,12 @@ static void listboxDraw(newtComponent co) SLsmg_write_nstring(item->text, li->curWidth); + if (li->flags & NEWT_FLAG_MULTIPLE) { + newtGotorc(co->top + i + li->bdyAdjust, co->left + li->bdxAdjust); + SLsmg_set_color(item->isSelected ? + NEWT_COLORSET_SELLISTBOX : NEWT_COLORSET_LISTBOX); + SLsmg_write_nstring(item->text, 1); + } } newtGotorc(co->top + (li->currItem - li->startShowItem) + li->bdyAdjust, co->left + li->bdxAdjust); diff --git a/textbox.c b/textbox.c index 745460c..d860da4 100644 --- a/textbox.c +++ b/textbox.c @@ -15,9 +15,10 @@ struct textbox { char *blankline; int linesAlloced; int doWrap; - newtComponent sb; + newtComponent sb_act, sb; int topLine; int textWidth; + int isActive; }; static char * expandTabs(const char * text); @@ -43,8 +44,10 @@ static void textboxMapped(newtComponent co, int isMapped) { struct textbox * tb = co->data; co->isMapped = isMapped; - if (tb->sb) + if (tb->sb) { tb->sb->ops->mapped(tb->sb, isMapped); + tb->sb_act->ops->mapped(tb->sb_act, isMapped); + } } static void textboxPlace(newtComponent co, int newLeft, int newTop) { @@ -53,8 +56,10 @@ static void textboxPlace(newtComponent co, int newLeft, int newTop) { co->top = newTop; co->left = newLeft; - if (tb->sb) + if (tb->sb) { tb->sb->ops->place(tb->sb, co->left + co->width - 1, co->top); + tb->sb_act->ops->place(tb->sb_act, co->left + co->width - 1, co->top); + } } void newtTextboxSetHeight(newtComponent co, int height) { @@ -107,16 +112,20 @@ newtComponent newtTextbox(int left, int top, int width, int height, int flags) { tb->lines = NULL; tb->topLine = 0; tb->textWidth = width; + tb->isActive = 0; tb->blankline = malloc(width+1); memset(tb->blankline,' ',width); tb->blankline[width] = '\0'; if (flags & NEWT_FLAG_SCROLL) { co->width += 2; + tb->sb_act = newtVerticalScrollbar(co->left + co->width - 1, co->top, + co->height, COLORSET_ACTTEXTBOX, COLORSET_TEXTBOX); tb->sb = newtVerticalScrollbar(co->left + co->width - 1, co->top, co->height, COLORSET_TEXTBOX, COLORSET_TEXTBOX); + co->takesFocus = 1; } else { - tb->sb = NULL; + tb->sb_act = tb->sb = NULL; } return co; @@ -342,8 +351,13 @@ static void textboxDraw(newtComponent c) { if (tb->sb) { size = tb->numLines - c->height; - newtScrollbarSet(tb->sb, tb->topLine, size ? size : 0); - tb->sb->ops->draw(tb->sb); + if (tb->isActive) { + newtScrollbarSet(tb->sb_act, tb->topLine, size ? size : 0); + tb->sb_act->ops->draw(tb->sb_act); + } else { + newtScrollbarSet(tb->sb, tb->topLine, size ? size : 0); + tb->sb->ops->draw(tb->sb); + } } SLsmg_set_color(NEWT_COLORSET_TEXTBOX); @@ -363,7 +377,11 @@ static struct eventResult textboxEvent(newtComponent co, er.result = ER_IGNORED; - if (ev.when == EV_EARLY && ev.event == EV_KEYPRESS && tb->sb) { + if (!tb->sb || ev.when == EV_EARLY || ev.when == EV_LATE) + return er; + + switch(ev.event) { + case EV_KEYPRESS: newtTrashScreen(); switch (ev.u.key) { case NEWT_KEY_UP: @@ -395,8 +413,8 @@ static struct eventResult textboxEvent(newtComponent co, er.result = ER_SWALLOWED; break; } - } - if (ev.when == EV_EARLY && ev.event == EV_MOUSE && tb->sb) { + break; + case EV_MOUSE: /* Top scroll arrow */ if (ev.u.mouse.x == co->width && ev.u.mouse.y == co->top) { if (tb->topLine) tb->topLine--; @@ -412,6 +430,17 @@ static struct eventResult textboxEvent(newtComponent co, er.result = ER_SWALLOWED; } + break; + case EV_FOCUS: + tb->isActive = 1; + textboxDraw(co); + er.result = ER_SWALLOWED; + break; + case EV_UNFOCUS: + tb->isActive = 0; + textboxDraw(co); + er.result = ER_SWALLOWED; + break; } return er; }