2 * $Id: arrows.c,v 1.33 2011/01/19 00:27:53 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))
41 merge_colors(chtype foreground, chtype background)
43 chtype result = foreground;
44 if ((foreground & A_COLOR) != (background & A_COLOR)) {
47 short fg_pair = (short) PAIR_NUMBER(foreground);
48 short bg_pair = (short) PAIR_NUMBER(background);
50 if (pair_content(fg_pair, &fg_f, &bg_f) != ERR
51 && pair_content(bg_pair, &fg_b, &bg_b) != ERR) {
53 result |= dlg_color_pair(fg_f, bg_b);
59 #define merge_colors(f,b) (f)
63 dlg_draw_arrows2(WINDOW *win,
72 chtype save = dlg_get_attrs(win);
74 int limit_x = getmaxx(win);
77 getyx(win, cur_y, cur_x);
80 * If we're drawing a centered title, do not overwrite with the arrows.
82 if (dialog_vars.title) {
83 int have = (limit_x - dlg_count_columns(dialog_vars.title)) / 2;
90 (void) wmove(win, top, x);
92 wattrset(win, merge_colors(uarrow_attr, attr));
93 (void) add_acs(win, ACS_UARROW);
94 (void) waddstr(win, "(-)");
97 (void) whline(win, dlg_boxchar(ACS_HLINE), 4);
100 mouse_mkbutton(top, x - 1, 6, KEY_PPAGE);
102 (void) wmove(win, bottom, x);
104 wattrset(win, merge_colors(darrow_attr, attr));
105 (void) add_acs(win, ACS_DARROW);
106 (void) waddstr(win, "(+)");
108 wattrset(win, borderattr);
109 (void) whline(win, dlg_boxchar(ACS_HLINE), 4);
111 mouse_mkbutton(bottom, x - 1, 6, KEY_NPAGE);
113 (void) wmove(win, cur_y, cur_x);
120 dlg_draw_scrollbar(WINDOW *win,
135 int oldy, oldx, maxy, maxx;
137 chtype save = dlg_get_attrs(win);
138 int top_arrow = (first_data != 0);
139 int bottom_arrow = (next_data < total_data);
141 getyx(win, oldy, oldx);
142 getmaxyx(win, maxy, maxx);
144 if (bottom_arrow || top_arrow || dialog_state.use_scrollbar) {
145 percent = (!total_data
147 : (int) ((next_data * 100)
152 else if (percent > 100)
155 wattrset(win, position_indicator_attr);
156 (void) sprintf(buffer, "%d%%", percent);
157 (void) wmove(win, bottom, right - 7);
158 (void) waddstr(win, buffer);
159 if ((len = dlg_count_columns(buffer)) < 4) {
160 wattrset(win, border_attr);
161 whline(win, dlg_boxchar(ACS_HLINE), 4 - len);
164 #define BARSIZE(num) (int) (((all_high * (num)) + all_high - 1) / total_data)
166 if (dialog_state.use_scrollbar) {
167 int all_high = (bottom - top - 1);
169 if (total_data > 0 && all_high > 0) {
173 bar_high = BARSIZE(next_data - this_data);
177 if (bar_high < all_high) {
178 wmove(win, top + 1, right);
181 wvline(win, ACS_VLINE | A_REVERSE, all_high);
183 bar_y = BARSIZE(this_data);
184 if (bar_y > all_high - bar_high)
185 bar_y = all_high - bar_high;
187 wmove(win, top + 1 + bar_y, right);
189 wattrset(win, position_indicator_attr);
190 wattron(win, A_REVERSE);
191 wvline(win, ACS_BLOCK, bar_high);
195 dlg_draw_arrows2(win,
205 wmove(win, oldy, oldx);
209 dlg_draw_arrows(WINDOW *win,
216 dlg_draw_arrows2(win,
223 menubox_border_attr);