1999-09-09 Federico Mena Quintero <federico@redhat.com>
[midnight-commander.git] / src / view.h
blob3ec93c23112a0731775ad00e8fcfc2af98ba7066
1 #ifndef __VIEW_H
2 #define __VIEW_H
4 #ifdef WANT_WIDGETS
5 /* The growing buffers data types */
6 typedef struct {
7 unsigned char *data;
8 int present; /* Unused, for DOS port maybe */
9 } block_ptr_t;
11 enum ViewSide {
12 view_side_left,
13 view_side_right
16 typedef struct {
17 Widget widget;
19 char *filename; /* Name of the file */
20 char *command; /* Command used to pipe data in */
21 char *localcopy;
22 int view_active;
23 int have_frame;
25 unsigned char *data; /* Memory area for the file to be viewed */
27 /* File information */
28 int file; /* File descriptor (for mmap and munmap) */
29 FILE *stdfile; /* Stdio struct for reading file in parts */
30 int reading_pipe; /* Flag: Reading from pipe(use popen/pclose) */
31 unsigned long bytes_read; /* How much of file is read */
32 int mmapping; /* Did we use mmap on the file? */
34 /* Display information */
35 unsigned long last; /* Last byte shown */
36 unsigned long last_byte; /* Last byte of file */
37 long first; /* First byte in file */
38 long bottom_first; /* First byte shown when very last page is displayed */
39 /* For the case of WINCH we should reset it to -1 */
40 unsigned long start_display;/* First char displayed */
41 int start_col; /* First displayed column, negative */
42 unsigned long edit_cursor; /* HexEdit cursor position in file */
43 char hexedit_mode; /* Hexidecimal editing mode flag */
44 char nib_shift; /* A flag for inserting nibbles into bytes */
45 enum ViewSide view_side; /* A flag for the active editing panel */
46 int file_dirty; /* Number of changes */
47 int start_save; /* Line start shift between Ascii and Hex */
48 int cursor_col; /* Cursor column */
49 int cursor_row; /* Cursor row */
50 struct hexedit_change_node *change_list; /* Linked list of changes */
52 int dirty; /* Number of skipped updates */
53 int wrap_mode; /* wrap_mode */
55 /* Mode variables */
56 int hex_mode; /* Hexadecimal mode flag */
57 int bytes_per_line; /* Number of bytes per line in hex mode */
58 int viewer_magic_flag; /* Selected viewer */
59 int viewer_nroff_flag; /* Do we do nroff style highlighting? */
61 /* Growing buffers information */
62 int growing_buffer; /* Use the growing buffers? */
63 block_ptr_t *block_ptr; /* Pointer to the block pointers */
64 int blocks; /* The number of blocks in *block_ptr */
67 /* Search variables */
68 int search_start; /* First character to start searching from */
69 int found_len; /* Length of found string or 0 if none was found */
70 char *search_exp; /* The search expression */
71 int direction; /* 1= forward; -1 backward */
72 void (*last_search)(void *, char *);
73 /* Pointer to the last search command */
74 int view_quit; /* Quit flag */
76 int monitor; /* Monitor file growth (like tail -f) */
77 /* Markers */
78 int marker; /* mark to use */
79 int marks [10]; /* 10 marks: 0..9 */
82 #ifdef HAVE_GNOME
83 int current_x, current_y; /* Current x,y position */
84 int color; /* Current color */
85 void *gtk_fname; /* filename widget */
86 void *gtk_offset; /* offset widget */
87 void *gtk_bytes; /* bytes */
88 void *gtk_flags; /* flags (growing) */
89 void *gtk_percent; /* percent */
90 void *sadj; /* scrollbar adjustment */
91 #endif
93 int move_dir; /* return value from widget:
94 * 0 do nothing
95 * -1 view previous file
96 * 1 view next file
98 struct stat s; /* stat for file */
99 } WView;
101 #define vwidth (view->widget.cols - (view->have_frame ? 2 : 0))
102 #define vheight (view->widget.lines - (view->have_frame ? 2 : 0))
104 /* Creation/initialization of a new view widget */
105 WView *view_new (int y, int x, int cols, int lines, int is_panel);
106 int view_init (WView *view, char *_command, char *_file, int start_line);
107 void view_update_bytes_per_line(WView *view);
108 int view_file (char *filename, int normal, int internal);
110 /* Internal view routines */
111 void view_status (WView *, gboolean update_gui);
112 void view_percent (WView *, int p, int w, gboolean update_gui);
113 void view_update (WView *view, gboolean update_gui);
114 void view_labels (WView *view);
115 int view_event (WView *view, Gpm_Event *event,int *result);
116 void toggle_wrap_mode (WView *);
117 void toggle_hex_mode (WView *);
118 void goto_line (WView *);
119 void regexp_search_cmd (WView *);
120 void normal_search_cmd (WView *);
121 void continue_search (WView *);
122 void change_nroff (WView *view);
123 void set_monitor (WView *view, int set_on);
124 void view_move_forward (WView *view, int i);
125 void view_move_backward (WView *view, int i);
126 void view_add_one_vline (void);
127 #endif
129 /* Command: view a file, if _command != NULL we use popen on _command */
130 /* move direction should be apointer that will hold the direction in which the user */
131 /* wants to move (-1 previous file, 1 next file, 0 do nothing) */
132 int view (char *_command, char *_file, int *move_direction, int start_line);
134 extern int mouse_move_pages_viewer;
135 extern int max_dirt_limit;
136 extern int global_wrap_mode;
137 extern int have_fast_cpu;
138 extern int default_hex_mode;
139 extern int default_magic_flag;
140 extern int default_nroff_flag;
141 extern int altered_hex_mode;
142 extern int altered_magic_flag;
143 extern int altered_nroff_flag;
145 void view_adjust_size (Dlg_head *);
147 /* A node for building a change list on change_list */
148 struct hexedit_change_node {
149 struct hexedit_change_node *next;
150 long offset;
151 unsigned char value;
154 #ifdef HAVE_TK
155 #define DEF_COLOR 0
156 #define BOLD_COLOR 1
157 #define UNDERLINE_COLOR 2
158 #define MARK_COLOR 3
159 #endif
161 #ifdef HAVE_X
162 #ifdef WANT_WIDGETS
163 void view_add_character (WView *view, int c);
164 void view_add_string (WView *view, char *s);
165 void view_gotoyx (WView *view, int r, int c);
166 void view_set_color (WView *view, int font);
167 void view_display_clean (WView *view, int h, int w);
169 void x_destroy_view (WView *);
170 void x_create_viewer (WView *);
171 void x_focus_view (WView *);
172 void x_init_view (WView *);
174 #ifdef PORT_HAS_VIEW_FREEZE
175 void view_freeze (WView *view);
176 void view_thaw (WView *view);
177 #endif
179 #endif
180 #else
181 # define x_init_view(x)
182 # define x_destroy_view(x)
183 # define x_create_viewer(x)
184 # define x_focus_view(x)
185 #endif
187 #endif /* __VIEW_H */