/* * Help * Provides support for the !Help application * * v. 1.00 (25 July 1993) * * © 1993-1998 Straylight */ /*----- Licensing note ----------------------------------------------------* * * This file is part of Straylight's Steel library. * * Steel 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, or (at your option) * any later version. * * Steel 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 Steel. If not, write to the Free Software Foundation, * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "wimp.h" #include "wimpt.h" #include "help.h" #include "msgs.h" #include "werr.h" #include #include #include static wimp_msgstr help__msg; static wimp_t help__hisHandle; static wimp_w help__window; static wimp_i help__icon; static char *help__transString= "-0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"; #define help__TRANSLEN 62 /* * void help_startHelp(void) * * Use * This call sets up a new message to bundle off to !Help. */ void help_startHelp(void) { wimp_eventstr *e=wimpt_last_event(); help__msg.hdr.size=256; help__msg.hdr.your_ref=e->data.msg.hdr.my_ref; help__msg.hdr.action=wimp_MHELPREPLY; help__msg.data.helpreply.text[0]='\0'; help__hisHandle=e->data.msg.hdr.task; help__window=e->data.msg.data.helprequest.m.w; help__icon=e->data.msg.data.helprequest.m.i; } /* * void help_addLine(char *line,...) * * Use * This call adds a line of text to the current help message. If the * message starts off blank, then the line will become the current message, * otherwise the message will have a '|m' followed by the new line appended * on the end. * * Parameters * char *line == a printf()-style format string. */ void help_addLine(char *line,...) { va_list ap; char buffer[255]; va_start(ap,line); vsprintf(buffer,line,ap); va_end(ap); if (help__msg.data.helpreply.text[0]=='\0') strcpy(help__msg.data.helpreply.text,buffer); else { strcat(help__msg.data.helpreply.text,"|m"); strcat(help__msg.data.helpreply.text,buffer); } } /* * void help_endHelp(void) * * Use * This call bundles off the current help message to the application. */ void help_endHelp(void) { help__msg.hdr.size=((sizeof(wimp_msghdr)+strlen(help__msg.data.helpreply.text)+1)&(~3))+4; wimpt_noerr(wimp_sendmessage(wimp_ESEND,&help__msg,help__hisHandle)); } /* * void help_readFromIcon(void) * * Use * This call will read a help message from the icon the help system is * interested in, and tack it on the end of the message. The help message * should be stored in the icon's validation string with the command 'H' * (e.g. validation string == "A0-9;B3;HType a number in this icon." * Alternatively, you can use a message-file tag, which will be looked up. */ void help_readFromIcon(void) { wimp_icon icn; char *vs; int i; char msg[255]; BOOL foundMsg=FALSE; BOOL doneMsg=FALSE; int msgIndex=0; char *mfl; if (help__icon<0) return; wimpt_noerr(wimp_get_icon_info(help__window,help__icon,&icn)); if ( (icn.flags&wimp_INDIRECT)==0 || (icn.flags&(wimp_ITEXT|wimp_ISPRITE))==wimp_ISPRITE || ((wimpt_options() & wimpt_ONOWIMPSHADE) && (icn.flags & 0x001f0000)==0x001f0000) || icn.data.indirecttext.validstring==(char *)-1 ) return; vs=icn.data.indirecttext.validstring; if (vs[0]=='H' || vs[0]=='h') { foundMsg=TRUE; vs++; } for (i=0;vs[i]>31;i++) { switch (vs[i]) { case '\\': if (vs[i+1]>31) { i++; if (foundMsg) msg[msgIndex++]=vs[i]; } break; case ';': if (foundMsg) { foundMsg=FALSE; doneMsg=TRUE; } if (vs[i+1]>31) { i++; switch (vs[i]) { case 'H': case 'h': if (!doneMsg) foundMsg=TRUE; break; } } break; default: if (foundMsg) msg[msgIndex++]=vs[i]; break; } } msg[msgIndex]='\0'; if (msg[0]) { mfl=msgs_lookup(msg); if (mfl) help_addLine("%s",mfl); else help_addLine("%s",msg); } } /* * BOOL help_wasHelp(void) * * Use * Informs caller if the last event was a help request. * * Returns * TRUE if it was. */ BOOL help_wasHelp(void) { wimp_eventstr *e=wimpt_last_event(); if ( (e->e==wimp_ESEND || e->e==wimp_ESENDWANTACK) && e->data.msg.hdr.action==wimp_MHELPREQUEST ) return (TRUE); else return (FALSE); } /* * void help_readFromMenu(char *prefix,int hit[]) * * Use * Converts the menu hit structure into a message tag and then reads the * message and adds it to the help message being constructed. * The message tag is constructed from the prefix, followed by a character * for each entry in the hit structure. The characters are in order (first * to last) 0-9,A-Z,a-z, giving 62 entries. This WILL be enough for any * *reasonable* menu... * * Parameters * char *prefix == * int hit[] == a menu hit structure as passed to a menu handler. */ void help_readFromMenu(char *prefix,int hit[]) { char tag[20]; int i=0; char *p; strcpy(tag,prefix); p=tag+strlen(tag); while (hit[i]) { if (hit[i]>=help__TRANSLEN) werr(TRUE,msgs_lookup("(help_readFromMenu, caller fault): menu event array out of range.")); *(p++)=help__transString[hit[i++]]; } *p=0; help_addLine("%s",msgs_lookup(tag)); }