edit.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  1. /* edit.h - main include file
  2. Copyright (C) 1996, 1997 the Free Software Foundation
  3. Authors: 1996, 1997 Paul Sheer
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307, USA.
  16. */
  17. #ifndef __EDIT_H
  18. #define __EDIT_H
  19. #ifdef MIDNIGHT
  20. #ifdef HAVE_SLANG
  21. #define HAVE_SYNTAXH 1
  22. #endif
  23. # include <stdio.h>
  24. # include <stdarg.h>
  25. # include <sys/types.h>
  26. # ifdef HAVE_UNISTD_H
  27. # include <unistd.h>
  28. # endif
  29. # include <string.h>
  30. # include <ctype.h>
  31. # include <errno.h>
  32. # include "src/tty.h"
  33. # include <sys/stat.h>
  34. # include <errno.h>
  35. # include <fcntl.h>
  36. # include <stdlib.h>
  37. # include <malloc.h>
  38. #else /* ! MIDNIGHT */
  39. # include "global.h"
  40. # include <stdio.h>
  41. # include <stdarg.h>
  42. # include <sys/types.h>
  43. # ifdef HAVE_UNISTD_H
  44. # include <unistd.h>
  45. # endif
  46. #ifdef GTK
  47. # include <string.h>
  48. #else
  49. # include <my_string.h>
  50. #endif
  51. # include <ctype.h>
  52. # include <errno.h>
  53. # include <sys/stat.h>
  54. # ifdef HAVE_FCNTL_H
  55. # include <fcntl.h>
  56. # endif
  57. # include <stdlib.h>
  58. # include <stdarg.h>
  59. # if TIME_WITH_SYS_TIME
  60. # include <sys/time.h>
  61. # include <time.h>
  62. # else
  63. # if HAVE_SYS_TIME_H
  64. # include <sys/time.h>
  65. # else
  66. # include <time.h>
  67. # endif
  68. # endif
  69. # include "regex.h"
  70. #endif
  71. #ifndef MIDNIGHT
  72. # include <signal.h>
  73. # include <X11/Xlib.h>
  74. # include <X11/Xutil.h>
  75. # include <X11/Xresource.h>
  76. # include "lkeysym.h"
  77. #ifndef GTK
  78. # include "coolwidget.h"
  79. # include "app_glob.c"
  80. # include "coollocal.h"
  81. # include "stringtools.h"
  82. #else
  83. # include "gtk/gtk.h"
  84. # include "gdk/gdkprivate.h"
  85. # include "gdk/gdk.h"
  86. # include "gtkedit.h"
  87. # include "editcmddef.h"
  88. # ifndef _
  89. # define _(x) x
  90. # define N_(x) x
  91. # endif
  92. #endif
  93. #else
  94. # include "src/global.h"
  95. # include "src/main.h" /* for char *shell */
  96. # include "src/mad.h"
  97. # include "src/dlg.h"
  98. # include "src/widget.h"
  99. # include "src/color.h"
  100. # include "src/dialog.h"
  101. # include "src/mouse.h"
  102. # include "src/help.h"
  103. # include "src/key.h"
  104. # include "src/wtools.h" /* for QuickWidgets */
  105. # include "src/win.h"
  106. # include "vfs/vfs.h"
  107. # include "src/menu.h"
  108. # include <regex.h>
  109. # define WANT_WIDGETS
  110. # define WIDGET_COMMAND (WIDGET_USER + 10)
  111. # define N_menus 5
  112. #endif
  113. #ifdef GTK
  114. /* unistd.h defines _POSIX_VERSION on POSIX.1 systems. */
  115. #if defined(HAVE_DIRENT_H) || defined(_POSIX_VERSION)
  116. # include <dirent.h>
  117. # define NLENGTH(dirent) (strlen ((dirent)->d_name))
  118. #else
  119. # define dirent direct
  120. # define NLENGTH(dirent) ((dirent)->d_namlen)
  121. # ifdef HAVE_SYS_NDIR_H
  122. # include <sys/ndir.h>
  123. # endif /* HAVE_SYS_NDIR_H */
  124. # ifdef HAVE_SYS_DIR_H
  125. # include <sys/dir.h>
  126. # endif /* HAVE_SYS_DIR_H */
  127. # ifdef HAVE_NDIR_H
  128. # include <ndir.h>
  129. # endif /* HAVE_NDIR_H */
  130. #endif /* not (HAVE_DIRENT_H or _POSIX_VERSION) */
  131. # ifndef _
  132. # define _(x) x
  133. # define N_(x) x
  134. # endif
  135. #include "vfs/vfs.h"
  136. # define CDisplay gdk_display
  137. # define CRoot gdk_root_parent
  138. # define Window GtkEdit *
  139. #endif
  140. #define SEARCH_DIALOG_OPTION_NO_SCANF 1
  141. #define SEARCH_DIALOG_OPTION_NO_REGEX 2
  142. #define SEARCH_DIALOG_OPTION_NO_CASE 4
  143. #define SEARCH_DIALOG_OPTION_BACKWARDS 8
  144. #define SYNTAX_FILE "/.cedit/Syntax"
  145. #define CLIP_FILE "/.cedit/cooledit.clip"
  146. #define MACRO_FILE "/.cedit/cooledit.macros"
  147. #define BLOCK_FILE "/.cedit/cooledit.block"
  148. #define ERROR_FILE "/.cedit/cooledit.error"
  149. #define TEMP_FILE "/.cedit/cooledit.temp"
  150. #define SCRIPT_FILE "/.cedit/cooledit.script"
  151. #define EDIT_DIR "/.cedit"
  152. #define EDIT_KEY_EMULATION_NORMAL 0
  153. #define EDIT_KEY_EMULATION_EMACS 1
  154. #define REDRAW_LINE (1 << 0)
  155. #define REDRAW_LINE_ABOVE (1 << 1)
  156. #define REDRAW_LINE_BELOW (1 << 2)
  157. #define REDRAW_AFTER_CURSOR (1 << 3)
  158. #define REDRAW_BEFORE_CURSOR (1 << 4)
  159. #define REDRAW_PAGE (1 << 5)
  160. #define REDRAW_IN_BOUNDS (1 << 6)
  161. #define REDRAW_CHAR_ONLY (1 << 7)
  162. #define REDRAW_COMPLETELY (1 << 8)
  163. #define MOD_ABNORMAL (1 << 0)
  164. #define MOD_UNDERLINED (1 << 1)
  165. #define MOD_BOLD (1 << 2)
  166. #define MOD_HIGHLIGHTED (1 << 3)
  167. #define MOD_MARKED (1 << 4)
  168. #define MOD_ITALIC (1 << 5)
  169. #define MOD_CURSOR (1 << 6)
  170. #define MOD_INVERSE (1 << 7)
  171. #ifndef MIDNIGHT
  172. # ifdef GTK
  173. # define EDIT_TEXT_HORIZONTAL_OFFSET 0
  174. # define EDIT_TEXT_VERTICAL_OFFSET 0
  175. # else
  176. # define EDIT_TEXT_HORIZONTAL_OFFSET 4
  177. # define EDIT_TEXT_VERTICAL_OFFSET 3
  178. # endif
  179. #else
  180. # define EDIT_TEXT_HORIZONTAL_OFFSET 0
  181. # define EDIT_TEXT_VERTICAL_OFFSET 1
  182. # define FONT_OFFSET_X 0
  183. # define FONT_OFFSET_Y 0
  184. #endif
  185. #define EDIT_RIGHT_EXTREME option_edit_right_extreme
  186. #define EDIT_LEFT_EXTREME option_edit_left_extreme
  187. #define EDIT_TOP_EXTREME option_edit_top_extreme
  188. #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
  189. #define MAX_MACRO_LENGTH 1024
  190. /*there are a maximum of ... */
  191. #define MAXBUFF 1024
  192. /*... edit buffers, each of which is ... */
  193. #define EDIT_BUF_SIZE 0x10000
  194. /* ...bytes in size. */
  195. /*x / EDIT_BUF_SIZE equals x >> ... */
  196. #define S_EDIT_BUF_SIZE 16
  197. /* x % EDIT_BUF_SIZE is equal to x && ... */
  198. #define M_EDIT_BUF_SIZE 0xFFFF
  199. #define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
  200. /* Note a 16k stack is 64k of data and enough to hold (usually) around 10
  201. pages of undo info. */
  202. /* undo stack */
  203. #define START_STACK_SIZE 32
  204. /*some codes that may be pushed onto or returned from the undo stack: */
  205. #define CURS_LEFT 601
  206. #define CURS_RIGHT 602
  207. #define DELETE 603
  208. #define BACKSPACE 604
  209. #define STACK_BOTTOM 605
  210. #define CURS_LEFT_LOTS 606
  211. #define CURS_RIGHT_LOTS 607
  212. #define COLUMN_ON 608
  213. #define COLUMN_OFF 609
  214. #define MARK_1 1000
  215. #define MARK_2 700000000
  216. #define KEY_PRESS 1400000000
  217. /*Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
  218. #define TAB_SIZE option_tab_spacing
  219. #define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
  220. struct macro {
  221. short command;
  222. short ch;
  223. };
  224. struct selection {
  225. unsigned char * text;
  226. int len;
  227. };
  228. struct syntax_rule {
  229. unsigned short keyword;
  230. unsigned char end;
  231. unsigned char context;
  232. unsigned char _context;
  233. #define RULE_ON_LEFT_BORDER 1
  234. #define RULE_ON_RIGHT_BORDER 2
  235. unsigned char border;
  236. };
  237. #define MAX_WORDS_PER_CONTEXT 1024
  238. #define MAX_CONTEXTS 128
  239. struct key_word {
  240. char *keyword;
  241. unsigned char first;
  242. char *whole_word_chars_left;
  243. char *whole_word_chars_right;
  244. time_t time;
  245. #define NO_COLOR 0x7FFFFFFF
  246. #define SPELLING_ERROR 0x7EFEFEFE
  247. int line_start;
  248. int bg;
  249. int fg;
  250. };
  251. struct context_rule {
  252. char *left;
  253. unsigned char first_left;
  254. char *right;
  255. unsigned char first_right;
  256. char line_start_left;
  257. char line_start_right;
  258. int single_char;
  259. int between_delimiters;
  260. char *whole_word_chars_left;
  261. char *whole_word_chars_right;
  262. char *keyword_first_chars;
  263. int spelling;
  264. /* first word is word[1] */
  265. struct key_word **keyword;
  266. };
  267. struct _syntax_marker {
  268. long offset;
  269. struct syntax_rule rule;
  270. struct _syntax_marker *next;
  271. };
  272. struct _book_mark {
  273. int line; /* line number */
  274. #define BOOK_MARK_COLOR ((0 << 8) | 26) /* black on white */
  275. int c; /* colour */
  276. struct _book_mark *next;
  277. struct _book_mark *prev;
  278. };
  279. struct editor_widget {
  280. #ifdef MIDNIGHT
  281. Widget widget;
  282. #elif defined(GTK)
  283. GtkEdit *widget;
  284. #else
  285. struct cool_widget *widget;
  286. #endif
  287. #define from_here num_widget_lines
  288. int num_widget_lines;
  289. int num_widget_columns;
  290. #ifdef MIDNIGHT
  291. int have_frame;
  292. #else
  293. int stopped;
  294. #endif
  295. char *filename; /* Name of the file */
  296. char *dir; /* current directory */
  297. /* dynamic buffers and cursor position for editor: */
  298. long curs1; /*position of the cursor from the beginning of the file. */
  299. long curs2; /*position from the end of the file */
  300. unsigned char *buffers1[MAXBUFF + 1]; /*all data up to curs1 */
  301. unsigned char *buffers2[MAXBUFF + 1]; /*all data from end of file down to curs2 */
  302. /* search variables */
  303. long search_start; /* First character to start searching from */
  304. int found_len; /* Length of found string or 0 if none was found */
  305. long found_start; /* the found word from a search - start position */
  306. /* display information */
  307. long last_byte; /* Last byte of file */
  308. long start_display; /* First char displayed */
  309. long start_col; /* First displayed column, negative */
  310. long max_column; /* The maximum cursor position ever reached used to calc hori scroll bar */
  311. long curs_row; /*row position of cursor on the screen */
  312. long curs_col; /*column position on screen */
  313. int force; /* how much of the screen do we redraw? */
  314. unsigned char overwrite;
  315. unsigned char modified; /*has the file been changed?: 1 if char inserted or
  316. deleted at all since last load or save */
  317. #if defined(MIDNIGHT) || defined(GTK)
  318. int delete_file; /* has the file been created in edit_load_file? Delete
  319. it at end of editing when it hasn't been modified
  320. or saved */
  321. #endif
  322. unsigned char highlight;
  323. long prev_col; /*recent column position of the cursor - used when moving
  324. up or down past lines that are shorter than the current line */
  325. long curs_line; /*line number of the cursor. */
  326. long start_line; /*line nummber of the top of the page */
  327. /* file info */
  328. long total_lines; /*total lines in the file */
  329. long mark1; /*position of highlight start */
  330. long mark2; /*position of highlight end */
  331. int column1; /*position of column highlight start */
  332. int column2; /*position of column highlight end */
  333. long bracket; /*position of a matching bracket */
  334. /* cache speedup for line lookups */
  335. #define N_LINE_CACHES 32
  336. int caches_valid;
  337. int line_numbers[N_LINE_CACHES];
  338. long line_offsets[N_LINE_CACHES];
  339. struct _book_mark *book_mark;
  340. /* undo stack and pointers */
  341. unsigned long stack_pointer;
  342. long *undo_stack;
  343. unsigned long stack_size;
  344. unsigned long stack_size_mask;
  345. unsigned long stack_bottom;
  346. struct stat stat;
  347. /* syntax higlighting */
  348. struct _syntax_marker *syntax_marker;
  349. struct context_rule **rules;
  350. long last_get_rule;
  351. struct syntax_rule rule;
  352. char *syntax_type; /* description of syntax highlighting type being used */
  353. int explicit_syntax; /* have we forced the syntax hi. type in spite of the filename? */
  354. int to_here; /* dummy marker */
  355. /* macro stuff */
  356. int macro_i; /* -1 if not recording index to macro[] otherwise */
  357. struct macro macro[MAX_MACRO_LENGTH];
  358. };
  359. typedef struct editor_widget WEdit;
  360. #ifndef MIDNIGHT
  361. void edit_render_expose (WEdit * edit, XExposeEvent * xexpose);
  362. #ifndef GTK
  363. void edit_render_tidbits (struct cool_widget *w);
  364. int eh_editor (CWidget * w, XEvent * xevent, CEvent * cwevent);
  365. #endif
  366. void edit_draw_menus (Window parent, int x, int y);
  367. void edit_run_make (void);
  368. void edit_change_directory (void);
  369. int edit_man_page_cmd (WEdit * edit);
  370. void edit_search_replace_dialog (Window parent, int x, int y, char **search_text, char **replace_text, char **arg_order, char *heading, int option);
  371. void edit_search_dialog (WEdit * edit, char **search_text);
  372. long edit_find (long search_start, unsigned char *expr, int *len, long last_byte, int (*get_byte) (void *, long), void *data, void *d);
  373. void edit_set_foreground_colors (unsigned long normal, unsigned long bold, unsigned long italic);
  374. void edit_set_background_colors (unsigned long normal, unsigned long abnormal, unsigned long marked, unsigned long marked_abnormal, unsigned long highlighted);
  375. void edit_set_cursor_color (unsigned long c);
  376. void draw_options_dialog (Window parent, int x, int y);
  377. void CRefreshEditor (WEdit * edit);
  378. void edit_set_user_command (void (*func) (WEdit *, int));
  379. void edit_draw_this_line_proportional (WEdit * edit, long b, int curs_row, int start_column, int end_column);
  380. unsigned char get_international_character (unsigned char key_press);
  381. void edit_set_user_key_function (int (*user_def_key_func) (unsigned int, unsigned int, KeySym keysym));
  382. #else
  383. int edit_drop_hotkey_menu (WEdit * e, int key);
  384. void edit_menu_cmd (WEdit * e);
  385. void edit_init_menu_emacs (void);
  386. void edit_init_menu_normal (void);
  387. void edit_done_menu (void);
  388. int edit_raw_key_query (char *heading, char *query, int cancel);
  389. char *strcasechr (const unsigned char *s, int c);
  390. int edit (const char *_file, int line);
  391. int edit_translate_key (WEdit * edit, unsigned int x_keycode, long x_key, int x_state, int *cmd, int *ch);
  392. #endif
  393. #ifndef NO_INLINE_GETBYTE
  394. int edit_get_byte (WEdit * edit, long byte_index);
  395. #else
  396. static inline int edit_get_byte (WEdit * edit, long byte_index)
  397. {
  398. unsigned long p;
  399. if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
  400. return '\n';
  401. if (byte_index >= edit->curs1) {
  402. p = edit->curs1 + edit->curs2 - byte_index - 1;
  403. return edit->buffers2[p >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1];
  404. } else {
  405. return edit->buffers1[byte_index >> S_EDIT_BUF_SIZE][byte_index & M_EDIT_BUF_SIZE];
  406. }
  407. }
  408. #endif
  409. char *edit_get_buffer_as_text (WEdit * edit);
  410. int edit_load_file (WEdit * edit, const char *filename, const char *text, unsigned long text_size);
  411. int edit_count_lines (WEdit * edit, long current, int upto);
  412. long edit_move_forward (WEdit * edit, long current, int lines, long upto);
  413. long edit_move_forward3 (WEdit * edit, long current, int cols, long upto);
  414. long edit_move_backward (WEdit * edit, long current, int lines);
  415. void edit_scroll_screen_over_cursor (WEdit * edit);
  416. void edit_render_keypress (WEdit * edit);
  417. void edit_scroll_upward (WEdit * edit, unsigned long i);
  418. void edit_scroll_downward (WEdit * edit, int i);
  419. void edit_scroll_right (WEdit * edit, int i);
  420. void edit_scroll_left (WEdit * edit, int i);
  421. int edit_get_col (WEdit * edit);
  422. long edit_bol (WEdit * edit, long current);
  423. long edit_eol (WEdit * edit, long current);
  424. void edit_update_curs_row (WEdit * edit);
  425. void edit_update_curs_col (WEdit * edit);
  426. void edit_block_copy_cmd (WEdit * edit);
  427. void edit_block_move_cmd (WEdit * edit);
  428. int edit_block_delete_cmd (WEdit * edit);
  429. int edit_block_delete (WEdit * edit);
  430. void edit_delete_line (WEdit * edit);
  431. int edit_delete (WEdit * edit);
  432. void edit_insert (WEdit * edit, int c);
  433. int edit_cursor_move (WEdit * edit, long increment);
  434. void edit_push_action (WEdit * edit, long c,...);
  435. void edit_push_key_press (WEdit * edit);
  436. void edit_insert_ahead (WEdit * edit, int c);
  437. int edit_save_file (WEdit * edit, const char *filename);
  438. int edit_save_cmd (WEdit * edit);
  439. int edit_save_confirm_cmd (WEdit * edit);
  440. int edit_save_as_cmd (WEdit * edit);
  441. WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, const char *text, const char *dir, unsigned long text_size);
  442. int edit_clean (WEdit * edit);
  443. int edit_renew (WEdit * edit);
  444. int edit_new_cmd (WEdit * edit);
  445. int edit_reload (WEdit * edit, const char *filename, const char *text, const char *dir, unsigned long text_size);
  446. int edit_load_cmd (WEdit * edit);
  447. void edit_mark_cmd (WEdit * edit, int unmark);
  448. void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2);
  449. void edit_push_markers (WEdit * edit);
  450. void edit_quit_cmd (WEdit * edit);
  451. void edit_replace_cmd (WEdit * edit, int again);
  452. void edit_search_cmd (WEdit * edit, int again);
  453. int edit_save_block_cmd (WEdit * edit);
  454. int edit_insert_file_cmd (WEdit * edit);
  455. int edit_insert_file (WEdit * edit, const char *filename);
  456. void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block);
  457. char *catstrs (const char *first,...);
  458. void edit_refresh_cmd (WEdit * edit);
  459. void edit_date_cmd (WEdit * edit);
  460. void edit_goto_cmd (WEdit * edit);
  461. int eval_marks (WEdit * edit, long *start_mark, long *end_mark);
  462. void edit_status (WEdit * edit);
  463. int edit_execute_command (WEdit * edit, int command, int char_for_insertion);
  464. int edit_execute_key_command (WEdit * edit, int command, int char_for_insertion);
  465. void edit_update_screen (WEdit * edit);
  466. int edit_printf (WEdit * e, const char *fmt,...);
  467. int edit_print_string (WEdit * e, const char *s);
  468. void edit_move_to_line (WEdit * e, long line);
  469. void edit_move_display (WEdit * e, long line);
  470. void edit_word_wrap (WEdit * edit);
  471. unsigned char *edit_get_block (WEdit * edit, long start, long finish, int *l);
  472. int edit_sort_cmd (WEdit * edit);
  473. void edit_help_cmd (WEdit * edit);
  474. void edit_left_word_move (WEdit * edit, int s);
  475. void edit_right_word_move (WEdit * edit, int s);
  476. void edit_get_selection (WEdit * edit);
  477. int edit_save_macro_cmd (WEdit * edit, struct macro macro[], int n);
  478. int edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k);
  479. void edit_delete_macro_cmd (WEdit * edit);
  480. int edit_copy_to_X_buf_cmd (WEdit * edit);
  481. int edit_cut_to_X_buf_cmd (WEdit * edit);
  482. void edit_paste_from_X_buf_cmd (WEdit * edit);
  483. void edit_paste_from_history (WEdit *edit);
  484. void edit_split_filename (WEdit * edit, char *name);
  485. #ifdef MIDNIGHT
  486. #define CWidget Widget
  487. #elif defined(GTK)
  488. #define CWidget GtkEdit
  489. #endif
  490. void edit_set_syntax_change_callback (void (*callback) (CWidget *));
  491. void edit_load_syntax (WEdit * edit, char **names, char *type);
  492. void edit_free_syntax_rules (WEdit * edit);
  493. void edit_get_syntax_color (WEdit * edit, long byte_index, int *fg, int *bg);
  494. int edit_check_spelling (WEdit * edit);
  495. void book_mark_insert (WEdit * edit, int line, int c);
  496. int book_mark_query_color (WEdit * edit, int line, int c);
  497. int book_mark_query_all (WEdit * edit, int line, int *c);
  498. struct _book_mark *book_mark_find (WEdit * edit, int line);
  499. int book_mark_clear (WEdit * edit, int line, int c);
  500. void book_mark_flush (WEdit * edit, int c);
  501. void book_mark_inc (WEdit * edit, int line);
  502. void book_mark_dec (WEdit * edit, int line);
  503. #ifdef MIDNIGHT
  504. /* put OS2/NT/WIN95 defines here */
  505. # ifdef USE_O_TEXT
  506. # define MY_O_TEXT O_TEXT
  507. # else
  508. # define MY_O_TEXT 0
  509. # endif
  510. # define FONT_PIX_PER_LINE 1
  511. # define FONT_MEAN_WIDTH 1
  512. # define get_sys_error(s) (s)
  513. # define open mc_open
  514. # define close(f) mc_close(f)
  515. # define read(f,b,c) mc_read(f,b,c)
  516. # define write(f,b,c) mc_write(f,b,c)
  517. # define stat(f,s) mc_stat(f,s)
  518. # define mkdir(s,m) mc_mkdir(s,m)
  519. # define itoa MY_itoa
  520. # define edit_get_load_file(d,f,h) input_dialog (h, " Enter file name: ", f)
  521. # define edit_get_save_file(d,f,h) input_dialog (h, " Enter file name: ", f)
  522. # define CMalloc(x) malloc(x)
  523. # define set_error_msg(s) edit_init_error_msg = strdup(s)
  524. # ifdef _EDIT_C
  525. # define edit_error_dialog(h,s) set_error_msg(s)
  526. char *edit_init_error_msg = NULL;
  527. # else /* ! _EDIT_C */
  528. # define edit_error_dialog(h,s) query_dialog (h, s, 0, 1, _("&Dismiss"))
  529. # define edit_message_dialog(h,s) query_dialog (h, s, 0, 1, _("&Ok"))
  530. extern char *edit_init_error_msg;
  531. # endif /* ! _EDIT_C */
  532. # define get_error_msg(s) edit_init_error_msg
  533. # define edit_query_dialog2(h,t,a,b) query_dialog(h,t,0,2,a,b)
  534. # define edit_query_dialog3(h,t,a,b,c) query_dialog(h,t,0,3,a,b,c)
  535. # define edit_query_dialog4(h,t,a,b,c,d) query_dialog(h,t,0,4,a,b,c,d)
  536. #else /* ! MIDNIGHT */
  537. # ifdef GTK
  538. # define get_sys_error(s) (s)
  539. # define open mc_open
  540. # define close(f) mc_close(f)
  541. # define read(f,b,c) mc_read(f,b,c)
  542. # define write(f,b,c) mc_write(f,b,c)
  543. # define stat(f,s) mc_stat(f,s)
  544. # define mkdir(s,m) mc_mkdir(s,m)
  545. # define itoa MY_itoa
  546. # define CMalloc(x) malloc(x)
  547. # define EDITOR_NO_FILE (1<<3)
  548. # define EDITOR_NO_SCROLL (1<<4)
  549. # define EDITOR_NO_TEXT (1<<5)
  550. # define EDITOR_HORIZ_SCROLL (1<<6)
  551. #include <gdk/gdkprivate.h>
  552. # define CWindowOf(w) (w)
  553. # define CHeightOf(w) ((w)->editable.widget.allocation.height)
  554. # define CWidthOf(w) ((w)->editable.widget.allocation.width)
  555. # define COptionsOf(w) ((w)->options)
  556. # define cache_type unsigned int
  557. /* font dimensions */
  558. # define FONT_OVERHEAD gtk_edit_option_text_line_spacing
  559. # define FONT_BASE_LINE (FONT_OVERHEAD + gtk_edit_option_font_ascent)
  560. # define FONT_HEIGHT (gtk_edit_option_font_ascent + gtk_edit_option_font_descent)
  561. # define FONT_PIX_PER_LINE (FONT_OVERHEAD + FONT_HEIGHT)
  562. # define FONT_MEAN_WIDTH gtk_edit_option_font_mean_width
  563. # define EDIT_FRAME_H 3
  564. # define EDIT_FRAME_W 3
  565. # define FONT_OFFSET_X 0
  566. # define FONT_OFFSET_Y FONT_BASE_LINE
  567. # define per_char gtk_edit_font_width_per_char
  568. # ifndef _GTK_EDIT_C
  569. extern guchar gtk_edit_font_width_per_char[256];
  570. extern int gtk_edit_option_text_line_spacing;
  571. extern int gtk_edit_option_font_ascent;
  572. extern int gtk_edit_option_font_descent;
  573. extern int gtk_edit_option_font_mean_width;
  574. extern int gtk_edit_fixed_font;
  575. # endif
  576. /* start temporary */
  577. # define COLOR_BLACK 0
  578. # define COLOR_WHITE 1
  579. # define CURSOR_TYPE_EDITOR 0
  580. # define WIN_MESSAGES GTK_WINDOW_TOPLEVEL, 20, 20
  581. # define option_text_line_spacing 1
  582. # define fixed_font 0
  583. #define color_palette(x) win->color[x].pixel
  584. #define DndNotDnd -1
  585. #define DndUnknown 0
  586. #define DndRawData 1
  587. #define DndFile 2
  588. #define DndFiles 3
  589. #define DndText 4
  590. #define DndDir 5
  591. #define DndLink 6
  592. #define DndExe 7
  593. #define DndURL 8
  594. #define DndMIME 9
  595. #define DndEND 10
  596. #define dnd_null_term_type(d) \
  597. ((d) == DndFile || (d) == DndText || (d) == DndDir || \
  598. (d) == DndLink || (d) == DndExe || (d) == DndURL)
  599. /* end temporary */
  600. # else
  601. # define WIN_MESSAGES edit->widget ? edit->widget->mainid : CRoot, 20, 20
  602. # endif
  603. # define MY_O_TEXT 0
  604. # ifdef GTK
  605. # ifndef min
  606. # define min(x,y) (((x) < (y)) ? (x) : (y))
  607. # endif
  608. # ifndef max
  609. # define max(x,y) (((x) > (y)) ? (x) : (y))
  610. # endif
  611. /*
  612. extern Display *gdk_display;
  613. extern Window gdk_root_window;
  614. */
  615. enum {
  616. match_file, match_normal
  617. };
  618. # define edit_get_load_file(d,f,h) gtk_edit_dialog_get_load_file(d,f,h)
  619. # define edit_get_save_file(d,f,h) gtk_edit_dialog_get_save_file(d,f,h)
  620. # define edit_error_dialog(h,t) gtk_edit_dialog_error(h,"%s",t)
  621. # define edit_message_dialog(h,t) gtk_edit_dialog_message(0,h,"%s",t)
  622. # define edit_query_dialog2(h,t,a,b) gtk_edit_dialog_query(h,t,a,b,0)
  623. # define edit_query_dialog3(h,t,a,b,c) gtk_edit_dialog_query(h,t,a,b,c,0)
  624. # define edit_query_dialog4(h,t,a,b,c,d) gtk_edit_dialog_query(h,t,a,b,c,d,0)
  625. # define CError(x) printf("Error: %s\n",x)
  626. # define CIsDropAcknowledge(a,b) DndNotDnd
  627. # define CGetDrop(e,d,s,x,y) DndNotDnd
  628. # define CDropAcknowledge(x)
  629. /* # define edit_get_syntax_color(e,i,f,b) */
  630. # define get_international_character(k) 0
  631. # define compose_key_pressed 0
  632. # else
  633. # define edit_get_load_file(d,f,h) CGetLoadFile(WIN_MESSAGES,d,f,h)
  634. # define edit_get_save_file(d,f,h) CGetSaveFile(WIN_MESSAGES,d,f,h)
  635. # define edit_error_dialog(h,t) CErrorDialog(WIN_MESSAGES,h,"%s",t)
  636. # define edit_message_dialog(h,t) CMessageDialog(WIN_MESSAGES,0,h,"%s",t)
  637. # define edit_query_dialog2(h,t,a,b) CQueryDialog(WIN_MESSAGES,h,t,a,b,0)
  638. # define edit_query_dialog3(h,t,a,b,c) CQueryDialog(WIN_MESSAGES,h,t,a,b,c,0)
  639. # define edit_query_dialog4(h,t,a,b,c,d) CQueryDialog(WIN_MESSAGES,h,t,a,b,c,d,0)
  640. # endif
  641. #endif /* ! MIDNIGHT */
  642. extern char *home_dir;
  643. #define NUM_SELECTION_HISTORY 64
  644. #ifndef MAX_PATH_LEN
  645. #ifdef PATH_MAX
  646. #define MAX_PATH_LEN PATH_MAX
  647. #else
  648. #define MAX_PATH_LEN 1024
  649. #endif
  650. #endif
  651. #ifdef _EDIT_C
  652. struct selection selection =
  653. {0, 0};
  654. int current_selection = 0;
  655. /* Note: selection.text = selection_history[current_selection].text */
  656. struct selection selection_history[NUM_SELECTION_HISTORY] =
  657. {
  658. {0, 0},
  659. {0, 0},
  660. {0, 0},
  661. {0, 0},
  662. {0, 0},
  663. {0, 0},
  664. {0, 0},
  665. {0, 0},
  666. {0, 0},
  667. {0, 0},
  668. };
  669. #ifdef MIDNIGHT
  670. /*
  671. what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
  672. or EDIT_KEY_EMULATION_EMACS
  673. */
  674. int edit_key_emulation = EDIT_KEY_EMULATION_NORMAL;
  675. #endif /* ! MIDNIGHT */
  676. int option_word_wrap_line_length = 72;
  677. int option_typewriter_wrap = 0;
  678. int option_auto_para_formatting = 0;
  679. int option_international_characters = 0;
  680. int option_tab_spacing = 8;
  681. int option_fill_tabs_with_spaces = 0;
  682. int option_return_does_auto_indent = 1;
  683. int option_backspace_through_tabs = 0;
  684. int option_fake_half_tabs = 1;
  685. int option_save_mode = 0;
  686. int option_backup_ext_int = -1;
  687. int option_find_bracket = 1;
  688. int option_max_undo = 32768;
  689. int option_editor_fg_normal = 26;
  690. int option_editor_fg_bold = 8;
  691. int option_editor_fg_italic = 10;
  692. int option_edit_right_extreme = 0;
  693. int option_edit_left_extreme = 0;
  694. int option_edit_top_extreme = 0;
  695. int option_edit_bottom_extreme = 0;
  696. int option_editor_bg_normal = 1;
  697. int option_editor_bg_abnormal = 0;
  698. int option_editor_bg_marked = 2;
  699. int option_editor_bg_marked_abnormal = 9;
  700. int option_editor_bg_highlighted = 12;
  701. int option_editor_fg_cursor = 18;
  702. char *option_whole_chars_search = "0123456789abcdefghijklmnopqrstuvwxyz_";
  703. char *option_chars_move_whole_word = "!=&|<>^~ !:;, !'!`!.?!\"!( !) !Aa0 !+-*/= |<> ![ !] !\\#! ";
  704. char *option_backup_ext = "~";
  705. #else /* ! _EDIT_C */
  706. extern struct selection selection;
  707. extern struct selection selection_history[];
  708. extern int current_selection;
  709. #ifdef MIDNIGHT
  710. /*
  711. what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
  712. or EDIT_KEY_EMULATION_EMACS
  713. */
  714. extern int edit_key_emulation;
  715. #endif /* ! MIDNIGHT */
  716. extern int option_word_wrap_line_length;
  717. extern int option_typewriter_wrap;
  718. extern int option_auto_para_formatting;
  719. extern int option_international_characters;
  720. extern int option_tab_spacing;
  721. extern int option_fill_tabs_with_spaces;
  722. extern int option_return_does_auto_indent;
  723. extern int option_backspace_through_tabs;
  724. extern int option_fake_half_tabs;
  725. extern int option_save_mode;
  726. extern int option_backup_ext_int;
  727. extern int option_find_bracket;
  728. extern int option_max_undo;
  729. extern int option_editor_fg_normal;
  730. extern int option_editor_fg_bold;
  731. extern int option_editor_fg_italic;
  732. extern int option_edit_right_extreme;
  733. extern int option_edit_left_extreme;
  734. extern int option_edit_top_extreme;
  735. extern int option_edit_bottom_extreme;
  736. extern int option_editor_bg_normal;
  737. extern int option_editor_bg_abnormal;
  738. extern int option_editor_bg_marked;
  739. extern int option_editor_bg_marked_abnormal;
  740. extern int option_editor_bg_highlighted;
  741. extern int option_editor_fg_cursor;
  742. extern char *option_whole_chars_search;
  743. extern char *option_chars_move_whole_word;
  744. extern char *option_backup_ext;
  745. extern int edit_confirm_save;
  746. #endif /* ! _EDIT_C */
  747. #endif /* __EDIT_H */