Code

list_window: moved code to list_window_fetch_cursor()
[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         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 };
54 /* create a new list window */
55 struct list_window *list_window_init(WINDOW *w,
56                                      unsigned width, unsigned height);
58 /* destroy a list window (returns NULL) */
59 void list_window_free(struct list_window *lw);
61 /* reset a list window (selected=0, start=0) */
62 void list_window_reset(struct list_window *lw);
64 /* paint a list window */
65 void list_window_paint(struct list_window *lw,
66                        list_window_callback_fn_t callback,
67                        void *callback_data);
69 /* perform basic list window commands (movement) */
70 bool
71 list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd);
73 /**
74  * Scroll the window.  Returns non-zero if the command has been
75  * consumed.
76  */
77 bool
78 list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd);
80 #ifdef HAVE_GETMOUSE
81 /**
82  * The mouse was clicked.  Check if the list should be scrolled
83  * Returns non-zero if the mouse event has been handled.
84  */
85 bool
86 list_window_mouse(struct list_window *lw, unsigned rows,
87                   unsigned long bstate, int y);
88 #endif
90 void
91 list_window_center(struct list_window *lw, unsigned rows, unsigned n);
93 /* select functions */
94 void list_window_check_selected(struct list_window *lw, unsigned length);
96 /**
97  * Sets the position of the cursor.  Disables range selection.
98  */
99 void
100 list_window_set_cursor(struct list_window *lw, unsigned i);
102 /**
103  * Moves the cursor.  Modifies the range if range selection is
104  * enabled.
105  */
106 void
107 list_window_move_cursor(struct list_window *lw, unsigned n);
109 /**
110  * Ensures that the cursor is visible on the screen, i.e. it is not
111  * outside the current scrolling range.
112  */
113 void
114 list_window_fetch_cursor(struct list_window *lw, unsigned length);
116 /* find a string in a list window */
117 bool
118 list_window_find(struct list_window *lw,
119                  list_window_callback_fn_t callback,
120                  void *callback_data,
121                  const char *str,
122                  bool wrap,
123                  bool bell_on_wrap);
125 /* find a string in a list window (reversed) */
126 bool
127 list_window_rfind(struct list_window *lw,
128                   list_window_callback_fn_t callback,
129                   void *callback_data,
130                   const char *str,
131                   bool wrap,
132                   bool bell_on_wrap,
133                   unsigned rows);
135 /* find a string in a list window which begins with the given characters in *str */
136 bool
137 list_window_jump(struct list_window *lw,
138                  list_window_callback_fn_t callback,
139                  void *callback_data,
140                  const char *str);
142 #endif