home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 May / PCWorld_2003-05_cd.bin / Komunik / phoenix / chrome / toolkit.jar / content / global / bindings / wizard.xml < prev   
Extensible Markup Language  |  2002-04-16  |  18KB  |  506 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 width="500" height="380" persist="x y width height">
  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.           this.currentPage = this.wizardPages[val];
  99.         ]]>
  100.         </setter>
  101.       </property>
  102.  
  103.       <property name="onFirstPage"
  104.                 onget="return this._pageStack.length == 1;"/>
  105.  
  106.       <property name="onLastPage">
  107.         <getter><![CDATA[
  108.           var cp = this.currentPage;
  109.           return cp && ((this._accessMethod == "sequential" && cp.pageIndex == this.pageCount-1) ||
  110.                        (this._accessMethod == "random" && cp.next == ""));
  111.          ]]></getter>
  112.       </property>
  113.  
  114.       <method name="getButton">
  115.         <parameter name="aDlgType"/>
  116.         <body>
  117.         <![CDATA[
  118.           var btns = this.getElementsByAttribute("dlgtype", aDlgType);
  119.           return btns.length > 0 ? btns[0] : document.getAnonymousElementByAttribute(this._wizardButtons, "dlgtype", aDlgType);
  120.         ]]>
  121.         </body>
  122.       </method>
  123.  
  124.       <field name="_canAdvance"/>
  125.       <field name="_canRewind"/>
  126.       <field name="_wizardHeader"/>
  127.       <field name="_wizardButtons"/>
  128.       <field name="_deck"/>
  129.       <field name="_backButton"/>
  130.       <field name="_nextButton"/>
  131.       <field name="_cancelButton"/>
  132.  
  133.       <!-- functions to be added as oncommand listeners to the wizard buttons -->
  134.       <field name="_backFunc">(function() { document.documentElement.rewind(); })</field>
  135.       <field name="_nextFunc">(function() { document.documentElement.advance(); })</field>
  136.       <field name="_finishFunc">(function() { document.documentElement.advance(); })</field>
  137.       <field name="_cancelFunc">(function() { document.documentElement.cancel(); })</field>
  138.  
  139.       <field name="_closeHandler">(function(event) {
  140.         if (document.documentElement.cancel())
  141.           event.preventDefault();
  142.       })</field>
  143.        
  144.       <constructor><![CDATA[
  145.         this._canAdvance = true;
  146.         this._canRewind = false;
  147.         this._hasLoaded = false;
  148.         
  149.         this._pageStack = [];
  150.         
  151.         // need to create string bundle manually instead of using <xul:stringbundle/>
  152.         // see bug 63370 for details
  153.         var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"]
  154.                               .getService(Components.interfaces.nsILocaleService);
  155.         var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService);
  156.         var bundleURL = "chrome://global-platform/locale/wizard.properties";
  157.         this._bundle = stringBundleService.createBundle(bundleURL, localeService.GetApplicationLocale());
  158.         
  159.         // get anonymous content references
  160.         this._wizardHeader = document.getAnonymousElementByAttribute(this, "anonid", "Header");
  161.         this._wizardButtons = document.getAnonymousElementByAttribute(this, "anonid", "Buttons");
  162.         this._deck = document.getAnonymousElementByAttribute(this, "anonid", "Deck");
  163.         
  164.         this._initWizardButton("back");
  165.         this._initWizardButton("next");
  166.         this._initWizardButton("finish");
  167.         this._initWizardButton("cancel");
  168.         
  169.         this._initPages();
  170.         
  171.         window.addEventListener("close", this._closeHandler, false);
  172.         
  173.         // start off on the first page
  174.         this.pageCount = this.wizardPages.length;
  175.         this.advance();
  176.         
  177.         // give focus to the first focusable element in the dialog
  178.         window.addEventListener("load", this._setInitialFocus, false);
  179.       ]]></constructor>
  180.  
  181.       <method name="getPageById">
  182.         <parameter name="aPageId"/>
  183.         <body><![CDATA[
  184.           var els = this.getElementsByAttribute("pageid", aPageId);
  185.           return els.length > 0 ? els[0] : null;
  186.         ]]></body>
  187.       </method>
  188.  
  189.       <method name="rewind">
  190.         <body><![CDATA[
  191.           if (!this.canRewind)
  192.             return;
  193.  
  194.           if (this.currentPage && !this._fireEvent(this.currentPage, "pagehide"))
  195.             return;
  196.  
  197.           if (this.currentPage && !this._fireEvent(this.currentPage, "pagerewound"))
  198.             return;
  199.  
  200.           if (!this._fireEvent(this, "wizardback"))
  201.             return;
  202.             
  203.             
  204.           this._pageStack.pop();
  205.           this.currentPage = this._pageStack[this._pageStack.length-1];
  206.           this.setAttribute("pagestep", this._pageStack.length);
  207.         ]]></body>
  208.       </method>
  209.  
  210.       <method name="advance">
  211.         <parameter name="aPageId"/>
  212.         <body><![CDATA[
  213.           if (!this.canAdvance)
  214.             return; 
  215.             
  216.           if (this.currentPage && !this._fireEvent(this.currentPage, "pagehide"))
  217.             return;
  218.             
  219.           if (this.currentPage && !this._fireEvent(this.currentPage, "pageadvanced"))
  220.             return;
  221.  
  222.           if (this.onLastPage) {
  223.             if (this._fireEvent(this, "wizardfinish"))
  224.               window.setTimeout(function() {window.close();}, 1);
  225.           } else {
  226.             if (!this._fireEvent(this, "wizardnext"))
  227.               return; 
  228.             
  229.             var page;
  230.             if (aPageId)
  231.               page = this.getPageById(aPageId);
  232.             else {
  233.               if (this.currentPage) {
  234.                 if (this._accessMethod == "random")
  235.                   page = this.getPageById(this.currentPage.next);
  236.                 else
  237.                   page = this.wizardPages[this.currentPage.pageIndex+1];
  238.               } else
  239.                 page = this.wizardPages[0];
  240.             }
  241.  
  242.             if (page) {
  243.               this._pageStack.push(page);
  244.               this.setAttribute("pagestep", this._pageStack.length);
  245.   
  246.               this.currentPage = page;
  247.             }
  248.           }
  249.         ]]></body>
  250.       </method>
  251.       
  252.       <method name="goTo">
  253.         <parameter name="aPageId"/>
  254.         <body><![CDATA[
  255.           var page = this.getPageById(aPageId);
  256.           if (page) {
  257.             this._pageStack[this._pageStack.length-1] = page;
  258.             this.currentPage = page;
  259.           }
  260.         ]]></body>
  261.       </method>
  262.               
  263.       <method name="cancel">
  264.         <body><![CDATA[
  265.           if (!this._fireEvent(this, "wizardcancel"))
  266.             return true;
  267.  
  268.           window.close();
  269.           window.setTimeout(function() {window.close();}, 1);
  270.         ]]></body>
  271.       </method>
  272.       
  273.       <method name="_setInitialFocus">
  274.         <parameter name="aEvent"/>
  275.         <body>
  276.         <![CDATA[
  277.           document.documentElement._hasLoaded = true;
  278.           var focusInit = 
  279.             function() {
  280.               // give focus to the first focusable element in the dialog
  281.               if (!document.commandDispatcher.focusedElement)
  282.                 document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement);
  283.             };
  284.  
  285.           // Give focus after onload completes, see bug 103197.
  286.           setTimeout(focusInit, 0);
  287.         ]]>
  288.         </body>
  289.       </method>                
  290.  
  291.       <method name="_advanceFocusToPage">
  292.         <parameter name="aPage"/>
  293.         <body>
  294.         <![CDATA[
  295.           if (!this._hasLoaded)
  296.             return;
  297.             
  298.           document.commandDispatcher.advanceFocusIntoSubtree(aPage);
  299.           
  300.           // if advanceFocusIntoSubtree tries to focus one of our
  301.           // dialog buttons, then remove it and put it on the root
  302.           var focused = document.commandDispatcher.focusedElement;
  303.           if (focused && focused.hasAttribute("dlgtype"))
  304.             this.focus();
  305.         ]]>
  306.         </body>
  307.       </method>                
  308.  
  309.       <method name="_initPages">
  310.         <body><![CDATA[
  311.           var meth = "sequential";
  312.           var pages = this.wizardPages;
  313.           for (var i = 0; i < pages.length; ++i) {
  314.             var page = pages[i];
  315.             page.pageIndex = i;
  316.             if (page.next != "")
  317.               meth = "random";
  318.           }
  319.           this._accessMethod = meth;
  320.         ]]></body>
  321.       </method>
  322.  
  323.       <method name="_initWizardButton">
  324.         <parameter name="aName"/>
  325.         <body><![CDATA[
  326.          var btn = document.getAnonymousElementByAttribute(this._wizardButtons, "dlgtype", aName);
  327.          if (btn) {
  328.            btn.addEventListener("command", this["_"+aName+"Func"], false);
  329.            btn.setAttribute("label", this._bundle.GetStringFromName("button-"+aName));
  330.            this["_"+aName+"Button"] = btn;
  331.          }
  332.          return btn;
  333.         ]]></body>
  334.       </method>
  335.  
  336.       <method name="_adjustWizardHeader">
  337.         <body><![CDATA[
  338.           var label = this.currentPage.getAttribute("label");
  339.           if (!label && this.onFirstPage)
  340.             label = this._bundle.formatStringFromName("default-first-title", [this.title], 1);
  341.           else if (!label && this.onLastPage)
  342.             label = this._bundle.formatStringFromName("default-last-title", [this.title], 1);
  343.           this._wizardHeader.setAttribute("label", label);
  344.           this._wizardHeader.setAttribute("description", this.currentPage.getAttribute("description"));
  345.         ]]></body>
  346.       </method>
  347.  
  348.       <method name="_hitEnter">
  349.         <body>
  350.         <![CDATA[
  351.           // if a button is focused, dispatch its command instead 
  352.           // of advancing the wizard
  353.           var focused = document.commandDispatcher.focusedElement;
  354.           if (!(focused && focused.localName == "button" && focused.hasAttribute("dlgtype")))
  355.             this.advance();
  356.         ]]>
  357.         </body>
  358.       </method>
  359.  
  360.       <method name="_fireEvent">
  361.         <parameter name="aTarget"/>
  362.         <parameter name="aType"/>
  363.         <body>
  364.         <![CDATA[
  365.           var event = document.createEvent("Events");
  366.           event.initEvent(aType, false, true);
  367.           
  368.           // handle dom event handlers
  369.           var noCancel = aTarget.dispatchEvent(event);
  370.           
  371.           // handle any xml attribute event handlers
  372.           var handler = aTarget.getAttribute("on"+aType);
  373.           if (handler != "") {
  374.             var fn = new Function("event", handler);
  375.             var returned = fn.apply(aTarget, [event]);
  376.             if (returned == false)
  377.               noCancel = false;
  378.           }
  379.  
  380.           return noCancel;
  381.         ]]>
  382.         </body>
  383.       </method>
  384.  
  385.     </implementation>
  386.  
  387.     <handlers>
  388.       <handler event="keypress" keycode="VK_ENTER" action="this._hitEnter()"/>
  389.       <handler event="keypress" keycode="VK_RETURN" action="this._hitEnter()"/>
  390.       <handler event="keypress" keycode="VK_ESCAPE" action="this.cancel();"/>
  391.     </handlers>
  392.   </binding>
  393.  
  394.   <binding id="wizardpage" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  395.     <implementation>
  396.       <field name="pageIndex">null</field>
  397.       
  398.       <property name="pageid" onget="return this.getAttribute('pageid');"
  399.                               onset="this.setAttribute('pageid', val);"/>
  400.  
  401.       <property name="next"   onget="return this.getAttribute('next');"
  402.                               onset="this.setAttribute('next', val);
  403.                                      this.parentNode._accessMethod = 'random';
  404.                                      return val;"/>
  405.     </implementation>
  406.   </binding>
  407.  
  408.   <binding id="wizard-header" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  409.     <content>
  410.       <xul:hbox class="wizard-header-box-1" flex="1">
  411.         <xul:vbox class="wizard-header-box-text" flex="1">
  412.           <xul:label class="wizard-header-label" xbl:inherits="value=label"/>
  413.           <xul:label class="wizard-header-description" xbl:inherits="value=description"/>
  414.         </xul:vbox>
  415.         <xul:image class="wizard-header-icon" xbl:inherits="src=iconsrc"/>
  416.       </xul:hbox>
  417.     </content>
  418.   </binding>
  419.   
  420.   <binding id="wizard-buttons" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  421.     <content>
  422.       <xul:vbox class="wizard-buttons-box-1" flex="1">
  423.         <xul:separator class="wizard-buttons-separator groove"/>
  424.         <xul:hbox class="wizard-buttons-box-2">
  425.           <xul:spacer flex="1"/>
  426.           <xul:button class="wizard-button" dlgtype="back"/>
  427.           <xul:deck class="wizard-next-deck" anonid="WizardButtonDeck">
  428.             <xul:hbox>
  429.               <xul:button class="wizard-button" dlgtype="finish" default="true" flex="1"/> 
  430.             </xul:hbox>
  431.             <xul:hbox>
  432.               <xul:button class="wizard-button" dlgtype="next" default="true" flex="1"/> 
  433.             </xul:hbox>
  434.           </xul:deck>
  435.           <xul:button class="wizard-button" dlgtype="cancel"/> 
  436.         </xul:hbox>
  437.       </xul:vbox>
  438.     </content>
  439.     
  440.     <implementation>
  441.       <constructor>
  442.          this._wizardButtonDeck = document.getAnonymousElementByAttribute(this, "anonid", "WizardButtonDeck");
  443.       </constructor>
  444.       
  445.       <method name="onPageChange">
  446.         <body><![CDATA[
  447.           if (this.getAttribute("lastpage") == "true") {
  448.             this._wizardButtonDeck.setAttribute("selectedIndex", 0);
  449.           } else {
  450.             this._wizardButtonDeck.setAttribute("selectedIndex", 1);
  451.           }
  452.         ]]></body>
  453.       </method>
  454.     </implementation>
  455.   </binding>
  456.  
  457.   <binding id="wizard-header-mac" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  458.     <content>
  459.       <xul:stack class="wizard-header-stack" flex="1">
  460.         <xul:vbox class="wizard-header-box-1">
  461.           <xul:vbox class="wizard-header-box-2">
  462.             <xul:vbox class="wizard-header-box-text">
  463.               <xul:label class="wizard-header-label" xbl:inherits="value=label"/>
  464.             </xul:vbox>
  465.           </xul:vbox>
  466.         </xul:vbox>
  467.         <xul:hbox class="wizard-header-box-icon">
  468.           <xul:spacer flex="1"/>
  469.           <xul:image class="wizard-header-icon" xbl:inherits="src=iconsrc"/>
  470.         </xul:hbox>
  471.       </xul:stack>
  472.     </content>
  473.   </binding>
  474.   
  475.   <binding id="wizard-buttons-mac" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  476.     <content>
  477.       <xul:vbox flex="1">
  478.         <xul:hbox class="wizard-buttons-top" xbl:inherits="hidden=hidetoprow">
  479.           <xul:spacer flex="1"/>
  480.           <xul:button class="wizard-button" dlgtype="cancel"/> 
  481.           <xul:button class="wizard-button" dlgtype="finish" default="true"/> 
  482.         </xul:hbox>
  483.         <xul:separator class="wizard-buttons-separator groove"/>
  484.         <xul:hbox class="wizard-buttons-btm">
  485.           <xul:spacer flex="1"/>
  486.           <xul:button class="wizard-button wizard-nav-button" dlgtype="back"/>
  487.           <xul:hbox class="wizard-label-box" align="center">
  488.             <xul:label class="wizard-page-label" xbl:inherits="value=pagestep"/>
  489.           </xul:hbox>
  490.           <xul:button class="wizard-button wizard-nav-button" dlgtype="next" default="true" xbl:inherits="disabled=lastpage"/> 
  491.         </xul:hbox>
  492.       </xul:vbox>
  493.     </content>
  494.  
  495.     <implementation>
  496.       <method name="onPageChange">
  497.         <body><![CDATA[
  498.           this.setAttribute("hidetoprow", !(this.getAttribute("lastpage") == "true"));
  499.         ]]></body>
  500.       </method>
  501.     </implementation>
  502.  
  503.   </binding>
  504.  
  505. </bindings>
  506.