| 1 | /* Specific command window processing. |
| 2 | |
| 3 | Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, |
| 4 | Inc. |
| 5 | |
| 6 | Contributed by Hewlett-Packard Company. |
| 7 | |
| 8 | This file is part of GDB. |
| 9 | |
| 10 | This program is free software; you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation; either version 2 of the License, or |
| 13 | (at your option) any later version. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program; if not, write to the Free Software |
| 22 | Foundation, Inc., 59 Temple Place - Suite 330, |
| 23 | Boston, MA 02111-1307, USA. */ |
| 24 | |
| 25 | #include "defs.h" |
| 26 | #include <ctype.h> |
| 27 | #include "tui.h" |
| 28 | #include "tuiData.h" |
| 29 | #include "tuiWin.h" |
| 30 | #include "tuiIO.h" |
| 31 | |
| 32 | #ifdef HAVE_NCURSES_H |
| 33 | #include <ncurses.h> |
| 34 | #else |
| 35 | #ifdef HAVE_CURSES_H |
| 36 | #include <curses.h> |
| 37 | #endif |
| 38 | #endif |
| 39 | |
| 40 | |
| 41 | /***************************************** |
| 42 | ** STATIC LOCAL FUNCTIONS FORWARD DECLS ** |
| 43 | ******************************************/ |
| 44 | |
| 45 | |
| 46 | |
| 47 | /***************************************** |
| 48 | ** PUBLIC FUNCTIONS ** |
| 49 | ******************************************/ |
| 50 | |
| 51 | /* |
| 52 | ** tuiDispatchCtrlChar(). |
| 53 | ** Dispatch the correct tui function based upon the control character. |
| 54 | */ |
| 55 | unsigned int |
| 56 | tuiDispatchCtrlChar (unsigned int ch) |
| 57 | { |
| 58 | TuiWinInfoPtr winInfo = tuiWinWithFocus (); |
| 59 | WINDOW *w = cmdWin->generic.handle; |
| 60 | |
| 61 | /* |
| 62 | ** If the command window has the logical focus, or no-one does |
| 63 | ** assume it is the command window; in this case, pass the |
| 64 | ** character on through and do nothing here. |
| 65 | */ |
| 66 | if (winInfo == (TuiWinInfoPtr) NULL || winInfo == cmdWin) |
| 67 | return ch; |
| 68 | else |
| 69 | { |
| 70 | unsigned int c = 0, chCopy = ch; |
| 71 | register int i; |
| 72 | char *term; |
| 73 | |
| 74 | /* If this is an xterm, page next/prev keys aren't returned |
| 75 | ** by keypad as a single char, so we must handle them here. |
| 76 | ** Seems like a bug in the curses library? |
| 77 | */ |
| 78 | term = (char *) getenv ("TERM"); |
| 79 | for (i = 0; (term && term[i]); i++) |
| 80 | term[i] = toupper (term[i]); |
| 81 | if ((strcmp (term, "XTERM") == 0) && m_isStartSequence (ch)) |
| 82 | { |
| 83 | unsigned int pageCh = 0, tmpChar; |
| 84 | |
| 85 | tmpChar = 0; |
| 86 | while (!m_isEndSequence (tmpChar)) |
| 87 | { |
| 88 | tmpChar = (int) wgetch (w); |
| 89 | if (tmpChar == ERR) |
| 90 | { |
| 91 | return ch; |
| 92 | } |
| 93 | if (!tmpChar) |
| 94 | break; |
| 95 | if (tmpChar == 53) |
| 96 | pageCh = KEY_PPAGE; |
| 97 | else if (tmpChar == 54) |
| 98 | pageCh = KEY_NPAGE; |
| 99 | else |
| 100 | { |
| 101 | return 0; |
| 102 | } |
| 103 | } |
| 104 | chCopy = pageCh; |
| 105 | } |
| 106 | |
| 107 | switch (chCopy) |
| 108 | { |
| 109 | case KEY_NPAGE: |
| 110 | tuiScrollForward (winInfo, 0); |
| 111 | break; |
| 112 | case KEY_PPAGE: |
| 113 | tuiScrollBackward (winInfo, 0); |
| 114 | break; |
| 115 | case KEY_DOWN: |
| 116 | case KEY_SF: |
| 117 | tuiScrollForward (winInfo, 1); |
| 118 | break; |
| 119 | case KEY_UP: |
| 120 | case KEY_SR: |
| 121 | tuiScrollBackward (winInfo, 1); |
| 122 | break; |
| 123 | case KEY_RIGHT: |
| 124 | tuiScrollLeft (winInfo, 1); |
| 125 | break; |
| 126 | case KEY_LEFT: |
| 127 | tuiScrollRight (winInfo, 1); |
| 128 | break; |
| 129 | case '\f': |
| 130 | tuiRefreshAll (); |
| 131 | break; |
| 132 | default: |
| 133 | c = chCopy; |
| 134 | break; |
| 135 | } |
| 136 | return c; |
| 137 | } |
| 138 | } |