1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2018 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
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.
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.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef LIST_WINDOW_HXX
21 #define LIST_WINDOW_HXX
24 #include "ncmpc_curses.h"
26 #include "util/Compiler.h"
28 enum class Command : unsigned;
33 * The bounds of a range selection, see list_window_get_range().
35 struct ListWindowRange {
37 * The index of the first selected item.
42 * The index after the last selected item. The selection is
43 * empty when this is the same as "start".
47 constexpr bool empty() const {
48 return start_index >= end_index;
51 constexpr bool Contains(unsigned i) const {
52 return i >= start_index && i < end_index;
55 struct const_iterator {
58 const_iterator &operator++() {
63 constexpr bool operator==(const const_iterator &other) const {
64 return value == other.value;
67 constexpr bool operator!=(const const_iterator &other) const {
68 return !(*this == other);
71 const unsigned &operator *() const {
76 constexpr const_iterator begin() const {
80 constexpr const_iterator end() const {
91 * Number of items in this list.
96 unsigned selected = 0;
99 * Represents the base item.
101 unsigned range_base = 0;
104 * Range selection activated?
106 bool range_selection = false;
108 bool hide_cursor = false;
110 ListWindow(WINDOW *_w, Size _size)
111 :w(_w), size(_size) {}
113 /** reset a list window (selected=0, start=0) */
116 void Resize(Size _size);
118 void SetLength(unsigned length);
120 void Paint(const ListRenderer &renderer) const;
122 /** perform basic list window commands (movement) */
123 bool HandleCommand(Command cmd);
126 * Scroll the window. Returns true if the command has been
129 bool HandleScrollCommand(Command cmd);
133 * The mouse was clicked. Check if the list should be scrolled
134 * Returns non-zero if the mouse event has been handled.
136 bool HandleMouse(mmask_t bstate, int y);
140 * Centers the visible range around item n on the list.
142 void Center(unsigned n);
145 * Scrolls the view to item n, as if the cursor would have been moved
148 void ScrollTo(unsigned n);
151 * Sets the position of the cursor. Disables range selection.
153 void SetCursor(unsigned i);
156 * Moves the cursor. Modifies the range if range selection is
159 void MoveCursor(unsigned n);
161 void MoveCursorNext();
162 void MoveCursorPrevious();
163 void MoveCursorTop();
164 void MoveCursorMiddle();
165 void MoveCursorBottom();
166 void MoveCursorFirst();
167 void MoveCursorLast();
168 void MoveCursorNextPage();
169 void MoveCursorPreviousPage();
171 void ScrollUp(unsigned n);
172 void ScrollDown(unsigned n);
175 * Ensures that the cursor is visible on the screen, i.e. it is not
176 * outside the current scrolling range.
181 * Determines the lower and upper bound of the range selection. If
182 * range selection is disabled, it returns the cursor position (range
186 ListWindowRange GetRange() const;
189 * Find a string in a list window.
191 bool Find(const ListText &text,
197 * Find a string in a list window (reversed).
199 bool ReverseFind(const ListText &text,
205 * Find a string in a list window which begins with the given
206 * characters in *str.
208 bool Jump(const ListText &text, const char *str);
212 unsigned ValidateIndex(unsigned i) const;
214 void CheckSelected();
217 * Scroll after the cursor was moved, the list was changed or
218 * the window was resized.