void newtPopWindowNoRefresh(void) { int j, row, col; int n = 0; if (currentWindow == NULL) return; row = col = 0; row = currentWindow->top - 1; col = currentWindow->left - 2; if (row < 0) row = 0; if (col < 0) col = 0; for (j = 0; j < currentWindow->height + 3; j++, row++) { SLsmg_gotorc(row, col); SLsmg_write_raw(currentWindow->buffer + n, currentWindow->width + 5); n += currentWindow->width + 5; } free(currentWindow->buffer); free(currentWindow->title); if (currentWindow == windowStack) currentWindow = NULL; else currentWindow--; SLsmg_set_char_set(0); newtTrashScreen(); }
static struct eventResult textboxEvent(newtComponent co, struct event ev) { struct textbox * tb = co->data; struct eventResult er; er.result = ER_IGNORED; if (ev.when == EV_EARLY && ev.event == EV_KEYPRESS && tb->sb) { newtTrashScreen(); switch (ev.u.key) { case NEWT_KEY_UP: if (tb->topLine) tb->topLine--; textboxDraw(co); er.result = ER_SWALLOWED; break; case NEWT_KEY_DOWN: if (tb->topLine < (tb->numLines - co->height)) tb->topLine++; textboxDraw(co); er.result = ER_SWALLOWED; break; case NEWT_KEY_PGDN: tb->topLine += co->height; if (tb->topLine > (tb->numLines - co->height)) { tb->topLine = tb->numLines - co->height; if (tb->topLine < 0) tb->topLine = 0; } textboxDraw(co); er.result = ER_SWALLOWED; break; case NEWT_KEY_PGUP: tb->topLine -= co->height; if (tb->topLine < 0) tb->topLine = 0; textboxDraw(co); er.result = ER_SWALLOWED; break; } } if (ev.when == EV_EARLY && ev.event == EV_MOUSE && tb->sb) { /* Top scroll arrow */ if (ev.u.mouse.x == co->width && ev.u.mouse.y == co->top) { if (tb->topLine) tb->topLine--; textboxDraw(co); er.result = ER_SWALLOWED; } /* Bottom scroll arrow */ if (ev.u.mouse.x == co->width && ev.u.mouse.y == co->top + co->height - 1) { if (tb->topLine < (tb->numLines - co->height)) tb->topLine++; textboxDraw(co); er.result = ER_SWALLOWED; } } return er; }
static void listboxDraw(newtComponent co) { struct listbox * li = co->data; struct items *item; int i, j; if (!co->isMapped) return ; newtTrashScreen(); if(li->flags & NEWT_FLAG_BORDER) { if(li->isActive) SLsmg_set_color(NEWT_COLORSET_ACTLISTBOX); else SLsmg_set_color(NEWT_COLORSET_LISTBOX); newtDrawBox(co->left, co->top, co->width, co->height, 0); } if(li->sb) li->sb->ops->draw(li->sb); SLsmg_set_color(NEWT_COLORSET_LISTBOX); for(i = 0, item = li->boxItems; item != NULL && i < li->startShowItem; i++, item = item->next); j = i; for (i = 0; item != NULL && i < li->curHeight; i++, item = item->next) { if (!item->text) continue; newtGotorc(co->top + i + li->bdyAdjust, co->left + li->bdxAdjust); if(j + i == li->currItem) { if(item->isSelected) SLsmg_set_color(NEWT_COLORSET_ACTSELLISTBOX); else SLsmg_set_color(NEWT_COLORSET_ACTLISTBOX); } else if(item->isSelected) SLsmg_set_color(NEWT_COLORSET_SELLISTBOX); else SLsmg_set_color(NEWT_COLORSET_LISTBOX); SLsmg_write_nstring(item->text, li->curWidth); } newtGotorc(co->top + (li->currItem - li->startShowItem) + 1, co->left + 1); }
void newtTextboxSetText(newtComponent co, const char * text) { const char * start, * end; struct textbox * tb = co->data; char * reflowed, * expanded; int badness, height; if (tb->lines) { free(tb->lines); tb->linesAlloced = tb->numLines = 0; } expanded = expandTabs(text); if (tb->doWrap) { doReflow(expanded, &reflowed, tb->textWidth, &badness, &height); free(expanded); expanded = reflowed; } for (start = expanded; *start; start++) if (*start == '\n') tb->linesAlloced++; /* This ++ leaves room for an ending line w/o a \n */ tb->linesAlloced++; tb->lines = malloc(sizeof(char *) * tb->linesAlloced); start = expanded; while ((end = strchr(start, '\n'))) { addLine(co, start, end - start); start = end + 1; } if (*start) addLine(co, start, strlen(start)); free(expanded); newtTrashScreen(); }
/** * Open a new window. * @param left. int Size; _not_ including border * @param top: int size, _not_ including border * @param width unsigned int * @param height unsigned int * @param title - title string * @return zero on success */ int newtOpenWindow(int left, int top, unsigned int width, unsigned int height, const char * title) { int j, row, col; int n; int i; newtFlushInput(); if (currentWindow && currentWindow - windowStack + 1 >= sizeof (windowStack) / sizeof (struct Window)) return 1; if (!currentWindow) { currentWindow = windowStack; } else { currentWindow++; } currentWindow->left = left; currentWindow->top = top; currentWindow->width = width; currentWindow->height = height; currentWindow->title = title ? strdup(title) : NULL; currentWindow->buffer = malloc(sizeof(SLsmg_Char_Type) * (width + 5) * (height + 3)); row = top - 1; col = left - 2; /* clip to the current screen bounds - msw */ if (row < 0) row = 0; if (col < 0) col = 0; if (left + width > SLtt_Screen_Cols) width = SLtt_Screen_Cols - left; if (top + height > SLtt_Screen_Rows) height = SLtt_Screen_Rows - top; n = 0; for (j = 0; j < height + 3; j++, row++) { SLsmg_gotorc(row, col); SLsmg_read_raw(currentWindow->buffer + n, currentWindow->width + 5); n += currentWindow->width + 5; } newtTrashScreen(); SLsmg_set_color(NEWT_COLORSET_BORDER); SLsmg_set_char_set(1); SLsmg_draw_box(top - 1, left - 1, height + 2, width + 2); SLsmg_set_char_set(0); if (currentWindow->title) { trim_string (currentWindow->title, width-4); i = wstrlen(currentWindow->title,-1) + 4; i = ((width - i) / 2) + left; SLsmg_gotorc(top - 1, i); SLsmg_set_char_set(1); SLsmg_write_char(SLSMG_RTEE_CHAR); SLsmg_set_char_set(0); SLsmg_write_char(' '); SLsmg_set_color(NEWT_COLORSET_TITLE); SLsmg_write_string((char *)currentWindow->title); SLsmg_set_color(NEWT_COLORSET_BORDER); SLsmg_write_char(' '); SLsmg_set_char_set(1); SLsmg_write_char(SLSMG_LTEE_CHAR); SLsmg_set_char_set(0); } SLsmg_set_color(NEWT_COLORSET_WINDOW); SLsmg_fill_region(top, left, height, width, ' '); SLsmg_set_color(NEWT_COLORSET_SHADOW); SLsmg_fill_region(top + height + 1, left, 1, width + 2, ' '); SLsmg_fill_region(top, left + width + 1, height + 1, 1, ' '); for (i = top; i < (top + height + 1); i++) { SLsmg_gotorc(i, left + width + 1); SLsmg_write_string(" "); } return 0; }