README: convert to reStructuredText
[ncmpc.git] / src / list_window.h
blob697e1e0e163af938e337bf1773111bde68b79523
1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2017 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.
20 #ifndef LIST_WINDOW_H
21 #define LIST_WINDOW_H
23 #include "config.h"
24 #include "command.h"
25 #include "colors.h"
26 #include "ncmpc_curses.h"
28 #include <glib.h>
29 #include <stdbool.h>
31 typedef const char *
32 (*list_window_callback_fn_t)(unsigned i, void *data);
34 typedef void
35 (*list_window_paint_callback_t)(WINDOW *w, unsigned i,
36 unsigned y, unsigned width,
37 bool selected,
38 const void *data);
40 struct list_window {
41 WINDOW *w;
42 unsigned rows, cols;
44 /**
45 * Number of items in this list.
47 unsigned length;
49 unsigned start;
50 unsigned selected;
52 /**
53 * Represents the base item.
55 unsigned range_base;
57 /**
58 * Range selection activated?
60 bool range_selection;
62 bool hide_cursor;
65 /**
66 * The bounds of a range selection, see list_window_get_range().
68 struct list_window_range {
69 /**
70 * The index of the first selected item.
72 unsigned start;
74 /**
75 * The index after the last selected item. The selection is
76 * empty when this is the same as "start".
78 unsigned end;
81 /* create a new list window */
82 struct list_window *list_window_init(WINDOW *w,
83 unsigned width, unsigned height);
85 /* destroy a list window */
86 void list_window_free(struct list_window *lw);
88 /* reset a list window (selected=0, start=0) */
89 void list_window_reset(struct list_window *lw);
91 void
92 list_window_resize(struct list_window *lw, unsigned width, unsigned height);
94 void
95 list_window_set_length(struct list_window *lw, unsigned length);
97 /* paint a list window */
98 void list_window_paint(const struct list_window *lw,
99 list_window_callback_fn_t callback,
100 void *callback_data);
102 void
103 list_window_paint2(const struct list_window *lw,
104 list_window_paint_callback_t paint_callback,
105 const void *callback_data);
107 /* perform basic list window commands (movement) */
108 bool
109 list_window_cmd(struct list_window *lw, command_t cmd);
112 * Scroll the window. Returns true if the command has been
113 * consumed.
115 bool
116 list_window_scroll_cmd(struct list_window *lw, command_t cmd);
118 #ifdef HAVE_GETMOUSE
120 * The mouse was clicked. Check if the list should be scrolled
121 * Returns non-zero if the mouse event has been handled.
123 bool
124 list_window_mouse(struct list_window *lw, unsigned long bstate, int y);
125 #endif
128 * Centers the visible range around item n on the list.
130 void
131 list_window_center(struct list_window *lw, unsigned n);
134 * Scrolls the view to item n, as if the cursor would have been moved
135 * to the position.
137 void
138 list_window_scroll_to(struct list_window *lw, unsigned n);
141 * Sets the position of the cursor. Disables range selection.
143 void
144 list_window_set_cursor(struct list_window *lw, unsigned i);
147 * Moves the cursor. Modifies the range if range selection is
148 * enabled.
150 void
151 list_window_move_cursor(struct list_window *lw, unsigned n);
154 * Ensures that the cursor is visible on the screen, i.e. it is not
155 * outside the current scrolling range.
157 void
158 list_window_fetch_cursor(struct list_window *lw);
161 * Determines the lower and upper bound of the range selection. If
162 * range selection is disabled, it returns the cursor position (range
163 * length is 1).
165 void
166 list_window_get_range(const struct list_window *lw,
167 struct list_window_range *range);
169 /* find a string in a list window */
170 bool
171 list_window_find(struct list_window *lw,
172 list_window_callback_fn_t callback,
173 void *callback_data,
174 const char *str,
175 bool wrap,
176 bool bell_on_wrap);
178 /* find a string in a list window (reversed) */
179 bool
180 list_window_rfind(struct list_window *lw,
181 list_window_callback_fn_t callback,
182 void *callback_data,
183 const char *str,
184 bool wrap,
185 bool bell_on_wrap);
187 /* find a string in a list window which begins with the given characters in *str */
188 bool
189 list_window_jump(struct list_window *lw,
190 list_window_callback_fn_t callback,
191 void *callback_data,
192 const char *str);
194 #endif