| 1 | /* General window behavior. |
| 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 "tui.h" |
| 27 | #include "tuiData.h" |
| 28 | #include "tuiGeneralWin.h" |
| 29 | #include "tuiWin.h" |
| 30 | |
| 31 | #ifdef HAVE_NCURSES_H |
| 32 | #include <ncurses.h> |
| 33 | #else |
| 34 | #ifdef HAVE_CURSES_H |
| 35 | #include <curses.h> |
| 36 | #endif |
| 37 | #endif |
| 38 | |
| 39 | /*********************** |
| 40 | ** PUBLIC FUNCTIONS |
| 41 | ***********************/ |
| 42 | /* |
| 43 | ** tuiRefreshWin() |
| 44 | ** Refresh the window |
| 45 | */ |
| 46 | void |
| 47 | tuiRefreshWin (TuiGenWinInfoPtr winInfo) |
| 48 | { |
| 49 | if (winInfo->type == DATA_WIN && winInfo->contentSize > 0) |
| 50 | { |
| 51 | int i; |
| 52 | |
| 53 | for (i = 0; (i < winInfo->contentSize); i++) |
| 54 | { |
| 55 | TuiGenWinInfoPtr dataItemWinPtr; |
| 56 | |
| 57 | dataItemWinPtr = &((TuiWinContent) |
| 58 | winInfo->content)[i]->whichElement.dataWindow; |
| 59 | if (m_genWinPtrNotNull (dataItemWinPtr) && |
| 60 | dataItemWinPtr->handle != (WINDOW *) NULL) |
| 61 | wrefresh (dataItemWinPtr->handle); |
| 62 | } |
| 63 | } |
| 64 | else if (winInfo->type == CMD_WIN) |
| 65 | { |
| 66 | /* Do nothing */ |
| 67 | } |
| 68 | else |
| 69 | { |
| 70 | if (winInfo->handle != (WINDOW *) NULL) |
| 71 | wrefresh (winInfo->handle); |
| 72 | } |
| 73 | |
| 74 | return; |
| 75 | } /* tuiRefreshWin */ |
| 76 | |
| 77 | |
| 78 | /* |
| 79 | ** tuiDelwin() |
| 80 | ** Function to delete the curses window, checking for null |
| 81 | */ |
| 82 | void |
| 83 | tuiDelwin (WINDOW * window) |
| 84 | { |
| 85 | if (window != (WINDOW *) NULL) |
| 86 | delwin (window); |
| 87 | |
| 88 | return; |
| 89 | } /* tuiDelwin */ |
| 90 | |
| 91 | |
| 92 | /* Draw a border arround the window. */ |
| 93 | void |
| 94 | boxWin (TuiGenWinInfoPtr winInfo, int highlightFlag) |
| 95 | { |
| 96 | if (winInfo && winInfo->handle) |
| 97 | { |
| 98 | WINDOW *win; |
| 99 | int attrs; |
| 100 | |
| 101 | win = winInfo->handle; |
| 102 | if (highlightFlag == HILITE) |
| 103 | attrs = tui_active_border_attrs; |
| 104 | else |
| 105 | attrs = tui_border_attrs; |
| 106 | |
| 107 | wattron (win, attrs); |
| 108 | wborder (win, tui_border_vline, tui_border_vline, |
| 109 | tui_border_hline, tui_border_hline, |
| 110 | tui_border_ulcorner, tui_border_urcorner, |
| 111 | tui_border_llcorner, tui_border_lrcorner); |
| 112 | if (winInfo->title) |
| 113 | mvwaddstr (win, 0, 3, winInfo->title); |
| 114 | wattroff (win, attrs); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | |
| 119 | /* |
| 120 | ** unhighlightWin(). |
| 121 | */ |
| 122 | void |
| 123 | unhighlightWin (TuiWinInfoPtr winInfo) |
| 124 | { |
| 125 | if (m_winPtrNotNull (winInfo) && winInfo->generic.handle != (WINDOW *) NULL) |
| 126 | { |
| 127 | boxWin ((TuiGenWinInfoPtr) winInfo, NO_HILITE); |
| 128 | wrefresh (winInfo->generic.handle); |
| 129 | m_setWinHighlightOff (winInfo); |
| 130 | } |
| 131 | } /* unhighlightWin */ |
| 132 | |
| 133 | |
| 134 | /* |
| 135 | ** highlightWin(). |
| 136 | */ |
| 137 | void |
| 138 | highlightWin (TuiWinInfoPtr winInfo) |
| 139 | { |
| 140 | if (m_winPtrNotNull (winInfo) && |
| 141 | winInfo->canHighlight && winInfo->generic.handle != (WINDOW *) NULL) |
| 142 | { |
| 143 | boxWin ((TuiGenWinInfoPtr) winInfo, HILITE); |
| 144 | wrefresh (winInfo->generic.handle); |
| 145 | m_setWinHighlightOn (winInfo); |
| 146 | } |
| 147 | } /* highlightWin */ |
| 148 | |
| 149 | |
| 150 | /* |
| 151 | ** checkAndDisplayHighlightIfNecessay |
| 152 | */ |
| 153 | void |
| 154 | checkAndDisplayHighlightIfNeeded (TuiWinInfoPtr winInfo) |
| 155 | { |
| 156 | if (m_winPtrNotNull (winInfo) && winInfo->generic.type != CMD_WIN) |
| 157 | { |
| 158 | if (winInfo->isHighlighted) |
| 159 | highlightWin (winInfo); |
| 160 | else |
| 161 | unhighlightWin (winInfo); |
| 162 | |
| 163 | } |
| 164 | return; |
| 165 | } /* checkAndDisplayHighlightIfNeeded */ |
| 166 | |
| 167 | |
| 168 | /* |
| 169 | ** makeWindow(). |
| 170 | */ |
| 171 | void |
| 172 | makeWindow (TuiGenWinInfoPtr winInfo, int boxIt) |
| 173 | { |
| 174 | WINDOW *handle; |
| 175 | |
| 176 | handle = newwin (winInfo->height, |
| 177 | winInfo->width, |
| 178 | winInfo->origin.y, |
| 179 | winInfo->origin.x); |
| 180 | winInfo->handle = handle; |
| 181 | if (handle != (WINDOW *) NULL) |
| 182 | { |
| 183 | if (boxIt == BOX_WINDOW) |
| 184 | boxWin (winInfo, NO_HILITE); |
| 185 | winInfo->isVisible = TRUE; |
| 186 | scrollok (handle, TRUE); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | |
| 191 | /* |
| 192 | ** makeVisible(). |
| 193 | ** We can't really make windows visible, or invisible. So we |
| 194 | ** have to delete the entire window when making it visible, |
| 195 | ** and create it again when making it visible. |
| 196 | */ |
| 197 | void |
| 198 | makeVisible (TuiGenWinInfoPtr winInfo, int visible) |
| 199 | { |
| 200 | /* Don't tear down/recreate command window */ |
| 201 | if (winInfo->type == CMD_WIN) |
| 202 | return; |
| 203 | |
| 204 | if (visible) |
| 205 | { |
| 206 | if (!winInfo->isVisible) |
| 207 | { |
| 208 | makeWindow ( |
| 209 | winInfo, |
| 210 | (winInfo->type != CMD_WIN && !m_winIsAuxillary (winInfo->type))); |
| 211 | winInfo->isVisible = TRUE; |
| 212 | } |
| 213 | } |
| 214 | else if (!visible && |
| 215 | winInfo->isVisible && winInfo->handle != (WINDOW *) NULL) |
| 216 | { |
| 217 | winInfo->isVisible = FALSE; |
| 218 | tuiDelwin (winInfo->handle); |
| 219 | winInfo->handle = (WINDOW *) NULL; |
| 220 | } |
| 221 | |
| 222 | return; |
| 223 | } /* makeVisible */ |
| 224 | |
| 225 | |
| 226 | /* |
| 227 | ** makeAllVisible(). |
| 228 | ** Makes all windows invisible (except the command and locator windows) |
| 229 | */ |
| 230 | void |
| 231 | makeAllVisible (int visible) |
| 232 | { |
| 233 | int i; |
| 234 | |
| 235 | for (i = 0; i < MAX_MAJOR_WINDOWS; i++) |
| 236 | { |
| 237 | if (m_winPtrNotNull (winList[i]) && |
| 238 | ((winList[i])->generic.type) != CMD_WIN) |
| 239 | { |
| 240 | if (m_winIsSourceType ((winList[i])->generic.type)) |
| 241 | makeVisible ((winList[i])->detail.sourceInfo.executionInfo, |
| 242 | visible); |
| 243 | makeVisible ((TuiGenWinInfoPtr) winList[i], visible); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | return; |
| 248 | } /* makeAllVisible */ |
| 249 | |
| 250 | /* |
| 251 | ** refreshAll(). |
| 252 | ** Function to refresh all the windows currently displayed |
| 253 | */ |
| 254 | void |
| 255 | refreshAll (TuiWinInfoPtr * list) |
| 256 | { |
| 257 | TuiWinType type; |
| 258 | TuiGenWinInfoPtr locator = locatorWinInfoPtr (); |
| 259 | |
| 260 | for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++) |
| 261 | { |
| 262 | if (list[type] && list[type]->generic.isVisible) |
| 263 | { |
| 264 | if (type == SRC_WIN || type == DISASSEM_WIN) |
| 265 | { |
| 266 | touchwin (list[type]->detail.sourceInfo.executionInfo->handle); |
| 267 | tuiRefreshWin (list[type]->detail.sourceInfo.executionInfo); |
| 268 | } |
| 269 | touchwin (list[type]->generic.handle); |
| 270 | tuiRefreshWin (&list[type]->generic); |
| 271 | } |
| 272 | } |
| 273 | if (locator->isVisible) |
| 274 | { |
| 275 | touchwin (locator->handle); |
| 276 | tuiRefreshWin (locator); |
| 277 | } |
| 278 | |
| 279 | return; |
| 280 | } /* refreshAll */ |
| 281 | |
| 282 | |
| 283 | /********************************* |
| 284 | ** Local Static Functions |
| 285 | *********************************/ |