📄 help.c
字号:
static const char CVSID[] = "$Id: help.c,v 1.95 2003/05/15 19:42:31 n8gray Exp $";/******************************************************************************** ** help.c -- Nirvana Editor help display ** ** Copyright (C) 1999 Mark Edel ** ** This is free software; you can redistribute it and/or modify it under the ** terms of the GNU General Public License as published by the Free Software ** Foundation; either version 2 of the License, or (at your option) any later ** version. ** ** This software is distributed in the hope that it will be useful, but WITHOUT ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ** for more details. ** ** You should have received a copy of the GNU General Public License along with ** software; if not, write to the Free Software Foundation, Inc., 59 Temple ** Place, Suite 330, Boston, MA 02111-1307 USA ** ** Nirvana Text Editor ** September 10, 1991 ** ** Written by Mark Edel, mostly rewritten by Steve Haehn for new help system, ** December, 2001 ** ********************************************************************************/#ifdef HAVE_CONFIG_H#include "../config.h"#endif#include "help.h"#include "textBuf.h"#include "text.h"#include "textP.h"#include "textDisp.h"#include "textSel.h"#include "nedit.h"#include "search.h"#include "window.h"#include "preferences.h"#include "help_data.h"#include "file.h"#include "highlight.h"#include "../util/misc.h"#include "../util/DialogF.h"#include "../util/system.h"#include <locale.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#ifdef VMS#include "../util/VMSparam.h"#else#ifndef __MVS__#include <sys/param.h>#endif#endif /*VMS*/#include <Xm/Xm.h>#include <Xm/XmP.h> /* These are for applying style info to help text */#include <Xm/Form.h>#include <Xm/PrimitiveP.h>#include <Xm/ScrolledW.h>#include <Xm/ScrollBar.h>#include <Xm/PushB.h>#ifdef EDITRES#include <X11/Xmu/Editres.h>/* extern void _XEditResCheckMessages(); */#endif /* EDITRES */#ifdef HAVE_DEBUG_H#include "../debug.h"#endif/*============================================================================*//* SYMBOL DEFINITIONS *//*============================================================================*/#define EOS '\0' /* end-of-string character */#define CLICK_THRESHOLD 5 /* number of pixels mouse may move from its */ /* pressed location for mouse-up to be */ /* considered a valid click (as opposed to */ /* a drag or mouse-pick error) *//*============================================================================*//* VARIABLE DECLARATIONS *//*============================================================================*/static Widget HelpWindows[NUM_TOPICS] = {NULL}; static Widget HelpTextPanes[NUM_TOPICS] = {NULL};static textBuffer *HelpStyleBuffers[NUM_TOPICS] = {NULL};static int navHistForw[NUM_TOPICS];static int navHistBack[NUM_TOPICS];/* Information on the last search for search-again */static char LastSearchString[DF_MAX_PROMPT_LENGTH] = "";static int LastSearchTopic = -1;static int LastSearchPos = 0;static int LastSearchWasAllTopics = False;/* Fonts for each help text style generated by the help generator (setext). The NEdit text widget uses the first help style, 'A', to calculate window width, so making 'A' a fixed font will yield window widths calibrated to match width-dependent fixed font layouts in the help text. */static enum helpFonts StyleFonts[] ={ /* Fixed fonts, styles: 'A', 'B', 'C', 'D' */ FIXED_HELP_FONT, BOLD_FIXED_HELP_FONT, BOLD_FIXED_HELP_FONT, BOLD_ITALIC_FIXED_HELP_FONT, /* Underlined fixed fonts, styles: 'E', 'F', 'G', 'H' */ FIXED_HELP_FONT, BOLD_FIXED_HELP_FONT, BOLD_FIXED_HELP_FONT, BOLD_ITALIC_FIXED_HELP_FONT, /* Normal (proportional) fonts, styles: 'I', 'J', 'K', 'L' */ HELP_FONT, BOLD_HELP_FONT, ITALIC_HELP_FONT, BOLD_ITALIC_HELP_FONT, /* Underlined fonts, styles: 'M', 'N', 'O', 'P' */ HELP_FONT, BOLD_HELP_FONT, ITALIC_HELP_FONT, BOLD_ITALIC_HELP_FONT, /* Link font, style: 'Q' */ HELP_FONT, /* Heading fonts, styles: 'R', 'S', 'T' */ H1_HELP_FONT, H2_HELP_FONT, H3_HELP_FONT};static int StyleUnderlines[] ={ /* Fixed fonts, styles: 'A', 'B', 'C', 'D' */ False, False, False, False, /* Underlined fixed fonts, styles: 'E', 'F', 'G', 'H' */ True, True, True, True, /* Normal (proportional) fonts, styles: 'I', 'J', 'K', 'L' */ False, False, False, False, /* Underlined fonts, styles: 'M', 'N', 'O', 'P' */ True, True, True, True, /* Link font, style: 'Q' */ True, /* Heading fonts, styles: 'R', 'S', 'T' */ False, False, False};#define N_STYLES (XtNumber(StyleFonts))static styleTableEntry HelpStyleInfo[ N_STYLES ];/* Translation table for style codes (A, B, C, ...) to their ASCII codes. For systems using ASCII, this is just a one-to-one mapping, but the table makes it possible to use the style codes also on an EBCDIC system. */static unsigned char AlphabetToAsciiTable[256];/* Macro that calculates the zero-based index for a given style, taking into account that the character set may not use ASCII coding, but EBCDIC. The "style" argument must be one of the characters A - Z. In ASCII, this comes down to "style - STYLE_PLAIN". */#define STYLE_INDEX(style) \ (AlphabetToAsciiTable[(unsigned char)style] - \ AlphabetToAsciiTable[(unsigned char)STYLE_PLAIN])/*============================================================================*//* PROGRAM PROTOTYPES *//*============================================================================*/static Widget createHelpPanel(enum HelpTopic topic);static void dismissCB(Widget w, XtPointer clientData, XtPointer callData);static void prevTopicCB(Widget w, XtPointer clientData, XtPointer callData);static void nextTopicCB(Widget w, XtPointer clientData, XtPointer callData);static void bwHistoryCB(Widget w, XtPointer clientData, XtPointer callData);static void fwHistoryCB(Widget w, XtPointer clientData, XtPointer callData);static void searchHelpCB(Widget w, XtPointer clientData, XtPointer callData);static void searchHelpAgainCB(Widget w, XtPointer clientData, XtPointer callData);static void printCB(Widget w, XtPointer clientData, XtPointer callData);static char *stitch(Widget parent, char **string_list,char **styleMap);static void searchHelpText(Widget parent, int parentTopic, const char *searchFor, int allSections, int startPos, int startTopic);static void changeWindowTopic(int existingTopic, enum HelpTopic newTopic);static int findTopicFromShellWidget(Widget shellWidget);static void loadFontsAndColors(Widget parent, int style);static void initNavigationHistory(void);#ifdef HAVE__XMVERSIONSTRINGextern char _XmVersionString[];#elsestatic char _XmVersionString[] = "unknown";#endif/*============================================================================*//*================================= PROGRAMS =================================*//*============================================================================*//*** Create a string containing information on the build environment. Returned** string must NOT be freed by caller.*/static char *bldInfoString = NULL;static void freeBuildInfo(void){ /* This keeps memory leak detectors happy */ XtFree(bldInfoString);}static const char *getBuildInfo(void){ const char * bldFormat = "%s\n" " Built on: %s, %s, %s\n" " Built at: %s, %s\n" " With Motif: %d.%d.%d [%s]"#ifdef BUILD_BROKEN_NEDIT " (KNOWN-BAD)\n"#elif defined BUILD_UNTESTED_NEDIT " (UNTESTED)\n"#else "\n"#endif "Running Motif: %d.%d [%s]\n" " Server: %s %d\n" " Visual: %s\n" " Locale: %s\n"#ifdef BUILD_BROKEN_NEDIT "\nThis NEdit was built with a known-bad version of Motif. Please\n" "do not report any bugs you encounter unless you can reproduce\n" "them with a known-good binary from the www.nedit.org website.\n" "If this binary was supplied with your Linux distribution please\n" "file a bug report with them asking them to build NEdit with a\n" "known-good version of Motif.\n"#endif ; const char * visualClass[] = {"StaticGray", "GrayScale", "StaticColor", "PseudoColor", "TrueColor", "DirectColor"}; const char *locale; if (bldInfoString == NULL) { char visualStr[500] = "<unknown>"; if (TheDisplay) { Visual *visual; int depth; Colormap map; Boolean usingDefaultVisual = FindBestVisual(TheDisplay, APP_NAME, APP_CLASS, &visual, &depth, &map); sprintf(visualStr,"%d-bit %s (ID %#lx%s)", depth, visualClass[visual->class], visual->visualid, usingDefaultVisual ? ", Default" : ""); } bldInfoString = XtMalloc (strlen (bldFormat) + 1024); locale = setlocale(LC_MESSAGES, ""); sprintf(bldInfoString, bldFormat, NEditVersion, COMPILE_OS, COMPILE_MACHINE, COMPILE_COMPILER, linkdate, linktime, XmVERSION, XmREVISION, XmUPDATE_LEVEL, XmVERSION_STRING, xmUseVersion/1000, xmUseVersion%1000, _XmVersionString, ServerVendor(TheDisplay), VendorRelease(TheDisplay), visualStr, locale ? locale : "None"); atexit(freeBuildInfo); } return bldInfoString;}/*** Initialization for help system data, needs to be done only once.*/static void initHelpStyles (Widget parent) { static int styleTableInitialized = False; if (! styleTableInitialized) { Pixel fg; int styleIndex; char ** line; XtVaGetValues(parent, XtNforeground, &fg, NULL); for (styleIndex = 0; styleIndex < STL_HD + MAX_HEADING; styleIndex++) { HelpStyleInfo[ styleIndex ].color = fg; HelpStyleInfo[ styleIndex ].underline = StyleUnderlines[styleIndex]; HelpStyleInfo[ styleIndex ].font = NULL; } styleTableInitialized = True; /*------------------------------------------------------- * Only attempt to add build information to version text * when string formatting symbols are present in the text. * This special case is needed to incorporate this * dynamically created information into the static help. *-------------------------------------------------------*/ for (line = HelpText[ HELP_VERSION ]; *line != NULL; line++) { /*-------------------------------------------------- * If and when this printf format is found in the * version help text, replace that line with the * build information. Then stitching the help text * will have the final count of characters to use.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -