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

📄 textdisp.c

📁 nedit 是一款linux下的开发源码的功能强大的编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (end >= textD->lastChar)    	endIndex = INT_MAX;    else if (textD->lineStarts[lastLine] == -1)    	endIndex = 0;    else    	endIndex = end - textD->lineStarts[lastLine];        /* Reset the clipping rectangles for the drawing GCs which are shared       using XtAllocateGC, and may have changed since the last use */    resetClipRectangles(textD);        /* If the starting and ending lines are the same, redisplay the single       line between "start" and "end" */    if (startLine == lastLine) {    	redisplayLine(textD, startLine, 0, INT_MAX, startIndex, endIndex);    	return;    }        /* Redisplay the first line from "start" */    redisplayLine(textD, startLine, 0, INT_MAX, startIndex, INT_MAX);        /* Redisplay the lines in between at their full width */    for (i=startLine+1; i<lastLine; i++)	redisplayLine(textD, i, 0, INT_MAX, 0, INT_MAX);    /* Redisplay the last line to "end" */    redisplayLine(textD, lastLine, 0, INT_MAX, 0, endIndex);}/*** Set the scroll position of the text display vertically by line number and** horizontally by pixel offset from the left margin*/void TextDSetScroll(textDisp *textD, int topLineNum, int horizOffset){    int sliderSize, sliderMax;    int vPadding = (int)(TEXT_OF_TEXTD(textD).cursorVPadding);        /* Limit the requested scroll position to allowable values */    if (topLineNum < 1)        topLineNum = 1;    else if ((topLineNum > textD->topLineNum) &&             (topLineNum > (textD->nBufferLines + 2 - textD->nVisibleLines +                          vPadding)))        topLineNum = max(textD->topLineNum,                textD->nBufferLines + 2 - textD->nVisibleLines + vPadding);    XtVaGetValues(textD->hScrollBar, XmNmaximum, &sliderMax,             XmNsliderSize, &sliderSize, NULL);    if (horizOffset < 0)        horizOffset = 0;    if (horizOffset > sliderMax - sliderSize)        horizOffset = sliderMax - sliderSize;    setScroll(textD, topLineNum, horizOffset, True, True);}/*** Get the current scroll position for the text display, in terms of line** number of the top line and horizontal pixel offset from the left margin*/void TextDGetScroll(textDisp *textD, int *topLineNum, int *horizOffset){    *topLineNum = textD->topLineNum;    *horizOffset = textD->horizOffset;}/*** Set the position of the text insertion cursor for text display "textD"*/void TextDSetInsertPosition(textDisp *textD, int newPos){    /* make sure new position is ok, do nothing if it hasn't changed */    if (newPos == textD->cursorPos)    	return;    if (newPos < 0) newPos = 0;    if (newPos > textD->buffer->length) newPos = textD->buffer->length;     /* cursor movement cancels vertical cursor motion column */    textD->cursorPreferredCol = -1;       /* erase the cursor at it's previous position */    TextDBlankCursor(textD);        /* draw it at its new position */    textD->cursorPos = newPos;    textD->cursorOn = True;    TextDRedisplayRange(textD, textD->cursorPos-1, textD->cursorPos + 1);}void TextDBlankCursor(textDisp *textD){    if (!textD->cursorOn)    	return;        blankCursorProtrusions(textD);    textD->cursorOn = False;    TextDRedisplayRange(textD, textD->cursorPos-1, textD->cursorPos+1);}void TextDUnblankCursor(textDisp *textD){    if (!textD->cursorOn) {    	textD->cursorOn = True;    	TextDRedisplayRange(textD, textD->cursorPos-1, textD->cursorPos+1);    }}void TextDSetCursorStyle(textDisp *textD, int style){    textD->cursorStyle = style;    blankCursorProtrusions(textD);    if (textD->cursorOn)    	TextDRedisplayRange(textD, textD->cursorPos-1, textD->cursorPos + 1);}void TextDSetWrapMode(textDisp *textD, int wrap, int wrapMargin){    textD->wrapMargin = wrapMargin;    textD->continuousWrap = wrap;        /* wrapping can change change the total number of lines, re-count */    textD->nBufferLines = TextDCountLines(textD, 0, textD->buffer->length,True);        /* changing wrap margins wrap or changing from wrapped mode to non-wrapped       can leave the character at the top no longer at a line start, and/or       change the line number */    textD->firstChar = TextDStartOfLine(textD, textD->firstChar);    textD->topLineNum = TextDCountLines(textD, 0, textD->firstChar, True) + 1;    resetAbsLineNum(textD);            /* update the line starts array */    calcLineStarts(textD, 0, textD->nVisibleLines);    calcLastChar(textD);        /* Update the scroll bar page increment size (as well as other scroll       bar parameters) */    updateVScrollBarRange(textD);    updateHScrollBarRange(textD);        /* Decide if the horizontal scroll bar needs to be visible */    hideOrShowHScrollBar(textD);    /* Do a full redraw */    TextDRedisplayRect(textD, 0, textD->top, textD->width + textD->left,	    textD->height);}int TextDGetInsertPosition(textDisp *textD){    return textD->cursorPos;}/*** Insert "text" at the current cursor location.  This has the same** effect as inserting the text into the buffer using BufInsert and** then moving the insert position after the newly inserted text, except** that it's optimized to do less redrawing.*/void TextDInsert(textDisp *textD, char *text){    int pos = textD->cursorPos;        textD->cursorToHint = pos + strlen(text);    BufInsert(textD->buffer, pos, text);    textD->cursorToHint = NO_HINT;}/*** Insert "text" (which must not contain newlines), overstriking the current** cursor location.*/void TextDOverstrike(textDisp *textD, char *text){    int startPos = textD->cursorPos;    textBuffer *buf = textD->buffer;    int lineStart = BufStartOfLine(buf, startPos);    int textLen = strlen(text);    int i, p, endPos, indent, startIndent, endIndent;    char *c, ch, *paddedText = NULL;        /* determine how many displayed character positions are covered */    startIndent = BufCountDispChars(textD->buffer, lineStart, startPos);    indent = startIndent;    for (c=text; *c!='\0'; c++)    	indent += BufCharWidth(*c, indent, buf->tabDist, buf->nullSubsChar);    endIndent = indent;        /* find which characters to remove, and if necessary generate additional       padding to make up for removed control characters at the end */    indent=startIndent;    for (p=startPos; ; p++) {    	if (p == buf->length)    	    break;    	ch = BufGetCharacter(buf, p);    	if (ch == '\n')    	    break;    	indent += BufCharWidth(ch, indent, buf->tabDist, buf->nullSubsChar);    	if (indent == endIndent) {    	    p++;    	    break;    	} else if (indent > endIndent) {    	    if (ch != '\t') {    	    	p++;    	    	paddedText = XtMalloc(textLen + MAX_EXP_CHAR_LEN + 1);    	    	strcpy(paddedText, text);    	    	for (i=0; i<indent-endIndent; i++)    	    	    paddedText[textLen+i] = ' ';    	    	paddedText[textLen+i] = '\0';    	    }    	    break;    	}    }    endPos = p;	            textD->cursorToHint = startPos + textLen;    BufReplace(buf, startPos, endPos, paddedText == NULL ? text : paddedText);    textD->cursorToHint = NO_HINT;    if (paddedText != NULL)    	XtFree(paddedText);}/*** Translate window coordinates to the nearest text cursor position.*/int TextDXYToPosition(textDisp *textD, int x, int y){    return xyToPos(textD, x, y, CURSOR_POS);}/*** Translate window coordinates to the nearest character cell.*/int TextDXYToCharPos(textDisp *textD, int x, int y){    return xyToPos(textD, x, y, CHARACTER_POS);}/*** Translate window coordinates to the nearest row and column number for** positioning the cursor.  This, of course, makes no sense when the font** is proportional, since there are no absolute columns.*/void TextDXYToUnconstrainedPosition(textDisp *textD, int x, int y, int *row,	int *column){    xyToUnconstrainedPos(textD, x, y, row, column, CURSOR_POS);}/*** Translate line and column to the nearest row and column number for** positioning the cursor.  This, of course, makes no sense when the font** is proportional, since there are no absolute columns.*/int TextDLineAndColToPos(textDisp *textD, int lineNum, int column){    int i, lineEnd, charIndex, outIndex;    int lineStart=0, charLen=0;    char *lineStr, expandedChar[MAX_EXP_CHAR_LEN];    /* Count lines */    if (lineNum < 1)        lineNum = 1;    lineEnd = -1;    for (i=1; i<=lineNum && lineEnd<textD->buffer->length; i++) {        lineStart = lineEnd + 1;        lineEnd = BufEndOfLine(textD->buffer, lineStart);    }    /* If line is beyond end of buffer, position at last character in buffer */    if ( lineNum >= i ) {      return lineEnd;    }    /* Start character index at zero */    charIndex=0;    /* Only have to count columns if column isn't zero (or negative) */    if (column > 0) {      /* Count columns, expanding each character */      lineStr = BufGetRange(textD->buffer, lineStart, lineEnd);      outIndex = 0;      for(i=lineStart; i<lineEnd; i++, charIndex++) {          charLen = BufExpandCharacter(lineStr[charIndex], outIndex,                  expandedChar, textD->buffer->tabDist,                  textD->buffer->nullSubsChar);          if ( outIndex+charLen >= column ) break;          outIndex+=charLen;      }      /* If the column is in the middle of an expanded character, put cursor       * in front of character if in first half of character, and behind       * character if in last half of character       */      if (column >= outIndex + ( charLen / 2 ))        charIndex++;      /* If we are beyond the end of the line, back up one space */      if ((i>=lineEnd)&&(charIndex>0)) charIndex--;    }    /* Position is the start of the line plus the index into line buffer */    return lineStart + charIndex;}/*** Translate a buffer text position to the XY location where the center** of the cursor would be positioned to point to that character.  Returns** False if the position is not displayed because it is VERTICALLY out** of view.  If the position is horizontally out of view, returns the** x coordinate where the position would be if it were visible.*/int TextDPositionToXY(textDisp *textD, int pos, int *x, int *y){    int charIndex, lineStartPos, fontHeight, lineLen;    int visLineNum, charLen, outIndex, xStep, charStyle;    char *lineStr, expandedChar[MAX_EXP_CHAR_LEN];        /* If position is not displayed, return false */    if (pos < textD->firstChar ||    	    (pos > textD->lastChar && !emptyLinesVisible(textD)))    	return False;    	    /* Calculate y coordinate */    if (!posToVisibleLineNum(textD, pos, &visLineNum))    	return False;    fontHeight = textD->ascent + textD->descent;    *y = textD->top + visLineNum*fontHeight + fontHeight/2;        /* Get the text, length, and  buffer position of the line. If the position       is beyond the end of the buffer and should be at the first position on       the first empty line, don't try to get or scan the text  */    lineStartPos = textD->lineStarts[visLineNum];    if (lineStartPos == -1) {    	*x = textD->left - textD->horizOffset;    	return True;    }    lineLen = visLineLength(textD, visLineNum);    lineStr = BufGetRange(textD->buffer, lineStartPos, lineStartPos + lineLen);        /* Step through character positions from the beginning of the line       to "pos" to calculate the x coordinate */    xStep = textD->left - textD->horizOffset;    outIndex = 0;    for(charIndex=0; charIndex<pos-lineStartPos; charIndex++) {

⌨️ 快捷键说明

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