📄 button.c
字号:
rawCol = startcol; } /* else use old values in rawRow, Col */ saveStartRRow = startERow = rawRow; saveStartRCol = startECol = rawCol; saveEndRRow = endERow = rawRow; saveEndRCol = endECol = rawCol; if (Coordinate(startrow, startcol) < Coordinate(rawRow, rawCol)) { eventMode = LEFTEXTENSION; startERow = startrow; startECol = startcol; } else { eventMode = RIGHTEXTENSION; endERow = startrow; endECol = startcol; } ComputeSelect(startERow, startECol, endERow, endECol, False);}static voidEndExtend(w, event, params, num_params, use_cursor_loc) Widget w; XEvent *event; /* must be XButtonEvent */ String *params; /* selections */ Cardinal num_params; Bool use_cursor_loc;{ int row, col; TScreen *screen = &term->screen; char line[9]; if (use_cursor_loc) { row = screen->cursor_row; col = screen->cursor_col; } else { PointToRowCol(event->xbutton.y, event->xbutton.x, &row, &col); } ExtendExtend (row, col); lastButtonUpTime = event->xbutton.time; if (startSRow != endSRow || startSCol != endSCol) { if (replyToEmacs) { if (rawRow == startSRow && rawCol == startSCol && row == endSRow && col == endSCol) { /* Use short-form emacs select */ strcpy(line, "\033[t"); line[3] = ' ' + endSCol + 1; line[4] = ' ' + endSRow + 1; v_write(screen->respond, line, 5); } else { /* long-form, specify everything */ strcpy(line, "\033[T"); line[3] = ' ' + startSCol + 1; line[4] = ' ' + startSRow + 1; line[5] = ' ' + endSCol + 1; line[6] = ' ' + endSRow + 1; line[7] = ' ' + col + 1; line[8] = ' ' + row + 1; v_write(screen->respond, line, 9); } TrackText(0, 0, 0, 0); } } SelectSet(w, event, params, num_params); eventMode = NORMAL;}voidHandleSelectSet(w, event, params, num_params) Widget w; XEvent *event; String *params; Cardinal *num_params;{ SelectSet (w, event, params, *num_params);}static void SaltTextAway();/* ARGSUSED */static voidSelectSet (w, event, params, num_params) Widget w; XEvent *event; String *params; Cardinal num_params;{ /* Only do select stuff if non-null select */ if (startSRow != endSRow || startSCol != endSCol) { SaltTextAway(startSRow, startSCol, endSRow, endSCol, params, num_params); } else DisownSelection(term);}#define Abs(x) ((x) < 0 ? -(x) : (x))/* ARGSUSED */static void do_start_extend (w, event, params, num_params, use_cursor_loc)Widget w;XEvent *event; /* must be XButtonEvent* */String *params; /* unused */Cardinal *num_params; /* unused */Bool use_cursor_loc;{ TScreen *screen = &((XtermWidget)w)->screen; int row, col, coord; if (SendMousePosition(w, event)) return; firstValidRow = 0; lastValidRow = screen->max_row; SetSelectUnit(event->xbutton.time, selectUnit); replyToEmacs = FALSE; if (numberOfClicks == 1) { /* Save existing selection so we can reestablish it if the guy extends past the other end of the selection */ saveStartRRow = startERow = startRRow; saveStartRCol = startECol = startRCol; saveEndRRow = endERow = endRRow; saveEndRCol = endECol = endRCol; } else { /* He just needed the selection mode changed, use old values. */ startERow = startRRow = saveStartRRow; startECol = startRCol = saveStartRCol; endERow = endRRow = saveEndRRow; endECol = endRCol = saveEndRCol; } if (use_cursor_loc) { row = screen->cursor_row; col = screen->cursor_col; } else { PointToRowCol(event->xbutton.y, event->xbutton.x, &row, &col); } coord = Coordinate(row, col); if (Abs(coord - Coordinate(startSRow, startSCol)) < Abs(coord - Coordinate(endSRow, endSCol)) || coord < Coordinate(startSRow, startSCol)) { /* point is close to left side of selection */ eventMode = LEFTEXTENSION; startERow = row; startECol = col; } else { /* point is close to left side of selection */ eventMode = RIGHTEXTENSION; endERow = row; endECol = col; } ComputeSelect(startERow, startECol, endERow, endECol, True);}static voidExtendExtend (row, col) int row, col;{ int coord = Coordinate(row, col); if (eventMode == LEFTEXTENSION && (coord + (selectUnit!=SELECTCHAR)) > Coordinate(endSRow, endSCol)) { /* Whoops, he's changed his mind. Do RIGHTEXTENSION */ eventMode = RIGHTEXTENSION; startERow = saveStartRRow; startECol = saveStartRCol; } else if (eventMode == RIGHTEXTENSION && coord < Coordinate(startSRow, startSCol)) { /* Whoops, he's changed his mind. Do LEFTEXTENSION */ eventMode = LEFTEXTENSION; endERow = saveEndRRow; endECol = saveEndRCol; } if (eventMode == LEFTEXTENSION) { startERow = row; startECol = col; } else { endERow = row; endECol = col; } ComputeSelect(startERow, startECol, endERow, endECol, False);}void HandleStartExtend(w, event, params, num_params)Widget w;XEvent *event; /* must be XButtonEvent* */String *params; /* unused */Cardinal *num_params; /* unused */{ do_start_extend (w, event, params, num_params, False);}void HandleKeyboardStartExtend(w, event, params, num_params)Widget w;XEvent *event; /* must be XButtonEvent* */String *params; /* unused */Cardinal *num_params; /* unused */{ do_start_extend (w, event, params, num_params, True);}ScrollSelection(screen, amount)register TScreen* screen;register int amount;{ register int minrow = -screen->savedlines; /* Sent by scrollbar stuff, so amount never takes selection out of saved text */ /* XXX - the preceeding is false; cat /etc/termcap (or anything larger than the number of saved lines plus the screen height) and then hit extend select */ startRRow += amount; endRRow += amount; startSRow += amount; endSRow += amount; rawRow += amount; screen->startHRow += amount; screen->endHRow += amount; if (startRRow < minrow) { startRRow = minrow; startRCol = 0; } if (endRRow < minrow) { endRRow = minrow; endRCol = 0; } if (startSRow < minrow) { startSRow = minrow; startSCol = 0; } if (endSRow < minrow) { endSRow = minrow; endSCol = 0; } if (rawRow < minrow) { rawRow = minrow; rawCol = 0; } if (screen->startHRow < minrow) { screen->startHRow = minrow; screen->startHCol = 0; } if (screen->endHRow < minrow) { screen->endHRow = minrow; screen->endHCol = 0; } screen->startHCoord = Coordinate (screen->startHRow, screen->startHCol); screen->endHCoord = Coordinate (screen->endHRow, screen->endHCol);}/*ARGSUSED*/ResizeSelection (screen, rows, cols) TScreen *screen; int rows, cols;{ rows--; /* decr to get 0-max */ cols--; if (startRRow > rows) startRRow = rows; if (startSRow > rows) startSRow = rows; if (endRRow > rows) endRRow = rows; if (endSRow > rows) endSRow = rows; if (rawRow > rows) rawRow = rows; if (startRCol > cols) startRCol = cols; if (startSCol > cols) startSCol = cols; if (endRCol > cols) endRCol = cols; if (endSCol > cols) endSCol = cols; if (rawCol > cols) rawCol = cols;}static voidPointToRowCol(y, x, r, c) register int y, x; int *r, *c;/* Convert pixel coordinates to character coordinates. Rows are clipped between firstValidRow and lastValidRow. Columns are clipped between to be 0 or greater, but are not clipped to some maximum value. */{ register TScreen *screen = &term->screen; register row, col; row = (y - screen->border) / FontHeight(screen); if(row < firstValidRow) row = firstValidRow; else if(row > lastValidRow) row = lastValidRow; col = (x - screen->border - screen->scrollbar) / FontWidth(screen); if(col < 0) col = 0; else if(col > screen->max_col+1) { col = screen->max_col+1; } *r = row; *c = col;}static intLastTextCol(row) register int row;{ register TScreen *screen = &term->screen; register int i; register Char *ch; for ( i = screen->max_col, ch = screen->buf[4 * (row + screen->topline) + 1] + i ; i >= 0 && !(*ch & CHARDRAWN) ; ch--, i--) ; return(i);} /*** double click table for cut and paste in 8 bits**** This table is divided in four parts :**** - control characters [0,0x1f] U [0x80,0x9f]** - separators [0x20,0x3f] U [0xa0,0xb9]** - binding characters [0x40,0x7f] U [0xc0,0xff]** - execeptions*/static int charClass[256] = {/* NUL SOH STX ETX EOT ENQ ACK BEL */ 32, 1, 1, 1, 1, 1, 1, 1,/* BS HT NL VT NP CR SO SI */ 1, 32, 1, 1, 1, 1, 1, 1,/* DLE DC1 DC2 DC3 DC4 NAK SYN ETB */ 1, 1, 1, 1, 1, 1, 1, 1,/* CAN EM SUB ESC FS GS RS US */ 1, 1, 1, 1, 1, 1, 1, 1,/* SP ! " # $ % & ' */ 32, 33, 34, 35, 36, 37, 38, 39,/* ( ) * + , - . / */ 40, 41, 42, 43, 44, 45, 46, 47,/* 0 1 2 3 4 5 6 7 */ 48, 48, 48, 48, 48, 48, 48, 48,/* 8 9 : ; < = > ? */ 48, 48, 58, 59, 60, 61, 62, 63,/* @ A B C D E F G */ 64, 48, 48, 48, 48, 48, 48, 48,/* H I J K L M N O */ 48, 48, 48, 48, 48, 48, 48, 48,/* P Q R S T U V W */ 48, 48, 48, 48, 48, 48, 48, 48,/* X Y Z [ \ ] ^ _ */ 48, 48, 48, 91, 92, 93, 94, 48,/* ` a b c d e f g */ 96, 48, 48, 48, 48, 48, 48, 48,/* h i j k l m n o */ 48, 48, 48, 48, 48, 48, 48, 48,/* p q r s t u v w */ 48, 48, 48, 48, 48, 48, 48, 48,/* x y z { | } ~ DEL */ 48, 48, 48, 123, 124, 125, 126, 1,/* x80 x81 x82 x83 IND NEL SSA ESA */ 1, 1, 1, 1, 1, 1, 1, 1,/* HTS HTJ VTS PLD PLU RI SS2 SS3 */ 1, 1, 1, 1, 1, 1, 1, 1,/* DCS PU1 PU2 STS CCH MW SPA EPA */ 1, 1, 1, 1, 1, 1, 1, 1,/* x98 x99 x9A CSI ST OSC PM APC */ 1, 1, 1, 1, 1, 1, 1, 1,/* - i c/ L ox Y- | So */ 160, 161, 162, 163, 164, 165, 166, 167,/* .. c0 ip << _ R0 - */ 168, 169, 170, 171, 172, 173, 174, 175,/* o +- 2 3 ' u q| . */ 176, 177, 178, 179, 180, 181, 182, 183,/* , 1 2 >> 1/4 1/2 3/4 ? */ 184, 185, 186, 187, 188, 189, 190, 191,/* A` A' A^ A~ A: Ao AE C, */ 48, 48, 48, 48, 48, 48, 48, 48,/* E` E' E^ E: I` I' I^ I: */ 48, 48, 48, 48, 48, 48, 48, 48,/* D- N~ O` O' O^ O~ O: X */ 48, 48, 48, 48, 48, 48, 48, 216,/* O/ U` U' U^ U: Y' P B */ 48, 48, 48, 48, 48, 48, 48, 48,/* a` a' a^ a~ a: ao ae c, */ 48, 48, 48, 48, 48, 48, 48, 48,/* e` e' e^ e: i` i' i^ i: */ 48, 48, 48, 48, 48, 48, 48, 48,/* d n~ o` o' o^ o~ o: -: */ 48, 48, 48, 48, 48, 48, 48, 248,/* o/ u` u' u^ u: y' P y: */ 48, 48, 48, 48, 48, 48, 48, 48};int SetCharacterClassRange (low, high, value) register int low, high; /* in range of [0..255] */ register int value; /* arbitrary */{ if (low < 0 || high > 255 || high < low) return (-1); for (; low <= high; low++) charClass[low] = value; return (0);}/* * sets startSRow startSCol endSRow endSCol * ensuring that they have legal values */static voidComputeSelect(startRow, startCol, endRow, endCol, extend) int startRow, startCol, endRow, endCol; Bool extend;{ register TScreen *screen = &term->screen; register Char *ptr; register int length; register int class; int osc = startSCol; if (Coordinate(startRow, startCol) <= Coordinate(endRow, endCol)) { startSRow = startRRow = startRow; startSCol = startRCol = startCol; endSRow = endRRow = endRow; endSCol = endRCol = endCol; } else { /* Swap them */ startSRow = startRRow = endRow; startSCol = startRCol = endCol; endSRow = endRRow = startRow; endSCol = endRCol = startCol; } switch (selectUnit) { case SELECTCHAR : if (startSCol > (LastTextCol(startSRow) + 1)) { startSCol = 0; startSRow++; } if (endSCol > (LastTextCol(endSRow) + 1)) { endSCol = 0; endSRow++; } break; case SELECTWORD : if (startSCol > (LastTextCol(startSRow) + 1)) { startSCol = 0; startSRow++; } else { ptr = screen->buf[4*(startSRow+screen->topline)] + startSCol; class = charClass[*ptr]; do { --startSCol; --ptr; } while (startSCol >= 0 && charClass[*ptr] == class); ++startSCol; } if (endSCol > (LastTextCol(endSRow) + 1)) { endSCol = 0; endSRow++; } else { length = LastTextCol(endSRow); ptr = screen->buf[4*(endSRow+screen->topline)] + endSCol; class = charClass[*ptr]; do { ++endSCol; ++ptr; } while (endSCol <= length && charClass[*ptr] == class); /* Word select selects if pointing to any char in "word", especially in that it includes the last character in a word. So no --endSCol and do special eol handling */ if (endSCol > length+1) { endSCol = 0; ++endSRow; } } break; case SELECTLINE : if (term->screen.cutToBeginningOfLine) { startSCol = 0; } else if (!extend) { startSCol = osc; } if (term->screen.cutNewline) { endSCol = 0; ++endSRow; } else { endSCol = LastTextCol(endSRow) + 1; } break; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -