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

📄 window.c

📁 nedit 是一款linux下的开发源码的功能强大的编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
}void SetEmTabDist(WindowInfo *window, int emTabDist){    int i;    XtVaSetValues(window->textArea, textNemulateTabs, emTabDist, NULL);    for (i = 0; i < window->nPanes; ++i) {        XtVaSetValues(window->textPanes[i], textNemulateTabs, emTabDist, NULL);    }}/*** Turn on and off the display of the statistics line*/void ShowStatsLine(WindowInfo *window, int state){    Widget text;    int i;        /* In continuous wrap mode, text widgets must be told to keep track of       the top line number in absolute (non-wrapped) lines, because it can       be a costly calculation, and is only needed for displaying line       numbers, either in the stats line, or along the left margin */    for (i=0; i<=window->nPanes; i++) {        text = i==0 ? window->textArea : window->textPanes[i-1];        TextDMaintainAbsLineNum(((TextWidget)text)->text.textD, state);    }    window->showStats = state;    showStats(window, state);}/*** Displays and undisplays the statistics line (regardless of settings of** window->showStats or window->modeMessageDisplayed)*/static void showStats(WindowInfo *window, int state){    if (state) {        Dimension ht;        XtVaSetValues(window->iSearchForm,                XmNbottomAttachment, XmATTACH_NONE, NULL);        XtManageChild(window->statsLineForm);        showStatsForm(window, True);                /* workaround for Lesstif (0.93.0, maybe others) to reveal the             statsline */        XtVaGetValues(window->statsLine, XmNheight, &ht, NULL);        XtVaSetValues(window->statsLineColNo, XmNheight, ht, NULL);    } else {        XtUnmanageChild(window->statsLineForm);        XtVaSetValues(window->iSearchForm,                XmNbottomAttachment, XmATTACH_FORM, NULL);        showStatsForm(window, window->showISearchLine);    }          /* Tell WM that the non-expandable part of the window has changed size */    /* Already done in showStatsForm */    /* UpdateWMSizeHints(window); */}/*** Turn on and off the continuing display of the incremental search line** (when off, it is popped up and down as needed via TempShowISearch)*/void ShowISearchLine(WindowInfo *window, int state){    if (window->showISearchLine == state)        return;    window->showISearchLine = state;    showISearch(window, state);}/*** Temporarily show and hide the incremental search line if the line is not** already up.*/void TempShowISearch(WindowInfo *window, int state){    if (window->showISearchLine)        return;    if (XtIsManaged(window->iSearchForm) != state)        showISearch(window, state);}/*** Put up or pop-down the incremental search line regardless of settings** of showISearchLine or TempShowISearch*/static void showISearch(WindowInfo *window, int state){    if (state) {        XtManageChild(window->iSearchForm);        XtVaSetValues(window->statsLineForm, XmNtopAttachment,                 XmATTACH_WIDGET, XmNtopWidget, window->iSearchForm, NULL);        showStatsForm(window, True);    } else {        XtUnmanageChild(window->iSearchForm);        XtVaSetValues(window->statsLineForm, XmNtopAttachment,                 XmATTACH_FORM, NULL);        showStatsForm(window, window->showStats ||                 window->modeMessageDisplayed);    }          /* Tell WM that the non-expandable part of the window has changed size */    /* This is already done in showStatsForm */    /* UpdateWMSizeHints(window); */}/*** Show or hide the extra display area under the main menu bar which** optionally contains the status line and the incremental search bar*/static void showStatsForm(WindowInfo *window, int state){    Widget statsAreaForm = XtParent(window->statsLineForm);    Widget mainW = XtParent(statsAreaForm);    /* The very silly use of XmNcommandWindowLocation and XmNshowSeparator       below are to kick the main window widget to position and remove the       status line when it is managed and unmanaged.  At some Motif version       level, the showSeparator trick backfires and leaves the separator       shown, but fortunately the dynamic behavior is fixed, too so the       workaround is no longer necessary, either.  (... the version where       this occurs may be earlier than 2.1.  If the stats line shows       double thickness shadows in earlier Motif versions, the #if XmVersion       directive should be moved back to that earlier version) */    if (state) {        XtUnmanageChild(statsAreaForm);    /*... will this fix Solaris 7??? */        XtVaSetValues(mainW, XmNcommandWindowLocation,                XmCOMMAND_ABOVE_WORKSPACE, NULL);#if XmVersion < 2001        XtVaSetValues(mainW, XmNshowSeparator, True, NULL);#endif        XtManageChild(statsAreaForm);        XtVaSetValues(mainW, XmNshowSeparator, False, NULL);        UpdateStatsLine(window);    } else {        XtUnmanageChild(statsAreaForm);        XtVaSetValues(mainW, XmNcommandWindowLocation,                XmCOMMAND_BELOW_WORKSPACE, NULL);    }          /* Tell WM that the non-expandable part of the window has changed size */    UpdateWMSizeHints(window);}/*** Display a special message in the stats line (show the stats line if it** is not currently shown).*/void SetModeMessage(WindowInfo *window, const char *message){    window->modeMessageDisplayed = True;    XmTextSetString(window->statsLine, (char*)message);    /*     * Don't invoke the stats line again, if stats line is already displayed.     */    if (!window->showStats)	showStats(window, True);}/*** Clear special statistics line message set in SetModeMessage, returns** the statistics line to its original state as set in window->showStats*/void ClearModeMessage(WindowInfo *window){    window->modeMessageDisplayed = False;    /*     * Remove the stats line only if indicated by it's window state.     */    if (!window->showStats)        showStats(window, False);    UpdateStatsLine(window);}/*** Count the windows*/int NWindows(void){    WindowInfo *win;    int n;        for (win=WindowList, n=0; win!=NULL; win=win->next, n++);    return n;}/*** Set autoindent state to one of  NO_AUTO_INDENT, AUTO_INDENT, or SMART_INDENT.*/void SetAutoIndent(WindowInfo *window, int state){    int autoIndent = state == AUTO_INDENT, smartIndent = state == SMART_INDENT;    int i;        if (window->indentStyle == SMART_INDENT && !smartIndent)        EndSmartIndent(window);    else if (smartIndent && window->indentStyle != SMART_INDENT)        BeginSmartIndent(window, True);    window->indentStyle = state;    XtVaSetValues(window->textArea, textNautoIndent, autoIndent,            textNsmartIndent, smartIndent, NULL);    for (i=0; i<window->nPanes; i++)        XtVaSetValues(window->textPanes[i], textNautoIndent, autoIndent,                textNsmartIndent, smartIndent, NULL);    XmToggleButtonSetState(window->smartIndentItem, smartIndent, False);    XmToggleButtonSetState(window->autoIndentItem, autoIndent, False);    XmToggleButtonSetState(window->autoIndentOffItem, state == NO_AUTO_INDENT,            False);}/*** Set showMatching state to one of NO_FLASH, FLASH_DELIMIT or FLASH_RANGE.** Update the menu to reflect the change of state.*/void SetShowMatching(WindowInfo *window, int state){    window->showMatchingStyle = state;    XmToggleButtonSetState(window->showMatchingOffItem,         state == NO_FLASH, False);    XmToggleButtonSetState(window->showMatchingDelimitItem,         state == FLASH_DELIMIT, False);    XmToggleButtonSetState(window->showMatchingRangeItem,         state == FLASH_RANGE, False);}/*** Set the fonts for "window" from a font name, and updates the display.** Also updates window->fontList which is used for statistics line.**** Note that this leaks memory and server resources.  In previous NEdit** versions, fontLists were carefully tracked and freed, but X and Motif** have some kind of timing problem when widgets are distroyed, such that** fonts may not be freed immediately after widget destruction with 100%** safety.  Rather than kludge around this with timerProcs, I have chosen** to create new fontLists only when the user explicitly changes the font** (which shouldn't happen much in normal NEdit operation), and skip the** futile effort of freeing them.*/void SetFonts(WindowInfo *window, const char *fontName, const char *italicName,        const char *boldName, const char *boldItalicName){    XFontStruct *font, *oldFont;    int i, oldFontWidth, oldFontHeight, fontWidth, fontHeight;    int borderWidth, borderHeight, marginWidth, marginHeight;    int primaryChanged, highlightChanged = False;    Dimension oldWindowWidth, oldWindowHeight, oldTextWidth, oldTextHeight;    Dimension textHeight, newWindowWidth, newWindowHeight;    textDisp *textD = ((TextWidget)window->textArea)->text.textD;        /* Check which fonts have changed */    primaryChanged = strcmp(fontName, window->fontName);    if (strcmp(italicName, window->italicFontName)) highlightChanged = True;    if (strcmp(boldName, window->boldFontName)) highlightChanged = True;    if (strcmp(boldItalicName, window->boldItalicFontName))        highlightChanged = True;    if (!primaryChanged && !highlightChanged)        return;            /* Get information about the current window sizing, to be used to       determine the correct window size after the font is changed */    XtVaGetValues(window->shell, XmNwidth, &oldWindowWidth, XmNheight,            &oldWindowHeight, NULL);    XtVaGetValues(window->textArea, XmNheight, &textHeight,            textNmarginHeight, &marginHeight, textNmarginWidth,            &marginWidth, textNfont, &oldFont, NULL);    oldTextWidth = textD->width + textD->lineNumWidth;    oldTextHeight = textHeight - 2*marginHeight;    for (i=0; i<window->nPanes; i++) {        XtVaGetValues(window->textPanes[i], XmNheight, &textHeight, NULL);        oldTextHeight += textHeight - 2*marginHeight;    }    borderWidth = oldWindowWidth - oldTextWidth;    borderHeight = oldWindowHeight - oldTextHeight;    oldFontWidth = oldFont->max_bounds.width;    oldFontHeight = textD->ascent + textD->descent;                /* Change the fonts in the window data structure.  If the primary font       didn't work, use Motif's fallback mechanism by stealing it from the       statistics line.  Highlight fonts are allowed to be NULL, which       is interpreted as "use the primary font" */    if (primaryChanged) {        strcpy(window->fontName, fontName);        font = XLoadQueryFont(TheDisplay, fontName);        if (font == NULL)            XtVaGetValues(window->statsLine, XmNfontList, &window->fontList,                    NULL);        else            window->fontList = XmFontListCreate(font, XmSTRING_DEFAULT_CHARSET);    }    if (highlightChanged) {        strcpy(window->italicFontName, italicName);        window->italicFontStruct = XLoadQueryFont(TheDisplay, italicName);        strcpy(window->boldFontName, boldName);        window->boldFontStruct = XLoadQueryFont(TheDisplay, boldName);        strcpy(window->boldItalicFontName, boldItalicName);        window->boldItalicFontStruct = XLoadQueryFont(TheDisplay, boldItalicName);    }    /* Change the primary font in all the widgets */    if (primaryChanged) {        font = GetDefaultFontStruct(window->fontList);        XtVaSetValues(window->textArea, textNfont, font, NULL);        for (i=0; i<window->nPanes; i++)            XtVaSetValues(window->textPanes[i], textNfont, font, NULL);    }        /* Change the highlight fonts, even if they didn't change, because       primary font is read through the style table for syntax highlighting */    if (window->highlightData != NULL)        UpdateHighlightStyles(window);            /* Change the window manager size hints.        Note: this has to be done _before_ we set the new sizes. ICCCM2       compliant window managers (such as fvwm2) would otherwise resize       the window twice: once because of the new sizes requested, and once       because of the new size increments, resulting in an overshoot. */    UpdateWMSizeHints(window);        /* Use the information from the old window to re-size the window to a       size appropriate for the new font */    fontWidth = GetDefaultFontStruct(window->fontList)->max_bounds.width;    fontHeight = textD->ascent + textD->descent;    newWindowWidth = (oldTextWidth*fontWidth) / oldFontWidth + borderWidth;    newWindowHeight = (oldTextHeight*fontHeight) / oldFontHeight + borderHeight;    XtVaSetValues(window->shell, XmNwidth, newWindowWidth, XmNheight,            newWindowHeight, NULL);

⌨️ 快捷键说明

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