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