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"
26 #include <glib.h>
27 #include <stdbool.h>
29 #ifdef HAVE_NCURSESW_NCURSES_H
30 #include <ncursesw/ncurses.h>
31 #else
32 #include <ncurses.h>
33 #endif
35 typedef const char *(*list_window_callback_fn_t)(unsigned index,
36 bool *highlight,
37 char **second_column,
38 void *data);
40 struct list_window {
41 WINDOW *w;
42 unsigned rows, cols;
44 /**
45 * Number of items in this list.
46 */
47 unsigned length;
49 unsigned start;
50 unsigned selected;
51 unsigned selected_start; /* for range selection, first selected item */
52 unsigned selected_end; /* for range selection, last selected item */
53 unsigned range_base; /* represents the base item. */
54 bool range_selection; /* range selection activated */
56 bool hide_cursor;
57 };
59 /* create a new list window */
60 struct list_window *list_window_init(WINDOW *w,
61 unsigned width, unsigned height);
63 /* destroy a list window (returns NULL) */
64 void list_window_free(struct list_window *lw);
66 /* reset a list window (selected=0, start=0) */
67 void list_window_reset(struct list_window *lw);
69 void
70 list_window_set_length(struct list_window *lw, unsigned length);
72 /* paint a list window */
73 void list_window_paint(struct list_window *lw,
74 list_window_callback_fn_t callback,
75 void *callback_data);
77 /* perform basic list window commands (movement) */
78 bool
79 list_window_cmd(struct list_window *lw, command_t cmd);
81 /**
82 * Scroll the window. Returns non-zero if the command has been
83 * consumed.
84 */
85 bool
86 list_window_scroll_cmd(struct list_window *lw, command_t cmd);
88 #ifdef HAVE_GETMOUSE
89 /**
90 * The mouse was clicked. Check if the list should be scrolled
91 * Returns non-zero if the mouse event has been handled.
92 */
93 bool
94 list_window_mouse(struct list_window *lw, unsigned long bstate, int y);
95 #endif
97 void
98 list_window_center(struct list_window *lw, unsigned n);
100 /**
101 * Sets the position of the cursor. Disables range selection.
102 */
103 void
104 list_window_set_cursor(struct list_window *lw, unsigned i);
106 /**
107 * Moves the cursor. Modifies the range if range selection is
108 * enabled.
109 */
110 void
111 list_window_move_cursor(struct list_window *lw, unsigned n);
113 /**
114 * Ensures that the cursor is visible on the screen, i.e. it is not
115 * outside the current scrolling range.
116 */
117 void
118 list_window_fetch_cursor(struct list_window *lw);
120 /* find a string in a list window */
121 bool
122 list_window_find(struct list_window *lw,
123 list_window_callback_fn_t callback,
124 void *callback_data,
125 const char *str,
126 bool wrap,
127 bool bell_on_wrap);
129 /* find a string in a list window (reversed) */
130 bool
131 list_window_rfind(struct list_window *lw,
132 list_window_callback_fn_t callback,
133 void *callback_data,
134 const char *str,
135 bool wrap,
136 bool bell_on_wrap);
138 /* find a string in a list window which begins with the given characters in *str */
139 bool
140 list_window_jump(struct list_window *lw,
141 list_window_callback_fn_t callback,
142 void *callback_data,
143 const char *str);
145 #endif