home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Programy / nsb-install-8-0.exe / chrome / toolkit.jar / content / global / bindings / wizard.xml < prev   
Extensible Markup Language  |  2005-07-29  |  16KB  |  461 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="wizardBindings"
  4.    xmlns="http://www.mozilla.org/xbl"
  5.    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  6.    xmlns:xbl="http://www.mozilla.org/xbl">
  7.  
  8.   <binding id="wizard-base">
  9.     <resources>
  10.       <stylesheet src="chrome://global/skin/wizard.css"/>
  11.     </resources>
  12.   </binding>
  13.   
  14.   <binding id="wizard" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  15.     <content>
  16.       <xul:hbox class="wizard-header" anonid="Header"/>
  17.       
  18.       <xul:deck class="wizard-page-box" flex="1" anonid="Deck">
  19.         <children includes="wizardpage"/>
  20.       </xul:deck>
  21.       <children/>
  22.       
  23.       <xul:hbox class="wizard-buttons" anonid="Buttons" xbl:inherits="pagestep,firstpage,lastpage"/>
  24.     </content>
  25.     
  26.     <implementation>
  27.       <property name="title" onget="return this.getAttribute('title')"
  28.                              onset="this.setAttribute('title', val);"/>
  29.  
  30.       <property name="canAdvance" onget="return this._canAdvance;"
  31.                                   onset="this._canAdvance=val; this._nextButton.setAttribute('disabled', !val);"/>
  32.       <property name="canRewind" onget="return this._canRewind;"
  33.                                  onset="this._canRewind=val; this._backButton.setAttribute('disabled', !val);"/>
  34.  
  35.       <property name="pageStep" onget="return this._pageStack.length"/>
  36.  
  37.       <field name="pageCount">0</field>
  38.       
  39.       <field name="_accessMethod">null</field>
  40.       <field name="_pageStack">null</field>
  41.       <field name="_currentPage">null</field>
  42.  
  43.       <property name="wizardPages">
  44.         <getter>
  45.         <![CDATA[
  46.           var xulns = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  47.           return this.getElementsByTagNameNS(xulns, "wizardpage");
  48.         ]]>
  49.         </getter>
  50.       </property>
  51.  
  52.       <property name="currentPage" onget="return this._currentPage">
  53.         <setter>
  54.         <![CDATA[
  55.           if (!val)
  56.             return val;
  57.             
  58.           this._currentPage = val;
  59.  
  60.           // Setting this attribute allows wizard's clients to dynamically
  61.           // change the styles of each page based on purpose of the page. 
  62.           this.setAttribute("currentpageid", val.pageid);
  63.                     
  64.           if (this.onFirstPage) {
  65.             this.canRewind = false;
  66.             this.setAttribute("firstpage", "true");
  67.           } else {
  68.             this.canRewind = true;
  69.             this.setAttribute("firstpage", "false");
  70.           }
  71.                     
  72.           if (this.onLastPage) {
  73.             this.canAdvance = true;
  74.             this.setAttribute("lastpage", "true");
  75.           } else {
  76.             this.setAttribute("lastpage", "false");
  77.           }
  78.  
  79.           this._deck.setAttribute("selectedIndex", val.pageIndex);
  80.           this._advanceFocusToPage(val);
  81.  
  82.           this._adjustWizardHeader();
  83.           this._wizardButtons.onPageChange();
  84.  
  85.           this._fireEvent(val, "pageshow");
  86.           
  87.           return val;
  88.         ]]>
  89.         </setter>
  90.       </property>
  91.  
  92.       <property name="pageIndex" onget="return this._pageIndex;">
  93.         <setter>
  94.         <![CDATA[
  95.           if (val < 0 || val >= this.pageCount)
  96.             return this._pageIndex;
  97.  
  98.           var page = this.wizardPages[val];
  99.           this._pageStack[this._pageStack.length-1] = page;
  100.           this.currentPage = page;
  101.         ]]>
  102.         </setter>
  103.       </property>
  104.  
  105.       <property name="onFirstPage"
  106.                 onget="return this._pageStack.length == 1;"/>
  107.  
  108.       <property name="onLastPage">
  109.         <getter><![CDATA[
  110.           var cp = this.currentPage;
  111.           return cp && ((this._accessMethod == "sequential" && cp.pageIndex == this.pageCount-1) ||
  112.                        (this._accessMethod == "random" && cp.next == ""));
  113.          ]]></getter>
  114.       </property>
  115.  
  116.       <method name="getButton">
  117.         <parameter name="aDlgType"/>
  118.         <body>
  119.         <![CDATA[
  120.           var btns = this.getElementsByAttribute("dlgtype", aDlgType);
  121.           return btns.length > 0 ? btns[0] : document.getAnonymousElementByAttribute(this._wizardButtons, "dlgtype", aDlgType);
  122.         ]]>
  123.         </body>
  124.       </method>
  125.  
  126.       <field name="_canAdvance"/>
  127.       <field name="_canRewind"/>
  128.       <field name="_wizardHeader"/>
  129.       <field name="_wizardButtons"/>
  130.       <field name="_deck"/>
  131.       <field name="_backButton"/>
  132.       <field name="_nextButton"/>
  133.       <field name="_cancelButton"/>
  134.  
  135.       <!-- functions to be added as oncommand listeners to the wizard buttons -->
  136.       <field name="_backFunc">(function() { document.documentElement.rewind(); })</field>
  137.       <field name="_nextFunc">(function() { document.documentElement.advance(); })</field>
  138.       <field name="_finishFunc">(function() { document.documentElement.advance(); })</field>
  139.       <field name="_cancelFunc">(function() { document.documentElement.cancel(); })</field>
  140.  
  141.       <field name="_closeHandler">(function(event) {
  142.         if (document.documentElement.cancel())
  143.           event.preventDefault();
  144.       })</field>
  145.        
  146.       <constructor><![CDATA[
  147.         this._canAdvance = true;
  148.         this._canRewind = false;
  149.         this._hasLoaded = false;
  150.         
  151.         this._pageStack = [];
  152.         
  153.         // need to create string bundle manually instead of using <xul:stringbundle/>
  154.         // see bug 63370 for details
  155.         var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"]
  156.                               .getService(Components.interfaces.nsILocaleService);
  157.         var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService);
  158.         var bundleURL = "chrome://global/locale/wizard.properties";
  159.         this._bundle = stringBundleService.createBundle(bundleURL, localeService.getApplicationLocale());
  160.         
  161.         // get anonymous content references
  162.         this._wizardHeader = document.getAnonymousElementByAttribute(this, "anonid", "Header");
  163.         this._wizardButtons = document.getAnonymousElementByAttribute(this, "anonid", "Buttons");
  164.         this._deck = document.getAnonymousElementByAttribute(this, "anonid", "Deck");
  165.         
  166.         this._initWizardButton("back");
  167.         this._initWizardButton("next");
  168.         this._initWizardButton("finish");
  169.         this._initWizardButton("cancel");
  170.         
  171.         this._initPages();
  172.         
  173.         window.addEventListener("close", this._closeHandler, false);
  174.         
  175.         // start off on the first page
  176.         this.pageCount = this.wizardPages.length;
  177.         this.advance();
  178.         
  179.         // give focus to the first focusable element in the dialog
  180.         window.addEventListener("load", this._setInitialFocus, false);
  181.       ]]></constructor>
  182.  
  183.       <method name="getPageById">
  184.         <parameter name="aPageId"/>
  185.         <body><![CDATA[
  186.           var els = this.getElementsByAttribute("pageid", aPageId);
  187.           return els.length > 0 ? els[0] : null;
  188.         ]]></body>
  189.       </method>
  190.  
  191.       <method name="rewind">
  192.         <body><![CDATA[
  193.           if (!this.canRewind)
  194.             return;
  195.  
  196.           if (this.currentPage && !this._fireEvent(this.currentPage, "pagehide"))
  197.             return;
  198.  
  199.           if (this.currentPage && !this._fireEvent(this.currentPage, "pagerewound"))
  200.             return;
  201.  
  202.           if (!this._fireEvent(this, "wizardback"))
  203.             return;
  204.             
  205.             
  206.           this._pageStack.pop();
  207.           this.currentPage = this._pageStack[this._pageStack.length-1];
  208.           this.setAttribute("pagestep", this._pageStack.length);
  209.         ]]></body>
  210.       </method>
  211.  
  212.       <method name="advance">
  213.         <parameter name="aPageId"/>
  214.         <body><![CDATA[
  215.           if (!this.canAdvance)
  216.             return; 
  217.             
  218.           if (this.currentPage && !this._fireEvent(this.currentPage, "pagehide"))
  219.             return;
  220.             
  221.           if (this.currentPage && !this._fireEvent(this.currentPage, "pageadvanced"))
  222.             return;
  223.  
  224.           if (this.onLastPage) {
  225.             if (this._fireEvent(this, "wizardfinish"))
  226.               window.setTimeout(function() {window.close();}, 1);
  227.           } else {
  228.             if (!this._fireEvent(this, "wizardnext"))
  229.               return; 
  230.             
  231.             var page;
  232.             if (aPageId)
  233.               page = this.getPageById(aPageId);
  234.             else {
  235.               if (this.currentPage) {
  236.                 if (this._accessMethod == "random")
  237.                   page = this.getPageById(this.currentPage.next);
  238.                 else
  239.                   page = this.wizardPages[this.currentPage.pageIndex+1];
  240.               } else
  241.                 page = this.wizardPages[0];
  242.             }
  243.  
  244.             if (page) {
  245.               this._pageStack.push(page);
  246.               this.setAttribute("pagestep", this._pageStack.length);
  247.   
  248.               this.currentPage = page;
  249.             }
  250.           }
  251.         ]]></body>
  252.       </method>
  253.       
  254.       <method name="goTo">
  255.         <parameter name="aPageId"/>
  256.         <body><![CDATA[
  257.           var page = this.getPageById(aPageId);
  258.           if (page) {
  259.             this._pageStack[this._pageStack.length-1] = page;
  260.             this.currentPage = page;
  261.           }
  262.         ]]></body>
  263.       </method>
  264.               
  265.       <method name="cancel">
  266.         <body><![CDATA[
  267.           if (!this._fireEvent(this, "wizardcancel"))
  268.             return true;
  269.  
  270.           window.close();
  271.           window.setTimeout(function() {window.close();}, 1);
  272.         ]]></body>
  273.       </method>
  274.       
  275.       <method name="_setInitialFocus">
  276.         <parameter name="aEvent"/>
  277.         <body>
  278.         <![CDATA[
  279.           document.documentElement._hasLoaded = true;
  280.           var focusInit = 
  281.             function() {
  282.               // give focus to the first focusable element in the dialog
  283.               if (!document.commandDispatcher.focusedElement)
  284.                 document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement);
  285.             };
  286.  
  287.           // Give focus after onload completes, see bug 103197.
  288.           setTimeout(focusInit, 0);
  289.         ]]>
  290.         </body>
  291.       </method>                
  292.  
  293.       <method name="_advanceFocusToPage">
  294.         <parameter name="aPage"/>
  295.         <body>
  296.         <![CDATA[
  297.           if (!this._hasLoaded)
  298.             return;
  299.             
  300.           document.commandDispatcher.advanceFocusIntoSubtree(aPage);
  301.           
  302.           // if advanceFocusIntoSubtree tries to focus one of our
  303.           // dialog buttons, then remove it and put it on the root
  304.           var focused = document.commandDispatcher.focusedElement;
  305.           if (focused && focused.hasAttribute("dlgtype"))
  306.             this.focus();
  307.         ]]>
  308.         </body>
  309.       </method>                
  310.  
  311.       <method name="_initPages">
  312.         <body><![CDATA[
  313.           var meth = "sequential";
  314.           var pages = this.wizardPages;
  315.           for (var i = 0; i < pages.length; ++i) {
  316.             var page = pages[i];
  317.             page.pageIndex = i;
  318.             if (page.next != "")
  319.               meth = "random";
  320.           }
  321.           this._accessMethod = meth;
  322.         ]]></body>
  323.       </method>
  324.  
  325.       <method name="_initWizardButton">
  326.         <parameter name="aName"/>
  327.         <body><![CDATA[
  328.          var btn = document.getAnonymousElementByAttribute(this._wizardButtons, "dlgtype", aName);
  329.          if (btn) {
  330.            btn.addEventListener("command", this["_"+aName+"Func"], false);
  331.            btn.setAttribute("label", this._bundle.GetStringFromName("button-"+aName));
  332.            this["_"+aName+"Button"] = btn;
  333.          }
  334.          return btn;
  335.         ]]></body>
  336.       </method>
  337.  
  338.       <method name="_adjustWizardHeader">
  339.         <body><![CDATA[
  340.           var label = this.currentPage.getAttribute("label");
  341.           if (!label && this.onFirstPage)
  342.             label = this._bundle.formatStringFromName("default-first-title", [this.title], 1);
  343.           else if (!label && this.onLastPage)
  344.             label = this._bundle.formatStringFromName("default-last-title", [this.title], 1);
  345.           this._wizardHeader.setAttribute("label", label);
  346.           this._wizardHeader.setAttribute("description", this.currentPage.getAttribute("description"));
  347.         ]]></body>
  348.       </method>
  349.  
  350.       <method name="_hitEnter">
  351.         <body>
  352.         <![CDATA[
  353.           // if a button is focused, dispatch its command instead 
  354.           // of advancing the wizard
  355.           var focused = document.commandDispatcher.focusedElement;
  356.           if (!(focused && focused.localName == "button" && focused.hasAttribute("dlgtype")))
  357.             this.advance();
  358.         ]]>
  359.         </body>
  360.       </method>
  361.  
  362.       <method name="_fireEvent">
  363.         <parameter name="aTarget"/>
  364.         <parameter name="aType"/>
  365.         <body>
  366.         <![CDATA[
  367.           var event = document.createEvent("Events");
  368.           event.initEvent(aType, false, true);
  369.           
  370.           // handle dom event handlers
  371.           var noCancel = aTarget.dispatchEvent(event);
  372.           
  373.           // handle any xml attribute event handlers
  374.           var handler = aTarget.getAttribute("on"+aType);
  375.           if (handler != "") {
  376.             var fn = new Function("event", handler);
  377.             var returned = fn.apply(aTarget, [event]);
  378.             if (returned == false)
  379.               noCancel = false;
  380.           }
  381.  
  382.           return noCancel;
  383.         ]]>
  384.         </body>
  385.       </method>
  386.  
  387.     </implementation>
  388.  
  389.     <handlers>
  390.       <handler event="keypress" keycode="VK_ENTER" action="this._hitEnter()"/>
  391.       <handler event="keypress" keycode="VK_RETURN" action="this._hitEnter()"/>
  392.       <handler event="keypress" keycode="VK_ESCAPE" action="this.cancel();"/>
  393.     </handlers>
  394.   </binding>
  395.  
  396.   <binding id="wizardpage" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  397.     <implementation>
  398.       <field name="pageIndex">null</field>
  399.       
  400.       <property name="pageid" onget="return this.getAttribute('pageid');"
  401.                               onset="this.setAttribute('pageid', val);"/>
  402.  
  403.       <property name="next"   onget="return this.getAttribute('next');"
  404.                               onset="this.setAttribute('next', val);
  405.                                      this.parentNode._accessMethod = 'random';
  406.                                      return val;"/>
  407.     </implementation>
  408.   </binding>
  409.  
  410.  
  411.   <binding id="wizard-header" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  412.     <content>
  413.       <xul:hbox class="wizard-header-box-1" flex="1">
  414.         <xul:vbox class="wizard-header-box-text" flex="1">
  415.           <xul:label class="wizard-header-label" xbl:inherits="value=label"/>
  416.           <xul:label class="wizard-header-description" xbl:inherits="value=description"/>
  417.         </xul:vbox>
  418.         <xul:image class="wizard-header-icon" xbl:inherits="src=iconsrc"/>
  419.       </xul:hbox>
  420.     </content>
  421.   </binding>
  422.   
  423.   <binding id="wizard-buttons" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  424.     <content>
  425.       <xul:vbox class="wizard-buttons-box-1" flex="1">
  426.         <xul:separator class="wizard-buttons-separator groove"/>
  427.         <xul:hbox class="wizard-buttons-box-2">
  428.           <xul:spacer flex="1"/>
  429.           <xul:button class="wizard-button" dlgtype="back"/>
  430.           <xul:deck class="wizard-next-deck" anonid="WizardButtonDeck">
  431.             <xul:hbox>
  432.               <xul:button class="wizard-button" dlgtype="finish" default="true" flex="1"/> 
  433.             </xul:hbox>
  434.             <xul:hbox>
  435.               <xul:button class="wizard-button" dlgtype="next" default="true" flex="1"/> 
  436.             </xul:hbox>
  437.           </xul:deck>
  438.           <xul:button class="wizard-button" dlgtype="cancel"/> 
  439.         </xul:hbox>
  440.       </xul:vbox>
  441.     </content>
  442.     
  443.     <implementation>
  444.       <field name="_wizardButtonDeck" readonly="true">
  445.         document.getAnonymousElementByAttribute(this, "anonid", "WizardButtonDeck");
  446.       </field>
  447.       
  448.       <method name="onPageChange">
  449.         <body><![CDATA[
  450.           if (this.getAttribute("lastpage") == "true") {
  451.             this._wizardButtonDeck.setAttribute("selectedIndex", 0);
  452.           } else {
  453.             this._wizardButtonDeck.setAttribute("selectedIndex", 1);
  454.           }
  455.         ]]></body>
  456.       </method>
  457.     </implementation>
  458.   </binding>
  459.  
  460. </bindings>
  461.