8ffe40f9bd5ca0cf79d11b3a82c11b16e51f0744
1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2009 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 *(*list_window_callback_fn_t)(unsigned index,
37 bool *highlight,
38 char **second_column,
39 void *data);
41 typedef void
42 (*list_window_paint_callback_t)(WINDOW *w, unsigned i,
43 unsigned y, unsigned width,
44 bool selected,
45 void *data);
47 struct list_window {
48 WINDOW *w;
49 unsigned rows, cols;
51 /**
52 * Number of items in this list.
53 */
54 unsigned length;
56 unsigned start;
57 unsigned selected;
58 unsigned range_base; /* represents the base item. */
59 bool range_selection; /* range selection activated */
61 bool hide_cursor;
62 };
64 /**
65 * The bounds of a range selection, see list_window_get_range().
66 */
67 struct list_window_range {
68 /**
69 * The index of the first selected item.
70 */
71 unsigned start;
73 /**
74 * The index after the last selected item. The selection is
75 * empty when this is the same as "start".
76 */
77 unsigned end;
78 };
80 /* create a new list window */
81 struct list_window *list_window_init(WINDOW *w,
82 unsigned width, unsigned height);
84 /* destroy a list window (returns NULL) */
85 void list_window_free(struct list_window *lw);
87 /* reset a list window (selected=0, start=0) */
88 void list_window_reset(struct list_window *lw);
90 void
91 list_window_resize(struct list_window *lw, unsigned width, unsigned height);
93 void
94 list_window_set_length(struct list_window *lw, unsigned length);
96 /* paint a list window */
97 void list_window_paint(const struct list_window *lw,
98 list_window_callback_fn_t callback,
99 void *callback_data);
101 void
102 list_window_paint2(const struct list_window *lw,
103 list_window_paint_callback_t paint_callback,
104 void *callback_data);
106 /* perform basic list window commands (movement) */
107 bool
108 list_window_cmd(struct list_window *lw, command_t cmd);
110 /**
111 * Scroll the window. Returns non-zero if the command has been
112 * consumed.
113 */
114 bool
115 list_window_scroll_cmd(struct list_window *lw, command_t cmd);
117 #ifdef HAVE_GETMOUSE
118 /**
119 * The mouse was clicked. Check if the list should be scrolled
120 * Returns non-zero if the mouse event has been handled.
121 */
122 bool
123 list_window_mouse(struct list_window *lw, unsigned long bstate, int y);
124 #endif
126 void
127 list_window_center(struct list_window *lw, unsigned n);
129 /**
130 * Sets the position of the cursor. Disables range selection.
131 */
132 void
133 list_window_set_cursor(struct list_window *lw, unsigned i);
135 /**
136 * Moves the cursor. Modifies the range if range selection is
137 * enabled.
138 */
139 void
140 list_window_move_cursor(struct list_window *lw, unsigned n);
142 /**
143 * Ensures that the cursor is visible on the screen, i.e. it is not
144 * outside the current scrolling range.
145 */
146 void
147 list_window_fetch_cursor(struct list_window *lw);
149 /**
150 * Determines the lower and upper bound of the range selection. If
151 * range selection is disabled, it returns the cursor position (range
152 * length is 1).
153 */
154 void
155 list_window_get_range(const struct list_window *lw,
156 struct list_window_range *range);
158 /* find a string in a list window */
159 bool
160 list_window_find(struct list_window *lw,
161 list_window_callback_fn_t callback,
162 void *callback_data,
163 const char *str,
164 bool wrap,
165 bool bell_on_wrap);
167 /* find a string in a list window (reversed) */
168 bool
169 list_window_rfind(struct list_window *lw,
170 list_window_callback_fn_t callback,
171 void *callback_data,
172 const char *str,
173 bool wrap,
174 bool bell_on_wrap);
176 /* find a string in a list window which begins with the given characters in *str */
177 bool
178 list_window_jump(struct list_window *lw,
179 list_window_callback_fn_t callback,
180 void *callback_data,
181 const char *str);
183 #endif