Code

list_window: use "bool" instead of "int"
[ncmpc.git] / src / list_window.h
1 #ifndef LIST_WINDOW_H
2 #define LIST_WINDOW_H
4 #include "../config.h"
5 #include "command.h"
7 #include <glib.h>
8 #include <stdbool.h>
10 #ifdef HAVE_NCURSESW_NCURSES_H
11 #include <ncursesw/ncurses.h>
12 #else
13 #include <ncurses.h>
14 #endif
16 #define LW_HIDE_CURSOR    0x01
18 typedef const char *(*list_window_callback_fn_t)(unsigned index,
19                                                  bool *highlight,
20                                                  void *data);
22 typedef struct list_window {
23         WINDOW *w;
24         unsigned rows, cols;
26         unsigned start;
27         unsigned selected;
28         unsigned xoffset;
29         int flags;
30 } list_window_t;
33 /* create a new list window */
34 struct list_window *list_window_init(WINDOW *w,
35                                      unsigned width, unsigned height);
37 /* destroy a list window (returns NULL) */
38 void list_window_free(struct list_window *lw);
40 /* reset a list window (selected=0, start=0) */
41 void list_window_reset(struct list_window *lw);
43 /* paint a list window */
44 void list_window_paint(struct list_window *lw,
45                        list_window_callback_fn_t callback,
46                        void *callback_data);
48 /* perform basic list window commands (movement) */
49 bool
50 list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd);
52 /**
53  * Scroll the window.  Returns non-zero if the command has been
54  * consumed.
55  */
56 bool
57 list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd);
59 #ifdef HAVE_GETMOUSE
60 /**
61  * The mouse was clicked.  Check if the list should be scrolled
62  * Returns non-zero if the mouse event has been handled.
63  */
64 bool
65 list_window_mouse(struct list_window *lw, unsigned rows,
66                   unsigned long bstate, int y);
67 #endif
69 void
70 list_window_center(struct list_window *lw, unsigned rows, unsigned n);
72 /* select functions */
73 void list_window_set_selected(struct list_window *lw, unsigned n);
74 void list_window_check_selected(struct list_window *lw, unsigned length);
76 /* find a string in a list window */
77 bool
78 list_window_find(struct list_window *lw,
79                  list_window_callback_fn_t callback,
80                  void *callback_data,
81                  const char *str,
82                  bool wrap);
84 /* find a string in a list window (reversed) */
85 bool
86 list_window_rfind(struct list_window *lw,
87                   list_window_callback_fn_t callback,
88                   void *callback_data,
89                   const char *str,
90                   bool wrap,
91                   unsigned rows);
93 #endif