* edit.c: Eliminate all code disabled for the text edition.

* editcmddef.h: Likewise.
* editmenu.c: Likewise.
* editwidget.c: Likewise.
* syntax.c: Likewise.
* wordproc.c: Likewise.
This commit is contained in:
Pavel Roskin 2001-09-07 20:10:45 +00:00
parent 4895273a57
commit afee09a276
7 changed files with 11 additions and 1408 deletions

View File

@ -1,5 +1,12 @@
2001-09-07 Pavel Roskin <proski@gnu.org>
* edit.c: Eliminate all code disabled for the text edition.
* editcmddef.h: Likewise.
* editmenu.c: Likewise.
* editwidget.c: Likewise.
* syntax.c: Likewise.
* wordproc.c: Likewise.
* edit-widget.h: Change ~/.cedit to ~/.mc/cedit to keep mcedit
files separate from cooledit.

View File

@ -2084,12 +2084,6 @@ int edit_execute_key_command (WEdit * edit, int command, int char_for_insertion)
edit_push_key_press (edit);
r = edit_execute_cmd (edit, command, char_for_insertion);
#ifdef GTK
if (edit->stopped && edit->widget->destroy_me) {
(*edit->widget->destroy_me) (edit->widget->destroy_me_user_data);
return 0;
}
#endif
if (column_highlighting)
edit->force |= REDRAW_PAGE;

View File

@ -141,7 +141,6 @@
#define CK_XPaste 703
#define CK_Selection_History 704
#ifdef MIDNIGHT /* cooledit now has its own full-featured script editor and executor */
#define CK_Shell 801
/*
@ -163,7 +162,5 @@
#define IS_USER_COMMAND(i) ((i) & (1 << 16))
#define CK_Macro(i) ((i) | (1 << 17))
#define IS_MACRO_COMMAND(i) ((i) & (1 << 17))
#endif
#endif
#endif /* !__EDIT_CMD_DEF_H */

View File

@ -24,18 +24,10 @@
#include <config.h>
#include "edit.h"
#include "../src/user.h"
#include "src/user.h"
#include "editcmddef.h"
#if defined (HAVE_MAD) && ! defined (MIDNIGHT) && ! defined (GTK)
#include "mad.h"
#endif
#ifdef MIDNIGHT
#include "../src/mad.h"
extern int edit_key_emulation;
extern WButtonBar *edit_bar;
extern Dlg_head *edit_dlg;
@ -351,135 +343,3 @@ int edit_drop_hotkey_menu (WEdit * e, int key)
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, (unsigned long) CK_Load,
_("New\tC-n"), '~', menu_cmd, (unsigned long) CK_New,
"", ' ', (void *) 0, 0L,
_("Save\tF2"), '~', menu_cmd, (unsigned long) CK_Save,
_("Save as...\tF12"), '~', menu_cmd, (unsigned long) CK_Save_As,
"", ' ', (void *) 0, 0L,
_("Insert file...\tF15"), '~', menu_cmd, (unsigned long) CK_Insert_File,
_("Copy to file...\tC-f"), '~', menu_cmd, (unsigned long) CK_Save_Block
);
/* Tool hint */
CSetToolHint (catstrs (ident, ".filemenu", 0), _("Disk operations and file indexing/searching"));
CGetHintPos (&x, &d);
CDrawMenuButton (catstrs (ident, ".editmenu", 0), parent, focus_return, x, y, AUTO_WIDTH, AUTO_HEIGHT, 20,
_(" Edit "),
_("Toggle mark\tF3"), '~', menu_cmd, (unsigned long) CK_Mark,
_("Toggle mark columns\tC-b"), '~', menu_cmd, (unsigned long) CK_Column_Mark,
"", ' ', (void *) 0, 0L,
_("Toggle book mark\tC-M-Ins"), '~', menu_cmd, (unsigned long) CK_Toggle_Bookmark,
_("Previous book mark\tC-M-Up"), '~', menu_cmd, (unsigned long) CK_Prev_Bookmark,
_("Next book mark\tC-M-Down"), '~', menu_cmd, (unsigned long) CK_Next_Bookmark,
_("Flush book marks"), '~', menu_cmd, (unsigned long) CK_Flush_Bookmarks,
"", ' ', (void *) 0, 0L,
_("Toggle insert/overwrite\tIns"), '~', menu_cmd, (unsigned long) CK_Toggle_Insert,
"", ' ', (void *) 0, 0L,
_("Copy block to cursor\tF5"), '~', menu_cmd, (unsigned long) CK_Copy,
_("Move block to cursor\tF6"), '~', menu_cmd, (unsigned long) CK_Move,
_("Delete block\tF8/C-Del"), '~', menu_cmd, (unsigned long) CK_Remove,
"", ' ', (void *) 0, 0L,
_("Copy block to clipbrd\tC-Ins"), '~', menu_cmd, (unsigned long) CK_XStore,
_("Cut block to clipbrd\tS-Del"), '~', menu_cmd, (unsigned long) CK_XCut,
_("Paste block from clipbrd\tS-Ins"), '~', menu_cmd, (unsigned long) CK_XPaste,
_("Selection history\tM-Ins"), '~', menu_cmd, (unsigned long) CK_Selection_History,
"", ' ', (void *) 0, 0L,
_("Undo\tC-BackSpace"), '~', menu_cmd, (unsigned long) 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, (unsigned long) CK_Find,
_("Search again\tF17"), '~', menu_cmd, (unsigned long) CK_Find_Again,
_("Replace...\tF4"), '~', menu_cmd, (unsigned long) CK_Replace,
_("Replace again\tF14"), '~', menu_cmd, (unsigned long) 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, 12,
_(" Command "),
_("Goto line...\tM-l"), '~', menu_cmd, (unsigned long) CK_Goto,
_("Goto matching bracket\tM-b"), '~', menu_cmd, (unsigned long) CK_Match_Bracket,
"", ' ', (void *) 0, 0L,
_("Start record macro\tC-r"), '~', menu_cmd, (unsigned long) CK_Begin_Record_Macro,
_("Finish record macro...\tC-r"), '~', menu_cmd, (unsigned long) CK_End_Record_Macro,
_("Execute macro...\tC-a, KEY"), '~', menu_ctrl_key, (unsigned long) XK_a,
_("Delete macro...\t"), '~', menu_cmd, (unsigned long) CK_Delete_Macro,
"", ' ', (void *) 0, 0L,
_("Insert date/time\tC-d"), '~', menu_cmd, (unsigned long) CK_Date,
_("Format paragraph\tM-p"), '~', menu_cmd, (unsigned long) CK_Paragraph_Format,
"", ' ', (void *) 0, 0L,
_("Refresh display\tC-l"), '~', menu_cmd, (unsigned long) CK_Refresh
);
/* Tool hint */
CSetToolHint (catstrs (ident, ".commandmenu", 0), _("Macros and internal commands"));
}
#endif /* !MIDNIGHT */

View File

@ -23,909 +23,6 @@
#include <config.h>
#include "edit.h"
#ifndef MIDNIGHT
#include <X11/Xmd.h> /* CARD32 */
#include <X11/Xatom.h>
#include "app_glob.c"
#include "coollocal.h"
#include "editcmddef.h"
#include "mousemark.h"
#endif
#if defined (HAVE_MAD) && ! defined (MIDNIGHT) && ! defined (GTK)
#include "mad.h"
#endif
#ifndef MIDNIGHT
#include "xdnd.h"
extern int EditExposeRedraw;
CWidget *wedit = 0;
void edit_destroy_callback (CWidget * w)
{
if (w) {
edit_clean (w->editor);
if (w->editor)
free (w->editor);
w->editor = NULL;
} else
/* NLS ? */
CError ("Trying to destroy non-existing editor widget.\n");
}
void link_hscrollbar_to_editor (CWidget * scrollbar, CWidget * editor, XEvent * xevent, CEvent * cwevent, int whichscrbutton);
/* returns the position in the edit buffer of a window click */
long edit_get_click_pos (WEdit * edit, int x, int y)
{
long click;
/* (1) goto to left margin */
click = edit_bol (edit, edit->curs1);
/* (1) move up or down */
if (y > (edit->curs_row + 1))
click = edit_move_forward (edit, click, y - (edit->curs_row + 1), 0);
if (y < (edit->curs_row + 1))
click = edit_move_backward (edit, click, (edit->curs_row + 1) - y);
/* (3) move right to x pos */
click = edit_move_forward3 (edit, click, x - edit->start_col - 1, 0);
return click;
}
void edit_translate_xy (int xs, int ys, int *x, int *y)
{
*x = xs - EDIT_TEXT_HORIZONTAL_OFFSET;
*y = (ys - EDIT_TEXT_VERTICAL_OFFSET - option_text_line_spacing / 2 - 1) / FONT_PIX_PER_LINE + 1;
}
extern int just_dropped_something;
void mouse_redraw (WEdit * edit, long click)
{
edit->force |= REDRAW_PAGE | REDRAW_LINE;
edit_update_curs_row (edit);
edit_update_curs_col (edit);
edit->prev_col = edit_get_col (edit);
edit_update_screen (edit);
edit->search_start = click;
}
static void xy (int x, int y, int *x_return, int *y_return)
{
edit_translate_xy (x, y, x_return, y_return);
}
static long cp (WEdit * edit, int x, int y)
{
return edit_get_click_pos (edit, x, y);
}
/* return 1 if not marked */
static int marks (WEdit * edit, long *start, long *end)
{
return eval_marks (edit, start, end);
}
int column_highlighting = 0;
static int erange (WEdit * edit, long start, long end, int click)
{
if (column_highlighting) {
int x;
x = edit_move_forward3 (edit, edit_bol (edit, click), 0, click);
if ((x >= edit->column1 && x < edit->column2)
|| (x > edit->column2 && x <= edit->column1))
return (start <= click && click < end);
else
return 0;
}
return (start <= click && click < end);
}
static void fin_mark (WEdit * edit)
{
if (edit->mark2 < 0)
edit_mark_cmd (edit, 0);
}
static void move_mark (WEdit * edit)
{
edit_mark_cmd (edit, 1);
edit_mark_cmd (edit, 0);
}
static void release_mark (WEdit * edit, XEvent * event)
{
if (edit->mark2 < 0)
edit_mark_cmd (edit, 0);
else
edit_mark_cmd (edit, 1);
if (edit->mark1 != edit->mark2 && event) {
edit_get_selection (edit);
XSetSelectionOwner (CDisplay, XA_PRIMARY, CWindowOf (edit->widget), event->xbutton.time);
}
#ifdef GTK
else {
edit->widget->editable.has_selection = TRUE;
}
#endif
}
static char *get_block (WEdit * edit, long start_mark, long end_mark, int *type, int *l)
{
char *t;
t = (char *) edit_get_block (edit, start_mark, end_mark, l);
if (strlen (t) < *l)
*type = DndRawData; /* if there are nulls in the data, send as raw */
else
*type = DndText; /* else send as text */
return t;
}
static void move (WEdit * edit, long click, int y)
{
edit_cursor_move (edit, click - edit->curs1);
}
static void dclick (WEdit * edit, XEvent * event)
{
edit_mark_cmd (edit, 1);
edit_right_word_move (edit, 1);
edit_mark_cmd (edit, 0);
edit_left_word_move (edit, 1);
release_mark (edit, event);
}
static void redraw (WEdit * edit, long click)
{
mouse_redraw (edit, click);
}
void edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int width);
/* strips out the first i chars and returns a null terminated string, result must be free'd */
char *filename_from_url (char *data, int size, int i)
{
char *p, *f;
int l;
for (p = data + i; (unsigned long) p - (unsigned long) data < size && *p && *p != '\n'; p++);
l = (unsigned long) p - (unsigned long) data - i;
f = malloc (l + 1);
memcpy (f, data + i, l);
f[l] = '\0';
return f;
}
static int insert_drop (WEdit * e, Window from, unsigned char *data, int size, int xs, int ys, Atom type, Atom action)
{
long start_mark = 0, end_mark = 0;
int x, y;
edit_translate_xy (xs, ys, &x, &y);
/* musn't be able to drop into a block, otherwise a single click will copy a block: */
if (eval_marks (e, &start_mark, &end_mark))
goto fine;
if (start_mark > e->curs1 || e->curs1 >= end_mark)
goto fine;
if (column_highlighting) {
if (!((x >= e->column1 && x < e->column2)
|| (x > e->column2 && x <= e->column1)))
goto fine;
}
return 1;
fine:
if (from == e->widget->winid && action == CDndClass->XdndActionMove) {
edit_block_move_cmd (e);
edit_mark_cmd (e, 1);
return 0;
} else if (from == e->widget->winid) {
edit_block_copy_cmd (e);
return 0;
} else { /* data from another widget, or from another application */
edit_push_action (e, KEY_PRESS + e->start_display);
if (type == XInternAtom (CDisplay, "url/url", False)) {
if (!strncmp ((char *) data, "file:/", 6)) {
char *f;
edit_insert_file (e, f = filename_from_url ((char *) data, size, strlen ("file:")));
free (f);
} else {
while (size--)
edit_insert_ahead (e, data[size]);
}
} else {
if (column_highlighting) {
edit_insert_column_of_text (e, data, size, abs (e->column2 - e->column1));
} else {
while (size--)
edit_insert_ahead (e, data[size]);
}
}
}
CExpose (e->widget->ident);
return 0;
}
static char *mime_majors[2] =
{"text", 0};
struct mouse_funcs edit_mouse_funcs =
{
0,
(void (*)(int, int, int *, int *)) xy,
(long (*)(void *, int, int)) cp,
(int (*)(void *, long *, long *)) marks,
(int (*)(void *, long, long, long)) erange,
(void (*)(void *)) fin_mark,
(void (*)(void *)) move_mark,
(void (*)(void *, XEvent *)) release_mark,
(char *(*)(void *, long, long, int *, int *)) get_block,
(void (*)(void *, long, int)) move,
0,
(void (*)(void *, XEvent *)) dclick,
(void (*)(void *, long)) redraw,
(int (*)(void *, Window, unsigned char *, int, int, int, Atom, Atom)) insert_drop,
(void (*)(void *)) edit_block_delete,
DndText,
mime_majors
};
static void render_book_marks (CWidget * w);
extern int option_editor_bg_normal;
void edit_tri_cursor (Window win);
/* starting_directory is for the filebrowser */
CWidget *CDrawEditor (const char *identifier, Window parent, int x, int y,
int width, int height, const char *text, const char *filename,
const char *starting_directory, unsigned int options, unsigned long text_size)
{
static int made_directory = 0;
int extra_space_for_hscroll = 0;
CWidget *w;
WEdit *e;
CPushFont ("editor", 0);
#ifdef NEXT_LOOK
x += NEXT_SPACING;
if (options & EDITOR_HORIZ_SCROLL)
extra_space_for_hscroll = 21;
#else
if (options & EDITOR_HORIZ_SCROLL)
extra_space_for_hscroll = 8;
#endif
wedit = w = CSetupWidget (identifier, parent, x, y,
width + EDIT_FRAME_W, height + EDIT_FRAME_H, C_EDITOR_WIDGET,
ExposureMask | ButtonPressMask | ButtonReleaseMask | \
KeyPressMask | KeyReleaseMask | ButtonMotionMask | \
PropertyChangeMask | StructureNotifyMask | \
EnterWindowMask | LeaveWindowMask, color_palette (option_editor_bg_normal), 1);
xdnd_set_dnd_aware (CDndClass, w->winid, 0);
xdnd_set_type_list (CDndClass, w->winid, xdnd_typelist_send[DndText]);
edit_tri_cursor (w->winid);
w->options = options | WIDGET_TAKES_SELECTION;
w->destroy = edit_destroy_callback;
if (filename)
w->label = (char *) strdup (filename);
else
w->label = (char *) strdup ("");
if (!made_directory) {
mkdir (catstrs (home_dir, EDIT_DIR, 0), 0700);
made_directory = 1;
}
e = w->editor = CMalloc (sizeof (WEdit));
w->funcs = mouse_funcs_new (w->editor, &edit_mouse_funcs);
if (!w->editor) {
/* Not essential to translate */
CError (_ ("Error initialising editor.\n"));
CPopFont ();
return 0;
}
w->editor->widget = w;
w->editor = edit_init (e, height / FONT_PIX_PER_LINE, width / FONT_MEAN_WIDTH, filename, text, starting_directory, text_size);
w->funcs->data = (void *) w->editor;
if (!w->editor) {
free (e);
CDestroyWidget (w->ident);
CPopFont ();
return 0;
}
e->macro_i = -1;
e->widget = w;
if (!(options & EDITOR_NO_SCROLL)) {
w->vert_scrollbar = CDrawVerticalScrollbar (catstrs (identifier, ".vsc", 0), parent,
x + width + EDIT_FRAME_W + WIDGET_SPACING, y, height + EDIT_FRAME_H,
#ifdef NEXT_LOOK
AUTO_WIDTH,
#else
20,
#endif
0, 0);
CSetScrollbarCallback (w->vert_scrollbar->ident, w->ident, link_scrollbar_to_editor);
w->vert_scrollbar->scroll_bar_extra_render = render_book_marks;
}
set_hint_pos (x + width + EDIT_FRAME_W + WIDGET_SPACING, y + height + EDIT_FRAME_H + WIDGET_SPACING + extra_space_for_hscroll);
if (extra_space_for_hscroll) {
w->hori_scrollbar = CDrawHorizontalScrollbar (catstrs (identifier, ".hsc", 0), parent,
x, y + height + EDIT_FRAME_H, width + EDIT_FRAME_W,
#ifdef NEXT_LOOK
AUTO_HEIGHT,
#else
12,
#endif
0, 0);
CSetScrollbarCallback (w->hori_scrollbar->ident, w->ident, link_hscrollbar_to_editor);
}
CGetHintPos (0, &y);
if (!(options & EDITOR_NO_TEXT)) {
CPushFont ("widget", 0);
#ifdef NEXT_LOOK
CDrawStatus (catstrs (identifier, ".text", 0), parent, x, y + WIDGET_SPACING + NEXT_SPACING, width + EDIT_FRAME_W, e->filename);
#else
CDrawStatus (catstrs (identifier, ".text", 0), parent, x, y, width + EDIT_FRAME_W, e->filename);
#endif
CPopFont ();
}
CPopFont ();
return w;
}
static void render_book_marks (CWidget * w)
{
struct _book_mark *p;
WEdit *edit;
int l;
char i[32];
if (!w)
return;
strcpy (i, CIdentOf (w));
*(strstr (i, ".vsc")) = '\0';
edit = (CIdent (i))->editor;
if (!edit->book_mark)
return;
l = CHeightOf (w) - 10 * CWidthOf (w) / 3 - 10;
for (p = edit->book_mark; p->next; p = p->next);
for (; p->prev; p = p->prev) {
int y = (CWidthOf (w) + 2 * CWidthOf (w) / 3 + 4) + (int) ((double) l * p->line / edit->total_lines);
CSetColor (color_palette (((p->c & 0xFF00) >> 8) ? ((p->c & 0xFF00) >> 8) : (p->c & 0xFF)));
CLine (CWindowOf (w), 5, y, CWidthOf (w) - 6, y);
}
}
void update_scroll_bars (WEdit * e)
{
int i, x1, x2;
CWidget *scroll;
CPushFont ("editor", 0);
scroll = e->widget->vert_scrollbar;
if (scroll) {
i = e->total_lines - e->start_line + 1;
if (i > e->num_widget_lines)
i = e->num_widget_lines;
if (e->total_lines) {
x1 = (double) 65535.0 *e->start_line / (e->total_lines + 1);
x2 = (double) 65535.0 *i / (e->total_lines + 1);
} else {
x1 = 0;
x2 = 65535;
}
if (x1 != scroll->firstline || x2 != scroll->numlines) {
scroll->firstline = x1;
scroll->numlines = x2;
EditExposeRedraw = 1;
render_scrollbar (scroll);
EditExposeRedraw = 0;
}
}
scroll = e->widget->hori_scrollbar;
if (scroll) {
i = e->max_column - (-e->start_col) + 1;
if (i > e->num_widget_columns * FONT_MEAN_WIDTH)
i = e->num_widget_columns * FONT_MEAN_WIDTH;
x1 = (double) 65535.0 *(-e->start_col) / (e->max_column + 1);
x2 = (double) 65535.0 *i / (e->max_column + 1);
if (x1 != scroll->firstline || x2 != scroll->numlines) {
scroll->firstline = x1;
scroll->numlines = x2;
EditExposeRedraw = 1;
render_scrollbar (scroll);
EditExposeRedraw = 0;
}
}
CPopFont ();
}
void edit_mouse_mark (WEdit * edit, XEvent * event, int double_click)
{
CPushFont ("editor", 0);
edit_update_curs_row (edit);
edit_update_curs_col (edit);
if (event->type != MotionNotify) {
edit_push_action (edit, KEY_PRESS + edit->start_display);
if (edit->mark2 == -1)
edit_push_action (edit, MARK_1 + edit->mark1); /* mark1 must be following the cursor */
}
if (event->type == ButtonPress) {
edit->highlight = 0;
edit->found_len = 0;
}
mouse_mark (
event,
double_click,
edit->widget->funcs
);
CPopFont ();
}
void link_scrollbar_to_editor (CWidget * scrollbar, CWidget * editor, XEvent * xevent, CEvent * cwevent, int whichscrbutton)
{
int i, start_line;
WEdit *e;
e = editor->editor;
if (!e)
return;
if (!e->widget->vert_scrollbar)
return;
CPushFont ("editor", 0);
start_line = e->start_line;
if ((xevent->type == ButtonRelease || xevent->type == MotionNotify) && whichscrbutton == 3) {
edit_move_display (e, (double) scrollbar->firstline * e->total_lines / 65535.0 + 1);
} else if (xevent->type == ButtonPress && (cwevent->button == Button1 || cwevent->button == Button2)) {
switch (whichscrbutton) {
case 1:
edit_move_display (e, e->start_line - e->num_widget_lines + 1);
break;
case 2:
edit_move_display (e, e->start_line - 1);
break;
case 5:
edit_move_display (e, e->start_line + 1);
break;
case 4:
edit_move_display (e, e->start_line + e->num_widget_lines - 1);
break;
}
}
if (e->total_lines)
scrollbar->firstline = (double) 65535.0 *e->start_line / (e->total_lines + 1);
else
scrollbar->firstline = 0;
i = e->total_lines - e->start_line + 1;
if (i > e->num_widget_lines)
i = e->num_widget_lines;
if (e->total_lines)
scrollbar->numlines = (double) 65535.0 *i / (e->total_lines + 1);
else
scrollbar->numlines = 65535;
if (start_line != e->start_line) {
e->force |= REDRAW_PAGE | REDRAW_LINE;
set_cursor_position (0, 0, 0, 0, 0, 0, 0, 0, 0);
if (CCheckWindowEvent (xevent->xany.window, ButtonReleaseMask | ButtonMotionMask, 0)) {
CPopFont ();
return;
}
}
if (e->force) {
edit_render_keypress (e);
edit_status (e);
}
CPopFont ();
}
void link_hscrollbar_to_editor (CWidget * scrollbar, CWidget * editor, XEvent * xevent, CEvent * cwevent, int whichscrbutton)
{
int i, start_col;
WEdit *e;
e = editor->editor;
if (!e)
return;
if (!e->widget->hori_scrollbar)
return;
CPushFont ("editor", 0);
start_col = (-e->start_col);
if ((xevent->type == ButtonRelease || xevent->type == MotionNotify) && whichscrbutton == 3) {
e->start_col = (double) scrollbar->firstline * e->max_column / 65535.0 + 1;
e->start_col -= e->start_col % FONT_MEAN_WIDTH;
if (e->start_col < 0)
e->start_col = 0;
e->start_col = (-e->start_col);
} else if (xevent->type == ButtonPress && (cwevent->button == Button1 || cwevent->button == Button2)) {
switch (whichscrbutton) {
case 1:
edit_scroll_left (e, (e->num_widget_columns - 1) * FONT_MEAN_WIDTH);
break;
case 2:
edit_scroll_left (e, FONT_MEAN_WIDTH);
break;
case 5:
edit_scroll_right (e, FONT_MEAN_WIDTH);
break;
case 4:
edit_scroll_right (e, (e->num_widget_columns - 1) * FONT_MEAN_WIDTH);
break;
}
}
scrollbar->firstline = (double) 65535.0 *(-e->start_col) / (e->max_column + 1);
i = e->max_column - (-e->start_col) + 1;
if (i > e->num_widget_columns * FONT_MEAN_WIDTH)
i = e->num_widget_columns * FONT_MEAN_WIDTH;
scrollbar->numlines = (double) 65535.0 *i / (e->max_column + 1);
if (start_col != (-e->start_col)) {
e->force |= REDRAW_PAGE | REDRAW_LINE;
set_cursor_position (0, 0, 0, 0, 0, 0, 0, 0, 0);
if (CCheckWindowEvent (xevent->xany.window, ButtonReleaseMask | ButtonMotionMask, 0)) {
CPopFont ();
return;
}
}
if (e->force) {
edit_render_keypress (e);
edit_status (e);
}
CPopFont ();
}
/*
This section comes from rxvt-2.21b1/src/screen.c by
Robert Nation <nation@rocket.sanders.lockheed.com> &
mods by mj olesen <olesen@me.QueensU.CA>
Changes made for cooledit
*/
void selection_send (XSelectionRequestEvent * rq)
{
XEvent ev;
static Atom xa_targets = None;
if (xa_targets == None)
xa_targets = XInternAtom (CDisplay, "TARGETS", False);
ev.xselection.type = SelectionNotify;
ev.xselection.property = None;
ev.xselection.display = rq->display;
ev.xselection.requestor = rq->requestor;
ev.xselection.selection = rq->selection;
ev.xselection.target = rq->target;
ev.xselection.time = rq->time;
if (rq->target == xa_targets) {
/*
* On some systems, the Atom typedef is 64 bits wide.
* We need to have a typedef that is exactly 32 bits wide,
* because a format of 64 is not allowed by the X11 protocol.
*
* XXX: yes, but Xlib requires that you pass it 64 bits for 32bit
* quantities on 64 bit archs.
*/
/* typedef CARD32 Atom32; */
Atom target_list[2];
target_list[0] = xa_targets;
target_list[1] = XA_STRING;
XChangeProperty (CDisplay, rq->requestor, rq->property,
xa_targets, 8 * sizeof (target_list[0]), PropModeReplace,
(unsigned char *) target_list,
sizeof (target_list) / sizeof (target_list[0]));
ev.xselection.property = rq->property;
} else if (rq->target == XA_STRING) {
XChangeProperty (CDisplay, rq->requestor, rq->property,
XA_STRING, 8, PropModeReplace,
selection.text, selection.len);
ev.xselection.property = rq->property;
}
XSendEvent (CDisplay, rq->requestor, False, 0, &ev);
}
/*{{{ paste selection */
/*
* Respond to a notification that a primary selection has been sent
*/
void paste_prop (void *data, void (*insert) (void *, int), Window win, unsigned prop, int delete)
{
long nread;
unsigned long bytes_after;
if (prop == None)
return;
nread = 0;
do {
unsigned char *s;
Atom actual_type;
int actual_fmt, i;
unsigned long nitems;
if (XGetWindowProperty (CDisplay, win, prop,
nread / 4, 65536, delete,
AnyPropertyType, &actual_type, &actual_fmt,
&nitems, &bytes_after,
&s) != Success) {
XFree (s);
return;
}
nread += nitems;
for (i = 0; i < nitems; i++)
(*insert) (data, s[i]);
XFree (s);
} while (bytes_after);
}
void selection_paste (WEdit * edit, Window win, unsigned prop, int delete)
{
long c;
c = edit->curs1;
paste_prop ((void *) edit,
(void (*)(void *, int)) edit_insert,
win, prop, delete);
edit_cursor_move (edit, c - edit->curs1);
edit->force |= REDRAW_COMPLETELY | REDRAW_LINE;
}
/*}}} */
void selection_clear (void)
{
selection.text = 0;
selection.len = 0;
}
void edit_update_screen (WEdit * e)
{
if (!e)
return;
if (!e->force)
return;
CPushFont ("editor", 0);
edit_scroll_screen_over_cursor (e);
edit_update_curs_row (e);
edit_update_curs_col (e);
update_scroll_bars (e);
edit_status (e);
if (e->force & REDRAW_COMPLETELY)
e->force |= REDRAW_PAGE;
/* pop all events for this window for internal handling */
if (e->force & (REDRAW_CHAR_ONLY | REDRAW_COMPLETELY)) {
edit_render_keypress (e);
} else if (CCheckWindowEvent (e->widget->winid, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, 0)
|| CKeyPending ()) {
e->force |= REDRAW_PAGE;
CPopFont ();
return;
} else {
edit_render_keypress (e);
}
CPopFont ();
}
extern int space_width;
#ifdef HAVE_DND
#define free_data if (data) {free(data);data=0;}
/* handles drag and drop */
void handle_client_message (CWidget * w, XEvent * xevent)
{
int data_type;
unsigned char *data = 0;
unsigned long size;
int xs, ys;
long start_line;
int x, y, r, deleted = 0;
long click;
unsigned int state;
long start_mark = 0, end_mark = 0;
WEdit *e = w->editor;
/* see just below for a comment on what this is for: */
if (CIsDropAcknowledge (xevent, &state) != DndNotDnd) {
if (!(state & Button1Mask) && just_dropped_something) {
edit_push_action (e, KEY_PRESS + e->start_display);
edit_block_delete_cmd (e);
}
return;
}
data_type = CGetDrop (xevent, &data, &size, &xs, &ys);
if (data_type == DndNotDnd || xs < 0 || ys < 0 || xs >= CWidthOf (w) || ys >= CHeightOf (w)) {
free_data;
return;
}
edit_translate_xy (xs, ys, &x, &y);
click = edit_get_click_pos (e, x, y);
r = eval_marks (e, &start_mark, &end_mark);
/* musn't be able to drop into a block, otherwise a single click will copy a block: */
if (r)
goto fine;
if (start_mark > click || click >= end_mark)
goto fine;
if (column_highlighting) {
if (!((x >= e->column1 && x < e->column2)
|| (x > e->column2 && x <= e->column1)))
goto fine;
}
free_data;
return;
fine:
edit_push_action (e, KEY_PRESS + e->start_display);
/* drops to the same window moving to the left: */
start_line = e->start_line;
if (xevent->xclient.data.l[2] == xevent->xclient.window && !(xevent->xclient.data.l[1] & Button1Mask))
if ((column_highlighting && x < max (e->column1, e->column2)) || !column_highlighting) {
edit_block_delete_cmd (e);
deleted = 1;
}
edit_update_curs_row (e);
edit_move_display (e, start_line);
click = edit_get_click_pos (e, x, y); /* click pos changes with edit_block_delete_cmd() */
edit_cursor_move (e, click - e->curs1);
if (data_type == DndFile) {
edit_insert_file (e, (char *) data);
} else if (data_type != DndFiles) {
if (dnd_null_term_type (data_type)) {
int len;
len = strlen ((char *) data);
size = min (len, size);
}
if (column_highlighting) {
edit_insert_column_of_text (e, data, size, abs (e->column2 - e->column1));
} else {
while (size--)
edit_insert_ahead (e, data[size]);
}
} else {
while (size--)
edit_insert_ahead (e, data[size] ? data[size] : '\n');
}
/* drops to the same window moving to the right: */
if (xevent->xclient.data.l[2] == xevent->xclient.window && !(xevent->xclient.data.l[1] & Button1Mask))
if (column_highlighting && !deleted)
edit_block_delete_cmd (e);
/* The drop has now been successfully recieved. We can now send an acknowledge
event back to the window that send the data. When this window recieves
the acknowledge event, the app can decide whether or not to delete the data.
This allows text to be safely moved betweem text windows without the
risk of data being lost. In our case, drag with button1 is a copy
drag, while drag with any other button is a move drag (i.e. the sending
application must delete its selection after recieving an acknowledge
event). We must not, however, send an acknowledge signal if a filelist
(for example) was passed to us, since the sender might take this to
mean that all those files can be deleted! The two types we can acknowledge
are: */
if (xevent->xclient.data.l[2] != xevent->xclient.window) /* drops to the same window */
if (data_type == DndText || data_type == DndRawData)
CDropAcknowledge (xevent);
e->force |= REDRAW_COMPLETELY | REDRAW_LINE;
free_data;
}
#endif
int eh_editor (CWidget * w, XEvent * xevent, CEvent * cwevent)
{
WEdit *e = w->editor;
int r = 0;
static int old_tab_spacing = -1;
if (!e)
return 0;
if (old_tab_spacing != option_tab_spacing)
e->force |= REDRAW_COMPLETELY + REDRAW_LINE;
old_tab_spacing = option_tab_spacing;
if (xevent->type == KeyPress) {
if (xevent->xkey.keycode == 0x31 && xevent->xkey.state == 0xD) {
CSetColor (color_palette (18));
CRectangle (w->winid, 0, 0, w->width, w->height);
}
}
switch (xevent->type) {
case SelectionNotify:
selection_paste (e, xevent->xselection.requestor, xevent->xselection.property, True);
r = 1;
break;
case SelectionRequest:
selection_send (&(xevent->xselectionrequest));
return 1;
/* case SelectionClear: ---> This is handled by coolnext.c: CNextEvent() */
#ifdef HAVE_DND
case ClientMessage:
handle_client_message (w, xevent);
r = 1;
#endif
break;
case ButtonPress:
CFocus (w);
edit_render_tidbits (w);
case ButtonRelease:
if (xevent->xbutton.state & ControlMask) {
if (!column_highlighting)
edit_push_action (e, COLUMN_OFF);
column_highlighting = 1;
} else {
if (column_highlighting)
edit_push_action (e, COLUMN_ON);
column_highlighting = 0;
}
case MotionNotify:
if (!xevent->xmotion.state && xevent->type == MotionNotify)
return 0;
resolve_button (xevent, cwevent);
if ((cwevent->button == Button4 || cwevent->button == Button5)
&& (xevent->type == ButtonRelease)) {
/* ahaack: wheel mouse mapped as button 4 and 5 */
r = edit_execute_key_command (e, (cwevent->button == Button5) ? CK_Page_Down : CK_Page_Up, -1);
break;
}
edit_mouse_mark (e, xevent, cwevent->double_click);
break;
case Expose:
edit_render_expose (e, &(xevent->xexpose));
return 1;
case FocusIn:
CSetCursorColor (e->overwrite ? color_palette (24) : color_palette (19));
case FocusOut:
edit_render_tidbits (w);
e->force |= REDRAW_CHAR_ONLY | REDRAW_LINE;
edit_render_keypress (e);
return 1;
break;
case KeyRelease:
#if 0
if (column_highlighting) {
column_highlighting = 0;
e->force = REDRAW_COMPLETELY | REDRAW_LINE;
edit_mark_cmd (e, 1);
}
#endif
break;
case KeyPress:
cwevent->ident = w->ident;
if (!cwevent->command && cwevent->insert < 0) { /* no translation */
if ((cwevent->key == XK_r || cwevent->key == XK_R) && (cwevent->state & ControlMask)) {
cwevent->command = e->macro_i < 0 ? CK_Begin_Record_Macro : CK_End_Record_Macro;
} else {
cwevent->command = CKeySymMod (xevent);
if (cwevent->command > 0)
cwevent->command = CK_Macro (cwevent->command);
else
break;
}
}
r = edit_execute_key_command (e, cwevent->command, cwevent->insert);
if (r)
edit_update_screen (e);
return r;
break;
case EditorCommand:
cwevent->ident = w->ident;
cwevent->command = xevent->xkey.keycode;
r = cwevent->handled = edit_execute_key_command (e, xevent->xkey.keycode, -1);
if (r)
edit_update_screen (e);
return r;
default:
return 0;
}
edit_update_screen (e);
return r;
}
#else
WEdit *wedit;
WButtonBar *edit_bar;
Dlg_head *edit_dlg;
@ -1225,5 +322,3 @@ static int edit_callback (Dlg_head * h, WEdit * e, int msg, int par)
}
return default_proc (h, msg, par);
}
#endif

View File

@ -23,14 +23,7 @@
*/
#include <config.h>
#if defined(MIDNIGHT) || defined(GTK)
#include "edit.h"
#else
#include "coolwidget.h"
#endif
#if defined (HAVE_MAD) && ! defined (MIDNIGHT) && ! defined (GTK)
#include "mad.h"
#endif
/* bytes */
#define SYNTAX_MARKER_DENSITY 512
@ -47,7 +40,7 @@
#define UNKNOWN_FORMAT "unknown"
#if !defined(MIDNIGHT) || defined(HAVE_SYNTAXH)
#ifdef HAVE_SYNTAXH
int option_syntax_highlighting = 1;
int option_auto_spellcheck = 1;
@ -384,12 +377,7 @@ void edit_get_syntax_color (WEdit * edit, long byte_index, int *fg, int *bg)
option_syntax_highlighting && use_colors) {
translate_rule_to_color (edit, edit_get_rule (edit, byte_index), fg, bg);
} else {
#ifdef MIDNIGHT
*fg = EDITOR_NORMAL_COLOR;
#else
*fg = NO_COLOR;
*bg = NO_COLOR;
#endif
}
}
@ -532,8 +520,6 @@ static void free_args (char **args)
#define check_a {if(!*a){result=line;break;}}
#define check_not_a {if(*a){result=line;break;}}
#ifdef MIDNIGHT
int try_alloc_color_pair (char *fg, char *bg);
int this_try_alloc_color_pair (char *fg, char *bg)
@ -561,39 +547,6 @@ int this_try_alloc_color_pair (char *fg, char *bg)
}
return try_alloc_color_pair (fg, bg);
}
#else
#ifdef GTK
int allocate_color (WEdit *edit, gchar *color);
int this_allocate_color (WEdit *edit, char *fg)
{
char *p;
if (fg)
if (!*fg)
fg = 0;
if (!fg)
return allocate_color (edit, 0);
p = strchr (fg, '/');
if (!p)
return allocate_color (edit, fg);
return allocate_color (edit, p + 1);
}
#else
int this_allocate_color (WEdit *edit, char *fg)
{
char *p;
if (fg)
if (!*fg)
fg = 0;
if (!fg)
return allocate_color (0);
p = strchr (fg, '/');
if (!p)
return allocate_color (fg);
return allocate_color (p + 1);
}
#endif /* GTK */
#endif /* MIDNIGHT */
static char *error_file_name = 0;
@ -615,12 +568,8 @@ static FILE *open_include_file (char *filename)
f = fopen (p, "r");
if (f)
return f;
#if !defined (MIDNIGHT) && !defined(GTK)
strcpy (p, LIBDIR "/syntax/");
#else
strcpy (p, mc_home);
strcat (p, "/syntax/");
#endif /* MIDNIGHT || GTK */
strcat (p, filename);
syntax_free (error_file_name);
error_file_name = (char *) strdup (p);
@ -762,12 +711,7 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
a++;
strcpy (last_fg, fg ? fg : "");
strcpy (last_bg, bg ? bg : "");
#ifdef MIDNIGHT
c->keyword[0]->fg = this_try_alloc_color_pair (fg, bg);
#else
c->keyword[0]->fg = this_allocate_color (edit, fg);
c->keyword[0]->bg = this_allocate_color (edit, bg);
#endif
c->keyword[0]->keyword = (char *) strdup (" ");
check_not_a;
num_contexts++;
@ -816,12 +760,7 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
fg = last_fg;
if (!bg)
bg = last_bg;
#ifdef MIDNIGHT
k->fg = this_try_alloc_color_pair (fg, bg);
#else
k->fg = this_allocate_color (edit, fg);
k->bg = this_allocate_color (edit, bg);
#endif
check_not_a;
num_words++;
} else if (!strncmp (args[0], "#", 1)) {
@ -866,265 +805,11 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
return result;
}
#if !defined (GTK) && !defined (MIDNIGHT)
/* strdup and append c */
static char *strdupc (char *s, int c)
{
char *t;
int l;
strcpy (t = syntax_malloc ((l = strlen (s)) + 3), s);
t[l] = c;
t[l + 1] = '\0';
return t;
}
static void edit_syntax_clear_keyword (WEdit * edit, int context, int j)
{
struct context_rule *c;
struct _syntax_marker *s;
c = edit->rules[context];
/* first we clear any instances of this keyword in our cache chain (we used to just clear the cache chain, but this slows things down) */
for (s = edit->syntax_marker; s; s = s->next)
if (s->rule.keyword == j)
s->rule.keyword = 0;
else if (s->rule.keyword > j)
s->rule.keyword--;
syntax_free (c->keyword[j]->keyword);
syntax_free (c->keyword[j]->whole_word_chars_left);
syntax_free (c->keyword[j]->whole_word_chars_right);
syntax_free (c->keyword[j]);
memcpy (&c->keyword[j], &c->keyword[j + 1], (MAX_WORDS_PER_CONTEXT - j - 1) * sizeof (struct keyword *));
strcpy (&c->keyword_first_chars[j], &c->keyword_first_chars[j + 1]);
}
FILE *spelling_pipe_in = 0;
FILE *spelling_pipe_out = 0;
pid_t ispell_pid = 0;
/* adds a keyword for underlining into the keyword list for this context, returns 1 if too many words */
static int edit_syntax_add_keyword (WEdit * edit, char *keyword, int context, time_t t)
{
int j;
char *s;
struct context_rule *c;
c = edit->rules[context];
for (j = 1; c->keyword[j]; j++) {
/* if a keyword has been around for more than TRANSIENT_WORD_TIME_OUT
seconds, then remove it - we don't want to run out of space or makes syntax highlighting to slow */
if (c->keyword[j]->time) {
if (c->keyword[j]->time + TRANSIENT_WORD_TIME_OUT < t) {
edit->force |= REDRAW_PAGE;
edit_syntax_clear_keyword (edit, context, j);
j--;
}
}
}
/* are we out of space? */
if (j >= MAX_WORDS_PER_CONTEXT - 2)
return 1;
/* add the new keyword and date it */
c->keyword[j + 1] = 0;
c->keyword[j] = syntax_malloc (sizeof (struct key_word));
#ifdef MIDNIGHT
c->keyword[j]->fg = SPELLING_ERROR;
#else
c->keyword[j]->fg = c->keyword[0]->fg;
c->keyword[j]->bg = SPELLING_ERROR;
#endif
c->keyword[j]->keyword = (char *) strdup (keyword);
c->keyword[j]->first = *c->keyword[j]->keyword;
c->keyword[j]->whole_word_chars_left = (char *) strdup ("-'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ¡¢£¤¥¦§§¨©©ª«¬­®®¯°±²³´µ¶¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ");
c->keyword[j]->whole_word_chars_right = (char *) strdup ("-'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ¡¢£¤¥¦§§¨©©ª«¬­®®¯°±²³´µ¶¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ");
c->keyword[j]->time = t;
s = strdupc (c->keyword_first_chars, c->keyword[j]->first);
syntax_free (c->keyword_first_chars);
c->keyword_first_chars = s;
return 0;
}
/* checks spelling of the word at offset */
static int edit_check_spelling_at (WEdit * edit, long byte_index)
{
int context;
long p1, p2;
unsigned char *p, *q;
int r, c1, c2, j;
int ch;
time_t t;
struct context_rule *c;
/* sanity check */
if (!edit->rules || byte_index > edit->last_byte)
return 0;
/* in what context are we */
context = edit_get_rule (edit, byte_index).context;
c = edit->rules[context];
/* does this context have `spellcheck' */
if (!edit->rules[context]->spelling)
return 0;
/* find word start */
for (p1 = byte_index - 1;; p1--) {
ch = edit_get_byte (edit, p1);
if (isalpha (ch) || ch == '-' || ch == '\'')
continue;
break;
}
p1++;
/* find word end */
for (p2 = byte_index;; p2++) {
ch = edit_get_byte (edit, p2);
if (isalpha (ch) || ch == '-' || ch == '\'')
continue;
break;
}
if (p2 <= p1)
return 0;
/* create string */
q = p = syntax_malloc (p2 - p1 + 2);
for (; p1 < p2; p1++)
*p++ = edit_get_byte (edit, p1);
*p = '\0';
if (q[0] == '-' || strlen ((char *) q) > 40) { /* if you are using words over 40 characters, you are on your own */
syntax_free (q);
return 0;
}
time (&t);
for (j = 1; c->keyword[j]; j++) {
/* if the keyword is present, then update its time only. if it is a fixed keyword from the rules file, then just return */
if (!strcmp (c->keyword[j]->keyword, (char *) q)) {
if (c->keyword[j]->time)
c->keyword[j]->time = t;
syntax_free (q);
return 0;
}
}
/* feed it to ispell */
fprintf (spelling_pipe_out, "%s\n", (char *) q);
fflush (spelling_pipe_out);
/* what does ispell say? */
do {
r = fgetc (spelling_pipe_in);
} while (r == -1 && errno == EINTR);
if (r == -1) {
syntax_free (q);
return 1;
}
if (r == '\n') { /* ispell sometimes returns just blank line if it is given bad characters */
syntax_free (q);
return 0;
}
/* now read ispell output untill we get two blanks lines - we are not intersted in this part */
do {
c1 = fgetc (spelling_pipe_in);
} while (c1 == -1 && errno == EINTR);
for (;;) {
if (c1 == -1) {
syntax_free (q);
return 1;
}
do {
c2 = fgetc (spelling_pipe_in);
} while (c2 == -1 && errno == EINTR);
if (c1 == '\n' && c2 == '\n')
break;
c1 = c2;
}
/* spelled ok */
if (r == '*' || r == '+' || r == '-') {
syntax_free (q);
return 0;
}
/* not spelled ok - so add a syntax keyword for this word */
edit_syntax_add_keyword (edit, (char *) q, context, t);
syntax_free (q);
return 0;
}
char *option_alternate_dictionary = "";
int edit_check_spelling (WEdit * edit)
{
if (!option_auto_spellcheck)
return 0;
/* magic arg to close up shop */
if (!edit) {
option_auto_spellcheck = 0;
goto close_spelling;
}
/* do we at least have a syntax rule struct to put new wrongly spelled keyword in for highlighting? */
if (!edit->rules && !edit->explicit_syntax)
edit_load_syntax (edit, 0, UNKNOWN_FORMAT);
if (!edit->rules) {
option_auto_spellcheck = 0;
return 0;
}
/* is ispell running? */
if (!spelling_pipe_in) {
int in, out, a = 0;
char *arg[10];
arg[a++] = "ispell";
arg[a++] = "-a";
if (option_alternate_dictionary)
if (*option_alternate_dictionary) {
arg[a++] = "-d";
arg[a++] = option_alternate_dictionary;
}
arg[a++] = "-a";
arg[a++] = 0;
/* start ispell process */
ispell_pid = triple_pipe_open (&in, &out, 0, 1, arg[0], arg);
if (ispell_pid < 1) {
option_auto_spellcheck = 0;
#if 0
CErrorDialog (0, 0, 0, _ (" Spelling Message "), "%s", _ (" Fail trying to open ispell program. \n Check that it is in your path and works with the -a option. \n Alternatively, disable spell checking from the Options menu. "));
#endif
return 1;
}
/* prepare pipes */
spelling_pipe_in = (FILE *) fdopen (out, "r");
spelling_pipe_out = (FILE *) fdopen (in, "w");
if (!spelling_pipe_in || !spelling_pipe_out) {
option_auto_spellcheck = 0;
CErrorDialog (0, 0, 0, _ (" Spelling Message "), "%s", _ (" Fail trying to open ispell pipes. \n Check that it is in your path and works with the -a option. \n Alternatively, disable spell checking from the Options menu. "));
return 1;
}
/* read the banner message */
for (;;) {
int c1;
c1 = fgetc (spelling_pipe_in);
if (c1 == -1 && errno != EINTR) {
option_auto_spellcheck = 0;
CErrorDialog (0, 0, 0, _ (" Spelling Message "), "%s", _ (" Fail trying to read ispell pipes. \n Check that it is in your path and works with the -a option. \n Alternatively, disable spell checking from the Options menu. "));
return 1;
}
if (c1 == '\n')
break;
}
}
/* spellcheck the word under the cursor */
if (edit_check_spelling_at (edit, edit->curs1)) {
CMessageDialog (0, 0, 0, 0, _ (" Spelling Message "), "%s", _ (" Error reading from ispell. \n Ispell is being restarted. "));
close_spelling:
fclose (spelling_pipe_in);
spelling_pipe_in = 0;
fclose (spelling_pipe_out);
spelling_pipe_out = 0;
kill (ispell_pid, SIGKILL);
}
return 0;
}
#else /* ! GTK && ! MIDNIGHT*/
int edit_check_spelling (WEdit * edit)
{
return 0;
}
#endif
void (*syntax_change_callback) (CWidget *) = 0;
void edit_set_syntax_change_callback (void (*callback) (CWidget *))
@ -1143,11 +828,7 @@ void edit_free_syntax_rules (WEdit * edit)
syntax_free (edit->syntax_type);
edit->syntax_type = 0;
if (syntax_change_callback)
#ifdef MIDNIGHT
(*syntax_change_callback) (&edit->widget);
#else
(*syntax_change_callback) (edit->widget);
#endif
for (i = 0; edit->rules[i]; i++) {
if (edit->rules[i]->keyword) {
for (j = 0; edit->rules[i]->keyword[j]; j++) {
@ -1388,11 +1069,7 @@ FILE *upgrade_syntax_file (char *syntax_file)
unlink (s);
rename (syntax_file, s);
unlink (syntax_file); /* might rename() fail ? */
#if defined(MIDNIGHT) || defined(GTK)
edit_message_dialog (_(" Load Syntax Rules "), _(" Your syntax rule file is outdated \n A new rule file is being installed. \n Your old rule file has been saved with a .OLD extension. "));
#else
CMessageDialog (0, 20, 20, 0,_(" Load Syntax Rules "), _(" Your syntax rule file is outdated \n A new rule file is being installed. \n Your old rule file has been saved with a .OLD extension. "));
#endif
goto rewrite_rule_file;
}
rewind (f);
@ -1479,11 +1156,7 @@ static int edit_read_syntax_file (WEdit * edit, char **names, char *syntax_file,
}
/* notify the callback of a change in rule set */
if (syntax_change_callback)
#ifdef MIDNIGHT
(*syntax_change_callback) (&edit->widget);
#else
(*syntax_change_callback) (edit->widget);
#endif
}
break;
}
@ -1574,5 +1247,4 @@ int edit_check_spelling (WEdit * edit)
return 0;
}
#endif /* !defined(MIDNIGHT) || defined(HAVE_SYNTAXH) */
#endif /* HAVE_SYNTAXH */

View File

@ -20,13 +20,8 @@
#include <config.h>
#include "edit.h"
#if defined (HAVE_MAD) && ! defined (MIDNIGHT) && ! defined (GTK)
#include "mad.h"
#endif
#ifdef MIDNIGHT
#define tab_width option_tab_spacing
#endif
int line_is_blank (WEdit * edit, long line);
@ -138,9 +133,6 @@ static void strip_newlines (unsigned char *t, int size)
}
}
#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)
@ -164,11 +156,7 @@ static int line_pixel_length (unsigned char *t, long b, int l)
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)
@ -346,13 +334,3 @@ void format_paragraph (WEdit * edit, int force)
put_paragraph (edit, t, p, q, indent, size);
free (t);
}