2 * $Id: arrows.c,v 1.36 2011/06/27 09:13:56 tom Exp $
4 * arrows.c -- draw arrows to indicate end-of-range for lists
6 * Copyright 2000-2010,2011 Thomas E. Dickey
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License, version 2.1
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to
19 * Free Software Foundation, Inc.
20 * 51 Franklin St., Fifth Floor
21 * Boston, MA 02110, USA.
26 #ifdef USE_WIDE_CURSES
27 #if defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
28 /* workaround for NetBSD 5.1 curses */
31 #define WACS_DARROW &(CURSES_WACS_ARRAY['.'])
32 #define WACS_UARROW &(CURSES_WACS_ARRAY['-'])
34 #define add_acs(win, code) wadd_wch(win, W ## code)
36 #define add_acs(win, code) waddch(win, dlg_boxchar(code))
39 /* size of decorations */
45 merge_colors(chtype foreground, chtype background)
47 chtype result = foreground;
48 if ((foreground & A_COLOR) != (background & A_COLOR)) {
51 short fg_pair = (short) PAIR_NUMBER(foreground);
52 short bg_pair = (short) PAIR_NUMBER(background);
54 if (pair_content(fg_pair, &fg_f, &bg_f) != ERR
55 && pair_content(bg_pair, &fg_b, &bg_b) != ERR) {
57 result |= dlg_color_pair(fg_f, bg_b);
63 #define merge_colors(f,b) (f)
67 * If we have help-line text, e.g., from "--hline", draw it between the other
68 * decorations at the bottom of the dialog window.
71 dlg_draw_helpline(WINDOW *win, bool decorations)
76 if (dialog_vars.help_line != 0
77 && (bottom = getmaxy(win) - 1) > 0) {
78 chtype attr = A_NORMAL;
79 const int *cols = dlg_index_columns(dialog_vars.help_line);
80 int other = decorations ? (ON_LEFT + ON_RIGHT) : 0;
81 int avail = (getmaxx(win) - other - 2);
82 int limit = dlg_limit_columns(dialog_vars.help_line, avail, 0);
85 getyx(win, cur_y, cur_x);
86 other = decorations ? ON_LEFT : 0;
87 (void) wmove(win, bottom, other + (avail - limit) / 2);
89 dlg_print_text(win, dialog_vars.help_line, cols[limit], &attr);
91 wmove(win, cur_y, cur_x);
97 dlg_draw_arrows2(WINDOW *win,
106 chtype save = dlg_get_attrs(win);
108 int limit_x = getmaxx(win);
109 bool draw_top = TRUE;
111 getyx(win, cur_y, cur_x);
114 * If we're drawing a centered title, do not overwrite with the arrows.
116 if (dialog_vars.title) {
117 int have = (limit_x - dlg_count_columns(dialog_vars.title)) / 2;
124 (void) wmove(win, top, x);
126 wattrset(win, merge_colors(uarrow_attr, attr));
127 (void) add_acs(win, ACS_UARROW);
128 (void) waddstr(win, "(-)");
131 (void) whline(win, dlg_boxchar(ACS_HLINE), ON_LEFT);
134 mouse_mkbutton(top, x - 1, 6, KEY_PPAGE);
136 (void) wmove(win, bottom, x);
138 wattrset(win, merge_colors(darrow_attr, attr));
139 (void) add_acs(win, ACS_DARROW);
140 (void) waddstr(win, "(+)");
142 wattrset(win, borderattr);
143 (void) whline(win, dlg_boxchar(ACS_HLINE), ON_LEFT);
145 mouse_mkbutton(bottom, x - 1, 6, KEY_NPAGE);
147 (void) wmove(win, cur_y, cur_x);
154 dlg_draw_scrollbar(WINDOW *win,
169 int oldy, oldx, maxy, maxx;
171 chtype save = dlg_get_attrs(win);
172 int top_arrow = (first_data != 0);
173 int bottom_arrow = (next_data < total_data);
175 getyx(win, oldy, oldx);
176 getmaxyx(win, maxy, maxx);
178 dlg_draw_helpline(win, TRUE);
179 if (bottom_arrow || top_arrow || dialog_state.use_scrollbar) {
180 percent = (!total_data
182 : (int) ((next_data * 100)
187 else if (percent > 100)
190 wattrset(win, position_indicator_attr);
191 (void) sprintf(buffer, "%d%%", percent);
192 (void) wmove(win, bottom, right - 7);
193 (void) waddstr(win, buffer);
194 if ((len = dlg_count_columns(buffer)) < 4) {
195 wattrset(win, border_attr);
196 whline(win, dlg_boxchar(ACS_HLINE), 4 - len);
199 #define BARSIZE(num) (int) (((all_high * (num)) + all_high - 1) / total_data)
201 if (dialog_state.use_scrollbar) {
202 int all_high = (bottom - top - 1);
204 if (total_data > 0 && all_high > 0) {
208 bar_high = BARSIZE(next_data - this_data);
212 if (bar_high < all_high) {
213 wmove(win, top + 1, right);
216 wvline(win, ACS_VLINE | A_REVERSE, all_high);
218 bar_y = BARSIZE(this_data);
219 if (bar_y > all_high - bar_high)
220 bar_y = all_high - bar_high;
222 wmove(win, top + 1 + bar_y, right);
224 wattrset(win, position_indicator_attr);
225 wattron(win, A_REVERSE);
226 wvline(win, ACS_BLOCK, bar_high);
230 dlg_draw_arrows2(win,
240 wmove(win, oldy, oldx);
244 dlg_draw_arrows(WINDOW *win,
251 dlg_draw_helpline(win, TRUE);
252 dlg_draw_arrows2(win,
259 menubox_border_attr);