1 /* vifm
2  * Copyright (C) 2001 Ken Steen.
3  * Copyright (C) 2011 xaizek.
4  *
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.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19 
20 #ifndef VIFM__UI__FILEVIEW_H__
21 #define VIFM__UI__FILEVIEW_H__
22 
23 #include "../utils/test_helpers.h"
24 
25 struct view_t;
26 
27 /* Initialization/termination functions. */
28 
29 /* Initializes file view unit. */
30 void fview_setup(void);
31 
32 /* Initializes view once before. */
33 void fview_init(struct view_t *view);
34 
35 /* Resets view state partially. */
36 void fview_reset(struct view_t *view);
37 
38 /* Resets view state with regard to color schemes. */
39 void fview_reset_cs(struct view_t *view);
40 
41 /* Appearance related functions. */
42 
43 /* Redraws directory list and puts inactive mark for the other view. */
44 void draw_dir_list(struct view_t *view);
45 
46 /* Redraws directory list without putting inactive mark if view == other. */
47 void draw_dir_list_only(struct view_t *view);
48 
49 /* Updates view (maybe postponed) on the screen (redraws file list and
50  * cursor). */
51 void redraw_view(struct view_t *view);
52 
53 /* Updates current view (maybe postponed) on the screen (redraws file list and
54  * cursor) */
55 void redraw_current_view(void);
56 
57 /* Draws inactive cursor on the view. */
58 void fview_draw_inactive_cursor(struct view_t *view);
59 
60 /* Redraws cursor of the view on the screen. */
61 void fview_cursor_redraw(struct view_t *view);
62 
63 /* Scrolling related functions. */
64 
65 /* Checks if view can be scrolled up (there are more files).  Returns non-zero
66  * if so, and zero otherwise. */
67 int can_scroll_up(const struct view_t *view);
68 
69 /* Checks if view can be scrolled down (there are more files).  Returns non-zero
70  * if so, and zero otherwise. */
71 int can_scroll_down(const struct view_t *view);
72 
73 /* Scrolls view up at least by specified number of files.  Updates both top and
74  * cursor positions. */
75 void scroll_up(struct view_t *view, int by);
76 
77 /* Scrolls view down at least by specified number of files.  Updates both top
78  * and cursor positions. */
79 void scroll_down(struct view_t *view, int by);
80 
81 /* Calculates list position corrected for scrolling down.  Returns adjusted
82  * position. */
83 int get_corrected_list_pos_down(const struct view_t *view, int pos_delta);
84 
85 /* Calculates list position corrected for scrolling up.  Returns adjusted
86  * position. */
87 int get_corrected_list_pos_up(const struct view_t *view, int pos_delta);
88 
89 /* Updates current and top line of a view according to 'scrolloff' option value.
90  * Returns non-zero if redraw is needed. */
91 int consider_scroll_offset(struct view_t *view);
92 
93 /* Scrolls view down or up at least by specified number of files.  Updates both
94  * top and cursor positions.  A wrapper for scroll_up() and scroll_down()
95  * functions. */
96 void scroll_by_files(struct view_t *view, int by);
97 
98 /* Recalculates difference of two panes scroll positions. */
99 void update_scroll_bind_offset(void);
100 
101 /* Layout related functions. */
102 
103 /* Enables/disables ls-like style of the view. */
104 void fview_set_lsview(struct view_t *view, int enabled);
105 
106 /* Checks whether view displays grid that's filled by column. */
107 int fview_is_transposed(const struct view_t *view);
108 
109 /* Enables/disables cascading columns style of the view. */
110 void fview_set_millerview(struct view_t *view, int enabled);
111 
112 /* Requests update of view geometry properties (stuff that depends on
113  * dimensions; there is also an implicit dependency on file list, because grid
114  * is defined by longest file name). */
115 void fview_update_geometry(struct view_t *view);
116 
117 /* Callback-like function which triggers some view-specific updates after
118  * directory of the view changes. */
119 void fview_dir_updated(struct view_t *view);
120 
121 /* Callback-like function which triggers some view-specific updates after list
122  * of files changes. */
123 void fview_list_updated(struct view_t *view);
124 
125 /* Callback-like function which triggers some view-specific updates after cursor
126  * position in the list changed. */
127 void fview_position_updated(struct view_t *view);
128 
129 /* Callback-like function which triggers some view-specific updates after view
130  * sorting changed. */
131 void fview_sorting_updated(struct view_t *view);
132 
133 #ifdef TEST
134 #include <stddef.h> /* size_t */
135 
136 #include "ui.h"
137 #endif
138 
139 TSTATIC_DEFS(
140 	/* Packet set of parameters to pass as user data for processing columns. */
141 	typedef struct
142 	{
143 		struct view_t *view; /* View on which cell is being drawn. */
144 		dir_entry_t *entry;  /* Entry that is being displayed. */
145 		int line_pos;        /* File position in the file list (the view). */
146 		int line_hi_group;   /* Line highlight (to avoid per-column calculation). */
147 		int current_pos;     /* Position of entry selected with the cursor. */
148 		int total_width;     /* Total width available for drawing. */
149 		int number_width;    /* Width of line number column (0 when disabled). */
150 
151 		size_t current_line;  /* Line of the cell within the view window. */
152 		size_t column_offset; /* Offset in characters of the column. */
153 
154 		size_t *prefix_len; /* Data prefix length (should be drawn in neutral
155 		                       color).  A pointer to allow changing value in const
156 		                       struct.  Should be zero first time, then auto
157 		                       reset. */
158 		int is_main;        /* Whether this is main file list. */
159 	}
160 	column_data_t;
161 
162 	void format_name(int id, const void *data, size_t buf_len, char buf[]);
163 )
164 
165 #endif /* VIFM__UI__FILEVIEW_H__ */
166 
167 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
168 /* vim: set cinoptions+=t0 filetype=c : */
169