static void _map_button(chtype *inp) { SLK_MAP *slk = SP->slk; int num = slk->_num; int len = slk->_len; int i; /* first determine if this mouse button event should be */ /* mapped into function key */ if (!(SP->_map_mbe_to_key & ((BUTTON_CHANGED(3) << (10 + BUTTON_STATUS(3))) | (BUTTON_CHANGED(2) << (5 + BUTTON_STATUS(2))) | (BUTTON_CHANGED(1) << BUTTON_STATUS(1))))) return; for (i = 0; i < num; i++) { if (MOUSE_X_POS < slk->_labx[i]) break; if (MOUSE_X_POS > slk->_labx[i] + len) continue; *inp = KEY_F(1) + i; break; } }
WINDOW *Xinitscr(int argc, char *argv[]) { int i; PDC_LOG(("Xinitscr() - called\n")); if (SP && SP->alive) return NULL; if (PDC_scr_open(argc, argv) == ERR) { fprintf(stderr, "initscr(): Unable to create SP\n"); exit(8); } SP->autocr = TRUE; /* cr -> lf by default */ SP->raw_out = FALSE; /* tty I/O modes */ SP->raw_inp = FALSE; /* tty I/O modes */ SP->cbreak = TRUE; SP->save_key_modifiers = FALSE; SP->return_key_modifiers = FALSE; SP->echo = TRUE; SP->visibility = 1; SP->resized = FALSE; SP->_trap_mbe = 0L; SP->_map_mbe_to_key = 0L; SP->linesrippedoff = 0; SP->linesrippedoffontop = 0; SP->delaytenths = 0; SP->line_color = -1; SP->orig_cursor = PDC_get_cursor_mode(); LINES = SP->lines; COLS = SP->cols; if (LINES < 2 || COLS < 2) { fprintf(stderr, "initscr(): LINES=%d COLS=%d: too small.\n", LINES, COLS); exit(4); } if ((curscr = newwin(LINES, COLS, 0, 0)) == (WINDOW *)NULL) { fprintf(stderr, "initscr(): Unable to create curscr.\n"); exit(2); } if ((pdc_lastscr = newwin(LINES, COLS, 0, 0)) == (WINDOW *)NULL) { fprintf(stderr, "initscr(): Unable to create pdc_lastscr.\n"); exit(2); } wattrset(pdc_lastscr, (chtype)(-1)); werase(pdc_lastscr); PDC_slk_initialize(); LINES -= SP->slklines; /* We have to sort out ripped off lines here, and reduce the height of stdscr by the number of lines ripped off */ for (i = 0; i < linesrippedoff; i++) { if (linesripped[i].line < 0) (*linesripped[i].init)(newwin(1, COLS, LINES - 1, 0), COLS); else (*linesripped[i].init)(newwin(1, COLS, SP->linesrippedoffontop++, 0), COLS); SP->linesrippedoff++; LINES--; } linesrippedoff = 0; if (!(stdscr = newwin(LINES, COLS, SP->linesrippedoffontop, 0))) { fprintf(stderr, "initscr(): Unable to create stdscr.\n"); exit(1); } wclrtobot(stdscr); /* If preserving the existing screen, don't allow a screen clear */ if (SP->_preserve) { untouchwin(curscr); untouchwin(stdscr); stdscr->_clear = FALSE; curscr->_clear = FALSE; } else curscr->_clear = TRUE; PDC_init_atrtab(); /* set up default colors */ MOUSE_X_POS = MOUSE_Y_POS = -1; BUTTON_STATUS(1) = BUTTON_RELEASED; BUTTON_STATUS(2) = BUTTON_RELEASED; BUTTON_STATUS(3) = BUTTON_RELEASED; Mouse_status.changes = 0; SP->alive = TRUE; def_shell_mode(); sprintf(ttytype, "pdcurses|PDCurses for %s", PDC_sysname()); return stdscr; }
static void inputTest(WINDOW *win) { int answered; int repeat; int w, h, bx, by, sw, sh, i, c, num; char buffer[80]; WINDOW *subWin; wclear(win); getmaxyx(win, h, w); getbegyx(win, by, bx); sw = w / 3; sh = h / 3; if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL) return; #ifdef A_COLOR if (has_colors()) { init_pair(2, COLOR_WHITE, COLOR_RED); wbkgd(subWin, (chtype) COLOR_PAIR(2) | A_BOLD); } else wbkgd(subWin, A_BOLD); #else wbkgd(subWin, A_BOLD); #endif box(subWin, ACS_VLINE, ACS_HLINE); wrefresh(win); nocbreak(); MvWAddStr(win, 2, 1, "Press some keys for 5 seconds"); MvWAddStr(win, 1, 1, "Pressing ^C should do nothing"); wrefresh(win); werase(subWin); box(subWin, ACS_VLINE, ACS_HLINE); for (i = 0; i < 5; i++) { MvWPrintw(subWin, 1, 1, "Time = %d", i); wrefresh(subWin); napms(1000); flushinp(); } delwin(subWin); werase(win); flash(); wrefresh(win); napms(500); MvWAddStr(win, 2, 1, "Press a key, followed by ENTER"); wmove(win, 9, 10); wrefresh(win); echo(); noraw(); wgetch(win); flushinp(); wmove(win, 9, 10); wdelch(win); MvWAddStr(win, 4, 1, "The character should now have been deleted"); Continue(win); wclear(win); MvWAddStr(win, 1, 1, "Press keys (or mouse buttons) to show their names"); MvWAddStr(win, 2, 1, "Press spacebar to finish"); wrefresh(win); keypad(win, TRUE); raw(); noecho(); #if HAVE_TYPEAHEAD typeahead(-1); #endif #ifdef NCURSES_MOUSE_VERSION mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0); #endif #if defined(PDCURSES) mouse_set(ALL_MOUSE_EVENTS); #endif for (;;) { wmove(win, 3, 5); c = wgetch(win); wclrtobot(win); if (c >= KEY_MIN) wprintw(win, "Key Pressed: %s", keyname(c)); else if (isprint(c)) wprintw(win, "Key Pressed: %c", c); else wprintw(win, "Key Pressed: %s", unctrl(UChar(c))); #ifdef KEY_MOUSE if (c == KEY_MOUSE) { #if defined(NCURSES_MOUSE_VERSION) #define ButtonChanged(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, 037)) #define ButtonPressed(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_PRESSED)) #define ButtonDouble(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_DOUBLE_CLICKED)) #define ButtonTriple(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_TRIPLE_CLICKED)) #define ButtonRelease(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_RELEASED)) MEVENT event; int button = 0; getmouse(&event); if (ButtonChanged(1)) button = 1; else if (ButtonChanged(2)) button = 2; else if (ButtonChanged(3)) button = 3; else button = 0; wmove(win, 4, 18); wprintw(win, "Button %d: ", button); if (ButtonPressed(button)) wprintw(win, "pressed: "); else if (ButtonDouble(button)) wprintw(win, "double: "); else if (ButtonTriple(button)) wprintw(win, "triple: "); else wprintw(win, "released: "); wprintw(win, " Position: Y: %d X: %d", event.y, event.x); #elif defined(PDCURSES) int button = 0; request_mouse_pos(); if (BUTTON_CHANGED(1)) button = 1; else if (BUTTON_CHANGED(2)) button = 2; else if (BUTTON_CHANGED(3)) button = 3; else button = 0; wmove(win, 4, 18); wprintw(win, "Button %d: ", button); if (MOUSE_MOVED) wprintw(win, "moved: "); else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED) wprintw(win, "pressed: "); else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED) wprintw(win, "double: "); else wprintw(win, "released: "); wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS); #endif /* NCURSES_VERSION vs PDCURSES */ } #endif /* KEY_MOUSE */ wrefresh(win); if (c == ' ') break; } #if 0 nodelay(win, TRUE); wgetch(win); nodelay(win, FALSE); #endif #if defined(PDCURSES) mouse_set(0L); #endif refresh(); repeat = 0; do { static const char *fmt[] = { "%d %10s", "%d %[a-zA-Z]s", "%d %[][a-zA-Z]s", "%d %[^0-9]" }; char *format = strdup(fmt[(unsigned) repeat % SIZEOF(fmt)]); wclear(win); MvWAddStr(win, 3, 2, "The window should have moved"); MvWAddStr(win, 4, 2, "This text should have appeared without you pressing a key"); MvWPrintw(win, 6, 2, "Scanning with format \"%s\"", format); mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4)); erase(); refresh(); wrefresh(win); echo(); noraw(); num = 0; *buffer = 0; answered = mvwscanw(win, 7, 6, format, &num, buffer); MvWPrintw(win, 8, 6, "String: %s Number: %d (%d values read)", buffer, num, answered); Continue(win); ++repeat; free(format); } while (answered > 0); }
void inputTest(WINDOW *win) { int w, h, bx, by, sw, sh, i, c, num = 0; char buffer[80]; WINDOW *subWin; static const char spinner[4] = "/-\\|"; int spinner_count = 0; wclear(win); getmaxyx(win, h, w); getbegyx(win, by, bx); sw = w / 3; sh = h / 3; if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL) return; #ifdef A_COLOR if (has_colors()) { init_pair(2, COLOR_WHITE, COLOR_RED); wbkgd(subWin, COLOR_PAIR(2) | A_BOLD); } else #endif wbkgd(subWin, A_BOLD); box(subWin, ACS_VLINE, ACS_HLINE); wrefresh(win); nocbreak(); wclear (win); mvwaddstr(win, 1, 1, "Press keys (or mouse buttons) to show their names"); mvwaddstr(win, 2, 1, "Press spacebar to finish"); wrefresh(win); keypad(win, TRUE); raw(); noecho(); wtimeout(win, 200); #ifdef PDCURSES mouse_set(ALL_MOUSE_EVENTS); PDC_save_key_modifiers(TRUE); PDC_return_key_modifiers(TRUE); #endif curs_set(0); /* turn cursor off */ while (1) { while (1) { c = wgetch(win); if (c == ERR) { spinner_count++; if (spinner_count == 4) spinner_count = 0; mvwaddch(win, 3, 3, spinner[spinner_count]); wrefresh(win); } else break; } #ifdef PDCURSES wmove(win, 4, 18); wclrtoeol(win); #endif mvwaddstr(win, 3, 5, "Key Pressed: "); wclrtoeol(win); if (c >= KEY_MIN) wprintw(win, "%s", keyname(c)); else if (isprint(c)) wprintw(win, "%c", c); else wprintw(win, "%s", unctrl(c)); #ifdef PDCURSES if (c == KEY_MOUSE) { int button = 0; request_mouse_pos(); if (BUTTON_CHANGED(1)) button = 1; else if (BUTTON_CHANGED(2)) button = 2; else if (BUTTON_CHANGED(3)) button = 3; if (button && (BUTTON_STATUS(button) & BUTTON_MODIFIER_MASK)) { waddstr(win, " Modifier(s):"); if (BUTTON_STATUS(button) & BUTTON_SHIFT) waddstr(win, " SHIFT"); if (BUTTON_STATUS(button) & BUTTON_CONTROL) waddstr(win, " CONTROL"); if (BUTTON_STATUS(button) & BUTTON_ALT) waddstr(win, " ALT"); } wmove(win, 4, 18); wclrtoeol(win); wprintw(win, "Button %d: ", button); if (MOUSE_MOVED) waddstr(win, "moved: "); else if (MOUSE_WHEEL_UP) waddstr(win, "wheel up: "); else if (MOUSE_WHEEL_DOWN) waddstr(win, "wheel dn: "); else if (MOUSE_WHEEL_LEFT) waddstr(win, "wheel lt: "); else if (MOUSE_WHEEL_RIGHT) waddstr(win, "wheel rt: "); else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED) waddstr(win, "pressed: "); else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_CLICKED) waddstr(win, "clicked: "); else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED) waddstr(win, "double: "); else waddstr(win, "released: "); wprintw(win, "Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS); } else if (PDC_get_key_modifiers()) { waddstr(win, " Modifier(s):"); if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_SHIFT) waddstr(win, " SHIFT"); if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_CONTROL) waddstr(win, " CONTROL"); if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_ALT) waddstr(win, " ALT"); if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_NUMLOCK) waddstr(win, " NUMLOCK"); } #endif wrefresh(win); if (c == ' ') break; } wtimeout(win, -1); /* turn off timeout() */ curs_set(1); /* turn cursor back on */ #ifdef PDCURSES mouse_set(0L); PDC_save_key_modifiers(FALSE); PDC_return_key_modifiers(FALSE); #endif wclear(win); mvwaddstr(win, 2, 1, "Press some keys for 5 seconds"); mvwaddstr(win, 1, 1, "Pressing ^C should do nothing"); wrefresh(win); werase(subWin); box(subWin, ACS_VLINE, ACS_HLINE); for (i = 0; i < 5; i++) { mvwprintw(subWin, 1, 1, "Time = %d", i); wrefresh(subWin); napms(1000); flushinp(); } delwin(subWin); werase(win); flash(); wrefresh(win); napms(500); flushinp(); mvwaddstr(win, 2, 1, "Press a key, followed by ENTER"); wmove(win, 9, 10); wrefresh(win); echo(); keypad(win, TRUE); raw(); wgetnstr(win, buffer, 3); flushinp(); wmove(win, 9, 10); wdelch(win); mvwaddstr(win, 4, 1, "The character should now have been deleted"); Continue(win); refresh(); wclear(win); echo(); buffer[0] = '\0'; mvwaddstr(win, 3, 2, "The window should have moved"); mvwaddstr(win, 4, 2, "This text should have appeared without you pressing a key"); mvwaddstr(win, 6, 2, "Enter a number then a string seperated by space"); mvwin(win, 2, 1); wrefresh(win); mvwscanw(win, 7, 6, "%d %s", &num, buffer); mvwprintw(win, 8, 6, "String: %s Number: %d", buffer, num); Continue(win); refresh(); wclear(win); echo(); mvwaddstr(win, 3, 2, "Enter a 5 character string: "); wgetnstr(win, buffer, 5); mvwprintw(win, 4, 2, "String: %s", buffer); Continue(win); }
/* * The routine returns the following: * -3: not a mouse button event * -2: read timed out * -1: the read failed * [0, 1, 2, 3] - the first character in the mouse event */ static int get_xterm_mouse(int blockpeek, int *i) { chtype *inputQ = cur_term->_input_queue; /* ??? */ /* LINTED */ chtype *chars_onQ = (chtype *) &(cur_term->_chars_on_queue); int j, mx, my; int char1, char2, c1, c2; /* the first character should be 0, 1, 2, or 4 */ char1 = (inputQ[(*i)++] = (blockpeek) ? _pk() : _fpk()); /* read error or timeout */ if (char1 < 0) return (char1); (*chars_onQ)++; if (char1 < '0' || char1 > '3') return (-3); /* if the character is 1, 2, or 3 it must be followed by */ /* P, R, C, D, or T */ if (char1 != '0') { char2 = (inputQ[(*i)++] = (blockpeek) ? _pk() : _fpk()); if (char2 < 0) return (char2); (*chars_onQ)++; if (char2 != 'P' && char2 != 'R' && char2 != 'C' && char2 != 'D' && char2 != 'T') return (-3); } /* read X and Y coordinates of the mouse */ for (j = 0; j < 2; j++) { c1 = (inputQ[(*i)++] = (blockpeek) ? _pk() : _fpk()); if (c1 < 0) return (c1); (*chars_onQ)++; if (c1 >= ' ' && c1 <= '~') { /* ascii char */ if (j == 0) mx = c1 - ' '; else my = c1 - ' '; } else if (char1 == 01 || char1 == 02) { /* ^A || ^B */ c2 = (inputQ[(*i)++] = (blockpeek) ? _pk() : _fpk()); if (c2 < 0) return (c2); (*chars_onQ)++; if (c2 >= ' ' && c2 <= '~') { if (j == 0) mx = c1 * (c2 - ' '); else my = c1 * (c2 - ' '); } else return (-3); } else return (-3); } /* read complete mouse event: update the Mouse_status structure */ MOUSE_X_POS = mx; MOUSE_Y_POS = my; j = char1 - '0'; if (j != 0) { switch (char2) { case 'P': BUTTON_STATUS(j) = BUTTON_PRESSED; break; case 'R': BUTTON_STATUS(j) = BUTTON_RELEASED; break; case 'C': BUTTON_STATUS(j) = BUTTON_CLICKED; break; case 'D': BUTTON_STATUS(j) = BUTTON_DOUBLE_CLICKED; break; case 'T': BUTTON_STATUS(j) = BUTTON_TRIPLE_CLICKED; break; } } return (j); }