Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI window generic functions. |
f33c6cbf | 2 | |
61baf725 | 3 | Copyright (C) 1998-2017 Free Software Foundation, Inc. |
f33c6cbf | 4 | |
f377b406 | 5 | Contributed by Hewlett-Packard Company. |
c906108c | 6 | |
f377b406 SC |
7 | This file is part of GDB. |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
f377b406 SC |
12 | (at your option) any later version. |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
f377b406 SC |
21 | |
22 | /* This module contains procedures for handling tui window functions | |
23 | like resize, scrolling, scrolling, changing focus, etc. | |
24 | ||
25 | Author: Susan B. Macchia */ | |
c906108c | 26 | |
c906108c SS |
27 | #include "defs.h" |
28 | #include "command.h" | |
29 | #include "symtab.h" | |
30 | #include "breakpoint.h" | |
31 | #include "frame.h" | |
41783295 | 32 | #include "cli/cli-cmds.h" |
3e752b04 | 33 | #include "top.h" |
52575520 | 34 | #include "source.h" |
c4ef48c6 | 35 | #include "event-loop.h" |
c906108c | 36 | |
d7b2e967 | 37 | #include "tui/tui.h" |
c4ef48c6 | 38 | #include "tui/tui-io.h" |
d7b2e967 AC |
39 | #include "tui/tui-data.h" |
40 | #include "tui/tui-wingeneral.h" | |
41 | #include "tui/tui-stack.h" | |
42 | #include "tui/tui-regs.h" | |
43 | #include "tui/tui-disasm.h" | |
44 | #include "tui/tui-source.h" | |
45 | #include "tui/tui-winsource.h" | |
46 | #include "tui/tui-windata.h" | |
2c0b251b | 47 | #include "tui/tui-win.h" |
c906108c | 48 | |
6a83354a | 49 | #include "gdb_curses.h" |
96ec9981 | 50 | #include <ctype.h> |
dbda9972 | 51 | #include "readline/readline.h" |
96ec9981 | 52 | |
9612b5ec UW |
53 | #include <signal.h> |
54 | ||
c906108c SS |
55 | /******************************* |
56 | ** Static Local Decls | |
57 | ********************************/ | |
6ba8e26f | 58 | static void make_visible_with_new_height (struct tui_win_info *); |
08ef48c5 MS |
59 | static void make_invisible_and_set_new_height (struct tui_win_info *, |
60 | int); | |
61 | static enum tui_status tui_adjust_win_heights (struct tui_win_info *, | |
62 | int); | |
6ba8e26f AC |
63 | static int new_height_ok (struct tui_win_info *, int); |
64 | static void tui_set_tab_width_command (char *, int); | |
65 | static void tui_refresh_all_command (char *, int); | |
66 | static void tui_set_win_height_command (char *, int); | |
6ba8e26f AC |
67 | static void tui_all_windows_info (char *, int); |
68 | static void tui_set_focus_command (char *, int); | |
69 | static void tui_scroll_forward_command (char *, int); | |
70 | static void tui_scroll_backward_command (char *, int); | |
71 | static void tui_scroll_left_command (char *, int); | |
72 | static void tui_scroll_right_command (char *, int); | |
08ef48c5 MS |
73 | static void parse_scrolling_args (char *, |
74 | struct tui_win_info **, | |
75 | int *); | |
c906108c SS |
76 | |
77 | ||
78 | /*************************************** | |
79 | ** DEFINITIONS | |
80 | ***************************************/ | |
08ef48c5 MS |
81 | #define WIN_HEIGHT_USAGE "Usage: winheight <win_name> [+ | -] <#lines>\n" |
82 | #define XDBWIN_HEIGHT_USAGE "Usage: w <#lines>\n" | |
83 | #define FOCUS_USAGE "Usage: focus {<win> | next | prev}\n" | |
c906108c SS |
84 | |
85 | /*************************************** | |
86 | ** PUBLIC FUNCTIONS | |
87 | ***************************************/ | |
88 | ||
17aae570 SC |
89 | #ifndef ACS_LRCORNER |
90 | # define ACS_LRCORNER '+' | |
91 | #endif | |
92 | #ifndef ACS_LLCORNER | |
93 | # define ACS_LLCORNER '+' | |
94 | #endif | |
95 | #ifndef ACS_ULCORNER | |
96 | # define ACS_ULCORNER '+' | |
97 | #endif | |
98 | #ifndef ACS_URCORNER | |
99 | # define ACS_URCORNER '+' | |
100 | #endif | |
101 | #ifndef ACS_HLINE | |
102 | # define ACS_HLINE '-' | |
103 | #endif | |
104 | #ifndef ACS_VLINE | |
105 | # define ACS_VLINE '|' | |
106 | #endif | |
107 | ||
af101512 | 108 | /* Possible values for tui-border-kind variable. */ |
40478521 | 109 | static const char *const tui_border_kind_enums[] = { |
af101512 SC |
110 | "space", |
111 | "ascii", | |
112 | "acs", | |
113 | NULL | |
114 | }; | |
115 | ||
116 | /* Possible values for tui-border-mode and tui-active-border-mode. */ | |
40478521 | 117 | static const char *const tui_border_mode_enums[] = { |
af101512 SC |
118 | "normal", |
119 | "standout", | |
120 | "reverse", | |
121 | "half", | |
122 | "half-standout", | |
123 | "bold", | |
124 | "bold-standout", | |
125 | NULL | |
126 | }; | |
127 | ||
128 | struct tui_translate | |
129 | { | |
130 | const char *name; | |
131 | int value; | |
132 | }; | |
133 | ||
134 | /* Translation table for border-mode variables. | |
135 | The list of values must be terminated by a NULL. | |
136 | After the NULL value, an entry defines the default. */ | |
137 | struct tui_translate tui_border_mode_translate[] = { | |
138 | { "normal", A_NORMAL }, | |
139 | { "standout", A_STANDOUT }, | |
140 | { "reverse", A_REVERSE }, | |
141 | { "half", A_DIM }, | |
142 | { "half-standout", A_DIM | A_STANDOUT }, | |
143 | { "bold", A_BOLD }, | |
144 | { "bold-standout", A_BOLD | A_STANDOUT }, | |
145 | { 0, 0 }, | |
146 | { "normal", A_NORMAL } | |
147 | }; | |
148 | ||
149 | /* Translation tables for border-kind, one for each border | |
150 | character (see wborder, border curses operations). | |
151 | -1 is used to indicate the ACS because ACS characters | |
152 | are determined at run time by curses (depends on terminal). */ | |
153 | struct tui_translate tui_border_kind_translate_vline[] = { | |
154 | { "space", ' ' }, | |
155 | { "ascii", '|' }, | |
156 | { "acs", -1 }, | |
157 | { 0, 0 }, | |
158 | { "ascii", '|' } | |
159 | }; | |
160 | ||
161 | struct tui_translate tui_border_kind_translate_hline[] = { | |
162 | { "space", ' ' }, | |
163 | { "ascii", '-' }, | |
164 | { "acs", -1 }, | |
165 | { 0, 0 }, | |
166 | { "ascii", '-' } | |
167 | }; | |
168 | ||
169 | struct tui_translate tui_border_kind_translate_ulcorner[] = { | |
170 | { "space", ' ' }, | |
171 | { "ascii", '+' }, | |
172 | { "acs", -1 }, | |
173 | { 0, 0 }, | |
174 | { "ascii", '+' } | |
175 | }; | |
176 | ||
177 | struct tui_translate tui_border_kind_translate_urcorner[] = { | |
178 | { "space", ' ' }, | |
179 | { "ascii", '+' }, | |
180 | { "acs", -1 }, | |
181 | { 0, 0 }, | |
182 | { "ascii", '+' } | |
183 | }; | |
184 | ||
185 | struct tui_translate tui_border_kind_translate_llcorner[] = { | |
186 | { "space", ' ' }, | |
187 | { "ascii", '+' }, | |
188 | { "acs", -1 }, | |
189 | { 0, 0 }, | |
190 | { "ascii", '+' } | |
191 | }; | |
192 | ||
193 | struct tui_translate tui_border_kind_translate_lrcorner[] = { | |
194 | { "space", ' ' }, | |
195 | { "ascii", '+' }, | |
196 | { "acs", -1 }, | |
197 | { 0, 0 }, | |
198 | { "ascii", '+' } | |
199 | }; | |
200 | ||
201 | ||
202 | /* Tui configuration variables controlled with set/show command. */ | |
203 | const char *tui_active_border_mode = "bold-standout"; | |
920d2a44 | 204 | static void |
08ef48c5 MS |
205 | show_tui_active_border_mode (struct ui_file *file, |
206 | int from_tty, | |
207 | struct cmd_list_element *c, | |
208 | const char *value) | |
920d2a44 AC |
209 | { |
210 | fprintf_filtered (file, _("\ | |
211 | The attribute mode to use for the active TUI window border is \"%s\".\n"), | |
212 | value); | |
213 | } | |
214 | ||
af101512 | 215 | const char *tui_border_mode = "normal"; |
920d2a44 | 216 | static void |
08ef48c5 MS |
217 | show_tui_border_mode (struct ui_file *file, |
218 | int from_tty, | |
219 | struct cmd_list_element *c, | |
220 | const char *value) | |
920d2a44 AC |
221 | { |
222 | fprintf_filtered (file, _("\ | |
223 | The attribute mode to use for the TUI window borders is \"%s\".\n"), | |
224 | value); | |
225 | } | |
226 | ||
af101512 | 227 | const char *tui_border_kind = "acs"; |
920d2a44 | 228 | static void |
08ef48c5 MS |
229 | show_tui_border_kind (struct ui_file *file, |
230 | int from_tty, | |
231 | struct cmd_list_element *c, | |
232 | const char *value) | |
920d2a44 AC |
233 | { |
234 | fprintf_filtered (file, _("The kind of border for TUI windows is \"%s\".\n"), | |
235 | value); | |
236 | } | |
237 | ||
af101512 | 238 | |
1cc6d956 MS |
239 | /* Tui internal configuration variables. These variables are updated |
240 | by tui_update_variables to reflect the tui configuration | |
af101512 SC |
241 | variables. */ |
242 | chtype tui_border_vline; | |
243 | chtype tui_border_hline; | |
244 | chtype tui_border_ulcorner; | |
245 | chtype tui_border_urcorner; | |
246 | chtype tui_border_llcorner; | |
247 | chtype tui_border_lrcorner; | |
248 | ||
249 | int tui_border_attrs; | |
250 | int tui_active_border_attrs; | |
251 | ||
252 | /* Identify the item in the translation table. | |
253 | When the item is not recognized, use the default entry. */ | |
254 | static struct tui_translate * | |
255 | translate (const char *name, struct tui_translate *table) | |
256 | { | |
257 | while (table->name) | |
258 | { | |
259 | if (name && strcmp (table->name, name) == 0) | |
260 | return table; | |
261 | table++; | |
262 | } | |
263 | ||
264 | /* Not found, return default entry. */ | |
265 | table++; | |
266 | return table; | |
267 | } | |
268 | ||
269 | /* Update the tui internal configuration according to gdb settings. | |
270 | Returns 1 if the configuration has changed and the screen should | |
271 | be redrawn. */ | |
272 | int | |
d02c80cd | 273 | tui_update_variables (void) |
af101512 SC |
274 | { |
275 | int need_redraw = 0; | |
276 | struct tui_translate *entry; | |
277 | ||
278 | entry = translate (tui_border_mode, tui_border_mode_translate); | |
279 | if (tui_border_attrs != entry->value) | |
280 | { | |
281 | tui_border_attrs = entry->value; | |
282 | need_redraw = 1; | |
283 | } | |
284 | entry = translate (tui_active_border_mode, tui_border_mode_translate); | |
285 | if (tui_active_border_attrs != entry->value) | |
286 | { | |
287 | tui_active_border_attrs = entry->value; | |
288 | need_redraw = 1; | |
289 | } | |
290 | ||
291 | /* If one corner changes, all characters are changed. | |
292 | Only check the first one. The ACS characters are determined at | |
293 | run time by curses terminal management. */ | |
294 | entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner); | |
295 | if (tui_border_lrcorner != (chtype) entry->value) | |
296 | { | |
297 | tui_border_lrcorner = (entry->value < 0) ? ACS_LRCORNER : entry->value; | |
298 | need_redraw = 1; | |
299 | } | |
300 | entry = translate (tui_border_kind, tui_border_kind_translate_llcorner); | |
301 | tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value; | |
302 | ||
303 | entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner); | |
304 | tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value; | |
305 | ||
306 | entry = translate (tui_border_kind, tui_border_kind_translate_urcorner); | |
307 | tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value; | |
308 | ||
309 | entry = translate (tui_border_kind, tui_border_kind_translate_hline); | |
310 | tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value; | |
311 | ||
312 | entry = translate (tui_border_kind, tui_border_kind_translate_vline); | |
313 | tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value; | |
314 | ||
315 | return need_redraw; | |
316 | } | |
317 | ||
c9684879 | 318 | static void |
981a3fb3 | 319 | set_tui_cmd (const char *args, int from_tty) |
c9684879 SC |
320 | { |
321 | } | |
322 | ||
323 | static void | |
981a3fb3 | 324 | show_tui_cmd (const char *args, int from_tty) |
c9684879 SC |
325 | { |
326 | } | |
af101512 | 327 | |
10f59415 SC |
328 | static struct cmd_list_element *tuilist; |
329 | ||
330 | static void | |
981a3fb3 | 331 | tui_command (const char *args, int from_tty) |
10f59415 | 332 | { |
a3f17187 AC |
333 | printf_unfiltered (_("\"tui\" must be followed by the name of a " |
334 | "tui command.\n")); | |
635c7e8a | 335 | help_list (tuilist, "tui ", all_commands, gdb_stdout); |
10f59415 SC |
336 | } |
337 | ||
338 | struct cmd_list_element ** | |
da745b36 | 339 | tui_get_cmd_list (void) |
10f59415 SC |
340 | { |
341 | if (tuilist == 0) | |
342 | add_prefix_cmd ("tui", class_tui, tui_command, | |
1bedd215 | 343 | _("Text User Interface commands."), |
10f59415 SC |
344 | &tuilist, "tui ", 0, &cmdlist); |
345 | return &tuilist; | |
346 | } | |
347 | ||
6cdb25f4 EZ |
348 | /* The set_func hook of "set tui ..." commands that affect the window |
349 | borders on the TUI display. */ | |
350 | void | |
351 | tui_set_var_cmd (char *null_args, int from_tty, struct cmd_list_element *c) | |
352 | { | |
353 | if (tui_update_variables () && tui_active) | |
354 | tui_rehighlight_all (); | |
355 | } | |
356 | ||
97605e61 AB |
357 | /* Generic window name completion function. Complete window name pointed |
358 | to by TEXT and WORD. If INCLUDE_NEXT_PREV_P is true then the special | |
359 | window names 'next' and 'prev' will also be considered as possible | |
360 | completions of the window name. */ | |
2e52ae68 | 361 | |
eb3ff9a5 PA |
362 | static void |
363 | window_name_completer (completion_tracker &tracker, | |
364 | int include_next_prev_p, | |
97605e61 | 365 | const char *text, const char *word) |
2e52ae68 PP |
366 | { |
367 | VEC (const_char_ptr) *completion_name_vec = NULL; | |
2e52ae68 PP |
368 | int win_type; |
369 | ||
370 | for (win_type = SRC_WIN; win_type < MAX_MAJOR_WINDOWS; win_type++) | |
371 | { | |
372 | const char *completion_name = NULL; | |
373 | ||
374 | /* We can't focus on an invisible window. */ | |
375 | if (tui_win_list[win_type] == NULL | |
376 | || !tui_win_list[win_type]->generic.is_visible) | |
377 | continue; | |
378 | ||
150375dc AB |
379 | completion_name = tui_win_name (&tui_win_list [win_type]->generic); |
380 | gdb_assert (completion_name != NULL); | |
381 | VEC_safe_push (const_char_ptr, completion_name_vec, completion_name); | |
2e52ae68 PP |
382 | } |
383 | ||
384 | /* If no windows are considered visible then the TUI has not yet been | |
385 | initialized. But still "focus src" and "focus cmd" will work because | |
386 | invoking the focus command will entail initializing the TUI which sets the | |
387 | default layout to SRC_COMMAND. */ | |
388 | if (VEC_length (const_char_ptr, completion_name_vec) == 0) | |
389 | { | |
150375dc AB |
390 | VEC_safe_push (const_char_ptr, completion_name_vec, SRC_NAME); |
391 | VEC_safe_push (const_char_ptr, completion_name_vec, CMD_NAME); | |
2e52ae68 PP |
392 | } |
393 | ||
97605e61 AB |
394 | if (include_next_prev_p) |
395 | { | |
396 | VEC_safe_push (const_char_ptr, completion_name_vec, "next"); | |
397 | VEC_safe_push (const_char_ptr, completion_name_vec, "prev"); | |
398 | } | |
2e52ae68 | 399 | |
97605e61 | 400 | VEC_safe_push (const_char_ptr, completion_name_vec, NULL); |
eb3ff9a5 PA |
401 | complete_on_enum (tracker, |
402 | VEC_address (const_char_ptr, completion_name_vec), | |
403 | text, word); | |
2e52ae68 PP |
404 | |
405 | VEC_free (const_char_ptr, completion_name_vec); | |
2e52ae68 PP |
406 | } |
407 | ||
97605e61 AB |
408 | /* Complete possible window names to focus on. TEXT is the complete text |
409 | entered so far, WORD is the word currently being completed. */ | |
410 | ||
eb3ff9a5 | 411 | static void |
97605e61 | 412 | focus_completer (struct cmd_list_element *ignore, |
eb3ff9a5 PA |
413 | completion_tracker &tracker, |
414 | const char *text, const char *word) | |
97605e61 | 415 | { |
eb3ff9a5 | 416 | window_name_completer (tracker, 1, text, word); |
97605e61 AB |
417 | } |
418 | ||
419 | /* Complete possible window names for winheight command. TEXT is the | |
420 | complete text entered so far, WORD is the word currently being | |
421 | completed. */ | |
422 | ||
eb3ff9a5 | 423 | static void |
97605e61 | 424 | winheight_completer (struct cmd_list_element *ignore, |
eb3ff9a5 | 425 | completion_tracker &tracker, |
97605e61 AB |
426 | const char *text, const char *word) |
427 | { | |
428 | /* The first word is the window name. That we can complete. Subsequent | |
429 | words can't be completed. */ | |
430 | if (word != text) | |
eb3ff9a5 | 431 | return; |
97605e61 | 432 | |
eb3ff9a5 | 433 | window_name_completer (tracker, 0, text, word); |
97605e61 AB |
434 | } |
435 | ||
08ef48c5 MS |
436 | /* Function to initialize gdb commands, for tui window |
437 | manipulation. */ | |
2c0b251b | 438 | |
c906108c | 439 | void |
6ba8e26f | 440 | _initialize_tui_win (void) |
c906108c | 441 | { |
c9684879 SC |
442 | static struct cmd_list_element *tui_setlist; |
443 | static struct cmd_list_element *tui_showlist; | |
97605e61 | 444 | struct cmd_list_element *cmd; |
af101512 | 445 | |
41783295 SC |
446 | /* Define the classes of commands. |
447 | They will appear in the help list in the reverse of this order. */ | |
c9684879 | 448 | add_prefix_cmd ("tui", class_tui, set_tui_cmd, |
1bedd215 | 449 | _("TUI configuration variables"), |
c9684879 | 450 | &tui_setlist, "set tui ", |
1cc6d956 | 451 | 0 /* allow-unknown */, &setlist); |
c9684879 | 452 | add_prefix_cmd ("tui", class_tui, show_tui_cmd, |
1bedd215 | 453 | _("TUI configuration variables"), |
c9684879 | 454 | &tui_showlist, "show tui ", |
1cc6d956 | 455 | 0 /* allow-unknown */, &showlist); |
c9684879 | 456 | |
6ba8e26f | 457 | add_com ("refresh", class_tui, tui_refresh_all_command, |
1bedd215 | 458 | _("Refresh the terminal display.\n")); |
1bedd215 AC |
459 | add_com ("tabset", class_tui, tui_set_tab_width_command, _("\ |
460 | Set the width (in characters) of tab stops.\n\ | |
461 | Usage: tabset <n>\n")); | |
97605e61 AB |
462 | cmd = add_com ("winheight", class_tui, tui_set_win_height_command, _("\ |
463 | Set or modify the height of a specified window.\n\ | |
c906108c SS |
464 | Usage: winheight <win_name> [+ | -] <#lines>\n\ |
465 | Window names are:\n\ | |
466 | src : the source window\n\ | |
467 | cmd : the command window\n\ | |
468 | asm : the disassembly window\n\ | |
1bedd215 | 469 | regs : the register display\n")); |
41783295 | 470 | add_com_alias ("wh", "winheight", class_tui, 0); |
97605e61 | 471 | set_cmd_completer (cmd, winheight_completer); |
6ba8e26f | 472 | add_info ("win", tui_all_windows_info, |
1bedd215 | 473 | _("List of all displayed windows.\n")); |
97605e61 | 474 | cmd = add_com ("focus", class_tui, tui_set_focus_command, _("\ |
1bedd215 | 475 | Set focus to named window or next/prev window.\n\ |
c906108c SS |
476 | Usage: focus {<win> | next | prev}\n\ |
477 | Valid Window names are:\n\ | |
478 | src : the source window\n\ | |
479 | asm : the disassembly window\n\ | |
480 | regs : the register display\n\ | |
1bedd215 | 481 | cmd : the command window\n")); |
41783295 | 482 | add_com_alias ("fs", "focus", class_tui, 0); |
97605e61 | 483 | set_cmd_completer (cmd, focus_completer); |
1bedd215 AC |
484 | add_com ("+", class_tui, tui_scroll_forward_command, _("\ |
485 | Scroll window forward.\n\ | |
486 | Usage: + [win] [n]\n")); | |
487 | add_com ("-", class_tui, tui_scroll_backward_command, _("\ | |
488 | Scroll window backward.\n\ | |
489 | Usage: - [win] [n]\n")); | |
490 | add_com ("<", class_tui, tui_scroll_left_command, _("\ | |
bf555842 | 491 | Scroll window text to the left.\n\ |
1bedd215 AC |
492 | Usage: < [win] [n]\n")); |
493 | add_com (">", class_tui, tui_scroll_right_command, _("\ | |
bf555842 | 494 | Scroll window text to the right.\n\ |
1bedd215 | 495 | Usage: > [win] [n]\n")); |
af101512 SC |
496 | |
497 | /* Define the tui control variables. */ | |
7ab04401 AC |
498 | add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums, |
499 | &tui_border_kind, _("\ | |
500 | Set the kind of border for TUI windows."), _("\ | |
501 | Show the kind of border for TUI windows."), _("\ | |
502 | This variable controls the border of TUI windows:\n\ | |
503 | space use a white space\n\ | |
504 | ascii use ascii characters + - | for the border\n\ | |
505 | acs use the Alternate Character Set"), | |
6cdb25f4 | 506 | tui_set_var_cmd, |
920d2a44 | 507 | show_tui_border_kind, |
7ab04401 AC |
508 | &tui_setlist, &tui_showlist); |
509 | ||
510 | add_setshow_enum_cmd ("border-mode", no_class, tui_border_mode_enums, | |
511 | &tui_border_mode, _("\ | |
512 | Set the attribute mode to use for the TUI window borders."), _("\ | |
513 | Show the attribute mode to use for the TUI window borders."), _("\ | |
514 | This variable controls the attributes to use for the window borders:\n\ | |
515 | normal normal display\n\ | |
516 | standout use highlight mode of terminal\n\ | |
517 | reverse use reverse video mode\n\ | |
518 | half use half bright\n\ | |
519 | half-standout use half bright and standout mode\n\ | |
520 | bold use extra bright or bold\n\ | |
521 | bold-standout use extra bright or bold with standout mode"), | |
6cdb25f4 | 522 | tui_set_var_cmd, |
920d2a44 | 523 | show_tui_border_mode, |
7ab04401 AC |
524 | &tui_setlist, &tui_showlist); |
525 | ||
526 | add_setshow_enum_cmd ("active-border-mode", no_class, tui_border_mode_enums, | |
527 | &tui_active_border_mode, _("\ | |
528 | Set the attribute mode to use for the active TUI window border."), _("\ | |
529 | Show the attribute mode to use for the active TUI window border."), _("\ | |
530 | This variable controls the attributes to use for the active window border:\n\ | |
531 | normal normal display\n\ | |
532 | standout use highlight mode of terminal\n\ | |
533 | reverse use reverse video mode\n\ | |
534 | half use half bright\n\ | |
535 | half-standout use half bright and standout mode\n\ | |
536 | bold use extra bright or bold\n\ | |
537 | bold-standout use extra bright or bold with standout mode"), | |
6cdb25f4 | 538 | tui_set_var_cmd, |
920d2a44 | 539 | show_tui_active_border_mode, |
7ab04401 | 540 | &tui_setlist, &tui_showlist); |
41783295 | 541 | } |
c906108c | 542 | |
3e752b04 SC |
543 | /* Update gdb's knowledge of the terminal size. */ |
544 | void | |
d02c80cd | 545 | tui_update_gdb_sizes (void) |
3e752b04 | 546 | { |
d6e5e7f7 PP |
547 | int width, height; |
548 | ||
549 | if (tui_active) | |
550 | { | |
551 | width = TUI_CMD_WIN->generic.width; | |
552 | height = TUI_CMD_WIN->generic.height; | |
553 | } | |
554 | else | |
555 | { | |
556 | width = tui_term_width (); | |
557 | height = tui_term_height (); | |
558 | } | |
559 | ||
560 | set_screen_width_and_height (width, height); | |
3e752b04 SC |
561 | } |
562 | ||
c906108c | 563 | |
1cc6d956 | 564 | /* Set the logical focus to win_info. */ |
c906108c | 565 | void |
5b6fe301 | 566 | tui_set_win_focus_to (struct tui_win_info *win_info) |
c906108c | 567 | { |
6d012f14 | 568 | if (win_info != NULL) |
c906108c | 569 | { |
5b6fe301 | 570 | struct tui_win_info *win_with_focus = tui_win_with_focus (); |
c906108c | 571 | |
6ba8e26f AC |
572 | if (win_with_focus != NULL |
573 | && win_with_focus->generic.type != CMD_WIN) | |
574 | tui_unhighlight_win (win_with_focus); | |
6d012f14 AC |
575 | tui_set_win_with_focus (win_info); |
576 | if (win_info->generic.type != CMD_WIN) | |
577 | tui_highlight_win (win_info); | |
c906108c | 578 | } |
6ba8e26f | 579 | } |
c906108c SS |
580 | |
581 | ||
c906108c | 582 | void |
08ef48c5 MS |
583 | tui_scroll_forward (struct tui_win_info *win_to_scroll, |
584 | int num_to_scroll) | |
c906108c | 585 | { |
6ba8e26f | 586 | if (win_to_scroll != TUI_CMD_WIN) |
c906108c | 587 | { |
6ba8e26f | 588 | int _num_to_scroll = num_to_scroll; |
c906108c | 589 | |
6ba8e26f AC |
590 | if (num_to_scroll == 0) |
591 | _num_to_scroll = win_to_scroll->generic.height - 3; | |
ef5eab5a MS |
592 | |
593 | /* If we are scrolling the source or disassembly window, do a | |
594 | "psuedo" scroll since not all of the source is in memory, | |
595 | only what is in the viewport. If win_to_scroll is the | |
596 | command window do nothing since the term should handle | |
597 | it. */ | |
6ba8e26f AC |
598 | if (win_to_scroll == TUI_SRC_WIN) |
599 | tui_vertical_source_scroll (FORWARD_SCROLL, _num_to_scroll); | |
600 | else if (win_to_scroll == TUI_DISASM_WIN) | |
601 | tui_vertical_disassem_scroll (FORWARD_SCROLL, _num_to_scroll); | |
602 | else if (win_to_scroll == TUI_DATA_WIN) | |
603 | tui_vertical_data_scroll (FORWARD_SCROLL, _num_to_scroll); | |
c906108c | 604 | } |
a21fcd8f | 605 | } |
c906108c | 606 | |
c906108c | 607 | void |
08ef48c5 MS |
608 | tui_scroll_backward (struct tui_win_info *win_to_scroll, |
609 | int num_to_scroll) | |
c906108c | 610 | { |
6ba8e26f | 611 | if (win_to_scroll != TUI_CMD_WIN) |
c906108c | 612 | { |
6ba8e26f | 613 | int _num_to_scroll = num_to_scroll; |
c906108c | 614 | |
6ba8e26f AC |
615 | if (num_to_scroll == 0) |
616 | _num_to_scroll = win_to_scroll->generic.height - 3; | |
ef5eab5a MS |
617 | |
618 | /* If we are scrolling the source or disassembly window, do a | |
619 | "psuedo" scroll since not all of the source is in memory, | |
620 | only what is in the viewport. If win_to_scroll is the | |
621 | command window do nothing since the term should handle | |
622 | it. */ | |
6ba8e26f AC |
623 | if (win_to_scroll == TUI_SRC_WIN) |
624 | tui_vertical_source_scroll (BACKWARD_SCROLL, _num_to_scroll); | |
625 | else if (win_to_scroll == TUI_DISASM_WIN) | |
626 | tui_vertical_disassem_scroll (BACKWARD_SCROLL, _num_to_scroll); | |
627 | else if (win_to_scroll == TUI_DATA_WIN) | |
628 | tui_vertical_data_scroll (BACKWARD_SCROLL, _num_to_scroll); | |
c906108c | 629 | } |
a21fcd8f | 630 | } |
c906108c SS |
631 | |
632 | ||
c906108c | 633 | void |
08ef48c5 MS |
634 | tui_scroll_left (struct tui_win_info *win_to_scroll, |
635 | int num_to_scroll) | |
c906108c | 636 | { |
6ba8e26f | 637 | if (win_to_scroll != TUI_CMD_WIN) |
c906108c | 638 | { |
6ba8e26f | 639 | int _num_to_scroll = num_to_scroll; |
c906108c | 640 | |
6ba8e26f AC |
641 | if (_num_to_scroll == 0) |
642 | _num_to_scroll = 1; | |
ef5eab5a MS |
643 | |
644 | /* If we are scrolling the source or disassembly window, do a | |
645 | "psuedo" scroll since not all of the source is in memory, | |
646 | only what is in the viewport. If win_to_scroll is the command | |
647 | window do nothing since the term should handle it. */ | |
e5908723 MS |
648 | if (win_to_scroll == TUI_SRC_WIN |
649 | || win_to_scroll == TUI_DISASM_WIN) | |
9a2b4c1b MS |
650 | tui_horizontal_source_scroll (win_to_scroll, LEFT_SCROLL, |
651 | _num_to_scroll); | |
c906108c | 652 | } |
a21fcd8f | 653 | } |
c906108c SS |
654 | |
655 | ||
c906108c | 656 | void |
08ef48c5 MS |
657 | tui_scroll_right (struct tui_win_info *win_to_scroll, |
658 | int num_to_scroll) | |
c906108c | 659 | { |
6ba8e26f | 660 | if (win_to_scroll != TUI_CMD_WIN) |
c906108c | 661 | { |
6ba8e26f | 662 | int _num_to_scroll = num_to_scroll; |
c906108c | 663 | |
6ba8e26f AC |
664 | if (_num_to_scroll == 0) |
665 | _num_to_scroll = 1; | |
ef5eab5a MS |
666 | |
667 | /* If we are scrolling the source or disassembly window, do a | |
668 | "psuedo" scroll since not all of the source is in memory, | |
669 | only what is in the viewport. If win_to_scroll is the command | |
670 | window do nothing since the term should handle it. */ | |
e5908723 MS |
671 | if (win_to_scroll == TUI_SRC_WIN |
672 | || win_to_scroll == TUI_DISASM_WIN) | |
9a2b4c1b MS |
673 | tui_horizontal_source_scroll (win_to_scroll, RIGHT_SCROLL, |
674 | _num_to_scroll); | |
c906108c | 675 | } |
a21fcd8f | 676 | } |
c906108c SS |
677 | |
678 | ||
1cc6d956 | 679 | /* Scroll a window. Arguments are passed through a va_list. */ |
c906108c | 680 | void |
2a8854a7 | 681 | tui_scroll (enum tui_scroll_direction direction, |
5b6fe301 | 682 | struct tui_win_info *win_to_scroll, |
6ba8e26f | 683 | int num_to_scroll) |
c906108c | 684 | { |
c906108c SS |
685 | switch (direction) |
686 | { | |
687 | case FORWARD_SCROLL: | |
6ba8e26f | 688 | tui_scroll_forward (win_to_scroll, num_to_scroll); |
c906108c SS |
689 | break; |
690 | case BACKWARD_SCROLL: | |
6ba8e26f | 691 | tui_scroll_backward (win_to_scroll, num_to_scroll); |
c906108c SS |
692 | break; |
693 | case LEFT_SCROLL: | |
6ba8e26f | 694 | tui_scroll_left (win_to_scroll, num_to_scroll); |
c906108c SS |
695 | break; |
696 | case RIGHT_SCROLL: | |
6ba8e26f | 697 | tui_scroll_right (win_to_scroll, num_to_scroll); |
c906108c SS |
698 | break; |
699 | default: | |
700 | break; | |
701 | } | |
e8b915dc | 702 | } |
c906108c SS |
703 | |
704 | ||
c906108c | 705 | void |
a21fcd8f | 706 | tui_refresh_all_win (void) |
c906108c | 707 | { |
570dc176 | 708 | int type; |
c906108c | 709 | |
3e266828 | 710 | clearok (curscr, TRUE); |
6d012f14 | 711 | tui_refresh_all (tui_win_list); |
c906108c SS |
712 | for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++) |
713 | { | |
e5908723 MS |
714 | if (tui_win_list[type] |
715 | && tui_win_list[type]->generic.is_visible) | |
c906108c SS |
716 | { |
717 | switch (type) | |
718 | { | |
719 | case SRC_WIN: | |
720 | case DISASSEM_WIN: | |
6d012f14 AC |
721 | tui_show_source_content (tui_win_list[type]); |
722 | tui_check_and_display_highlight_if_needed (tui_win_list[type]); | |
723 | tui_erase_exec_info_content (tui_win_list[type]); | |
724 | tui_update_exec_info (tui_win_list[type]); | |
c906108c SS |
725 | break; |
726 | case DATA_WIN: | |
edae1ccf | 727 | tui_refresh_data_win (); |
c906108c SS |
728 | break; |
729 | default: | |
730 | break; | |
731 | } | |
732 | } | |
733 | } | |
47d3492a | 734 | tui_show_locator_content (); |
bc712bbf | 735 | } |
c906108c | 736 | |
6cdb25f4 EZ |
737 | void |
738 | tui_rehighlight_all (void) | |
739 | { | |
570dc176 | 740 | int type; |
6cdb25f4 EZ |
741 | |
742 | for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++) | |
743 | tui_check_and_display_highlight_if_needed (tui_win_list[type]); | |
744 | } | |
c906108c | 745 | |
b021a221 MS |
746 | /* Resize all the windows based on the terminal size. This function |
747 | gets called from within the readline sinwinch handler. */ | |
c906108c | 748 | void |
6ba8e26f | 749 | tui_resize_all (void) |
c906108c | 750 | { |
6ba8e26f | 751 | int height_diff, width_diff; |
9255ee31 | 752 | int screenheight, screenwidth; |
c906108c | 753 | |
9255ee31 | 754 | rl_get_screen_size (&screenheight, &screenwidth); |
6ba8e26f AC |
755 | width_diff = screenwidth - tui_term_width (); |
756 | height_diff = screenheight - tui_term_height (); | |
757 | if (height_diff || width_diff) | |
c906108c | 758 | { |
6ba8e26f | 759 | enum tui_layout_type cur_layout = tui_current_layout (); |
5b6fe301 | 760 | struct tui_win_info *win_with_focus = tui_win_with_focus (); |
6ba8e26f AC |
761 | struct tui_win_info *first_win; |
762 | struct tui_win_info *second_win; | |
5b6fe301 | 763 | struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); |
570dc176 | 764 | int win_type; |
6ba8e26f | 765 | int new_height, split_diff, cmd_split_diff, num_wins_displayed = 2; |
c906108c | 766 | |
10f59415 SC |
767 | #ifdef HAVE_RESIZE_TERM |
768 | resize_term (screenheight, screenwidth); | |
769 | #endif | |
1cc6d956 | 770 | /* Turn keypad off while we resize. */ |
6ba8e26f | 771 | if (win_with_focus != TUI_CMD_WIN) |
6d012f14 | 772 | keypad (TUI_CMD_WIN->generic.handle, FALSE); |
3e752b04 | 773 | tui_update_gdb_sizes (); |
dd1abb8c AC |
774 | tui_set_term_height_to (screenheight); |
775 | tui_set_term_width_to (screenwidth); | |
e5908723 MS |
776 | if (cur_layout == SRC_DISASSEM_COMMAND |
777 | || cur_layout == SRC_DATA_COMMAND | |
778 | || cur_layout == DISASSEM_DATA_COMMAND) | |
6ba8e26f AC |
779 | num_wins_displayed++; |
780 | split_diff = height_diff / num_wins_displayed; | |
781 | cmd_split_diff = split_diff; | |
782 | if (height_diff % num_wins_displayed) | |
c906108c | 783 | { |
6ba8e26f AC |
784 | if (height_diff < 0) |
785 | cmd_split_diff--; | |
c906108c | 786 | else |
c366c1f0 TT |
787 | cmd_split_diff++; |
788 | } | |
1cc6d956 | 789 | /* Now adjust each window. */ |
c366c1f0 TT |
790 | /* erase + clearok are used instead of a straightforward clear as |
791 | AIX 5.3 does not define clear. */ | |
792 | erase (); | |
793 | clearok (curscr, TRUE); | |
c906108c | 794 | refresh (); |
6ba8e26f | 795 | switch (cur_layout) |
c366c1f0 | 796 | { |
c906108c SS |
797 | case SRC_COMMAND: |
798 | case DISASSEM_COMMAND: | |
6ba8e26f AC |
799 | first_win = (struct tui_win_info *) (tui_source_windows ())->list[0]; |
800 | first_win->generic.width += width_diff; | |
801 | locator->width += width_diff; | |
1cc6d956 | 802 | /* Check for invalid heights. */ |
6ba8e26f AC |
803 | if (height_diff == 0) |
804 | new_height = first_win->generic.height; | |
805 | else if ((first_win->generic.height + split_diff) >= | |
c906108c | 806 | (screenheight - MIN_CMD_WIN_HEIGHT - 1)) |
6ba8e26f AC |
807 | new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1; |
808 | else if ((first_win->generic.height + split_diff) <= 0) | |
809 | new_height = MIN_WIN_HEIGHT; | |
c906108c | 810 | else |
6ba8e26f | 811 | new_height = first_win->generic.height + split_diff; |
c906108c | 812 | |
0036e657 | 813 | locator->origin.y = new_height + 1; |
6ba8e26f | 814 | make_invisible_and_set_new_height (first_win, new_height); |
6d012f14 | 815 | TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1; |
6ba8e26f AC |
816 | TUI_CMD_WIN->generic.width += width_diff; |
817 | new_height = screenheight - TUI_CMD_WIN->generic.origin.y; | |
818 | make_invisible_and_set_new_height (TUI_CMD_WIN, new_height); | |
819 | make_visible_with_new_height (first_win); | |
820 | make_visible_with_new_height (TUI_CMD_WIN); | |
821 | if (first_win->generic.content_size <= 0) | |
822 | tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT); | |
c906108c SS |
823 | break; |
824 | default: | |
6ba8e26f | 825 | if (cur_layout == SRC_DISASSEM_COMMAND) |
c906108c | 826 | { |
6ba8e26f AC |
827 | first_win = TUI_SRC_WIN; |
828 | first_win->generic.width += width_diff; | |
829 | second_win = TUI_DISASM_WIN; | |
830 | second_win->generic.width += width_diff; | |
c906108c SS |
831 | } |
832 | else | |
833 | { | |
6ba8e26f AC |
834 | first_win = TUI_DATA_WIN; |
835 | first_win->generic.width += width_diff; | |
9a2b4c1b MS |
836 | second_win = (struct tui_win_info *) |
837 | (tui_source_windows ())->list[0]; | |
6ba8e26f | 838 | second_win->generic.width += width_diff; |
c906108c | 839 | } |
1cc6d956 MS |
840 | /* Change the first window's height/width. */ |
841 | /* Check for invalid heights. */ | |
6ba8e26f AC |
842 | if (height_diff == 0) |
843 | new_height = first_win->generic.height; | |
844 | else if ((first_win->generic.height + | |
845 | second_win->generic.height + (split_diff * 2)) >= | |
c906108c | 846 | (screenheight - MIN_CMD_WIN_HEIGHT - 1)) |
6ba8e26f AC |
847 | new_height = (screenheight - MIN_CMD_WIN_HEIGHT - 1) / 2; |
848 | else if ((first_win->generic.height + split_diff) <= 0) | |
849 | new_height = MIN_WIN_HEIGHT; | |
c906108c | 850 | else |
6ba8e26f AC |
851 | new_height = first_win->generic.height + split_diff; |
852 | make_invisible_and_set_new_height (first_win, new_height); | |
c906108c | 853 | |
6ba8e26f | 854 | locator->width += width_diff; |
c906108c | 855 | |
1cc6d956 MS |
856 | /* Change the second window's height/width. */ |
857 | /* Check for invalid heights. */ | |
6ba8e26f AC |
858 | if (height_diff == 0) |
859 | new_height = second_win->generic.height; | |
860 | else if ((first_win->generic.height + | |
861 | second_win->generic.height + (split_diff * 2)) >= | |
c906108c SS |
862 | (screenheight - MIN_CMD_WIN_HEIGHT - 1)) |
863 | { | |
6ba8e26f AC |
864 | new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1; |
865 | if (new_height % 2) | |
866 | new_height = (new_height / 2) + 1; | |
c906108c | 867 | else |
6ba8e26f | 868 | new_height /= 2; |
c906108c | 869 | } |
6ba8e26f AC |
870 | else if ((second_win->generic.height + split_diff) <= 0) |
871 | new_height = MIN_WIN_HEIGHT; | |
c906108c | 872 | else |
6ba8e26f AC |
873 | new_height = second_win->generic.height + split_diff; |
874 | second_win->generic.origin.y = first_win->generic.height - 1; | |
875 | make_invisible_and_set_new_height (second_win, new_height); | |
c906108c | 876 | |
1cc6d956 | 877 | /* Change the command window's height/width. */ |
6d012f14 | 878 | TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1; |
9a2b4c1b MS |
879 | make_invisible_and_set_new_height (TUI_CMD_WIN, |
880 | TUI_CMD_WIN->generic.height | |
881 | + cmd_split_diff); | |
6ba8e26f AC |
882 | make_visible_with_new_height (first_win); |
883 | make_visible_with_new_height (second_win); | |
884 | make_visible_with_new_height (TUI_CMD_WIN); | |
885 | if (first_win->generic.content_size <= 0) | |
886 | tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT); | |
887 | if (second_win->generic.content_size <= 0) | |
888 | tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT); | |
c906108c SS |
889 | break; |
890 | } | |
ef5eab5a MS |
891 | /* Now remove all invisible windows, and their content so that |
892 | they get created again when called for with the new size. */ | |
6ba8e26f | 893 | for (win_type = SRC_WIN; (win_type < MAX_MAJOR_WINDOWS); win_type++) |
c906108c | 894 | { |
e5908723 MS |
895 | if (win_type != CMD_WIN |
896 | && (tui_win_list[win_type] != NULL) | |
6ba8e26f | 897 | && !tui_win_list[win_type]->generic.is_visible) |
c906108c | 898 | { |
6ba8e26f | 899 | tui_free_window (tui_win_list[win_type]); |
e65b5245 | 900 | tui_win_list[win_type] = NULL; |
c906108c SS |
901 | } |
902 | } | |
1cc6d956 MS |
903 | /* Turn keypad back on, unless focus is in the command |
904 | window. */ | |
6ba8e26f | 905 | if (win_with_focus != TUI_CMD_WIN) |
6d012f14 | 906 | keypad (TUI_CMD_WIN->generic.handle, TRUE); |
c906108c | 907 | } |
6ba8e26f | 908 | } |
c906108c | 909 | |
2c0b251b | 910 | #ifdef SIGWINCH |
c4ef48c6 PP |
911 | /* Token for use by TUI's asynchronous SIGWINCH handler. */ |
912 | static struct async_signal_handler *tui_sigwinch_token; | |
913 | ||
914 | /* TUI's SIGWINCH signal handler. */ | |
2c0b251b | 915 | static void |
6ba8e26f | 916 | tui_sigwinch_handler (int signal) |
c906108c | 917 | { |
c4ef48c6 | 918 | mark_async_signal_handler (tui_sigwinch_token); |
dd1abb8c | 919 | tui_set_win_resized_to (TRUE); |
6ba8e26f | 920 | } |
c4ef48c6 PP |
921 | |
922 | /* Callback for asynchronously resizing TUI following a SIGWINCH signal. */ | |
923 | static void | |
924 | tui_async_resize_screen (gdb_client_data arg) | |
925 | { | |
a88d0bb3 PP |
926 | rl_resize_terminal (); |
927 | ||
c4ef48c6 | 928 | if (!tui_active) |
a88d0bb3 PP |
929 | { |
930 | int screen_height, screen_width; | |
c4ef48c6 | 931 | |
a88d0bb3 PP |
932 | rl_get_screen_size (&screen_height, &screen_width); |
933 | set_screen_width_and_height (screen_width, screen_height); | |
934 | ||
935 | /* win_resized is left set so that the next call to tui_enable() | |
936 | resizes the TUI windows. */ | |
937 | } | |
938 | else | |
939 | { | |
1e04046d | 940 | tui_set_win_resized_to (FALSE); |
a88d0bb3 PP |
941 | tui_resize_all (); |
942 | tui_refresh_all_win (); | |
943 | tui_update_gdb_sizes (); | |
a88d0bb3 PP |
944 | tui_redisplay_readline (); |
945 | } | |
c4ef48c6 | 946 | } |
2c0b251b | 947 | #endif |
c906108c | 948 | |
c4ef48c6 PP |
949 | /* Initialize TUI's SIGWINCH signal handler. Note that the handler is not |
950 | uninstalled when we exit TUI, so the handler should not assume that TUI is | |
951 | always active. */ | |
9612b5ec UW |
952 | void |
953 | tui_initialize_win (void) | |
954 | { | |
955 | #ifdef SIGWINCH | |
c4ef48c6 PP |
956 | tui_sigwinch_token |
957 | = create_async_signal_handler (tui_async_resize_screen, NULL); | |
958 | ||
959 | { | |
9612b5ec | 960 | #ifdef HAVE_SIGACTION |
c4ef48c6 | 961 | struct sigaction old_winch; |
1c5313c5 | 962 | |
c4ef48c6 PP |
963 | memset (&old_winch, 0, sizeof (old_winch)); |
964 | old_winch.sa_handler = &tui_sigwinch_handler; | |
a344fc09 | 965 | #ifdef SA_RESTART |
c4ef48c6 | 966 | old_winch.sa_flags = SA_RESTART; |
a344fc09 | 967 | #endif |
c4ef48c6 | 968 | sigaction (SIGWINCH, &old_winch, NULL); |
9612b5ec | 969 | #else |
c4ef48c6 | 970 | signal (SIGWINCH, &tui_sigwinch_handler); |
9612b5ec | 971 | #endif |
c4ef48c6 | 972 | } |
9612b5ec UW |
973 | #endif |
974 | } | |
c906108c SS |
975 | |
976 | ||
977 | /************************* | |
978 | ** STATIC LOCAL FUNCTIONS | |
979 | **************************/ | |
980 | ||
981 | ||
c906108c | 982 | static void |
6ba8e26f | 983 | tui_scroll_forward_command (char *arg, int from_tty) |
c906108c | 984 | { |
6ba8e26f | 985 | int num_to_scroll = 1; |
5b6fe301 | 986 | struct tui_win_info *win_to_scroll; |
c906108c | 987 | |
1854bb21 SC |
988 | /* Make sure the curses mode is enabled. */ |
989 | tui_enable (); | |
c906108c | 990 | if (arg == (char *) NULL) |
6ba8e26f | 991 | parse_scrolling_args (arg, &win_to_scroll, (int *) NULL); |
c906108c | 992 | else |
6ba8e26f AC |
993 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
994 | tui_scroll (FORWARD_SCROLL, win_to_scroll, num_to_scroll); | |
e8b915dc | 995 | } |
c906108c SS |
996 | |
997 | ||
c906108c | 998 | static void |
6ba8e26f | 999 | tui_scroll_backward_command (char *arg, int from_tty) |
c906108c | 1000 | { |
6ba8e26f | 1001 | int num_to_scroll = 1; |
5b6fe301 | 1002 | struct tui_win_info *win_to_scroll; |
c906108c | 1003 | |
1854bb21 SC |
1004 | /* Make sure the curses mode is enabled. */ |
1005 | tui_enable (); | |
c906108c | 1006 | if (arg == (char *) NULL) |
6ba8e26f | 1007 | parse_scrolling_args (arg, &win_to_scroll, (int *) NULL); |
c906108c | 1008 | else |
6ba8e26f AC |
1009 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
1010 | tui_scroll (BACKWARD_SCROLL, win_to_scroll, num_to_scroll); | |
e8b915dc | 1011 | } |
c906108c SS |
1012 | |
1013 | ||
c906108c | 1014 | static void |
6ba8e26f | 1015 | tui_scroll_left_command (char *arg, int from_tty) |
c906108c | 1016 | { |
6ba8e26f | 1017 | int num_to_scroll; |
5b6fe301 | 1018 | struct tui_win_info *win_to_scroll; |
c906108c | 1019 | |
1854bb21 SC |
1020 | /* Make sure the curses mode is enabled. */ |
1021 | tui_enable (); | |
6ba8e26f AC |
1022 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
1023 | tui_scroll (LEFT_SCROLL, win_to_scroll, num_to_scroll); | |
e8b915dc | 1024 | } |
c906108c SS |
1025 | |
1026 | ||
c906108c | 1027 | static void |
6ba8e26f | 1028 | tui_scroll_right_command (char *arg, int from_tty) |
c906108c | 1029 | { |
6ba8e26f | 1030 | int num_to_scroll; |
5b6fe301 | 1031 | struct tui_win_info *win_to_scroll; |
c906108c | 1032 | |
1854bb21 SC |
1033 | /* Make sure the curses mode is enabled. */ |
1034 | tui_enable (); | |
6ba8e26f AC |
1035 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
1036 | tui_scroll (RIGHT_SCROLL, win_to_scroll, num_to_scroll); | |
e8b915dc | 1037 | } |
c906108c SS |
1038 | |
1039 | ||
6ba8e26f | 1040 | /* Set focus to the window named by 'arg'. */ |
c906108c | 1041 | static void |
6ba8e26f | 1042 | tui_set_focus (char *arg, int from_tty) |
c906108c SS |
1043 | { |
1044 | if (arg != (char *) NULL) | |
1045 | { | |
6ba8e26f | 1046 | char *buf_ptr = (char *) xstrdup (arg); |
c906108c | 1047 | int i; |
e65b5245 | 1048 | struct tui_win_info *win_info = NULL; |
c906108c | 1049 | |
6ba8e26f | 1050 | for (i = 0; (i < strlen (buf_ptr)); i++) |
6dce28e4 | 1051 | buf_ptr[i] = tolower (arg[i]); |
c906108c | 1052 | |
6dce28e4 | 1053 | if (subset_compare (buf_ptr, "next")) |
6d012f14 | 1054 | win_info = tui_next_win (tui_win_with_focus ()); |
6dce28e4 | 1055 | else if (subset_compare (buf_ptr, "prev")) |
6d012f14 | 1056 | win_info = tui_prev_win (tui_win_with_focus ()); |
c906108c | 1057 | else |
6ba8e26f | 1058 | win_info = tui_partial_win_by_name (buf_ptr); |
c906108c | 1059 | |
e5908723 MS |
1060 | if (win_info == (struct tui_win_info *) NULL |
1061 | || !win_info->generic.is_visible) | |
8a3fe4f8 AC |
1062 | warning (_("Invalid window specified. \n\ |
1063 | The window name specified must be valid and visible.\n")); | |
c906108c SS |
1064 | else |
1065 | { | |
6d012f14 AC |
1066 | tui_set_win_focus_to (win_info); |
1067 | keypad (TUI_CMD_WIN->generic.handle, (win_info != TUI_CMD_WIN)); | |
c906108c SS |
1068 | } |
1069 | ||
6d012f14 | 1070 | if (TUI_DATA_WIN && TUI_DATA_WIN->generic.is_visible) |
edae1ccf | 1071 | tui_refresh_data_win (); |
6ba8e26f | 1072 | xfree (buf_ptr); |
a3f17187 | 1073 | printf_filtered (_("Focus set to %s window.\n"), |
10e9aaa3 | 1074 | tui_win_name (&tui_win_with_focus ()->generic)); |
c906108c SS |
1075 | } |
1076 | else | |
8a3fe4f8 | 1077 | warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE); |
6ba8e26f | 1078 | } |
c906108c | 1079 | |
c906108c | 1080 | static void |
6ba8e26f | 1081 | tui_set_focus_command (char *arg, int from_tty) |
c906108c | 1082 | { |
1854bb21 SC |
1083 | /* Make sure the curses mode is enabled. */ |
1084 | tui_enable (); | |
6ba8e26f | 1085 | tui_set_focus (arg, from_tty); |
e8b915dc | 1086 | } |
c906108c SS |
1087 | |
1088 | ||
c906108c | 1089 | static void |
6ba8e26f | 1090 | tui_all_windows_info (char *arg, int from_tty) |
c906108c | 1091 | { |
570dc176 | 1092 | int type; |
5b6fe301 | 1093 | struct tui_win_info *win_with_focus = tui_win_with_focus (); |
c906108c SS |
1094 | |
1095 | for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++) | |
e5908723 MS |
1096 | if (tui_win_list[type] |
1097 | && tui_win_list[type]->generic.is_visible) | |
c906108c | 1098 | { |
6ba8e26f | 1099 | if (win_with_focus == tui_win_list[type]) |
c906108c | 1100 | printf_filtered (" %s\t(%d lines) <has focus>\n", |
6d012f14 AC |
1101 | tui_win_name (&tui_win_list[type]->generic), |
1102 | tui_win_list[type]->generic.height); | |
c906108c SS |
1103 | else |
1104 | printf_filtered (" %s\t(%d lines)\n", | |
6d012f14 AC |
1105 | tui_win_name (&tui_win_list[type]->generic), |
1106 | tui_win_list[type]->generic.height); | |
c906108c | 1107 | } |
6ba8e26f | 1108 | } |
c906108c SS |
1109 | |
1110 | ||
c906108c | 1111 | static void |
6ba8e26f | 1112 | tui_refresh_all_command (char *arg, int from_tty) |
c906108c | 1113 | { |
1854bb21 SC |
1114 | /* Make sure the curses mode is enabled. */ |
1115 | tui_enable (); | |
1116 | ||
a21fcd8f | 1117 | tui_refresh_all_win (); |
c906108c SS |
1118 | } |
1119 | ||
1120 | ||
c54da50d | 1121 | /* Set the tab width of the specified window. */ |
c906108c | 1122 | static void |
6ba8e26f | 1123 | tui_set_tab_width_command (char *arg, int from_tty) |
c906108c | 1124 | { |
1854bb21 SC |
1125 | /* Make sure the curses mode is enabled. */ |
1126 | tui_enable (); | |
c906108c SS |
1127 | if (arg != (char *) NULL) |
1128 | { | |
1129 | int ts; | |
1130 | ||
1131 | ts = atoi (arg); | |
1132 | if (ts > 0) | |
cb86fcc1 EZ |
1133 | { |
1134 | tui_set_default_tab_len (ts); | |
1135 | /* We don't really change the height of any windows, but | |
1136 | calling these 2 functions causes a complete regeneration | |
1137 | and redisplay of the window's contents, which will take | |
1138 | the new tab width into account. */ | |
1139 | if (tui_win_list[SRC_WIN] | |
1140 | && tui_win_list[SRC_WIN]->generic.is_visible) | |
1141 | { | |
1142 | make_invisible_and_set_new_height (TUI_SRC_WIN, | |
1143 | TUI_SRC_WIN->generic.height); | |
1144 | make_visible_with_new_height (TUI_SRC_WIN); | |
1145 | } | |
1146 | if (tui_win_list[DISASSEM_WIN] | |
1147 | && tui_win_list[DISASSEM_WIN]->generic.is_visible) | |
1148 | { | |
1149 | make_invisible_and_set_new_height (TUI_DISASM_WIN, | |
1150 | TUI_DISASM_WIN->generic.height); | |
1151 | make_visible_with_new_height (TUI_DISASM_WIN); | |
1152 | } | |
1153 | } | |
c906108c | 1154 | else |
8a3fe4f8 | 1155 | warning (_("Tab widths greater than 0 must be specified.")); |
c906108c | 1156 | } |
6ba8e26f | 1157 | } |
c906108c SS |
1158 | |
1159 | ||
1cc6d956 | 1160 | /* Set the height of the specified window. */ |
c906108c | 1161 | static void |
6ba8e26f | 1162 | tui_set_win_height (char *arg, int from_tty) |
c906108c | 1163 | { |
1854bb21 SC |
1164 | /* Make sure the curses mode is enabled. */ |
1165 | tui_enable (); | |
c906108c SS |
1166 | if (arg != (char *) NULL) |
1167 | { | |
f71c8822 TT |
1168 | std::string copy = arg; |
1169 | char *buf = ©[0]; | |
6ba8e26f | 1170 | char *buf_ptr = buf; |
e65b5245 | 1171 | char *wname = NULL; |
6ba8e26f | 1172 | int new_height, i; |
5b6fe301 | 1173 | struct tui_win_info *win_info; |
c906108c | 1174 | |
6ba8e26f AC |
1175 | wname = buf_ptr; |
1176 | buf_ptr = strchr (buf_ptr, ' '); | |
1177 | if (buf_ptr != (char *) NULL) | |
c906108c | 1178 | { |
6ba8e26f | 1179 | *buf_ptr = (char) 0; |
c906108c | 1180 | |
ef5eab5a | 1181 | /* Validate the window name. */ |
c906108c | 1182 | for (i = 0; i < strlen (wname); i++) |
6dce28e4 | 1183 | wname[i] = tolower (wname[i]); |
6d012f14 | 1184 | win_info = tui_partial_win_by_name (wname); |
c906108c | 1185 | |
e5908723 MS |
1186 | if (win_info == (struct tui_win_info *) NULL |
1187 | || !win_info->generic.is_visible) | |
8a3fe4f8 AC |
1188 | warning (_("Invalid window specified. \n\ |
1189 | The window name specified must be valid and visible.\n")); | |
c906108c SS |
1190 | else |
1191 | { | |
1cc6d956 | 1192 | /* Process the size. */ |
6ba8e26f | 1193 | while (*(++buf_ptr) == ' ') |
c906108c SS |
1194 | ; |
1195 | ||
6ba8e26f | 1196 | if (*buf_ptr != (char) 0) |
c906108c SS |
1197 | { |
1198 | int negate = FALSE; | |
6ba8e26f AC |
1199 | int fixed_size = TRUE; |
1200 | int input_no;; | |
c906108c | 1201 | |
6ba8e26f | 1202 | if (*buf_ptr == '+' || *buf_ptr == '-') |
c906108c | 1203 | { |
6ba8e26f | 1204 | if (*buf_ptr == '-') |
c906108c | 1205 | negate = TRUE; |
6ba8e26f AC |
1206 | fixed_size = FALSE; |
1207 | buf_ptr++; | |
c906108c | 1208 | } |
6ba8e26f AC |
1209 | input_no = atoi (buf_ptr); |
1210 | if (input_no > 0) | |
c906108c SS |
1211 | { |
1212 | if (negate) | |
6ba8e26f AC |
1213 | input_no *= (-1); |
1214 | if (fixed_size) | |
1215 | new_height = input_no; | |
c906108c | 1216 | else |
6ba8e26f | 1217 | new_height = win_info->generic.height + input_no; |
ef5eab5a MS |
1218 | |
1219 | /* Now change the window's height, and adjust | |
1220 | all other windows around it. */ | |
6ba8e26f AC |
1221 | if (tui_adjust_win_heights (win_info, |
1222 | new_height) == TUI_FAILURE) | |
8a3fe4f8 | 1223 | warning (_("Invalid window height specified.\n%s"), |
c906108c SS |
1224 | WIN_HEIGHT_USAGE); |
1225 | else | |
3e752b04 | 1226 | tui_update_gdb_sizes (); |
c906108c SS |
1227 | } |
1228 | else | |
8a3fe4f8 | 1229 | warning (_("Invalid window height specified.\n%s"), |
c906108c SS |
1230 | WIN_HEIGHT_USAGE); |
1231 | } | |
1232 | } | |
1233 | } | |
1234 | else | |
1235 | printf_filtered (WIN_HEIGHT_USAGE); | |
c906108c SS |
1236 | } |
1237 | else | |
1238 | printf_filtered (WIN_HEIGHT_USAGE); | |
6ba8e26f | 1239 | } |
c906108c | 1240 | |
1cc6d956 | 1241 | /* Set the height of the specified window, with va_list. */ |
c906108c | 1242 | static void |
6ba8e26f | 1243 | tui_set_win_height_command (char *arg, int from_tty) |
c906108c | 1244 | { |
1854bb21 SC |
1245 | /* Make sure the curses mode is enabled. */ |
1246 | tui_enable (); | |
6ba8e26f | 1247 | tui_set_win_height (arg, from_tty); |
e8b915dc | 1248 | } |
c906108c | 1249 | |
6ba8e26f | 1250 | /* Function to adjust all window heights around the primary. */ |
22940a24 | 1251 | static enum tui_status |
08ef48c5 MS |
1252 | tui_adjust_win_heights (struct tui_win_info *primary_win_info, |
1253 | int new_height) | |
c906108c | 1254 | { |
22940a24 | 1255 | enum tui_status status = TUI_FAILURE; |
c906108c | 1256 | |
6ba8e26f | 1257 | if (new_height_ok (primary_win_info, new_height)) |
c906108c SS |
1258 | { |
1259 | status = TUI_SUCCESS; | |
6ba8e26f | 1260 | if (new_height != primary_win_info->generic.height) |
c906108c | 1261 | { |
bc712bbf | 1262 | int diff; |
5b6fe301 MS |
1263 | struct tui_win_info *win_info; |
1264 | struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); | |
6ba8e26f | 1265 | enum tui_layout_type cur_layout = tui_current_layout (); |
c906108c | 1266 | |
6ba8e26f | 1267 | diff = (new_height - primary_win_info->generic.height) * (-1); |
e5908723 MS |
1268 | if (cur_layout == SRC_COMMAND |
1269 | || cur_layout == DISASSEM_COMMAND) | |
c906108c | 1270 | { |
5b6fe301 | 1271 | struct tui_win_info *src_win_info; |
c906108c | 1272 | |
6ba8e26f AC |
1273 | make_invisible_and_set_new_height (primary_win_info, new_height); |
1274 | if (primary_win_info->generic.type == CMD_WIN) | |
c906108c | 1275 | { |
96c1eda2 | 1276 | win_info = (tui_source_windows ())->list[0]; |
6ba8e26f | 1277 | src_win_info = win_info; |
c906108c SS |
1278 | } |
1279 | else | |
1280 | { | |
6d012f14 | 1281 | win_info = tui_win_list[CMD_WIN]; |
6ba8e26f | 1282 | src_win_info = primary_win_info; |
c906108c | 1283 | } |
6ba8e26f | 1284 | make_invisible_and_set_new_height (win_info, |
6d012f14 AC |
1285 | win_info->generic.height + diff); |
1286 | TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1; | |
6ba8e26f AC |
1287 | make_visible_with_new_height (win_info); |
1288 | make_visible_with_new_height (primary_win_info); | |
1289 | if (src_win_info->generic.content_size <= 0) | |
1290 | tui_erase_source_content (src_win_info, EMPTY_SOURCE_PROMPT); | |
c906108c SS |
1291 | } |
1292 | else | |
1293 | { | |
6ba8e26f AC |
1294 | struct tui_win_info *first_win; |
1295 | struct tui_win_info *second_win; | |
c906108c | 1296 | |
6ba8e26f | 1297 | if (cur_layout == SRC_DISASSEM_COMMAND) |
c906108c | 1298 | { |
6ba8e26f AC |
1299 | first_win = TUI_SRC_WIN; |
1300 | second_win = TUI_DISASM_WIN; | |
c906108c SS |
1301 | } |
1302 | else | |
1303 | { | |
6ba8e26f | 1304 | first_win = TUI_DATA_WIN; |
96c1eda2 | 1305 | second_win = (tui_source_windows ())->list[0]; |
c906108c | 1306 | } |
6ba8e26f | 1307 | if (primary_win_info == TUI_CMD_WIN) |
ef5eab5a MS |
1308 | { /* Split the change in height accross the 1st & 2nd |
1309 | windows, adjusting them as well. */ | |
1310 | /* Subtract the locator. */ | |
1311 | int first_split_diff = diff / 2; | |
6ba8e26f | 1312 | int second_split_diff = first_split_diff; |
c906108c SS |
1313 | |
1314 | if (diff % 2) | |
1315 | { | |
6ba8e26f AC |
1316 | if (first_win->generic.height > |
1317 | second_win->generic.height) | |
c906108c | 1318 | if (diff < 0) |
6ba8e26f | 1319 | first_split_diff--; |
c906108c | 1320 | else |
6ba8e26f | 1321 | first_split_diff++; |
c906108c SS |
1322 | else |
1323 | { | |
1324 | if (diff < 0) | |
6ba8e26f | 1325 | second_split_diff--; |
c906108c | 1326 | else |
6ba8e26f | 1327 | second_split_diff++; |
c906108c SS |
1328 | } |
1329 | } | |
1cc6d956 MS |
1330 | /* Make sure that the minimum hieghts are |
1331 | honored. */ | |
6ba8e26f | 1332 | while ((first_win->generic.height + first_split_diff) < 3) |
c906108c | 1333 | { |
6ba8e26f AC |
1334 | first_split_diff++; |
1335 | second_split_diff--; | |
c906108c | 1336 | } |
6ba8e26f | 1337 | while ((second_win->generic.height + second_split_diff) < 3) |
c906108c | 1338 | { |
6ba8e26f AC |
1339 | second_split_diff++; |
1340 | first_split_diff--; | |
c906108c | 1341 | } |
6ba8e26f AC |
1342 | make_invisible_and_set_new_height ( |
1343 | first_win, | |
1344 | first_win->generic.height + first_split_diff); | |
1345 | second_win->generic.origin.y = first_win->generic.height - 1; | |
9a2b4c1b MS |
1346 | make_invisible_and_set_new_height (second_win, |
1347 | second_win->generic.height | |
1348 | + second_split_diff); | |
6d012f14 | 1349 | TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1; |
6ba8e26f | 1350 | make_invisible_and_set_new_height (TUI_CMD_WIN, new_height); |
c906108c SS |
1351 | } |
1352 | else | |
1353 | { | |
6d012f14 | 1354 | if ((TUI_CMD_WIN->generic.height + diff) < 1) |
ef5eab5a MS |
1355 | { /* If there is no way to increase the command |
1356 | window take real estate from the 1st or 2nd | |
1357 | window. */ | |
6d012f14 | 1358 | if ((TUI_CMD_WIN->generic.height + diff) < 1) |
c906108c SS |
1359 | { |
1360 | int i; | |
1c5313c5 | 1361 | |
6d012f14 | 1362 | for (i = TUI_CMD_WIN->generic.height + diff; |
c906108c | 1363 | (i < 1); i++) |
6ba8e26f AC |
1364 | if (primary_win_info == first_win) |
1365 | second_win->generic.height--; | |
c906108c | 1366 | else |
6ba8e26f | 1367 | first_win->generic.height--; |
c906108c SS |
1368 | } |
1369 | } | |
6ba8e26f AC |
1370 | if (primary_win_info == first_win) |
1371 | make_invisible_and_set_new_height (first_win, new_height); | |
c906108c | 1372 | else |
6ba8e26f AC |
1373 | make_invisible_and_set_new_height ( |
1374 | first_win, | |
1375 | first_win->generic.height); | |
1376 | second_win->generic.origin.y = first_win->generic.height - 1; | |
1377 | if (primary_win_info == second_win) | |
1378 | make_invisible_and_set_new_height (second_win, new_height); | |
c906108c | 1379 | else |
6ba8e26f AC |
1380 | make_invisible_and_set_new_height ( |
1381 | second_win, second_win->generic.height); | |
6d012f14 AC |
1382 | TUI_CMD_WIN->generic.origin.y = locator->origin.y + 1; |
1383 | if ((TUI_CMD_WIN->generic.height + diff) < 1) | |
6ba8e26f | 1384 | make_invisible_and_set_new_height (TUI_CMD_WIN, 1); |
c906108c | 1385 | else |
9a2b4c1b MS |
1386 | make_invisible_and_set_new_height (TUI_CMD_WIN, |
1387 | TUI_CMD_WIN->generic.height + diff); | |
c906108c | 1388 | } |
6ba8e26f AC |
1389 | make_visible_with_new_height (TUI_CMD_WIN); |
1390 | make_visible_with_new_height (second_win); | |
1391 | make_visible_with_new_height (first_win); | |
1392 | if (first_win->generic.content_size <= 0) | |
1393 | tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT); | |
1394 | if (second_win->generic.content_size <= 0) | |
1395 | tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT); | |
c906108c SS |
1396 | } |
1397 | } | |
1398 | } | |
1399 | ||
1400 | return status; | |
6ba8e26f | 1401 | } |
c906108c SS |
1402 | |
1403 | ||
6ba8e26f | 1404 | /* Function make the target window (and auxillary windows associated |
1cc6d956 MS |
1405 | with the targer) invisible, and set the new height and |
1406 | location. */ | |
c906108c | 1407 | static void |
08ef48c5 MS |
1408 | make_invisible_and_set_new_height (struct tui_win_info *win_info, |
1409 | int height) | |
c906108c SS |
1410 | { |
1411 | int i; | |
5b6fe301 | 1412 | struct tui_gen_win_info *gen_win_info; |
c906108c | 1413 | |
6d012f14 AC |
1414 | tui_make_invisible (&win_info->generic); |
1415 | win_info->generic.height = height; | |
c906108c | 1416 | if (height > 1) |
6d012f14 | 1417 | win_info->generic.viewport_height = height - 1; |
c906108c | 1418 | else |
6d012f14 AC |
1419 | win_info->generic.viewport_height = height; |
1420 | if (win_info != TUI_CMD_WIN) | |
1421 | win_info->generic.viewport_height--; | |
c906108c | 1422 | |
1cc6d956 | 1423 | /* Now deal with the auxillary windows associated with win_info. */ |
6d012f14 | 1424 | switch (win_info->generic.type) |
c906108c SS |
1425 | { |
1426 | case SRC_WIN: | |
1427 | case DISASSEM_WIN: | |
6ba8e26f AC |
1428 | gen_win_info = win_info->detail.source_info.execution_info; |
1429 | tui_make_invisible (gen_win_info); | |
1430 | gen_win_info->height = height; | |
1431 | gen_win_info->origin.y = win_info->generic.origin.y; | |
c906108c | 1432 | if (height > 1) |
6ba8e26f | 1433 | gen_win_info->viewport_height = height - 1; |
c906108c | 1434 | else |
6ba8e26f | 1435 | gen_win_info->viewport_height = height; |
6d012f14 | 1436 | if (win_info != TUI_CMD_WIN) |
6ba8e26f | 1437 | gen_win_info->viewport_height--; |
c906108c | 1438 | |
6d012f14 | 1439 | if (tui_win_has_locator (win_info)) |
c906108c | 1440 | { |
6ba8e26f AC |
1441 | gen_win_info = tui_locator_win_info_ptr (); |
1442 | tui_make_invisible (gen_win_info); | |
1443 | gen_win_info->origin.y = win_info->generic.origin.y + height; | |
c906108c SS |
1444 | } |
1445 | break; | |
1446 | case DATA_WIN: | |
1cc6d956 | 1447 | /* Delete all data item windows. */ |
6d012f14 | 1448 | for (i = 0; i < win_info->generic.content_size; i++) |
c906108c | 1449 | { |
9a2b4c1b MS |
1450 | gen_win_info = (struct tui_gen_win_info *) |
1451 | &((struct tui_win_element *) | |
1452 | win_info->generic.content[i])->which_element.data_window; | |
6ba8e26f | 1453 | tui_delete_win (gen_win_info->handle); |
e65b5245 | 1454 | gen_win_info->handle = NULL; |
c906108c SS |
1455 | } |
1456 | break; | |
1457 | default: | |
1458 | break; | |
1459 | } | |
bc712bbf | 1460 | } |
c906108c SS |
1461 | |
1462 | ||
6ba8e26f AC |
1463 | /* Function to make the windows with new heights visible. This means |
1464 | re-creating the windows' content since the window had to be | |
1465 | destroyed to be made invisible. */ | |
c906108c | 1466 | static void |
5b6fe301 | 1467 | make_visible_with_new_height (struct tui_win_info *win_info) |
c906108c | 1468 | { |
c906108c SS |
1469 | struct symtab *s; |
1470 | ||
6d012f14 AC |
1471 | tui_make_visible (&win_info->generic); |
1472 | tui_check_and_display_highlight_if_needed (win_info); | |
1473 | switch (win_info->generic.type) | |
c906108c SS |
1474 | { |
1475 | case SRC_WIN: | |
1476 | case DISASSEM_WIN: | |
6d012f14 AC |
1477 | tui_free_win_content (win_info->detail.source_info.execution_info); |
1478 | tui_make_visible (win_info->detail.source_info.execution_info); | |
1479 | if (win_info->generic.content != NULL) | |
c906108c | 1480 | { |
13274fc3 | 1481 | struct gdbarch *gdbarch = win_info->detail.source_info.gdbarch; |
362c05fe | 1482 | struct tui_line_or_address line_or_addr; |
52575520 EZ |
1483 | struct symtab_and_line cursal |
1484 | = get_current_source_symtab_and_line (); | |
c906108c | 1485 | |
362c05fe | 1486 | line_or_addr = win_info->detail.source_info.start_line_or_addr; |
6d012f14 | 1487 | tui_free_win_content (&win_info->generic); |
13274fc3 UW |
1488 | tui_update_source_window (win_info, gdbarch, |
1489 | cursal.symtab, line_or_addr, TRUE); | |
c906108c | 1490 | } |
206415a3 | 1491 | else if (deprecated_safe_get_selected_frame () != NULL) |
c906108c | 1492 | { |
362c05fe | 1493 | struct tui_line_or_address line; |
9a2b4c1b MS |
1494 | struct symtab_and_line cursal |
1495 | = get_current_source_symtab_and_line (); | |
206415a3 | 1496 | struct frame_info *frame = deprecated_safe_get_selected_frame (); |
13274fc3 | 1497 | struct gdbarch *gdbarch = get_frame_arch (frame); |
52575520 | 1498 | |
34248c3a | 1499 | s = find_pc_line_symtab (get_frame_pc (frame)); |
6d012f14 | 1500 | if (win_info->generic.type == SRC_WIN) |
362c05fe AS |
1501 | { |
1502 | line.loa = LOA_LINE; | |
1503 | line.u.line_no = cursal.line; | |
1504 | } | |
c906108c | 1505 | else |
84b1e7c7 | 1506 | { |
362c05fe AS |
1507 | line.loa = LOA_ADDRESS; |
1508 | find_line_pc (s, cursal.line, &line.u.addr); | |
84b1e7c7 | 1509 | } |
13274fc3 | 1510 | tui_update_source_window (win_info, gdbarch, s, line, TRUE); |
c906108c | 1511 | } |
6d012f14 | 1512 | if (tui_win_has_locator (win_info)) |
c906108c | 1513 | { |
dd1abb8c | 1514 | tui_make_visible (tui_locator_win_info_ptr ()); |
47d3492a | 1515 | tui_show_locator_content (); |
c906108c SS |
1516 | } |
1517 | break; | |
1518 | case DATA_WIN: | |
edae1ccf | 1519 | tui_display_all_data (); |
c906108c SS |
1520 | break; |
1521 | case CMD_WIN: | |
110ed339 | 1522 | #ifdef HAVE_WRESIZE |
d27b3be4 PA |
1523 | wresize (TUI_CMD_WIN->generic.handle, |
1524 | TUI_CMD_WIN->generic.height, | |
1525 | TUI_CMD_WIN->generic.width); | |
110ed339 | 1526 | #endif |
d27b3be4 PA |
1527 | mvwin (TUI_CMD_WIN->generic.handle, |
1528 | TUI_CMD_WIN->generic.origin.y, | |
1529 | TUI_CMD_WIN->generic.origin.x); | |
6f1cb6ea | 1530 | wmove (win_info->generic.handle, 0, 0); |
c906108c SS |
1531 | break; |
1532 | default: | |
1533 | break; | |
1534 | } | |
6ba8e26f | 1535 | } |
c906108c SS |
1536 | |
1537 | ||
1538 | static int | |
08ef48c5 MS |
1539 | new_height_ok (struct tui_win_info *primary_win_info, |
1540 | int new_height) | |
c906108c | 1541 | { |
6ba8e26f | 1542 | int ok = (new_height < tui_term_height ()); |
c906108c SS |
1543 | |
1544 | if (ok) | |
1545 | { | |
bc712bbf | 1546 | int diff; |
6d012f14 | 1547 | enum tui_layout_type cur_layout = tui_current_layout (); |
c906108c | 1548 | |
6ba8e26f | 1549 | diff = (new_height - primary_win_info->generic.height) * (-1); |
6d012f14 | 1550 | if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND) |
c906108c | 1551 | { |
e5908723 MS |
1552 | ok = ((primary_win_info->generic.type == CMD_WIN |
1553 | && new_height <= (tui_term_height () - 4) | |
1554 | && new_height >= MIN_CMD_WIN_HEIGHT) | |
1555 | || (primary_win_info->generic.type != CMD_WIN | |
1556 | && new_height <= (tui_term_height () - 2) | |
1557 | && new_height >= MIN_WIN_HEIGHT)); | |
c906108c | 1558 | if (ok) |
1cc6d956 | 1559 | { /* Check the total height. */ |
5b6fe301 | 1560 | struct tui_win_info *win_info; |
c906108c | 1561 | |
6ba8e26f | 1562 | if (primary_win_info == TUI_CMD_WIN) |
96c1eda2 | 1563 | win_info = (tui_source_windows ())->list[0]; |
c906108c | 1564 | else |
6d012f14 | 1565 | win_info = TUI_CMD_WIN; |
6ba8e26f | 1566 | ok = ((new_height + |
6d012f14 | 1567 | (win_info->generic.height + diff)) <= tui_term_height ()); |
c906108c SS |
1568 | } |
1569 | } | |
1570 | else | |
1571 | { | |
6ba8e26f AC |
1572 | int cur_total_height, total_height, min_height = 0; |
1573 | struct tui_win_info *first_win; | |
1574 | struct tui_win_info *second_win; | |
c906108c | 1575 | |
6d012f14 | 1576 | if (cur_layout == SRC_DISASSEM_COMMAND) |
c906108c | 1577 | { |
6ba8e26f AC |
1578 | first_win = TUI_SRC_WIN; |
1579 | second_win = TUI_DISASM_WIN; | |
c906108c SS |
1580 | } |
1581 | else | |
1582 | { | |
6ba8e26f | 1583 | first_win = TUI_DATA_WIN; |
96c1eda2 | 1584 | second_win = (tui_source_windows ())->list[0]; |
c906108c | 1585 | } |
ef5eab5a MS |
1586 | /* We could simply add all the heights to obtain the same |
1587 | result but below is more explicit since we subtract 1 for | |
1588 | the line that the first and second windows share, and add | |
1589 | one for the locator. */ | |
6ba8e26f AC |
1590 | total_height = cur_total_height = |
1591 | (first_win->generic.height + second_win->generic.height - 1) | |
1cc6d956 | 1592 | + TUI_CMD_WIN->generic.height + 1; /* Locator. */ |
6ba8e26f | 1593 | if (primary_win_info == TUI_CMD_WIN) |
c906108c | 1594 | { |
1cc6d956 | 1595 | /* Locator included since first & second win share a line. */ |
6ba8e26f AC |
1596 | ok = ((first_win->generic.height + |
1597 | second_win->generic.height + diff) >= | |
e5908723 MS |
1598 | (MIN_WIN_HEIGHT * 2) |
1599 | && new_height >= MIN_CMD_WIN_HEIGHT); | |
c906108c SS |
1600 | if (ok) |
1601 | { | |
e5908723 MS |
1602 | total_height = new_height + |
1603 | (first_win->generic.height + | |
1604 | second_win->generic.height + diff); | |
6ba8e26f | 1605 | min_height = MIN_CMD_WIN_HEIGHT; |
c906108c SS |
1606 | } |
1607 | } | |
1608 | else | |
1609 | { | |
6ba8e26f | 1610 | min_height = MIN_WIN_HEIGHT; |
ef5eab5a MS |
1611 | |
1612 | /* First see if we can increase/decrease the command | |
1613 | window. And make sure that the command window is at | |
1614 | least 1 line. */ | |
6d012f14 | 1615 | ok = ((TUI_CMD_WIN->generic.height + diff) > 0); |
c906108c | 1616 | if (!ok) |
ef5eab5a MS |
1617 | { /* Looks like we have to increase/decrease one of |
1618 | the other windows. */ | |
6ba8e26f AC |
1619 | if (primary_win_info == first_win) |
1620 | ok = (second_win->generic.height + diff) >= min_height; | |
c906108c | 1621 | else |
6ba8e26f | 1622 | ok = (first_win->generic.height + diff) >= min_height; |
c906108c SS |
1623 | } |
1624 | if (ok) | |
1625 | { | |
6ba8e26f AC |
1626 | if (primary_win_info == first_win) |
1627 | total_height = new_height + | |
1628 | second_win->generic.height + | |
6d012f14 | 1629 | TUI_CMD_WIN->generic.height + diff; |
c906108c | 1630 | else |
6ba8e26f AC |
1631 | total_height = new_height + |
1632 | first_win->generic.height + | |
6d012f14 | 1633 | TUI_CMD_WIN->generic.height + diff; |
c906108c SS |
1634 | } |
1635 | } | |
ef5eab5a MS |
1636 | /* Now make sure that the proposed total height doesn't |
1637 | exceed the old total height. */ | |
c906108c | 1638 | if (ok) |
e5908723 MS |
1639 | ok = (new_height >= min_height |
1640 | && total_height <= cur_total_height); | |
c906108c SS |
1641 | } |
1642 | } | |
1643 | ||
1644 | return ok; | |
6ba8e26f | 1645 | } |
c906108c SS |
1646 | |
1647 | ||
c906108c | 1648 | static void |
08ef48c5 MS |
1649 | parse_scrolling_args (char *arg, |
1650 | struct tui_win_info **win_to_scroll, | |
6ba8e26f | 1651 | int *num_to_scroll) |
c906108c | 1652 | { |
6ba8e26f AC |
1653 | if (num_to_scroll) |
1654 | *num_to_scroll = 0; | |
1655 | *win_to_scroll = tui_win_with_focus (); | |
c906108c | 1656 | |
ef5eab5a MS |
1657 | /* First set up the default window to scroll, in case there is no |
1658 | window name arg. */ | |
c906108c SS |
1659 | if (arg != (char *) NULL) |
1660 | { | |
f71c8822 | 1661 | char *buf_ptr; |
c906108c | 1662 | |
1cc6d956 | 1663 | /* Process the number of lines to scroll. */ |
f71c8822 TT |
1664 | std::string copy = arg; |
1665 | buf_ptr = ©[0]; | |
6ba8e26f | 1666 | if (isdigit (*buf_ptr)) |
c906108c | 1667 | { |
6ba8e26f | 1668 | char *num_str; |
c906108c | 1669 | |
6ba8e26f AC |
1670 | num_str = buf_ptr; |
1671 | buf_ptr = strchr (buf_ptr, ' '); | |
1672 | if (buf_ptr != (char *) NULL) | |
c906108c | 1673 | { |
6ba8e26f AC |
1674 | *buf_ptr = (char) 0; |
1675 | if (num_to_scroll) | |
1676 | *num_to_scroll = atoi (num_str); | |
1677 | buf_ptr++; | |
c906108c | 1678 | } |
6ba8e26f AC |
1679 | else if (num_to_scroll) |
1680 | *num_to_scroll = atoi (num_str); | |
c906108c SS |
1681 | } |
1682 | ||
1cc6d956 | 1683 | /* Process the window name if one is specified. */ |
6ba8e26f | 1684 | if (buf_ptr != (char *) NULL) |
c906108c | 1685 | { |
a121b7c1 | 1686 | const char *wname; |
c906108c | 1687 | |
6ba8e26f AC |
1688 | if (*buf_ptr == ' ') |
1689 | while (*(++buf_ptr) == ' ') | |
c906108c SS |
1690 | ; |
1691 | ||
6ba8e26f | 1692 | if (*buf_ptr != (char) 0) |
c709a7c2 | 1693 | { |
c709a7c2 | 1694 | /* Validate the window name. */ |
a121b7c1 PA |
1695 | for (char *p = buf_ptr; *p != '\0'; p++) |
1696 | *p = tolower (*p); | |
1697 | ||
1698 | wname = buf_ptr; | |
c709a7c2 | 1699 | } |
a4b99e53 SC |
1700 | else |
1701 | wname = "?"; | |
1702 | ||
6ba8e26f | 1703 | *win_to_scroll = tui_partial_win_by_name (wname); |
c906108c | 1704 | |
e5908723 MS |
1705 | if (*win_to_scroll == (struct tui_win_info *) NULL |
1706 | || !(*win_to_scroll)->generic.is_visible) | |
ec502284 | 1707 | error (_("Invalid window specified. \n\ |
8a3fe4f8 | 1708 | The window name specified must be valid and visible.\n")); |
6ba8e26f | 1709 | else if (*win_to_scroll == TUI_CMD_WIN) |
96c1eda2 | 1710 | *win_to_scroll = (tui_source_windows ())->list[0]; |
c906108c | 1711 | } |
c906108c | 1712 | } |
6ba8e26f | 1713 | } |