X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Flist_window.h;h=cf938f8ce1a793a312bfbb7875d5af61217941a4;hb=3a0114cd65186bbbcb6e0ff3c7eeb9c05fac0ab3;hp=5506f8c77e8eb7e68a5761db1fd94d5a34b59c75;hpb=bcb11a82d4ba42079c14333f9e0d395a4452e256;p=ncmpc.git diff --git a/src/list_window.h b/src/list_window.h index 5506f8c..cf938f8 100644 --- a/src/list_window.h +++ b/src/list_window.h @@ -1,7 +1,7 @@ /* ncmpc (Ncurses MPD Client) * (c) 2004-2009 The Music Player Daemon Project * Project homepage: http://musicpd.org - + * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -22,6 +22,7 @@ #include "config.h" #include "command.h" +#include "colors.h" #include #include @@ -32,21 +33,47 @@ #include #endif -typedef const char *(*list_window_callback_fn_t)(unsigned index, - bool *highlight, - void *data); +typedef const char * +(*list_window_callback_fn_t)(unsigned i, void *data); + +typedef void +(*list_window_paint_callback_t)(WINDOW *w, unsigned i, + unsigned y, unsigned width, + bool selected, + void *data); -typedef struct list_window { +struct list_window { WINDOW *w; unsigned rows, cols; + /** + * Number of items in this list. + */ + unsigned length; + unsigned start; unsigned selected; - unsigned xoffset; + unsigned range_base; /* represents the base item. */ + bool range_selection; /* range selection activated */ bool hide_cursor; -} list_window_t; +}; + +/** + * The bounds of a range selection, see list_window_get_range(). + */ +struct list_window_range { + /** + * The index of the first selected item. + */ + unsigned start; + /** + * The index after the last selected item. The selection is + * empty when this is the same as "start". + */ + unsigned end; +}; /* create a new list window */ struct list_window *list_window_init(WINDOW *w, @@ -58,21 +85,32 @@ void list_window_free(struct list_window *lw); /* reset a list window (selected=0, start=0) */ void list_window_reset(struct list_window *lw); +void +list_window_resize(struct list_window *lw, unsigned width, unsigned height); + +void +list_window_set_length(struct list_window *lw, unsigned length); + /* paint a list window */ -void list_window_paint(struct list_window *lw, +void list_window_paint(const struct list_window *lw, list_window_callback_fn_t callback, void *callback_data); +void +list_window_paint2(const struct list_window *lw, + list_window_paint_callback_t paint_callback, + void *callback_data); + /* perform basic list window commands (movement) */ bool -list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd); +list_window_cmd(struct list_window *lw, command_t cmd); /** * Scroll the window. Returns non-zero if the command has been * consumed. */ bool -list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd); +list_window_scroll_cmd(struct list_window *lw, command_t cmd); #ifdef HAVE_GETMOUSE /** @@ -80,16 +118,40 @@ list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd); * Returns non-zero if the mouse event has been handled. */ bool -list_window_mouse(struct list_window *lw, unsigned rows, - unsigned long bstate, int y); +list_window_mouse(struct list_window *lw, unsigned long bstate, int y); #endif void -list_window_center(struct list_window *lw, unsigned rows, unsigned n); +list_window_center(struct list_window *lw, unsigned n); + +/** + * Sets the position of the cursor. Disables range selection. + */ +void +list_window_set_cursor(struct list_window *lw, unsigned i); + +/** + * Moves the cursor. Modifies the range if range selection is + * enabled. + */ +void +list_window_move_cursor(struct list_window *lw, unsigned n); + +/** + * Ensures that the cursor is visible on the screen, i.e. it is not + * outside the current scrolling range. + */ +void +list_window_fetch_cursor(struct list_window *lw); -/* select functions */ -void list_window_set_selected(struct list_window *lw, unsigned n); -void list_window_check_selected(struct list_window *lw, unsigned length); +/** + * Determines the lower and upper bound of the range selection. If + * range selection is disabled, it returns the cursor position (range + * length is 1). + */ +void +list_window_get_range(const struct list_window *lw, + struct list_window_range *range); /* find a string in a list window */ bool @@ -97,7 +159,8 @@ list_window_find(struct list_window *lw, list_window_callback_fn_t callback, void *callback_data, const char *str, - bool wrap); + bool wrap, + bool bell_on_wrap); /* find a string in a list window (reversed) */ bool @@ -106,6 +169,13 @@ list_window_rfind(struct list_window *lw, void *callback_data, const char *str, bool wrap, - unsigned rows); + bool bell_on_wrap); + +/* find a string in a list window which begins with the given characters in *str */ +bool +list_window_jump(struct list_window *lw, + list_window_callback_fn_t callback, + void *callback_data, + const char *str); #endif