forked from cmus/cmus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.h
104 lines (87 loc) · 3.41 KB
/
window.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Copyright 2008-2013 Various Authors
* Copyright 2004-2005 Timo Hirvonen
*
* 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.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CMUS_WINDOW_H
#define CMUS_WINDOW_H
#include "iter.h"
/*
* window contains list of rows
* - the list is double linked circular list
* - head contains no data. head is not a real row
* - head->prev gets the last row (or head if the list is empty) in the list
* - head->next gets the first row (or head if the list is empty) in the list
*
* get_prev(&iter) always stores prev row to the iter
* get_next(&iter) always stores next row to the iter
*
* these return 1 if the new row is real row (not head), 0 otherwise
*
* sel_changed callback is called if not NULL and selection has changed
*/
struct window {
/* head of the row list */
struct iter head;
/* top row */
struct iter top;
/* selected row */
struct iter sel;
/* window height */
int nr_rows;
unsigned changed : 1;
/* return 1 if got next/prev, otherwise 0 */
int (*get_prev)(struct iter *iter);
int (*get_next)(struct iter *iter);
/* NULL if all rows are selectable */
int (*selectable)(struct iter *iter);
void (*sel_changed)(void);
};
struct window *window_new(int (*get_prev)(struct iter *), int (*get_next)(struct iter *));
void window_free(struct window *win);
void window_set_empty(struct window *win);
void window_set_contents(struct window *win, void *head);
/* call this after rows were added to window or order of rows was changed.
* top and sel MUST point to valid rows (or window must be empty, but then
* why do you want to call this function :)).
*
* if you remove row from window then call window_row_vanishes BEFORE removing
* the row instead of this function.
*/
void window_changed(struct window *win);
/* call this BEFORE row is removed from window */
void window_row_vanishes(struct window *win, struct iter *iter);
int window_get_top(struct window *win, struct iter *iter);
int window_get_sel(struct window *win, struct iter *iter);
int window_get_prev(struct window *win, struct iter *iter);
int window_get_next(struct window *win, struct iter *iter);
/* set selected row */
void window_set_sel(struct window *win, struct iter *iter);
void window_set_nr_rows(struct window *win, int nr_rows);
void window_up(struct window *win, int rows);
void window_down(struct window *win, int rows);
void window_goto_top(struct window *win);
void window_goto_bottom(struct window *win);
void window_page_up(struct window *win);
void window_half_page_up(struct window *win);
void window_page_down(struct window *win);
void window_half_page_down(struct window *win);
void window_scroll_down(struct window *win);
void window_scroll_up(struct window *win);
void window_page_top(struct window *win);
void window_page_bottom(struct window *win);
void window_page_middle(struct window *win);
int window_get_nr_rows(struct window *win);
#endif