home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / toolkit.jar / content / global / bindings / wizard.xml < prev   
Encoding:
Extensible Markup Language  |  2001-08-04  |  16.1 KB  |  450 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.  
  7.   <binding id="wizard-base">
  8.     <resources>
  9.       <stylesheet src="chrome://global/skin/wizard.css"/>
  10.     </resources>
  11.   </binding>
  12.   
  13.   <binding id="wizard" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  14.     <content width="500" height="380" persist="x y width height">
  15.       <xul:hbox class="wizard-header" anonid="Header"/>
  16.       
  17.       <xul:deck class="wizard-page-box" deck="true" flex="1" anonid="Deck">
  18.         <children includes="wizardpage"/>
  19.       </xul:deck>
  20.       <children/>
  21.       
  22.       <xul:hbox class="wizard-buttons" anonid="Buttons" inherits="pagestep,firstpage,lastpage"/>
  23.     </content>
  24.     
  25.     <implementation>
  26.       <property name="title" onget="return this.getAttribute('title')"
  27.                              onset="this.setAttribute('title', val);"/>
  28.  
  29.       <property name="canAdvance" onget="return this._canAdvance;"
  30.                                   onset="this._canAdvance=val; this._nextButton.disabled=!val;"/>
  31.       <property name="canRewind" onget="return this._canRewind;"
  32.                                  onset="this._canRewind=val; this._backButton.disabled=!val;"/>
  33.       <property name="canCancel"/>
  34.  
  35.       <property name="accessMethod" onget="return this._accessMethod"/>
  36.  
  37.       <property name="pageCount">0</property>
  38.  
  39.       <property name="pageStack">null</property>
  40.  
  41.       <property name="pageStep" onget="return this.pageStack.length"/>
  42.  
  43.       <property name="currentPage" onget="return this._currentPage">
  44.         <setter>
  45.         <![CDATA[
  46.           this._currentPage = val;
  47.                     
  48.           if (this.onFirstPage) {
  49.             this.canRewind = false;
  50.             this.setAttribute("firstpage", "true");
  51.           } else {
  52.             this.canRewind = true;
  53.             this.setAttribute("firstpage", "false");
  54.           }
  55.                     
  56.           if (this.onLastPage) {
  57.             this.canAdvance = true;
  58.             this.setAttribute("lastpage", "true");
  59.           } else {
  60.             this.setAttribute("lastpage", "false");
  61.           }
  62.  
  63.           this._deck.setAttribute("index", val.pageIndex);
  64.           document.commandDispatcher.advanceFocusIntoSubtree(val);
  65.  
  66.           this.adjustWizardHeader();
  67.           this._wizardButtons.onPageChange();
  68.  
  69.           val.fireShow();
  70.           
  71.           return val;
  72.         ]]>
  73.         </setter>
  74.       </property>
  75.  
  76.       <property name="pageIndex" onget="return this._pageIndex;">
  77.         <setter>
  78.         <![CDATA[
  79.           if (val < 0 || val >= this.pageCount)
  80.             return this._pageIndex;
  81.  
  82.           this.currentPage = this.childNodes[val];
  83.         ]]>
  84.         </setter>
  85.       </property>
  86.  
  87.       <property name="onFirstPage"
  88.                 onget="return this.pageStack.length == 1;"/>
  89.  
  90.       <property name="onLastPage">
  91.         <getter><![CDATA[
  92.           var cp = this.currentPage;
  93.           return cp && ((this._accessMethod == "sequential" && cp.pageIndex == this.pageCount-1) ||
  94.                        (this._accessMethod == "random" && cp.next == ""));
  95.          ]]></getter>
  96.       </property>
  97.  
  98.       <property name="_canAdvance"/>
  99.       <property name="_canRewind"/>
  100.       <property name="_onBack"/>
  101.       <property name="_onNext"/>
  102.       <property name="_onCancel"/>
  103.       <property name="_wizardHeader"/>
  104.       <property name="_wizardButtons"/>
  105.       <property name="_deck"/>
  106.       <property name="_backButton"/>
  107.       <property name="_nextButton"/>
  108.       <property name="_cancelButton"/>
  109.  
  110.       <property name="_backFunc">(function() { this._wizard.rewind(); })</property>
  111.       <property name="_nextFunc">(function() { this._wizard.advance(); })</property>
  112.       <property name="_finishFunc">(function() { this._wizard.advance(); })</property>
  113.       <property name="_cancelFunc">(function() { this._wizard.cancel(); })</property>
  114.        
  115.       <constructor><![CDATA[
  116.         this._canAdvance = true;
  117.         this._canRewind = false;
  118.         this.canCancel = true;
  119.         
  120.         this.pageStack = [];
  121.         
  122.         // need to create string bundle manually instead of using <xul:stringbundle/>
  123.         // see bug 63370 for details
  124.         var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"]
  125.                               .getService(Components.interfaces.nsILocaleService);
  126.         var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService);
  127.         var bundleURL = "chrome://global-platform/locale/wizard.properties";
  128.         this._bundle = stringBundleService.createBundle(bundleURL, localeService.GetApplicationLocale());
  129.         
  130.         // get anonymous content references
  131.         this._wizardHeader = document.getAnonymousElementByAttribute(this, "anonid", "Header");
  132.         this._wizardButtons = document.getAnonymousElementByAttribute(this, "anonid", "Buttons");
  133.         this._deck = document.getAnonymousElementByAttribute(this, "anonid", "Deck");
  134.         
  135.         this.initWizardButton("back");
  136.         this.initWizardButton("next");
  137.         this.initWizardButton("finish");
  138.         this.initWizardButton("cancel");
  139.         
  140.         this.initPages();
  141.         
  142.         // get wizard event handlers
  143.         var back = this.getAttribute("onwizardback");
  144.         if (back)
  145.           this._onBack = new Function("wizard", back);
  146.         var next = this.getAttribute("onwizardnext");
  147.         if (next)
  148.           this._onNext = new Function("wizard", next);
  149.         var cancel = this.getAttribute("onwizardcancel");
  150.         if (cancel)
  151.           this._onCancel = new Function("wizard", cancel);
  152.         var finish = this.getAttribute("onwizardfinish");
  153.         if (finish)
  154.           this._onFinish = new Function("wizard", finish);
  155.         
  156.         window.addEventListener("close", this._cancelFunc, false);
  157.         
  158.         this.pageCount = this.childNodes.length;
  159.         this.advance(this.childNodes[0].pageid);
  160.       ]]></constructor>
  161.  
  162.       <method name="initPages">
  163.         <body><![CDATA[
  164.           var meth = "sequential";
  165.           for (var i = 0; i < this.childNodes.length; ++i) {
  166.             var page = this.childNodes[i];
  167.             page._pageIndex = i;
  168.             if (page.next != "")
  169.               meth = "random";
  170.           }
  171.           this._accessMethod = meth;
  172.         ]]></body>
  173.       </method>
  174.  
  175.       <method name="initWizardButton">
  176.         <parameter name="aName"/>
  177.         <body><![CDATA[
  178.          var btn = document.getAnonymousElementByAttribute(this._wizardButtons, "wizardbutton", aName);
  179.          if (btn) {
  180.            btn.addEventListener("command", this["_"+aName+"Func"], false);
  181.            btn.setAttribute("label", this._bundle.GetStringFromName("button-"+aName));
  182.            btn._wizard = this;
  183.            this["_"+aName+"Button"] = btn;
  184.          }
  185.          return btn;
  186.         ]]></body>
  187.       </method>
  188.  
  189.       <method name="adjustWizardHeader">
  190.         <body><![CDATA[
  191.           var label = this.currentPage.getAttribute("label");
  192.           if (!label && this.onFirstPage)
  193.             label = this._bundle.formatStringFromName("default-first-title", [this.title], 1);
  194.           else if (!label && this.onLastPage)
  195.             label = this._bundle.formatStringFromName("default-last-title", [this.title], 1);
  196.           this._wizardHeader.setAttribute("label", label);
  197.           this._wizardHeader.setAttribute("description", this.currentPage.getAttribute("description"));
  198.         ]]></body>
  199.       </method>
  200.  
  201.       <method name="getPageById">
  202.         <parameter name="aPageId"/>
  203.         <body><![CDATA[
  204.           var els = this.getElementsByAttribute("pageid", aPageId);
  205.           return els.length > 0 ? els[0] : null;
  206.         ]]></body>
  207.       </method>
  208.  
  209.       <method name="isPageLoaded">
  210.         <parameter name="aPageId"/>
  211.         <body><![CDATA[
  212.         ]]></body>
  213.       </method>
  214.  
  215.       <method name="rewind">
  216.         <body><![CDATA[
  217.           if (!this.canRewind)
  218.             return;
  219.  
  220.           if (this.currentPage && !this.currentPage.fireHide())
  221.             return;
  222.  
  223.           if (this._onBack && !this._onBack(this))
  224.             return;
  225.             
  226.           this.pageStack.pop();
  227.           this.currentPage = this.pageStack[this.pageStack.length-1];
  228.           this.setAttribute("pagestep", this.pageStack.length);
  229.         ]]></body>
  230.       </method>
  231.  
  232.       <method name="advance">
  233.         <parameter name="aPageId"/>
  234.         <body><![CDATA[
  235.           if (!this.canAdvance)
  236.             return; 
  237.             
  238.           if (this.currentPage && !this.currentPage.fireHide())
  239.             return;
  240.           
  241.           if (this.onLastPage) {
  242.             if (!this._onFinish || this._onFinish(this))
  243.               window.close();
  244.           } else {
  245.             if (this._onNext && !this._onNext(this))
  246.               return; 
  247.             
  248.             var page;
  249.             if (aPageId)
  250.               page = this.getPageById(aPageId);
  251.             else {
  252.               if (this._accessMethod == "random")
  253.                 page = this.getPageById(this.currentPage.next);
  254.               else
  255.                 page = this.childNodes[this.currentPage.pageIndex+1];
  256.             }
  257.  
  258.             this.pageStack.push(page);
  259.             this.setAttribute("pagestep", this.pageStack.length);
  260.  
  261.             this.currentPage = page;
  262.           }
  263.         ]]></body>
  264.       </method>
  265.       
  266.       <method name="goTo">
  267.         <parameter name="aPageId"/>
  268.         <body><![CDATA[
  269.           var page = this.getPageById(aPageId);
  270.           if (page) {
  271.             this.pageStack[this.pageStack.length-1] = page;
  272.             this.currentPage = page;
  273.           }
  274.         ]]></body>
  275.       </method>
  276.               
  277.       <method name="cancel">
  278.         <body><![CDATA[
  279.           if (this._onCancel && !this._onCancel(this))
  280.             return;
  281.  
  282.           window.close();            
  283.         ]]></body>
  284.       </method>
  285.       
  286.     </implementation>
  287.  
  288.     <handlers>
  289.       <handler event="keypress" keycode="VK_ENTER" 
  290.         action="var c = document.commandDispatcher.focusedElement;
  291.                 if (c == this._cancelButton)
  292.                   this.cancel();
  293.                 else if (c == this._backButton)
  294.                   this.rewind();
  295.                 else
  296.                   this.advance();"/>
  297.  
  298.       <handler event="keypress" keycode="VK_RETURN"
  299.          action="var c = document.commandDispatcher.focusedElement;
  300.                  if (c == this._cancelButton)
  301.                    this.cancel();
  302.                  else if (c == this._backButton)
  303.                    this.rewind();
  304.                   else
  305.                    this.advance();"/>
  306.                    
  307.       <handler event="keypress" keycode="VK_ESCAPE" action="document.firstChild.cancel();"/>
  308.     </handlers>
  309.   </binding>
  310.  
  311.   <binding id="wizardpage" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  312.     <implementation>
  313.       <property name="pageid" onget="return this.getAttribute('pageid');"
  314.                               onset="this.setAttribute('pageid', val);"/>
  315.  
  316.       <property name="pageIndex" onget="return this._pageIndex;"/>
  317.  
  318.       <property name="next"   onget="return this.getAttribute('next');"
  319.                               onset="this.setAttribute('next', val); 
  320.                                      this.parentNode._accessType = 'random';"/>
  321.  
  322.       <constructor><![CDATA[
  323.         var onpageshow = this.getAttribute("onpageshow");
  324.         var onpagehide = this.getAttribute("onpagehide");
  325.         try {
  326.           if (onpageshow)
  327.             this.onpageshow = new Function(onpageshow);
  328.           if (onpagehide)
  329.             this.onpagehide = new Function(onpagehide);
  330.         } catch (ex) {}
  331.       ]]></constructor>
  332.  
  333.       <method name="fireShow">
  334.         <body><![CDATA[
  335.           if (this.onpageshow) {
  336.             var result = this.onpageshow();
  337.             return result == undefined ? true : result;
  338.           }
  339.           return true;
  340.         ]]></body>
  341.       </method>
  342.       
  343.       <method name="fireHide">
  344.         <body><![CDATA[
  345.           if (this.onpagehide) {
  346.             var result = this.onpagehide();
  347.             return result == undefined ? true : result;
  348.           }
  349.           return true;
  350.         ]]></body>
  351.       </method>
  352.       
  353.     </implementation>
  354.   </binding>
  355.  
  356.   <binding id="wizard-header" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  357.     <content>
  358.       <xul:hbox class="wizard-header-box-1" flex="1">
  359.         <xul:vbox class="wizard-header-box-text" flex="1">
  360.           <xul:text class="wizard-header-label" inherits="value=label"/>
  361.           <xul:text class="wizard-header-description" inherits="value=description"/>
  362.         </xul:vbox>
  363.         <xul:image class="wizard-header-icon" inherits="src=iconsrc"/>
  364.       </xul:hbox>
  365.     </content>
  366.   </binding>
  367.   
  368.   <binding id="wizard-buttons" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  369.     <content>
  370.       <xul:vbox class="wizard-buttons-box-1" flex="1">
  371.         <xul:separator class="wizard-buttons-separator groove"/>
  372.         <xul:hbox class="wizard-buttons-box-2">
  373.           <xul:spring flex="1"/>
  374.           <xul:button class="wizard-button" wizardbutton="back"/>
  375.           <xul:deck class="wizard-next-deck" anonid="WizardButtonDeck">
  376.             <xul:button class="wizard-button" wizardbutton="finish" default="true"/> 
  377.             <xul:button class="wizard-button" wizardbutton="next" default="true"/> 
  378.           </xul:deck>
  379.           <xul:button class="wizard-button" wizardbutton="cancel"/> 
  380.         </xul:hbox>
  381.       </xul:vbox>
  382.     </content>
  383.     
  384.     <implementation>
  385.       <constructor>
  386.          this._wizardButtonDeck = document.getAnonymousElementByAttribute(this, "anonid", "WizardButtonDeck");
  387.       </constructor>
  388.       
  389.       <method name="onPageChange">
  390.         <body><![CDATA[
  391.           if (this.getAttribute("lastpage") == "true") {
  392.             this._wizardButtonDeck.setAttribute("index", 0);
  393.           } else {
  394.             this._wizardButtonDeck.setAttribute("index", 1);
  395.           }
  396.         ]]></body>
  397.       </method>
  398.     </implementation>
  399.   </binding>
  400.  
  401.   <binding id="wizard-header-mac" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  402.     <content>
  403.       <xul:stack class="wizard-header-stack" flex="1">
  404.         <xul:vbox class="wizard-header-box-1">
  405.           <xul:vbox class="wizard-header-box-2">
  406.             <xul:vbox class="wizard-header-box-text">
  407.               <xul:text class="wizard-header-label" inherits="value=label"/>
  408.             </xul:vbox>
  409.           </xul:vbox>
  410.         </xul:vbox>
  411.         <xul:hbox class="wizard-header-box-icon">
  412.           <xul:spring flex="1"/>
  413.           <xul:image class="wizard-header-icon" inherits="src=iconsrc"/>
  414.         </xul:hbox>
  415.       </xul:stack>
  416.     </content>
  417.   </binding>
  418.   
  419.   <binding id="wizard-buttons-mac" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  420.     <content>
  421.       <xul:vbox flex="1">
  422.         <xul:hbox class="wizard-buttons-top" inherits="hidden=hidetoprow">
  423.           <xul:spring flex="1"/>
  424.           <xul:button class="wizard-button" wizardbutton="cancel"/> 
  425.           <xul:button class="wizard-button" wizardbutton="finish" default="true"/> 
  426.         </xul:hbox>
  427.         <xul:separator class="wizard-buttons-separator groove"/>
  428.         <xul:hbox class="wizard-buttons-btm">
  429.           <xul:spring flex="1"/>
  430.           <xul:button class="wizard-button wizard-nav-button" wizardbutton="back"/>
  431.           <xul:hbox class="wizard-label-box" align="center">
  432.             <xul:text class="wizard-page-label" inherits="value=pagestep"/>
  433.           </xul:hbox>
  434.           <xul:button class="wizard-button wizard-nav-button" wizardbutton="next" default="true" inherits="disabled=lastpage"/> 
  435.         </xul:hbox>
  436.       </xul:vbox>
  437.     </content>
  438.  
  439.     <implementation>
  440.       <method name="onPageChange">
  441.         <body><![CDATA[
  442.           this.setAttribute("hidetoprow", !(this.getAttribute("lastpage") == "true"));
  443.         ]]></body>
  444.       </method>
  445.     </implementation>
  446.  
  447.   </binding>
  448.  
  449. </bindings>
  450.