configure.ac: require GLib 2.14
[ncmpc.git] / src / list_window.h
blob495657b3cb93f9fcd4972bcae61e6dff83021116
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.
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 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;
51 unsigned range_base; /* represents the base item. */
52 bool range_selection; /* range selection activated */
54 bool hide_cursor;
57 /**
58 * The bounds of a range selection, see list_window_get_range().
60 struct list_window_range {
61 /**
62 * The index of the first selected item.
64 unsigned start;
66 /**
67 * The index after the last selected item. The selection is
68 * empty when this is the same as "start".
70 unsigned end;
73 /* create a new list window */
74 struct list_window *list_window_init(WINDOW *w,
75 unsigned width, unsigned height);
77 /* destroy a list window */
78 void list_window_free(struct list_window *lw);
80 /* reset a list window (selected=0, start=0) */
81 void list_window_reset(struct list_window *lw);
83 void
84 list_window_resize(struct list_window *lw, unsigned width, unsigned height);
86 void
87 list_window_set_length(struct list_window *lw, unsigned length);
89 /* paint a list window */
90 void list_window_paint(const struct list_window *lw,
91 list_window_callback_fn_t callback,
92 void *callback_data);
94 void
95 list_window_paint2(const struct list_window *lw,
96 list_window_paint_callback_t paint_callback,
97 void *callback_data);
99 /* perform basic list window commands (movement) */
100 bool
101 list_window_cmd(struct list_window *lw, command_t cmd);
104 * Scroll the window. Returns true if the command has been
105 * consumed.
107 bool
108 list_window_scroll_cmd(struct list_window *lw, command_t cmd);
110 #ifdef HAVE_GETMOUSE
112 * The mouse was clicked. Check if the list should be scrolled
113 * Returns non-zero if the mouse event has been handled.
115 bool
116 list_window_mouse(struct list_window *lw, unsigned long bstate, int y);
117 #endif
120 * Centers the visible range around item n on the list.
122 void
123 list_window_center(struct list_window *lw, unsigned n);
126 * Scrolls the view to item n, as if the cursor would have been moved
127 * to the position.
129 void
130 list_window_scroll_to(struct list_window *lw, unsigned n);
133 * Sets the position of the cursor. Disables range selection.
135 void
136 list_window_set_cursor(struct list_window *lw, unsigned i);
139 * Moves the cursor. Modifies the range if range selection is
140 * enabled.
142 void
143 list_window_move_cursor(struct list_window *lw, unsigned n);
146 * Ensures that the cursor is visible on the screen, i.e. it is not
147 * outside the current scrolling range.
149 void
150 list_window_fetch_cursor(struct list_window *lw);
153 * Determines the lower and upper bound of the range selection. If
154 * range selection is disabled, it returns the cursor position (range
155 * length is 1).
157 void
158 list_window_get_range(const struct list_window *lw,
159 struct list_window_range *range);
161 /* find a string in a list window */
162 bool
163 list_window_find(struct list_window *lw,
164 list_window_callback_fn_t callback,
165 void *callback_data,
166 const char *str,
167 bool wrap,
168 bool bell_on_wrap);
170 /* find a string in a list window (reversed) */
171 bool
172 list_window_rfind(struct list_window *lw,
173 list_window_callback_fn_t callback,
174 void *callback_data,
175 const char *str,
176 bool wrap,
177 bool bell_on_wrap);
179 /* find a string in a list window which begins with the given characters in *str */
180 bool
181 list_window_jump(struct list_window *lw,
182 list_window_callback_fn_t callback,
183 void *callback_data,
184 const char *str);
186 #endif