3 * Provides support for the !Help application
5 * v. 1.00 (25 July 1993)
7 * © 1993-1998 Straylight
10 /*----- Licensing note ----------------------------------------------------*
12 * This file is part of Straylight's Steel library.
14 * Steel is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * Steel is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Steel. If not, write to the Free Software Foundation,
26 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 static wimp_msgstr help__msg;
39 static wimp_t help__hisHandle;
40 static wimp_w help__window;
41 static wimp_i help__icon;
43 static char *help__transString=
45 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
46 "abcdefghijklmnopqrstuvwxyz";
48 #define help__TRANSLEN 62
51 * void help_startHelp(void)
54 * This call sets up a new message to bundle off to !Help.
57 void help_startHelp(void)
59 wimp_eventstr *e=wimpt_last_event();
60 help__msg.hdr.size=256;
61 help__msg.hdr.your_ref=e->data.msg.hdr.my_ref;
62 help__msg.hdr.action=wimp_MHELPREPLY;
63 help__msg.data.helpreply.text[0]='\0';
64 help__hisHandle=e->data.msg.hdr.task;
65 help__window=e->data.msg.data.helprequest.m.w;
66 help__icon=e->data.msg.data.helprequest.m.i;
70 * void help_addLine(char *line,...)
73 * This call adds a line of text to the current help message. If the
74 * message starts off blank, then the line will become the current message,
75 * otherwise the message will have a '|m' followed by the new line appended
79 * char *line == a printf()-style format string.
82 void help_addLine(char *line,...)
87 vsprintf(buffer,line,ap);
89 if (help__msg.data.helpreply.text[0]=='\0')
90 strcpy(help__msg.data.helpreply.text,buffer);
93 strcat(help__msg.data.helpreply.text,"|m");
94 strcat(help__msg.data.helpreply.text,buffer);
99 * void help_endHelp(void)
102 * This call bundles off the current help message to the application.
105 void help_endHelp(void)
107 help__msg.hdr.size=((sizeof(wimp_msghdr)+strlen(help__msg.data.helpreply.text)+1)&(~3))+4;
108 wimpt_noerr(wimp_sendmessage(wimp_ESEND,&help__msg,help__hisHandle));
112 * void help_readFromIcon(void)
115 * This call will read a help message from the icon the help system is
116 * interested in, and tack it on the end of the message. The help message
117 * should be stored in the icon's validation string with the command 'H'
118 * (e.g. validation string == "A0-9;B3;HType a number in this icon."
119 * Alternatively, you can use a message-file tag, which will be looked up.
122 void help_readFromIcon(void)
134 wimpt_noerr(wimp_get_icon_info(help__window,help__icon,&icn));
137 (icn.flags&wimp_INDIRECT)==0 ||
138 (icn.flags&(wimp_ITEXT|wimp_ISPRITE))==wimp_ISPRITE ||
139 ((wimpt_options() & wimpt_ONOWIMPSHADE) &&
140 (icn.flags & 0x001f0000)==0x001f0000) ||
141 icn.data.indirecttext.validstring==(char *)-1
144 vs=icn.data.indirecttext.validstring;
145 if (vs[0]=='H' || vs[0]=='h')
150 for (i=0;vs[i]>31;i++)
159 msg[msgIndex++]=vs[i];
183 msg[msgIndex++]=vs[i];
190 mfl=msgs_lookup(msg);
192 help_addLine("%s",mfl);
194 help_addLine("%s",msg);
199 * BOOL help_wasHelp(void)
202 * Informs caller if the last event was a help request.
208 BOOL help_wasHelp(void)
210 wimp_eventstr *e=wimpt_last_event();
214 e->e==wimp_ESENDWANTACK) &&
215 e->data.msg.hdr.action==wimp_MHELPREQUEST
223 * void help_readFromMenu(char *prefix,int hit[])
226 * Converts the menu hit structure into a message tag and then reads the
227 * message and adds it to the help message being constructed.
228 * The message tag is constructed from the prefix, followed by a character
229 * for each entry in the hit structure. The characters are in order (first
230 * to last) 0-9,A-Z,a-z, giving 62 entries. This WILL be enough for any
231 * *reasonable* menu...
235 * int hit[] == a menu hit structure as passed to a menu handler.
238 void help_readFromMenu(char *prefix,int hit[])
247 if (hit[i]>=help__TRANSLEN)
248 werr(TRUE,msgs_lookup("(help_readFromMenu, caller fault): menu event array out of range."));
249 *(p++)=help__transString[hit[i++]];
252 help_addLine("%s",msgs_lookup(tag));