📄 helpbox.c
字号:
/* ------------ helpbox.c ----------- */
#include "dflat.h"
#include "htree.h"
extern DBOX HelpBox;
/* Strings of D-Flat classes for calling default help text collections */
char *ClassNames[] = {
#undef ClassDef
#define ClassDef(c,b,p,a) #c,
#include "classes.h"
NULL
};
#define MAXHEIGHT (SCREENHEIGHT-10)
#define MAXHELPKEYWORDS 50 /* Maximum keywords in a window */
#define MAXHELPSTACK 100
static struct helps *FirstHelp;
static struct helps *ThisHelp;
static char HelpFileName[9];
static char hline[160];
static int HelpCount;
static int HelpStack[MAXHELPSTACK];
static int stacked;
static int keywordcount;
static FILE *helpfp;
static BOOL Helping;
/* --- keywords in the current help text -------- */
static struct keywords {
struct helps *hkey;
int lineno;
int off1, off2, off3;
char isDefinition;
} KeyWords[MAXHELPKEYWORDS];
static struct keywords *thisword;
static void SelectHelp(WINDOW, struct helps *, BOOL);
static void ReadHelp(WINDOW);
static struct helps *FindHelp(char *);
static void DisplayDefinition(WINDOW, char *);
static void BestFit(WINDOW, DIALOGWINDOW *);
/* ------------- CREATE_WINDOW message ------------ */
static void CreateWindowMsg(WINDOW wnd)
{
Helping=TRUE;
GetClass(wnd)=HELPBOX;
InitWindowColors(wnd);
if (ThisHelp != NULL)
ThisHelp->hwnd=wnd;
}
/* ------------- COMMAND message ------------ */
static BOOL CommandMsg(WINDOW wnd, PARAM p1)
{
switch ((int)p1)
{
case ID_PREV:
if (ThisHelp != NULL)
SelectHelp(wnd, FirstHelp+(ThisHelp->prevhlp), TRUE);
return TRUE;
case ID_NEXT:
if (ThisHelp != NULL)
SelectHelp(wnd, FirstHelp+(ThisHelp->nexthlp), TRUE);
return TRUE;
case ID_BACK:
if (stacked)
SelectHelp(wnd, FirstHelp+HelpStack[--stacked], FALSE);
return TRUE;
default:
break;
}
return FALSE;
}
/* ------------- KEYBOARD message ------------ */
static BOOL KeyboardMsg(WINDOW wnd, PARAM p1)
{
WINDOW cwnd;
cwnd=ControlWindow(wnd->extension, ID_HELPTEXT);
if (cwnd == NULL || inFocus != cwnd)
return FALSE;
switch ((int)p1)
{
case '\r':
if (keywordcount)
if (thisword != NULL)
{
char *hp=thisword->hkey->hname;
if (thisword->isDefinition)
DisplayDefinition(GetParent(wnd), hp);
else
SelectHelp(wnd, thisword->hkey, TRUE);
}
return TRUE;
case '\t':
if (!keywordcount)
return TRUE;
if (thisword == NULL || ++thisword == KeyWords+keywordcount)
thisword=KeyWords;
break;
case SHIFT_HT:
if (!keywordcount)
return TRUE;
if (thisword == NULL || thisword == KeyWords)
thisword=KeyWords+keywordcount;
--thisword;
break;
default:
return FALSE;
}
if (thisword->lineno < cwnd->wtop || thisword->lineno >= cwnd->wtop+ClientHeight(cwnd))
{
int distance=ClientHeight(cwnd)/2;
do
{
cwnd->wtop=thisword->lineno-distance;
distance /= 2;
}
while (cwnd->wtop < 0);
}
SendMessage(cwnd, PAINT, 0, 0);
return TRUE;
}
/* ---- window processing module for the HELPBOX ------- */
int HelpBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg)
{
case CREATE_WINDOW:
CreateWindowMsg(wnd);
break;
case INITIATE_DIALOG:
ReadHelp(wnd);
break;
case COMMAND:
if (p2 != 0)
break;
if (CommandMsg(wnd, p1))
return TRUE;
break;
case KEYBOARD:
if (WindowMoving)
break;
if (KeyboardMsg(wnd, p1))
return TRUE;
break;
case CLOSE_WINDOW:
if (ThisHelp != NULL)
ThisHelp->hwnd=NULL;
Helping=FALSE;
break;
default:
break;
}
return BaseWndProc(HELPBOX, wnd, msg, p1, p2);
}
/* ---- PAINT message for the helpbox text editbox ---- */
static int PaintMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
int rtn;
if (thisword != NULL)
{
WINDOW pwnd=GetParent(wnd);
char *cp;
cp=TextLine(wnd, thisword->lineno);
cp+=thisword->off1;
*(cp+1)=(pwnd->WindowColors[SELECT_COLOR][FG] & 255) | 0x80;
*(cp+2)=(pwnd->WindowColors[SELECT_COLOR][BG] & 255) | 0x80;
rtn=DefaultWndProc(wnd, PAINT, p1, p2);
*(cp+1)=(pwnd->WindowColors[HILITE_COLOR][FG] & 255) | 0x80;
*(cp+2)=(pwnd->WindowColors[HILITE_COLOR][BG] & 255) | 0x80;
return rtn;
}
return DefaultWndProc(wnd, PAINT, p1, p2);
}
/* ---- LEFT_BUTTON message for the helpbox text editbox ---- */
static int LeftButtonMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
int rtn,mx,my,i;
rtn=DefaultWndProc(wnd, LEFT_BUTTON, p1, p2);
mx=(int)p1-GetClientLeft(wnd);
my=(int)p2-GetClientTop(wnd);
my+=wnd->wtop;
thisword=KeyWords;
for (i=0;i<keywordcount;i++)
{
if (my == thisword->lineno)
{
if (mx >= thisword->off2 && mx < thisword->off3)
{
SendMessage(wnd, PAINT, 0, 0);
if (thisword->isDefinition)
{
WINDOW pwnd=GetParent(wnd);
if (pwnd != NULL)
DisplayDefinition(GetParent(pwnd), thisword->hkey->hname);
}
break;
}
}
thisword++;
}
if (i == keywordcount)
thisword=NULL;
return rtn;
}
/* --- window processing module for HELPBOX's text EDITBOX -- */
int HelpTextProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg)
{
case KEYBOARD:
break;
case PAINT:
return PaintMsg(wnd, p1, p2);
case LEFT_BUTTON:
return LeftButtonMsg(wnd, p1, p2);
case DOUBLE_CLICK:
PostMessage(wnd, KEYBOARD, '\r', 0);
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
/* -------- read the help text into the editbox ------- */
static void ReadHelp(WINDOW wnd)
{
WINDOW cwnd=ControlWindow(wnd->extension, ID_HELPTEXT);
int linectr=0;
if (cwnd == NULL)
return;
thisword=KeyWords;
keywordcount=0;
cwnd->wndproc=HelpTextProc;
SendMessage(cwnd, CLEARTEXT, 0, 0);
/* Read the help text */
while (TRUE)
{
unsigned char *cp=hline, *cp1;
int colorct=0;
if (GetHelpLine(hline) == NULL)
break;
if (*hline == '<')
break;
hline[strlen(hline)-1]='\0';
/* Add help text to the help window */
while (cp != NULL)
{
if ((cp=strchr(cp, '[')) != NULL)
{
if (*(cp+1) != '.' && *(cp+1) != '*')
{
cp++;
continue;
}
thisword->lineno=cwnd->wlines;
thisword->off1=(int) (cp-hline);
thisword->off2=thisword->off1-colorct * 4;
thisword->isDefinition=*(cp+1) == '*';
colorct++;
*cp++ =CHANGECOLOR;
*cp++ =(wnd->WindowColors [HILITE_COLOR] [FG] & 255) | 0x80;
*cp++ =(wnd->WindowColors [HILITE_COLOR] [BG] & 255) | 0x80;
cp1=cp;
if ((cp=strchr(cp, ']')) != NULL)
{
if (thisword != NULL)
thisword->off3=thisword->off2+(int) (cp-cp1);
*cp++ = RESETCOLOR;
}
if ((cp=strchr(cp, '<')) != NULL)
{
char *cp1=strchr(cp, '>');
if (cp1 != NULL)
{
char hname[80];
int len=(int) (cp1-cp);
memset(hname, 0, 80);
strncpy(hname, cp+1, len-1);
thisword->hkey=FindHelp(hname);
memmove(cp, cp1+1, strlen(cp1));
}
}
thisword++;
keywordcount++;
}
}
PutItemText(wnd, ID_HELPTEXT, hline);
/* Display help text as soon as window is full */
if (++linectr == ClientHeight(cwnd))
{
struct keywords *holdthis=thisword;
thisword=NULL;
SendMessage(cwnd, PAINT, 0, 0);
thisword=holdthis;
}
if (linectr > ClientHeight(cwnd) && !TestAttribute(cwnd, VSCROLLBAR))
{
AddAttribute(cwnd, VSCROLLBAR);
SendMessage(cwnd, BORDER, 0, 0);
}
}
thisword=NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -