⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editwidget.c

📁 具有IDE功能的编辑器
💻 C
📖 第 1 页 / 共 3 页
字号:
	      || (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;}#endifint 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;}#elseWEdit *wedit;WButtonBar *edit_bar;Dlg_head *edit_dlg;WMenu *edit_menubar;int column_highlighting = 0;static int edit_callback (Dlg_head * h, WEdit * edit, int msg, int par);static int edit_mode_callback (struct Dlg_head *h, int id, int msg){    return 0;}int edit_event (WEdit * edit, Gpm_Event * event, int *result){    *result = MOU_NORMAL;    edit_update_curs_row (edit);    edit_update_curs_col (edit);    if (event->type & (GPM_DOWN | GPM_DRAG | GPM_UP)) {	if (event->y > 1 && event->x > 0	    && event->x <= edit->num_widget_columns	    && event->y <= edit->num_widget_lines + 1) {	    if (edit->mark2 != -1 && event->type & (GPM_UP | GPM_DRAG))		return 1;	/* a lone up mustn't do anything */	    if (event->type & (GPM_DOWN | GPM_UP))		edit_push_key_press (edit);	    edit_cursor_move (edit, edit_bol (edit, edit->curs1) - edit->curs1);	    if (--event->y > (edit->curs_row + 1))		edit_cursor_move (edit,				  edit_move_forward (edit, edit->curs1, event->y - (edit->curs_row + 1), 0)				  - edit->curs1);	    if (event->y < (edit->curs_row + 1))		edit_cursor_move (edit,				  +edit_move_backward (edit, edit->curs1, (edit->curs_row + 1) - event->y)				  - edit->curs1);	    edit_cursor_move (edit, (int) edit_move_forward3 (edit, edit->curs1,		       event->x - edit->start_col - 1, 0) - edit->curs1);	    edit->prev_col = edit_get_col (edit);	    if (event->type & GPM_DOWN) {		edit_mark_cmd (edit, 1);	/* reset */		edit->highlight = 0;	    }	    if (!(event->type & GPM_DRAG))		edit_mark_cmd (edit, 0);	    edit->force |= REDRAW_COMPLETELY;	    edit_update_curs_row (edit);	    edit_update_curs_col (edit);	    edit_update_screen (edit);	    return 1;	}    }    return 0;}int menubar_event (Gpm_Event * event, WMenu * menubar);		/* menu.c */int edit_mouse_event (Gpm_Event * event, void *x){    int result;    if (edit_event ((WEdit *) x, event, &result))	return result;    else	return menubar_event (event, edit_menubar);}extern Menu EditMenuBar[5];int edit (const char *_file, int line){    static int made_directory = 0;    int framed = 0;    int midnight_colors[4];    char *text = 0;    if (option_backup_ext_int != -1) {	option_backup_ext = malloc (sizeof (int) + 1);	option_backup_ext[sizeof (int)] = '\0';	memcpy (option_backup_ext, (char *) &option_backup_ext_int, sizeof (int));    }    if (!made_directory) {	mkdir (catstrs (home_dir, EDIT_DIR, 0), 0700);	made_directory = 1;    }    if (_file) {	if (!(*_file)) {	    _file = 0;	    text = "";	}    } else	text = "";    if (!(wedit = edit_init (NULL, LINES - 2, COLS, _file, text, "", 0))) {	message (1, _ (" Error "), get_error_msg (""));	return 0;    }    wedit->macro_i = -1;    /* Create a new dialog and add it widgets to it */    edit_dlg = create_dlg (0, 0, LINES, COLS, midnight_colors,			   edit_mode_callback, "[Internal File Editor]",			   "edit",			   DLG_NONE);    edit_dlg->raw = 1;		/*so that tab = '\t' key works */    init_widget (&(wedit->widget), 0, 0, LINES - 1, COLS,		 (callback_fn) edit_callback,		 (destroy_fn) edit_clean,		 (mouse_h) edit_mouse_event, 0);    widget_want_cursor (wedit->widget, 1);    edit_bar = buttonbar_new (1);    if (!framed) {	switch (edit_key_emulation) {	case EDIT_KEY_EMULATION_NORMAL:	    edit_init_menu_normal ();	/* editmenu.c */	    break;	case EDIT_KEY_EMULATION_EMACS:	    edit_init_menu_emacs ();	/* editmenu.c */	    break;	}	edit_menubar = menubar_new (0, 0, COLS, EditMenuBar, N_menus);    }    add_widget (edit_dlg, wedit);    if (!framed)	add_widget (edit_dlg, edit_menubar);    add_widget (edit_dlg, edit_bar);    edit_move_display (wedit, line - 1);    edit_move_to_line (wedit, line - 1);    run_dlg (edit_dlg);    if (!framed)	edit_done_menu ();	/* editmenu.c */    destroy_dlg (edit_dlg);    return 1;}static void edit_my_define (Dlg_head * h, int idx, char *text,			    void (*fn) (WEdit *), WEdit * edit){    define_label_data (h, (Widget *) edit, idx, text, (buttonbarfn) fn, edit);}void cmd_F1 (WEdit * edit){    send_message (edit->widget.parent, (Widget *) edit, WIDGET_KEY, KEY_F (1));}void cmd_F2 (WEdit * edit){    send_message (edit->widget.parent, (Widget *) edit, WIDGET_KEY, KEY_F (2));}void cmd_F3 (WEdit * edit){    send_message (edit->widget.parent, (Widget *) edit, WIDGET_KEY, KEY_F (3));}void cmd_F4 (WEdit * edit){    send_message (edit->widget.parent, (Widget *) edit, WIDGET_KEY, KEY_F (4));}void cmd_F5 (WEdit * edit){    send_message (edit->widget.parent, (Widget *) edit, WIDGET_KEY, KEY_F (5));}void cmd_F6 (WEdit * edit){    send_message (edit->widget.parent, (Widget *) edit, WIDGET_KEY, KEY_F (6));}void cmd_F7 (WEdit * edit){    send_message (edit->widget.parent, (Widget *) edit, WIDGET_KEY, KEY_F (7));}void cmd_F8 (WEdit * edit){    send_message (edit->widget.parent, (Widget *) edit, WIDGET_KEY, KEY_F (8));}void cmd_F9 (WEdit * edit){    send_message (edit->widget.parent, (Widget *) edit, WIDGET_KEY, KEY_F (9));}void cmd_F10 (WEdit * edit){    send_message (edit->widget.parent, (Widget *) edit, WIDGET_KEY, KEY_F (10));}void edit_labels (WEdit * edit){    Dlg_head *h = edit->widget.parent;    edit_my_define (h, 1, _ ("Help"), cmd_F1, edit);    edit_my_define (h, 2, _ ("Save"), cmd_F2, edit);    edit_my_define (h, 3, _ ("Mark"), cmd_F3, edit);    edit_my_define (h, 4, _ ("Replac"), cmd_F4, edit);    edit_my_define (h, 5, _ ("Copy"), cmd_F5, edit);    edit_my_define (h, 6, _ ("Move"), cmd_F6, edit);    edit_my_define (h, 7, _ ("Search"), cmd_F7, edit);    edit_my_define (h, 8, _ ("Delete"), cmd_F8, edit);    if (!edit->have_frame)	edit_my_define (h, 9, _ ("PullDn"), edit_menu_cmd, edit);    edit_my_define (h, 10, _ ("Quit"), cmd_F10, edit);    redraw_labels (h, (Widget *) edit);}long get_key_state (){    return (long) get_modifier ();}void edit_adjust_size (Dlg_head * h){    WEdit *edit;    WButtonBar *edit_bar;    edit = (WEdit *) find_widget_type (h, (callback_fn) edit_callback);    edit_bar = (WButtonBar *) edit->widget.parent->current->next->widget;    widget_set_size (&edit->widget, 0, 0, LINES - 1, COLS);    widget_set_size (&edit_bar->widget, LINES - 1, 0, 1, COLS);    widget_set_size (&edit_menubar->widget, 0, 0, 1, COLS);#ifdef RESIZABLE_MENUBAR    menubar_arrange (edit_menubar);#endif}void edit_update_screen (WEdit * e){    edit_scroll_screen_over_cursor (e);    edit_update_curs_col (e);    edit_status (e);/* pop all events for this window for internal handling */    if (!is_idle ()) {	e->force |= REDRAW_PAGE;	return;    }    if (e->force & REDRAW_COMPLETELY)	e->force |= REDRAW_PAGE;    edit_render_keypress (e);}static int edit_callback (Dlg_head * h, WEdit * e, int msg, int par){    switch (msg) {    case WIDGET_INIT:	e->force |= REDRAW_COMPLETELY;	edit_labels (e);	break;    case WIDGET_DRAW:	e->force |= REDRAW_COMPLETELY;	e->num_widget_lines = LINES - 2;	e->num_widget_columns = COLS;    case WIDGET_FOCUS:	edit_update_screen (e);	return 1;    case WIDGET_KEY:{	    int cmd, ch;	    if (edit_drop_hotkey_menu (e, par))		/* first check alt-f, alt-e, alt-s, etc for drop menus */		return 1;	    if (!edit_translate_key (e, 0, par, get_key_state (), &cmd, &ch))		return 0;	    edit_execute_key_command (e, cmd, ch);	    edit_update_screen (e);	}	return 1;    case WIDGET_COMMAND:	edit_execute_key_command (e, par, -1);	edit_update_screen (e);	return 1;    case WIDGET_CURSOR:	widget_move (&e->widget, e->curs_row + EDIT_TEXT_VERTICAL_OFFSET, e->curs_col + e->start_col);	return 1;    }    return default_proc (h, msg, par);}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -