summaryrefslogtreecommitdiff
path: root/texmf-dist/tex/latex/popupmenu/popupmenu.sty
blob: c22027550c87a60e8923524914193a64f7ad921b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
%%
%% This is file `popupmenu.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% popupmenu.dtx  (with options: `copyright,package')
%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% popupmenu.sty package,                               %%
%% Copyright (C) 2009--2020                             %%
%%   dpstory@acrotex.net                                %%
%%                                                      %%
%% This program can redistributed and/or modified under %%
%% the terms of the LaTeX Project Public License        %%
%% Distributed from CTAN archives in directory          %%
%% macros/latex/base/lppl.txt; either version 1 of the  %%
%% License, or (at your option) any later version.      %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{popupmenu}
 [2020/07/26 v1.2 Provides support for popup menus (dps)]
\RequirePackage{xkeyval}
\newif\iftrackingPU \trackingPUfalse
\DeclareOptionX{tracking}{\trackingPUtrue\def\puTracking{true}}
\DeclareOptionX{!tracking}{\trackingPUfalse\def\puTracking{false}}
\def\puTracking{false}
\ProcessOptionsX\relax
\edef\pu@restoreCats{%
  \catcode`\noexpand\"=\the\catcode`\"\relax
  \catcode`\noexpand\'=\the\catcode`\'\relax
  \catcode`\noexpand\,=\the\catcode`\,\relax
  \catcode`\noexpand\!=\the\catcode`\!\relax
}
\@makeother\"\@makeother\'\@makeother\,\@makeother\!
\RequirePackage{eforms}
\def\title@dash{-}\def\puNone{none}
\define@key{menustruct}{title}[]{\Hy@unicodefalse
  \let\btitle@dash\ef@NO
  \def\@rgi{#1}\ifx\@rgi\title@dash\let\btitle@dash\ef@YES\fi
  \pdfstringdef\menustruct@title{#1}}
\define@boolkey{menustruct}{marked}[true]{}
\define@boolkey{menustruct}{enabled}[true]{}
\define@key{menustruct}{return}[]{\def\menustruct@return{#1}\relax
  \ifx\menustruct@return\puNone\def\menustruct@return{null}\fi}
\let\pum@holdtoks\@empty
\let\pum@holdtoksEx\@empty
\def\@AddToMenuToks{\g@addto@macro\pum@holdtoks}
\def\@AddToMenuToksEx{\g@addto@macro\pum@holdtoksEx}
\newcount\pum@cnt
\def\pum@updateindex{\global\advance\pum@cnt\@ne
   \edef\pum@rc{\pum@topindex[\the\pum@cnt]}\edef\itemindex{'\pum@rc'}}
\def\pum@initIndexMenu#1{\global\pum@cnt=\m@ne\edef\pum@rc{#1}%
   \edef\pum@topindex{\pum@rc}}
\newcount\submenuLevel \submenuLevel\z@
\newenvironment{popupmenu}[1]{\pum@initIndexMenu{}\submenuLevel\z@
  \ifpdfmarkup
    \def\textbackslash{\eqbs}\relax
    \def\Esc{\textbackslash}\relax
    \def\csiv{\eqbs\eqbs}\relax
    \def\cs##1{\csiv\csiv##1}\else
    \def\Esc{\eqbs\eqbs}\def\cs{\Esc\Esc}\fi
  \let\pum@holdtoks\@empty\let\pum@holdtoksEx\@empty
  \toks@={\pum@mytab}\@temptokena={\pum@mytab}\@makeother\~%
  \gdef\msarg{#1}\gdef\msargEx{#1Ex}\@AddToMenuToks{\@gobble}%
  \@AddToMenuToksEx{\@gobble}\let\item\pum@item
\ignorespaces}{%
  \csarg\xdef{\msarg}{var \msarg\space = [ \pum@holdtoks^^J];}%
  \iftrackingPU
  \csarg\xdef{\msargEx}{var \msargEx\space = [ \pum@holdtoksEx^^J];}\fi
\aftergroup\ignorespaces}
\newcommand{\pum@item}[1]{\pum@updateindex
  \setkeys{menustruct}{title,marked=false,enabled,return,#1}\relax
  \ifx\menustruct@title\@empty
    \PackageWarning{popupmenu}
    {A value of the key 'title' is required,\MessageBreak
      putting in a place keeper title}%
    \def\menustruct@title{This title is undefined}\fi
  \edef\tmp@exp{,^^J\the\toks@
    {cName: "\menustruct@title"%
    \ifKV@menustruct@marked, bMarked: true\fi%
    \ifKV@menustruct@enabled\else, bEnabled: false\fi%
    \ifx\menustruct@return\@empty\else,%
      cReturn: "\menustruct@return"\fi}}\expandafter
  \@AddToMenuToks\expandafter{\tmp@exp}%
  \edef\tmp@expEx{,^^J\the\@temptokena
    {cName: "\menustruct@title"%
    \ifKV@menustruct@marked, bMarked: true\fi%
    \ifKV@menustruct@enabled\else, bEnabled: false\fi%
    \ifx\btitle@dash\ef@NO
    \ifx\menustruct@return\@empty,%
      cReturn:"[\itemindex,'\menustruct@title']"%
    \else,cReturn:"[\itemindex,'\menustruct@return']"\fi\fi}}%
  \expandafter\@AddToMenuToksEx\expandafter{\tmp@expEx}%
\ignorespaces}
\begingroup
\catcode`<=1 \catcode`\>=2 \@makeother\{ \@makeother\}
\gdef\pum@lbrace<{>\gdef\pum@rbrace<}>
\endgroup
\def\pum@mytab{\space\space\space\space}
\newenvironment{submenu}[1]{\pum@updateindex\advance\submenuLevel\@ne
  \csarg\xdef{pum@cntLevel\the\submenuLevel}{\the\pum@cnt}%
  \pum@initIndexMenu{\pum@rc.oSubMenu}\edef\temp@toks{\the\toks@}%
  \def\temp@toksEx{\the\@temptokena}%
  \toks@=\expandafter{\temp@toks\pum@mytab}%
  \@temptokena=\expandafter{\temp@toksEx\pum@mytab}%
  \setkeys{menustruct}{title,marked=false,enabled,return,#1}%
  \edef\tmp@exp{,^^J\the\toks@
    \noexpand\pum@lbrace cName: "\menustruct@title"%
    \ifKV@menustruct@marked, bMarked: true\fi%
    \ifKV@menustruct@enabled\else, bEnabled: false\fi,
  oSubMenu:^^J\the\toks@[}%
  \expandafter\@AddToMenuToks\expandafter{\tmp@exp\@gobble}%
  \edef\tmp@expEx{,^^J\the\@temptokena
    \noexpand\pum@lbrace cName: "\menustruct@title"%
    \ifKV@menustruct@marked, bMarked: true\fi%
    \ifKV@menustruct@enabled\else, bEnabled: false\fi,
  oSubMenu:^^J\the\@temptokena[}%
  \expandafter\@AddToMenuToksEx\expandafter{\tmp@expEx\@gobble}%
\ignorespaces}{%
  \edef\tmp@exp{^^J\the\toks@ ]\pum@rbrace}%
  \edef\tmp@expEx{^^J\the\@temptokena ]\pum@rbrace}%
  \expandafter\@AddToMenuToks\expandafter{\tmp@exp}%
  \expandafter\@AddToMenuToksEx\expandafter{\tmp@expEx}%
  \global\pum@cnt\@nameuse{pum@cntLevel\the\submenuLevel}%
\aftergroup\ignorespaces}
\def\popUpMenu(#1){app.popUpMenuEx.apply( app, #1 )}
\def\puProcessMenu(#1){\iftrackingPU
  puProcessMenu("#1")\else\popUpMenu(#1)\fi}
\providecommand{\urlPath}[1]{\def\pum@urlName{#1}%
  \hyper@normalise\pum@urlPath}
\def\pum@urlPath#1{\expandafter\xdef\pum@urlName{#1}}
\def\puUseTheseMenus{// No pop-up data defined^^J}
\let\puMenuCmds\@empty
\newcommand{\puUseMenus}[1]{\bgroup
  \@for\pu@menu:=#1\do{\ifx\puMenuCmds\@empty
    \def\puUseTheseMenus{// popupmenu: Begin popup menu data^^J}\fi
    \expandafter\g@addto@macro\expandafter
      \puMenuCmds\expandafter{%
      \csname\pu@menu\endcsname^^J}\relax
    \iftrackingPU
      \expandafter\g@addto@macro\expandafter
      \puMenuCmds\expandafter{%
      \csname\pu@menu Ex\endcsname^^J}\relax
    \fi
    \edef\x{\expandafter\noexpand\@nameuse{\pu@menu}}%
    \toks@=\expandafter{\x^^J}%
    \expandafter\g@addto@macro\expandafter
      \puUseTheseMenus\expandafter{\the\toks@}%
    \iftrackingPU
      \edef\x{\expandafter\noexpand\@nameuse{\pu@menu Ex}}%
      \toks@=\expandafter{\x^^J}%
      \expandafter\g@addto@macro\expandafter
        \puUseTheseMenus\expandafter{\the\toks@}%
    \fi
  }\g@addto@macro\puUseTheseMenus
    {// popupmenu: End of popup menu data}\egroup
  \ifx\puUseTheseMenus\@empty
  \def\puUseTheseMenus{// No pop-up data defined}\fi
}
\iftrackingPU
\begin{insDLJS}{pujs}{Pop-up Menu Data}
\puUseTheseMenus
\end{insDLJS}
\@onlypreamble\puUseMenus
\begin{insDLJS*}{pumenu}
\begin{newsegment}{popupmenu: Menu tracking support}
var trackingPU=\puTracking;
var PUdebug=false;
var aPULastChoice=new Array;
var bPULastChoice=false;
var bIsMarked=false;
function puProcessMenu(cMenu) { // aMenu->cMenu now a string
  var cMenuEx=(trackingPU)?cMenu+"Ex":cMenu;
  var aMenuEx=eval(cMenuEx);
  var cChoice = app.popUpMenuEx.apply( app, aMenuEx );
  if (trackingPU) {
    if ( cChoice != null ) {
      aChoice=eval(cChoice);
      if (aChoice[1]==""||aChoice[1]=="null") return null;
      var puRtn=aChoice[1];
      var thisChoice=aChoice[0];
//      eval(cMenuEx+thisChoice).bMarked=true;
      if (!bPULastChoice) {
        eval(cMenuEx+aChoice[0]).bMarked=true; 
      } else {
        var structLoc=aPULastChoice[1];
        if(aPULastChoice[0]+structLoc==cMenuEx+aChoice[0]) {
          bIsMarked = eval(cMenuEx+aChoice[0]).bMarked;
          eval(cMenuEx+aChoice[0]).bMarked=!(bIsMarked);
          bPULastChoice=false;
          if (bIsMarked) var puRtn=null
  } else {
        eval(aPULastChoice[0]+structLoc).bMarked=false;
        eval(cMenuEx+aChoice[0]).bMarked=true;
  }
    }
      aPULastChoice=[cMenuEx,aChoice[0]];
      bPULastChoice=true;
      return puRtn;
    } else return null;
  } else return cChoice;
}
\end{newsegment}
\end{insDLJS*}
\fi
\pu@restoreCats
\endinput
%%
%% End of file `popupmenu.sty'.