home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / mc454src.zip / mc-4.5.4.src / mc-4.5.4 / gtkedit / edit.h < prev    next >
C/C++ Source or Header  |  1999-01-04  |  26KB  |  873 lines

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