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

📄 window.c

📁 nedit 是一款linux下的开发源码的功能强大的编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
        /* Change the minimum pane height */    UpdateMinPaneHeights(window);}void SetColors(WindowInfo *window, const char *textFg, const char *textBg,        const char *selectFg, const char *selectBg, const char *hiliteFg,         const char *hiliteBg, const char *lineNoFg, const char *cursorFg){    int i, dummy;    Pixel   textFgPix   = AllocColor( window->textArea, textFg,                     &dummy, &dummy, &dummy),            textBgPix   = AllocColor( window->textArea, textBg,                     &dummy, &dummy, &dummy),            selectFgPix = AllocColor( window->textArea, selectFg,                     &dummy, &dummy, &dummy),            selectBgPix = AllocColor( window->textArea, selectBg,                     &dummy, &dummy, &dummy),            hiliteFgPix = AllocColor( window->textArea, hiliteFg,                     &dummy, &dummy, &dummy),            hiliteBgPix = AllocColor( window->textArea, hiliteBg,                     &dummy, &dummy, &dummy),            lineNoFgPix = AllocColor( window->textArea, lineNoFg,                     &dummy, &dummy, &dummy),            cursorFgPix = AllocColor( window->textArea, cursorFg,                     &dummy, &dummy, &dummy);    textDisp *textD;    /* Update the main pane */    XtVaSetValues(window->textArea,            XmNforeground, textFgPix,            XmNbackground, textBgPix,            NULL);    textD = ((TextWidget)window->textArea)->text.textD;    TextDSetColors( textD, textFgPix, textBgPix, selectFgPix, selectBgPix,             hiliteFgPix, hiliteBgPix, lineNoFgPix, cursorFgPix );    /* Update any additional panes */    for (i=0; i<window->nPanes; i++) {        XtVaSetValues(window->textPanes[i],                XmNforeground, textFgPix,                XmNbackground, textBgPix,                NULL);        textD = ((TextWidget)window->textPanes[i])->text.textD;        TextDSetColors( textD, textFgPix, textBgPix, selectFgPix, selectBgPix,                 hiliteFgPix, hiliteBgPix, lineNoFgPix, cursorFgPix );    }        /* Redo any syntax highlighting */    if (window->highlightData != NULL)        UpdateHighlightStyles(window);}/*** Set insert/overstrike mode*/void SetOverstrike(WindowInfo *window, int overstrike){    int i;    XtVaSetValues(window->textArea, textNoverstrike, overstrike, NULL);    for (i=0; i<window->nPanes; i++)        XtVaSetValues(window->textPanes[i], textNoverstrike, overstrike, NULL);    window->overstrike = overstrike;}/*** Select auto-wrap mode, one of NO_WRAP, NEWLINE_WRAP, or CONTINUOUS_WRAP*/void SetAutoWrap(WindowInfo *window, int state){    int i;    int autoWrap = state == NEWLINE_WRAP, contWrap = state == CONTINUOUS_WRAP;    XtVaSetValues(window->textArea, textNautoWrap, autoWrap,            textNcontinuousWrap, contWrap, NULL);    for (i=0; i<window->nPanes; i++)        XtVaSetValues(window->textPanes[i], textNautoWrap, autoWrap,                textNcontinuousWrap, contWrap, NULL);    window->wrapMode = state;        XmToggleButtonSetState(window->newlineWrapItem, autoWrap, False);    XmToggleButtonSetState(window->continuousWrapItem, contWrap, False);    XmToggleButtonSetState(window->noWrapItem, state == NO_WRAP, False);}/*** Set the wrap margin (0 == wrap at right edge of window)*/void SetWrapMargin(WindowInfo *window, int margin){    int i;        XtVaSetValues(window->textArea, textNwrapMargin, margin, NULL);    for (i=0; i<window->nPanes; i++)        XtVaSetValues(window->textPanes[i], textNwrapMargin, margin, NULL);}/*** Recover the window pointer from any widget in the window, by searching** up the widget hierarcy for the top level container widget where the window** pointer is stored in the userData field.*/WindowInfo *WidgetToWindow(Widget w){    WindowInfo *window;    Widget parent;        while (True) {        parent = XtParent(w);        if (parent == NULL)            return NULL;        if (XtClass(parent) == applicationShellWidgetClass)            break;        w = parent;    }    XtVaGetValues(w, XmNuserData, &window, NULL);    return window;}/*** Change the window appearance and the window data structure to show** that the file it contains has been modified*/void SetWindowModified(WindowInfo *window, int modified){    if (window->fileChanged == FALSE && modified == TRUE) {        XtSetSensitive(window->closeItem, TRUE);        window->fileChanged = TRUE;        UpdateWindowTitle(window);    } else if (window->fileChanged == TRUE && modified == FALSE) {        window->fileChanged = FALSE;        UpdateWindowTitle(window);    }}/*** Update the window title to reflect the filename, read-only, and modified** status of the window data structure*/void UpdateWindowTitle(const WindowInfo *window){    char *title = FormatWindowTitle(window->filename,                                    window->path,#ifdef VMS                                    NULL,#else                                    GetClearCaseViewTag(),#endif /* VMS */                                    GetPrefServerName(),                                    IsServer,                                    window->filenameSet,                                    window->lockReasons,                                    window->fileChanged,                                    GetPrefTitleFormat());                       char *iconTitle = XtMalloc(strlen(window->filename) + 2); /* strlen("*")+1 */    strcpy(iconTitle, window->filename);    if (window->fileChanged)        strcat(iconTitle, "*");    XtVaSetValues(window->shell, XmNtitle, title, XmNiconName, iconTitle, NULL);        /* If there's a find or replace dialog up in "Keep Up" mode, with a       file name in the title, update it too */    if (window->findDlog && XmToggleButtonGetState(window->findKeepBtn)) {        sprintf(title, "Find (in %s)", window->filename);        XtVaSetValues(XtParent(window->findDlog), XmNtitle, title, NULL);    }    if (window->replaceDlog && XmToggleButtonGetState(window->replaceKeepBtn)) {        sprintf(title, "Replace (in %s)", window->filename);        XtVaSetValues(XtParent(window->replaceDlog), XmNtitle, title, NULL);    }    XtFree(iconTitle);    /* Update the Windows menus with the new name */    InvalidateWindowMenus();}/*** Update the read-only state of the text area(s) in the window, and** the ReadOnly toggle button in the File menu to agree with the state in** the window data structure.*/void UpdateWindowReadOnly(WindowInfo *window){    int i, state;        state = IS_ANY_LOCKED(window->lockReasons);    XtVaSetValues(window->textArea, textNreadOnly, state, NULL);    for (i=0; i<window->nPanes; i++)        XtVaSetValues(window->textPanes[i], textNreadOnly, state, NULL);    XmToggleButtonSetState(window->readOnlyItem, state, FALSE);    XtSetSensitive(window->readOnlyItem,        !IS_ANY_LOCKED_IGNORING_USER(window->lockReasons));}/*** Get the start and end of the current selection.  This routine is obsolete** because it ignores rectangular selections, and reads from the widget** instead of the buffer.  Use BufGetSelectionPos.*/int GetSelection(Widget widget, int *left, int *right){    return GetSimpleSelection(TextGetBuffer(widget), left, right);}/*** Find the start and end of a single line selection.  Hides rectangular** selection issues for older routines which use selections that won't** span lines.*/int GetSimpleSelection(textBuffer *buf, int *left, int *right){    int selStart, selEnd, isRect, rectStart, rectEnd, lineStart;    /* get the character to match and its position from the selection, or       the character before the insert point if nothing is selected.       Give up if too many characters are selected */    if (!BufGetSelectionPos(buf, &selStart, &selEnd, &isRect,            &rectStart, &rectEnd))        return False;    if (isRect) {        lineStart = BufStartOfLine(buf, selStart);        selStart = BufCountForwardDispChars(buf, lineStart, rectStart);        selEnd = BufCountForwardDispChars(buf, lineStart, rectEnd);    }    *left = selStart;    *right = selEnd;    return True;}/*** Returns a range of text from a text widget (this routine is obsolete,** get text from the buffer instead).  Memory is allocated with** XtMalloc and caller should free it.*/char *GetTextRange(Widget widget, int left, int right){    return BufGetRange(TextGetBuffer(widget), left, right);}/*** If the selection (or cursor position if there's no selection) is not** fully shown, scroll to bring it in to view.  Note that as written,** this won't work well with multi-line selections.  Modest re-write** of the horizontal scrolling part would be quite easy to make it work** well with rectangular selections.*/void MakeSelectionVisible(WindowInfo *window, Widget textPane){    int left, right, isRect, rectStart, rectEnd, horizOffset;    int scrollOffset, leftX, rightX, y, rows, margin;    int topLineNum, lastLineNum, rightLineNum, leftLineNum, linesToScroll;    textDisp *textD = ((TextWidget)textPane)->text.textD;    int topChar = TextFirstVisiblePos(textPane);    int lastChar = TextLastVisiblePos(textPane);    int targetLineNum;    Dimension width;    /* find out where the selection is */    if (!BufGetSelectionPos(window->buffer, &left, &right, &isRect,            &rectStart, &rectEnd)) {        left = right = TextGetCursorPos(textPane);        isRect = False;    }    /* Check vertical positioning unless the selection is already shown or       already covers the display.  If the end of the selection is below       bottom, scroll it in to view until the end selection is scrollOffset       lines from the bottom of the display or the start of the selection       scrollOffset lines from the top.  Calculate a pleasing distance from the       top or bottom of the window, to scroll the selection to (if scrolling is       necessary), around 1/3 of the height of the window */    if (!((left >= topChar && right <= lastChar) ||            (left <= topChar && right >= lastChar))) {        XtVaGetValues(textPane, textNrows, &rows, NULL);        scrollOffset = rows/3;        TextGetScroll(textPane, &topLineNum, &horizOffset);        if (right > lastChar) {            /* End of sel. is below bottom of screen */            leftLineNum = topLineNum +                    TextDCountLines(textD, topChar, left, False);            targetLineNum = topLineNum + scrollOffset;            if (leftLineNum >= targetLineNum) {                /* Start of sel. is not between top & target */                linesToScroll = TextDCountLines(textD, lastChar, right, False) +                        scrollOffset;                if (leftLineNum - linesToScroll < targetLineNum)                    linesToScroll = leftLineNum - targetLineNum;                /* Scroll start of selection to the target line */                TextSetScroll(textPane, topLineNum+linesToScroll, horizOffset);            }        } else if (left < topChar) {            /* Start of sel. is above top of screen */            lastLineNum = topLineNum + rows;            rightLineNum = lastLineNum -                    TextDCountLines(textD, right, lastChar, False);            targetLineNum = lastLineNum - scrollOffset;            if (rightLineNum <= targetLineNum) {                /* End of sel. is not between bottom & target */                linesToScroll = TextDCountLines(textD, left, topChar, False) +                        scrollOffset;                if (rightLineNum + linesToScroll > targetLineNum)                    linesToScroll = targetLineNum - rightLineNum;                /* Scroll end of selection to the target line */                TextSetScroll(textPane, topLineNum-linesToScroll, horizOffset);            }        }    }    /* If either end of the selection off screen horizontally, try to bring it       in view, by making sure both end-points are visible.  Using only end       points of a multi-line selection is not a great idea, and disaster for       rectangular selections, so this part of the routine should be re-written       if it is to be used much with either.  Note also that this is a second       scrolling operation, causing the display to jump twice.  It's done after       vertical scrolling to take advantage of TextPosToXY which requires it's       reqested position to be vertically on screen) */    if (    TextPosToXY(textPane, left, &leftX, &y) &&            TextPosToXY(textPane, right, &rightX, &y) && leftX <= rightX) {        TextGetScroll(textPane, &topLineNum, &horizOffset);        XtVaGetValues(textPane, XmNwidth, &width, textNmarginWidth, &margin,                NULL);        if (leftX < margin + textD->lineNumLeft + textD->lineNumWidth)            horizOffset -=                    margin + textD->lineNumLeft + textD->lineNumWidth - leftX;        else if (rightX > width - margin)            horizOffset += rightX - (width - margin);        TextSetSc

⌨️ 快捷键说明

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