Remove input_set_origin(). Use widget_set_size() instead.
[midnight-commander.git] / src / editor / edit-impl.h
blobe840d30eaf243871db663ed742cc8bf7a5ee1902
1 /*
2 editor private API
3 */
5 /** \file edit-impl.h
6 * \brief Header: editor low level data handling and cursor fundamentals
7 * \author Paul Sheer
8 * \date 1996, 1997
9 */
11 #ifndef MC__EDIT_IMPL_H
12 #define MC__EDIT_IMPL_H
14 #include <stdio.h>
16 #include "lib/search.h" /* mc_search_type_t */
17 #include "lib/widget.h" /* cb_ret_t */
18 #include "lib/vfs/vfs.h" /* vfs_path_t */
20 #include "edit.h"
22 /*** typedefs(not structures) and defined constants **********************************************/
24 #define REDRAW_LINE (1 << 0)
25 #define REDRAW_LINE_ABOVE (1 << 1)
26 #define REDRAW_LINE_BELOW (1 << 2)
27 #define REDRAW_AFTER_CURSOR (1 << 3)
28 #define REDRAW_BEFORE_CURSOR (1 << 4)
29 #define REDRAW_PAGE (1 << 5)
30 #define REDRAW_IN_BOUNDS (1 << 6)
31 #define REDRAW_CHAR_ONLY (1 << 7)
32 #define REDRAW_COMPLETELY (1 << 8)
34 #define EDIT_TEXT_HORIZONTAL_OFFSET 0
35 #define EDIT_TEXT_VERTICAL_OFFSET 0
37 #define EDIT_RIGHT_EXTREME option_edit_right_extreme
38 #define EDIT_LEFT_EXTREME option_edit_left_extreme
39 #define EDIT_TOP_EXTREME option_edit_top_extreme
40 #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
42 /* Initial size of the undo stack, in bytes */
43 #define START_STACK_SIZE 32
45 /* Some codes that may be pushed onto or returned from the undo stack */
46 #define CURS_LEFT 601
47 #define CURS_RIGHT 602
48 #define DELCHAR 603
49 #define BACKSPACE 604
50 #define STACK_BOTTOM 605
51 #define CURS_LEFT_LOTS 606
52 #define CURS_RIGHT_LOTS 607
53 #define COLUMN_ON 608
54 #define COLUMN_OFF 609
55 #define DELCHAR_BR 610
56 #define BACKSPACE_BR 611
57 #define MARK_1 1000
58 #define MARK_2 500000000
59 #define MARK_CURS 1000000000
60 #define KEY_PRESS 1500000000
62 /* Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
63 #define TAB_SIZE option_tab_spacing
64 #define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
66 /* max count stack files */
67 #define MAX_HISTORY_MOVETO 50
68 #define LINE_STATE_WIDTH 8
70 #define LB_NAMES (LB_MAC + 1)
72 #define get_sys_error(s) (s)
74 #define edit_error_dialog(h,s) query_dialog (h, s, D_ERROR, 1, _("&Dismiss"))
76 #define edit_query_dialog2(h,t,a,b) query_dialog (h, t, D_NORMAL, 2, a, b)
77 #define edit_query_dialog3(h,t,a,b,c) query_dialog (h, t, D_NORMAL, 3, a, b, c)
79 /*** enums ***************************************************************************************/
81 /* line breaks */
82 typedef enum
84 LB_ASIS = 0,
85 LB_UNIX,
86 LB_WIN,
87 LB_MAC
88 } LineBreaks;
90 typedef enum
92 EDIT_QUICK_SAVE = 0,
93 EDIT_SAFE_SAVE,
94 EDIT_DO_BACKUP
95 } edit_save_mode_t;
97 /*** structures declarations (and typedefs of structures)*****************************************/
99 /* search/replace options */
100 typedef struct edit_search_options_t
102 mc_search_type_t type;
103 gboolean case_sens;
104 gboolean backwards;
105 gboolean only_in_selection;
106 gboolean whole_words;
107 gboolean all_codepages;
108 } edit_search_options_t;
110 typedef struct edit_stack_type
112 long line;
113 vfs_path_t *filename_vpath;
114 } edit_stack_type;
116 struct Widget;
117 struct WMenuBar;
119 /*** global variables defined in .c file *********************************************************/
121 extern const char VERTICAL_MAGIC[5];
122 /* if enable_show_tabs_tws ==1 then use visible_tab visible_tws */
123 extern int enable_show_tabs_tws;
125 extern edit_search_options_t edit_search_options;
127 extern unsigned int edit_stack_iterator;
128 extern edit_stack_type edit_history_moveto[MAX_HISTORY_MOVETO];
130 extern int option_line_state_width;
132 extern int option_max_undo;
133 extern int option_auto_syntax;
135 extern int option_edit_right_extreme;
136 extern int option_edit_left_extreme;
137 extern int option_edit_top_extreme;
138 extern int option_edit_bottom_extreme;
140 extern gboolean search_create_bookmark;
142 extern char *edit_window_state_char;
143 extern char *edit_window_close_char;
145 /*** declarations of public functions ************************************************************/
147 gboolean edit_add_window (WDialog * h, int y, int x, int lines, int cols,
148 const vfs_path_t * f, long fline);
149 WEdit *find_editor (const WDialog * h);
150 gboolean edit_widget_is_editor (const Widget * w);
151 gboolean edit_drop_hotkey_menu (WDialog * h, int key);
152 void edit_menu_cmd (WDialog * h);
153 void user_menu (WEdit * edit, const char *menu_file, int selected_entry);
154 void edit_init_menu (struct WMenuBar *menubar);
155 void edit_save_mode_cmd (void);
156 off_t edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto);
157 void edit_scroll_screen_over_cursor (WEdit * edit);
158 void edit_render_keypress (WEdit * edit);
159 void edit_scroll_upward (WEdit * edit, long i);
160 void edit_scroll_downward (WEdit * edit, long i);
161 void edit_scroll_right (WEdit * edit, long i);
162 void edit_scroll_left (WEdit * edit, long i);
163 void edit_move_up (WEdit * edit, long i, gboolean do_scroll);
164 void edit_move_down (WEdit * edit, long i, gboolean do_scroll);
165 void edit_move_to_prev_col (WEdit * edit, off_t p);
166 long edit_get_col (const WEdit * edit);
167 void edit_update_curs_row (WEdit * edit);
168 void edit_update_curs_col (WEdit * edit);
169 void edit_find_bracket (WEdit * edit);
170 gboolean edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line);
171 void edit_set_codeset (WEdit * edit);
173 void edit_block_copy_cmd (WEdit * edit);
174 void edit_block_move_cmd (WEdit * edit);
175 int edit_block_delete_cmd (WEdit * edit);
176 void edit_delete_line (WEdit * edit);
178 int edit_delete (WEdit * edit, gboolean byte_delete);
179 int edit_backspace (WEdit * edit, gboolean byte_delete);
180 void edit_insert (WEdit * edit, int c);
181 void edit_insert_over (WEdit * edit);
182 void edit_cursor_move (WEdit * edit, off_t increment);
183 void edit_push_undo_action (WEdit * edit, long c);
184 void edit_push_redo_action (WEdit * edit, long c);
185 void edit_push_key_press (WEdit * edit);
186 void edit_insert_ahead (WEdit * edit, int c);
187 off_t edit_write_stream (WEdit * edit, FILE * f);
188 char *edit_get_write_filter (const vfs_path_t * write_name_vpath,
189 const vfs_path_t * filename_vpath);
190 gboolean edit_save_confirm_cmd (WEdit * edit);
191 gboolean edit_save_as_cmd (WEdit * edit);
192 WEdit *edit_init (WEdit * edit, int y, int x, int lines, int cols,
193 const vfs_path_t * filename_vpath, long line);
194 gboolean edit_clean (WEdit * edit);
195 gboolean edit_ok_to_exit (WEdit * edit);
196 gboolean edit_load_cmd (WDialog * h);
197 gboolean edit_load_syntax_file (WDialog * h);
198 gboolean edit_load_menu_file (WDialog * h);
199 gboolean edit_close_cmd (WEdit * edit);
200 void edit_mark_cmd (WEdit * edit, gboolean unmark);
201 void edit_mark_current_word_cmd (WEdit * edit);
202 void edit_mark_current_line_cmd (WEdit * edit);
203 void edit_set_markers (WEdit * edit, off_t m1, off_t m2, long c1, long c2);
204 void edit_push_markers (WEdit * edit);
205 void edit_replace_cmd (WEdit * edit, int again);
206 void edit_search_cmd (WEdit * edit, gboolean again);
207 mc_search_cbret_t edit_search_cmd_callback (const void *user_data, gsize char_offset,
208 int *current_char);
209 void edit_complete_word_cmd (WEdit * edit);
210 void edit_get_match_keyword_cmd (WEdit * edit);
212 #ifdef HAVE_ASPELL
213 int edit_suggest_current_word (WEdit * edit);
214 void edit_spellcheck_file (WEdit * edit);
215 void edit_set_spell_lang (void);
216 #endif
218 gboolean edit_save_block (WEdit * edit, const char *filename, off_t start, off_t finish);
219 gboolean edit_save_block_cmd (WEdit * edit);
220 gboolean edit_insert_file_cmd (WEdit * edit);
222 off_t edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath);
223 gboolean edit_load_back_cmd (WEdit * edit);
224 gboolean edit_load_forward_cmd (WEdit * edit);
225 void edit_block_process_cmd (WEdit * edit, int macro_number);
226 void edit_refresh_cmd (void);
227 void edit_syntax_onoff_cmd (WDialog * h);
228 void edit_show_tabs_tws_cmd (WDialog * h);
229 void edit_show_margin_cmd (WDialog * h);
230 void edit_show_numbers_cmd (WDialog * h);
231 void edit_date_cmd (WEdit * edit);
232 void edit_goto_cmd (WEdit * edit);
233 gboolean eval_marks (WEdit * edit, off_t * start_mark, off_t * end_mark);
234 void edit_status (WEdit * edit, gboolean active);
235 void edit_execute_key_command (WEdit * edit, unsigned long command, int char_for_insertion);
236 void edit_update_screen (WEdit * edit);
237 void edit_save_size (WEdit * edit);
238 gboolean edit_handle_move_resize (WEdit * edit, unsigned long command);
239 void edit_toggle_fullscreen (WEdit * edit);
240 void edit_move_to_line (WEdit * e, long line);
241 void edit_move_display (WEdit * e, long line);
242 void edit_word_wrap (WEdit * edit);
243 int edit_sort_cmd (WEdit * edit);
244 int edit_ext_cmd (WEdit * edit);
246 int edit_store_macro_cmd (WEdit * edit);
247 gboolean edit_load_macro_cmd (WEdit * edit);
248 void edit_delete_macro_cmd (WEdit * edit);
249 gboolean edit_repeat_macro_cmd (WEdit * edit);
251 gboolean edit_copy_to_X_buf_cmd (WEdit * edit);
252 gboolean edit_cut_to_X_buf_cmd (WEdit * edit);
253 gboolean edit_paste_from_X_buf_cmd (WEdit * edit);
255 void edit_select_codepage_cmd (WEdit * edit);
256 void edit_insert_literal_cmd (WEdit * edit);
257 gboolean edit_execute_macro (WEdit * edit, int hotkey);
258 void edit_begin_end_macro_cmd (WEdit * edit);
259 void edit_begin_end_repeat_cmd (WEdit * edit);
261 void edit_paste_from_history (WEdit * edit);
263 void edit_set_filename (WEdit * edit, const vfs_path_t * name_vpath);
265 void edit_load_syntax (WEdit * edit, char ***pnames, const char *type);
266 void edit_free_syntax_rules (WEdit * edit);
267 int edit_get_syntax_color (WEdit * edit, off_t byte_index);
269 void book_mark_insert (WEdit * edit, long line, int c);
270 gboolean book_mark_query_color (WEdit * edit, long line, int c);
271 struct edit_book_mark_t *book_mark_find (WEdit * edit, long line);
272 gboolean book_mark_clear (WEdit * edit, long line, int c);
273 void book_mark_flush (WEdit * edit, int c);
274 void book_mark_inc (WEdit * edit, long line);
275 void book_mark_dec (WEdit * edit, long line);
276 void book_mark_serialize (WEdit * edit, int color);
277 void book_mark_restore (WEdit * edit, int color);
279 gboolean edit_line_is_blank (WEdit * edit, long line);
280 gboolean is_break_char (char c);
281 void edit_options_dialog (WDialog * h);
282 void edit_syntax_dialog (WEdit * edit);
283 void edit_mail_dialog (WEdit * edit);
284 void format_paragraph (WEdit * edit, gboolean force);
286 /* either command or char_for_insertion must be passed as -1 */
287 void edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion);
289 /*** inline functions ****************************************************************************/
292 * Load a new file into the editor. If it fails, preserve the old file.
293 * To do it, allocate a new widget, initialize it and, if the new file
294 * was loaded, copy the data to the old widget.
296 * @return TRUE on success, FALSE on failure.
298 static inline gboolean
299 edit_reload (WEdit * edit, const vfs_path_t * filename_vpath)
301 return edit_reload_line (edit, filename_vpath, 0);
304 #endif /* MC__EDIT_IMPL_H */