Code

eef6b9a7c43c1d8739971bfe3470e8041f65056a
[ncmpc.git] / src / list_window.h
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_resize(struct list_window *lw, unsigned width, unsigned height);
72 void
73 list_window_set_length(struct list_window *lw, unsigned length);
75 /* paint a list window */
76 void list_window_paint(const struct list_window *lw,
77                        list_window_callback_fn_t callback,
78                        void *callback_data);
80 /* perform basic list window commands (movement) */
81 bool
82 list_window_cmd(struct list_window *lw, command_t cmd);
84 /**
85  * Scroll the window.  Returns non-zero if the command has been
86  * consumed.
87  */
88 bool
89 list_window_scroll_cmd(struct list_window *lw, command_t cmd);
91 #ifdef HAVE_GETMOUSE
92 /**
93  * The mouse was clicked.  Check if the list should be scrolled
94  * Returns non-zero if the mouse event has been handled.
95  */
96 bool
97 list_window_mouse(struct list_window *lw, unsigned long bstate, int y);
98 #endif
100 void
101 list_window_center(struct list_window *lw, unsigned n);
103 /**
104  * Sets the position of the cursor.  Disables range selection.
105  */
106 void
107 list_window_set_cursor(struct list_window *lw, unsigned i);
109 /**
110  * Moves the cursor.  Modifies the range if range selection is
111  * enabled.
112  */
113 void
114 list_window_move_cursor(struct list_window *lw, unsigned n);
116 /**
117  * Ensures that the cursor is visible on the screen, i.e. it is not
118  * outside the current scrolling range.
119  */
120 void
121 list_window_fetch_cursor(struct list_window *lw);
123 /* find a string in a list window */
124 bool
125 list_window_find(struct list_window *lw,
126                  list_window_callback_fn_t callback,
127                  void *callback_data,
128                  const char *str,
129                  bool wrap,
130                  bool bell_on_wrap);
132 /* find a string in a list window (reversed) */
133 bool
134 list_window_rfind(struct list_window *lw,
135                   list_window_callback_fn_t callback,
136                   void *callback_data,
137                   const char *str,
138                   bool wrap,
139                   bool bell_on_wrap);
141 /* find a string in a list window which begins with the given characters in *str */
142 bool
143 list_window_jump(struct list_window *lw,
144                  list_window_callback_fn_t callback,
145                  void *callback_data,
146                  const char *str);
148 #endif