*** empty log message ***

This commit is contained in:
Paul Sheer 1998-09-14 21:26:41 +00:00
parent c57d9e424e
commit f36e99f150
10 changed files with 11929 additions and 0 deletions

2262
edit/edit.c Normal file

File diff suppressed because it is too large Load Diff

835
edit/edit.h Normal file
View File

@ -0,0 +1,835 @@
#ifndef __EDIT_H
#define __EDIT_H
#ifdef MIDNIGHT
#ifdef HAVE_SLANG
#define HAVE_SYNTAXH 1
#endif
# include <stdio.h>
# include <stdarg.h>
# include <sys/types.h>
# ifdef HAVE_UNISTD_H
# include <unistd.h>
# endif
# include <string.h>
# include "src/tty.h"
# include <sys/stat.h>
# include <errno.h>
# ifdef HAVE_FCNTL_H
# include <fcntl.h>
# endif
# include <stdlib.h>
# include <malloc.h>
#else /* ! MIDNIGHT */
# include "global.h"
# include <stdio.h>
# include <stdarg.h>
# include <sys/types.h>
# ifdef HAVE_UNISTD_H
# include <unistd.h>
# endif
#ifdef GTK
# include <string.h>
#else
# include <my_string.h>
#endif
# include <sys/stat.h>
# ifdef HAVE_FCNTL_H
# include <fcntl.h>
# endif
# include <stdlib.h>
# include <stdarg.h>
# if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
# else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
# endif
# include "regex.h"
#endif
#ifndef MIDNIGHT
# include <signal.h>
# include <X11/Xlib.h>
# include <X11/Xutil.h>
# include <X11/Xresource.h>
# include "lkeysym.h"
#ifndef GTK
# include "coolwidget.h"
# include "app_glob.c"
# include "coollocal.h"
# include "stringtools.h"
#else
# include "gtk/gtk.h"
# include "gdk/gdkprivate.h"
# include "gdk/gdk.h"
# include "gtkedit.h"
# include "editcmddef.h"
# ifdef _
# define _(x) x
# define N_(x) x
# endif
#endif
#else
# include "src/main.h" /* for char *shell */
# include "src/mad.h"
# include "src/dlg.h"
# include "src/widget.h"
# include "src/color.h"
# include "src/dialog.h"
# include "src/mouse.h"
# include "src/global.h"
# include "src/help.h"
# include "src/key.h"
# include "src/wtools.h" /* for QuickWidgets */
# include "src/win.h"
# include "vfs/vfs.h"
# include "src/menu.h"
# include "src/regex.h"
# define WANT_WIDGETS
# define WIDGET_COMMAND (WIDGET_USER + 10)
# define N_menus 5
#endif
#ifdef GTK
/* unistd.h defines _POSIX_VERSION on POSIX.1 systems. */
#if defined(HAVE_DIRENT_H) || defined(_POSIX_VERSION)
# include <dirent.h>
# define NLENGTH(dirent) (strlen ((dirent)->d_name))
#else
# define dirent direct
# define NLENGTH(dirent) ((dirent)->d_namlen)
# ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h>
# endif /* HAVE_SYS_NDIR_H */
# ifdef HAVE_SYS_DIR_H
# include <sys/dir.h>
# endif /* HAVE_SYS_DIR_H */
# ifdef HAVE_NDIR_H
# include <ndir.h>
# endif /* HAVE_NDIR_H */
#endif /* not (HAVE_DIRENT_H or _POSIX_VERSION) */
#define _(x) x
#define N_(x) x
#include "vfs/vfs.h"
#include "intl/libgettext.h"
# define CDisplay gdk_display
# define CRoot gdk_root_parent
# define Window GtkEdit *
#endif
#define SEARCH_DIALOG_OPTION_NO_SCANF 1
#define SEARCH_DIALOG_OPTION_NO_REGEX 2
#define SEARCH_DIALOG_OPTION_NO_CASE 4
#define SEARCH_DIALOG_OPTION_BACKWARDS 8
#define SYNTAX_FILE "/.cedit/syntax"
#define CLIP_FILE "/.cedit/cooledit.clip"
#define MACRO_FILE "/.cedit/cooledit.macros"
#define BLOCK_FILE "/.cedit/cooledit.block"
#define ERROR_FILE "/.cedit/cooledit.error"
#define TEMP_FILE "/.cedit/cooledit.temp"
#define SCRIPT_FILE "/.cedit/cooledit.script"
#define EDIT_DIR "/.cedit"
#define EDIT_KEY_EMULATION_NORMAL 0
#define EDIT_KEY_EMULATION_EMACS 1
#define REDRAW_LINE (1 << 0)
#define REDRAW_LINE_ABOVE (1 << 1)
#define REDRAW_LINE_BELOW (1 << 2)
#define REDRAW_AFTER_CURSOR (1 << 3)
#define REDRAW_BEFORE_CURSOR (1 << 4)
#define REDRAW_PAGE (1 << 5)
#define REDRAW_IN_BOUNDS (1 << 6)
#define REDRAW_CHAR_ONLY (1 << 7)
#define REDRAW_COMPLETELY (1 << 8)
#define MOD_ABNORMAL (1 << 0)
#define MOD_UNDERLINED (1 << 1)
#define MOD_BOLD (1 << 2)
#define MOD_HIGHLIGHTED (1 << 3)
#define MOD_MARKED (1 << 4)
#define MOD_ITALIC (1 << 5)
#define MOD_CURSOR (1 << 6)
#define MOD_INVERSE (1 << 7)
#ifndef MIDNIGHT
# ifdef GTK
# define EDIT_TEXT_HORIZONTAL_OFFSET 0
# define EDIT_TEXT_VERTICAL_OFFSET 0
# else
# define EDIT_TEXT_HORIZONTAL_OFFSET 4
# define EDIT_TEXT_VERTICAL_OFFSET 3
# endif
#else
# define EDIT_TEXT_HORIZONTAL_OFFSET 0
# define EDIT_TEXT_VERTICAL_OFFSET 1
# define FONT_OFFSET_X 0
# define FONT_OFFSET_Y 0
#endif
#define EDIT_RIGHT_EXTREME option_edit_right_extreme
#define EDIT_LEFT_EXTREME option_edit_left_extreme
#define EDIT_TOP_EXTREME option_edit_top_extreme
#define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
#define MAX_MACRO_LENGTH 1024
/*there are a maximum of ... */
#define MAXBUFF 1024
/*... edit buffers, each of which is ... */
#define EDIT_BUF_SIZE 0x10000
/* ...bytes in size. */
/*x / EDIT_BUF_SIZE equals x >> ... */
#define S_EDIT_BUF_SIZE 16
/* x % EDIT_BUF_SIZE is equal to x && ... */
#define M_EDIT_BUF_SIZE 0xFFFF
#define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
/* Note a 16k stack is 64k of data and enough to hold (usually) around 10
pages of undo info. */
/* undo stack */
#define START_STACK_SIZE 32
/*some codes that may be pushed onto or returned from the undo stack: */
#define CURS_LEFT 601
#define CURS_RIGHT 602
#define DELETE 603
#define BACKSPACE 604
#define STACK_BOTTOM 605
#define CURS_LEFT_LOTS 606
#define CURS_RIGHT_LOTS 607
#define COLUMN_ON 608
#define COLUMN_OFF 609
#define MARK_1 1000
#define MARK_2 700000000
#define KEY_PRESS 1400000000
/*Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
#define TAB_SIZE option_tab_spacing
#define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
struct macro {
short command;
short ch;
};
struct selection {
unsigned char * text;
int len;
};
#define RULE_CONTEXT 0x00FFF000UL
#define RULE_CONTEXT_SHIFT 12
#define RULE_WORD 0x00000FFFUL
#define RULE_WORD_SHIFT 0
#define RULE_ON_LEFT_BORDER 0x02000000UL
#define RULE_ON_RIGHT_BORDER 0x01000000UL
struct key_word {
char *keyword;
char first;
char last;
char *whole_word_chars_left;
char *whole_word_chars_right;
#define NO_COLOR ((unsigned long) -1);
int line_start;
int bg;
int fg;
};
struct context_rule {
int rule_number;
char *left;
char first_left;
char last_left;
char line_start_left;
char *right;
char first_right;
char last_right;
char line_start_right;
int single_char;
int between_delimiters;
char *whole_word_chars_left;
char *whole_word_chars_right;
unsigned char *conflicts;
char *keyword_first_chars;
char *keyword_last_chars;
/* first word is word[1] */
struct key_word **keyword;
};
struct editor_widget {
#ifdef MIDNIGHT
Widget widget;
#elif defined(GTK)
GtkEdit *widget;
#else
struct cool_widget *widget;
#endif
#define from_here num_widget_lines
int num_widget_lines;
int num_widget_columns;
#ifdef MIDNIGHT
int have_frame;
#else
int stopped;
#endif
char *filename; /* Name of the file */
char *dir; /* current directory */
/* dynamic buffers and curser position for editor: */
long curs1; /*position of the cursor from the beginning of the file. */
long curs2; /*position from the end of the file */
unsigned char *buffers1[MAXBUFF + 1]; /*all data up to curs1 */
unsigned char *buffers2[MAXBUFF + 1]; /*all data from end of file down to curs2 */
/* search variables */
long search_start; /* First character to start searching from */
int found_len; /* Length of found string or 0 if none was found */
long found_start; /* the found word from a search - start position */
/* display information */
long last_byte; /* Last byte of file */
long start_display; /* First char displayed */
long start_col; /* First displayed column, negative */
long max_column; /* The maximum cursor position ever reached used to calc hori scroll bar */
long curs_row; /*row position of curser on the screen */
long curs_col; /*column position on screen */
int force; /* how much of the screen do we redraw? */
unsigned char overwrite;
unsigned char modified; /*has the file been changed?: 1 if char inserted or
deleted at all since last load or save */
#if defined(MIDNIGHT) || defined(GTK)
int delete_file; /* has the file been created in edit_load_file? Delete
it at end of editing when it hasn't been modified
or saved */
#endif
unsigned char highlight;
long prev_col; /*recent column position of the curser - used when moving
up or down past lines that are shorter than the current line */
long curs_line; /*line number of the cursor. */
long start_line; /*line nummber of the top of the page */
/* file info */
long total_lines; /*total lines in the file */
long mark1; /*position of highlight start */
long mark2; /*position of highlight end */
int column1; /*position of column highlight start */
int column2; /*position of column highlight end */
long bracket; /*position of a matching bracket */
/* undo stack and pointers */
unsigned long stack_pointer;
long *undo_stack;
unsigned long stack_size;
unsigned long stack_size_mask;
unsigned long stack_bottom;
struct stat stat;
/* syntax higlighting */
struct context_rule **rules;
long last_get_rule;
unsigned long rule;
char *syntax_type; /* description of syntax highlighting type being used */
int explicit_syntax; /* have we forced the syntax hi. type in spite of the filename? */
int to_here; /* dummy marker */
/* macro stuff */
int macro_i; /* -1 if not recording index to macro[] otherwise */
struct macro macro[MAX_MACRO_LENGTH];
};
typedef struct editor_widget WEdit;
#ifndef MIDNIGHT
void edit_render_expose (WEdit * edit, XExposeEvent * xexpose);
#ifndef GTK
void edit_render_tidbits (struct cool_widget *w);
int eh_editor (CWidget * w, XEvent * xevent, CEvent * cwevent);
#endif
void edit_draw_menus (Window parent, int x, int y);
void edit_run_make (void);
void edit_change_directory (void);
int edit_man_page_cmd (WEdit * edit);
void edit_search_replace_dialog (Window parent, int x, int y, char **search_text, char **replace_text, char **arg_order, char *heading, int option);
void edit_search_dialog (WEdit * edit, char **search_text);
long edit_find (long search_start, unsigned char *expr, int *len, long last_byte, int (*get_byte) (void *, long), void *data);
void edit_set_foreground_colors (unsigned long normal, unsigned long bold, unsigned long italic);
void edit_set_background_colors (unsigned long normal, unsigned long abnormal, unsigned long marked, unsigned long marked_abnormal, unsigned long highlighted);
void edit_set_cursor_color (unsigned long c);
void draw_options_dialog (Window parent, int x, int y);
void CRefreshEditor (WEdit * edit);
void edit_set_user_command (void (*func) (WEdit *, int));
void edit_draw_this_line_proportional (WEdit * edit, long b, int curs_row, int start_column, int end_column);
unsigned char get_international_character (unsigned char key_press);
void edit_set_user_key_function (int (*user_def_key_func) (unsigned int, unsigned int, KeySym keysym));
#else
int edit_drop_hotkey_menu (WEdit * e, int key);
void edit_menu_cmd (WEdit * e);
void edit_init_menu_emacs (void);
void edit_init_menu_normal (void);
void edit_done_menu (void);
int edit_raw_key_query (char *heading, char *query, int cancel);
char *strcasechr (const unsigned char *s, int c);
int edit (const char *_file, int line);
int edit_translate_key (WEdit * edit, unsigned int x_keycode, long x_key, int x_state, int *cmd, int *ch);
#endif
#ifndef NO_INLINE_GETBYTE
int edit_get_byte (WEdit * edit, long byte_index);
#else
static inline int edit_get_byte (WEdit * edit, long byte_index)
{
unsigned long p;
if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
return '\n';
if (byte_index >= edit->curs1) {
p = edit->curs1 + edit->curs2 - byte_index - 1;
return edit->buffers2[p >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1];
} else {
return edit->buffers1[byte_index >> S_EDIT_BUF_SIZE][byte_index & M_EDIT_BUF_SIZE];
}
}
#endif
char *edit_get_buffer_as_text (WEdit * edit);
int edit_load_file (WEdit * edit, const char *filename, const char *text, unsigned long text_size);
int edit_count_lines (WEdit * edit, long current, int upto);
long edit_move_forward (WEdit * edit, long current, int lines, long upto);
long edit_move_forward3 (WEdit * edit, long current, int cols, long upto);
long edit_move_backward (WEdit * edit, long current, int lines);
void edit_scroll_screen_over_cursor (WEdit * edit);
void edit_render_keypress (WEdit * edit);
void edit_scroll_upward (WEdit * edit, unsigned long i);
void edit_scroll_downward (WEdit * edit, int i);
void edit_scroll_right (WEdit * edit, int i);
void edit_scroll_left (WEdit * edit, int i);
int edit_get_col (WEdit * edit);
long edit_bol (WEdit * edit, long current);
long edit_eol (WEdit * edit, long current);
void edit_update_curs_row (WEdit * edit);
void edit_update_curs_col (WEdit * edit);
void edit_block_copy_cmd (WEdit * edit);
void edit_block_move_cmd (WEdit * edit);
int edit_block_delete_cmd (WEdit * edit);
int edit_block_delete (WEdit * edit);
void edit_delete_line (WEdit * edit);
int edit_delete (WEdit * edit);
void edit_insert (WEdit * edit, int c);
int edit_cursor_move (WEdit * edit, long increment);
void edit_push_action (WEdit * edit, long c,...);
void edit_push_key_press (WEdit * edit);
void edit_insert_ahead (WEdit * edit, int c);
int edit_save_file (WEdit * edit, const char *filename);
int edit_save_cmd (WEdit * edit);
int edit_save_confirm_cmd (WEdit * edit);
int edit_save_as_cmd (WEdit * edit);
WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, const char *text, const char *dir, unsigned long text_size);
int edit_clean (WEdit * edit);
int edit_renew (WEdit * edit);
int edit_new_cmd (WEdit * edit);
int edit_reload (WEdit * edit, const char *filename, const char *text, const char *dir, unsigned long text_size);
int edit_load_cmd (WEdit * edit);
void edit_mark_cmd (WEdit * edit, int unmark);
void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2);
void edit_push_markers (WEdit * edit);
void edit_quit_cmd (WEdit * edit);
void edit_replace_cmd (WEdit * edit, int again);
void edit_search_cmd (WEdit * edit, int again);
int edit_save_block_cmd (WEdit * edit);
int edit_insert_file_cmd (WEdit * edit);
int edit_insert_file (WEdit * edit, const char *filename);
void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block);
char *catstrs (const char *first,...);
void edit_refresh_cmd (WEdit * edit);
void edit_date_cmd (WEdit * edit);
void edit_goto_cmd (WEdit * edit);
int eval_marks (WEdit * edit, long *start_mark, long *end_mark);
void edit_status (WEdit * edit);
int edit_execute_command (WEdit * edit, int command, int char_for_insertion);
int edit_execute_key_command (WEdit * edit, int command, int char_for_insertion);
void edit_update_screen (WEdit * edit);
int edit_printf (WEdit * e, const char *fmt,...);
int edit_print_string (WEdit * e, const char *s);
void edit_move_to_line (WEdit * e, long line);
void edit_move_display (WEdit * e, long line);
void edit_word_wrap (WEdit * edit);
unsigned char *edit_get_block (WEdit * edit, long start, long finish, int *l);
int edit_sort_cmd (WEdit * edit);
void edit_help_cmd (WEdit * edit);
void edit_left_word_move (WEdit * edit);
void edit_right_word_move (WEdit * edit);
void edit_get_selection (WEdit * edit);
int edit_save_macro_cmd (WEdit * edit, struct macro macro[], int n);
int edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k);
void edit_delete_macro_cmd (WEdit * edit);
int edit_copy_to_X_buf_cmd (WEdit * edit);
int edit_cut_to_X_buf_cmd (WEdit * edit);
void edit_paste_from_X_buf_cmd (WEdit * edit);
void edit_paste_from_history (WEdit *edit);
void edit_split_filename (WEdit * edit, char *name);
#ifdef MIDNIGHT
#define CWidget Widget
#elif defined(GTK)
#define CWidget GtkEdit
#endif
void edit_set_syntax_change_callback (void (*callback) (CWidget *));
void edit_load_syntax (WEdit * edit, char **names, char *type);
void edit_free_syntax_rules (WEdit * edit);
void edit_get_syntax_color (WEdit * edit, long byte_index, int *fg, int *bg);
#ifdef MIDNIGHT
/* put OS2/NT/WIN95 defines here */
# ifdef OS2_NT
# define MY_O_TEXT O_TEXT
# else
# define MY_O_TEXT 0
# endif
# define FONT_PIX_PER_LINE 1
# define FONT_MEAN_WIDTH 1
# define get_sys_error(s) (s)
# define open mc_open
# define close(f) mc_close(f)
# define read(f,b,c) mc_read(f,b,c)
# define write(f,b,c) mc_write(f,b,c)
# define stat(f,s) mc_stat(f,s)
# define mkdir(s,m) mc_mkdir(s,m)
# define itoa MY_itoa
# define edit_get_load_file(d,f,h) input_dialog (h, " Enter file name: ", f)
# define edit_get_save_file(d,f,h) input_dialog (h, " Enter file name: ", f)
# define CMalloc(x) malloc(x)
# define set_error_msg(s) edit_init_error_msg = strdup(s)
# ifdef _EDIT_C
# define edit_error_dialog(h,s) set_error_msg(s)
char *edit_init_error_msg = NULL;
# else /* ! _EDIT_C */
# define edit_error_dialog(h,s) query_dialog (h, s, 0, 1, _("&Dismiss"))
# define edit_message_dialog(h,s) query_dialog (h, s, 0, 1, _("&Ok"))
extern char *edit_init_error_msg;
# endif /* ! _EDIT_C */
# define get_error_msg(s) edit_init_error_msg
# define edit_query_dialog2(h,t,a,b) query_dialog(h,t,0,2,a,b)
# define edit_query_dialog3(h,t,a,b,c) query_dialog(h,t,0,3,a,b,c)
# define edit_query_dialog4(h,t,a,b,c,d) query_dialog(h,t,0,4,a,b,c,d)
#else /* ! MIDNIGHT */
# ifdef GTK
# define get_sys_error(s) (s)
# define open mc_open
# define close(f) mc_close(f)
# define read(f,b,c) mc_read(f,b,c)
# define write(f,b,c) mc_write(f,b,c)
# define stat(f,s) mc_stat(f,s)
# define mkdir(s,m) mc_mkdir(s,m)
# define itoa MY_itoa
# define CMalloc(x) malloc(x)
# define EDITOR_NO_FILE (1<<3)
# define EDITOR_NO_SCROLL (1<<4)
# define EDITOR_NO_TEXT (1<<5)
# define EDITOR_HORIZ_SCROLL (1<<6)
#include <gdk/gdkprivate.h>
# define CWindowOf(w) (w)
# define CHeightOf(w) ((w)->editable.widget.allocation.height)
# define CWidthOf(w) ((w)->editable.widget.allocation.width)
# define COptionsOf(w) ((w)->options)
# define cache_type unsigned int
/* font dimensions */
# define FONT_OVERHEAD gtk_edit_option_text_line_spacing
# define FONT_BASE_LINE (FONT_OVERHEAD + gtk_edit_option_font_ascent)
# define FONT_HEIGHT (gtk_edit_option_font_ascent + gtk_edit_option_font_descent)
# define FONT_PIX_PER_LINE (FONT_OVERHEAD + FONT_HEIGHT)
# define FONT_MEAN_WIDTH gtk_edit_option_font_mean_width
# define FONT_OFFSET_X 0
# define FONT_OFFSET_Y FONT_BASE_LINE
# define per_char gtk_edit_font_width_per_char
# ifndef _GTK_EDIT_C
extern guchar gtk_edit_font_width_per_char[256];
extern int gtk_edit_option_text_line_spacing;
extern int gtk_edit_option_font_ascent;
extern int gtk_edit_option_font_descent;
extern int gtk_edit_option_font_mean_width;
extern int gtk_edit_fixed_font;
# endif
/* start temporary */
# define COLOR_BLACK 0
# define COLOR_WHITE 1
# define CURSOR_TYPE_EDITOR 0
# define WIN_MESSAGES GTK_WINDOW_TOPLEVEL, 20, 20
# define option_text_line_spacing 1
# define fixed_font 0
#define color_palette(x) win->color[x].pixel
#define DndNotDnd -1
#define DndUnknown 0
#define DndRawData 1
#define DndFile 2
#define DndFiles 3
#define DndText 4
#define DndDir 5
#define DndLink 6
#define DndExe 7
#define DndURL 8
#define DndMIME 9
#define DndEND 10
#define dnd_null_term_type(d) \
((d) == DndFile || (d) == DndText || (d) == DndDir || \
(d) == DndLink || (d) == DndExe || (d) == DndURL)
/* end temporary */
# else
# define WIN_MESSAGES edit->widget->mainid, 20, 20
# endif
# define MY_O_TEXT 0
# ifdef GTK
# ifndef min
# define min(x,y) (((x) < (y)) ? (x) : (y))
# endif
# ifndef max
# define max(x,y) (((x) > (y)) ? (x) : (y))
# endif
/*
extern Display *gdk_display;
extern Window gdk_root_window;
*/
enum {
match_file, match_normal
};
# define edit_get_load_file(d,f,h) gtk_edit_dialog_get_load_file(d,f,h)
# define edit_get_save_file(d,f,h) gtk_edit_dialog_get_save_file(d,f,h)
# define edit_error_dialog(h,t) gtk_edit_dialog_error(h,"%s",t)
# define edit_message_dialog(h,t) gtk_edit_dialog_message(0,h,"%s",t)
# define edit_query_dialog2(h,t,a,b) gtk_edit_dialog_query(h,t,a,b,0)
# define edit_query_dialog3(h,t,a,b,c) gtk_edit_dialog_query(h,t,a,b,c,0)
# define edit_query_dialog4(h,t,a,b,c,d) gtk_edit_dialog_query(h,t,a,b,c,d,0)
# define CError(x) printf("Error: %s\n",x)
# define CIsDropAcknowledge(a,b) DndNotDnd
# define CGetDrop(e,d,s,x,y) DndNotDnd
# define CDropAcknowledge(x)
/* # define edit_get_syntax_color(e,i,f,b) */
# define get_international_character(k) 0
# define compose_key_pressed 0
# else
# define edit_get_load_file(d,f,h) CGetLoadFile(WIN_MESSAGES,d,f,h)
# define edit_get_save_file(d,f,h) CGetSaveFile(WIN_MESSAGES,d,f,h)
# define edit_error_dialog(h,t) CErrorDialog(WIN_MESSAGES,h,"%s",t)
# define edit_message_dialog(h,t) CMessageDialog(WIN_MESSAGES,0,h,"%s",t)
# define edit_query_dialog2(h,t,a,b) CQueryDialog(WIN_MESSAGES,h,t,a,b,0)
# define edit_query_dialog3(h,t,a,b,c) CQueryDialog(WIN_MESSAGES,h,t,a,b,c,0)
# define edit_query_dialog4(h,t,a,b,c,d) CQueryDialog(WIN_MESSAGES,h,t,a,b,c,d,0)
# endif
#endif /* ! MIDNIGHT */
extern char *home_dir;
#define NUM_SELECTION_HISTORY 32
#ifdef _EDIT_C
struct selection selection =
{0, 0};
int current_selection = 0;
/* Note: selection.text = selection_history[current_selection].text */
struct selection selection_history[NUM_SELECTION_HISTORY] =
{
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
};
#ifdef MIDNIGHT
/*
what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
or EDIT_KEY_EMULATION_EMACS
*/
int edit_key_emulation = EDIT_KEY_EMULATION_NORMAL;
#endif /* ! MIDNIGHT */
int option_word_wrap_line_length = 72;
int option_typewriter_wrap = 0;
int option_auto_para_formatting = 0;
int option_international_characters = 0;
int option_tab_spacing = 8;
int option_fill_tabs_with_spaces = 0;
int option_return_does_auto_indent = 1;
int option_backspace_through_tabs = 0;
int option_fake_half_tabs = 1;
int option_save_mode = 0;
int option_backup_ext_int = -1;
int option_find_bracket = 1;
int option_max_undo = 32768;
int option_editor_fg_normal = 26;
int option_editor_fg_bold = 8;
int option_editor_fg_italic = 10;
int option_edit_right_extreme = 0;
int option_edit_left_extreme = 0;
int option_edit_top_extreme = 0;
int option_edit_bottom_extreme = 0;
int option_editor_bg_normal = 1;
int option_editor_bg_abnormal = 0;
int option_editor_bg_marked = 2;
int option_editor_bg_marked_abnormal = 9;
int option_editor_bg_highlighted = 12;
int option_editor_fg_cursor = 18;
char *option_whole_chars_search = "0123456789abcdefghijklmnopqrstuvwxyz_";
char *option_whole_chars_move = "0123456789abcdefghijklmnopqrstuvwxyz_; ,[](){}";
char *option_backup_ext = "~";
#else /* ! _EDIT_C */
extern struct selection selection;
extern struct selection selection_history[];
extern int current_selection;
#ifdef MIDNIGHT
/*
what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
or EDIT_KEY_EMULATION_EMACS
*/
extern int edit_key_emulation;
#endif /* ! MIDNIGHT */
extern int option_word_wrap_line_length;
extern int option_typewriter_wrap;
extern int option_auto_para_formatting;
extern int option_international_characters;
extern int option_tab_spacing;
extern int option_fill_tabs_with_spaces;
extern int option_return_does_auto_indent;
extern int option_backspace_through_tabs;
extern int option_fake_half_tabs;
extern int option_save_mode;
extern int option_backup_ext_int;
extern int option_find_bracket;
extern int option_max_undo;
extern int option_editor_fg_normal;
extern int option_editor_fg_bold;
extern int option_editor_fg_italic;
extern int option_edit_right_extreme;
extern int option_edit_left_extreme;
extern int option_edit_top_extreme;
extern int option_edit_bottom_extreme;
extern int option_editor_bg_normal;
extern int option_editor_bg_abnormal;
extern int option_editor_bg_marked;
extern int option_editor_bg_marked_abnormal;
extern int option_editor_bg_highlighted;
extern int option_editor_fg_cursor;
extern char *option_whole_chars_search;
extern char *option_whole_chars_move;
extern char *option_backup_ext;
extern int edit_confirm_save;
#endif /* ! _EDIT_C */
#endif /* __EDIT_H */

2870
edit/editcmd.c Normal file

File diff suppressed because it is too large Load Diff

140
edit/editcmddef.h Normal file
View File

@ -0,0 +1,140 @@
#ifndef __EDIT_CMD_DEF_H
#define __EDIT_CMD_DEF_H
/* in the distant future, keyboards will be invented with a
seperate key for each one of these commands *sigh* */
/* cursor movements */
#define CK_No_Command -1
#define CK_BackSpace 1
#define CK_Delete 2
#define CK_Enter 3
#define CK_Page_Up 4
#define CK_Page_Down 5
#define CK_Left 6
#define CK_Right 7
#define CK_Word_Left 8
#define CK_Word_Right 9
#define CK_Up 10
#define CK_Down 11
#define CK_Home 12
#define CK_End 13
#define CK_Tab 14
#define CK_Undo 15
#define CK_Beginning_Of_Text 16
#define CK_End_Of_Text 17
#define CK_Scroll_Up 18
#define CK_Scroll_Down 19
#define CK_Return 20
#define CK_Begin_Page 21
#define CK_End_Page 22
#define CK_Delete_Word_Left 23
#define CK_Delete_Word_Right 24
#define CK_Paragraph_Up 25
#define CK_Paragraph_Down 26
/* file commands */
#define CK_Save 101
#define CK_Load 102
#define CK_New 103
#define CK_Save_As 104
/* block commands */
#define CK_Mark 201
#define CK_Copy 202
#define CK_Move 203
#define CK_Remove 204
#define CK_Unmark 206
#define CK_Save_Block 207
#define CK_Column_Mark 208
/* search and replace */
#define CK_Find 301
#define CK_Find_Again 302
#define CK_Replace 303
#define CK_Replace_Again 304
/* misc */
#define CK_Insert_File 401
#define CK_Exit 402
#define CK_Toggle_Insert 403
#define CK_Help 404
#define CK_Date 405
#define CK_Refresh 406
#define CK_Goto 407
#define CK_Delete_Line 408
#define CK_Delete_To_Line_End 409
#define CK_Delete_To_Line_Begin 410
#define CK_Man_Page 411
#define CK_Sort 412
#define CK_Mail 413
#define CK_Cancel 414
#define CK_Complete 415
#define CK_Paragraph_Format 416
/* application control */
#define CK_Save_Desktop 451
#define CK_New_Window 452
#define CK_Cycle 453
#define CK_Menu 454
#define CK_Save_And_Quit 455
#define CK_Run_Another 456
#define CK_Check_Save_And_Quit 457
#define CK_Maximise 458
/* macro */
#define CK_Begin_Record_Macro 501
#define CK_End_Record_Macro 502
#define CK_Delete_Macro 503
/* highlight commands */
#define CK_Page_Up_Highlight 604
#define CK_Page_Down_Highlight 605
#define CK_Left_Highlight 606
#define CK_Right_Highlight 607
#define CK_Word_Left_Highlight 608
#define CK_Word_Right_Highlight 609
#define CK_Up_Highlight 610
#define CK_Down_Highlight 611
#define CK_Home_Highlight 612
#define CK_End_Highlight 613
#define CK_Beginning_Of_Text_Highlight 614
#define CK_End_Of_Text_Highlight 615
#define CK_Begin_Page_Highlight 616
#define CK_End_Page_Highlight 617
#define CK_Scroll_Up_Highlight 618
#define CK_Scroll_Down_Highlight 619
#define CK_Paragraph_Up_Highlight 620
#define CK_Paragraph_Down_Highlight 621
/* X clipboard operations */
#define CK_XStore 701
#define CK_XCut 702
#define CK_XPaste 703
#define CK_Selection_History 704
#ifdef MIDNIGHT /* cooledit now has its own full-featured script editor and executor */
/*
Process a block through a shell command: CK_Pipe_Block(i) executes shell_cmd[i].
shell_cmd[i] must process the file ~/cooledit.block and output ~/cooledit.block
which is then inserted into the text in place of the original block. shell_cmd[i] must
also produce a file homedir/cooledit.error . If this file is not empty an error will
have been assumed to have occured, and the block will not be replaced.
TODO: bring up a viewer to display the error message instead of inserting
it into the text, which is annoying.
*/
#define CK_Pipe_Block(i) (1000+(i))
#define SHELL_COMMANDS_i {"/.cedit/edit.indent.rc", "/.cedit/edit.spell.rc", /* and so on */ 0};
#else
#define CK_User_Command(i) (1000+(i))
#endif
/* execute a macro */
#define CK_Macro(i) (2000+(i))
#define CK_Last_Macro CK_Macro(0x7FFF)
#endif

736
edit/editdraw.c Normal file
View File

@ -0,0 +1,736 @@
/* editor text drawing.
Copyright (C) 1996, 1997 the Free Software Foundation
Authors: 1996, 1997 Paul Sheer
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <config.h>
#include "edit.h"
#define MAX_LINE_LEN 1024
#ifndef MIDNIGHT
#ifndef GTK
#include "app_glob.c"
#include "coollocal.h"
#endif
#else
#include "../src/mad.h"
#endif
extern int column_highlighting;
void status_string (WEdit * edit, char *s, int w, int fill, int font_width)
{
int i;
char t[160]; /* 160 just to be sure */
/* The field lengths just prevents the status line from shortening to much */
sprintf (t, "[%c%c%c%c] %2ld:%3ld+%2ld=%3ld/%3ld - *%-4ld/%4ldb=%3d",
edit->mark1 != edit->mark2 ? ( column_highlighting ? 'C' : 'B') : '-',
edit->modified ? 'M' : '-', edit->macro_i < 0 ? '-' : 'R',
edit->overwrite == 0 ? '-' : 'O',
edit->curs_col / font_width, edit->start_line + 1, edit->curs_row,
edit->curs_line + 1, edit->total_lines + 1, edit->curs1,
edit->last_byte, edit->curs1 < edit->last_byte
? edit_get_byte (edit, edit->curs1) : -1);
sprintf (s, "%.*s", w + 1, t);
i = strlen (s);
s[i] = ' ';
i = w;
do {
if (strchr (" +-*=/:b", s[i])) /* chop off the last word/number */
break;
s[i] = fill;
} while (i--);
s[i] = fill;
s[w] = 0;
}
#ifdef MIDNIGHT
/* how to get as much onto the status line as is numerically possible :) */
void edit_status (WEdit * edit)
{
int w, i, t;
char *s;
w = edit->widget.cols - (edit->have_frame * 2);
s = malloc (w + 15);
if (w < 4)
w = 4;
memset (s, ' ', w);
attrset (SELECTED_COLOR);
if (w > 4) {
widget_move (edit, edit->have_frame, edit->have_frame);
i = w > 24 ? 18 : w - 6;
i = i < 13 ? 13 : i;
sprintf (s, "%s", name_trunc (edit->filename ? edit->filename : "", i));
i += strlen (s);
s[strlen (s)] = ' ';
t = w - 20;
if (t < 0)
t = 0;
status_string (edit, s + 20, t, ' ', 1);
} else {
s[w] = 0;
}
printw ("%.*s", w, s);
attrset (NORMAL_COLOR);
free (s);
}
#else
#ifndef GTK
extern int fixed_font;
#endif
void rerender_text (CWidget * wdt);
#ifdef GTK
void edit_status (WEdit *edit)
{
int w, i, t;
char id[33];
char s[160];
w = edit->num_widget_columns - 1;
if (w > 150)
w = 150;
if (w < 0)
w = 0;
memset (s, 0, w);
if (w > 1) {
i = w > 24 ? 18 : w - 6;
i = i < 13 ? 13 : i;
sprintf (s, "%s", name_trunc (edit->filename ? edit->filename : "", i));
i = strlen (s);
s[i] = ' ';
s[i + 1] = ' ';
t = w - i - 2;
if (t < 0)
t = 0;
status_string (edit, s + i + 2, t, 0, FONT_MEAN_WIDTH);
}
s[w] = 0;
if (strcmp (s, GTK_LABEL(edit->widget->status)->label))
gtk_label_set (GTK_LABEL(edit->widget->status), s);
}
#else
void edit_status (WEdit * edit)
{
if ((COptionsOf (edit->widget) & EDITOR_NO_TEXT)) {
return;
} else {
int w, i, t;
CWidget *wdt;
char id[33];
char s[160];
w = edit->num_widget_columns - 1;
if (w > 150)
w = 150;
if (w < 0)
w = 0;
memset (s, 0, w);
if (w > 1) {
i = w > 24 ? 18 : w - 6;
i = i < 13 ? 13 : i;
sprintf (s, "%s", name_trunc (edit->filename ? edit->filename : "", i));
i = strlen (s);
s[i] = ' ';
s[i+1] = ' ';
t = w - i - 2;
if (t < 0)
t = 0;
status_string (edit, s + i + 2, t, 0, FONT_MEAN_WIDTH);
}
s[w] = 0;
strcpy (id, CIdentOf (edit->widget));
strcat (id, ".text");
wdt = CIdent (id);
free (wdt->text);
wdt->text = strdup (s);
CSetWidgetSize (id, CWidthOf (edit->widget), CHeightOf (wdt));
rerender_text (wdt);
}
}
#endif
#endif
/* boolean */
int cursor_in_screen (WEdit * edit, long row)
{
if (row < 0 || row >= edit->num_widget_lines)
return 0;
else
return 1;
}
/* returns rows from the first displayed line to the cursor */
int cursor_from_display_top (WEdit * edit)
{
if (edit->curs1 < edit->start_display)
return -edit_move_forward (edit, edit->curs1, 0, edit->start_display);
else
return edit_move_forward (edit, edit->start_display, 0, edit->curs1);
}
/* returns how far the cursor is out of the screen */
int cursor_out_of_screen (WEdit * edit)
{
int row = cursor_from_display_top (edit);
if (row >= edit->num_widget_lines)
return row - edit->num_widget_lines + 1;
if (row < 0)
return row;
return 0;
}
#ifndef MIDNIGHT
extern unsigned char per_char[256];
int edit_width_of_long_printable (int c);
#endif
/* this scrolls the text so that cursor is on the screen */
void edit_scroll_screen_over_cursor (WEdit * edit)
{
int p, l;
int outby;
p = edit_get_col (edit);
edit_update_curs_row (edit);
#ifdef MIDNIGHT
outby = p + edit->start_col - edit->num_widget_columns + 1 + (EDIT_RIGHT_EXTREME + edit->found_len);
#else
outby = p + edit->start_col - CWidthOf (edit->widget) + 7 + (EDIT_RIGHT_EXTREME + edit->found_len) * FONT_MEAN_WIDTH + edit_width_of_long_printable (edit_get_byte (edit, edit->curs1));
#endif
if (outby > 0)
edit_scroll_right (edit, outby);
#ifdef MIDNIGHT
outby = EDIT_LEFT_EXTREME - p - edit->start_col;
#else
outby = EDIT_LEFT_EXTREME * FONT_MEAN_WIDTH - p - edit->start_col;
#endif
if (outby > 0)
edit_scroll_left (edit, outby);
p = edit->curs_row;
l = 0;
if (edit->found_len != 0)
l = edit->num_widget_lines / 5;
outby = p - edit->num_widget_lines + 1 + EDIT_BOTTOM_EXTREME + l;
if (outby > 0)
edit_scroll_downward (edit, outby);
outby = EDIT_TOP_EXTREME - p + l;
if (outby > 0)
edit_scroll_upward (edit, outby);
edit_update_curs_row (edit);
}
#ifndef MIDNIGHT
#define CACHE_WIDTH 256
#define CACHE_HEIGHT 128
int EditExposeRedraw = 0;
int EditClear = 0;
/* background colors: marked is refers to mouse highlighting, highlighted refers to a found string. */
unsigned long edit_abnormal_color, edit_marked_abnormal_color;
unsigned long edit_highlighted_color, edit_marked_color;
unsigned long edit_normal_background_color;
/* foreground colors */
unsigned long edit_normal_foreground_color, edit_bold_color;
unsigned long edit_italic_color;
/* cursor color */
unsigned long edit_cursor_color;
void edit_set_foreground_colors (unsigned long normal, unsigned long bold, unsigned long italic)
{
edit_normal_foreground_color = normal;
edit_bold_color = bold;
edit_italic_color = italic;
}
void edit_set_background_colors (unsigned long normal, unsigned long abnormal, unsigned long marked, unsigned long marked_abnormal, unsigned long highlighted)
{
edit_abnormal_color = abnormal;
edit_marked_abnormal_color = marked_abnormal;
edit_marked_color = marked;
edit_highlighted_color = highlighted;
edit_normal_background_color = normal;
}
void edit_set_cursor_color (unsigned long c)
{
edit_cursor_color = c;
}
#else
#define BOLD_COLOR MARKED_COLOR
#define UNDERLINE_COLOR VIEW_UNDERLINED_COLOR
#define MARK_COLOR SELECTED_COLOR
#define DEF_COLOR NORMAL_COLOR
static void set_color (int font)
{
attrset (font);
}
#define edit_move(x,y) widget_move(edit, y, x);
static void print_to_widget (WEdit * edit, long row, int start_col, float start_col_real, long end_col, unsigned int line[])
{
int x = (float) start_col_real + EDIT_TEXT_HORIZONTAL_OFFSET;
int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET;
int y = row + EDIT_TEXT_VERTICAL_OFFSET;
set_color (DEF_COLOR);
edit_move (x1, y);
hline (' ', end_col + 1 - EDIT_TEXT_HORIZONTAL_OFFSET - x1);
edit_move (x + FONT_OFFSET_X, y + FONT_OFFSET_Y);
{
unsigned int *p = line;
int textchar = ' ';
long style;
while (*p) {
style = *p >> 8;
textchar = *p & 0xFF;
#ifdef HAVE_SYNTAXH
if (!(style & (0xFF - MOD_ABNORMAL - MOD_CURSOR)))
SLsmg_set_color ((*p & 0x007F0000) >> 16);
#endif
if (style & MOD_ABNORMAL)
textchar = '.';
if (style & MOD_HIGHLIGHTED) {
set_color (BOLD_COLOR);
} else if (style & MOD_MARKED) {
set_color (MARK_COLOR);
}
if (style & MOD_UNDERLINED) {
set_color (UNDERLINE_COLOR);
}
if (style & MOD_BOLD) {
set_color (BOLD_COLOR);
}
addch (textchar);
p++;
}
}
}
/* b pointer to begining of line */
static void edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_col)
{
static unsigned int line[MAX_LINE_LEN];
unsigned int *p = line;
long m1 = 0, m2 = 0, q, c1, c2;
int col, start_col_real;
unsigned int c;
int fg, bg;
int i;
edit_get_syntax_color (edit, b - 1, &fg, &bg);
q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
start_col_real = (col = (int) edit_move_forward3 (edit, b, 0, q)) + edit->start_col;
c1 = min (edit->column1, edit->column2);
c2 = max (edit->column1, edit->column2);
if (col + 16 > -edit->start_col) {
eval_marks (edit, &m1, &m2);
if (row <= edit->total_lines - edit->start_line) {
while (col <= end_col - edit->start_col) {
*p = 0;
if (q == edit->curs1)
*p |= MOD_CURSOR * 256;
if (q >= m1 && q < m2) {
if (column_highlighting) {
int x;
x = edit_move_forward3 (edit, b, 0, q);
if (x >= c1 && x < c2)
*p |= MOD_MARKED * 256;
} else
*p |= MOD_MARKED * 256;
}
if (q == edit->bracket)
*p |= MOD_BOLD * 256;
if (q >= edit->found_start && q < edit->found_start + edit->found_len)
*p |= MOD_HIGHLIGHTED * 256;
c = edit_get_byte (edit, q);
edit_get_syntax_color (edit, q, &fg, &bg);
/* we don't use bg for mc - fg contains both */
*p |= fg << 16;
q++;
switch (c) {
case '\n':
col = end_col - edit->start_col + 1; /* quit */
*(p++) |= ' ';
break;
case '\t':
i = TAB_SIZE - ((int) col % TAB_SIZE);
*p |= ' ';
c = *(p++) & (0xFFFFFFFF - MOD_CURSOR * 256);
col += i;
while (--i)
*(p++) = c;
break;
case '\r':
break;
default:
if (is_printable (c)) {
*(p++) |= c;
} else {
*(p++) = '.';
*p |= (256 * MOD_ABNORMAL);
}
col++;
break;
}
}
}
} else {
start_col_real = start_col = 0;
}
*p = 0;
print_to_widget (edit, row, start_col, start_col_real, end_col, line);
}
#endif
#ifdef MIDNIGHT
#define key_pending(x) (!is_idle())
#else
int edit_mouse_pending (Window win);
#define edit_draw_this_line edit_draw_this_line_proportional
static int key_pending (WEdit * edit)
{
#ifdef GTK
/* ******* */
#else
if (!(edit->force & REDRAW_COMPLETELY) && !EditExposeRedraw)
return CKeyPending ();
#endif
return 0;
}
#endif
/* b for pointer to begining of line */
static void edit_draw_this_char (WEdit * edit, long curs, long row)
{
int b = edit_bol (edit, curs);
#ifdef MIDNIGHT
edit_draw_this_line (edit, b, row, 0, edit->num_widget_columns - 1);
#else
edit_draw_this_line (edit, b, row, 0, CWidthOf (edit->widget));
#endif
}
/* cursor must be in screen for other than REDRAW_PAGE passed in force */
void render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, long end_column)
{
long row = 0, curs_row;
static int prev_curs_row = 0;
static long prev_start_display = 0;
static int prev_start_col = 0;
static long prev_curs = 0;
unsigned long syntax_rule;
#ifndef MIDNIGHT
static unsigned long prev_win = 0;
#endif
int fg, bg;
int force = edit->force;
long b;
edit_get_syntax_color (edit, edit->start_display - 1, &fg, &bg);
syntax_rule = edit->rule;
/*
if the position of the page has not moved then we can draw the cursor character only.
This will prevent line flicker when using arrow keys.
*/
if ((!(force & REDRAW_CHAR_ONLY)) || (force & REDRAW_PAGE)
#ifndef MIDNIGHT
#ifdef GTK
|| prev_win != ((GdkWindowPrivate *) CWindowOf (edit->widget)->text_area)->xwindow
#else
|| prev_win != CWindowOf (edit->widget)
#endif
#endif
) {
if (!(force & REDRAW_IN_BOUNDS)) { /* !REDRAW_IN_BOUNDS means to ignore bounds and redraw whole rows */
start_row = 0;
end_row = edit->num_widget_lines - 1;
start_column = 0;
#ifdef MIDNIGHT
end_column = edit->num_widget_columns - 1;
#else
end_column = CWidthOf (edit->widget);
#endif
}
if (force & REDRAW_PAGE) {
row = start_row;
b = edit_move_forward (edit, edit->start_display, start_row, 0);
while (row <= end_row) {
if (key_pending (edit))
goto exit_render;
edit_draw_this_line (edit, b, row, start_column, end_column);
b = edit_move_forward (edit, b, 1, 0);
row++;
}
} else {
curs_row = edit->curs_row;
if (force & REDRAW_BEFORE_CURSOR) {
if (start_row < curs_row) {
long upto = curs_row - 1 <= end_row ? curs_row - 1 : end_row;
row = start_row;
b = edit->start_display;
while (row <= upto) {
if (key_pending (edit))
goto exit_render;
edit_draw_this_line (edit, b, row, start_column, end_column);
b = edit_move_forward (edit, b, 1, 0);
}
}
}
/* if (force & REDRAW_LINE) { ---> default */
b = edit_bol (edit, edit->curs1);
if (curs_row >= start_row && curs_row <= end_row) {
if (key_pending (edit))
goto exit_render;
edit_draw_this_line (edit, b, curs_row, start_column, end_column);
}
if (force & REDRAW_AFTER_CURSOR) {
if (end_row > curs_row) {
row = curs_row + 1 < start_row ? start_row : curs_row + 1;
b = edit_move_forward (edit, b, 1, 0);
while (row <= end_row) {
if (key_pending (edit))
goto exit_render;
edit_draw_this_line (edit, b, row, start_column, end_column);
b = edit_move_forward (edit, b, 1, 0);
row++;
}
}
}
if (force & REDRAW_LINE_ABOVE && curs_row >= 1) {
row = curs_row - 1;
b = edit_move_backward (edit, edit_bol (edit, edit->curs1), 1);
if (row >= start_row && row <= end_row) {
if (key_pending (edit))
goto exit_render;
edit_draw_this_line (edit, b, row, start_column, end_column);
}
}
if (force & REDRAW_LINE_BELOW && row < edit->num_widget_lines - 1) {
row = curs_row + 1;
b = edit_bol (edit, edit->curs1);
b = edit_move_forward (edit, b, 1, 0);
if (row >= start_row && row <= end_row) {
if (key_pending (edit))
goto exit_render;
edit_draw_this_line (edit, b, row, start_column, end_column);
}
}
}
} else {
if (prev_curs_row < edit->curs_row) { /* with the new text highlighting, we must draw from the top down */
edit_draw_this_char (edit, prev_curs, prev_curs_row);
edit_draw_this_char (edit, edit->curs1, edit->curs_row);
} else {
edit_draw_this_char (edit, edit->curs1, edit->curs_row);
edit_draw_this_char (edit, prev_curs, prev_curs_row);
}
}
edit->force = 0;
prev_curs_row = edit->curs_row;
prev_curs = edit->curs1;
prev_start_display = edit->start_display;
prev_start_col = edit->start_col;
#ifndef MIDNIGHT
#ifdef GTK
prev_win = ((GdkWindowPrivate *) CWindowOf (edit->widget)->text_area)->xwindow;
#else
prev_win = CWindowOf (edit->widget);
#endif
#endif
exit_render:
edit->last_get_rule = edit->start_display - 1;
edit->rule = syntax_rule;
}
#ifndef MIDNIGHT
void edit_convert_expose_to_area (XExposeEvent * xexpose, int *row1, int *col1, int *row2, int *col2)
{
*col1 = xexpose->x - EDIT_TEXT_HORIZONTAL_OFFSET;
*row1 = (xexpose->y - EDIT_TEXT_VERTICAL_OFFSET) / FONT_PIX_PER_LINE;
*col2 = xexpose->x + xexpose->width + EDIT_TEXT_HORIZONTAL_OFFSET + 3;
*row2 = (xexpose->y + xexpose->height - EDIT_TEXT_VERTICAL_OFFSET) / FONT_PIX_PER_LINE;
}
#ifdef GTK
void edit_render_tidbits (GtkEdit * edit)
{
return;
}
#else
void edit_render_tidbits (CWidget * wdt)
{
int isfocussed;
int w = wdt->width, h = wdt->height;
Window win;
win = wdt->winid;
isfocussed = (win == CGetFocus ());
CSetColor (COLOR_FLAT);
if (isfocussed) {
render_bevel (win, 0, 0, w - 1, h - 1, 3, 1); /*most outer border bevel */
} else {
render_bevel (win, 2, 2, w - 3, h - 3, 1, 1); /*border bevel */
render_bevel (win, 0, 0, w - 1, h - 1, 2, 0); /*most outer border bevel */
}
}
#endif
void edit_set_space_width (int s);
extern int option_long_whitespace;
#endif
void edit_render (WEdit * edit, int page, int row_start, int col_start, int row_end, int col_end)
{
int f = 0;
#ifdef GTK
GtkEdit *win;
#endif
if (page) /* if it was an expose event, 'page' would be set */
edit->force |= REDRAW_PAGE | REDRAW_IN_BOUNDS;
f = edit->force & (REDRAW_PAGE | REDRAW_COMPLETELY);
#ifdef MIDNIGHT
if (edit->force & REDRAW_COMPLETELY)
redraw_labels (edit->widget.parent, (Widget *) edit);
#else
if (option_long_whitespace)
edit_set_space_width (per_char[' '] * 2);
else
edit_set_space_width (per_char[' ']);
#ifdef GTK
win = (GtkEdit *) edit->widget;
#endif
edit_set_foreground_colors (
color_palette (option_editor_fg_normal),
color_palette (option_editor_fg_bold),
color_palette (option_editor_fg_italic)
);
edit_set_background_colors (
color_palette (option_editor_bg_normal),
color_palette (option_editor_bg_abnormal),
color_palette (option_editor_bg_marked),
color_palette (option_editor_bg_marked_abnormal),
color_palette (option_editor_bg_highlighted)
);
edit_set_cursor_color (
color_palette (option_editor_fg_cursor)
);
#ifdef GTK
/* *********** */
#else
if (!EditExposeRedraw)
set_cursor_position (0, 0, 0, 0, 0, 0, 0, 0, 0);
#endif
#endif
render_edit_text (edit, row_start, col_start, row_end, col_end);
if (edit->force) /* edit->force != 0 means a key was pending and the redraw
was halted, so next time we must redraw everything in case stuff
was left undrawn from a previous key press */
edit->force |= REDRAW_PAGE;
#ifndef MIDNIGHT
if (f) {
edit_render_tidbits (edit->widget);
#ifdef GTK
/* ***************** */
#else
CSetColor (edit_normal_background_color);
CLine (CWindowOf (edit->widget), 3, 3, 3, CHeightOf (edit->widget) - 4);
#endif
}
#endif
}
#ifndef MIDNIGHT
void edit_render_expose (WEdit * edit, XExposeEvent * xexpose)
{
int row_start, col_start, row_end, col_end;
EditExposeRedraw = 1;
edit->num_widget_lines = (CHeightOf (edit->widget) - 6) / FONT_PIX_PER_LINE;
edit->num_widget_columns = (CWidthOf (edit->widget) - 7) / FONT_MEAN_WIDTH;
if (edit->force & (REDRAW_PAGE | REDRAW_COMPLETELY)) {
edit->force |= REDRAW_PAGE | REDRAW_COMPLETELY;
edit_render_keypress (edit);
} else {
edit_convert_expose_to_area (xexpose, &row_start, &col_start, &row_end, &col_end);
edit_render (edit, 1, row_start, col_start, row_end, col_end);
}
EditExposeRedraw = 0;
}
void edit_render_keypress (WEdit * edit)
{
edit_render (edit, 0, 0, 0, 0, 0);
}
#else
void edit_render_keypress (WEdit * edit)
{
edit_render (edit, 0, 0, 0, 0, 0);
}
#endif

461
edit/editmenu.c Normal file
View File

@ -0,0 +1,461 @@
/* editor menu definitions and initialisation
Copyright (C) 1996 the Free Software Foundation
Authors: 1996, 1997 Paul Sheer
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <config.h>
#include "edit.h"
#include "editcmddef.h"
#ifdef MIDNIGHT
#include "../src/mad.h"
extern int edit_key_emulation;
extern WEdit *wedit;
extern WButtonBar *edit_bar;
extern Dlg_head *edit_dlg;
extern WMenu *edit_menubar;
#undef edit_message_dialog
#define edit_message_dialog(w,x,y,h,s) query_dialog (h, s, 0, 1, "&Ok")
#define CFocus(x)
static void menu_cmd (int i)
{
send_message (wedit->widget.parent, (Widget *) wedit, WIDGET_COMMAND, i);
}
static void menu_key (int i)
{
send_message (wedit->widget.parent, (Widget *) wedit, WIDGET_KEY, i);
}
void edit_wrap_cmd ()
{
char *f;
char s[12];
sprintf (s, "%d", option_word_wrap_line_length);
f = input_dialog (_(" Word wrap "),
/* Not essential to translate */
_(" Enter line length, 0 for off: "), s);
if (f) {
if (*f) {
option_word_wrap_line_length = atoi (f);
free (f);
}
}
}
void edit_about_cmd ()
{
edit_message_dialog (wedit->mainid, 20, 20, " About ",
"\n"
" Cooledit v2.1\n"
"\n"
" Copyright (C) 1996 the Free Software Foundation\n"
"\n"
" A user friendly text editor written\n"
" for the Midnight Commander.\n"
);
}
void menu_mail_cmd (void) { menu_cmd (CK_Mail); }
void menu_load_cmd (void) { menu_cmd (CK_Load); }
void menu_new_cmd (void) { menu_cmd (CK_New); }
void menu_save_cmd (void) { menu_cmd (CK_Save); }
void menu_save_as_cmd (void) { menu_cmd (CK_Save_As); }
void menu_insert_file_cmd (void) { menu_cmd (CK_Insert_File); }
void menu_quit_cmd (void) { menu_cmd (CK_Exit); }
void menu_mark_cmd (void) { menu_cmd (CK_Mark); }
void menu_markcol_cmd (void) { menu_cmd (CK_Column_Mark); }
void menu_ins_cmd (void) { menu_cmd (CK_Toggle_Insert); }
void menu_copy_cmd (void) { menu_cmd (CK_Copy); }
void menu_move_cmd (void) { menu_cmd (CK_Move); }
void menu_delete_cmd (void) { menu_cmd (CK_Remove); }
void menu_cut_cmd (void) { menu_cmd (CK_Save_Block); }
void menu_search_cmd (void) { menu_cmd (CK_Find); }
void menu_search_again_cmd (void) { menu_cmd (CK_Find_Again); }
void menu_replace_cmd (void) { menu_cmd (CK_Replace); }
void menu_begin_record_cmd (void) { menu_cmd (CK_Begin_Record_Macro); }
void menu_end_record_cmd (void) { menu_cmd (CK_End_Record_Macro); }
void menu_wrap_cmd (void) { edit_wrap_cmd (); }
void menu_exec_macro_cmd (void) { menu_key (XCTRL ('a')); }
void menu_exec_macro_delete_cmd (void) { menu_cmd (CK_Delete_Macro); }
void menu_c_form_cmd (void) { menu_key (KEY_F (19)); }
void menu_ispell_cmd (void) { menu_cmd (CK_Pipe_Block (1)); }
void menu_sort_cmd (void) { menu_cmd (CK_Sort); }
void menu_date_cmd (void) { menu_cmd (CK_Date); }
void menu_undo_cmd (void) { menu_cmd (CK_Undo); }
void menu_beginning_cmd (void) { menu_cmd (CK_Beginning_Of_Text); }
void menu_end_cmd (void) { menu_cmd (CK_End_Of_Text); }
void menu_refresh_cmd (void) { menu_cmd (CK_Refresh); }
void menu_goto_line (void) { menu_cmd (CK_Goto); }
void menu_lit_cmd (void) { menu_key (XCTRL ('q')); }
void menu_format_paragraph (void) { menu_cmd (CK_Paragraph_Format); }
void edit_options_dialog (void);
void menu_options (void) { edit_options_dialog (); }
static menu_entry FileMenu[] =
{
{' ', N_("&Open/load... C-o"), 'O', menu_load_cmd},
{' ', N_("&New C-n"), 'N', menu_new_cmd},
{' ', "", ' ', 0},
{' ', N_("&Save F2"), 'S', menu_save_cmd},
{' ', N_("save &As... F12"), 'A', menu_save_as_cmd},
{' ', "", ' ', 0},
{' ', N_("&Insert file... F15"), 'I', menu_insert_file_cmd},
{' ', N_("copy to &File... C-f"), 'F', menu_cut_cmd},
{' ', "", ' ', 0},
{' ', N_("a&Bout... "), 'B', edit_about_cmd},
{' ', "", ' ', 0},
{' ', N_("&Quit F10"), 'Q', menu_quit_cmd}
};
static menu_entry FileMenuEmacs[] =
{
{' ', N_("&Open/load... C-o"), 'O', menu_load_cmd},
{' ', N_("&New C-x k"), 'N', menu_new_cmd},
{' ', "", ' ', 0},
{' ', N_("&Save F2"), 'S', menu_save_cmd},
{' ', N_("save &As... F12"), 'A', menu_save_as_cmd},
{' ', "", ' ', 0},
{' ', N_("&Insert file... F15"), 'I', menu_insert_file_cmd},
{' ', N_("copy to &File... "), 'F', menu_cut_cmd},
{' ', "", ' ', 0},
{' ', N_("a&Bout... "), 'B', edit_about_cmd},
{' ', "", ' ', 0},
{' ', N_("&Quit F10"), 'Q', menu_quit_cmd}
};
static menu_entry EditMenu[] =
{
{' ', N_("&Toggle Mark F3"), 'T', menu_mark_cmd},
{' ', N_("&Mark Columns S-F3"), 'T', menu_markcol_cmd},
{' ', "", ' ', 0},
{' ', N_("toggle &Ins/overw Ins"), 'I', menu_ins_cmd},
{' ', "", ' ', 0},
{' ', N_("&Copy F5"), 'C', menu_copy_cmd},
{' ', N_("&Move F6"), 'M', menu_move_cmd},
{' ', N_("&Delete F8"), 'D', menu_delete_cmd},
{' ', "", ' ', 0},
{' ', N_("&Undo C-u"), 'U', menu_undo_cmd},
{' ', "", ' ', 0},
{' ', N_("&Beginning C-PgUp"), 'B', menu_beginning_cmd},
{' ', N_("&End C-PgDn"), 'E', menu_end_cmd}
};
static menu_entry EditMenuEmacs[] =
{
{' ', N_("&Toggle Mark F3"), 'T', menu_mark_cmd},
{' ', N_("&Mark Columns S-F3"), 'T', menu_markcol_cmd},
{' ', "", ' ', 0},
{' ', N_("toggle &Ins/overw Ins"), 'I', menu_ins_cmd},
{' ', "", ' ', 0},
{' ', N_("&Copy F5"), 'C', menu_copy_cmd},
{' ', N_("&Move F6"), 'M', menu_move_cmd},
{' ', N_("&Delete F8"), 'D', menu_delete_cmd},
{' ', "", ' ', 0},
{' ', N_("&Undo C-u"), 'U', menu_undo_cmd},
{' ', "", ' ', 0},
{' ', N_("&Beginning C-PgUp"), 'B', menu_beginning_cmd},
{' ', N_("&End C-PgDn"), 'E', menu_end_cmd}
};
static menu_entry SearReplMenu[] =
{
{' ', N_("&Search... F7"), 'S', menu_search_cmd},
{' ', N_("search &Again F17"), 'A', menu_search_again_cmd},
{' ', N_("&Replace... F4"), 'R', menu_replace_cmd}
};
static menu_entry SearReplMenuEmacs[] =
{
{' ', N_("&Search... F7"), 'S', menu_search_cmd},
{' ', N_("search &Again F17"), 'A', menu_search_again_cmd},
{' ', N_("&Replace... F4"), 'R', menu_replace_cmd}
};
static menu_entry CmdMenu[] =
{
{' ', N_("&Goto line... M-l"), 'G', menu_goto_line},
{' ', "", ' ', 0},
{' ', N_("insert &Literal... C-q"), 'L', menu_lit_cmd},
{' ', "", ' ', 0},
{' ', N_("&Refresh screen C-l"), 'R', menu_refresh_cmd},
{' ', "", ' ', 0},
{' ', N_("&Start record macro C-r"), 'S', menu_begin_record_cmd},
{' ', N_("&Finish record macro... C-r"), 'F', menu_end_record_cmd},
{' ', N_("&Execute macro... C-a, KEY"), 'E', menu_exec_macro_cmd},
{' ', N_("delete macr&O... "), 'O', menu_exec_macro_delete_cmd},
{' ', "", ' ', 0},
{' ', N_("insert &Date/time "), 'D', menu_date_cmd},
{' ', "", ' ', 0},
{' ', N_("format p&Aragraph M-p"), 'A', menu_format_paragraph},
{' ', N_("'ispell' s&Pell check C-p"), 'P', menu_ispell_cmd},
{' ', N_("sor&T... M-t"), 'T', menu_sort_cmd},
{' ', N_("'indent' &C Formatter F19"), 'C', menu_c_form_cmd},
{' ', N_("&Mail... "), 'M', menu_mail_cmd}
};
static menu_entry CmdMenuEmacs[] =
{
{' ', N_("&Goto line... M-l"), 'G', menu_goto_line},
{' ', "", ' ', 0},
{' ', N_("insert &Literal... C-q"), 'L', menu_lit_cmd},
{' ', "", ' ', 0},
{' ', N_("&Refresh screen C-l"), 'R', menu_refresh_cmd},
{' ', "", ' ', 0},
{' ', N_("&Start record macro C-r"), 'S', menu_begin_record_cmd},
{' ', N_("&Finish record macro... C-r"), 'F', menu_end_record_cmd},
{' ', N_("&Execute macro... C-x e, KEY"), 'E', menu_exec_macro_cmd},
{' ', N_("delete macr&O... "), 'o', menu_exec_macro_delete_cmd},
{' ', "", ' ', 0},
{' ', N_("insert &Date/time "), 'D', menu_date_cmd},
{' ', "", ' ', 0},
{' ', N_("format p&Aragraph M-p"), 'a', menu_format_paragraph},
{' ', N_("'ispell' s&Pell check M-$"), 'P', menu_ispell_cmd},
{' ', N_("sor&T... M-t"), 'T', menu_sort_cmd},
{' ', N_("'indent' &C Formatter F19"), 'C', menu_c_form_cmd}
};
extern void menu_save_mode_cmd (void);
static menu_entry OptMenu[] =
{
{' ', N_("&General... "), 'G', menu_options},
{' ', N_("&Save mode..."), 'S', menu_save_mode_cmd}
#if 0
{' ', N_("&Layout..."), 'L', menu_layout_cmd}
#endif
};
static menu_entry OptMenuEmacs[] =
{
{' ', N_("&General... "), 'G', menu_options},
{' ', N_("&Save mode..."), 'S', menu_save_mode_cmd}
#if 0
{' ', N_("&Layout..."), 'L', menu_layout_cmd}
#endif
};
#define menu_entries(x) sizeof(x)/sizeof(menu_entry)
Menu EditMenuBar[N_menus];
void edit_init_menu_normal (void)
{
EditMenuBar[0] = create_menu (_(" File "), FileMenu, menu_entries (FileMenu));
EditMenuBar[1] = create_menu (_(" Edit "), EditMenu, menu_entries (EditMenu));
EditMenuBar[2] = create_menu (_(" Sear/Repl "), SearReplMenu, menu_entries (SearReplMenu));
EditMenuBar[3] = create_menu (_(" Command "), CmdMenu, menu_entries (CmdMenu));
EditMenuBar[4] = create_menu (_(" Options "), OptMenu, menu_entries (OptMenu));
}
void edit_init_menu_emacs (void)
{
EditMenuBar[0] = create_menu (_(" File "), FileMenuEmacs, menu_entries (FileMenuEmacs));
EditMenuBar[1] = create_menu (_(" Edit "), EditMenuEmacs, menu_entries (EditMenuEmacs));
EditMenuBar[2] = create_menu (_(" Sear/Repl "), SearReplMenuEmacs, menu_entries (SearReplMenuEmacs));
EditMenuBar[3] = create_menu (_(" Command "), CmdMenuEmacs, menu_entries (CmdMenuEmacs));
EditMenuBar[4] = create_menu (_(" Options "), OptMenuEmacs, menu_entries (OptMenuEmacs));
}
void edit_done_menu (void)
{
int i;
for (i = 0; i < N_menus; i++)
destroy_menu (EditMenuBar[i]);
}
void edit_drop_menu_cmd (WEdit * e, int which)
{
if (edit_menubar->active)
return;
edit_menubar->active = 1;
edit_menubar->dropped = drop_menus;
edit_menubar->previous_selection = which >= 0 ? which : dlg_item_number (edit_dlg);
if (which >= 0)
edit_menubar->selected = which;
dlg_select_widget (edit_dlg, edit_menubar);
}
void edit_menu_cmd (WEdit * e)
{
edit_drop_menu_cmd (e, -1);
}
int edit_drop_hotkey_menu (WEdit * e, int key)
{
int m = 0;
switch (key) {
case ALT ('f'):
if (edit_key_emulation == EDIT_KEY_EMULATION_EMACS)
return 0;
m = 0;
break;
case ALT ('e'):
m = 1;
break;
case ALT ('s'):
m = 2;
break;
case ALT ('c'):
m = 3;
break;
case ALT ('o'):
m = 4;
break;
default:
return 0;
}
edit_drop_menu_cmd (e, m);
return 1;
}
#else /* !MIDNIGHT */
extern CWidget *wedit;
void CSetEditMenu (const char *ident)
{
wedit = CIdent (ident);
}
CWidget *CGetEditMenu (void)
{
return wedit;
}
static void menu_cmd (unsigned long i)
{
XEvent e;
if (wedit) {
memset (&e, 0, sizeof (XEvent));
e.type = EditorCommand;
e.xkey.keycode = i;
e.xkey.window = wedit->winid;
CFocus (wedit);
CSendEvent (&e);
}
}
void CEditMenuCommand (int i)
{
menu_cmd ((unsigned long) i);
}
static void menu_key (KeySym i, int state)
{
int cmd, ch;
if (edit_translate_key (0, i, state, &cmd, &ch)) {
if (cmd > 0)
menu_cmd (cmd);
}
}
static void menu_ctrl_key (unsigned long i)
{
menu_key ((KeySym) i, ControlMask);
}
void CDrawEditMenuButtons (const char *ident, Window parent, Window focus_return, int x, int y)
{
int d;
CDrawMenuButton (catstrs (ident, ".filemenu", 0), parent, focus_return, x, y, AUTO_WIDTH, AUTO_HEIGHT, 8,
/* The following are menu options. Do not change the key bindings (eg. C-o) and preserve '\t' */
_(" File "),
_("Open...\tC-o"), '~', menu_cmd, CK_Load,
_("New\tC-n"), '~', menu_cmd, CK_New,
"", ' ', 0, 0,
_("Save\tF2"), '~', menu_cmd, CK_Save,
_("Save as...\tF12"), '~', menu_cmd, CK_Save_As,
"", ' ', 0, 0,
_("Insert file...\tF15"), '~', menu_cmd, CK_Insert_File,
_("Copy to file...\tC-f"), '~', menu_cmd, CK_Save_Block
);
/* Tool hint */
CSetToolHint (catstrs (ident, ".filemenu", 0), _("Disk operations"));
CGetHintPos (&x, &d);
CDrawMenuButton (catstrs (ident, ".editmenu", 0), parent, focus_return, x, y, AUTO_WIDTH, AUTO_HEIGHT, 15,
_(" Edit "),
_("Toggle mark\tF3"), '~', menu_cmd, CK_Mark,
_("Toggle mark columns\tC-b"), '~', menu_cmd, CK_Column_Mark,
"", ' ', 0, 0,
_("Toggle insert/overwrite\tIns"), '~', menu_cmd, CK_Toggle_Insert,
"", ' ', 0, 0,
_("Copy block to cursor\tF5"), '~', menu_cmd, CK_Copy,
_("Move block to cursor\tF6"), '~', menu_cmd, CK_Move,
_("Delete block\tF8/C-Del"), '~', menu_cmd, CK_Remove,
"", ' ', 0, 0,
_("Copy block to clipbrd\tC-Ins"), '~', menu_cmd, CK_XStore,
_("Cut block to clipbrd\tS-Del"), '~', menu_cmd, CK_XCut,
_("Paste block from clipbrd\tS-Ins"), '~', menu_cmd, CK_XPaste,
_("Selection history\tM-Ins"), '~', menu_cmd, CK_Selection_History,
"", ' ', 0, 0,
_("Undo\tC-BackSpace"), '~', menu_cmd, CK_Undo
);
/* Tool hint */
CSetToolHint (catstrs (ident, ".editmenu", 0), _("Manipulating blocks of text"));
CGetHintPos (&x, &d);
CDrawMenuButton (catstrs (ident, ".searchmenu", 0), parent, focus_return, x, y, AUTO_WIDTH, AUTO_HEIGHT, 4,
_(" Srch/Replce "),
_("Search...\tF7"), '~', menu_cmd, CK_Find,
_("Search again\tF17"), '~', menu_cmd, CK_Find_Again,
_("Replace...\tF4"), '~', menu_cmd, CK_Replace,
_("Replace again\tF14"), '~', menu_cmd, CK_Replace_Again
);
/* Tool hint */
CSetToolHint (catstrs (ident, ".searchmenu", 0), _("Search for and replace text"));
CGetHintPos (&x, &d);
CDrawMenuButton (catstrs (ident, ".commandmenu", 0), parent, focus_return, x, y, AUTO_WIDTH, AUTO_HEIGHT, 11,
_(" Command "),
_("Goto line...\tM-l"), '~', menu_cmd, CK_Goto,
"", ' ', 0, 0,
_("Start record macro\tC-r"), '~', menu_cmd, CK_Begin_Record_Macro,
_("Finish record macro...\tC-r"), '~', menu_cmd, CK_End_Record_Macro,
_("Execute macro...\tC-a, KEY"), '~', menu_ctrl_key, XK_a,
_("Delete macro...\t"), '~', menu_cmd, CK_Delete_Macro,
"", ' ', 0, 0,
_("Insert date/time\tC-d"), '~', menu_cmd, CK_Date,
_("Format paragraph\tM-p"), '~', menu_cmd, CK_Paragraph_Format,
"", ' ', 0, 0,
_("Refresh display\tC-l"), '~', menu_cmd, CK_Refresh
);
/* Tool hint */
CSetToolHint (catstrs (ident, ".commandmenu", 0), _("Macros and internal commands"));
}
#endif /* !MIDNIGHT */

182
edit/editoptions.c Normal file
View File

@ -0,0 +1,182 @@
/* editor options dialog box
Copyright (C) 1996, 1997 the Free Software Foundation
Authors: 1996, 1997 Paul Sheer
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <config.h>
#include "edit.h"
#define OPT_DLG_H 15
#define OPT_DLG_W 72
#ifndef USE_INTERNAL_EDIT
#define USE_INTERNAL_EDIT 1
#endif
#include "../src/main.h" /* extern int option_this_and_that ... */
char *key_emu_str[] =
{"Intuitive", "Emacs"};
char *wrap_str[] =
{N_("None"), N_("Dynamic paragraphing"), N_("Type writer wrap")};
extern int option_syntax_highlighting;
void edit_options_dialog (void)
{
char wrap_length[32], tab_spacing[32], *p, *q;
int wrap_mode = 0;
int tedit_key_emulation = edit_key_emulation;
int toption_fill_tabs_with_spaces = option_fill_tabs_with_spaces;
int tedit_confirm_save = edit_confirm_save;
int tedit_syntax_highlighting = option_syntax_highlighting;
int toption_return_does_auto_indent = option_return_does_auto_indent;
int toption_backspace_through_tabs = option_backspace_through_tabs;
int toption_fake_half_tabs = option_fake_half_tabs;
QuickWidget quick_widgets[] =
{
/*0 */
{quick_button, 6, 10, OPT_DLG_H - 3, OPT_DLG_H, "&Cancel", 0, B_CANCEL, 0,
0, XV_WLAY_DONTCARE, NULL},
/*1 */
{quick_button, 2, 10, OPT_DLG_H - 3, OPT_DLG_H, "&Ok", 0, B_ENTER, 0,
0, XV_WLAY_DONTCARE, NULL},
/*2 */
{quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 4, OPT_DLG_H, "Word wrap line length : ", 0, 0,
0, 0, XV_WLAY_DONTCARE, NULL},
/*3 */
{quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 4, OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0,
0, 0, XV_WLAY_DONTCARE, "i"},
/*4 */
{quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 5, OPT_DLG_H, "Tab spacing : ", 0, 0,
0, 0, XV_WLAY_DONTCARE, NULL},
/*5 */
{quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 5, OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0,
0, 0, XV_WLAY_DONTCARE, "i"},
/*6 */
#if !defined(MIDNIGHT) || defined(HAVE_SYNTAXH)
#define OA 1
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H, "syntax h&Ighlighting", 8, 0,
0, 0, XV_WLAY_DONTCARE, NULL},
#else
#define OA 0
#endif
/*7 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 8, OPT_DLG_H, "confir&M before saving", 6, 0,
0, 0, XV_WLAY_DONTCARE, NULL},
/*8 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 9, OPT_DLG_H, "&Fill tabs with spaces", 0, 0,
0, 0, XV_WLAY_DONTCARE, NULL},
/*9 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 10, OPT_DLG_H, "&Return does auto indent", 0, 0,
0, 0, XV_WLAY_DONTCARE, NULL},
/*10 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H, "&Backspace through tabs", 0, 0,
0, 0, XV_WLAY_DONTCARE, NULL},
/*11 */
{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H, "&Fake half tabs", 0, 0,
0, 0, XV_WLAY_DONTCARE, NULL},
/*12 */
{quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 6, OPT_DLG_H, "", 3, 0,
0, wrap_str, XV_WLAY_DONTCARE, "wrapm"},
/*13 */
{quick_label, 4, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H, N_("Wrap mode"), 0, 0,
0, 0, XV_WLAY_DONTCARE, NULL},
/*14 */
{quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H, "", 2, 0,
0, key_emu_str, XV_WLAY_DONTCARE, "keyemu"},
/*15 */
{quick_label, 4, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H, N_("Key emulation"), 0, 0,
0, 0, XV_WLAY_DONTCARE, NULL},
{0}};
sprintf (wrap_length, "%d", option_word_wrap_line_length);
sprintf (tab_spacing, "%d", option_tab_spacing);
quick_widgets[3].text = wrap_length;
quick_widgets[3].str_result = &p;
quick_widgets[5].text = tab_spacing;
quick_widgets[5].str_result = &q;
quick_widgets[5 + OA].result = &tedit_syntax_highlighting;
quick_widgets[6 + OA].result = &tedit_confirm_save;
quick_widgets[7 + OA].result = &toption_fill_tabs_with_spaces;
quick_widgets[8 + OA].result = &toption_return_does_auto_indent;
quick_widgets[9 + OA].result = &toption_backspace_through_tabs;
quick_widgets[10 + OA].result = &toption_fake_half_tabs;
if (option_auto_para_formatting)
wrap_mode = 1;
else if (option_typewriter_wrap)
wrap_mode = 2;
else
wrap_mode = 0;
quick_widgets[11 + OA].result = &wrap_mode;
quick_widgets[11 + OA].value = wrap_mode;
quick_widgets[13 + OA].result = &tedit_key_emulation;
quick_widgets[13 + OA].value = tedit_key_emulation;
{
QuickDialog Quick_options =
{OPT_DLG_W, OPT_DLG_H, -1, 0, " Editor Options ",
"", "quick_input", 0};
Quick_options.widgets = quick_widgets;
if (quick_dialog (&Quick_options) != B_CANCEL) {
if (p) {
option_word_wrap_line_length = atoi (p);
free (p);
}
if (q) {
option_tab_spacing = atoi (q);
if (option_tab_spacing < 0)
option_tab_spacing = 2;
option_tab_spacing += option_tab_spacing & 1;
free (q);
}
option_syntax_highlighting = *quick_widgets[5 + OA].result;
edit_confirm_save = *quick_widgets[6 + OA].result;
option_fill_tabs_with_spaces = *quick_widgets[7 + OA].result;
option_return_does_auto_indent = *quick_widgets[8 + OA].result;
option_backspace_through_tabs = *quick_widgets[9 + OA].result;
option_fake_half_tabs = *quick_widgets[10 + OA].result;
if (*quick_widgets[11 + OA].result == 1) {
option_auto_para_formatting = 1;
option_typewriter_wrap = 0;
} else if (*quick_widgets[11 + OA].result == 2) {
option_auto_para_formatting = 0;
option_typewriter_wrap = 1;
} else {
option_auto_para_formatting = 0;
option_typewriter_wrap = 0;
}
edit_key_emulation = *quick_widgets[13 + OA].result;
return;
} else {
return;
}
}
}

1212
edit/editwidget.c Normal file

File diff suppressed because it is too large Load Diff

2881
edit/syntax.c Normal file

File diff suppressed because it is too large Load Diff

350
edit/wordproc.c Normal file
View File

@ -0,0 +1,350 @@
/* wordproc.c - word-processor mode for the editor: does dynamic
paragraph formatting.
Copyright (C) 1996 Paul Sheer
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include "edit.h"
#ifdef MIDNIGHT
#define tab_width option_tab_spacing
#endif
int line_is_blank (WEdit * edit, long line);
#define NO_FORMAT_CHARS_START "-+*\\,.;:&>"
static long line_start (WEdit * edit, long line)
{
static long p = -1, l = 0;
int c;
if (p == -1 || abs (l - line) > abs (edit->curs_line - line)) {
l = edit->curs_line;
p = edit->curs1;
}
if (line < l)
p = edit_move_backward (edit, p, l - line);
else if (line > l)
p = edit_move_forward (edit, p, line - l, 0);
l = line;
p = edit_bol (edit, p);
while (strchr ("\t ", c = edit_get_byte (edit, p)))
p++;
return p;
}
static int bad_line_start (WEdit * edit, long p)
{
int c;
c = edit_get_byte (edit, p);
if (c == '.') { /* `...' is acceptable */
if (edit_get_byte (edit, p + 1) == '.')
if (edit_get_byte (edit, p + 2) == '.')
return 0;
return 1;
}
if (c == '-') {
if (edit_get_byte (edit, p + 1) == '-')
if (edit_get_byte (edit, p + 2) == '-')
return 0; /* `---' is acceptable */
return 1;
}
if (strchr (NO_FORMAT_CHARS_START, c))
return 1;
return 0;
}
static long begin_paragraph (WEdit * edit, long p, int force)
{
int i;
for (i = edit->curs_line - 1; i > 0; i--) {
if (line_is_blank (edit, i)) {
i++;
break;
}
if (force) {
if (bad_line_start (edit, line_start (edit, i))) {
i++;
break;
}
}
}
return edit_move_backward (edit, edit_bol (edit, edit->curs1), edit->curs_line - i);
}
static long end_paragraph (WEdit * edit, long p, int force)
{
int i;
for (i = edit->curs_line + 1; i < edit->total_lines; i++) {
if (line_is_blank (edit, i)) {
i--;
break;
}
if (force)
if (bad_line_start (edit, line_start (edit, i))) {
i--;
break;
}
}
return edit_eol (edit, edit_move_forward (edit, edit_bol (edit, edit->curs1), i - edit->curs_line, 0));
}
static char *get_paragraph (WEdit * edit, long p, long q, int indent, int *size)
{
char *s, *t;
t = malloc ((q - p) + 2 * (q - p) / option_word_wrap_line_length + 10);
if (!t)
return 0;
for (s = t; p < q; p++, s++) {
if (indent)
if (edit_get_byte (edit, p - 1) == '\n')
while (strchr ("\t ", edit_get_byte (edit, p)))
p++;
*s = edit_get_byte (edit, p);
}
*size = (unsigned long) s - (unsigned long) t;
t[*size] = '\n';
return t;
}
static void strip_newlines (char *t, int size)
{
char *p = t;
while (size--) {
*p = *p == '\n' ? ' ' : *p;
p++;
}
}
#ifndef MIDNIGHT
int edit_width_of_long_printable (int c);
#endif
/*
This is a copy of the function
int calc_text_pos (WEdit * edit, long b, long *q, int l)
in propfont.c :(
It calculates the number of chars in a line specified to length l in pixels
*/
extern int tab_width;
static inline int next_tab_pos (int x)
{
return x += tab_width - x % tab_width;
}
static int line_pixel_length (char *t, long b, int l)
{
int x = 0, c, xn = 0;
for (;;) {
c = t[b];
switch (c) {
case '\n':
return b;
case '\t':
xn = next_tab_pos (x);
break;
default:
#ifdef MIDNIGHT
xn = x + 1;
#else
xn = x + edit_width_of_long_printable (c);
#endif
break;
}
if (xn > l)
break;
x = xn;
b++;
}
return b;
}
/* find the start of a word */
static int next_word_start (char *t, int q, int size)
{
int i;
for (i = q;; i++) {
switch (t[i]) {
case '\n':
return -1;
case '\t':
case ' ':
for (;; i++) {
if (t[i] == '\n')
return -1;
if (t[i] != ' ' && t[i] != '\t')
return i;
}
break;
}
}
}
/* find the start of a word */
static int word_start (char *t, int q, int size)
{
int i = q;
if (t[q] == ' ' || t[q] == '\t')
return next_word_start (t, q, size);
for (;;) {
int c;
if (!i)
return -1;
c = t[i - 1];
if (c == '\n')
return -1;
if (c == ' ' || c == '\t')
return i;
i--;
}
}
/* replaces ' ' with '\n' to properly format a paragraph */
static void format_this (char *t, int size, int indent)
{
int q = 0, ww;
strip_newlines (t, size);
ww = option_word_wrap_line_length * FONT_MEAN_WIDTH - indent;
if (ww < FONT_MEAN_WIDTH * 2)
ww = FONT_MEAN_WIDTH * 2;
for (;;) {
int p;
q = line_pixel_length (t, q, ww);
if (q > size)
break;
if (t[q] == '\n')
break;
p = word_start (t, q, size);
if (p == -1)
q = next_word_start (t, q, size); /* Return the end of the word if the beginning
of the word is at the beginning of a line
(i.e. a very long word) */
else
q = p;
if (q == -1) /* end of paragraph */
break;
if (q)
t[q - 1] = '\n';
}
}
static void replace_at (WEdit * edit, long q, int c)
{
edit_cursor_move (edit, q - edit->curs1);
edit_delete (edit);
edit_insert_ahead (edit, c);
}
void edit_insert_indent (WEdit * edit, int indent);
/* replaces a block of text */
static void put_paragraph (WEdit * edit, char *t, long p, long q, int indent, int size)
{
long cursor;
int i, c = 0;
cursor = edit->curs1;
if (indent)
while (strchr ("\t ", edit_get_byte (edit, p)))
p++;
for (i = 0; i < size; i++, p++) {
if (i && indent) {
if (t[i - 1] == '\n' && c == '\n') {
while (strchr ("\t ", edit_get_byte (edit, p)))
p++;
} else if (t[i - 1] == '\n') {
long curs;
edit_cursor_move (edit, p - edit->curs1);
curs = edit->curs1;
edit_insert_indent (edit, indent);
if (cursor >= curs)
cursor += edit->curs1 - p;
p = edit->curs1;
} else if (c == '\n') {
edit_cursor_move (edit, p - edit->curs1);
while (strchr ("\t ", edit_get_byte (edit, p))) {
edit_delete (edit);
if (cursor > edit->curs1)
cursor--;
}
p = edit->curs1;
}
}
c = edit_get_byte (edit, p);
if (c != t[i])
replace_at (edit, p, t[i]);
}
edit_cursor_move (edit, cursor - edit->curs1); /* restore cursor position */
}
int edit_indent_width (WEdit * edit, long p);
static int test_indent (WEdit * edit, long p, long q)
{
int indent;
indent = edit_indent_width (edit, p++);
if (!indent)
return 0;
for (; p < q; p++)
if (edit_get_byte (edit, p - 1) == '\n')
if (indent != edit_indent_width (edit, p))
return 0;
return indent;
}
void format_paragraph (WEdit * edit, int force)
{
long p, q;
int size;
char *t;
int indent = 0;
if (option_word_wrap_line_length < 2)
return;
if (line_is_blank (edit, edit->curs_line))
return;
p = begin_paragraph (edit, edit->curs1, force);
q = end_paragraph (edit, edit->curs1, force);
indent = test_indent (edit, p, q);
t = get_paragraph (edit, p, q, indent, &size);
if (!t)
return;
if (!force) {
int i;
if (strchr (NO_FORMAT_CHARS_START, *t)) {
free (t);
return;
}
for (i = 0; i < size - 1; i++) {
if (t[i] == '\n') {
if (strchr (NO_FORMAT_CHARS_START "\t ", t[i + 1])) {
free (t);
return;
}
}
}
}
format_this (t, q - p, indent);
put_paragraph (edit, t, p, q, indent, size);
free (t);
}