1 #ifndef LIST_WINDOW_H
2 #define LIST_WINDOW_H
4 #include "../config.h"
5 #include "command.h"
7 #include <ncurses.h>
8 #include <glib.h>
10 #define LW_ROW(lw) (lw ? lw->selected-lw->start : 0)
12 #define LW_HIDE_CURSOR 0x01
14 typedef const char *(*list_window_callback_fn_t)(unsigned index,
15 int *highlight,
16 void *data);
18 typedef struct list_window {
19 WINDOW *w;
20 unsigned rows, cols;
22 unsigned start;
23 unsigned selected;
24 unsigned xoffset;
25 int clear;
26 int repaint;
27 int flags;
28 } list_window_t;
30 typedef struct list_window_state {
31 GList *list;
32 } list_window_state_t;
35 /* create a new list window */
36 struct list_window *list_window_init(WINDOW *w,
37 unsigned width, unsigned height);
39 /* destroy a list window (returns NULL) */
40 void list_window_free(struct list_window *lw);
42 /* reset a list window (selected=0, start=0, clear=1) */
43 void list_window_reset(struct list_window *lw);
45 /* paint a list window */
46 void list_window_paint(struct list_window *lw,
47 list_window_callback_fn_t callback,
48 void *callback_data);
50 /* perform basic list window commands (movement) */
51 int list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd);
53 /**
54 * Scroll the window. Returns non-zero if the command has been
55 * consumed.
56 */
57 int
58 list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd);
60 #ifdef HAVE_GETMOUSE
61 /**
62 * The mouse was clicked. Check if the list should be scrolled
63 * Returns non-zero if the mouse event has been handled.
64 */
65 int
66 list_window_mouse(struct list_window *lw, unsigned rows,
67 unsigned long bstate, int y);
68 #endif
70 void
71 list_window_center(struct list_window *lw, unsigned rows, unsigned n);
73 /* select functions */
74 void list_window_set_selected(struct list_window *lw, unsigned n);
75 void list_window_previous(struct list_window *lw, unsigned length);
76 void list_window_next(struct list_window *lw, unsigned length);
77 void list_window_first(struct list_window *lw);
78 void list_window_last(struct list_window *lw, unsigned length);
79 void list_window_previous_page(struct list_window *lw);
80 void list_window_next_page(struct list_window *lw, unsigned length);
81 void list_window_check_selected(struct list_window *lw, unsigned length);
83 /* find a string in a list window */
84 int list_window_find(struct list_window *lw,
85 list_window_callback_fn_t callback,
86 void *callback_data,
87 const char *str,
88 int wrap);
90 /* find a string in a list window (reversed) */
91 int
92 list_window_rfind(struct list_window *lw,
93 list_window_callback_fn_t callback,
94 void *callback_data,
95 const char *str,
96 int wrap,
97 unsigned rows);
99 /* list window states */
100 list_window_state_t *list_window_init_state(void);
101 void list_window_free_state(list_window_state_t *state);
102 void list_window_push_state(list_window_state_t *state,
103 struct list_window *lw);
104 bool list_window_pop_state(list_window_state_t *state, struct list_window *lw);
108 #endif