/* * Arrow keys move cursor, return location at current on non-arrow key. */ static PAIR * selectcell(WINDOW *parent, int uli, int ulj, int lri, int lrj) { static PAIR res; /* result cell */ int si = lri - uli + 1; /* depth of the select area */ int sj = lrj - ulj + 1; /* width of the select area */ int i = 0, j = 0; /* offsets into the select area */ res.y = uli; res.x = ulj; for (;;) { tail_line("Upper left [%2d,%2d] Lower right [%2d,%2d] -> %d,%d", uli, ulj, lri, lrj, uli + i, ulj + j); wmove(parent, uli + i, ulj + j); switch (wgetch(parent)) { case KEY_UP: i += si - 1; break; case KEY_DOWN: i++; break; case KEY_LEFT: j += sj - 1; break; case KEY_RIGHT: j++; break; case QUIT: case ESCAPE: return ((PAIR *) 0); #ifdef NCURSES_MOUSE_VERSION case KEY_MOUSE: { MEVENT event; getmouse(&event); if (event.y > uli && event.x > ulj) { i = event.y - uli; j = event.x - ulj; } else { beep(); break; } } /* FALLTHRU */ #endif default: res.y = uli + i; res.x = ulj + j; return (&res); } i %= si; j %= sj; } }
/* * Arrow keys move cursor, return location at current on non-arrow key. */ static PAIR * selectcell(WINDOW *parent, WINDOW *child, int uli, int ulj, int lri, int lrj, bool relative, bool * more) { static PAIR res; /* result cell */ int si = lri - uli + 1; /* depth of the select area */ int sj = lrj - ulj + 1; /* width of the select area */ int i = 0, j = 0; /* offsets into the select area */ res.y = uli; res.x = ulj; if (child != 0) { if (relative) { getparyx(child, i, j); } else { getbegyx(child, i, j); i -= uli + getbegy(parent); j -= ulj + getbegx(parent); } } if (more) *more = FALSE; for (;;) { bool moved = FALSE; tail_line("Upper left [%2d,%2d] Lower right [%2d,%2d] -> %d,%d -> %d,%d", uli, ulj, lri, lrj, i, j, uli + i, ulj + j); wmove(parent, uli + i, ulj + j); switch (wgetch(parent)) { case KEY_UP: i += si - 1; moved = TRUE; break; case KEY_DOWN: i++; moved = TRUE; break; case KEY_LEFT: j += sj - 1; moved = TRUE; break; case KEY_RIGHT: j++; moved = TRUE; break; case QUIT: case ESCAPE: return ((PAIR *) 0); #ifdef NCURSES_MOUSE_VERSION case KEY_MOUSE: { MEVENT event; getmouse(&event); if (event.y > uli && event.x > ulj) { if (parent != stdscr) { i = event.y - getbegy(parent) - uli; j = event.x - getbegx(parent) - ulj; } else { i = event.y - uli; j = event.x - ulj; } } else { beep(); break; } } /* FALLTHRU */ #endif default: res.y = uli + i; res.x = ulj + j; return (&res); } if (si <= 0) i = 0; else i %= si; if (sj <= 0) j = 0; else j %= sj; /* * If the caller can handle continuous movement, return the result. */ if (moved && more) { *more = TRUE; res.y = uli + i; res.x = ulj + j; return (&res); } } }