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 typedef struct list_window {
41 WINDOW *w;
42 unsigned rows, cols;
44 unsigned start;
45 unsigned selected;
46 unsigned selected_start; /* for range selection, first selected item */
47 unsigned selected_end; /* for range selection, last selected item */
48 unsigned range_base; /* represents the base item. */
49 bool range_selection; /* range selection activated */
51 bool hide_cursor;
52 } list_window_t;
55 /* create a new list window */
56 struct list_window *list_window_init(WINDOW *w,
57 unsigned width, unsigned height);
59 /* destroy a list window (returns NULL) */
60 void list_window_free(struct list_window *lw);
62 /* reset a list window (selected=0, start=0) */
63 void list_window_reset(struct list_window *lw);
65 /* paint a list window */
66 void list_window_paint(struct list_window *lw,
67 list_window_callback_fn_t callback,
68 void *callback_data);
70 /* perform basic list window commands (movement) */
71 bool
72 list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd);
74 /**
75 * Scroll the window. Returns non-zero if the command has been
76 * consumed.
77 */
78 bool
79 list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd);
81 #ifdef HAVE_GETMOUSE
82 /**
83 * The mouse was clicked. Check if the list should be scrolled
84 * Returns non-zero if the mouse event has been handled.
85 */
86 bool
87 list_window_mouse(struct list_window *lw, unsigned rows,
88 unsigned long bstate, int y);
89 #endif
91 void
92 list_window_center(struct list_window *lw, unsigned rows, unsigned n);
94 /* select functions */
95 void list_window_set_selected(struct list_window *lw, unsigned n);
96 void list_window_check_selected(struct list_window *lw, unsigned length);
98 /* find a string in a list window */
99 bool
100 list_window_find(struct list_window *lw,
101 list_window_callback_fn_t callback,
102 void *callback_data,
103 const char *str,
104 bool wrap,
105 bool bell_on_wrap);
107 /* find a string in a list window (reversed) */
108 bool
109 list_window_rfind(struct list_window *lw,
110 list_window_callback_fn_t callback,
111 void *callback_data,
112 const char *str,
113 bool wrap,
114 bool bell_on_wrap,
115 unsigned rows);
117 /* find a string in a list window which begins with the given characters in *str */
118 bool
119 list_window_jump(struct list_window *lw,
120 list_window_callback_fn_t callback,
121 void *callback_data,
122 const char *str);
124 #endif