WView: remove WView::active. Use WST_FOCUSED instead.
[midnight-commander.git] / src / viewer / internal.h
blob2b2886a948f295bc101298451a7b3e3298513bdf
1 #ifndef MC__VIEWER_INTERNAL_H
2 #define MC__VIEWER_INTERNAL_H
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <sys/types.h>
8 #include "lib/global.h"
10 #include "lib/search.h"
11 #include "lib/widget.h"
12 #include "lib/vfs/vfs.h" /* vfs_path_t */
14 #include "src/keybind-defaults.h" /* global_keymap_t */
15 #include "src/filemanager/dir.h" /* dir_list */
17 #include "mcviewer.h"
19 /*** typedefs(not structures) and defined constants **********************************************/
21 typedef unsigned char byte;
23 /* A width or height on the screen */
24 typedef unsigned int screen_dimen;
26 extern const off_t OFFSETTYPE_MAX;
28 /*** enums ***************************************************************************************/
30 /* data sources of the view */
31 enum view_ds
33 DS_NONE, /* No data available */
34 DS_STDIO_PIPE, /* Data comes from a pipe using popen/pclose */
35 DS_VFS_PIPE, /* Data comes from a piped-in VFS file */
36 DS_FILE, /* Data comes from a VFS file */
37 DS_STRING /* Data comes from a string in memory */
40 enum ccache_type
42 CCACHE_OFFSET,
43 CCACHE_LINECOL
46 typedef enum
48 NROFF_TYPE_NONE = 0,
49 NROFF_TYPE_BOLD = 1,
50 NROFF_TYPE_UNDERLINE = 2
51 } nroff_type_t;
53 /*** structures declarations (and typedefs of structures)*****************************************/
55 /* A node for building a change list on change_list */
56 struct hexedit_change_node
58 struct hexedit_change_node *next;
59 off_t offset;
60 byte value;
63 struct area
65 screen_dimen top, left;
66 screen_dimen height, width;
69 /* A cache entry for mapping offsets into line/column pairs and vice versa.
70 * cc_offset, cc_line, and cc_column are the 0-based values of the offset,
71 * line and column of that cache entry. cc_nroff_column is the column
72 * corresponding to cc_offset in nroff mode.
74 typedef struct
76 off_t cc_offset;
77 off_t cc_line;
78 off_t cc_column;
79 off_t cc_nroff_column;
80 } coord_cache_entry_t;
82 typedef struct
84 size_t size;
85 size_t capacity;
86 coord_cache_entry_t **cache;
87 } coord_cache_t;
89 /* TODO: find a better name. This is not actually a "state machine",
90 * but a "state machine's state", but that sounds silly.
91 * Could be parser_state, formatter_state... */
92 typedef struct
94 off_t offset; /* The file offset at which this is the state. */
95 off_t unwrapped_column; /* Columns if the paragraph wasn't wrapped, */
96 /* used for positioning TABs in wrapped lines */
97 gboolean nroff_underscore_is_underlined; /* whether _\b_ is underlined rather than bold */
98 gboolean print_lonely_combining; /* whether lonely combining marks are printed on a dotted circle */
99 } mcview_state_machine_t;
101 struct mcview_nroff_struct;
103 struct WView
105 Widget widget;
107 vfs_path_t *filename_vpath; /* Name of the file */
108 vfs_path_t *workdir_vpath; /* Name of the working directory */
109 char *command; /* Command used to pipe data in */
111 enum view_ds datasource; /* Where the displayed data comes from */
113 /* stdio pipe data source */
114 mc_pipe_t *ds_stdio_pipe; /* Output of a shell command */
115 gboolean pipe_first_err_msg; /* Show only 1st message from stderr */
117 /* vfs pipe data source */
118 int ds_vfs_pipe; /* Non-seekable vfs file descriptor */
120 /* vfs file data source */
121 int ds_file_fd; /* File with random access */
122 off_t ds_file_filesize; /* Size of the file */
123 off_t ds_file_offset; /* Offset of the currently loaded data */
124 byte *ds_file_data; /* Currently loaded data */
125 size_t ds_file_datalen; /* Number of valid bytes in file_data */
126 size_t ds_file_datasize; /* Number of allocated bytes in file_data */
128 /* string data source */
129 byte *ds_string_data; /* The characters of the string */
130 size_t ds_string_len; /* The length of the string */
132 /* Growing buffers information */
133 gboolean growbuf_in_use; /* Use the growing buffers? */
134 GPtrArray *growbuf_blockptr; /* Pointer to the block pointers */
135 size_t growbuf_lastindex; /* Number of bytes in the last page of the
136 growing buffer */
137 gboolean growbuf_finished; /* TRUE when all data has been read. */
139 /* Editor modes */
140 gboolean hex_mode; /* Hexview or Hexedit */
141 gboolean hexedit_mode; /* Hexedit */
142 gboolean hexview_in_text; /* Is the hexview cursor in the text area? */
143 gboolean text_nroff_mode; /* Nroff-style highlighting */
144 gboolean text_wrap_mode; /* Wrap text lines to fit them on the screen */
145 gboolean magic_mode; /* Preprocess the file using external programs */
146 gboolean hexedit_lownibble; /* Are we editing the last significant nibble? */
147 gboolean locked; /* We hold lock on current file */
149 #ifdef HAVE_CHARSET
150 gboolean utf8; /* It's multibyte file codeset */
151 #endif
153 coord_cache_t *coord_cache; /* Cache for mapping offsets to cursor positions */
155 /* Display information */
156 screen_dimen dpy_frame_size; /* Size of the frame surrounding the real viewer */
157 off_t dpy_start; /* Offset of the displayed data (start of the paragraph in non-hex mode) */
158 off_t dpy_end; /* Offset after the displayed data */
159 off_t dpy_paragraph_skip_lines; /* Extra lines to skip in wrap mode */
160 mcview_state_machine_t dpy_state_top; /* Parser-formatter state at the topmost visible line in wrap mode */
161 mcview_state_machine_t dpy_state_bottom; /* Parser-formatter state after the bottomvisible line in wrap mode */
162 gboolean dpy_wrap_dirty; /* dpy_state_top needs to be recomputed */
163 off_t dpy_text_column; /* Number of skipped columns in non-wrap
164 * text mode */
165 off_t hex_cursor; /* Hexview cursor position in file */
166 screen_dimen cursor_col; /* Cursor column */
167 screen_dimen cursor_row; /* Cursor row */
168 struct hexedit_change_node *change_list; /* Linked list of changes */
169 struct area status_area; /* Where the status line is displayed */
170 struct area ruler_area; /* Where the ruler is displayed */
171 struct area data_area; /* Where the data is displayed */
173 ssize_t force_max; /* Force a max offset, or -1 */
175 int dirty; /* Number of skipped updates */
176 gboolean dpy_bbar_dirty; /* Does the button bar need to be updated? */
178 /* Mode variables */
179 int bytes_per_line; /* Number of bytes per line in hex mode */
181 /* Search variables */
182 off_t search_start; /* First character to start searching from */
183 off_t search_end; /* Length of found string or 0 if none was found */
185 /* Markers */
186 int marker; /* mark to use */
187 off_t marks[10]; /* 10 marks: 0..9 */
189 off_t update_steps; /* The number of bytes between percent
190 * increments */
191 off_t update_activate; /* Last point where we updated the status */
193 /* converter for translation of text */
194 GIConv converter;
196 /* handle of search engine */
197 mc_search_t *search;
198 gchar *last_search_string;
199 struct mcview_nroff_struct *search_nroff_seq;
201 int search_numNeedSkipChar;
203 GArray *saved_bookmarks;
205 dir_list *dir; /* List of current directory files
206 * to handle CK_FileNext and CK_FilePrev commands */
207 int *dir_idx; /* Index of current file in dir structure.
208 * Pointer is used here as reference to WPanel::dir::count */
209 vfs_path_t *ext_script; /* Temporary script file created by regex_command_for() */
212 typedef struct mcview_nroff_struct
214 WView *view;
215 off_t index;
216 int char_length;
217 int current_char;
218 nroff_type_t type;
219 nroff_type_t prev_type;
220 } mcview_nroff_t;
222 typedef struct mcview_search_options_t
224 mc_search_type_t type;
225 gboolean case_sens;
226 gboolean backwards;
227 gboolean whole_words;
228 gboolean all_codepages;
229 } mcview_search_options_t;
231 /*** global variables defined in .c file *********************************************************/
233 extern mcview_search_options_t mcview_search_options;
235 /*** declarations of public functions ************************************************************/
237 /* actions_cmd.c: */
238 cb_ret_t mcview_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
239 cb_ret_t mcview_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm,
240 void *data);
242 /* ascii.c: */
243 void mcview_display_text (WView *);
244 void mcview_state_machine_init (mcview_state_machine_t *, off_t);
245 void mcview_ascii_move_down (WView *, off_t);
246 void mcview_ascii_move_up (WView *, off_t);
247 void mcview_ascii_moveto_bol (WView *);
248 void mcview_ascii_moveto_eol (WView *);
250 /* coord_cache.c: */
251 coord_cache_t *coord_cache_new (void);
252 void coord_cache_free (coord_cache_t * cache);
254 #ifdef MC_ENABLE_DEBUGGING_CODE
255 void mcview_ccache_dump (WView * view);
256 #endif
258 void mcview_ccache_lookup (WView * view, coord_cache_entry_t * coord, enum ccache_type lookup_what);
260 /* datasource.c: */
261 void mcview_set_datasource_none (WView *);
262 off_t mcview_get_filesize (WView *);
263 void mcview_update_filesize (WView * view);
264 char *mcview_get_ptr_file (WView *, off_t);
265 char *mcview_get_ptr_string (WView *, off_t);
266 gboolean mcview_get_utf (WView * view, off_t byte_index, int *ch, int *ch_len);
267 gboolean mcview_get_byte_string (WView *, off_t, int *);
268 gboolean mcview_get_byte_none (WView *, off_t, int *);
269 void mcview_set_byte (WView *, off_t, byte);
270 void mcview_file_load_data (WView *, off_t);
271 void mcview_close_datasource (WView *);
272 void mcview_set_datasource_file (WView *, int, const struct stat *);
273 gboolean mcview_load_command_output (WView *, const char *);
274 void mcview_set_datasource_vfs_pipe (WView *, int);
275 void mcview_set_datasource_string (WView *, const char *);
277 /* dialog.c: */
278 gboolean mcview_dialog_search (WView * view);
279 gboolean mcview_dialog_goto (WView * view, off_t * offset);
281 /* display.c: */
282 void mcview_update (WView * view);
283 void mcview_display (WView * view);
284 void mcview_compute_areas (WView * view);
285 void mcview_update_bytes_per_line (WView * view);
286 void mcview_display_toggle_ruler (WView * view);
287 void mcview_display_clean (WView * view);
288 void mcview_display_ruler (WView * view);
290 /* growbuf.c: */
291 void mcview_growbuf_init (WView * view);
292 void mcview_growbuf_done (WView * view);
293 void mcview_growbuf_free (WView * view);
294 off_t mcview_growbuf_filesize (WView * view);
295 void mcview_growbuf_read_until (WView * view, off_t p);
296 gboolean mcview_get_byte_growing_buffer (WView * view, off_t p, int *);
297 char *mcview_get_ptr_growing_buffer (WView * view, off_t p);
299 /* hex.c: */
300 void mcview_display_hex (WView * view);
301 gboolean mcview_hexedit_save_changes (WView * view);
302 void mcview_toggle_hexedit_mode (WView * view);
303 void mcview_hexedit_free_change_list (WView * view);
304 void mcview_enqueue_change (struct hexedit_change_node **, struct hexedit_change_node *);
306 /* lib.c: */
307 void mcview_toggle_magic_mode (WView * view);
308 void mcview_toggle_wrap_mode (WView * view);
309 void mcview_toggle_nroff_mode (WView * view);
310 void mcview_toggle_hex_mode (WView * view);
311 void mcview_init (WView * view);
312 void mcview_done (WView * view);
313 void mcview_select_encoding (WView * view);
314 void mcview_set_codeset (WView * view);
315 void mcview_show_error (WView * view, const char *error);
316 off_t mcview_bol (WView * view, off_t current, off_t limit);
317 off_t mcview_eol (WView * view, off_t current, off_t limit);
318 char *mcview_get_title (const WDialog * h, size_t len);
319 int mcview_calc_percent (WView * view, off_t p);
321 /* move.c */
322 void mcview_move_up (WView *, off_t);
323 void mcview_move_down (WView *, off_t);
324 void mcview_move_left (WView *, off_t);
325 void mcview_move_right (WView *, off_t);
326 void mcview_moveto_top (WView *);
327 void mcview_moveto_bottom (WView *);
328 void mcview_moveto_bol (WView *);
329 void mcview_moveto_eol (WView *);
330 void mcview_moveto_offset (WView *, off_t);
331 void mcview_moveto (WView *, off_t, off_t);
332 void mcview_coord_to_offset (WView *, off_t *, off_t, off_t);
333 void mcview_offset_to_coord (WView *, off_t *, off_t *, off_t);
334 void mcview_place_cursor (WView *);
335 void mcview_moveto_match (WView *);
337 /* nroff.c: */
338 int mcview__get_nroff_real_len (WView * view, off_t, off_t p);
339 mcview_nroff_t *mcview_nroff_seq_new_num (WView * view, off_t p);
340 mcview_nroff_t *mcview_nroff_seq_new (WView * view);
341 void mcview_nroff_seq_free (mcview_nroff_t **);
342 nroff_type_t mcview_nroff_seq_info (mcview_nroff_t *);
343 int mcview_nroff_seq_next (mcview_nroff_t *);
344 int mcview_nroff_seq_prev (mcview_nroff_t *);
346 /* search.c: */
347 mc_search_cbret_t mcview_search_cmd_callback (const void *user_data, gsize char_offset,
348 int *current_char);
349 mc_search_cbret_t mcview_search_update_cmd_callback (const void *user_data, gsize char_offset);
350 void mcview_do_search (WView * view, off_t want_search_start);
352 /*** inline functions ****************************************************************************/
354 #include "inlines.h"
356 #endif /* MC__VIEWER_INTERNAL_H */