!!compatible avec geogebra3.2

!if $wims_read_parm!=slib_header
 !goto proc
!endif
slib_title=Geogebra Applet
slib_parms=1\
,option or applet command for javascript, one by line or joined by a semicolon 
slib_author=Paul BYACHE et Bernadette PERRIN-RIOU
slib_out=

slib_comment=the available applet commands are either the definition of an object\
<br>or javascript methods. For syntax details on how to create objects, you can report to the GeoGebra help page : \
<a target="wims_external" href="http://www.geogebra.org/help/docufr/"> www.geogebra.org/help/docufr </a>\
There are a lot of available javascript methods : for example, \
<tt>evalCommand setValue setColor setVisible \
  setLabelVisible setFixed setTrace\
  setAxesVisible setGridVisible setCoordSystem\
  deleteObject renameObject setLayerVisible\
  setLineStyle setAnimationSpeed startAnimation</tt>\
The complete list <a target="wims_external" href="http://www.geogebra.org/en/wiki/index.php/GeoGebra_JavaScript_Methods"> is here.</a>\
<br><br>Allowed options are the followings. See <a target="wims_external" href="http://www.geogebra.org/en/wiki/index.php/GeoGebra_Applet_Parameters"> here for details.</a>\
<br><tt>height</tt> default 300\
<br><tt>width</tt> default 300\
<br><tt>file</tt> default none&#46; Be careful &#58; the &#46;ggb file must be in the "image" \
directory if you use the slib in an OEF exercise, \
<br>in the "files" directory if you use the slib in a document ;\
<br>otherwise you have to use relative adress from module directory.\
<br><tt>showToolBar</tt> default false\
<br><tt>customToolBar</tt> default none. Be careful : no comma is allowed and if you want \
<br>to separate two integers by a space-character, type a "@" instead of this space-character ! \
The list of the icones <a target="wims_external" href="http://www.geogebra.org/source/program/doc/geogebra_modes.html">is here</a>\
<br><tt>showMenuBar</tt> default false\
<br><tt>showAlgebraInput</tt> default false\
<br><tt>showResetIcon</tt> default false (Be careful : this option enable to \
reset the applet, but without the construction done from wims)\
<br><tt>showToolBarHelp</tt> default true\
<br><tt>enableRightClick</tt> default true (Be careful : by right-clicking \
on an object, the student can modify all the objects in the construction !)\
<br><tt>language</tt> default fr\
<br><tt>enableLabelDrags</tt> default true\
<br><tt>enableShiftDragZoom</tt> default true\
<br><tt>errorDialogsActive</tt> default true\
<br><tt>debug</tt> default false\
<br><tt>number</tt> number of the applet in the html page (default 1)
<br><tt>EXAMPLE\
<br><tt>&#92;integer{x=random(3)}\
<br><tt>&#92;text{appletcommand= Z=(&#92;x,3.78)&#92;\
<br><tt>W=(6.2,2.8)&#92;\
<br><tt>Ellipse[Z,W,5]&#92;\
<br><tt>u=Line[W,Z]}\
<br><tt>#the language can be setted in the options\
<br><tt>&#92;text{option= showToolBar=true\
<br><tt>language=en\
<br><tt>customToolBar="0|5@40 10||1|2"\
<br><tt>width=600\
<br><tt>height=500\
<br><tt>number=1</tt>
<br><tt>#to hide the algebra window (on the left), use a ".ggb" file in the options\
<br><tt>&#92;text{applet=slib(geo2D/geogebra3  &#92;appletcommand ; &#92;option)}\
<br><tt>&#92;statement{&#92;applet}
 
 supprimer <br><tt>js</tt> for extra javascript commands for geogebra in brackets
 
slib_example=Z=(-3,6.78);W=(0.2,5.8);a=Circle[Z,W];Ellipse[Z,W,5];u=Line[W,Z];showMenuBar=true;showToolBar=true;language=en;customToolBar="0|40@10||1|2";width=600;height=300;setCoordSystem(-9,7,1,11.5)\
A=(0,3.5);B=(0,5);a=Cercle[A,B];d:y=2x+1;number=2;width=600;language=fr;showToolBar=true;customToolBar="0|40"\
A=(0,3);B=(0,4);C=(2,3);s=Segment[A,C];Angle[C,A,B];a=Droite[C,B];D=Point[a];b=3;f(x)=b+sin(x);number=3;width=600;language=fr
!exit

:proc
!set name_clickgeogebra_fr=Initialiser

!default name_clickgeogebra_$lang=Init

!reset slib_out
!default slib_cnt=0
slib_cnt= $[$slib_cnt +1]
slib_data=!trim $wims_read_parm

slib_data= !items2lines $wims_read_parm
slib_data=!replace internal $	$ by $\
$ in $slib_data

slib_data = !rows2lines $slib_data
slib_data= !replace internal ; by $\
$ in $slib_data
slib_data=!nonempty lines $slib_data

slib_z2= $slib_data

slib_option= !item 2 to -1 of $wims_read_parm
slib_option= !replace internal , by @ in $slib_option
slib_option= !replace internal ; by $\
$ in $slib_option
!!only for compatibility, only one js method in js=[]
slib_extra= !getopt js in $slib_data
slib_extra=!declosing $slib_extra
slib_extra= !replace internal @ by , in $slib_extra
slib_extra=!words2lines $slib_extra
slib_extra = !rows2lines $slib_extra
slib_data=$slib_data\
$slib_extra

slib_list_ap = enableLabelDrags,enableShiftDragZoom,errorDialogsActive,file,showToolBar,showAlgebraView,showMenuBar,showResetIcon,showToolBarHelp,enableRightClick,showAlgebraInput,customToolBar,language,debug,number,ggbBase64
slib_list_ap1=!items2words $slib_list_ap

!for slib_a in width,height,language,$slib_list_ap
  slib_$slib_a=!getopt $slib_a in $slib_data
!next slib_a
slib_ggbBase64=$(slib_ggbBase64)
slib_customToolBar1= !nospace $slib_customToolBar
slib_customToolBar=$slib_customToolBar1
slib_customToolBar= !replace internal @ by , in $slib_customToolBar
slib_customToolBar= !replace internal || by % in $slib_customToolBar
slib_customToolBar= !replace internal | by ,|, in $slib_customToolBar
slib_customToolBar= !replace internal % by ,||, in $slib_customToolBar
slib_customToolBar= !items2words  $slib_customToolBar
!default slib_width=300
!default slib_height=300
!default slib_enableRightClick=true
!default slib_showToolBar=false
!default slib_showToolBarHelp=true
!default slib_showMenuBar=false
!default slib_showResetIcon=false
!default slib_showAlgebraInput=false
!default slib_language=$module_language
!default slib_enableLabelDrags=true
!default slib_enableShiftDragZoom=true
!default slib_errorDialogsActive=true
!default slib_debug=false
!default slib_customToolBar=
!default slib_number=1
slib_number=$[$slib_number-1]

!! ne trouve pas le fichier (? getXML ?)
!!slib_algebraview=<script type="text/javascript">\
!!function algebraview() {\
!! var myapplet = document.applet$slib_number; \
!! var ch=new String(myapplet.getXML());\
!! var f=new String('"false"'); var t=new String('"true"');\
!! var cmd=new String('cmdList');var alg=new String('algebraView');\
!! var i=ch.indexOf(alg + '=' + t) ;\
!! if (i>-1){ ch=ch.substr(0,i)+ alg +'='+ f+ch.substring(i+alg.length+1+t.length,ch.length);}\
!! var j=ch.indexOf(cmd +'=' + t) ;\
!! if (j>-1){ ch=ch.substr(0,j)+cmd+'='+f +ch.substring(i+cmd.length+1+t.length,ch.length);}\
!! myapplet.setXML(ch);\
!!}\
!!</script>
!!slib_out=$slib_algebraview

slib_js_parm=evalCommand setValue setCoords setColor setVisible \
  setLabelVisible setLabelStyle setFixed setTrace\
  setAxesVisible setGridVisible setCoordSystem setUndoPoint\
  deleteObject renameObject setLayer setLayerVisible\
  setLineStyle setThickness setPointStyle setPointSize\
  setFilling setAnimating setAnimationSpeed\
  startAnimation stopAnimation isAnimationRunning

slib_cnt=!linecnt $slib_data

slib_data1=!replace internal = by , in $slib_data
slib_data1=!replace internal ( by , in $slib_data1


slib_appletcommand=
slib_appletoption=
slib_geogebracommand=

slib_out=$slib_out\
<applet name="applet$slib_number" codebase="java/geogebra3" code="geogebra.GeoGebraApplet" archive="geogebra.jar" width="$slib_width" height="$slib_height" MAYSCRIPT>\
<param name="framePossible" value="false">\
<param name="language" value="$slib_language">\
<param name="showToolBar" value="$slib_showToolBar">\
<param name="showToolBarHelp" value="$slib_showToolBarHelp">\
<param name="showResetIcon" value="$slib_showResetIcon">\
<param name="enableRightClick" value="$slib_enableRightClick">\
<param name="showMenuBar" value="$slib_showMenuBar">\
<param name="showAlgebraInput" value="$slib_showAlgebraInput">\
<param name="showAlgebraView" value="false">
!for slib_u=1 to $slib_cnt
  slib_line=!line $slib_u of $slib_data
  slib_line=!nospace $slib_line
  slib_line1=!replace internal = by , in $slib_line
  slib_line1=!replace internal ( by , in $slib_line1
  slib_first=!item 1 of $slib_line1
  !if $slib_first iswordof width height $slib_list_ap1
    slib_out=!append line <param name="$slib_first" value="$(slib_$slib_first)"> to $slib_out
    !if $slib_first != customToolBar
      slib_appletoption=!append line $slib_first=$(slib_$slib_first) to $slib_appletoption
    !else
      slib_appletoption=!append line $slib_first=$(slib_$(slib_first)1) to $slib_appletoption
    !endif
  !else 
    !if $slib_first iswordof $slib_js_parm
      slib_appletcommand=!append line  myapplet.$slib_line; to $slib_appletcommand
      slib_geogebracommand=!append line $slib_line to $slib_geogebracommand
    !else
      !if $slib_first notwordof height width
        slib_appletcommand=!append line myapplet.evalCommand("$slib_line"); to $slib_appletcommand
        slib_geogebracommand=!append line $slib_line to $slib_geogebracommand
      !endif
    !endif
  !endif
!next
!if $slib_file!=$empty
  slib_mod = $module_category
  slib_mod = !items2words $slib_mod
  !if document iswordof $slib_mod
    slib_image_dir=$Docdir/$doc/files
  !endif
  !if oef iswordof $slib_mod
    slib_image_dir=$imagedir
  !endif
  !if adm iswordof $slib_mod
    slib_image_dir=$wims_ref_name?session=$wims_session&+cmd=getfile&+special_parm=doc
  !endif
  !default slib_image_dir=$module_dir

 slib_out=$slib_out\
<param name="filename" value="$slib_image_dir/$slib_file">
!endif

!if $slib_customToolBar!=$empty
  slib_out=$slib_out \
<param name="customToolBar" value="$slib_customToolBar">
!endif
slib_out=$slib_out\
Sorry - the GeoGebra Applet could not be started. Please make sure that Java 1.4.2 (or later) is installed and activated. (<a href="http://java.sun.com/getjava">click here to install Java now</a>)\
</applet>

!if $slib_appletcommand!=
 slib_out=<input type="button" style="background-color:$wims_ref_button_bgcolor;color:$wims_ref_button_color;" value="$(name_clickgeogebra_$lang)" onclick="Construction$slib_number();">\
 $slib_out\
 <script type="text/javascript">\
 function Construction$slib_number() {\
 var myapplet = document.applet$slib_number; \
 myapplet.setRepaintingActive(false); \
 $slib_appletcommand\
 myapplet.setRepaintingActive(true);\
}\
</script>

!endif
slib_z1=$wims_read_parm
!if $slib_debug=true
  slib_out=$slib_out \
<br><br>Parameters read by the applet : $slib_z1<br><br>The slib_data : $slib_z2 --> $slib_data
!endif


