win_wchnstr(WINDOW *win, cchar_t * wchstr, int n) { int code = OK; TR(TRACE_CCALLS, (T_CALLED("win_wchnstr(%p,%p,%d)"), win, wchstr, n)); if (win != 0 && wchstr != 0) { if (n < 0) { n = getmaxx(win) + 1 - getcurx(win); } while (n-- > 0) win_wch(win, wchstr++); } else { code = ERR; } returnCode(code); }
/*--------------------------------------------------------------------------- | Facility : libnform | Function : static char * Only_Padding( | WINDOW *w, | int len, | int pad) | | Description : Test if 'length' cells starting at the current position | contain a padding character. | | Return Values : true if only padding cells are found +--------------------------------------------------------------------------*/ NCURSES_INLINE static bool Only_Padding(WINDOW *w, int len, int pad) { bool result = TRUE; int y, x, j; FIELD_CELL cell; getyx(w, y, x); for (j = 0; j < len; ++j) { if (wmove(w, y, x + j) != ERR) { #if USE_WIDEC_SUPPORT if (win_wch(w, &cell) != ERR) { if ((chtype)CharOf(cell) != ChCharOf(pad) || cell.chars[1] != 0) { result = FALSE; break; } } #else cell = winch(w); if (ChCharOf(cell) != ChCharOf(pad)) { result = FALSE; break; } #endif } else { /* if an error, return true: no non-padding text found */ break; } } /* no need to reset the cursor position; caller does this */ return result; }
static int test_inchs(int level, char **argv, WINDOW *chrwin, WINDOW *strwin) { WINDOW *txtbox = 0; WINDOW *txtwin = 0; FILE *fp; int j; int txt_x = 0, txt_y = 0; int base_y; int limit; cchar_t ch; cchar_t text[MAX_COLS]; if (argv[level] == 0) { beep(); return FALSE; } if (level > 1) { txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level); box(txtbox, 0, 0); wnoutrefresh(txtbox); txtwin = derwin(txtbox, getmaxy(txtbox) - 2, getmaxx(txtbox) - 2, 1, 1); base_y = 0; } else { txtwin = stdscr; base_y = BASE_Y; } keypad(txtwin, TRUE); /* enable keyboard mapping */ (void) cbreak(); /* take input chars one at a time, no wait for \n */ (void) noecho(); /* don't echo input */ txt_y = base_y; txt_x = 0; wmove(txtwin, txt_y, txt_x); if ((fp = fopen(argv[level], "r")) != 0) { while ((j = fgetc(fp)) != EOF) { if (waddch(txtwin, UChar(j)) != OK) { break; } } fclose(fp); } else { wprintw(txtwin, "Cannot open:\n%s", argv[1]); } while (!Quit(j = mvwgetch(txtwin, txt_y, txt_x))) { switch (j) { case KEY_DOWN: case 'j': if (txt_y < getmaxy(txtwin) - 1) txt_y++; else beep(); break; case KEY_UP: case 'k': if (txt_y > base_y) txt_y--; else beep(); break; case KEY_LEFT: case 'h': if (txt_x > 0) txt_x--; else beep(); break; case KEY_RIGHT: case 'l': if (txt_x < getmaxx(txtwin) - 1) txt_x++; else beep(); break; case 'w': test_inchs(level + 1, argv, chrwin, strwin); if (txtbox != 0) { touchwin(txtbox); wnoutrefresh(txtbox); } else { touchwin(txtwin); wnoutrefresh(txtwin); } break; default: beep(); break; } MvWPrintw(chrwin, 0, 0, "char:"); wclrtoeol(chrwin); if (txtwin != stdscr) { wmove(txtwin, txt_y, txt_x); if (win_wch(txtwin, &ch) != ERR) { if (wadd_wch(chrwin, &ch) != ERR) { for (j = txt_x + 1; j < getmaxx(txtwin); ++j) { if (mvwin_wch(txtwin, txt_y, j, &ch) != ERR) { if (wadd_wch(chrwin, &ch) == ERR) { break; } } else { break; } } } } } else { move(txt_y, txt_x); if (in_wch(&ch) != ERR) { if (wadd_wch(chrwin, &ch) != ERR) { for (j = txt_x + 1; j < getmaxx(txtwin); ++j) { if (mvin_wch(txt_y, j, &ch) != ERR) { if (wadd_wch(chrwin, &ch) == ERR) { break; } } else { break; } } } } } wnoutrefresh(chrwin); MvWPrintw(strwin, 0, 0, "text:"); wclrtobot(strwin); limit = getmaxx(strwin) - 5; if (txtwin != stdscr) { wmove(txtwin, txt_y, txt_x); if (win_wchstr(txtwin, text) != ERR) { (void) mvwadd_wchstr(strwin, 0, 5, text); } wmove(txtwin, txt_y, txt_x); if (win_wchnstr(txtwin, text, limit) != ERR) { (void) mvwadd_wchstr(strwin, 1, 5, text); } if (mvwin_wchstr(txtwin, txt_y, txt_x, text) != ERR) { (void) mvwadd_wchstr(strwin, 2, 5, text); } if (mvwin_wchnstr(txtwin, txt_y, txt_x, text, limit) != ERR) { (void) mvwadd_wchstr(strwin, 3, 5, text); } } else { move(txt_y, txt_x); if (in_wchstr(text) != ERR) { (void) mvwadd_wchstr(strwin, 0, 5, text); } move(txt_y, txt_x); if (in_wchnstr(text, limit) != ERR) { (void) mvwadd_wchstr(strwin, 1, 5, text); } if (mvin_wchstr(txt_y, txt_x, text) != ERR) { (void) mvwadd_wchstr(strwin, 2, 5, text); } if (mvin_wchnstr(txt_y, txt_x, text, limit) != ERR) { (void) mvwadd_wchstr(strwin, 3, 5, text); } } wnoutrefresh(strwin); } if (level > 1) { delwin(txtwin); delwin(txtbox); } return TRUE; }
void dlg_trace_win(WINDOW *win) { if (myFP != 0) { int y, x; int j, k; WINDOW *top = wgetparent(win); while (top != 0 && top != stdscr) { win = top; top = wgetparent(win); } if (win != 0) { int rc = getmaxy(win); int cc = getmaxx(win); chtype ch, c2; fprintf(myFP, "window %dx%d at %d,%d\n", rc, cc, getbegy(win), getbegx(win)); getyx(win, y, x); for (j = 0; j < rc; ++j) { fprintf(myFP, "%3d:", j); for (k = 0; k < cc; ++k) { #ifdef USE_WIDE_CURSES char buffer[80]; ch = mvwinch(win, j, k) & (A_CHARTEXT | A_ALTCHARSET); if (ch & A_ALTCHARSET) { c2 = dlg_asciibox(ch); if (c2 != 0) { ch = c2; } buffer[0] = (char) ch; buffer[1] = '\0'; } else { cchar_t cch; wchar_t *uc; if (win_wch(win, &cch) == ERR || (uc = wunctrl((&cch))) == 0 || uc[1] != 0 || wcwidth(uc[0]) <= 0) { buffer[0] = '.'; buffer[1] = '\0'; } else { mbstate_t state; const wchar_t *ucp = uc; memset(&state, 0, sizeof(state)); wcsrtombs(buffer, &ucp, sizeof(buffer), &state); k += wcwidth(uc[0]) - 1; } } fputs(buffer, myFP); #else ch = mvwinch(win, j, k) & (A_CHARTEXT | A_ALTCHARSET); c2 = dlg_asciibox(ch); if (c2 != 0) { ch = c2; } else if (unctrl(ch) == 0 || strlen(unctrl(ch)) > 1) { ch = '.'; } fputc((int) (ch & 0xff), myFP); #endif } fputc('\n', myFP); } wmove(win, y, x); fflush(myFP); } } }
//------------------------------------------------------------------------------ int in_wch( cchar_t* wcval ) { __QCS_FCONTEXT( "in_wch" ); return win_wch( stdscr, wcval ); }
NCURSES_EXPORT(int) (in_wch) (cchar_t * z) { T((T_CALLED("in_wch(%p)"), (const void *)z)); returnCode(win_wch(stdscr,z)); }
NCURSES_EXPORT(int) (mvwin_wch) (WINDOW * a1, int a2, int a3, cchar_t * z) { T((T_CALLED("mvwin_wch(%p,%d,%d,%p)"), (const void *)a1, a2, a3, (const void *)z)); returnCode((wmove(a1,a2,a3) == (-1) ? (-1) : win_wch(a1,z))); }
NCURSES_EXPORT(int) (mvin_wch) (int a1, int a2, cchar_t * z) { T((T_CALLED("mvin_wch(%d,%d,%p)"), a1, a2, (const void *)z)); returnCode((wmove(stdscr,a1,a2) == (-1) ? (-1) : win_wch(stdscr,z))); }