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