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