Debian Codegraph @

texmf-dist/source/latex/grayhints/grayhints.dtx

raw
1 %\iffalse
2 % makeindex -s gglo.ist -o grayhints.gls grayhints.glo
3 % makeindex -s gind.ist -o grayhints.ind grayhints.idx
4 %<*copyright>
5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 %% grayhints.sty package, %%
7 %% Copyright (C) 2017--2018 %%
8 %% [email protected] %%
9 %% %%
10 %% This program can redistributed and/or modified under %%
11 %% the terms of the LaTeX Project Public License %%
12 %% Distributed from CTAN archives in directory %%
13 %% macros/latex/base/lppl.txt; either version 1.2 of the %%
14 %% License, or (at your option) any later version. %%
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16 %</copyright>
17 %<package>\NeedsTeXFormat{LaTeX2e}[1997/12/01]
18 %<package>\ProvidesPackage{grayhints}
19 %<package> [2018/11/01 v1.2 grayhints: Create gray hints in text fields]
20 %<*driver>
21 \documentclass{ltxdoc}
22 \usepackage{xcolor}
23 \usepackage[colorlinks,hyperindex=false]{hyperref}
24 \usepackage{grayhints}
25 %\pdfstringdefDisableCommands{\let\\\textbackslash}
26 \EnableCrossrefs
27 \CodelineIndex
28 \RecordChanges
29 \gdef\brpr#1{\texttt{\char123\relax#1\char125\relax}}
30 \let\darg\brpr
31 \let\env\texttt
32 \let\opt\texttt
33 \let\app\textsf
34 \let\pkg\textsf
35 \def\visispace{\symbol{32}}
36 \def\ameta#1{\ensuremath{\langle\textit{\texttt{#1}}\rangle}}
37 \def\meta#1{\textsl{\texttt{#1}}}
38 \def\SUB#1{\ensuremath{{}_{\mbox{\scriptsize\ttfamily#1}}}}
39 %\def\cs#1{\texttt{\bslash#1}}
40 \DeclareRobustCommand{\tmspace}[3]{%
41 \ifmmode\mskip#1#2\else\kern#1#3\fi\relax}
42 \renewcommand{\,}{\tmspace+\thinmuskip{.1667em}}
43 \let\thinspace\,
44 \renewcommand{\!}{\tmspace-\thinmuskip{.1667em}}
45 \let\negthinspace\!
46 \renewcommand{\:}{\tmspace+\medmuskip{.2222em}}
47 \let\medspace\:
48 \newcommand{\negmedspace}{\tmspace-\medmuskip{.2222em}}
49 \renewcommand{\;}{\tmspace+\thickmuskip{.2777em}}
50 \let\thickspace\;
51 \newcommand{\negthickspace}{\tmspace-\thickmuskip{.2777em}}
52 \makeatletter
53 \renewcommand{\paragraph}
54 {\@startsection{paragraph}{4}{0pt}{6pt}{-3pt}
55 {\normalfont\normalsize\bfseries}}
56 \renewenvironment{quote}[1][]
57 {\def\@rgi{#1}\ifx\@rgi\@empty
58 \let\rghtm\@empty\else\def\rghtm{\rightmargin\leftmargin}\fi
59 \list{}{\rghtm} %{\rightmargin\leftmargin}%
60 \item\relax}
61 {\endlist}
62 \makeatother
63 \InputIfFileExists{aebdocfmt.def}{\PackageInfo{grayhints}{Inputting aebdocfmt.def}}
64 {\def\IndexOpt{\DescribeMacro}\def\IndexKey{\DescribeMacro}\let\setupFullwidth\relax
65 \PackageInfo{grayhints}{aebdocfmt.def cannot be found}}
66 \begin{document}
67 \def\CMD#1{\textbackslash#1}
68 \GetFileInfo{grayhints.sty}
69 \title{\textsf{grayhints}: Create gray hints in text fields}
70 \author{D. P. Story\\
71 Email: \texttt{[email protected]}}
72 \date{processed \today}
73 \maketitle
74 \tableofcontents
75 \let\Email\texttt
76 \DocInput{grayhints.dtx}
77 \IfFileExists{\jobname.ind}{\newpage\setupFullwidth\par\PrintIndex}{\paragraph*{Index} The index goes here.\\Execute
78 \texttt{makeindex -s gind.ist -o grayhints.ind grayhints.idx}\\on the command line and recompile
79 \texttt{grayhints.dtx}.}
80 \IfFileExists{\jobname.gls}{\PrintChanges}{\paragraph*{Change History} The list of changes goes here.\\Execute
81 \texttt{makeindex -s gglo.ist -o grayhints.gls grayhints.glo}\\on the command line and recompile
82 \texttt{grayhints.dtx}.}
83 \end{document}
84 %</driver>
85 % \fi
86 % \MakeShortVerb{|}
87 %
88 % \InputIfFileExists{aebdonotindex.def}{\PackageInfo{web}{Inputting aebdonotindex.def}}
89 % {\PackageInfo{web}{cannot find aebdonotindex.def}}
90 %
91 % \begin{macrocode}
92 %<*package>
93 % \end{macrocode}
94 % \changes{v1.2}{2018/11/01}{Revisions to support PDF-XChange Editor}
95 % \changes{v1.1}{2018/10/04}{Modify \string\cs{FmtToGray}, \string\cs{FocusToBlack}, and
96 % \string\cs{BlurToBlack} for better behavior when entry is left empty}
97 % \section{Description}\previewOff
98 % We often see in HTML pages or compiled executable applications, form fields (text fields, input fields)
99 % that require user input. The untouched field has text within it that informs the user
100 % of the nature of the data to be entered into the field. This `grayed hint' immediately
101 % disappears when the user focuses the cursor on the field. Lest I be accused of being too obtuse, we
102 % illustrate with an example or two.
103 %\begin{quote}\small
104 %\def\myDateFmt{yyyy/mm/dd}
105 % \textField[\textColor{\matchGray}
106 % \TU{Enter your first name so I can get to know you better}
107 % \AA{\AAFormat{\FmtToGray{First Name}}
108 % \AAKeystroke{\KeyToGray}
109 % \AAOnFocus{\JS{\FocusToBlack}}
110 % \AAOnBlur{\JS{\BlurToBlack}}
111 % \AACalculate{\CalcToGray}
112 % }]{NameFirst}{2in}{11bp}\vcgBdry[\medskipamount]
113 % \textField[\textColor{\matchGray}
114 % \TU{Enter your favorite date, in the indicated format}
115 % \AA{\AAKeystroke{\DateKeyEx("\myDateFmt");\KeyToGray}
116 % \AAFormat{\DateFmtEx("\myDateFmt");\jsR\FmtToGray{\myDateFmt}}
117 % \AAOnFocus{\JS{\FocusToBlack}}
118 % \AAOnBlur{\JS{\BlurToBlack}}
119 % \AACalculate{\CalcToGray}
120 % }]{DateField}{1in}{11bp}\cgBdry[1.5em]
121 % \pushButton[\CA{Reset}
122 % \TU{Press to clear to clear all fields.}
123 % \A{\JS{this.resetForm();}}]{reset}{}{11bp}
124 %\end{quote}
125 % Of course, the usual tool tips may also be provided.\medskip
126 %
127 % \noindent It is not natural for Adobe form fields to do this, it takes a lot of support code for
128 % it to work properly; the Keystroke, Format, OnFocus, OnBlur, and Calculate events are needed. The
129 % verbatim listing of the first example field above is,
130 %
131 %\begin{quote}\small
132 %|\textField[\textColor{\matchGray}|\\
133 %| \TU{Enter your first name so I can get to know you better}|\\
134 %| \AA{\AAFormat{\FmtToGray{First Name}}|\\
135 %| \AAKeystroke{\KeyToGray}|\\
136 %| \AAOnFocus{\JS{\FocusToBlack}}|\\
137 %| \AAOnBlur{\JS{\BlurToBlack}}|\\
138 %| \AACalculate{\CalcToGray} %<-| required if using PDF-XChange Editor\\
139 %|}]{NameFirst}{2in}{11bp}|
140 %\end{quote}
141 % Code snippets are inserted into the Keystroke, Format,
142 % OnFocus, OnBlur, and Calculate events.
143 %
144 % \paragraph*{Demo files:} Four sample files are provided: \texttt{gh-eforms.tex}, \texttt{gh-hyperref.tex},
145 % \texttt{gh-fmts-eforms.tex}, and \texttt{gh-fmts-hyperref.tex}.
146 %
147 % \section{Documentation and Code}
148 %
149 % The \pkg{eforms} package is preferred, but you can use the form field macros of \pkg{hyperref}.
150 % Any unrecognized options specified for the \pkg{grayhints} package
151 % are passed on to \pkg{insdljs}. If the document
152 % author does not want to use \pkg{eforms}, he/she can pass the option \opt{usehyforms}\IndexOpt{usehyforms} to use the form
153 % fields of \pkg{hyperref}, in this case \pkg{insdljs} is required. For the last option, \opt{nodljs}
154 % is for users of \pkg{hyperref} forms who do not want to use \pkg{insdljs}. In the latter case,
155 % the option \opt{usehyforms} should not be used for that will include \pkg{insdljs}.
156 % \begin{macrocode}
157 \DeclareOption{usehyforms}{%
158 \def\FormsRequirement{\RequirePackage{insdljs}[2017/03/02]}}
159 \def\FormsRequirement{\RequirePackage{eforms}[2017/02/27]}
160 % \end{macrocode}
161 % The \IndexOpt{usealtadobe}\opt{usealtadobe} option is deprecated, the function definitions
162 % are automatically loaded unless the \opt{nocalcs} or \opt{nodljs} option is taken.
163 % \changes{v1.1}{2018/10/04}{Deprecated the \string\opt{usealtadobe} option, now automatically loaded}
164 % \begin{macrocode}
165 \DeclareOption{usealtadobe}{\PackageWarningNoLine{grayhints}
166 {The `usealtadobe' option is now deprecated.\MessageBreak
167 The alternate functions are automatically loaded.\MessageBreak
168 Please remove this grayhints package option}}
169 % \end{macrocode}
170 % \leavevmode\IndexOpt{nocalcs} If this option is taken, the document
171 % JavaScript function \texttt{AllowCalc()} is not embedded in the document. The
172 % implications are that you are not using any calculation fields.
173 % \begin{macrocode}
174 \DeclareOption{nocalcs}{\let\nocalcs\endinput}
175 \let\nocalcs\relax
176 % \end{macrocode}
177 % \leavevmode\IndexOpt{nodljs} When this option is specified, there are no
178 % requirements placed on this package; that is, neither \pkg{eforms}
179 % nor \pkg{insdljs} are required.
180 % \begin{macrocode}
181 \DeclareOption{nodljs}{\let\FormsRequirement\relax
182 \let\nodljsend\endinput}
183 \let\nodljsend\relax
184 \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{insdljs}}
185 \ProcessOptions
186 \FormsRequirement
187 % \end{macrocode}
188 % We include \texttt{eqcolor.def}, a component of \pkg{exerquiz} to help parse colors,
189 % and to match JS colors with PDF colors.
190 % \begin{macrocode}
191 \@ifundefined{jsColor}{\let\eq@YES=y\let\eq@NO=n%
192 \InputIfFileExists{eqcolor.def}
193 {\PackageInfo{grayhints}{Inputting eqcolor.def from exerquiz}}
194 {\PackageError{grayhints}{cannot find eqcolor.def belonging
195 to exerquiz}{Refresh your file name database and try again.}}
196 }{}
197 % \end{macrocode}
198 %
199 % \subsection{JavaScript snippets for Field JavaScript}
200 % Code snippets are inserted in to the Format, Calculate,
201 % OnFocus, and OnBlur events, as illustrated above.
202 %
203 % \begin{macro}{\normalGrayColors}\hspace{-\marginparsep}\thinspace
204 % \darg{\ameta{normalcolor}}\darg{\ameta{graycolor}} There are two colors
205 % in play, the normal color of the text field (\ameta{normalcolor}) and
206 % the color of the ``grayed'' text (\ameta{graycolor}). We set the defaults
207 % to \texttt{color.black} and \texttt{color.ltGray}, respectively. The two parameters
208 % are JavaScipt colors: array type \texttt{["RGB", 1, 0, 0]}, or predefined type
209 % \texttt{color.blue}. The command \cs{jsColor} is used to assign colors (taken from
210 % \texttt{eqcolor.def} of \pkg{exerquiz}).
211 % \begin{macrocode}
212 \newcommand{\normalGrayColors}[2]{\def\gh@rgi{#1}\def\gh@rgii{#2}%
213 \ifx\gh@rgi\@empty\else
214 \jsColor\gh@normalcolor{#1}\gh@chkTr@nsparency\fi
215 \ifx\gh@rgii\@empty\else\jsColor\gh@graycolor{#2}\m@tchGray\fi}
216 \def\gh@normalcolor{}\def\gh@graycolor{}
217 \AtEndOfPackage{\normalGrayColors{color.black}{color.ltGray}}
218 % \end{macrocode}
219 % \end{macro}
220 % There are several predefined JavaScript colors the user can specify. We need to
221 % convert them to PDF color too.
222 % \begin{macrocode}
223 \definecolor{ltGray}{gray}{0.75}
224 \definecolor{gray}{gray}{.5}
225 \definecolor{dkGray}{gray}{.25}
226 \def\gh@pd@transparent{ltGray}\def\gh@transparent{transparent}
227 \def\gh@pd@black{black}\def\gh@pd@white{white}
228 \def\gh@pd@dkGray{dkGray}\def\gh@pd@gray{gray}\def\gh@pd@ltGray{ltGray}
229 \def\gh@pd@red{red}\def\gh@pd@green{green}\def\gh@pd@blue{blue}
230 \def\gh@pd@cyan{cyan}\def\gh@pd@magenta{magenta}
231 \def\gh@pd@yellow{yellow}
232 % \end{macrocode}
233 % Convert the JS color for \cs{gh@graycolor} to a matching PDF color that can be
234 % used by the \cs{textColor} property of a form field. Here, we use commands defined
235 % in the \texttt{eqcolor.def} file from \pkg{exerquiz}. This command defines the user
236 % command \DescribeMacro{\matchGray}\cs{matchGray}.
237 % \begin{macrocode}
238 \def\m@tchGray{\eq@checkRawJSColor{\gh@graycolor}%
239 \ifx\eqpredefineJSCol\eq@NO
240 % \end{macrocode}
241 % \cs{gh@graycolor} is a JavaScript array
242 % \begin{macrocode}
243 \let\matchGray\@empty
244 \expandafter\gh@extr@ctJSModelInfo\gh@graycolor\@nil
245 \ifx\@rgi\@empty\else\edef\matchGray{\@rgi}\fi
246 \ifx\@rgii\@empty\else\edef\matchGray{\matchGray\space\@rgii}\fi
247 \ifx\@rgiii\@empty\else
248 \edef\matchGray{\matchGray\space\@rgiii}\fi
249 \ifx\@rgiv\@empty\else\edef\matchGray{\matchGray\space\@rgiv}\fi
250 \else
251 % \end{macrocode}
252 % \cs{gh@graycolor} is a predefined color (\texttt{color.ltGray})
253 % \begin{macrocode}
254 \expandafter\gh@getColorFromPrefined\gh@graycolor\@nil
255 \@ifundefined{gh@pd@\pd@color}{%
256 \def\gh@graycolor{color.ltGray}\def\pd@color{ltGray}%
257 \PackageWarning{grayhints}
258 {The color.\pd@color\space is undefined,\MessageBreak
259 substituting color.ltGray}}{\ifx\pd@color\gh@transparent
260 \def\gh@graycolor{color.ltGray}\def\pd@color{ltGray}%
261 \PackageWarning{grayhints}
262 {A transparent color is not supported,\MessageBreak
263 using color.ltGray instead}\fi
264 }%
265 \edef\matchGray{\@nameuse{gh@pd@\pd@color}}%
266 \fi}
267 \def\gh@chkTr@nsparency{\eq@checkRawJSColor{\gh@normalcolor}%
268 \ifx\eqpredefineJSCol\eq@YES
269 \expandafter\gh@getColorFromPrefined\gh@normalcolor\@nil
270 \@ifundefined{gh@pd@\pd@color}{\def\gh@normalcolor{color.black}%
271 \PackageWarning{grayhints}
272 {The color.\pd@color\space is undefined,\MessageBreak
273 substituting color.black}}{}%
274 \ifx\pd@color\gh@transparent\def\gh@normalcolor{color.black}%
275 \PackageWarning{grayhints}
276 {A transparent color is not supported,\MessageBreak
277 using color.black instead}\fi
278 \fi
279 }
280 % \end{macrocode}
281 % Various supporting macros to extract information.
282 % \begin{macrocode}
283 \def\gh@extr@ctJSModelInfo[#1,#2]\@nil{%
284 \gh@getspecv@lues#2,,,,\@nil}%
285 \def\gh@getspecv@lues#1,#2,#3,#4,#5\@nil{%
286 \def\@rgi{#1}\def\@rgii{#2}\def\@rgiii{#3}\def\@rgiv{#4}}
287 \def\gh@getColorFromPrefined color.#1\@nil{\def\pd@color{#1}}
288 \def\gh@PriorFormat{event.target.savevalue=event.value;\jsR}
289 % \end{macrocode}
290 % \DescribeMacro{\FailStringDef} provides a helpful string when the user enters an improper string.
291 % This is a language localization command.
292 % \changes{v1.2}{2018/11/01}{Added \string\cs{FailStringDef}}
293 % \begin{macrocode}
294 \newcommand\FailStringDef{continue editing}
295 % \end{macrocode}
296 % \DescribeMacro{\EnterCommitFailDef} Sets the code for \cs{FailStringDef}.
297 % \changes{v1.2}{2018/11/01}{Added \string\cs{EnterCommitFailDef}}
298 % \begin{macrocode}
299 \newcommand\EnterCommitFailDef{event.value=("\FailStringDef");}
300 % \end{macrocode}
301 % \DescribeMacro{\EnterCommitFailEvent} Sets the action when the user uses the \textsf{Enter} key to
302 % commit date, and the data is not validated.
303 % \changes{v1.2}{2018/11/01}{Added \string\cs{EnterCommitFailDef}}
304 % \begin{macrocode}
305 \def\EnterCommitFailEvent#1{\def\@rgi{#1}\ifx\@rgi\@empty
306 \def\gh@ECFE{\EnterCommitFailDef}\else\def\gh@ECFE{#1}\fi}
307 \EnterCommitFailEvent{}
308 % \end{macrocode}
309 % \DescribeMacro{\CommitSuccessEvent} Set what happens when entering a valid string into a formatting text field
310 % \changes{v1.2}{2018/11/01}{Added \string\cs{CommitSuccessEvent}}
311 % \begin{macrocode}
312 \def\CommitSuccessEvent#1{\def\@rgi{#1}\ifx\@rgi\@empty
313 \let\gh@CSE\jsR\else\def\gh@CSE{\jsR\jsT #1\jsR}\fi}
314 \let\gh@CSE\jsR
315 % \end{macrocode}
316 % \begin{macro}{\FmtToGray}\hspace{-\marginparsep}\thinspace
317 % \darg{\ameta{grayhint}} This command is placed in the Format event. It places the hint
318 % \ameta{grayhint} as the formatting text string when the field is empty.
319 % If a built-in Adobe function is also used, use \cs{FmtToGray} after it; for example,
320 % \begin{quote}\small
321 % |\AAFormat{AFNumber_Format(0,1,0,0,"",true);|\\
322 % |\FmtToGray{|\ameta{grayhint}|}}|
323 % \end{quote}
324 % \begin{macrocode}
325 \newcommand\FmtToGray[1]{%
326 if(typeof event.target.savevalue=="undefined"){\jsR\jsT
327 event.target.savevalue="";\jsR\jsT
328 event.target.success=false;\jsR
329 }\jsR
330 if(typeof event.target.ghBuiltin=="undefined")%
331 event.target.ghBuiltin=false;\jsR
332 if(!event.target.ghBuiltin)\gh@PriorFormat
333 event.target.ghBuildtin=false;\jsR\gh@FmtToGray{#1}}
334 \def\gh@FmtToGray#1{%
335 if(typeof event.target.saverc=="undefined")%
336 event.target.saverc=true;\jsR
337 if(!event.target.saverc||event.value==""){\jsR\jsT
338 if(event.target.savevalue!=""&&%
339 !event.target.success){\jsR\jsT\gh@ECFE\jsR\jsT
340 % \end{macrocode}
341 % Here is the only PDF dependent code. The event sequence of close to but not exactly the
342 % same as the event sequence for the Adobe PDF viewers, we must insert the following two
343 % lines of code to make things work for \app{PDF-XChange Editor}.
344 % \begin{macrocode}
345 if(typeof app.pxceInfo!="undefined")%
346 event.target.savevalue="";\jsR\jsT
347 } else {\jsR\jsT\jsT
348 event.target.success=false;\jsR\jsT\jsT
349 event.value=("#1");\jsT\gh@CSE\jsT}\jsR
350 } else {\jsR\jsT
351 event.target.success=true;\gh@CSE}
352 }
353 % \end{macrocode}
354 % \end{macro}
355 % \begin{macro}{\KeyToGray}
356 % This command is placed in the Keystroke event. It changes
357 % the color to `gray' (\cs{gh@graycolor}) if the field is empty.
358 % If a built-in Adobe function is also used, use \cs{KeyToGray} after it; for example,
359 % \begin{quote}\small
360 % |\AAFormat{AFNumber_Keystroke(0,1,0,0,"",true);|\\
361 % |\KeyToGray}|
362 % \end{quote}
363 % \begin{macrocode}
364 \newcommand\KeyToGray{%
365 if(event.willCommit&&event.value!=""&&!event.rc)\jsR\jsT
366 event.target.success=false;\jsR
367 event.target.saverc=event.rc;\jsR
368 event.rc=true;\jsR
369 if(event.willCommit&&event.value=="")%
370 event.target.textColor=\gh@graycolor;\jsR
371 if(event.willCommit)%
372 event.target.savevalue=event.value;
373 }
374 % \end{macrocode}
375 % \end{macro}
376 % \begin{macro}{\CalcToGray}
377 % The \cs{CalcToGray} is a Calculate script, it is needed only in a form field that performs
378 % a calculation. If a built-in Adobe function is also used, use \cs{KeyToGray} after it; for example,
379 %\begin{quote}\small
380 % |\AACalculate{var cArray=new Array("Integer");\jsR|\\
381 % |if (AllowCalc(cArray)) AFSimple_Calculate("SUM", cArray );\jsR|\\
382 % |\CalcToGray}|
383 %\end{quote}
384 % If the target population might use \app{PDF-XChange Editor}, whose features closely mimic those of
385 % \app{Adobe Acrobat Reader}, the use of \cs{CalcToGray} is recommended in all fields.
386 % \begin{macrocode}
387 \newcommand\CalcToGray{event.target.textColor=%
388 (event.value=="")?\gh@graycolor:\gh@normalcolor;}
389 % \end{macrocode}
390 % \end{macro}
391 % \begin{macro}{\FocusToBlack}
392 % A command placed within the OnFocus event. When the field comes into focus, and
393 % the field is empty, the color for the text is turned to black. This can be redefined
394 % to another color.
395 %
396 % \item (2018/10/04) We increase the complexity with the goal of getting a better user experience.
397 % \begin{macrocode}
398 \newcommand\FocusToBlack{%
399 if (typeof event.target.success=="undefined")%
400 event.target.success=false;\jsR
401 if(event.target.valueAsString==""%
402 ||!event.target.success)\jsR\jsT
403 event.target.textColor=\gh@normalcolor;
404 }
405 % \end{macrocode}
406 % \end{macro}
407 % \begin{macro}{\BlurToBlack}
408 % A command placed within the OnBlur event. It sets the text color to gray or black,
409 % depending on whether the field is empty or not. My be redefined with different colors.
410 %
411 % \item (2018/10/04) We increase the complexity with the goal of getting a better user experience.
412 % \begin{macrocode}
413 \newcommand\BlurToBlack{%
414 if (!event.target.success||event.target.valueAsString=="")\jsR\jsT
415 this.resetForm(event.target.name);\jsR
416 event.target.savevalue="";\jsR
417 event.target.textColor=(!event.target.success||%
418 event.target.valueAsString=="")?\gh@graycolor:\gh@normalcolor;
419 }
420 % \end{macrocode}
421 % \end{macro}
422 %
423 % \subsection{\texorpdfstring{\LaTeX}{LaTeX} commands for built-in functions}
424 % We define a series of commands as a convenience to the user. The arguments of each
425 % are the JavaScript argument enclosed in parentheses.\medskip\par
426 % \noindent
427 % \DescribeMacro{\NumKey}\cs{NumKey} for processing keystrokes for numbers, and \DescribeMacro{\NumFmt}
428 % \cs{NumFmt} formats a number according to its arguments.
429 % \begin{macrocode}
430 \def\NumKey{EFNumber_Keystroke}
431 \def\NumFmt(#1){try{EFNumber_Format(#1)}catch(e){}}
432 % \end{macrocode}
433 % \DescribeMacro{\DateKey}\cs{DateKey} and \DescribeMacro{\DateFmt}\cs{DateFmt} process the keystroke
434 % and format events for a date.
435 % \begin{macrocode}
436 \def\DateKey{EFDate_Keystroke}
437 \def\DateFmt(#1){%
438 AFDate_Format(#1);\jsR
439 event.target.ghBuiltin=true;
440 }
441 % \end{macrocode}
442 % \DescribeMacro{\DateKeyEx}\cs{DateKeyEx} and \DescribeMacro{\DateFmtEx}\cs{DateFmtEx} process the keystroke
443 % and format events for a date.
444 % \begin{macrocode}
445 \def\DateKeyEx{EFDate_KeystrokeEx}
446 \def\DateFmtEx(#1){%
447 AFDate_FormatEx(#1);\jsR
448 event.target.ghBuiltin=true;
449 }
450 % \end{macrocode}
451 % \DescribeMacro{\PercentKey}\cs{PercentKey} and \DescribeMacro{\PercentFmt}\cs{PercentFmt} process the keystroke
452 % and format events for a number represented as a percentage.
453 % \begin{macrocode}
454 \def\PercentKey{EFPercent_Keystroke}
455 \def\PercentFmt(#1){%
456 % \end{macrocode}
457 % Avoid the dreaded ``0.00\%'' when the field is blank
458 % \begin{macrocode}
459 if(event.value!=""||%
460 (typeof event.target.savevalue!="undefined"&&%
461 event.target.savevalue!=""))%
462 AFPercent_Format(#1);\jsR
463 event.target.ghBuiltin=true;
464 }
465 % \end{macrocode}
466 % \DescribeMacro{\TimeKey}\cs{TimeKey}, \DescribeMacro{\TimeFmt}\cs{TimeFmt}, and
467 % \DescribeMacro{\TimeFmtEx}\cs{TimeFmtEx} process the keystroke
468 % and format events for a time.
469 % \begin{macrocode}
470 \def\TimeKey{EFTime_Keystroke}\def\TimeFmt{EFTime_Format}
471 \def\TimeFmtEx(#1){try{EFTime_FormatEx(#1)}catch(e){}}
472 % \end{macrocode}
473 % \DescribeMacro{\SpecialKey}\cs{SpecialKey}, \DescribeMacro{\SpecialKeyEx}\cs{SpecialKeyEx}, and
474 % \DescribeMacro{\SpecialFmt}\cs{SpecialFmt} process the keystroke
475 % and format events for a special format.
476 % \begin{macrocode}
477 \def\SpecialKey{EFSpecial_Keystroke}
478 \def\SpecialKeyEx{EFSpecial_KeystrokeEx}
479 \def\SpecialFmt(#1){try{EFSpecial_Format(#1)}catch(e){}}
480 % \end{macrocode}
481 % \DescribeMacro{\RangeValidate}\cs{RangeValidate}, \DescribeMacro{\SimpleCalc}\cs{SimpleCalc}, and
482 % \DescribeMacro{\MergeChange}\cs{\MergeChange} are specialized JS functions for setting a range
483 % resstriction in the validate event, for making a simple calculation in the calculate event, and
484 % a general purpose function to merging the current keystroke with event.value, valid for the keystroke
485 % event.
486 % \begin{macrocode}
487 \def\RangeValidate{EFRange_Validate}
488 \def\SimpleCalc{EFSimple_Calculate}
489 \def\MergeChange{EFMergeChange}
490 % \end{macrocode}
491 % \subsection{Document JavaScript to support gray hints}
492 % The alternate names adobe built-in need to be used for any format function; the normal
493 % built-in function names can be otherwise be used.
494 % \begin{macrocode}
495 \nodljsend
496 \begin{insDLJS}{altadbfncs}{gh: Support for Adobe built-in functions}
497 var EFNumber_Keystroke=AFNumber_Keystroke;
498 function EFNumber_Format(){
499 event.target.savevalue=event.value;
500 event.target.ghBuiltin=true;
501 AFNumber_Format.apply(null,arguments);
502 }
503 var EFDate_Keystroke=AFDate_Keystroke;
504 function EFDate_Format(){
505 event.target.savevalue=event.value;
506 event.target.ghBuiltin=true;
507 AFDate_Format.apply(null,arguments);
508 }
509 var EFDate_KeystrokeEx=AFDate_KeystrokeEx;
510 function EFDate_FormatEx(){
511 event.target.savevalue=event.value;
512 event.target.ghBuiltin=true;
513 AFDate_FormatEx.apply(null,arguments);
514 }
515 var EFPercent_Keystroke=AFPercent_Keystroke;
516 function EFPercent_Format(){
517 event.target.savevalue=event.value;
518 event.target.ghBuiltin=true;
519 AFPercent_Format.apply(null,arguments);
520 }
521 var EFTime_Keystroke=AFTime_Keystroke;
522 function EFTime_Format(){
523 event.target.savevalue=event.value;
524 event.target.ghBuiltin=true;
525 AFTime_Format.apply(null,arguments);
526 }
527 function EFTime_FormatEx(){
528 event.target.savevalue=event.value;
529 ghBuiltin=true;
530 AFTime_FormatEx.apply(null,arguments);
531 }
532 var EFSpecial_Keystroke=AFSpecial_Keystroke;
533 var EFSpecial_KeystrokeEx=AFSpecial_KeystrokeEx;
534 function EFSpecial_Format(){
535 event.target.savevalue=event.value;
536 event.target.ghBuiltin=true;
537 AFSpecial_Format.apply(null,arguments);
538 }
539 var EFRange_Validate=AFRange_Validate;
540 var EFSimple_Calculate=AFSimple_Calculate;
541 var EFMergeChange=AFMergeChange;
542 \end{insDLJS}
543 % \end{macrocode}
544 % \cs{nocalcs} is \cs{relax} unless the \opt{nocalcs} option is taken, in which case
545 % it is \cs{let} to \cs{endinput}.
546 % \begin{macrocode}
547 \nocalcs
548 \begin{insDLJS}{ghsupport}{gh: Support for the Calculate Event}
549 % \end{macrocode}
550 % In order to get the gray hints to appear in the terminal field of a calculation group,
551 % we cannot perform the calculate when all the dependent fields are empty. \texttt{cArray}
552 % is an array of all dependent fields involved in the calculation. The use of this function
553 % is illustrated in \texttt{gh-eforms.tex} and \texttt{gh-hyperref.tex}.
554 % \begin{macrocode}
555 function AllowCalc(cArray) {
556 var f,g;
557 for (var i=0; i<cArray.length; i++) {
558 f=this.getField(cArray[i]);
559 g=f.getArray();
560 for (var j=0; j<g.length; j++)
561 if (g[j].valueAsString!="") return true;
562 }
563 return false;
564 }
565 \end{insDLJS}
566 % \end{macrocode}
567 % \begin{macrocode}
568 %</package>
569 % \end{macrocode}
570 \endinput