home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / toolkit.jar / content / global / bindings / tree.xml < prev    next >
Encoding:
Extensible Markup Language  |  2001-08-04  |  19.4 KB  |  569 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="treeBindings"
  4.    xmlns="http://www.mozilla.org/xbl"
  5.    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  6.   
  7.   <binding id="tree-base">
  8.     <resources>
  9.       <stylesheet src="chrome://global/content/bindings/tree.css"/>
  10.       <stylesheet src="chrome://global/skin/tree.css"/>
  11.     </resources>
  12.   </binding>
  13.   
  14.   <binding id="tree"
  15.            extends="chrome://global/content/bindings/tree.xml#tree-base">
  16.     <content>
  17.       <children>
  18.       <xul:treecolgroup>
  19.       <xul:treecol flex="1"/>
  20.     </xul:treecolgroup>
  21.     </children>
  22.       <xul:treerows class="tree-container-treerows" inherits="dragover,dragdroptree">
  23.         <children includes="treehead|treechildren"/>
  24.       </xul:treerows> 
  25.     </content>
  26.     <implementation>
  27.       <property name="selectedIndex"
  28.                 onget="return (this.selectedItems.length > 0 ? this.getIndexOfItem(this.selectedItems[0]) : -1)"
  29.                 onset="if(val>=0){var item=this.getItemAtIndex(val); if(item) this.selectItem(item);} else this.clearItemSelection();"
  30.                 />
  31.       <property name="treeBoxObject"
  32.                 onget="return this.boxObject.QueryInterface(Components.interfaces.nsITreeBoxObject);"
  33.                 readonly="true"/>
  34.       <property name="isUpSelection">
  35.         0
  36.       </property>
  37.       <property name="isDownSelection">
  38.         0
  39.       </property>
  40.       <method name="getNextItem">
  41.         <parameter name="startItem"/>
  42.         <parameter name="delta"/>
  43.         <body>
  44.           return this.treeBoxObject.getNextItem(startItem, delta);
  45.         </body>
  46.       </method>
  47.       <method name="getPreviousItem">
  48.         <parameter name="startItem"/>
  49.         <parameter name="delta"/>
  50.         <body>
  51.           return this.treeBoxObject.getPreviousItem(startItem, delta);
  52.         </body>
  53.       </method>
  54.       <method name="getIndexOfItem">
  55.         <parameter name="item"/>
  56.         <body>
  57.           return this.treeBoxObject.getIndexOfItem(item);
  58.         </body>
  59.       </method>
  60.       <method name="getItemAtIndex">
  61.         <parameter name="index"/>
  62.         <body>
  63.           return this.treeBoxObject.getItemAtIndex(index);
  64.         </body>
  65.       </method>
  66.       <method name="ensureIndexIsVisible">
  67.         <parameter name="index"/>
  68.         <body>
  69.           return this.treeBoxObject.ensureIndexIsVisible(index);
  70.         </body>
  71.       </method>
  72.       <method name="ensureElementIsVisible">
  73.         <parameter name="element"/>
  74.         <body>
  75.           return this.ensureIndexIsVisible(this.treeBoxObject.getIndexOfItem(element));
  76.         </body>
  77.       </method>
  78.       <method name="scrollToIndex">
  79.         <parameter name="index"/>
  80.         <body>
  81.           return this.treeBoxObject.scrollToIndex(index);
  82.         </body>
  83.       </method>
  84.       <method name="getNumberOfVisibleRows">
  85.         <body>
  86.           return this.treeBoxObject.getNumberOfVisibleRows();
  87.         </body>
  88.       </method>
  89.       <method name="getIndexOfFirstVisibleRow">
  90.         <body>
  91.           return this.treeBoxObject.getIndexOfFirstVisibleRow();
  92.         </body>
  93.       </method>
  94.       <method name="getRowCount">
  95.         <body>
  96.           return this.treeBoxObject.getRowCount();
  97.         </body>
  98.       </method>
  99.     </implementation>
  100.     <handlers>
  101.       <handler event="keypress" keycode="vk_enter">
  102.         <![CDATA[
  103.          if (event.target != this || selectedItems.length != 1)
  104.            return;
  105.          this.selectedItems[0].toggleOpenState();
  106.         ]]>
  107.       </handler>
  108.       <handler event="keypress" keycode="vk_return">
  109.         <![CDATA[
  110.          if (event.target != this || selectedItems.length != 1)
  111.            return;
  112.          this.selectedItems[0].toggleOpenState();
  113.         ]]>
  114.       </handler>
  115.       <handler event="keypress" keycode="vk_left">
  116.         <![CDATA[
  117.          if (event.target != this || this.selectedItems.length != 1)
  118.            return;
  119.          if (this.selectedItems[0].getAttribute("open") != "true") {
  120.            var el = this.selectedItems[0].parentNode.parentNode 
  121.            if ( el && (el.tagName != "tree") ) this.selectItem(el);
  122.          }
  123.          else {
  124.            el = this.selectedItems[0];
  125.            el.close();
  126.          }
  127.         ]]>
  128.       </handler>
  129.       <handler event="keypress" keycode="vk_right">
  130.         <![CDATA[
  131.          if (event.target != this || this.selectedItems.length != 1)
  132.            return;
  133.          this.selectedItems[0].open();
  134.         ]]>
  135.       </handler>
  136.       <handler event="keypress" keycode="vk_up">
  137.         <![CDATA[
  138.          if (event.target != this || this.selectedItems.length < 1)
  139.            return;
  140.          this.isUpSelection=0;
  141.          this.isDownSelection=0;
  142.          var n = this.getPreviousItem(this.selectedItems[this.selectedItems.length-1], 1);
  143.          if (n) {
  144.            this.ensureIndexIsVisible(this.getIndexOfItem(n));
  145.            this.timedSelect(n, 500);
  146.          }
  147.         ]]>
  148.       </handler>
  149.       <handler event="keypress" keycode="vk_down">
  150.         <![CDATA[
  151.          if (event.target != this)
  152.            return;
  153.  
  154.          var n;
  155.          if (this.selectedItems.length == 0) {
  156.            n = this.getItemAtIndex(0);
  157.          }
  158.          else {
  159.            this.isUpSelection=0;
  160.            this.isDownSelection=0;
  161.            n = this.getNextItem(this.selectedItems[this.selectedItems.length-1], 1);
  162.          }
  163.  
  164.          if (n) {
  165.            this.ensureIndexIsVisible(this.getIndexOfItem(n));
  166.            this.timedSelect(n, 500);
  167.          }
  168.         ]]>
  169.       </handler>
  170.       <handler event="keypress" modifiers="shift" keycode="vk_up">
  171.         <![CDATA[
  172.          var l=this.selectedItems.length;
  173.          if (event.target != this || l < 1 || this.getAttribute("multiple") != "true")
  174.            return;
  175.          var n = this.getPreviousItem(this.selectedItems[l-1], 1);
  176.          if (n) {
  177.            this.ensureElementIsVisible(n);
  178.            if ( this.isDownSelection) {
  179.              if ( l > 1 )
  180.                this.removeItemFromSelection(this.selectedItems[l-1]);
  181.              if ( l <= 2 )
  182.                this.isDownSelection=0;
  183.      }
  184.            else {
  185.              this.addItemToSelection(n);
  186.              this.isUpSelection=1;
  187.            }
  188.          }
  189.         ]]>
  190.       </handler>
  191.       <handler event="keypress" modifiers="shift" keycode="vk_down">
  192.         <![CDATA[
  193.          var l=this.selectedItems.length;
  194.          if (event.target != this || l < 1 || this.getAttribute("multiple") != "true")
  195.            return;
  196.          var n = this.getNextItem(this.selectedItems[l-1], 1);
  197.          if (n) {
  198.            this.ensureElementIsVisible(n);
  199.            if ( this.isUpSelection) {
  200.              if ( l > 1 )
  201.          this.removeItemFromSelection(this.selectedItems[l-1]);
  202.              if ( l <= 2 )
  203.                this.isUpSelection=0;
  204.            }
  205.            else {
  206.              this.addItemToSelection(n);
  207.              this.isDownSelection=1;
  208.            }
  209.          }
  210.         ]]>
  211.       </handler>
  212.       <handler event="keypress" keycode="vk_page_up">
  213.         <![CDATA[
  214.          var l = this.selectedItems.length;
  215.          if (event.target != this || l < 1)
  216.            return;
  217.          this.isUpSelection=0;
  218.          this.isDownSelection=0;
  219.          var i = this.getIndexOfFirstVisibleRow();
  220.          if ( i == 0 )
  221.            var n=this.getItemAtIndex(0);
  222.          else {
  223.            var v = this.getNumberOfVisibleRows();
  224.            n = this.getPreviousItem(this.selectedItems[l-1], v);
  225.            var newIndex = i - v;
  226.            if ( ! n || newIndex < 0 ) {
  227.              newIndex=0;
  228.              n=this.getItemAtIndex(this.getIndexOfItem(this.selectedItems[l-1]) - i);
  229.            }
  230.            this.scrollToIndex(newIndex);
  231.          }
  232.          this.timedSelect(n, 500);
  233.         ]]>
  234.       </handler>
  235.       <handler event="keypress" keycode="vk_page_down">
  236.         <![CDATA[
  237.          var l = this.selectedItems.length;
  238.          if (event.target != this || l < 1)
  239.            return;
  240.          this.isUpSelection=0;
  241.          this.isDownSelection=0;
  242.          var i = this.getIndexOfFirstVisibleRow();
  243.          var v = this.getNumberOfVisibleRows();
  244.          var count = this.getRowCount();
  245.          var n;
  246.          if ( i >= count - v )
  247.            n=this.getItemAtIndex(count - 1);
  248.          else {
  249.            n = this.getNextItem(this.selectedItems[l-1], v);
  250.            var newIndex = i + v;
  251.            if ( ! n || newIndex > count - v ) {
  252.              newIndex = count - v;
  253.              n = this.getItemAtIndex(newIndex + this.getIndexOfItem(this.selectedItems[l-1]) - i);
  254.            }
  255.            this.scrollToIndex(newIndex);
  256.          }
  257.          this.timedSelect(n, 500);
  258.         ]]>
  259.       </handler>
  260.       <handler event="keypress" keycode="vk_home">
  261.         <![CDATA[
  262.          if (event.target != this || this.selectedItems.length < 1)
  263.            return;
  264.          this.isUpSelection=0;
  265.          this.isDownSelection=0;
  266.          this.scrollToIndex(0);
  267.          this.selectItem(this.getItemAtIndex(0));
  268.         ]]>
  269.       </handler>
  270.       <handler event="keypress" keycode="vk_end">
  271.         <![CDATA[
  272.          if (event.target != this || this.selectedItems.length < 1)
  273.            return;
  274.          this.isUpSelection=0;
  275.          this.isDownSelection=0;
  276.          var count = this.getRowCount();
  277.          this.ensureIndexIsVisible(count-1);
  278.          this.selectItem(this.getItemAtIndex(count-1));
  279.         ]]>
  280.       </handler>
  281.     </handlers>    
  282.   </binding>
  283.  
  284.   <binding id="treerows"
  285.            extends="chrome://global/content/bindings/tree.xml#tree-base">
  286.     <content outer="true"/>
  287.     <handlers>
  288.       <!-- If there is no modifier key, we select on mousedown, not
  289.            click, so that drags work correctly. -->
  290.       <handler event="mousedown">
  291.       <![CDATA[
  292.          var lt = event.originalTarget.localName;
  293.          var target = (lt == 'treecell' || lt == 'treerow') ? lt : null;
  294.          if (target && !event.ctrlKey && !event.shiftKey && !event.metaKey) {
  295.            var parent = lt == 'treecell' ? event.target.parentNode.parentNode : event.target.parentNode;
  296.            var isSelected = parent.getAttribute("selected");
  297.            if (!isSelected) {
  298.              parentNode.selectItem(parent);
  299.            }
  300.            parentNode.currentItem = parent;
  301.          }
  302.       ]]>
  303.       </handler>
  304.  
  305.       <!-- On a click (up+down on the same item), deselect everything
  306.            except this item. -->
  307.       <handler event="click">
  308.       <![CDATA[
  309.          if (event.button != 0) return;
  310.          var t = event.originalTarget;
  311.          if (t.localName == 'treecell') {
  312.            if (event.ctrlKey || event.metaKey) {
  313.              parentNode.toggleItemSelection(t.parentNode.parentNode);
  314.              parentNode.currentItem = t.parentNode.parentNode;
  315.            }
  316.            else if (event.shiftKey) {
  317.              parentNode.selectItemRange(null, t.parentNode.parentNode);
  318.              parentNode.currentItem = t.parentNode.parentNode;
  319.            }
  320.            else {
  321.              /* We want to deselect all the selected items except what was
  322.                 clicked, UNLESS it was a right-click.  We have to do this
  323.                 in click rather than mousedown so that you can drag a
  324.                 selected group of items */
  325.  
  326.              var selectedItems = parentNode.selectedItems;
  327.              var didSuppressSelect = false;
  328.              var i = 0;
  329.              while (i < selectedItems.length) {
  330.                if (selectedItems[i] != t.parentNode.parentNode) {
  331.                  if (!didSuppressSelect) {
  332.                    parentNode.suppressOnSelect = true;
  333.                    didSuppressSelect = true;
  334.                  }
  335.                  parentNode.removeItemFromSelection(selectedItems[i]);
  336.                }
  337.                else
  338.                  i++;
  339.              }
  340.              if (didSuppressSelect)
  341.                parentNode.suppressOnSelect = false;
  342.            }
  343.          }
  344.       ]]>
  345.       </handler>
  346.  
  347.       <!-- double-click -->
  348.       <handler event="click" clickcount="2">
  349.       <![CDATA[
  350.          if (event.originalTarget.localName == 'treecell') {
  351.            var n = event.originalTarget.parentNode.parentNode;
  352.            n.toggleOpenState();
  353.          }
  354.       ]]>
  355.       </handler>
  356.  
  357.       <!-- normal, single click -->
  358.       <handler event="click">
  359.       <![CDATA[
  360.          try {
  361.            if (event.originalTarget.getAttribute('twisty') == 'true') {
  362.              var n = event.originalTarget.parentNode.parentNode.parentNode;
  363.              n.toggleOpenState();
  364.             }
  365.          } catch (e) {}
  366.       ]]>
  367.       </handler>
  368.       
  369.     </handlers>
  370.   </binding>
  371.  
  372.   <binding id="treeitem"
  373.            extends="chrome://global/content/bindings/tree.xml#tree-base">
  374.     <implementation>
  375.       <method name="toggleOpenState">
  376.         <body>
  377.           <![CDATA[
  378.             if ((this.getAttribute('container') == 'true') &&
  379.                  (this.getAttribute('empty') != 'true')) {
  380.                if (this.getAttribute('open') == 'true')
  381.                  this.removeAttribute('open');
  382.                else this.setAttribute('open', 'true');
  383.             }
  384.           ]]>
  385.         </body>
  386.       </method>
  387.      <method name="open">
  388.        <body>
  389.           <![CDATA[
  390.             if ((this.getAttribute('container') == 'true') &&
  391.                  (this.getAttribute('empty') != 'true')) {
  392.                if (this.getAttribute('open') != 'true')
  393.                  this.setAttribute('open', 'true');
  394.             }
  395.           ]]>
  396.         </body>
  397.      </method>
  398.      <method name="close">
  399.        <body>
  400.           <![CDATA[
  401.             if ((this.getAttribute('container') == 'true') &&
  402.                  (this.getAttribute('empty') != 'true')) {
  403.                if (this.getAttribute('open') == 'true')
  404.                  this.removeAttribute('open');
  405.             }
  406.           ]]>
  407.         </body>
  408.      </method>    
  409.    </implementation>
  410.   </binding>     
  411.  
  412.   <binding id="treecell"
  413.            extends="chrome://global/content/bindings/tree.xml#tree-base">
  414.     <content>
  415.        <xul:text class="tree-cell-text" inherits="crop,value=label,align" flex="1" crop="right"/>
  416.     </content>
  417.   </binding>
  418.  
  419.   <binding id="treecell-align-right"
  420.            extends="chrome://global/content/bindings/tree.xml#tree-base">
  421.     <content>
  422.       <xul:spring flex="5"/>
  423.       <xul:text class="tree-cell-text" inherits="crop,value=label,align" flex="1" crop="right"/>
  424.     </content>
  425.   </binding>
  426.  
  427.   <binding id="treecell-iconic"
  428.            extends="chrome://global/content/bindings/tree.xml#tree-base">
  429.     <content>
  430.       <xul:image class="tree-cell-icon" inherits="src"/>
  431.       <xul:text class="tree-cell-text" inherits="crop,value=label,align" flex="1" crop="right"/>
  432.     </content>
  433.   </binding>
  434.  
  435.   <binding id="treecell-image"
  436.            extends="chrome://global/content/bindings/tree.xml#tree-base">
  437.     <content>
  438.       <xul:image class="tree-cell-image" inherits="src"/>
  439.     </content>
  440.   </binding>
  441.  
  442.   <binding id="treecell-indented-folder"
  443.            extends="chrome://global/content/bindings/tree.xml#tree-base">
  444.     <content>
  445.       <xul:treeindentation/>
  446.       <xul:image class="tree-cell-twisty" twisty="true" inherits="hidden=notwisty" allowevents="true"/>
  447.       <xul:image class="tree-cell-primary-icon" inherits="src"/>
  448.       <xul:text class="tree-cell-text" inherits="crop,value=label,align" flex="1" crop="right"/>
  449.     </content>
  450.   </binding>
  451.  
  452.   <binding id="treecell-indented-folder-inline-edit" 
  453.            extends="chrome://global/content/bindings/general.xml#inline-edit-base">
  454.     <resources>
  455.       <stylesheet src="chrome://global/content/bindings/tree.css"/>
  456.       <stylesheet src="chrome://global/skin/tree.css"/>
  457.     </resources>
  458.  
  459.     <content>
  460.       <xul:treeindentation/>
  461.       <xul:image class="tree-cell-twisty" twisty="true" inherits="hidden=notwisty" allowevents="true"/>
  462.       <xul:image class="tree-cell-primary-icon-inline-edit-folder" inherits="src"/>
  463.       <xul:hbox class="inline-edit-cell-box" flex="1" ileattr="text-container">
  464.         <xul:text class="inline-edit-cell-text" ileattr="text" rootcontent="treecell"
  465.                   inherits="crop,value=label,align,mode" flex="1" crop="right"/>
  466.       </xul:hbox>
  467.     </content>
  468.   </binding>
  469.   
  470.   <binding id="treecell-indented-leaf-inline-edit"
  471.            extends="chrome://global/content/bindings/general.xml#inline-edit-base">
  472.     <resources>
  473.       <stylesheet src="chrome://global/content/bindings/tree.css"/>
  474.       <stylesheet src="chrome://global/skin/tree.css"/>
  475.     </resources>
  476.  
  477.     <content>
  478.       <xul:treeindentation/>
  479.       <xul:image class="tree-cell-primary-icon" inherits="src"/>
  480.       <xul:hbox class="inline-edit-cell-box" flex="1" ileattr="text-container">
  481.         <xul:text class="tree-cell-text" ileattr="text" rootcontent="treecell"
  482.                   inherits="crop,value=label,align,mode" flex="1" crop="right"/>
  483.       </xul:hbox>
  484.     </content>
  485.   </binding>
  486.   
  487.   <binding id="treecell-inline-edit"
  488.            extends="chrome://global/content/bindings/general.xml#inline-edit-base">
  489.     <resources>
  490.       <stylesheet src="chrome://global/content/bindings/tree.css"/>
  491.       <stylesheet src="chrome://global/skin/tree.css"/>
  492.     </resources>
  493.  
  494.     <content>
  495.       <xul:hbox class="inline-edit-cell-box" flex="1" ileattr="text-container">
  496.         <xul:text class="tree-cell-text" ileattr="text" rootcontent="treecell" 
  497.                   inherits="crop,value=label,align,mode" flex="1" crop="right"/>
  498.       </xul:hbox>
  499.     </content>
  500.   </binding>
  501.  
  502.   <binding id="treecell-indented-leaf"
  503.            extends="chrome://global/content/bindings/tree.xml#tree-base">
  504.     <content>
  505.       <xul:treeindentation/>
  506.       <xul:image class="tree-cell-primary-icon" inherits="src"/>
  507.       <xul:text class="tree-cell-text" inherits="crop,value=label,align" flex="1" crop="right"/>
  508.     </content>
  509.   </binding>
  510.  
  511.   <binding id="treecell-text" extends="xul:text">
  512.     <content crop="right"/>
  513.   </binding>
  514.  
  515.   <binding id="treecell-header"
  516.            extends="chrome://global/content/bindings/tree.xml#tree-base">
  517.     <content>
  518.       <xul:hbox class="treecell-header-box" flex="1" align="center">
  519.         <xul:image class="tree-header-image" inherits="src"/>
  520.         <xul:text class="tree-header-text" inherits="crop,value=label,disabled" flex="1" crop="right"/>
  521.         <xul:image class="tree-header-sortdirection"/>
  522.       </xul:hbox>
  523.     </content>
  524.   </binding>
  525.  
  526.   <binding id="treecell-header-image"
  527.            extends="chrome://global/content/bindings/tree.xml#tree-base">
  528.     <content>
  529.       <xul:hbox class="treecell-header-image-box" flex="1" align="center">
  530.         <xul:image class="tree-header-image" inherits="src"/>
  531.       </xul:hbox>
  532.     </content>
  533.   </binding>
  534.   
  535.   <binding id="listbox" extends="xul:tree">
  536.     <content>
  537.       <xul:cols>
  538.         <xul:col flex="1"/>
  539.       </xul:cols>
  540.       <xul:treerows>
  541.         <xul:treerows>
  542.           <children includes="listhead"/>
  543.           <xul:treechildren>
  544.             <children/>
  545.           </xul:treechildren>
  546.         </xul:treerows>
  547.       </xul:treerows> 
  548.     </content>    
  549.   </binding>
  550.  
  551.   <binding id="listhead" extends="xul:treehead">
  552.     <content>
  553.       <xul:treerow>
  554.         <xul:treecell inherits="label" class="listcell-header"/>
  555.       </xul:treerow>
  556.     </content>
  557.   </binding>
  558.  
  559.   <binding id="listitem" extends="xul:treeitem">
  560.     <content>
  561.       <xul:treerow>
  562.         <xul:treecell inherits="label" class="listcell-text"/>
  563.       </xul:treerow>
  564.     </content>
  565.   </binding>
  566.  
  567. </bindings>
  568.  
  569.