📄 helpbox.c
字号:
}
/* ---- compute the displayed length of a help text line --- */
static int HelpLength(char *s)
{
int len=strlen(s);
char *cp=strchr(s, '[');
while (cp != NULL)
{
len -= 4;
cp=strchr(cp+1, '[');
}
cp=strchr(s, '<');
while (cp != NULL)
{
char *cp1=strchr(cp, '>');
if (cp1 != NULL)
len -= (int) (cp1-cp)+1;
cp=strchr(cp1, '<');
}
return len;
}
/* ----------- load the help text file ------------ */
int LoadHelpFile(char *fname)
{
long where;
int i;
if (Helping)
return;
UnLoadHelpFile();
if ((helpfp=OpenHelpFile(fname, "rb")) == NULL)
return NULL;
strcpy(HelpFileName, fname);
fseek(helpfp, - (long) sizeof(long), SEEK_END);
fread(&where, sizeof(long), 1, helpfp);
fseek(helpfp, where, SEEK_SET);
fread(&HelpCount, sizeof(int), 1, helpfp);
FirstHelp=DFcalloc(sizeof(struct helps) * HelpCount, 1);
for (i=0;i<HelpCount;i++)
{
int len;
fread(&len, sizeof(int), 1, helpfp);
if (len)
{
(FirstHelp+i)->hname=DFcalloc(len+1, 1);
fread((FirstHelp+i)->hname, len+1, 1, helpfp);
}
fread(&len, sizeof(int), 1, helpfp);
if (len)
{
(FirstHelp+i)->comment=DFcalloc(len+1, 1);
fread((FirstHelp+i)->comment, len+1, 1, helpfp);
}
fread(&(FirstHelp+i)->hptr, sizeof(int)*5+sizeof(long), 1, helpfp);
}
fclose(helpfp);
helpfp=NULL;
}
/* ------ free the memory used by the help file table ------ */
void UnLoadHelpFile(void)
{
int i;
for (i=0;i<HelpCount;i++)
{
free((FirstHelp+i)->comment);
free((FirstHelp+i)->hname);
}
free(FirstHelp);
FirstHelp=NULL;
free(HelpTree);
HelpTree=NULL;
}
static void BuildHelpBox(WINDOW wnd)
{
int offset, i;
/* Seek to the first line of the help text */
SeekHelpLine(ThisHelp->hptr, ThisHelp->bit);
/* Read the title */
GetHelpLine(hline);
hline[strlen(hline)-1]='\0';
free(HelpBox.dwnd.title);
HelpBox.dwnd.title=DFmalloc(strlen(hline)+1);
strcpy(HelpBox.dwnd.title, hline);
/* Set the height and width */
HelpBox.dwnd.h=min(ThisHelp->hheight, MAXHEIGHT)+7;
HelpBox.dwnd.w=max(45, ThisHelp->hwidth+6);
/* Position the help window */
if (wnd != NULL)
BestFit(wnd, &HelpBox.dwnd);
/* Position the command buttons */
HelpBox.ctl[0].dwnd.w=max(40, ThisHelp->hwidth+2);
HelpBox.ctl[0].dwnd.h=min(ThisHelp->hheight, MAXHEIGHT)+2;
offset=(HelpBox.dwnd.w-40) / 2;
for (i=1;i<5;i++)
{
HelpBox.ctl[i].dwnd.y=min(ThisHelp->hheight, MAXHEIGHT)+3;
HelpBox.ctl[i].dwnd.x=(i-1) * 10+offset;
}
/* Disable ineffective buttons */
if (ThisHelp->nexthlp == -1)
DisableButton(&HelpBox, ID_NEXT);
else
EnableButton(&HelpBox, ID_NEXT);
if (ThisHelp->prevhlp == -1)
DisableButton(&HelpBox, ID_PREV);
else
EnableButton(&HelpBox, ID_PREV);
}
/* ----- select a new help window from its name ----- */
static void SelectHelp(WINDOW wnd, struct helps *newhelp, BOOL recall)
{
if (newhelp != NULL)
{
int i,x,y;
SendMessage(wnd, HIDE_WINDOW, 0, 0);
if (recall && stacked < MAXHELPSTACK)
HelpStack[stacked++]=ThisHelp-FirstHelp;
ThisHelp=newhelp;
SendMessage(GetParent(wnd), DISPLAY_HELP, (PARAM) ThisHelp->hname, 0);
if (stacked)
EnableButton(&HelpBox, ID_BACK);
else
DisableButton(&HelpBox, ID_BACK);
BuildHelpBox(NULL);
AddTitle(wnd, HelpBox.dwnd.title);
/* Reposition and resize the help window */
HelpBox.dwnd.x=(SCREENWIDTH-HelpBox.dwnd.w)/2;
HelpBox.dwnd.y=(SCREENHEIGHT-HelpBox.dwnd.h)/2;
SendMessage(wnd, MOVE, HelpBox.dwnd.x, HelpBox.dwnd.y);
SendMessage(wnd, SIZE, HelpBox.dwnd.x+HelpBox.dwnd.w-1, HelpBox.dwnd.y+HelpBox.dwnd.h-1);
/* Reposition the controls */
for (i=0;i<5;i++)
{
WINDOW cwnd=HelpBox.ctl[i].wnd;
x=HelpBox.ctl[i].dwnd.x+GetClientLeft(wnd);
y=HelpBox.ctl[i].dwnd.y+GetClientTop(wnd);
SendMessage(cwnd, MOVE, x, y);
if (i == 0)
{
x+=HelpBox.ctl[i].dwnd.w-1;
y+=HelpBox.ctl[i].dwnd.h-1;
SendMessage(cwnd, SIZE, x, y);
}
}
/* Read the help text into the help window */
ReadHelp(wnd);
ReFocus(wnd);
SendMessage(wnd, SHOW_WINDOW, 0, 0);
}
}
/* ---- strip tildes from the help name ---- */
static void StripTildes(char *fh, char *hp)
{
while (*hp)
{
if (*hp != '~')
*fh++ = *hp;
hp++;
}
*fh='\0';
}
/* --- return the comment associated with a help window --- */
char *HelpComment(char *Help)
{
char FixedHelp[30];
StripTildes(FixedHelp, Help);
if ((ThisHelp=FindHelp(FixedHelp)) != NULL)
return ThisHelp->comment;
return NULL;
}
/* ---------- display help text ----------- */
BOOL DisplayHelp(WINDOW wnd, char *Help)
{
char FixedHelp[30];
BOOL rtn=FALSE;
if (Helping)
return TRUE;
StripTildes(FixedHelp, Help);
stacked=0;
wnd->isHelping++;
if ((ThisHelp=FindHelp(FixedHelp)) != NULL)
{
if ((helpfp=OpenHelpFile(HelpFileName, "rb")) != NULL)
{
BuildHelpBox(wnd);
DisableButton(&HelpBox, ID_BACK);
/* Display the help window */
DialogBox(NULL, &HelpBox, TRUE, HelpBoxProc);
free(HelpBox.dwnd.title);
HelpBox.dwnd.title=NULL;
fclose(helpfp);
helpfp=NULL;
rtn=TRUE;
}
}
--wnd->isHelping;
return rtn;
}
/* ------- display a definition window --------- */
static void DisplayDefinition(WINDOW wnd, char *def)
{
WINDOW hwnd=wnd,dwnd;
int y;
struct helps *HoldThisHelp;
HoldThisHelp=ThisHelp;
if (GetClass(wnd) == POPDOWNMENU)
hwnd=GetParent(wnd);
y=GetClass(hwnd) == MENUBAR ? 2 : 1;
if ((ThisHelp=FindHelp(def)) != NULL)
{
dwnd=CreateWindow(TEXTBOX, NULL, GetClientLeft(hwnd), GetClientTop(hwnd)+y, min(ThisHelp->hheight, MAXHEIGHT)+3, ThisHelp->hwidth+2, NULL, wnd, NULL, HASBORDER | NOCLIP | SAVESELF);
if (dwnd != NULL)
{
clearBIOSbuffer();
/* Read the help text */
SeekHelpLine(ThisHelp->hptr, ThisHelp->bit);
while (TRUE)
{
clearBIOSbuffer();
if (GetHelpLine(hline) == NULL)
break;
if (*hline == '<')
break;
hline[strlen(hline)-1]='\0';
SendMessage(dwnd,ADDTEXT,(PARAM)hline,0);
}
SendMessage(dwnd, SHOW_WINDOW, 0, 0);
SendMessage(NULL, WAITKEYBOARD, 0, 0);
SendMessage(NULL, WAITMOUSE, 0, 0);
SendMessage(dwnd, CLOSE_WINDOW, 0, 0);
}
}
ThisHelp=HoldThisHelp;
}
/* ------ compare help names with wild cards ----- */
static BOOL wildcmp(char *s1, char *s2)
{
while (*s1 || *s2)
{
if (tolower(*s1) != tolower(*s2))
if (*s1 != '?' && *s2 != '?')
return TRUE;
s1++, s2++;
}
return FALSE;
}
/* --- ThisHelp=the help window matching specified name --- */
static struct helps *FindHelp(char *Help)
{
int i;
struct helps *thishelp=NULL;
for (i=0;i<HelpCount;i++)
{
if (wildcmp(Help, (FirstHelp+i)->hname) == FALSE)
{
thishelp=FirstHelp+i;
break;
}
}
return thishelp;
}
static int OverLap(int a, int b)
{
int ov=a-b;
if (ov<0)
ov=0;
return ov;
}
/* ----- compute the best location for a help dialogbox ----- */
static void BestFit(WINDOW wnd, DIALOGWINDOW *dwnd)
{
int above, below, right, left;
if (GetClass(wnd) == MENUBAR || GetClass(wnd) == APPLICATION)
{
dwnd->x=dwnd->y=-1;
return;
}
above=OverLap(dwnd->h, GetTop(wnd)); /* Compute above overlap */
below=OverLap(GetBottom(wnd), SCREENHEIGHT-dwnd->h); /* Compute below overlap */
right=OverLap(GetRight(wnd), SCREENWIDTH-dwnd->w); /* Compute right overlap */
left=OverLap(dwnd->w, GetLeft(wnd)); /* Compute left overlap */
if (above < below)
dwnd->y=max(0, GetTop(wnd)-dwnd->h-2);
else
dwnd->y=min(SCREENHEIGHT-dwnd->h, GetBottom(wnd)+2);
if (right < left)
dwnd->x=min(GetRight(wnd)+2, SCREENWIDTH-dwnd->w);
else
dwnd->x=max(0, GetLeft(wnd)-dwnd->w-2);
if (dwnd->x == GetRight(wnd)+2 || dwnd->x == GetLeft(wnd)-dwnd->w-2)
dwnd->y=-1;
if (dwnd->y ==GetTop(wnd)-dwnd->h-2 || dwnd->y == GetBottom(wnd)+2)
dwnd->x=-1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -