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