Code

added missing copyright headers
[ncmpc.git] / src / list_window.h
1 /*
2  * (c) 2004-2008 The Music Player Daemon Project
3  * http://www.musicpd.org/
4  *
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.
9  *
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.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
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                                                  void *data);
39 typedef struct list_window {
40         WINDOW *w;
41         unsigned rows, cols;
43         unsigned start;
44         unsigned selected;
45         unsigned xoffset;
47         bool hide_cursor;
48 } list_window_t;
51 /* create a new list window */
52 struct list_window *list_window_init(WINDOW *w,
53                                      unsigned width, unsigned height);
55 /* destroy a list window (returns NULL) */
56 void list_window_free(struct list_window *lw);
58 /* reset a list window (selected=0, start=0) */
59 void list_window_reset(struct list_window *lw);
61 /* paint a list window */
62 void list_window_paint(struct list_window *lw,
63                        list_window_callback_fn_t callback,
64                        void *callback_data);
66 /* perform basic list window commands (movement) */
67 bool
68 list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd);
70 /**
71  * Scroll the window.  Returns non-zero if the command has been
72  * consumed.
73  */
74 bool
75 list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd);
77 #ifdef HAVE_GETMOUSE
78 /**
79  * The mouse was clicked.  Check if the list should be scrolled
80  * Returns non-zero if the mouse event has been handled.
81  */
82 bool
83 list_window_mouse(struct list_window *lw, unsigned rows,
84                   unsigned long bstate, int y);
85 #endif
87 void
88 list_window_center(struct list_window *lw, unsigned rows, unsigned n);
90 /* select functions */
91 void list_window_set_selected(struct list_window *lw, unsigned n);
92 void list_window_check_selected(struct list_window *lw, unsigned length);
94 /* find a string in a list window */
95 bool
96 list_window_find(struct list_window *lw,
97                  list_window_callback_fn_t callback,
98                  void *callback_data,
99                  const char *str,
100                  bool wrap);
102 /* find a string in a list window (reversed) */
103 bool
104 list_window_rfind(struct list_window *lw,
105                   list_window_callback_fn_t callback,
106                   void *callback_data,
107                   const char *str,
108                   bool wrap,
109                   unsigned rows);
111 #endif