Initial commit

This commit is contained in:
Paul Sheer 1998-09-14 20:18:54 +00:00
parent e87670a3bd
commit df20f28f2e
24 changed files with 16499 additions and 0 deletions

90
gtkedit/Makefile Normal file
View File

@ -0,0 +1,90 @@
# Generated automatically from Makefile.in by configure.
srcdir = .
rootdir = $(srcdir)/..
include ../Make.common
CFLAGS = $(XCFLAGS)
CPPFLAGS = $(XCPPFLAGS)
LDFLAGS = $(XLDFLAGS)
DEFS = $(XDEFS)
LIBS = $(XLIBS) -lpam -ldl $(XLIB)
INSTALL = /usr/bin/ginstall -c
INSTALL_PROGRAM = ${INSTALL}
INSTALL_DATA = ${INSTALL} -m 644
AR = /usr/bin/ar
#
# Distribution variables
#
EDITSRC = edit.c editcmd.c editdraw.c \
editwidget.c gtkedit.c gtkeditkey.c \
mousemark.c propfont.c syntax.c wordproc.c \
config.h edit.h editcmddef.h global.h gtkedit.h \
libgettext.h lkeysym.h mousemark.h my_string.h
EDITOBJS = edit.o editcmd.o editdraw.o \
editwidget.o gtkedit.o gtkeditkey.o \
mousemark.o propfont.o syntax.o wordproc.o \
DIST = Makefile.in README.edit $(EDITSRC)
all: libgtkedit.a
.c.o:
$(CC) -c $(CPPFLAGS) $(DEFS) $(CFLAGS) -DGTK $<
check:
@echo no tests are supplied.
libgtkedit.a: $(EDITOBJS)
$(RMF) $@
$(AR) cr $@ $(EDITOBJS)
-$(RANLIB) $@
mcedit:
-$(RMF) $(DESTDIR)$(bindir)/$(binprefix)mcedit
$(LN_S) mc $(DESTDIR)$(bindir)/$(binprefix)mcedit
showlibdep:
@echo 'OBJS="$(EDITOBJS)"'
cross:
$(MAKE) CC=gcc-linux CPP="gcc-linux -E" \
CPPFLAGS="$(CPPFLAGS) -I/usr/local/lib/gcc-lib/i386-linux-linux/include/ncurses "
TAGS: $(EDITSRC)
etags $(EDITSRC)
clean:
$(RMF) *.o core a.out libgtkedit.a
realclean: clean
$(RMF) .depend
$(RMF) TAGS
$(RMF) *~
distclean:
-$(RMF) $(srcdir)/*~ $(srcdir)/*.o $(srcdir)/a.out
-$(RMF) $(srcdir)/core $(srcdir)/libgtkedit.a
-if test $(srcdir) = .; then $(MAKE) realclean; fi
-$(RMF) $(srcdir)/Makefile
install: mcedit
uninstall:
-$(RMF) $(DESTDIR)$(bindir)/$(binprefix)mcedit
distcopy:
$(CP) $(DIST) ../../mc-$(VERSION)/edit
depend dep: mcdep
fastdeploc:
# ***Dependencies***Do not edit***
ifeq (.depend,$(wildcard .depend))
include .depend
endif
# ***End of dependencies***

2262
gtkedit/edit.c Normal file

File diff suppressed because it is too large Load Diff

835
gtkedit/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 */

View File

@ -0,0 +1,545 @@
/* edit_key_translator.c - does key to command translation
Copyright (C) 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.
*/
/*
This sequence of code takes the integer 'x_state' and the long
integer 'x_key' and translates them into the integer 'command' or the
integer 'char_for_insertion'. 'x_key' holds one of the keys in the
system header file key_sym_def.h (/usr/include/X11/key_sym_def.h on
my Linux machine) and 'x_state' holds a bitwise inclusive OR of
Button1Mask, Button2Mask, ShiftMask, LockMask, ControlMask, MyAltMask,
Mod2Mask, Mod3Mask, Mod4Mask, or Mod5Mask as explained in the
XKeyEvent man page. The integer 'command' is one of the editor
commands in the header file editcmddef.h
Normally you would only be interested in the ShiftMask and
ControlMask modifiers. The MyAltMask modifier refers to the Alt key
on my system.
If the particular 'x_key' is an ordinary character (say XK_a) then
you must translate it into 'char_for_insertion', and leave 'command'
untouched.
So for example, to add the key binding Ctrl-@ for marking text,
the following piece of code can be used:
if ((x_state & ControlMask) && x_key == XK_2) {
command = CK_Mark;
goto fin:
}
For another example, suppose you want the exclamation mark key to
insert a '1' then,
if (x_key == XK_exclam) {
char_for_insertion = '1';
goto fin:
}
However you must not set both 'command' and 'char_for_insertion';
one or the other only.
Not every combination of key states and keys will work though,
and some experimentation may be necessary.
The code below is an example that may by appended or modified
by the user. For brevity, it has a lookup table for basic key presses.
*/
#include <config.h>
#include "edit.h"
#include "app_glob.c"
#include "coollocal.h"
#include "editcmddef.h"
int (*user_defined_key_function) (unsigned int state, unsigned int keycode, KeySym keysym) = 0;
int option_interpret_numlock = 0;
void edit_set_user_key_function (int (*user_def_key_func) (unsigned int, unsigned int, KeySym))
{
user_defined_key_function = user_def_key_func;
}
int edit_translate_key (unsigned int x_keycode, long x_key, int x_state, int *cmd, int *ch)
{
int command = -1;
int char_for_insertion = -1;
static long key_map[128] =
{XK_BackSpace, CK_BackSpace, XK_Delete, CK_Delete, XK_Return, CK_Enter, XK_Page_Up, CK_Page_Up,
XK_Page_Down, CK_Page_Down, XK_Left, CK_Left, XK_Right, CK_Right, XK_Up, CK_Up, XK_Down, CK_Down,
XK_Home, CK_Home, XK_End, CK_End, XK_Tab, CK_Tab, XK_Undo, CK_Undo, XK_Insert, CK_Toggle_Insert,
XK_F3, CK_Mark, XK_F5, CK_Copy, XK_F6, CK_Move, XK_F8, CK_Remove, XK_F2, CK_Save, XK_F12, CK_Save_As,
XK_F10, CK_Exit, XK_Escape, CK_Cancel, XK_F9, CK_Menu,
XK_F4, CK_Replace, XK_F4, CK_Replace_Again, XK_F17, CK_Find_Again, XK_F7, CK_Find, XK_F15, CK_Insert_File,
XK_F12, CK_Save_As, XK_F15, CK_Insert_File, XK_F14, CK_Replace_Again, XK_F13, CK_Run_Another, 0, 0};
static long key_pad_map[10] =
{XK_Insert, XK_End, XK_Down, XK_Page_Down, XK_Left,
XK_Down, XK_Right, XK_Home, XK_Up, XK_Page_Up};
#define DEFAULT_NUM_LOCK 1
static int num_lock = DEFAULT_NUM_LOCK;
static int raw = 0;
static int compose = 0;
static int decimal = 0;
static int hex = 0;
int i = 0;
int h;
if (compose) {
if (mod_type_key (x_key)) {
goto fin;
} else {
int c;
compose = 0;
c = get_international_character (x_key);
if (c == 1) {
get_international_character (0);
goto fin;
} else if (c) {
char_for_insertion = c;
goto fin;
}
goto fin;
}
}
if (option_international_characters) {
if (x_key >= ' ' && x_key <= '~') {
extern int compose_key_pressed;
if (compose_key_pressed) {
int c;
c = my_lower_case (x_key);
c = get_international_character ((x_state & ShiftMask) ?
((c >= 'a' && c <= 'z') ? c + 'A' - 'a' : c)
: c);
if (c == 1) {
compose = 1;
goto fin;
}
compose = 0;
if (c)
char_for_insertion = c;
else
goto fin;
}
}
}
if (x_key <= 0 || mod_type_key (x_key))
goto fin;
if (raw) {
if (!x_state) {
if (strchr ("0123456789abcdefh", x_key)) {
char u[2] =
{0, 0};
if (raw == 3) {
if (x_key == 'h') {
char_for_insertion = hex;
raw = 0;
goto fin;
} else {
if (x_key > '9') {
raw = 0;
goto fin;
}
}
}
decimal += (x_key - '0') * ((int) ("d\n\001")[raw - 1]);
u[0] = x_key;
hex += (strcspn ("0123456789abcdef", u) << (4 * (2 - raw)));
if (raw == 3) {
char_for_insertion = decimal;
raw = 0;
goto fin;
}
raw++;
goto fin;
}
}
if (raw > 1) {
raw = 0;
goto fin;
}
raw = 0;
if (x_key == XK_Return)
char_for_insertion = '\n';
else
char_for_insertion = x_key;
if (x_state & ControlMask)
char_for_insertion &= 31;
if (x_state & (MyAltMask))
char_for_insertion |= 128;
goto fin;
}
if (user_defined_key_function)
if ((h = (*(user_defined_key_function)) (x_state, x_keycode, x_key))) {
command = h;
goto fin;
}
if ((x_state & MyAltMask)) {
switch ((int) x_key) {
case XK_Left:
case XK_KP_Left:
command = CK_Delete_Word_Left;
goto fin;
case XK_Right:
case XK_KP_Right:
command = CK_Delete_Word_Right;
goto fin;
case XK_l:
case XK_L:
command = CK_Goto;
goto fin;
case XK_Insert:
case XK_KP_Insert:
command = CK_Selection_History;
goto fin;
case XK_Up:
case XK_KP_Up:
command = CK_Scroll_Up;
goto fin;
case XK_Down:
case XK_KP_Down:
command = CK_Scroll_Down;
goto fin;
case XK_Delete:
case XK_KP_Delete:
command = CK_Delete_To_Line_End;
goto fin;
case XK_BackSpace:
command = CK_Delete_To_Line_Begin;
goto fin;
case XK_m:
case XK_M:
command = CK_Mail;
goto fin;
case XK_x:
case XK_X:
command = CK_Save_And_Quit;
goto fin;
case XK_p:
case XK_P:
command = CK_Paragraph_Format;
goto fin;
case XK_F6:
command = CK_Maximise;
goto fin;
}
}
if ((x_state & MyAltMask) && (x_state & ShiftMask)) {
switch ((int) x_key) {
case XK_Up:
case XK_KP_Up:
command = CK_Scroll_Up_Highlight;
goto fin;
case XK_Down:
case XK_KP_Down:
command = CK_Scroll_Down_Highlight;
goto fin;
}
}
if (!(x_state & MyAltMask)) {
if ((x_key == XK_a || x_key == XK_A) && (x_state & ControlMask)) {
command = CK_Macro (CKeySymMod (CRawkeyQuery (0, 0, 0, " Execute Macro ", " Press macro hotkey: ")));
if (command == CK_Macro (0))
command = -1;
goto fin;
}
if (x_key == XK_Num_Lock && option_interpret_numlock) {
num_lock = 1 - num_lock;
goto fin;
}
switch ((int) x_key) {
case XK_KP_Home:
x_key = XK_Home;
break;
case XK_KP_End:
x_key = XK_End;
break;
case XK_KP_Page_Up:
x_key = XK_Page_Up;
break;
case XK_KP_Page_Down:
x_key = XK_Page_Down;
break;
case XK_KP_Up:
x_key = XK_Up;
break;
case XK_KP_Down:
x_key = XK_Down;
break;
case XK_KP_Left:
x_key = XK_Left;
break;
case XK_KP_Right:
x_key = XK_Right;
break;
case XK_KP_Insert:
x_key = XK_Insert;
break;
case XK_KP_Delete:
x_key = XK_Delete;
break;
case XK_KP_Enter:
x_key = XK_Return;
break;
case XK_KP_Add:
x_key = XK_plus;
break;
case XK_KP_Subtract:
x_key = XK_minus;
break;
}
/* first translate the key-pad */
if (num_lock) {
if (x_key >= XK_R1 && x_key <= XK_R9) {
x_key = key_pad_map[x_key - XK_R1 + 1];
} else if (x_key >= XK_KP_0 && x_key <= XK_KP_9) {
x_key = key_pad_map[x_key - XK_KP_0];
} else if (x_key == XK_KP_Decimal) {
x_key = XK_Delete;
}
} else {
if (x_key >= XK_KP_0 && x_key <= XK_KP_9) {
x_key += XK_0 - XK_KP_0;
}
if (x_key == XK_KP_Decimal) {
x_key = XK_period;
}
}
if ((x_state & ShiftMask) && (x_state & ControlMask)) {
switch ((int) x_key) {
case XK_Page_Up:
command = CK_Beginning_Of_Text_Highlight;
goto fin;
case XK_Page_Down:
command = CK_End_Of_Text_Highlight;
goto fin;
case XK_Left:
command = CK_Word_Left_Highlight;
goto fin;
case XK_Right:
command = CK_Word_Right_Highlight;
goto fin;
case XK_Up:
command = CK_Paragraph_Up_Highlight;
goto fin;
case XK_Down:
command = CK_Paragraph_Down_Highlight;
goto fin;
case XK_Home:
command = CK_Begin_Page_Highlight;
goto fin;
case XK_End:
command = CK_End_Page_Highlight;
goto fin;
}
}
if ((x_state & ShiftMask) && !(x_state & ControlMask)) {
switch ((int) x_key) {
case XK_Page_Up:
command = CK_Page_Up_Highlight;
goto fin;
case XK_Page_Down:
command = CK_Page_Down_Highlight;
goto fin;
case XK_Left:
command = CK_Left_Highlight;
goto fin;
case XK_Right:
command = CK_Right_Highlight;
goto fin;
case XK_Up:
command = CK_Up_Highlight;
goto fin;
case XK_Down:
command = CK_Down_Highlight;
goto fin;
case XK_Home:
command = CK_Home_Highlight;
goto fin;
case XK_End:
command = CK_End_Highlight;
goto fin;
case XK_Insert:
command = CK_XPaste;
goto fin;
case XK_Delete:
command = CK_XCut;
goto fin;
case XK_Return:
command = CK_Return;
goto fin;
/* this parallel F12, F19, F15, and F17 for some systems */
case XK_F2:
command = CK_Save_As;
goto fin;
case XK_F5:
command = CK_Insert_File;
goto fin;
case XK_F7:
command = CK_Find_Again;
goto fin;
case XK_F4:
command = CK_Replace_Again;
goto fin;
case XK_F3:
command = CK_Run_Another;
goto fin;
}
}
/* things that need a control key */
if (x_state & ControlMask) {
switch ((int) x_key) {
case XK_F1:
command = CK_Man_Page;
goto fin;
case XK_U:
case XK_u:
case XK_BackSpace:
command = CK_Undo;
goto fin;
case XK_Page_Up:
command = CK_Beginning_Of_Text;
goto fin;
case XK_Page_Down:
command = CK_End_Of_Text;
goto fin;
case XK_Up:
command = CK_Paragraph_Up;
goto fin;
case XK_Down:
command = CK_Paragraph_Down;
goto fin;
case XK_Left:
command = CK_Word_Left;
goto fin;
case XK_Right:
command = CK_Word_Right;
goto fin;
case XK_Home:
command = CK_Begin_Page;
goto fin;
case XK_End:
command = CK_End_Page;
goto fin;
case XK_N:
case XK_n:
command = CK_New;
goto fin;
case XK_O:
case XK_o:
command = CK_Load;
goto fin;
case XK_D:
case XK_d:
command = CK_Date;
goto fin;
case XK_S:
case XK_s:
command = CK_Save;
goto fin;
case XK_Q:
case XK_q:
raw = 1;
decimal = 0;
hex = 0;
goto fin;
case XK_F:
case XK_f:
command = CK_Save_Block;
goto fin;
case XK_F5:
case XK_F15:
command = CK_Insert_File;
goto fin;
case XK_Insert:
command = CK_XStore;
goto fin;
case XK_y:
case XK_Y:
command = CK_Delete_Line;
goto fin;
case XK_Delete:
command = CK_Remove;
goto fin;
case XK_F2:
command = CK_Save_Desktop;
goto fin;
case XK_F3:
command = CK_New_Window;
goto fin;
case XK_F6:
command = CK_Cycle;
goto fin;
case XK_F10:
command = CK_Check_Save_And_Quit;
goto fin;
case XK_Tab:
case XK_KP_Tab:
command = CK_Complete;
goto fin;
case XK_b:
case XK_B:
command = CK_Column_Mark;
goto fin;
case XK_l:
case XK_L:
command = CK_Refresh;
goto fin;
}
}
/* an ordinary ascii character or international character */
if (!(x_state & MyAltMask)) {
if (!(x_state & ControlMask)) {
if ((x_key >= XK_space && x_key <= XK_asciitilde) || ((x_key >= 160 && x_key < 256) && option_international_characters)) {
char_for_insertion = x_key;
goto fin;
}
/* other commands */
if (!(x_state & ShiftMask)) {
i = 0;
while (key_map[i] != x_key && key_map[i])
i += 2;
command = key_map[i + 1];
if (command)
goto fin;
}
}
}
}
fin:
*cmd = command;
*ch = char_for_insertion;
if ((command == -1 || command == 0) && char_for_insertion == -1) /* unchanged, key has no function here */
return 0;
return 1;
}

2870
gtkedit/editcmd.c Normal file

File diff suppressed because it is too large Load Diff

140
gtkedit/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
gtkedit/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
gtkedit/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
gtkedit/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
gtkedit/editwidget.c Normal file

File diff suppressed because it is too large Load Diff

31
gtkedit/global.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef __CW_GLOBAL_H
#define __CW_GLOBAL_H
/* Some X servers use a different mask for the Alt key: */
#define MyAltMask Mod1Mask
/* #define MyAltMask Mod2Mask */
/* #define MyAltMask Mod3Mask */
/* #define MyAltMask Mod4Mask */
/* #define MyAltMask Mod5Mask */
/* Some servers don't have a right Control key: */
#define MyComposeKey XK_Control_R
/* #define MyComposeKey XK_Shift_L */
/* #define MyComposeKey XK_Shift_R */
/* #define MyComposeKey XK_Meta_L */
/* #define MyComposeKey XK_Meta_R */
/* #define MyComposeKey XK_Alt_L */
/* #define MyComposeKey XK_Alt_R */
/* #define MyComposeKey XK_Super_L */
/* #define MyComposeKey XK_Super_R */
/* #define MyComposeKey XK_Hyper_L */
/* #define MyComposeKey XK_Hyper_R */
/* u_32bit_t should be four bytes */
#define u_32bit_t unsigned int
#define word unsigned short
#define byte unsigned char
#endif /* __CW_GLOBAL_H */

1212
gtkedit/gtkedit.c Normal file

File diff suppressed because it is too large Load Diff

113
gtkedit/gtkedit.h Normal file
View File

@ -0,0 +1,113 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GTK_EDIT_H__
#define __GTK_EDIT_H__
#include <gdk/gdk.h>
#include <gtk/gtkadjustment.h>
#include <gtk/gtkeditable.h>
#include <gtkedit/mousemark.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define GTK_EDIT(obj) GTK_CHECK_CAST (obj, gtk_edit_get_type (), GtkEdit)
#define GTK_EDIT_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_edit_get_type (), GtkEditClass)
#define GTK_IS_EDIT(obj) GTK_CHECK_TYPE (obj, gtk_edit_get_type ())
typedef struct _GtkEdit GtkEdit;
typedef struct _GtkEditClass GtkEditClass;
struct _GtkEdit
{
GtkEditable editable;
GdkWindow *text_area;
GtkWidget *menubar, *status;
GtkAdjustment *hadj;
gint last_hadj_value;
GtkAdjustment *vadj;
gint last_vadj_value;
GdkGC *gc;
GdkColor color[256];
int color_last_pixel;
void (*destroy_me) (void *);
void *destroy_me_user_data;
struct editor_widget *editor;
struct mouse_funcs *funcs;
gulong options;
gint timer;
};
struct _GtkEditClass
{
GtkEditableClass parent_class;
};
guint gtk_edit_get_type (void);
GtkWidget* gtk_edit_new (GtkAdjustment *hadj,
GtkAdjustment *vadj);
void gtk_edit_set_editable (GtkEdit *text,
gint editable);
void gtk_edit_set_word_wrap (GtkEdit *text,
gint word_wrap);
void gtk_edit_set_adjustments (GtkEdit *text,
GtkAdjustment *hadj,
GtkAdjustment *vadj);
void gtk_edit_set_point (GtkEdit *text,
guint index);
guint gtk_edit_get_point (GtkEdit *text);
guint gtk_edit_get_length (GtkEdit *text);
void gtk_edit_freeze (GtkEdit *text);
void gtk_edit_thaw (GtkEdit *text);
void gtk_edit_insert (GtkEdit *text,
GdkFont *font,
GdkColor *fore,
GdkColor *back,
const char *chars,
gint length);
gint gtk_edit_backward_delete (GtkEdit *text,
guint nchars);
gint gtk_edit_forward_delete (GtkEdit *text,
guint nchars);
char *gtk_edit_dialog_get_load_file (guchar * directory, guchar * file, guchar * heading);
char *gtk_edit_dialog_get_save_file (guchar * directory, guchar * file, guchar * heading);
void gtk_edit_dialog_error (guchar * heading, char *fmt,...);
void gtk_edit_dialog_message (guchar * heading, char *fmt,...);
int gtk_edit_dialog_query (guchar * heading, guchar * first,...);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GTK_EDIT_H__ */

479
gtkedit/gtkeditkey.c Normal file
View File

@ -0,0 +1,479 @@
#include <config.h>
#include "edit.h"
#include "editcmddef.h"
#include <gdk/gdkkeysyms.h>
int mod_type_key (guint x);
int (*user_defined_key_function) (unsigned int state, unsigned int keycode, KeySym keysym) = 0;
int option_interpret_numlock = 0;
void edit_set_user_key_function (int (*user_def_key_func) (unsigned int, unsigned int, KeySym))
{
user_defined_key_function = user_def_key_func;
}
int edit_translate_key (unsigned int x_keycode, long x_key, int x_state, int *cmd, int *ch)
{
int command = -1;
int char_for_insertion = -1;
static long key_map[128] =
{GDK_BackSpace, CK_BackSpace, GDK_Delete, CK_Delete, GDK_Return, CK_Enter, GDK_Page_Up, CK_Page_Up,
GDK_Page_Down, CK_Page_Down, GDK_Left, CK_Left, GDK_Right, CK_Right, GDK_Up, CK_Up, GDK_Down, CK_Down,
GDK_Home, CK_Home, GDK_End, CK_End, GDK_Tab, CK_Tab, GDK_Undo, CK_Undo, GDK_Insert, CK_Toggle_Insert,
GDK_F3, CK_Mark, GDK_F5, CK_Copy, GDK_F6, CK_Move, GDK_F8, CK_Remove, GDK_F2, CK_Save, GDK_F12, CK_Save_As,
GDK_F10, CK_Exit, GDK_Escape, CK_Cancel, GDK_F9, CK_Menu,
GDK_F4, CK_Replace, GDK_F4, CK_Replace_Again, GDK_F17, CK_Find_Again, GDK_F7, CK_Find, GDK_F15, CK_Insert_File, 0, 0};
static long key_pad_map[10] =
{GDK_Insert, GDK_End, GDK_Down, GDK_Page_Down, GDK_Left,
GDK_Down, GDK_Right, GDK_Home, GDK_Up, GDK_Page_Up};
#define DEFAULT_NUM_LOCK 1
static int num_lock = DEFAULT_NUM_LOCK;
static int raw = 0;
static int compose = 0;
static int decimal = 0;
static int hex = 0;
int i = 0;
int h;
if (compose) {
if (mod_type_key (x_key)) {
goto fin;
} else {
int c;
compose = 0;
c = get_international_character (x_key);
if (c == 1) {
/* *** */
#if 0
get_international_character (0);
#endif
goto fin;
} else if (c) {
char_for_insertion = c;
goto fin;
}
goto fin;
}
}
if (option_international_characters) {
if (x_key >= ' ' && x_key <= '~') {
/* *** */
#if 0
extern int compose_key_pressed;
#endif
if (compose_key_pressed) {
int c;
c = (x_key >= 'A' && x_key <= 'Z') ? x_key - 'A' + 'a' : x_key;
c = get_international_character ((x_state & ShiftMask) ?
((c >= 'a' && c <= 'z') ? c + 'A' - 'a' : c)
: c);
if (c == 1) {
compose = 1;
goto fin;
}
compose = 0;
if (c)
char_for_insertion = c;
else
goto fin;
}
}
}
if (x_key <= 0 || mod_type_key (x_key))
goto fin;
if (raw) {
if (!x_state) {
if (strchr ("0123456789abcdefh", x_key)) {
char u[2] =
{0, 0};
if (raw == 3) {
if (x_key == 'h') {
char_for_insertion = hex;
raw = 0;
goto fin;
} else {
if (x_key > '9') {
raw = 0;
goto fin;
}
}
}
decimal += (x_key - '0') * ((int) ("d\n\001")[raw - 1]);
u[0] = x_key;
hex += (strcspn ("0123456789abcdef", u) << (4 * (2 - raw)));
if (raw == 3) {
char_for_insertion = decimal;
raw = 0;
goto fin;
}
raw++;
goto fin;
}
}
if (raw > 1) {
raw = 0;
goto fin;
}
raw = 0;
if (x_key == GDK_Return)
char_for_insertion = '\n';
else
char_for_insertion = x_key;
if (x_state & ControlMask)
char_for_insertion &= 31;
if (x_state & (MyAltMask))
char_for_insertion |= 128;
goto fin;
}
if (user_defined_key_function)
if ((h = (*(user_defined_key_function)) (x_state, x_keycode, x_key))) {
command = h;
goto fin;
}
if ((x_state & MyAltMask)) {
switch ((int) x_key) {
case GDK_Left:
case GDK_KP_Left:
command = CK_Delete_Word_Left;
goto fin;
case GDK_Right:
case GDK_KP_Right:
command = CK_Delete_Word_Right;
goto fin;
case GDK_l:
case GDK_L:
command = CK_Goto;
goto fin;
case GDK_Insert:
case GDK_KP_Insert:
command = CK_Selection_History;
goto fin;
case GDK_Up:
case GDK_KP_Up:
command = CK_Scroll_Up;
goto fin;
case GDK_Down:
case GDK_KP_Down:
command = CK_Scroll_Down;
goto fin;
case GDK_Delete:
case GDK_KP_Delete:
command = CK_Delete_To_Line_End;
goto fin;
case GDK_BackSpace:
command = CK_Delete_To_Line_Begin;
goto fin;
case GDK_m:
case GDK_M:
command = CK_Mail;
goto fin;
case GDK_x:
case GDK_X:
command = CK_Save_And_Quit;
goto fin;
case GDK_p:
case GDK_P:
command = CK_Paragraph_Format;
goto fin;
}
}
if ((x_state & MyAltMask) && (x_state & ShiftMask)) {
switch ((int) x_key) {
case GDK_Up:
case GDK_KP_Up:
command = CK_Scroll_Up_Highlight;
goto fin;
case GDK_Down:
case GDK_KP_Down:
command = CK_Scroll_Down_Highlight;
goto fin;
}
}
if (!(x_state & MyAltMask)) {
if ((x_key == GDK_a || x_key == GDK_A) && (x_state & ControlMask)) {
#if 0
command = CK_Macro (CKeySymMod (CRawkeyQuery (0, 0, 0, " Execute Macro ", " Press macro hotkey: ")));
if (command == CK_Macro (0))
#endif
command = -1;
goto fin;
}
if (x_key == GDK_Num_Lock && option_interpret_numlock) {
num_lock = 1 - num_lock;
goto fin;
}
switch ((int) x_key) {
case GDK_KP_Home:
x_key = GDK_Home;
break;
case GDK_KP_End:
x_key = GDK_End;
break;
case GDK_KP_Page_Up:
x_key = GDK_Page_Up;
break;
case GDK_KP_Page_Down:
x_key = GDK_Page_Down;
break;
case GDK_KP_Up:
x_key = GDK_Up;
break;
case GDK_KP_Down:
x_key = GDK_Down;
break;
case GDK_KP_Left:
x_key = GDK_Left;
break;
case GDK_KP_Right:
x_key = GDK_Right;
break;
case GDK_KP_Insert:
x_key = GDK_Insert;
break;
case GDK_KP_Delete:
x_key = GDK_Delete;
break;
case GDK_KP_Enter:
x_key = GDK_Return;
break;
case GDK_KP_Add:
x_key = GDK_plus;
break;
case GDK_KP_Subtract:
x_key = GDK_minus;
break;
}
/* first translate the key-pad */
if (num_lock) {
if (x_key >= GDK_R1 && x_key <= GDK_R9) {
x_key = key_pad_map[x_key - GDK_R1 + 1];
} else if (x_key >= GDK_KP_0 && x_key <= GDK_KP_9) {
x_key = key_pad_map[x_key - GDK_KP_0];
} else if (x_key == GDK_KP_Decimal) {
x_key = GDK_Delete;
}
} else {
if (x_key >= GDK_KP_0 && x_key <= GDK_KP_9) {
x_key += GDK_0 - GDK_KP_0;
}
if (x_key == GDK_KP_Decimal) {
x_key = GDK_period;
}
}
if ((x_state & ShiftMask) && (x_state & ControlMask)) {
switch ((int) x_key) {
case GDK_Page_Up:
command = CK_Beginning_Of_Text_Highlight;
goto fin;
case GDK_Page_Down:
command = CK_End_Of_Text_Highlight;
goto fin;
case GDK_Left:
command = CK_Word_Left_Highlight;
goto fin;
case GDK_Right:
command = CK_Word_Right_Highlight;
goto fin;
case GDK_Up:
command = CK_Paragraph_Up_Highlight;
goto fin;
case GDK_Down:
command = CK_Paragraph_Down_Highlight;
goto fin;
case GDK_Home:
command = CK_Begin_Page_Highlight;
goto fin;
case GDK_End:
command = CK_End_Page_Highlight;
goto fin;
}
}
if ((x_state & ShiftMask) && !(x_state & ControlMask)) {
switch ((int) x_key) {
case GDK_Page_Up:
command = CK_Page_Up_Highlight;
goto fin;
case GDK_Page_Down:
command = CK_Page_Down_Highlight;
goto fin;
case GDK_Left:
command = CK_Left_Highlight;
goto fin;
case GDK_Right:
command = CK_Right_Highlight;
goto fin;
case GDK_Up:
command = CK_Up_Highlight;
goto fin;
case GDK_Down:
command = CK_Down_Highlight;
goto fin;
case GDK_Home:
command = CK_Home_Highlight;
goto fin;
case GDK_End:
command = CK_End_Highlight;
goto fin;
case GDK_Insert:
command = CK_XPaste;
goto fin;
case GDK_Delete:
command = CK_XCut;
goto fin;
case GDK_Return:
command = CK_Return;
goto fin;
/* this parallel F12, F19, F15, and F17 for some systems */
case GDK_F2:
command = CK_Save_As;
goto fin;
case GDK_F5:
command = CK_Insert_File;
goto fin;
case GDK_F7:
command = CK_Find_Again;
goto fin;
case GDK_F4:
command = CK_Replace_Again;
goto fin;
case GDK_F3:
command = CK_Run_Another;
goto fin;
}
}
/* things that need a control key */
if (x_state & ControlMask) {
switch ((int) x_key) {
case GDK_F1:
command = CK_Man_Page;
goto fin;
case GDK_U:
case GDK_u:
case GDK_BackSpace:
command = CK_Undo;
goto fin;
case GDK_Page_Up:
command = CK_Beginning_Of_Text;
goto fin;
case GDK_Page_Down:
command = CK_End_Of_Text;
goto fin;
case GDK_Up:
command = CK_Paragraph_Up;
goto fin;
case GDK_Down:
command = CK_Paragraph_Down;
goto fin;
case GDK_Left:
command = CK_Word_Left;
goto fin;
case GDK_Right:
command = CK_Word_Right;
goto fin;
case GDK_Home:
command = CK_Begin_Page;
goto fin;
case GDK_End:
command = CK_End_Page;
goto fin;
case GDK_N:
case GDK_n:
command = CK_New;
goto fin;
case GDK_O:
case GDK_o:
command = CK_Load;
goto fin;
case GDK_D:
case GDK_d:
command = CK_Date;
goto fin;
case GDK_Q:
case GDK_q:
raw = 1;
decimal = 0;
hex = 0;
goto fin;
case GDK_F:
case GDK_f:
command = CK_Save_Block;
goto fin;
case GDK_F5:
case GDK_F15:
command = CK_Insert_File;
goto fin;
case GDK_Insert:
command = CK_XStore;
goto fin;
case GDK_y:
case GDK_Y:
command = CK_Delete_Line;
goto fin;
case GDK_Delete:
command = CK_Remove;
goto fin;
case GDK_F2:
command = CK_Save_Desktop;
goto fin;
case GDK_F3:
command = CK_New_Window;
goto fin;
case GDK_F6:
command = CK_Cycle;
goto fin;
case GDK_F10:
command = CK_Check_Save_And_Quit;
goto fin;
case GDK_Tab:
case GDK_KP_Tab:
command = CK_Complete;
goto fin;
case GDK_b:
command = CK_Column_Mark;
goto fin;
}
}
/* an ordinary ascii character or international character */
if (!(x_state & MyAltMask)) {
if (!(x_state & ControlMask)) {
if ((x_key >= GDK_space && x_key <= GDK_asciitilde) || ((x_key >= 160 && x_key < 256) && option_international_characters)) {
char_for_insertion = x_key;
goto fin;
}
/* other commands */
if (!(x_state & ShiftMask)) {
i = 0;
while (key_map[i] != x_key && key_map[i])
i += 2;
command = key_map[i + 1];
if (command)
goto fin;
}
}
}
}
fin:
*cmd = command;
*ch = char_for_insertion;
if ((command == -1 || command == 0) && char_for_insertion == -1) /* unchanged, key has no function here */
return 0;
return 1;
}

182
gtkedit/libgettext.h Normal file
View File

@ -0,0 +1,182 @@
/* Message catalogs for internationalization.
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* Because on some systems (e.g. Solaris) we sometimes have to include
the systems libintl.h as well as this file we have more complex
include protection above. But the systems header might perhaps also
define _LIBINTL_H and therefore we have to protect the definition here. */
#if !defined (_LIBINTL_H) || !defined (_LIBGETTEXT_H)
#if !defined (_LIBINTL_H)
# define _LIBINTL_H 1
#endif
#define _LIBGETTEXT_H 1
/* We define an additional symbol to signal that we use the GNU
implementation of gettext. */
#define __USE_GNU_GETTEXT 1
#include <sys/types.h>
#if HAVE_LOCALE_H
# include <locale.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* @@ end of prolog @@ */
#ifndef PARAMS
# if __STDC__
# define PARAMS(args) args
# else
# define PARAMS(args) ()
# endif
#endif
#ifndef NULL
# if !defined __cplusplus || defined __GNUC__
# define NULL ((void *) 0)
# else
# define NULL (0)
# endif
#endif
#if !HAVE_LC_MESSAGES
/* This value determines the behaviour of the gettext() and dgettext()
function. But some system does not have this defined. Define it
to a default value. */
# define LC_MESSAGES (-1)
#endif
/* Declarations for gettext-using-catgets interface. Derived from
Jim Meyering's libintl.h. */
struct _msg_ent
{
const char *_msg;
int _msg_number;
};
#if HAVE_CATGETS
/* These two variables are defined in the automatically by po-to-tbl.sed
generated file `cat-id-tbl.c'. */
extern const struct _msg_ent _msg_tbl[];
extern int _msg_tbl_length;
#endif
/* For automatical extraction of messages sometimes no real
translation is needed. Instead the string itself is the result. */
#define gettext_noop(Str) (Str)
/* Look up MSGID in the current default message catalog for the current
LC_MESSAGES locale. If not found, returns MSGID itself (the default
text). */
extern char *gettext PARAMS ((const char *__msgid));
extern char *gettext__ PARAMS ((const char *__msgid));
/* Look up MSGID in the DOMAINNAME message catalog for the current
LC_MESSAGES locale. */
extern char *dgettext PARAMS ((const char *__domainname, const char *__msgid));
extern char *dgettext__ PARAMS ((const char *__domainname,
const char *__msgid));
/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
locale. */
extern char *dcgettext PARAMS ((const char *__domainname, const char *__msgid,
int __category));
extern char *dcgettext__ PARAMS ((const char *__domainname,
const char *__msgid, int __category));
/* Set the current default message catalog to DOMAINNAME.
If DOMAINNAME is null, return the current default.
If DOMAINNAME is "", reset to the default of "messages". */
extern char *textdomain PARAMS ((const char *__domainname));
extern char *textdomain__ PARAMS ((const char *__domainname));
/* Specify that the DOMAINNAME message catalog will be found
in DIRNAME rather than in the system locale data base. */
extern char *bindtextdomain PARAMS ((const char *__domainname,
const char *__dirname));
extern char *bindtextdomain__ PARAMS ((const char *__domainname,
const char *__dirname));
#if ENABLE_NLS
/* Solaris 2.3 has the gettext function but dcgettext is missing.
So we omit this optimization for Solaris 2.3. BTW, Solaris 2.4
has dcgettext. */
# if !HAVE_CATGETS && (!HAVE_GETTEXT || HAVE_DCGETTEXT)
# define gettext(Msgid) \
dgettext (NULL, Msgid)
# define dgettext(Domainname, Msgid) \
dcgettext (Domainname, Msgid, LC_MESSAGES)
# if defined __GNUC__ && __GNUC__ == 2 && __GNUC_MINOR__ >= 7
/* This global variable is defined in loadmsgcat.c. We need a sign,
whether a new catalog was loaded, which can be associated with all
translations. */
extern int _nl_msg_cat_cntr;
# define dcgettext(Domainname, Msgid, Category) \
(__extension__ \
({ \
char *__result; \
if (__builtin_constant_p (Msgid)) \
{ \
static char *__translation__; \
static int __catalog_counter__; \
if (! __translation__ || __catalog_counter__ != _nl_msg_cat_cntr) \
{ \
__translation__ = \
dcgettext__ (Domainname, Msgid, Category); \
__catalog_counter__ = _nl_msg_cat_cntr; \
} \
__result = __translation__; \
} \
else \
__result = dcgettext__ (Domainname, Msgid, Category); \
__result; \
}))
# endif
# endif
#else
# define gettext(Msgid) (Msgid)
# define dgettext(Domainname, Msgid) (Msgid)
# define dcgettext(Domainname, Msgid, Category) (Msgid)
# define textdomain(Domainname) while (0) /* nothing */
# define bindtextdomain(Domainname, Dirname) while (0) /* nothing */
#endif
/* @@ begin of epilog @@ */
#ifdef __cplusplus
}
#endif
#endif

39
gtkedit/lkeysym.h Normal file
View File

@ -0,0 +1,39 @@
/* lkeysym.h - for any undefined keys
Copyright (C) 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 <X11/keysym.h>
#ifndef XK_Page_Up
#define XK_Page_Up XK_Prior
#endif
#ifndef XK_Page_Down
#define XK_Page_Down XK_Next
#endif
#ifndef XK_KP_Page_Up
#define XK_KP_Page_Up XK_KP_Prior
#endif
#ifndef XK_KP_Page_Down
#define XK_KP_Page_Down XK_KP_Next
#endif
#ifndef XK_ISO_Left_Tab
#define XK_ISO_Left_Tab 0xFE20
#endif

487
gtkedit/mousemark.c Normal file
View File

@ -0,0 +1,487 @@
#include <config.h>
#ifndef GTK
#include "coolwidget.h"
#endif
int just_dropped_something = 0;
#include "edit.h"
#include <X11/Xmd.h>
#include <X11/Xatom.h>
#ifndef GTK
#include "app_glob.c"
#include "coollocal.h"
#endif
#include "editcmddef.h"
#include "xdnd.h"
#ifdef GTK
#include "src/mad.h"
#else
#include "mad.h"
#endif
#ifndef HAVE_DND
Atom **xdnd_typelist_send = 0;
Atom **xdnd_typelist_receive = 0;
#define NUM_SIMPLE_TYPES 10
/* each entry is listed in order of what we would like the RECEIVE */
static char *mime_type_send[NUM_SIMPLE_TYPES][10] =
{
{0}, /* DndUnknown 0 */
{0}, /* DndRawData 1 */
{"url/url", "text/plain", 0}, /* DndFile 2 (input widget) */
{"text/plain", "text/uri-list", 0}, /* DndFiles 3 (fielded text box) */
{"text/plain", "application/octet-stream", 0}, /* DndText 4 (editor widget) */
/* don't use these: */
{0}, /* DndLink 5 */
{0}, /* DndDir 6 */
{0}, /* DndExe 7 */
{0}, /* DndURL 8 */
{0}, /* DndMIME 9 */
};
static char *mime_type_recieve[NUM_SIMPLE_TYPES][10] =
{
{0}, /* DndUnknown 0 */
{0}, /* DndRawData 1 */
{"url/url", "text/uri-list", "text/plain", 0}, /* DndFile 2 (input widget) */
{0}, /* DndFiles 3 */
{"url/url", "text/plain", "application/octet-stream", "text/uri-list", 0}, /* DndText 4 (editor widget) */
/* don't use these: */
{0}, /* DndLink 5 */
{0}, /* DndDir 6 */
{0}, /* DndExe 7 */
{0}, /* DndURL 8 */
{0}, /* DndMIME 9 */
};
#ifndef GTK
static char dnd_directory[MAX_PATH_LEN] = "/";
char *striptrailing (char *s, int c)
{
int i;
i = strlen (s) - 1;
while (i >= 0) {
if (s[i] == c) {
s[i--] = 0;
continue;
}
break;
}
return s;
}
/* return the prepending directory (see CDndFileList() below) */
char *CDndDirectory (void)
{
return dnd_directory;
}
/*
Sets the directory, must be a null terminated complete path.
Strips trailing slashes.
*/
void CSetDndDirectory (char *d)
{
if (!d)
return;
strcpy (dnd_directory, d);
striptrailing (dnd_directory, '/');
if (*dnd_directory)
return;
*dnd_directory = '/';
}
/*
Takes a newline seperated list of files,
returns a newline seperated list of complete `file:' path names
by prepending dnd_directory to each file name.
returns 0 if no files in list.
result must always be free'd.
returns l as the total length of data.
returns num_files as the number of files in the list.
Alters t
*/
char *CDndFileList (char *t, int *l, int *num_files)
{
char *p, *q, *r, *result;
int i, len, done = 0;
/* strip leading newlines */
while (*t == '\n')
t++;
/* strip trailing newlines */
striptrailing (t, '\n');
if (!*t)
return 0;
/* count files */
for (i = 1, p = t; *p; p++)
if (*p == '\n')
i++;
*num_files = i;
len = (unsigned long) p - (unsigned long) t;
result = CMalloc ((strlen (dnd_directory) + strlen ("file:") + 2) * i + len + 2);
r = result;
p = t;
while (!done) {
q = strchr (p, '\n');
if (q)
*q = 0;
else
done = 1;
strcpy (r, "file:");
if (*p != '/') {
strcat (r, dnd_directory);
strcat (r, "/");
}
strcat (r, p);
r += strlen (r);
*r++ = '\n';
p = ++q;
}
*r = 0;
*l = (unsigned long) r - (unsigned long) result;
return result;
}
Window get_focus_border_widget (void);
static void widget_apply_leave (DndClass * dnd, Window widgets_window)
{
CWidget *w;
w = CWidgetOfWindow (widgets_window);
if (get_focus_border_widget () == widgets_window)
destroy_focus_border ();
if (w)
CExpose (w->ident);
}
static int widget_insert_drop (DndClass * dnd, unsigned char *data, int length, int remaining, Window into, Window from, Atom type)
{
CWidget *w;
char *p;
w = CWidgetOfWindow (into);
if (!w)
return 1;
if (*w->funcs->insert_drop) {
int r;
Window child_return;
int xd, yd;
if (!dnd->user_hook1)
dnd->user_hook2 = dnd->user_hook1 = CMalloc (length + remaining + 1);
memcpy (dnd->user_hook2, data, length);
p = dnd->user_hook2;
p += length; /* avoids ansi warning */
dnd->user_hook2 = p;
if (remaining)
return 0;
XTranslateCoordinates (CDisplay, CRoot, into, dnd->x, dnd->y, &xd, &yd, &child_return);
r = (*w->funcs->insert_drop) (w->funcs->data, from, dnd->user_hook1, (unsigned long) dnd->user_hook2 - (unsigned long) dnd->user_hook1, xd, yd, type, dnd->supported_action);
free (dnd->user_hook1);
dnd->user_hook1 = dnd->user_hook2 = 0;
if (get_focus_border_widget () == into)
destroy_focus_border ();
CExpose (w->ident);
return r;
}
return 1;
}
static int array_length (Atom * a)
{
int n;
for (n = 0; a[n]; n++);
return n;
}
static int widget_apply_position (DndClass * dnd, Window widgets_window, Window from,
Atom action, int x, int y, Time t, Atom * typelist,
int *want_position, Atom * supported_action, Atom * desired_type,
XRectangle * rectangle)
{
CWidget *w;
Window child_return;
int xt, yt;
int xd, yd;
long click;
int i, j;
Atom result = 0;
w = CWidgetOfWindow (widgets_window);
if (!w)
return 0;
/* input widgets can't drop to themselves :-( */
if (w->kind == C_TEXTINPUT_WIDGET && widgets_window == from)
return 0;
/* look up mime types from my own list of supported types */
for (j = 0; xdnd_typelist_receive[w->funcs->types][j]; j++) {
for (i = 0; typelist[i]; i++) {
if (typelist[i] == xdnd_typelist_receive[w->funcs->types][j]) {
result = typelist[i];
break;
}
}
if (result)
break;
}
if (!result && w->funcs->mime_majors) {
char **names_return;
names_return = CMalloc ((array_length (typelist) + 1) * sizeof (char *));
if (XGetAtomNames (CDisplay, typelist, array_length (typelist), names_return)) {
for (i = 0; i < array_length (typelist); i++) {
for (j = 0; w->funcs->mime_majors[j]; j++) {
if (!strncmp (w->funcs->mime_majors[j], names_return[i], strlen (w->funcs->mime_majors[j]))) {
result = typelist[i];
break;
}
}
if (result)
break;
}
}
}
/* not supported, so return false */
if (!result)
return 0;
XTranslateCoordinates (CDisplay, CRoot, widgets_window, x, y, &xd, &yd, &child_return);
if (xd < 0 || yd < 0 || xd >= CWidthOf (w) || yd >= CHeightOf (w))
return 0;
if (w->funcs->xy && w->funcs->cp && w->funcs->move) {
(*w->funcs->xy) (xd, yd, &xt, &yt);
click = (*w->funcs->cp) (w->funcs->data, xt, yt);
if (w->funcs->fin_mark)
(*w->funcs->fin_mark) (w->funcs->data);
if (w->funcs->move)
(*w->funcs->move) (w->funcs->data, click, yt);
if (w->funcs->redraw)
(*w->funcs->redraw) (w->funcs->data, click);
}
/* we want more position messages */
*want_position = 1;
/* we only support copy and move */
if (action == dnd->XdndActionMove) {
*supported_action = dnd->XdndActionMove;
} else {
*supported_action = dnd->XdndActionCopy;
}
*desired_type = result;
rectangle->x = x;
rectangle->y = y;
rectangle->width = rectangle->height = 0;
if (get_focus_border_widget () != widgets_window) {
destroy_focus_border ();
create_focus_border (w, 4);
}
CExpose (w->ident);
return 1;
}
static void widget_get_data (DndClass * dnd, Window window, unsigned char **data, int *length, Atom type)
{
int t = DndText;
long start_mark, end_mark;
CWidget *w;
w = CWidgetOfWindow (window);
if (!w) {
return;
}
if (!w->funcs)
return;
if ((*w->funcs->marks) (w->funcs->data, &start_mark, &end_mark)) {
return;
}
if (type == XInternAtom (dnd->display, "url/url", False))
t = DndFile;
else if (type == XInternAtom (dnd->display, "text/uri-list", False))
t = DndFiles;
*data = (unsigned char *) (*w->funcs->get_block) (w->funcs->data, start_mark, end_mark, &t, length);
}
static int widget_exists (DndClass * dnd, Window window)
{
return (CWidgetOfWindow (window) != 0);
}
static void handle_expose_events (DndClass * dnd, XEvent * xevent)
{
if (!xevent->xexpose.count)
render_focus_border (xevent->xexpose.window);
return;
}
void mouse_init (void)
{
CDndClass->handle_expose_events = handle_expose_events;
CDndClass->widget_insert_drop = widget_insert_drop;
CDndClass->widget_exists = widget_exists;
CDndClass->widget_apply_position = widget_apply_position;
CDndClass->widget_get_data = widget_get_data;
CDndClass->widget_apply_leave = widget_apply_leave;
CDndClass->options |= XDND_OPTION_NO_HYSTERESIS;
CDndClass->user_hook1 = CDndClass->user_hook2 = 0;
if (!xdnd_typelist_receive) {
int i;
xdnd_typelist_receive = malloc ((NUM_SIMPLE_TYPES + 1) * sizeof (Atom *));
xdnd_typelist_send = malloc ((NUM_SIMPLE_TYPES + 1) * sizeof (Atom *));
for (i = 0; i < NUM_SIMPLE_TYPES; i++) {
int j;
xdnd_typelist_receive[i] = CMalloc (32 * sizeof (Atom));
for (j = 0; mime_type_recieve[i][j]; j++) {
xdnd_typelist_receive[i][j] = XInternAtom (CDndClass->display, mime_type_recieve[i][j], False);
xdnd_typelist_receive[i][j + 1] = 0;
}
xdnd_typelist_receive[i + 1] = 0;
xdnd_typelist_send[i] = CMalloc (32 * sizeof (Atom));
for (j = 0; mime_type_send[i][j]; j++) {
xdnd_typelist_send[i][j] = XInternAtom (CDndClass->display, mime_type_send[i][j], False);
xdnd_typelist_send[i][j + 1] = 0;
}
xdnd_typelist_send[i + 1] = 0;
}
}
}
void mouse_shut (void)
{
if (xdnd_typelist_receive) {
int i;
for (i = 0; xdnd_typelist_send[i]; i++)
free (xdnd_typelist_send[i]);
free (xdnd_typelist_send);
xdnd_typelist_send = 0;
for (i = 0; xdnd_typelist_receive[i]; i++)
free (xdnd_typelist_receive[i]);
free (xdnd_typelist_receive);
xdnd_typelist_receive = 0;
}
}
#endif /* !GTK */
struct mouse_funcs *mouse_funcs_new (void *data, struct mouse_funcs *m)
{
struct mouse_funcs *p;
p = CMalloc (sizeof (*m));
memcpy (p, m, sizeof (*m));
p->data = data;
return p;
}
#endif /* HAVE_DND */
void mouse_mark (XEvent * event, int double_click, struct mouse_funcs *funcs)
{
void *data;
static unsigned long win_press = 0;
static int state = 0; /* 0 = button up, 1 = button pressed, 2 = button pressed and dragging */
static int x_last, y_last;
long click;
data = funcs->data;
if (event->type == ButtonPress) {
long start_mark, end_mark;
state = 1;
win_press = (unsigned long) event->xbutton.window;
(*funcs->xy) (event->xbutton.x, event->xbutton.y, &x_last, &y_last);
click = (*funcs->cp) (data, x_last, y_last);
if (!(*funcs->marks) (data, &start_mark, &end_mark)) {
if ((*funcs->range) (data, start_mark, end_mark, click)) { /* if clicked on highlighted text */
unsigned char *t;
int l;
#ifdef HAVE_DND
int type;
t = (unsigned char *) (*funcs->get_block) (data, start_mark, end_mark, &type, &l);
if (t) {
just_dropped_something = 1;
CDrag (event->xbutton.window, type, t, l, event->xbutton.button == Button1 ? Button1Mask : 0);
free (t);
}
#else
#ifndef GTK
/* this is just to get the type which depends on the number of lines selected for
the fileselection box: */
t = (unsigned char *) (*funcs->get_block) (data, start_mark, end_mark, &funcs->types, &l);
if (t) {
free (t);
if (xdnd_drag (CDndClass, event->xbutton.window,
event->xbutton.button == Button1 ? CDndClass->XdndActionCopy : CDndClass->XdndActionMove,
xdnd_typelist_send[funcs->types]) == CDndClass->XdndActionMove) {
if (funcs->delete_block)
(*funcs->delete_block) (data);
}
}
#endif
#endif
if (funcs->fin_mark)
(*funcs->fin_mark) (data);
return;
}
}
just_dropped_something = 0;
if (funcs->fin_mark)
(*funcs->fin_mark) (data);
(*funcs->move) (data, click, y_last);
if (double_click && funcs->dclick) {
(*funcs->dclick) (data, event);
state = 0;
}
if (funcs->redraw)
(*funcs->redraw) (data, click);
} else if (event->type == ButtonRelease && state > 0 && win_press == (unsigned long) event->xbutton.window && !double_click) {
int x, y;
long start_mark, end_mark;
(*funcs->xy) (event->xbutton.x, event->xbutton.y, &x, &y);
click = (*funcs->cp) (data, x, y);
(*funcs->move) (data, click, y);
if (state == 2)
goto unhighlight;
if (!(*funcs->marks) (data, &start_mark, &end_mark)) {
if ((*funcs->range) (data, start_mark, end_mark, click)) { /* if clicked on highlighted text */
unhighlight:
if (funcs->release_mark)
(*funcs->release_mark) (data, event);
}
}
state = 0;
if (funcs->redraw)
(*funcs->redraw) (data, click);
} else if (event->type == MotionNotify && state > 0 && win_press == (unsigned long) event->xbutton.window && event->xbutton.state) {
int x, y;
if (!event->xmotion.state)
return;
(*funcs->xy) (event->xbutton.x, event->xbutton.y, &x, &y);
if (x == x_last && y == y_last && state == 1)
return;
click = (*funcs->cp) (data, x, y);
if (state == 1) {
state = 2;
if (funcs->move_mark)
(funcs->move_mark) (data);
}
(*funcs->move) (data, click, y);
if (funcs->motion)
(*funcs->motion) (data, click);
if (funcs->redraw)
(*funcs->redraw) (data, click);
}
}

51
gtkedit/mousemark.h Normal file
View File

@ -0,0 +1,51 @@
#ifndef _MOUSE_MARK
#define _MOUSE_MARK
/* mouse_mark.h */
struct mouse_funcs {
void *data;
void (*xy) (int, int, int *, int *);
/* (row, pixel-x-pos) from click pos (x,y) */
long (*cp) (void *, int, int); /* get buffer offset from (row, pixel-x-pos) */
int (*marks) (void *, long *, long *);
/* get mark start and end */
int (*range) (void *, long, long, long);
/* is click between marks? */
void (*fin_mark) (void *); /* set marks to not-moving mode (optional) */
void (*move_mark) (void *); /* set marks to moving mode (optional) */
void (*release_mark) (void *, XEvent *);
/* set marks when button is release.
possibly sets selection owner (could be
same as fin_mark) (optional) */
char * (*get_block) (void *, long, long, int *, int *);
/* return block from between marks,
result is free'd by mouse_mark
int *, int * is Dnd type, length */
void (*move) (void *, long, int); /* move cursor, int is row if needed */
void (*motion) (void *, long); /* move second mark position */
void (*dclick) (void *, XEvent *); /* called on double click (optional) */
void (*redraw) (void *, long);/* called before exit, passing mouse
pos in buffer (optional) */
int (*insert_drop) (void *, Window, unsigned char *, int, int, int, Atom, Atom);
void (*delete_block) (void *);
/* this is one of the old dnd types. these are our preference
for drag between cooledits */
int types;
/* anything else that the widget can recieve eg {"text", "video"} */
char **mime_majors;
};
void mouse_mark (XEvent * event, int double_click, struct mouse_funcs *funcs);
struct mouse_funcs *mouse_funcs_new (void *data, struct mouse_funcs *m);
void mouse_shut (void);
void mouse_init (void);
extern Atom **xdnd_typelist_receive;
extern Atom **xdnd_typelist_send;
#endif

192
gtkedit/my_string.h Normal file
View File

@ -0,0 +1,192 @@
/* my_string.h - compatability for any system
Copyright (C) 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.
*/
#ifndef _MY_STRING_H
#define _MY_STRING_H
#include "global.h"
#include <config.h>
#include <stdlib.h>
#include <sys/types.h>
#include <ctype.h>
#include <stdarg.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_LOCALE_H
# include <locale.h>
#endif
#include "libgettext.h"
#define _(String) gettext (String)
#ifdef gettext_noop
# define N_(String) gettext_noop (String)
#else
# define N_(String) (String)
#endif
#define MAX_PATH_LEN 1024
/* string include, hopefully works across all unixes */
#ifndef INHIBIT_STRING_HEADER
# if defined (HAVE_STRING_H) || defined (STDC_HEADERS) || defined (_LIBC)
# include <string.h>
# else
# include <strings.h>
# endif
#endif
#if defined(__STRICT_ANSI__) && defined(__GNUC__)
int strcasecmp (const char *p1, const char *p2);
int strncasecmp (const char *p1, const char *p2, size_t n);
char *strdup (const char *s);
char *getwd (char *buf);
char *tempnam (const char *dir, const char *pfx);
int lstat(const char *file_name, struct stat *buf);
int kill(pid_t pid, int sig);
#endif
#ifndef STDC_HEADERS
# ifndef HAVE_STRCHR
# define strchr index
# define strrchr rindex
# endif
size_t strnlen (const char *s, size_t count);
# ifndef HAVE_MEMCPY
# define memcpy(d, s, n) bcopy ((s), (d), (n))
# endif
# ifndef HAVE_MEMCMP
int memcmp (const void *cs, const void *ct, size_t count);
# endif
# ifndef HAVE_MEMCHR
void *memchr (const void *s, int c, size_t n);
# endif
#ifndef HAVE_STRCASECMP
# ifndef __STRICT_ANSI__
int strcasecmp (const char *p1, const char *p2);
# endif
#endif
#ifndef HAVE_STRNCASECMP
# ifndef __STRICT_ANSI__
int strncasecmp (const char *p1, const char *p2, size_t n);
# endif
#endif
# ifndef HAVE_STRDUP
# ifndef __STRICT_ANSI__
char *strdup (const char *s);
# endif
# endif
#ifndef HAVE_MEMMOVE
void *memmove (void *dest, const void *src, size_t n);
# endif
# ifndef HAVE_MEMSET
void *memset (void *dest, int c, size_t n);
# endif
# ifndef HAVE_STRSPN
size_t strspn (const char *s, const char *accept);
# endif
# ifndef HAVE_STRSTR
char *strstr (const char *s1, const char *s2);
# endif
# ifndef HAVE_VPRINTF
int vsprintf (char *buf, const char *fmt, va_list args);
# endif
#endif
#ifndef S_IFMT
#define S_IFMT 0170000
#endif
#ifndef S_IFDIR
#define S_IFDIR 0040000
#endif
#ifndef S_IFCHR
#define S_IFCHR 0020000
#endif
#ifndef S_IFBLK
#define S_IFBLK 0060000
#endif
#ifndef S_IFREG
#define S_IFREG 0100000
#endif
#ifndef S_IFIFO
#define S_IFIFO 0010000
#endif
#ifndef S_IFLNK
#define S_IFLNK 0120000
#endif
#ifndef S_IFSOCK
#define S_IFSOCK 0140000
#endif
#ifndef S_ISUID
#define S_ISUID 04000
#endif
#ifndef S_ISGID
#define S_ISGID 02000
#endif
#ifndef S_ISVTX
#define S_ISVTX 01000
#endif
#ifndef S_IREAD
#define S_IREAD 0400
#endif
#ifndef S_IWRITE
#define S_IWRITE 0200
#endif
#ifndef S_IEXEC
#define S_IEXEC 0100
#endif
#ifndef S_ISTYPE
#define S_ISTYPE(mode, mask) (((mode) & S_IFMT) == (mask))
#endif
#ifndef S_ISDIR
#define S_ISDIR(mode) S_ISTYPE((mode), S_IFDIR)
#endif
#ifndef S_ISCHR
#define S_ISCHR(mode) S_ISTYPE((mode), S_IFCHR)
#endif
#ifndef S_ISBLK
#define S_ISBLK(mode) S_ISTYPE((mode), S_IFBLK)
#endif
#ifndef S_ISREG
#define S_ISREG(mode) S_ISTYPE((mode), S_IFREG)
#endif
#ifndef S_ISFIFO
#define S_ISFIFO(mode) S_ISTYPE((mode), S_IFIFO)
#endif
#ifndef S_ISLNK
#define S_ISLNK(mode) S_ISTYPE((mode), S_IFLNK)
#endif
#ifndef S_ISSOCK
#define S_ISSOCK(mode) S_ISTYPE((mode), S_IFSOCK)
#endif
#ifndef S_IRWXU
#define S_IRWXU (__S_IREAD|__S_IWRITE|__S_IEXEC)
#endif
#endif /* _MY_STRING_H */

881
gtkedit/propfont.c Normal file
View File

@ -0,0 +1,881 @@
/* propfont.c - editor text drawing for proportional fonts.
Copyright (C) 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"
/* this file definatively relies on int being 32 bits or more */
int option_long_whitespace = 0;
#define MAX_LINE_LEN 1024
#define CACHE_WIDTH 256
#define CACHE_HEIGHT 128
struct cache_line {
int x0, x1;
cache_type data[CACHE_WIDTH];
};
extern unsigned char per_char[256];
/* background colors: marked is refers to mouse highlighting, highlighted refers to a found string. */
extern unsigned long edit_abnormal_color, edit_marked_abnormal_color;
extern unsigned long edit_highlighted_color, edit_marked_color;
extern unsigned long edit_normal_background_color;
/* foreground colors */
extern unsigned long edit_normal_foreground_color, edit_bold_color;
extern unsigned long edit_italic_color;
/* cursor color */
extern unsigned long edit_cursor_color;
extern int EditExposeRedraw;
extern int EditClear;
void set_style_color (
#ifdef GTK
Window win,
#endif
cache_type s, unsigned long *fg, unsigned long *bg)
{
int fgp, bgp;
fgp = (s & 0xFF000000UL) >> 24;
if (fgp < 255)
*fg = color_palette (fgp);
else
*fg = edit_normal_foreground_color;
bgp = (s & 0x00FF0000) >> 16;
if (bgp < 255)
*bg = color_palette (bgp);
else
*bg = edit_normal_background_color;
if (!(s & 0xFFFFFF00UL)) /* check this first as an optimization */
return;
if (s & (MOD_ABNORMAL * 256)) {
*bg = edit_abnormal_color;
if (s & (MOD_MARKED * 256))
*bg = edit_marked_abnormal_color;
} else if (s & (MOD_HIGHLIGHTED * 256)) {
*bg = edit_highlighted_color;
} else if (s & (MOD_MARKED * 256)) {
*bg = edit_marked_color;
}
if (s & (MOD_BOLD * 256))
*fg = edit_bold_color;
if (s & (MOD_ITALIC * 256))
*fg = edit_italic_color;
if (s & (MOD_INVERSE * 256)) {
unsigned long t;
t = *fg;
*fg = *bg;
*bg = t;
if (*bg == COLOR_BLACK)
*bg = color_palette (1);
}
}
#ifdef GTK
#define set_style_color(s,f,b) set_style_color(win,s,f,b)
#endif
int tab_width = 1;
static inline int next_tab_pos (int x)
{
return x += tab_width - x % tab_width;
}
/* For Ryan: */
/* converts a possibly unprintable character to a string,
returning the string's width in pixels, t must have space for 4 chars */
static inline int convert_to_long_printable (int c, unsigned char *t)
{
if (c > ' ') {
if (c <= '~') {
t[0] = c;
t[1] = 0;
return per_char[c];
}
if (c >= 160)
if (option_international_characters) {
t[0] = c;
t[1] = 0;
return per_char[c];
}
if (c > '~') {
t[0] = ("0123456789ABCDEF")[c >> 4];
t[1] = ("0123456789ABCDEF")[c & 0xF];
t[2] = 'h';
t[3] = 0;
return per_char[t[0]] + per_char[t[1]] + per_char[t[2]];
}
}
if (c == ' ') {
if (option_long_whitespace) {
t[0] = ' ';
t[1] = ' ';
t[2] = 0;
return per_char[' '] + per_char[' '];
} else {
t[0] = ' ';
t[1] = 0;
return per_char[' '];
}
}
t[0] = '^';
t[1] = c + '@';
t[2] = 0;
return per_char[t[0]] + per_char[t[1]];
}
/* same as above but just gets the length */
static inline int width_of_long_printable (int c)
{
if (c > ' ') {
if (c <= '~')
return per_char[c];
if (c >= 160)
if (option_international_characters)
return per_char[c];
if (c > '~')
return per_char[(unsigned char) ("0123456789ABCDEF")[c >> 4]] + per_char[(unsigned char) ("0123456789ABCDEF")[c & 0xF]] + per_char['h'];
}
if (c == ' ') {
if (option_long_whitespace)
return per_char[' '] + per_char[' '];
else
return per_char[' '];
}
return per_char['^'] + per_char[c + '@'];
}
int edit_width_of_long_printable (int c)
{
return width_of_long_printable (c);
}
/* returns x pixel pos of char at offset *q with x not more than l */
int calc_text_pos (WEdit * edit, long b, long *q, int l)
{
int x = 0, c, xn;
for (;;) {
c = edit_get_byte (edit, b);
switch (c) {
case '\n':
*q = b;
if (x > edit->max_column)
edit->max_column = x;
return x;
case '\t':
xn = next_tab_pos (x);
break;
default:
xn = x + width_of_long_printable (c);
break;
}
if (xn > l)
break;
x = xn;
b++;
}
*q = b;
if (x > edit->max_column)
edit->max_column = x;
return x;
}
/* calcs pixel length of the line beginning at b up to upto */
int calc_text_len (WEdit * edit, long b, long upto)
{
int x = 0, c;
for (;;) {
if (b == upto) {
if (x > edit->max_column)
edit->max_column = x;
return x;
}
c = edit_get_byte (edit, b);
switch (c) {
case '\n':{
if (x > edit->max_column)
edit->max_column = x;
return x;
}
case '\t':
x = next_tab_pos (x);
break;
default:
x += width_of_long_printable (c);
break;
}
b++;
}
}
/* If pixels is zero this returns the count of pixels from current to upto. */
/* If upto is zero returns index of pixels across from current. */
long edit_move_forward3 (WEdit * edit, long current, int pixels, long upto)
{
if (upto) {
return calc_text_len (edit, current, upto);
} else if (pixels) {
long q;
calc_text_pos (edit, current, &q, pixels);
return q;
}
return current;
}
extern int column_highlighting;
/* gets the characters style (eg marked, highlighted) from its position in the edit buffer */
static inline cache_type get_style (WEdit * edit, long q, int c, long m1, long m2, int x)
{
cache_type s = 0;
unsigned int fg, bg;
if (q == edit->curs1)
s |= MOD_CURSOR * 256;
if (q >= m1 && q < m2) {
if (column_highlighting) {
if ((x >= edit->column1 && x < edit->column2)
|| (x >= edit->column2 && x < edit->column1))
s |= MOD_INVERSE * 256;
} else {
s |= MOD_MARKED * 256;
}
}
if (q == edit->bracket)
s |= MOD_BOLD * 256;
if (q >= edit->found_start && q < edit->found_start + edit->found_len)
s |= MOD_HIGHLIGHTED * 256;
if (option_international_characters) {
if ((c < ' ' || (c > '~' && c < 160)) && c != '\t' && c != '\n')
s |= MOD_ABNORMAL * 256;
} else {
if ((c < ' ' || c > '~') && c != '\t' && c != '\n')
s |= MOD_ABNORMAL * 256;
}
edit_get_syntax_color (edit, q, (int *) &fg, (int *) &bg);
return s | ((fg & 0xFF) << 24) | ((bg & 0xFF) << 16);
}
void convert_text (WEdit * edit, long q, cache_type *p, int x, int x_max)
{
int c;
cache_type s;
long m1, m2;
unsigned char *r, text[4];
eval_marks (edit, &m1, &m2);
for (;;) {
c = edit_get_byte (edit, q);
*p = get_style (edit, q, c, m1, m2, x);
switch (c) {
case '\n':
*p++ |= ' ';
*p = 0;
if (x > edit->max_column)
edit->max_column = x;
return;
case '\t':
if (fixed_font) {
int t;
t = next_tab_pos (x);
t = min (t, x_max);
s = *p;
while (x < t) {
x += per_char[' '];
*p++ = s | ' ';
}
} else {
*p++ |= '\t';
x = next_tab_pos (x);
}
break;
default:
x += convert_to_long_printable (c, text);
r = text;
s = *p;
*p++ = s | *r++;
if (*r) {
*p++ = s | *r++;
if (*r)
*p++ = s | *r++;
}
break;
}
if (x >= x_max)
break;
q++;
}
if (x > edit->max_column)
edit->max_column = x;
*p = 0;
}
void edit_set_cursor (Window win, int x, int y, int bg, int fg, int width, char t)
{
#ifdef GTK
gdk_gc_set_foreground (win->gc, &win->color[18]);
gdk_draw_rectangle (win->text_area, win->gc, 0, x, y + FONT_OVERHEAD, width - 1, FONT_HEIGHT - 1);
#else
CSetColor (edit_cursor_color);
CLine (win, x, y + FONT_OVERHEAD,
x, y + FONT_HEIGHT - 1); /* non focussed cursor form */
CLine (win, x + 1, y + FONT_OVERHEAD,
x + width - 1, y + FONT_OVERHEAD);
set_cursor_position (win, x, y, width, FONT_HEIGHT, CURSOR_TYPE_EDITOR, t, bg, fg); /* widget library's flashing cursor */
#endif
}
static inline int next_tab (int x, int scroll_right)
{
return next_tab_pos (x - scroll_right - EDIT_TEXT_HORIZONTAL_OFFSET) - x + scroll_right + EDIT_TEXT_HORIZONTAL_OFFSET;
}
int draw_tab (Window win, int x, int y, cache_type s, int scroll_right)
{
int l;
#ifdef GTK
GdkColor fg, bg;
#else
unsigned long fg, bg;
#endif
l = next_tab (x, scroll_right);
#ifdef GTK
set_style_color (s, &fg.pixel, &bg.pixel);
gdk_gc_set_foreground (win->gc, &bg);
gdk_draw_rectangle (win->text_area, win->gc, 1, x, y + FONT_OVERHEAD, l, FONT_HEIGHT);
/* if we printed a cursor: */
if (s & (MOD_CURSOR * 256))
edit_set_cursor (win, x, y, bg.pixel, fg.pixel, per_char[' '], ' ');
#else
set_style_color (s, &fg, &bg);
CSetColor (bg);
CRectangle (win, x, y + FONT_OVERHEAD, l, FONT_HEIGHT);
/* if we printed a cursor: */
if (s & (MOD_CURSOR * 256))
edit_set_cursor (win, x, y, bg, fg, per_char[' '], ' ');
#endif
return x + l;
}
#ifdef GTK
#include <gdk/gdk.h>
#endif
static inline void draw_space (Window win, int x, int y, cache_type s, int l)
{
#ifdef GTK
GdkColor fg, bg;
#else
unsigned long fg, bg;
#endif
#ifdef GTK
set_style_color (s, &fg.pixel, &bg.pixel);
gdk_gc_set_foreground (win->gc, &bg);
gdk_draw_rectangle (win->text_area, win->gc, 1, x, y + FONT_OVERHEAD, l, FONT_HEIGHT);
#else
set_style_color (s, &fg, &bg);
CSetColor (bg);
CRectangle (win, x, y + FONT_OVERHEAD, l, FONT_HEIGHT);
/* if we printed a cursor: */
if (s & (MOD_CURSOR * 256))
edit_set_cursor (win, x, y, bg, fg, per_char[' '], ' ');
#endif
}
#ifdef GTK
void
gdk_draw_image_text (GdkDrawable *drawable,
GdkFont *font,
GdkGC *gc,
gint x,
gint y,
const gchar *text,
gint text_length)
{
GdkWindowPrivate *drawable_private;
GdkFontPrivate *font_private;
GdkGCPrivate *gc_private;
g_return_if_fail (drawable != NULL);
g_return_if_fail (font != NULL);
g_return_if_fail (gc != NULL);
g_return_if_fail (text != NULL);
drawable_private = (GdkWindowPrivate*) drawable;
if (drawable_private->destroyed)
return;
gc_private = (GdkGCPrivate*) gc;
font_private = (GdkFontPrivate*) font;
if (font->type == GDK_FONT_FONT)
{
XFontStruct *xfont = (XFontStruct *) font_private->xfont;
XSetFont(drawable_private->xdisplay, gc_private->xgc, xfont->fid);
if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
{
XDrawImageString (drawable_private->xdisplay, drawable_private->xwindow,
gc_private->xgc, x, y, text, text_length);
}
else
{
XDrawImageString16 (drawable_private->xdisplay, drawable_private->xwindow,
gc_private->xgc, x, y, (XChar2b *) text, text_length / 2);
}
}
else if (font->type == GDK_FONT_FONTSET)
{
XFontSet fontset = (XFontSet) font_private->xfont;
XmbDrawImageString (drawable_private->xdisplay, drawable_private->xwindow,
fontset, gc_private->xgc, x, y, text, text_length);
}
else
g_error("undefined font type\n");
}
#endif
int draw_string (Window win, int x, int y, cache_type s, unsigned char *text, int length)
{
#ifdef GTK
GdkColor fg, bg;
#else
unsigned long fg, bg;
#endif
#ifdef GTK
set_style_color (s, &fg.pixel, &bg.pixel);
gdk_gc_set_background (win->gc, &bg);
gdk_gc_set_foreground (win->gc, &fg);
gdk_draw_image_text (win->text_area, GTK_WIDGET (win)->style->font, win->gc, x + FONT_OFFSET_X, y + FONT_OFFSET_Y, text, length);
#else
set_style_color (s, &fg, &bg);
CSetBackgroundColor (bg);
CSetColor (fg);
CImageString (win, x + FONT_OFFSET_X, y + FONT_OFFSET_Y, (char *) text, length);
#endif
/* if we printed a cursor: */
#ifdef GTK
if (s & (MOD_CURSOR * 256))
edit_set_cursor (win, x, y, bg.pixel, fg.pixel, per_char[*text], *text);
return x + gdk_text_width (GTK_WIDGET (win)->style->font, text, length);
#else
if (s & (MOD_CURSOR * 256))
edit_set_cursor (win, x, y, bg, fg, per_char[*text], *text);
return x + CTextWidth (win, (char *) text, length);
#endif
}
#define STYLE_DIFF (cache[i] != line[i] \
|| ((cache[i] | line[i]) & (MOD_CURSOR * 256)) \
|| !cache[i] || !line[i] \
)
int get_ignore_length (cache_type *cache, cache_type *line)
{
int i;
for (i = 0; i < CACHE_WIDTH; i++) {
if (STYLE_DIFF)
return i;
}
return CACHE_WIDTH;
}
static inline size_t lwstrnlen (const cache_type *s, size_t count)
{
const cache_type *sc;
for (sc = s; count-- && *sc != 0; ++sc);
return sc - s;
}
static inline size_t lwstrlen (const cache_type *s)
{
const cache_type *sc;
for (sc = s; *sc != 0; ++sc);
return sc - s;
}
int get_ignore_trailer (cache_type *cache, cache_type *line, int length)
{
int i;
int cache_len, line_len;
cache_len = lwstrnlen (cache, CACHE_WIDTH);
line_len = lwstrlen (line);
if (line_len > cache_len)
for (i = line_len - 1; i >= cache_len && i >= length; i--)
if (line[i] != ' ')
return i + 1;
for (i = cache_len - 1; i > length; i--)
if (STYLE_DIFF)
return i + 1;
return length + 1;
}
/* erases trailing bit of old line if a new line is printed over a longer old line */
void cover_trail (Window win, int x_new, int x_old, int y)
{
if (x_new < EDIT_TEXT_HORIZONTAL_OFFSET)
x_new = EDIT_TEXT_HORIZONTAL_OFFSET;
if (x_new >= x_old) /* no need to print */
return;
#ifdef GTK
gdk_gc_set_foreground (win->gc, &win->color[1]);
gdk_draw_rectangle (win->text_area, win->gc, 1, x_new, y + FONT_OVERHEAD, x_old - x_new, FONT_HEIGHT);
#else
CSetColor (edit_normal_background_color);
/* CSetColor (color_palette(12)); */
CRectangle (win, x_new, y + FONT_OVERHEAD, x_old - x_new, FONT_HEIGHT);
#endif
}
cache_type mode_spacing = 0;
#define NOT_VALID (-2000000000)
void edit_draw_proportional (void *data,
void (*converttext) (void *, long, cache_type *, int, int),
int calctextpos (void *, long, long *, int),
int scroll_right,
Window win,
int x_max,
long b,
int row,
int y,
int x_offset,
int tabwidth)
{
static struct cache_line lines[CACHE_HEIGHT];
static Window last = 0;
cache_type style, line[MAX_LINE_LEN], *p;
unsigned char text[128];
int x0, x, ignore_text = 0, ignore_trailer = 2000000000, j, i;
long q;
tab_width = tabwidth;
if (option_long_whitespace)
tab_width = tabwidth *= 2;
x_max -= 3;
/* if its not the same window, reset the screen rememberer */
if (last != win) {
last = win;
for (i = 0; i < CACHE_HEIGHT; i++) {
lines[i].x0 = NOT_VALID;
lines[i].x1 = x_max;
}
}
/* get point to start drawing */
x0 = (*calctextpos) (data, b, &q, -scroll_right + x_offset);
/* q contains the offset in the edit buffer */
/* translate this line into printable characters with a style (=color) high byte */
(*converttext) (data, q, line, x0, x_max - scroll_right - EDIT_TEXT_HORIZONTAL_OFFSET);
/* adjust for the horizontal scroll and border */
x0 += scroll_right + EDIT_TEXT_HORIZONTAL_OFFSET;
x = x0;
/* is some of the line identical to that already printed so that we can ignore it? */
if (!EditExposeRedraw) {
if (lines[row].x0 == x0 && row < CACHE_HEIGHT) { /* i.e. also && lines[row].x0 != NOT_VALID */
ignore_text = get_ignore_length (lines[row].data, line);
if (fixed_font)
ignore_trailer = get_ignore_trailer (lines[row].data, line, ignore_text);
}
}
p = line;
j = 0;
while (*p) {
if (mode_spacing) {
if ((*p & 0x80) && (*p & mode_spacing)) {
#ifdef STILL_TO_BE_SUPPORTED
x += edit_insert_pixmap (win, x, y, *p & 0x7F);
/* the pixmap will be clipped, if it's taller than the
current font, else centred top to bottom */
#endif
p++;
continue;
}
goto do_text;
}
if ((*p & 0xFF) == '\t') {
j++;
if (j > ignore_text && j < ignore_trailer + 1)
x = draw_tab (win, x, y, *p, scroll_right);
else
x += next_tab (x, scroll_right);
p++;
} else {
do_text:
style = *p & 0xFFFFFF00UL;
i = 0;
do {
text[i++] = (unsigned char) *p++;
j++;
if (j == ignore_text || j == ignore_trailer)
break;
} while (i < 128 && *p && style == (*p & 0xFFFFFF00UL) && (*p & 0xFF) != '\t');
if (style & mode_spacing) {
int k;
for (k = 0; k < i; k++) {
draw_space (win, x, y, (0xFFFFFF00UL - mode_spacing) & style, text[k]);
x += text[k];
}
} else {
if (j > ignore_text && j < ignore_trailer + 1)
x = draw_string (win, x, y, style, text, i);
else
#ifdef GTK
x += gdk_text_width (GTK_WIDGET(win)->style->font, text, i);
#else
x += CTextWidth (win, (char *) text, i);
#endif
}
}
}
x = min (x, x_max);
if (!EditExposeRedraw || EditClear)
cover_trail (win, x, lines[row].x1, y);
memcpy (&(lines[row].data[ignore_text]),
&(line[ignore_text]),
(min (j, CACHE_WIDTH) - ignore_text) * sizeof (cache_type));
lines[row].data[min (j, CACHE_WIDTH)] = 0;
lines[row].x0 = x0;
lines[row].x1 = x;
if (EditExposeRedraw)
last = 0;
else
last = win;
}
void edit_draw_this_line_proportional (WEdit * edit, long b, int row, int start_column, int end_column)
{
int fg, bg;
if (row < 0 || row >= edit->num_widget_lines)
return;
if (row + edit->start_line > edit->total_lines)
b = 2000000000; /* force b out of range of the edit buffer for blanks lines */
if (end_column > CWidthOf (edit->widget))
end_column = CWidthOf (edit->widget);
edit_get_syntax_color (edit, b - 1, &fg, &bg);
edit_draw_proportional (edit,
(void (*) (void *, long, cache_type *, int, int)) convert_text,
(int (*) (void *, long, long *, int)) calc_text_pos,
edit->start_col, CWindowOf (edit->widget),
end_column, b, row, row * FONT_PIX_PER_LINE + EDIT_TEXT_VERTICAL_OFFSET,
EditExposeRedraw ? start_column : 0, per_char[' '] * TAB_SIZE);
}
/*********************************************************************************/
/* The remainder is for the text box widget */
/*********************************************************************************/
static inline int nroff_printable (int c)
{
return ((c >= ' ' && c <= '~') || c >= 160);
}
int calc_text_pos_str (unsigned char *text, long b, long *q, int l)
{
int x = 0, c = 0, xn = 0, d;
for (;;) {
d = c;
c = text[b];
switch (c) {
case '\0':
case '\n':
*q = b;
return x;
case '\t':
xn = next_tab_pos (x);
break;
case '\r':
break;
case '\b':
if (d)
xn = x - per_char[d];
break;
default:
if (!nroff_printable (c))
c = ' ';
xn = x + per_char[c];
break;
}
if (xn > l)
break;
x = xn;
b++;
}
*q = b;
return x;
}
int prop_font_strcolmove (unsigned char *str, int i, int column)
{
long q;
calc_text_pos_str (str, i, &q, column * FONT_MEAN_WIDTH);
return q;
}
#ifndef GTK
/* b is the beginning of the line. l is the length in pixels up to a point
on some character which is unknown. The character pos is returned in
*q and the characters pixel x pos from b is return'ed. */
int calc_text_pos2 (CWidget * w, long b, long *q, int l)
{
return calc_text_pos_str ((unsigned char *) w->text, b, q, l);
}
/* calcs pixel length of the line beginning at b up to upto */
int calc_text_len2 (CWidget *w, long b, long upto)
{
int x = 0, c = 0, d;
for (;;) {
if (b == upto)
return x;
d = c;
c = w->text[b];
switch (c) {
case '\n':
case '\0':
return x;
case '\t':
x = next_tab_pos (x);
break;
case '\r':
break;
case '\b':
if (d)
x -= per_char[d];
break;
default:
if (!nroff_printable (c))
c = ' ';
x += per_char[c];
break;
}
b++;
}
}
int highlight_this_line;
/* this is for the text widget (i.e. nroff formatting) */
void convert_text2 (CWidget * w, long q, cache_type *line, int x, int x_max)
{
int c = 0, d;
cache_type s, *p;
long m1, m2;
m1 = min (w->mark1, w->mark2);
m2 = max (w->mark1, w->mark2);
p = line;
*p = 0;
for (;;) {
d = c;
c = w->text[q];
*(p + 1) = 0;
*p |= 0xFFFF0000UL; /* default background colors */
if (highlight_this_line)
*p |= MOD_HIGHLIGHTED * 256;
if (q >= m1 && q < m2)
*p |= MOD_MARKED * 256;
switch (c) {
case '\0':
case '\n':
*p++ |= ' ';
if (highlight_this_line) {
q--;
x += per_char[' '];
} else
return;
break;
case '\t':
if (fixed_font) {
int i;
i = next_tab_pos (x) - x;
x += i;
s = *p;
while (i > 0) {
i -= per_char[' '];
*p++ = s | ' ';
*p = 0;
}
} else {
*p++ |= '\t';
x = next_tab_pos (x);
}
break;
case '\r':
break;
case '\b':
if (d) {
--p;
x -= per_char[d];
if (d == '_')
*p |= MOD_ITALIC * 256;
else
*p |= MOD_BOLD * 256;
}
break;
default:
if (!nroff_printable (c)) {
c = ' ';
*p |= MOD_ABNORMAL * 256;
}
x += per_char[c];
*p &= 0xFFFFFF00UL;
*p |= c;
p++;
break;
}
if (x > x_max)
break;
q++;
}
*p = 0;
}
#endif

2881
gtkedit/syntax.c Normal file

File diff suppressed because it is too large Load Diff

48
gtkedit/testtext.c Normal file
View File

@ -0,0 +1,48 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gtk/gtk.h"
#include "gdk/gdk.h"
#include "gdk/gdkx.h"
#include "gtkedit.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main (int argc, char *argv[])
{
static GtkWidget *window = NULL;
GtkWidget *edit;
int infile;
gtk_set_locale ();
gnome_init ("Hi there", NULL, argc, argv, 0, NULL);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_usize (window, 400, 400);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_widget_destroyed),
&window);
gtk_container_border_width (GTK_CONTAINER (window), 3);
edit = gtk_edit_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (window), edit);
gtk_widget_show (edit);
gtk_widget_realize (edit);
infile = open ("edit.c", O_RDONLY);
if (infile) {
char buffer[1024];
int nchars;
while (1) {
nchars = read (infile, buffer, 1024);
gtk_edit_insert (GTK_EDIT (edit), NULL, NULL,
NULL, buffer, nchars);
if (nchars < 1024)
break;
}
close (infile);
}
gtk_editable_set_position (edit, 0);
gtk_widget_show (window);
gtk_main ();
return 0;
}

350
gtkedit/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);
}

220
gtkedit/xdnd.h Normal file
View File

@ -0,0 +1,220 @@
/* xdnd.c, xdnd.h - C program library for handling the Xdnd protocol
* Copyright (C) 1998 Paul Sheer
* Permission is hereby granted to study, compile, copy, modify, publish,
* distribute and sell (the "Activities") the files xdnd.c and xdnd.h
* (the "Code") subject to the following conditions:
* 1. Modification of the Code is not done against the impetus of
* development of the Xdnd protocol via community involvement.
* 1.1 This means that all modifications to the Code must be
* revealed to the copyright holder, along with a clear
* explanation of the modifications.
* 1.2 All authors that use the Code in their application
* programs, must report such use to the copyright holder.
* 2. The Code must remain intact with this copyright notice.
* 3. The Code is provided without warranty.
* 4. In as far as there is positive intension on the part of
* the author/s and copyright holder, no liability will be held
* against them out of damages incidental or consequential to
* the Activities.
* Permission is limited to the Activities only.
* The copyright holder may be reached by email at <psheer@obsidian.co.za>
*/
#ifndef _X_DND_H
#define _X_DND_H
#ifdef __cplusplus
extern "C" {
#endif
#define XDND_VERSION 2
/* XdndEnter */
#define XDND_THREE 3
#define XDND_ENTER_SOURCE_WIN(e) ((e)->xclient.data.l[0])
#define XDND_ENTER_THREE_TYPES(e) (((e)->xclient.data.l[1] & 0x1UL) == 0)
#define XDND_ENTER_THREE_TYPES_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x1UL) | (((b) == 0) ? 0 : 0x1UL)
#define XDND_ENTER_VERSION(e) ((e)->xclient.data.l[1] >> 24)
#define XDND_ENTER_VERSION_SET(e,v) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~(0xFF << 24)) | ((v) << 24)
#define XDND_ENTER_TYPE(e,i) ((e)->xclient.data.l[2 + i]) /* i => (0, 1, 2) */
/* XdndPosition */
#define XDND_POSITION_SOURCE_WIN(e) ((e)->xclient.data.l[0])
#define XDND_POSITION_ROOT_X(e) ((e)->xclient.data.l[2] >> 16)
#define XDND_POSITION_ROOT_Y(e) ((e)->xclient.data.l[2] & 0xFFFFUL)
#define XDND_POSITION_ROOT_SET(e,x,y) (e)->xclient.data.l[2] = ((x) << 16) | ((y) & 0xFFFFUL)
#define XDND_POSITION_TIME(e) ((e)->xclient.data.l[3])
#define XDND_POSITION_ACTION(e) ((e)->xclient.data.l[4])
/* XdndStatus */
#define XDND_STATUS_TARGET_WIN(e) ((e)->xclient.data.l[0])
#define XDND_STATUS_WILL_ACCEPT(e) ((e)->xclient.data.l[1] & 0x1L)
#define XDND_STATUS_WILL_ACCEPT_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x1UL) | (((b) == 0) ? 0 : 0x1UL)
#define XDND_STATUS_WANT_POSITION(e) ((e)->xclient.data.l[1] & 0x2UL)
#define XDND_STATUS_WANT_POSITION_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x2UL) | (((b) == 0) ? 0 : 0x2UL)
#define XDND_STATUS_RECT_X(e) ((e)->xclient.data.l[2] >> 16)
#define XDND_STATUS_RECT_Y(e) ((e)->xclient.data.l[2] & 0xFFFFL)
#define XDND_STATUS_RECT_WIDTH(e) ((e)->xclient.data.l[3] >> 16)
#define XDND_STATUS_RECT_HEIGHT(e) ((e)->xclient.data.l[3] & 0xFFFFL)
#define XDND_STATUS_RECT_SET(e,x,y,w,h) {(e)->xclient.data.l[2] = ((x) << 16) | ((y) & 0xFFFFUL); (e)->xclient.data.l[3] = ((w) << 16) | ((h) & 0xFFFFUL); }
#define XDND_STATUS_ACTION(e) ((e)->xclient.data.l[4])
/* XdndLeave */
#define XDND_LEAVE_SOURCE_WIN(e) ((e)->xclient.data.l[0])
/* XdndDrop */
#define XDND_DROP_SOURCE_WIN(e) ((e)->xclient.data.l[0])
#define XDND_DROP_TIME(e) ((e)->xclient.data.l[2])
/* XdndFinished */
#define XDND_FINISHED_TARGET_WIN(e) ((e)->xclient.data.l[0])
struct _DndCursor {
int width, height;
int x, y;
unsigned char *image_data, *mask_data;
char *_action;
Pixmap image_pixmap, mask_pixmap;
Cursor cursor;
Atom action;
};
typedef struct _DndCursor DndCursor;
typedef struct _DndClass DndClass;
struct _DndClass {
/* insert chars sequentionally into the target widget, type will be the same as `desired_type'
returned from widget_apply_position. This may be called several times in succession
with sequention blocks of data. Must return non-zero on failure */
int (*widget_insert_drop) (DndClass * dnd, unsigned char *data, int length, int remaining, Window into, Window from, Atom type);
/* In response to DELETE requests : FIXME - not yet used */
int (*widget_delete_selection) (DndClass * dnd, Window window, Window from);
/* returns 1 if widget exists, zero otherwise. If this method is not
set then the code assumes that no widgets have support for recieving drops.
In this case none of the widget methods need be set. */
int (*widget_exists) (DndClass * dnd, Window window);
/* must update the widgets border to its default appearance */
void (*widget_apply_leave) (DndClass * dnd, Window widgets_window);
/* must update the widgets border to give the appearance of being able to recieve a drop,
plus return all data to pointers. As per the protocol, if the widget cannot
perform the action specified by `action' then it should return either XdndActionPrivate
or XdndActionCopy into supported_action (leaving 0 supported_action unchanged is equivalent
to XdndActionCopy). Returns 1 if ready to ok drop */
int (*widget_apply_position) (DndClass * dnd, Window widgets_window, Window from,
Atom action, int x, int y, Time t, Atom * typelist,
int *want_position, Atom * supported_action, Atom * desired_type,
XRectangle * rectangle);
/* returns drag data of the specified type. This will be one of `typelist' given to xdnd_drag */
void (*widget_get_data) (DndClass * dnd, Window window, unsigned char **data, int *length, Atom type);
/* this is called from with the main event loop if an expose event is recieved and is optional */
void (*handle_expose_events) (DndClass * dnd, XEvent * xevent);
/* creates a chooser dialog if the action is XdndActionAsk. Returns non-zero on cancel */
int (*action_choose_dialog) (DndClass * dnd, char **descriptions, Atom * actions, Atom * result);
void *pad1[8];
DndCursor *cursors;
Display *display;
Atom XdndAware;
Atom XdndSelection;
Atom XdndEnter;
Atom XdndLeave;
Atom XdndPosition;
Atom XdndDrop;
Atom XdndFinished;
Atom XdndStatus;
Atom XdndActionCopy;
Atom XdndActionMove;
Atom XdndActionLink;
Atom XdndActionAsk;
Atom XdndActionPrivate;
Atom XdndTypeList;
Atom XdndActionList;
Atom XdndActionDescription;
Atom Xdnd_NON_PROTOCOL_ATOM;
Atom version;
Atom pad2[16];
Window root_window;
#define XDND_DROP_STAGE_IDLE 0
#define XDND_DRAG_STAGE_DRAGGING 1
#define XDND_DRAG_STAGE_ENTERED 2
#define XDND_DROP_STAGE_CONVERTING 3
#define XDND_DROP_STAGE_ENTERED 4
int stage;
int dragging_version;
int internal_drag;
int want_position;
int ready_to_drop;
int will_accept;
XRectangle rectangle;
Window dropper_window, dragger_window;
Atom *dragger_typelist;
Atom desired_type;
Atom supported_action;
Time time;
/* drop position from last XdndPosition */
int x, y;
int pad3[16];
/* move euclidian pixels before considering this to be an actual drag */
float drag_threshold;
/* block for only this many seconds on not receiving a XdndFinished from target, default : 10 */
int time_out;
#define XDND_OPTION_NO_HYSTERESIS (1<<0)
int options;
/* user hooks */
void *user_hook1;
void *user_hook2;
void *user_hook3;
void *pad4[16];
};
void xdnd_init (DndClass * dnd, Display * display);
void xdnd_shut (DndClass *dnd);
void xdnd_set_dnd_aware (DndClass * dnd, Window window, Atom * typelist);
int xdnd_is_dnd_aware (DndClass * dnd, Window window, int *version, Atom * typelist);
void xdnd_set_type_list (DndClass * dnd, Window window, Atom * typelist);
void xdnd_set_actions (DndClass * dnd, Window window, Atom * actions, char **descriptions);
int xdnd_get_actions (DndClass * dnd, Window window, Atom ** actions, char ***descriptions);
int xdnd_choose_action_dialog (DndClass * dnd, Atom * actions, char **descriptions, Atom * result);
void xdnd_send_enter (DndClass * dnd, Window window, Window from, Atom * typelist);
void xdnd_send_position (DndClass * dnd, Window window, Window from, Atom action, int x, int y, unsigned long etime);
void xdnd_send_status (DndClass * dnd, Window window, Window from, int will_accept,
int want_position, int x, int y, int w, int h, Atom action);
void xdnd_send_leave (DndClass * dnd, Window window, Window from);
void xdnd_send_drop (DndClass * dnd, Window window, Window from, unsigned long etime);
void xdnd_send_finished (DndClass * dnd, Window window, Window from, int error);
int xdnd_convert_selection (DndClass * dnd, Window window, Window requester, Atom type);
void xdnd_selection_send (DndClass * dnd, XSelectionRequestEvent * request, unsigned char *data, int length);
int xdnd_get_selection (DndClass * dnd, Window from, Atom property, Window insert);
Atom xdnd_drag (DndClass * dnd, Window from, Atom action, Atom * typelist);
/* Returns 1 if event is handled, This must be placed in the widget libraries main event
loop and be called if the event type is ClientMessage or SelectionNotify */
int xdnd_handle_drop_events (DndClass * dnd, XEvent * xevent);
Atom xdnd_get_drop (Display * display, XEvent * xevent, Atom * typelist, Atom * actionlist,
unsigned char **data, int *length, Atom * type, int *x, int *y);
#ifdef __cplusplus
}
#endif
#endif /* !_X_DND_H */