home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / 01_03.iso / software / ghostzilla_hit / files / ghostzilla-1.0-plus-install.exe / res / builtin / selectBindings.xml < prev    next >
Encoding:
Extensible Markup Language  |  2002-04-09  |  13.0 KB  |  414 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="formWidgets"
  4.           xmlns="http://www.mozilla.org/xbl"
  5.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  6.  
  7.   <binding id="select-base">
  8.     <implementation>
  9.       <property name="size">
  10.         <getter>
  11.           var size = this.getAttribute("size")
  12.           return !size ? 1 : size;
  13.         </getter>
  14.         <setter>
  15.           this.setAttribute("size", val);
  16.           return val;
  17.         </setter>
  18.       </property>
  19.       
  20.       <property name="_selectArray">[]</property>  
  21.       <method name="_initSelection">
  22.         <body>
  23.         <![CDATA[
  24.           // Note that here we only initialize a _selectArray[0], as a selection
  25.           // of more than one option in the case of a regular select is meaningless.
  26.           var options = this.getElementsByTagName("option");
  27.           for (var i = 0; i < options.length; ++i) {
  28.             if (options[i].hasAttribute("selected")) {
  29.               this._selectArray.push(options[i]);
  30.               this._selectArray[0].selected = true; // XXX lame
  31.               break;
  32.             }
  33.           }
  34.           if (this.size == 1 && options.length && 
  35.               !this._selectArray.length)
  36.             options[0].selected = true;
  37.         ]]>
  38.         </body>
  39.       </method>
  40.     </implementation>
  41.   </binding>
  42.           
  43.   <binding id="select-size" display="xul:tree"
  44.            extends="resource:///res/builtin/selectBindings.xml#select-base">
  45.     <implementation>
  46.       <property name="value" onget="return this.getAttribute('value');">
  47.         <setter>
  48.         <![CDATA[
  49.           var options = this.getElementsByTagName("option");
  50.           for (var i = 0; i < options.length; ++i) {
  51.             if (options[i].getAttribute("value") == val)
  52.               this._selectArray.push(options[i]);
  53.           }
  54.           this.setAttribute("value", val);            
  55.           return val;
  56.         ]]>
  57.         </setter>
  58.       </property>
  59.       <property name="disabled" onset="if (val) this.setAttribute('disabled',true); 
  60.                                        else this.removeAttribute('disabled');
  61.                                        return val;"
  62.                                 onget="return (this.getAttribute('disabled')=='true');"/>
  63.       <property name="selectedIndex">
  64.         <getter>
  65.         <![CDATA[
  66.           if (!this._selectArray)
  67.             return -1;
  68.   
  69.           var options = this.getElementsByTagName("option");
  70.           for (var i = 0; i < options.length; ++i) {
  71.             if (options[i].getAttribute("selected")) 
  72.               return i;
  73.           }
  74.  
  75.           return -1;
  76.         ]]>
  77.         </getter>
  78.         <setter>
  79.         <![CDATA[
  80.           if (val >= 0 && this.hasChildNodes() && this.childNodes[val]) {
  81.             this.childNodes[val].setAttribute("selected", "true");
  82.             this._selectArray.push(this.childNodes[val]);
  83.           }
  84.           
  85.           return val;    
  86.         ]]>
  87.         </setter>
  88.       </property>
  89.       
  90.       <!-- Internal Implementation Methods -->
  91.       <method name="getElementByAttribute">
  92.         <parameter name="aAttributeName"/>
  93.         <parameter name="aAttributeValue"/>
  94.         <body>
  95.         <![CDATA[
  96.           var anonymousNodes = document.getAnonymousNodes(this);
  97.           for (var i = 0; i < anonymousNodes.length; ++i)
  98.             return this.recursiveAttributeSearch(anonymousNodes[i], aAttributeName, aAttributeValue);
  99.           return null;
  100.         ]]> 
  101.         </body>
  102.       </method>
  103.       <method name="recursiveAttributeSearch">
  104.         <parameter name="aNode"/>
  105.         <parameter name="aAttributeName"/>
  106.         <parameter name="aAttributeValue"/>
  107.         <body>
  108.         <![CDATA[
  109.           if (aNode) {
  110.             if (aNode.getAttribute(aAttributeName) == aAttributeValue)
  111.               return aNode;
  112.               
  113.             for (var i = 0; i < aNode.childNodes.length; ++i)
  114.               return this.recursiveAttributeSearch(aNode.childNodes[i], aAttributeName, aAttributeValue);
  115.           } 
  116.           return null;
  117.         ]]>
  118.         </body>
  119.       </method>
  120.       <method name="_deselectAll">
  121.         <body>
  122.         <![CDATA[
  123.           for (var i = 0; i < this._selectArray.length; ++i) {
  124.             dump("*** clearing selection for = " + this._selectArray[i].text + "\n");
  125.             this._selectArray[i].selected = false;
  126.           }
  127.         ]]>
  128.         </body>
  129.       </method>
  130.       <method name="_adjustSelection">
  131.         <parameter name="aSelectUp"/>
  132.         <paramater name="aAdditive"/>
  133.         <body>
  134.         <![CDATA[
  135.           if (this._selectArray.length < 1) return;
  136.           for (var i = 0; i < this._selectArray.length; ++i) {
  137.             if (this._selectArray[i] == this.childNodes[this.selectedIndex]) {
  138.               var currItem = this._selectArray[i];
  139.               this._deselectAll();
  140.               var nextItem = aSelectUp ? currItem.previousSibling : currItem.nextSibling;
  141.               if (nextItem) this.selectedIndex = nextItem.index;
  142.               break;
  143.             }
  144.           }
  145.         ]]>
  146.         </body>      
  147.       </method>
  148.       <constructor action="this._initSelection()"/>
  149.     </implementation>
  150.     <handlers>
  151.       <handler event="mousedown">
  152.       <![CDATA[
  153.         if (event.target.localName != "OPTION")
  154.           return;
  155.           
  156.         for (var i = 0; i < this._selectArray.length; ++i)
  157.           this._selectArray[i].removeAttribute('selected');
  158.         this._selectArray = [event.target];
  159.         event.target.setAttribute("selected", "true");
  160.       ]]>
  161.       </handler>
  162.       <handler event="command" phase="capturing">
  163.       <![CDATA[
  164.         if (event.target.localName == "menuitem") 
  165.           this.selectedItem = event.target;
  166.       ]]>
  167.       </handler>
  168.       <handler event="popupshowing">
  169.       <![CDATA[
  170.         if (event.target.parentNode == this && this.selectedItem) {
  171.           // Not ready for auto-setting the active child in hierarchies yet.
  172.           // For now, only do this when the outermost menupopup opens.
  173.           var menuBox = this.boxObject.QueryInterface(Components.interfaces.nsIMenuBoxObject);
  174.           menuBox.activeChild = this.selectedItem;
  175.         }
  176.       ]]>
  177.       </handler>
  178.       
  179.       <!-- Selection Management -->
  180.       <handler event="keypress" keycode="vk_up">
  181.       <![CDATA[
  182.         if (event.target == this)
  183.           this._adjustSelection(true);
  184.         event.preventDefault();
  185.       ]]>
  186.       </handler>
  187.       <handler event="keypress" keycode="vk_down">
  188.       <![CDATA[
  189.         if (event.target == this)
  190.           this._adjustSelection(false);
  191.         event.preventDefault();
  192.       ]]>
  193.       </handler>
  194.       
  195.       
  196.     </handlers>      
  197.   </binding>
  198.  
  199.   <binding id="select" display="xul:menu"
  200.                        extends="resource:///res/builtin/selectBindings.xml#select-base">
  201.     <implementation>
  202.       <property name="value" onget="return this.getAttribute('value');">
  203.         <setter>
  204.         <![CDATA[
  205.           var options = this.getElementsByTagName("option");
  206.           for (var i = 0; i < options.length; ++i) {
  207.             if (options[i].getAttribute("value") == val)
  208.               this._selectArray.push(options[i]);
  209.           }
  210.           this.setAttribute("value", val);            
  211.           return val;
  212.         ]]>
  213.         </setter>
  214.       </property>
  215.       <property name="disabled">
  216.         <getter>
  217.           return this.hasAttribute("disabled");
  218.         </getter>
  219.         <setter>
  220.           if (val == "true") this.setAttribute("disabled", "true");
  221.           else this.removeAttribute("disabled");
  222.           return val;
  223.         </setter>
  224.       </property>
  225.       <property name="selectedIndex">
  226.         <getter>
  227.         <![CDATA[
  228.           if (!this._selectArray)
  229.             return -1;
  230.   
  231.           var options = this.getElementsByTagName("option");
  232.           for (var i = 0; i < options.length; ++i) {
  233.             if (options[i].getAttribute("selected")) 
  234.               return i;
  235.           }
  236.  
  237.           return -1;
  238.         ]]>
  239.         </getter>
  240.         <setter>
  241.         <![CDATA[
  242.           this._selectArray = [];
  243.           
  244.           if (val >= 0 && this.hasChildNodes() && this.childNodes[val]) {
  245.             this.childNodes[val].setAttribute("selected", "true");
  246.             this._selectArray.push(this.childNodes[val]);
  247.              
  248.             var textDisplayNode = this.getElementByAttribute("selectattr", "text");  
  249.             if (textDisplayNode) { 
  250.               var text = this.childNodes[val].text;
  251.               text = text.replace(/\n/g, "");
  252.               textDisplayNode.setAttribute("value", text);
  253.             }
  254.           }
  255.           
  256.           return val;    
  257.         ]]>
  258.         </setter>
  259.       </property>
  260.       
  261.       <!-- Internal Implementation Methods -->
  262.       <method name="getElementByAttribute">
  263.         <parameter name="aAttributeName"/>
  264.         <parameter name="aAttributeValue"/>
  265.         <body>
  266.         <![CDATA[
  267.           var anonymousNodes = document.getAnonymousNodes(this);
  268.           for (var i = 0; i < anonymousNodes.length; ++i)
  269.             return this.recursiveAttributeSearch(anonymousNodes[i], aAttributeName, aAttributeValue);
  270.           return null;
  271.         ]]> 
  272.         </body>
  273.       </method>
  274.       <method name="recursiveAttributeSearch">
  275.         <parameter name="aNode"/>
  276.         <parameter name="aAttributeName"/>
  277.         <parameter name="aAttributeValue"/>
  278.         <body>
  279.         <![CDATA[
  280.           if (aNode) {
  281.             if (aNode.getAttribute(aAttributeName) == aAttributeValue)
  282.               return aNode;
  283.               
  284.             for (var i = 0; i < aNode.childNodes.length; ++i)
  285.               return this.recursiveAttributeSearch(aNode.childNodes[i], aAttributeName, aAttributeValue);
  286.           } 
  287.           return null;
  288.         ]]>
  289.         </body>
  290.       </method>
  291.     </implementation>
  292.     <handlers>
  293.       <handler event="command" phase="capturing">
  294.       <![CDATA[
  295.         if (event.target.localName == "OPTION") 
  296.           this.selectedIndex = event.target.index;
  297.       ]]>
  298.       </handler>
  299.       <handler event="popupshowing">
  300.       <![CDATA[
  301.         if (event.target == this && this._selectArray.length) {
  302.           // Not ready for auto-setting the active child in hierarchies yet.
  303.           // For now, only do this when the outermost menupopup opens.
  304.           var boxObject = document.getBoxObjectFor(this);
  305.           var menuBox = boxObject.QueryInterface(Components.interfaces.nsIMenuBoxObject);
  306.           menuBox.activeChild = this._selectArray[0];
  307.         }
  308.       ]]>
  309.       </handler>
  310.       <handler event="mouseover">
  311.       <![CDATA[
  312.         if (event.target.localName == "OPTION") {
  313.           var oldactive = this.getElementByAttribute("menuactive", "true");
  314.           if (oldactive)
  315.             oldactive.removeAttribute("menuactive");
  316.         }
  317.       ]]>
  318.       </handler>
  319.       <handler event="bindingattached" action="this._initSelection()"/>
  320.     </handlers>      
  321.   </binding>
  322.     
  323.   <binding id="option" display="xul:menuitem"
  324.                        extends="resource:///res/builtin/selectBindings.xml#option-base"/>
  325.  
  326.   <binding id="option-size" display="xul:treerow"
  327.                        extends="resource:///res/builtin/selectBindings.xml#option-base"/>
  328.                          
  329.   <binding id="option-base">
  330.     <implementation>
  331.       <property name="form" readonly="true"/>
  332.       
  333.       <property name="defaultSelected">false</property>
  334.       
  335.       <property name="text" readonly="true">
  336.         <getter>
  337.         <![CDATA[
  338.           var textString = "";
  339.           if (this.hasChildNodes()) {
  340.             for (var i = 0; i < this.childNodes.length; ++i)
  341.               textString += this.childNodes[i].nodeValue;
  342.           }
  343.           return textString;
  344.         ]]>
  345.         </getter>
  346.       </property>
  347.       
  348.       <property name="index" readonly="true">
  349.         <getter>
  350.         <![CDATA[
  351.           var parent = this.parentNode;
  352.           // bail on supporting optgroup at this juncture.
  353.           if (!parent) return -1;
  354.           
  355.           for (var i = 0; i < parent.childNodes.length; ++i) {
  356.             if (parent.childNodes[i] == this) 
  357.               return i;
  358.           }
  359.           return -1;
  360.         ]]>
  361.         </getter>
  362.       </property>
  363.       
  364.       <property name="disabled">
  365.         <getter>
  366.           return this.hasAttribute("disabled");
  367.         </getter>
  368.         <setter>
  369.           if (val) this.setAttribute("disabled", "true");
  370.           else this.removeAttribute("disabled");
  371.         </setter>
  372.       </property>
  373.       
  374.       <property name="label">
  375.         <getter>
  376.           return this.getAttribute("label");
  377.         </getter>
  378.         <setter>
  379.           this.setAttribute("label", val);
  380.           return val;
  381.         </setter>
  382.       </property>
  383.       
  384.       <property name="selected">
  385.         <getter>
  386.           return this.hasAttribute("selected");
  387.         </getter>
  388.         <setter>
  389.           var parent = this.parentNode;
  390.           if (parent)
  391.             parent.selectedIndex = this.index;
  392.           return val;
  393.         </setter>
  394.       </property>
  395.       
  396.       <property name="value">
  397.         <getter>
  398.           return this.getAttribute("value");
  399.         </getter>
  400.         <setter>
  401.           this.setAttribute("value", val);
  402.           return val;
  403.         </setter>
  404.       </property>
  405.       
  406.       <property name="_textNode">
  407.       
  408.       </property>
  409.     </implementation>
  410.   </binding>
  411.  
  412. </bindings>          
  413.  
  414.