📄 editwidget.c
字号:
}
}
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;
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))
return;
}
if (e->force) {
edit_render_keypress (e);
edit_status (e);
}
}
/*
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.
*/
typedef CARD32 Atom32;
Atom32 target_list[2];
target_list[0] = (Atom32) xa_targets;
target_list[1] = (Atom32) 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;
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;
return;
} else {
edit_render_keypress (e);
}
}
extern int space_width;
static void edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int width)
{
long cursor;
int i, col;
cursor = edit->curs1;
col = edit_get_col (edit);
for (i = 0; i < size; i++) {
if (data[i] == '\n') { /* fill in and move to next line */
int l;
long p;
if (edit_get_byte (edit, edit->curs1) != '\n') {
l = width - (edit_get_col (edit) - col);
while (l > 0) {
edit_insert (edit, ' ');
l -= space_width;
}
}
for (p = edit->curs1;; p++) {
if (p == edit->last_byte)
edit_insert_ahead (edit, '\n');
if (edit_get_byte (edit, p) == '\n') {
p++;
break;
}
}
edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->curs1);
l = col - edit_get_col (edit);
while (l >= space_width) {
edit_insert (edit, ' ');
l -= space_width;
}
continue;
}
edit_insert (edit, data[i]);
}
edit_cursor_move (edit, cursor - edit->curs1);
}
#define free_data if (data) {free(data);data=0;}
/* handles drag and drop */
void handle_client_message (CWidget * w, XEvent * xevent, CEvent * cwevent)
{
int data_type;
unsigned char *data;
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 >= w->width || ys >= w->height) {
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;
}
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() */
case ClientMessage:
handle_client_message (w, xevent, cwevent);
r = 1;
break;
case ButtonPress:
CFocus (w);
edit_render_tidbits (w);
case ButtonRelease:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -