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 * Sets the position of the cursor. Disables range selection.
132 */
133 void
134 list_window_set_cursor(struct list_window *lw, unsigned i);
136 /**
137 * Moves the cursor. Modifies the range if range selection is
138 * enabled.
139 */
140 void
141 list_window_move_cursor(struct list_window *lw, unsigned n);
143 /**
144 * Ensures that the cursor is visible on the screen, i.e. it is not
145 * outside the current scrolling range.
146 */
147 void
148 list_window_fetch_cursor(struct list_window *lw);
150 /**
151 * Determines the lower and upper bound of the range selection. If
152 * range selection is disabled, it returns the cursor position (range
153 * length is 1).
154 */
155 void
156 list_window_get_range(const struct list_window *lw,
157 struct list_window_range *range);
159 /* find a string in a list window */
160 bool
161 list_window_find(struct list_window *lw,
162 list_window_callback_fn_t callback,
163 void *callback_data,
164 const char *str,
165 bool wrap,
166 bool bell_on_wrap);
168 /* find a string in a list window (reversed) */
169 bool
170 list_window_rfind(struct list_window *lw,
171 list_window_callback_fn_t callback,
172 void *callback_data,
173 const char *str,
174 bool wrap,
175 bool bell_on_wrap);
177 /* find a string in a list window which begins with the given characters in *str */
178 bool
179 list_window_jump(struct list_window *lw,
180 list_window_callback_fn_t callback,
181 void *callback_data,
182 const char *str);
184 #endif