%%
%% This is file `acrosort.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% acrosort.dtx  (with options: `copyright,package')
%% 
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% acrosort package,                                    %%
%% Copyright (C) 2006--2020  D. P. Story                %%
%%   dpstory@acrotex.net                                %%
%%   storyd@nwfsc.edu                                   %%
%%                                                      %%
%% 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{acrosort}
 [2020/06/17 v1.6.1 AcroSort (dps)]
\@ifpackageloaded{eforms}{\let\execjs=y}
  {\RequirePackage[execJS]{eforms}}
\ifxetex\makeXasPDOff\fi
\RequirePackage{icon-appr}
\RequirePackage{multido}
\RequirePackage{graphicx}
\newcommand{\StartSort}[4][]
  {\pushButton[\CA{Press Me}#1\A{\JS{\sortCustomStartJS;\r
   startSortAS("#2");
   \@ppendStartSortJS}}]{btStartSort}{#3}{#4}%
}
\newcommand{\ClearSort}[4][]%
  {\pushButton[\CA{Clear}#1\A{\JS{%
    var f=this.getField("btn#2pic");\r
    if(f!=null)f.display=display.hidden;\r
    asOk2Continue = false;
    \@ppendClearSortJS
  }}]{btnClearSort}{#3}{#4}%
}
\newcommand{\StopSort}[3][]
    {\pushButton[\CA{Stop}#1\A{\JS{%
      asOk2Continue = false;
      \@ppendStopSortJS
    }}]{btnStopSort}{#2}{#3}%
}
\newcommand{\customStartJS}[1]{\def\sortCustomStartJS{#1}}
\let\sortCustomStartJS\@gobbletwo
\def\appendStartSortJS#1{\def\@rgi{#1}\ifx\@rgi\@empty
  \let\@ppendStartSortJS\@empty\else
  \def\@ppendStartSortJS{\r #1}\fi}
\let\@ppendStartSortJS\@empty
\def\appendClearSortJS#1{\def\@rgi{#1}\ifx\@rgi\@empty
  \let\@ppendClearSortJS\@empty\else
  \def\@ppendClearSortJS{\r #1}\fi}
\let\@ppendClearSortJS\@empty
\def\appendStopSortJS#1{\def\@rgi{#1}\ifx\@rgi\@empty
  \let\@ppendStopSortJS\@empty\else
  \def\@ppendStopSortJS{\r #1}\fi}
\let\@ppendStopSortJS\@empty
\newcommand{\asIconPic}[4][]{% \I{\csOf{name}} required
  \pushButton[\Ff{\FfReadOnly}\BG{}\S{S}#1\TP{1}\F{\FHidden}
    \PA{.5 1}]{#2}{#3}{#4}}
\newcount\as@nCnt
\newif\if@isPackaged\@isPackagedfalse
\def\isPackage{\@isPackagedtrue}
\let\asIconObjs\@gobble
\newcommand{\asEmbedTiles}[4][]{\begingroup
  \gdef\asNumSideShowPics{#3}%
  \csarg\gdef{asGraphicPath#2}{#4}%
  \def\@Ext{#1}\ifx\@Ext\@empty\def\@Ext{.pdf}\else\def\@Ext{.#1}\fi
  \@tempcnta\z@
  \let\@embedList\@empty
  \edef\z{\noexpand\g@addto@macro\noexpand
    \asIconObjs{,"#2":\asNumSideShowPics}}\z
  \@whilenum \@tempcnta < \asNumSideShowPics \do{%
    \as@nCnt\@tempcnta\advance\as@nCnt\@ne
    \ifnum\as@nCnt<10\relax\edef\x{0\the\as@nCnt}\else
      \edef\x{\the\as@nCnt}\fi
    \ifxetex\if@isPackaged
      \PackageWarning{acrosort}
      {There is no support for embedding packaged\MessageBreak
      PDFs with xelatex. Ignoring the \string\isPackage\MessageBreak
      command}%
      \@isPackagedfalse
    \fi\fi
    \if@isPackaged
      \ifpdf
        \edef\y{\noexpand
          \embedIcon[name=#2pic\x,%
          hyopts={page=\x}]{#4_package.pdf}}%
      \else
        \edef\y{\noexpand
          \embedIcon[name=#2pic\x,placement=btn#2pic.\x,%
          page=\x-1]{#4_package.pdf}}%
      \fi
    \else
      \edef\y{\noexpand
        \embedIcon[name=#2pic\x,placement=btn#2pic.\x]{#4_\x\@Ext}}%
    \fi
    \expandafter\g@addto@macro\expandafter\@embedList\expandafter{\y}%
    \@tempcnta\as@nCnt
  }% do
  \toks@=\expandafter{\@embedList}\the\toks@
  \endgroup
  \global\@isPackagedfalse
}
\newcommand\insertTiles[4]{\begingroup
  \setbox\z@\hbox{%
    \includegraphics[draft,width=#2]{\@nameuse{asGraphicPath#1}}}%
  \edef\asGrphWd{\the\wd\z@}%
  \@tempdima\wd\z@
  \divide\@tempdima #4\relax
  \edef\asTileWd{\the\@tempdima}%
  \setlength\@tempdima{\ht\z@+\dp\z@}%
  \setbox\z@\box\voidb@x
  \edef\asTtlGrphHt{\the\@tempdima}%
  \@tempdima\asTtlGrphHt\relax
  \divide\@tempdima #3\relax
  \edef\asTileHt{\the\@tempdima}%
  \begin{minipage}{#2}%
    \offinterlineskip\@tempcnta\z@
    \multido{\iR=1+1}{#3}{\hbox{%
      \multido{\iC=1+1}{#4}{%
        \global\advance\@tempcnta\@ne
        \ifnum\@tempcnta<10\relax
          \edef\x{0\the\@tempcnta}\else
          \edef\x{\the\@tempcnta}\fi
        \edef\iconPresets{\noexpand\I{\noexpand\csOf{#1pic\x}}}%
        \asIconPic[\BC{}\FB{true}\presets{\iconPresets}%
          \presets{\astile@KVs}]{btn#1pic.\x}{\asTileWd}{\asTileHt}%
      }% inner multido
    }}% hbox, outer multido
  \end{minipage}%
  \endgroup
}
\def\astileKVs#1{\def\astile@KVs{#1}}
\astileKVs{}
\newcommand{\customFinishJS}[1]{\gdef\sortCustomFinishJS{#1}}
\def\sortCustomFinishJS{;}
\begin{insDLJS}{asSort}{AcroSort: Bubble Sort}
// Global Data:
var btnbase="";     // btn<name>pic.01, btn<name>pic.02, etc
var iconbase="";    // <name>pic01, <name>pic02, etc.
var iconObjs={\asIconObjs};
var sortName="";
var randomAS = new Array();
var timeout = 10;
var shutdown;
var asOk2Continue = false;
function initRandomDPS(name) {
  var nTotalTiles = iconObjs[name];
  for (i=1; i<=nTotalTiles; i++) randomAS[i]=i;
  return nTotalTiles;
}
function startSortAS(name) {
  if (!asOk2Continue) {
    sortName=name;
    randomAS = new Array();
    var f=this.getField("btn"+name+"pic");
    if(f!=null)f.display=display.visible;
    asOk2Continue = true;
    mixupAS();
    showAS();
    sortoutAS();
  }
}
function mixupAS()
{
    var i, rand, temp;
    var nTotalTiles=initRandomDPS(sortName);
    var ldps = randomAS.length;
    for (i=1; i<= nTotalTiles; i++)
    {
        var rand = Math.random();
        rand *= ldps*ldps;
        rand = Math.ceil(rand);
        rand = rand \% ldps;
        if (rand == 0 ) rand = 1;
        temp = randomAS[i];
        randomAS[i]=randomAS[rand];
        randomAS[rand]=temp;
    }
}
function showAS()
{
    var I,J;
    var nTotalTiles = iconObjs[sortName];
    btnbase="btn"+sortName+"pic.";
    iconbase=sortName+"pic";
    for ( var i=1; i<=nTotalTiles; i++ )
    {
        I=((i<10)?"0":"")+i;
        J=((randomAS[i]<10)?"0":"")+randomAS[i];
        var oIcon = this.getIcon(iconbase+J);
        var f = this.getField(btnbase+I);
        f.buttonSetIcon(oIcon);
    }
}
function sortoutAS()
{
    outerLoop(randomAS.length-1);
}
function outerLoop(i)
{
     if ( asOk2Continue && (i >= 0) )
        shutdown = app.setTimeOut("app.clearTimeOut(shutdown); %
innerLoop("+i+",1);", timeout);
     else {
      asOk2Continue=false;
     \sortCustomFinishJS
     }
}
function innerLoop(i,j)
{
    var I, J;
    if ( j <= i )
    {
       if (randomAS[j-1] > randomAS[j])
       {
            var temp = randomAS[j-1];
            randomAS[j-1] = randomAS[j];
            randomAS[j] = temp;
            J=((randomAS[j-1]<10)?"0":"")+randomAS[j-1];
            I=((j-1 < 10)?"0":"")+(j-1);
            var oIcon = this.getIcon(iconbase+J);
            var f = this.getField(btnbase+I);
            f.buttonSetIcon(oIcon);
            J=((randomAS[j]<10)?"0":"")+randomAS[j];
            I=((j < 10)?"0":"")+j;
            var oIcon = this.getIcon(iconbase+J);
            var f = this.getField(btnbase+I);
            f.buttonSetIcon(oIcon);
        }
        j++
        if ( asOk2Continue ) %
shutdown = app.setTimeOut("app.clearTimeOut(shutdown); %
innerLoop("+i+","+j+");", timeout);
    }
    else
    {
        i--;
        outerLoop(i);
    }
}
\end{insDLJS}
\endinput
%%
%% End of file `acrosort.sty'.
