1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2010 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
20 #ifndef LIST_WINDOW_H
21 #define LIST_WINDOW_H
23 #include "config.h"
24 #include "command.h"
25 #include "colors.h"
27 #include <glib.h>
28 #include <stdbool.h>
30 #ifdef HAVE_NCURSESW_NCURSES_H
31 #include <ncursesw/ncurses.h>
32 #else
33 #include <ncurses.h>
34 #endif
36 typedef const char *
37 (*list_window_callback_fn_t)(unsigned i, void *data);
39 typedef void
40 (*list_window_paint_callback_t)(WINDOW *w, unsigned i,
41 unsigned y, unsigned width,
42 bool selected,
43 void *data);
45 struct list_window {
46 WINDOW *w;
47 unsigned rows, cols;
49 /**
50 * Number of items in this list.
51 */
52 unsigned length;
54 unsigned start;
55 unsigned selected;
56 unsigned range_base; /* represents the base item. */
57 bool range_selection; /* range selection activated */
59 bool hide_cursor;
60 };
62 /**
63 * The bounds of a range selection, see list_window_get_range().
64 */
65 struct list_window_range {
66 /**
67 * The index of the first selected item.
68 */
69 unsigned start;
71 /**
72 * The index after the last selected item. The selection is
73 * empty when this is the same as "start".
74 */
75 unsigned end;
76 };
78 /* create a new list window */
79 struct list_window *list_window_init(WINDOW *w,
80 unsigned width, unsigned height);
82 /* destroy a list window (returns NULL) */
83 void list_window_free(struct list_window *lw);
85 /* reset a list window (selected=0, start=0) */
86 void list_window_reset(struct list_window *lw);
88 void
89 list_window_resize(struct list_window *lw, unsigned width, unsigned height);
91 void
92 list_window_set_length(struct list_window *lw, unsigned length);
94 /* paint a list window */
95 void list_window_paint(const struct list_window *lw,
96 list_window_callback_fn_t callback,
97 void *callback_data);
99 void
100 list_window_paint2(const struct list_window *lw,
101 list_window_paint_callback_t paint_callback,
102 void *callback_data);
104 /* perform basic list window commands (movement) */
105 bool
106 list_window_cmd(struct list_window *lw, command_t cmd);
108 /**
109 * Scroll the window. Returns true if the command has been
110 * consumed.
111 */
112 bool
113 list_window_scroll_cmd(struct list_window *lw, command_t cmd);
115 #ifdef HAVE_GETMOUSE
116 /**
117 * The mouse was clicked. Check if the list should be scrolled
118 * Returns non-zero if the mouse event has been handled.
119 */
120 bool
121 list_window_mouse(struct list_window *lw, unsigned long bstate, int y);
122 #endif
124 /**
125 * Centers the visible range around item n on the list.
126 */
127 void
128 list_window_center(struct list_window *lw, unsigned n);
130 /**
131 * Scrolls the view to item n, as if the cursor would have been moved
132 * to the position.
133 */
134 void
135 list_window_scroll_to(struct list_window *lw, unsigned n);
137 /**
138 * Sets the position of the cursor. Disables range selection.
139 */
140 void
141 list_window_set_cursor(struct list_window *lw, unsigned i);
143 /**
144 * Moves the cursor. Modifies the range if range selection is
145 * enabled.
146 */
147 void
148 list_window_move_cursor(struct list_window *lw, unsigned n);
150 /**
151 * Ensures that the cursor is visible on the screen, i.e. it is not
152 * outside the current scrolling range.
153 */
154 void
155 list_window_fetch_cursor(struct list_window *lw);
157 /**
158 * Determines the lower and upper bound of the range selection. If
159 * range selection is disabled, it returns the cursor position (range
160 * length is 1).
161 */
162 void
163 list_window_get_range(const struct list_window *lw,
164 struct list_window_range *range);
166 /* find a string in a list window */
167 bool
168 list_window_find(struct list_window *lw,
169 list_window_callback_fn_t callback,
170 void *callback_data,
171 const char *str,
172 bool wrap,
173 bool bell_on_wrap);
175 /* find a string in a list window (reversed) */
176 bool
177 list_window_rfind(struct list_window *lw,
178 list_window_callback_fn_t callback,
179 void *callback_data,
180 const char *str,
181 bool wrap,
182 bool bell_on_wrap);
184 /* find a string in a list window which begins with the given characters in *str */
185 bool
186 list_window_jump(struct list_window *lw,
187 list_window_callback_fn_t callback,
188 void *callback_data,
189 const char *str);
191 #endif