Code

list_window: removed selected_start, selected_end
[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 range_base;        /* represents the base item. */
52         bool range_selection;       /* range selection activated */
54         bool hide_cursor;
55 };
57 /**
58  * The bounds of a range selection, see list_window_get_range().
59  */
60 struct list_window_range {
61         /**
62          * The index of the first selected item.
63          */
64         unsigned start;
66         /**
67          * The index after the last selected item.  The selection is
68          * empty when this is the same as "start".
69          */
70         unsigned end;
71 };
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 (returns NULL) */
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 /* perform basic list window commands (movement) */
95 bool
96 list_window_cmd(struct list_window *lw, command_t cmd);
98 /**
99  * Scroll the window.  Returns non-zero if the command has been
100  * consumed.
101  */
102 bool
103 list_window_scroll_cmd(struct list_window *lw, command_t cmd);
105 #ifdef HAVE_GETMOUSE
106 /**
107  * The mouse was clicked.  Check if the list should be scrolled
108  * Returns non-zero if the mouse event has been handled.
109  */
110 bool
111 list_window_mouse(struct list_window *lw, unsigned long bstate, int y);
112 #endif
114 void
115 list_window_center(struct list_window *lw, unsigned n);
117 /**
118  * Sets the position of the cursor.  Disables range selection.
119  */
120 void
121 list_window_set_cursor(struct list_window *lw, unsigned i);
123 /**
124  * Moves the cursor.  Modifies the range if range selection is
125  * enabled.
126  */
127 void
128 list_window_move_cursor(struct list_window *lw, unsigned n);
130 /**
131  * Ensures that the cursor is visible on the screen, i.e. it is not
132  * outside the current scrolling range.
133  */
134 void
135 list_window_fetch_cursor(struct list_window *lw);
137 /**
138  * Determines the lower and upper bound of the range selection.  If
139  * range selection is disabled, it returns the cursor position (range
140  * length is 1).
141  */
142 void
143 list_window_get_range(const struct list_window *lw,
144                       struct list_window_range *range);
146 /* find a string in a list window */
147 bool
148 list_window_find(struct list_window *lw,
149                  list_window_callback_fn_t callback,
150                  void *callback_data,
151                  const char *str,
152                  bool wrap,
153                  bool bell_on_wrap);
155 /* find a string in a list window (reversed) */
156 bool
157 list_window_rfind(struct list_window *lw,
158                   list_window_callback_fn_t callback,
159                   void *callback_data,
160                   const char *str,
161                   bool wrap,
162                   bool bell_on_wrap);
164 /* find a string in a list window which begins with the given characters in *str */
165 bool
166 list_window_jump(struct list_window *lw,
167                  list_window_callback_fn_t callback,
168                  void *callback_data,
169                  const char *str);
171 #endif