<?xml version="1.0"?>

<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<dialog id="sbawPref"
      xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      title="ScrollbarAnywhere Options"
      buttons="accept, cancel"
      onload="init();"
      ondialogaccept="return savePrefs();"
      persist="width height screenX screenY">

<script type="application/x-javascript">
  <![CDATA[
function init() {
  var checkboxes  = ["grabNDragId", "reverseIdV", "reverseIdH" , "cursorId", "lockId"];
  var radiogroups = ["mousebuttOptions"];
  var checkbox, radiogroup, i;
  var pref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  for (i = 0; i < checkboxes.length; ++i) {
    checkbox = document.getElementById(checkboxes[i]);
    checkbox.checked = pref.getBoolPref(checkbox.getAttribute("prefstring"));
  }
  for (i = 0; i < radiogroups.length; ++i) {
    radiogroup = document.getElementById(radiogroups[i]);
    radiogroup.selectedItem = radiogroup.childNodes[pref.getIntPref(radiogroup.getAttribute("prefstring"))];
  }
  const myGUID = "{767a0048-69da-4392-b458-55b7a96b66f7}";
  const EMService = Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager);
  try {
   var aioVersion = EMService.getItemList(myGUID, Components.interfaces.nsIUpdateItem.TYPE_EXTENSION, {})[0].version;
  }
  catch(err) {
   var allItems = EMService.getItemList(Components.interfaces.nsIUpdateItem.TYPE_EXTENSION, {});
   for (i = 0; i < allItems.length; ++i)
      if (allItems[i].id == myGUID) {aioVersion = allItems[i].version; break;}
  }
  document.getElementById("versId").value += " " + aioVersion;
}

function savePrefs() {
  var checkboxes  = ["grabNDragId", "reverseIdV", "reverseIdH","cursorId", "lockId"];
  var radiogroups = ["mousebuttOptions"];
  var checkbox, radiogroup, i;
  var pref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  for (i = 0; i < checkboxes.length; ++i) {
    checkbox = document.getElementById(checkboxes[i]);
    pref.setBoolPref(checkbox.getAttribute("prefstring"), checkbox.checked);
  }
  for (i = 0; i < radiogroups.length; ++i) {
    radiogroup = document.getElementById(radiogroups[i]);
    pref.setIntPref(radiogroup.getAttribute("prefstring"), radiogroup.value);
  }
  return true;
}
  ]]>
</script>
   <groupbox orient="horizontal">
     <caption label="Preferences"/>
     <vbox flex="1">
      <label id="leftlabelId" value="Trigger Mouse Button" />
      <hbox pack="center">
       <vbox>
        <radiogroup id="mousebuttOptions" prefstring="scrollbarAnywhere.button"
                 orient="horizontal">
         <radio minwidth="115" id="mousebutt0" value="0" label="Left" />
         <radio minwidth="115" id="mousebutt1" value="1" label="Middle" />
         <radio id="mousebutt2" value="2" label="Right" />
        </radiogroup>
       </vbox>
      </hbox>
      <separator orient="horizontal" />
      <checkbox id="grabNDragId" type="checkbox" pref="true" preftype="bool"
           prefstring="scrollbarAnywhere.grabNDrag" label="Acrobat Reader mode" />
      <checkbox id="lockId" type="checkbox" pref="true" preftype="bool"
           prefstring="scrollbarAnywhere.enableLock" label="Don't exit scrolling the first time the mouse button is released" />
      <checkbox id="cursorId" type="checkbox" pref="true" preftype="bool"
           prefstring="scrollbarAnywhere.customCursor" label="Show a dedicated cursor when scrolling" />
   
      <separator style="groove" orient="horizontal" />
      <caption label="Scroll the page opposite"/>
      <checkbox id="reverseIdV" type="checkbox" pref="true" preftype="bool"
           prefstring="scrollbarAnywhere.reverseV" label="Vertically" />
      <checkbox id="reverseIdH" type="checkbox" pref="true" preftype="bool"
           prefstring="scrollbarAnywhere.reverseH" label="Horizontally" />
      
     </vbox>
   </groupbox>
   <groupbox>
     <caption label="About"/>
     <hbox flex="1" align="center">
        <label value="Author: Marc Boullet"/>
        <spring flex="1"/>
        <label id="versId" value="Version"/>
     </hbox>
   </groupbox>
</dialog>

