diff --git a/src/list_window.h b/src/list_window.h
index 9d1211ec4104b65a10eb656b084766dae46a5076..a61d24b4e9b3c0cdd0ee7640e673e4dadc2f8966 100644 (file)
--- a/src/list_window.h
+++ b/src/list_window.h
-#ifndef LIST_WINDOW_H
-#define LIST_WINDOW_H
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2010 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
-#define LW_ROW(lw) (lw ? lw->selected-lw->start : 0)
+ * 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
+ * (at your option) any later version.
-#define LW_HIDE_CURSOR 0x01
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
-typedef char * (*list_window_callback_fn_t) (int index,
- int *highlight,
- void *data);
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
-typedef struct
-{
- WINDOW *w;
- int rows, cols;
+#ifndef LIST_WINDOW_H
+#define LIST_WINDOW_H
- int start;
- int selected;
- int xoffset;
- int clear;
- int repaint;
- int flags;
+#include "config.h"
+#include "command.h"
+#include "colors.h"
-} list_window_t;
+#include <glib.h>
+#include <stdbool.h>
-typedef struct
-{
- GList *list;
-} list_window_state_t;
+#ifdef HAVE_NCURSESW_NCURSES_H
+#include <ncursesw/ncurses.h>
+#else
+#include <ncurses.h>
+#endif
+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);
+
+struct list_window {
+ WINDOW *w;
+ unsigned rows, cols;
+
+ /**
+ * Number of items in this list.
+ */
+ unsigned length;
+
+ unsigned start;
+ unsigned selected;
+ unsigned range_base; /* represents the base item. */
+ bool range_selection; /* range selection activated */
+
+ bool hide_cursor;
+};
+
+/**
+ * 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 */
-list_window_t *list_window_init(WINDOW *w, int width, int height);
+struct list_window *list_window_init(WINDOW *w,
+ unsigned width, unsigned height);
/* destroy a list window (returns NULL) */
-list_window_t *list_window_free(list_window_t *lw);
+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);
-/* reset a list window (selected=0, start=0, clear=1) */
-void list_window_reset(list_window_t *lw);
+void
+list_window_set_length(struct list_window *lw, unsigned length);
/* paint a list window */
-void list_window_paint(list_window_t *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) */
-int list_window_cmd(list_window_t *lw, int rows, command_t cmd);
-
-
-/* select functions */
-void list_window_set_selected(list_window_t *lw, int n);
-void list_window_previous(list_window_t *lw, int length);
-void list_window_next(list_window_t *lw, int length);
-void list_window_first(list_window_t *lw);
-void list_window_last(list_window_t *lw, int length);
-void list_window_previous_page(list_window_t *lw);
-void list_window_next_page(list_window_t *lw, int length);
-void list_window_check_selected(list_window_t *lw, int length);
-/* not implemented yet */
-void list_window_right(list_window_t *lw, int length);
-void list_window_left(list_window_t *lw);
+bool
+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, command_t cmd);
+
+#ifdef HAVE_GETMOUSE
+/**
+ * The mouse was clicked. Check if the list should be scrolled
+ * Returns non-zero if the mouse event has been handled.
+ */
+bool
+list_window_mouse(struct list_window *lw, unsigned long bstate, int y);
+#endif
+
+void
+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);
+
+/**
+ * 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 */
-int list_window_find(list_window_t *lw,
- list_window_callback_fn_t callback,
- void *callback_data,
- char *str,
- int wrap);
+bool
+list_window_find(struct list_window *lw,
+ list_window_callback_fn_t callback,
+ void *callback_data,
+ const char *str,
+ bool wrap,
+ bool bell_on_wrap);
/* find a string in a list window (reversed) */
-int
-list_window_rfind(list_window_t *lw,
+bool
+list_window_rfind(struct list_window *lw,
list_window_callback_fn_t callback,
void *callback_data,
- char *str,
- int wrap,
- int rows);
-
-/* list window states */
-list_window_state_t *list_window_init_state(void);
-list_window_state_t *list_window_free_state(list_window_state_t *state);
-void list_window_push_state(list_window_state_t *state, list_window_t *lw);
-bool list_window_pop_state(list_window_state_t *state, list_window_t *lw);
-
-
+ const char *str,
+ bool wrap,
+ 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