home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / toolkit.jar / content / global / treeBindings.xml < prev    next >
Extensible Markup Language  |  2001-02-14  |  16KB  |  477 lines

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