📄 help.c
字号:
*--------------------------------------------------*/ if (strstr (*line, "%s") != NULL) { const char * bldInfo = getBuildInfo(); char * text = XtMalloc (strlen (*line) + strlen (bldInfo)); sprintf (text, *line, bldInfo); *line = text; break; } } /*--------------------------------------------------------- * Also initialize the alphabet-to-ASCII-code table (to * make the style mapping also work on EBCDIC). * DON'T use 'A' to initialize the table! 'A' != 65 in EBCDIC. *--------------------------------------------------------*/ AlphabetToAsciiTable[(unsigned char)'A'] = ASCII_A + 0; AlphabetToAsciiTable[(unsigned char)'B'] = ASCII_A + 1; AlphabetToAsciiTable[(unsigned char)'C'] = ASCII_A + 2; AlphabetToAsciiTable[(unsigned char)'D'] = ASCII_A + 3; AlphabetToAsciiTable[(unsigned char)'E'] = ASCII_A + 4; AlphabetToAsciiTable[(unsigned char)'F'] = ASCII_A + 5; AlphabetToAsciiTable[(unsigned char)'G'] = ASCII_A + 6; AlphabetToAsciiTable[(unsigned char)'H'] = ASCII_A + 7; AlphabetToAsciiTable[(unsigned char)'I'] = ASCII_A + 8; AlphabetToAsciiTable[(unsigned char)'J'] = ASCII_A + 9; AlphabetToAsciiTable[(unsigned char)'K'] = ASCII_A + 10; AlphabetToAsciiTable[(unsigned char)'L'] = ASCII_A + 11; AlphabetToAsciiTable[(unsigned char)'M'] = ASCII_A + 12; AlphabetToAsciiTable[(unsigned char)'N'] = ASCII_A + 13; AlphabetToAsciiTable[(unsigned char)'O'] = ASCII_A + 14; AlphabetToAsciiTable[(unsigned char)'P'] = ASCII_A + 15; AlphabetToAsciiTable[(unsigned char)'Q'] = ASCII_A + 16; AlphabetToAsciiTable[(unsigned char)'R'] = ASCII_A + 17; AlphabetToAsciiTable[(unsigned char)'S'] = ASCII_A + 18; AlphabetToAsciiTable[(unsigned char)'T'] = ASCII_A + 19; AlphabetToAsciiTable[(unsigned char)'U'] = ASCII_A + 20; AlphabetToAsciiTable[(unsigned char)'V'] = ASCII_A + 21; AlphabetToAsciiTable[(unsigned char)'W'] = ASCII_A + 22; AlphabetToAsciiTable[(unsigned char)'X'] = ASCII_A + 23; AlphabetToAsciiTable[(unsigned char)'Y'] = ASCII_A + 24; AlphabetToAsciiTable[(unsigned char)'Z'] = ASCII_A + 25; }}/*** Help fonts are not loaded until they're actually needed. This function** checks if the style's font is loaded, and loads it if it's not.*/static void loadFontsAndColors(Widget parent, int style){ XFontStruct *font; int r,g,b; if (HelpStyleInfo[STYLE_INDEX(style)].font == NULL) { font = XLoadQueryFont(XtDisplay(parent), GetPrefHelpFontName(StyleFonts[STYLE_INDEX(style)])); if (font == NULL) { fprintf(stderr, "NEdit: help font, %s, not available\n", GetPrefHelpFontName(StyleFonts[STYLE_INDEX(style)])); font = XLoadQueryFont(XtDisplay(parent), "fixed"); if (font == NULL) { fprintf(stderr, "NEdit: fallback help font, \"fixed\", not " "available, cannot continue\n"); exit(EXIT_FAILURE); } } HelpStyleInfo[STYLE_INDEX(style)].font = font; if (style == STL_NM_LINK) HelpStyleInfo[STYLE_INDEX(style)].color = AllocColor(parent, GetPrefHelpLinkColor(), &r, &g, &b); }}static void adaptNavigationButtons(int topic) { Widget btn; if(HelpWindows[topic] == NULL) return; /* Shouldn't happen */ btn=XtNameToWidget(HelpWindows[topic], "helpForm.prevTopic"); if(btn) { if(topic > 0) XtSetSensitive(btn, True); else XtSetSensitive(btn, False); } btn=XtNameToWidget(HelpWindows[topic], "helpForm.nextTopic"); if(btn) { if(topic < (NUM_TOPICS - 1)) XtSetSensitive(btn, True); else XtSetSensitive(btn, False); } btn=XtNameToWidget(HelpWindows[topic], "helpForm.histBack"); if(btn) { if(navHistBack[topic] != -1) XtSetSensitive(btn, True); else XtSetSensitive(btn, False); } btn=XtNameToWidget(HelpWindows[topic], "helpForm.histForw"); if(btn) { if(navHistForw[topic] != -1) XtSetSensitive(btn, True); else XtSetSensitive(btn, False); }}/*** Put together stored help strings to create the text and optionally the style** information for a given help topic.*/static char * stitch ( Widget parent, /* used for dynamic font/color allocation */ char ** string_list, /* given help strings to stitch together */ char ** styleMap /* NULL, or a place to store help styles */){ char * cp; char * section, * sp; /* resulting help text section */ char * styleData, * sdp; /* resulting style data for text */ char style = STYLE_PLAIN; /* start off each section with this style */ int total_size = 0; /* help text section size */ char ** crnt_line; /*---------------------------------------------------- * How many characters are there going to be displayed? *----------------------------------------------------*/ for (crnt_line = string_list; *crnt_line != NULL; crnt_line++) { for (cp = *crnt_line; *cp != EOS; cp++) { /*--------------------------------------------- * The help text has embedded style information * consisting of the style marker and a single * character style, for a total of 2 characters. * This style information is not to be included * in the character counting below. *---------------------------------------------*/ if (*cp != STYLE_MARKER) { total_size++; } else { cp++; /* skipping style marker, loop will handle style */ } } } /*-------------------------------------------------------- * Get the needed space, one area for the help text being * stitched together, another for the styles to be applied. *--------------------------------------------------------*/ sp = section = XtMalloc (total_size +1); sdp = styleData = (styleMap) ? XtMalloc (total_size +1) : NULL; *sp = EOS; /*-------------------------------------------- * Fill in the newly acquired contiguous space * with help text and style information. *--------------------------------------------*/ for (crnt_line = string_list; *crnt_line != NULL; crnt_line++) { for (cp = *crnt_line; *cp != EOS; cp++) { if (*cp == STYLE_MARKER) { style = *(++cp); loadFontsAndColors(parent, style); } else { *(sp++) = *cp; /* Beware of possible EBCDIC coding! Use the mapping table. */ if (styleMap) *(sdp++) = AlphabetToAsciiTable[(unsigned char)style]; } } } *sp = EOS; /*----------------------------------------- * Only deal with style map, when available. *-----------------------------------------*/ if (styleMap) { *styleMap = styleData; *sdp = EOS; } return section;}/*** Display help for subject "topic". "parent" is a widget over which the help** dialog may be posted. Help dialogs are preserved when popped down by the** user, and may appear posted over a previous parent, regardless of the parent** argument.*/void Help(enum HelpTopic topic){ if (HelpWindows[topic] != NULL) RaiseShellWindow(HelpWindows[topic]); else HelpWindows[topic] = createHelpPanel(topic); adaptNavigationButtons(topic);}/* Setup Window/Icon title for the help window. */static void setHelpWinTitle(Widget win, enum HelpTopic topic) { char * buf, *topStr=HelpTitles[topic]; buf=malloc(strlen(topStr) + 24); topic++; sprintf(buf, "NEdit Help (%d)", (int)topic); XtVaSetValues(win, XmNiconName, buf, NULL); sprintf(buf, "NEdit Help: %s (%d)", topStr, (int)topic); XtVaSetValues(win, XmNtitle, buf, NULL); free(buf);}/*** Create a new help window displaying a given subject, "topic"**** Important hint: If this widget is restructured or the name of the text** subwidget is changed don't forget to adapt the default translations of the** help text. They are located in nedit.c, look for ** static char *fallbackResources ** (currently: nedit.helpForm.sw.helpText*translations...)*/static Widget createHelpPanel(enum HelpTopic topic){ Arg al[50]; int ac; Widget appShell, btn, dismissBtn, form, btnFW; Widget sw, hScrollBar, vScrollBar; XmString st1; char * helpText = NULL; char * styleData = NULL; ac = 0; XtSetArg(al[ac], XmNdeleteResponse, XmDO_NOTHING); ac++; appShell = CreateShellWithBestVis(APP_NAME, APP_CLASS, applicationShellWidgetClass, TheDisplay, al, ac); AddSmallIcon(appShell); /* With openmotif 2.1.30, a crash may occur when the text widget of the help window is (slowly) resized to a zero width. By imposing a minimum _window_ width, we can work around this problem. The minimum width should be larger than the width of the scrollbar. 50 is probably a safe value; this leaves room for a few characters */ XtVaSetValues(appShell, XtNminWidth, 50, NULL); form = XtVaCreateManagedWidget("helpForm", xmFormWidgetClass, appShell, NULL); XtVaSetValues(form, XmNshadowThickness, 0, NULL); /* Create the bottom row of buttons */ btn = XtVaCreateManagedWidget("find", xmPushButtonWidgetClass, form, XmNlabelString, st1=XmStringCreateSimple("Find..."), XmNmnemonic, 'F', XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 3, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 25, NULL); XtAddCallback(btn, XmNactivateCallback, searchHelpCB, appShell); XmStringFree(st1); btn = XtVaCreateManagedWidget("findAgain", xmPushButtonWidgetClass, form, XmNlabelString, st1=XmStringCreateSimple("Find Again"), XmNmnemonic, 'A', XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 27, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 49, NULL); XtAddCallback(btn, XmNactivateCallback, searchHelpAgainCB, appShell); XmStringFree(st1); btn = XtVaCreateManagedWidget("print", xmPushButtonWidgetClass, form, XmNlabelString, st1=XmStringCreateSimple("Print..."), XmNmnemonic, 'P', XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 51, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 73, NULL); XtAddCallback(btn, XmNactivateCallback, printCB, appShell); XmStringFree(st1); dismissBtn = XtVaCreateManagedWidget("dismiss", xmPushButtonWidgetClass, form, XmNlabelString, st1=XmStringCreateSimple("Dismiss"), XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 75, XmNrightAttachment, XmATTACH_POSITION, XmNrightPosition, 97, NULL); XtAddCallback(dismissBtn, XmNactivateCallback, dismissCB, appShell); XmStringFree(st1); /* Create the next row of buttons (for navigation) */ btn = XtVaCreateManagedWidget("prevTopic", xmPushButtonWidgetClass, form,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -