home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 May / PCWorld_2003-05_cd.bin / Komunik / phoenix / chrome / toolkit.jar / content / global / widgets / toolbar.xml < prev    next >
Extensible Markup Language  |  2002-11-10  |  11KB  |  303 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="toolbarBindings"
  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="toolbar-base">
  9.     <resources>
  10.       <stylesheet src="chrome://global/skin/toolbar.css"/>
  11.     </resources>
  12.     <implementation implements="nsIAccessibleProvider">
  13.       <property name="accessible">
  14.         <getter>
  15.           <![CDATA[
  16.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  17.             if (this.localName == "toolbarseparator")
  18.               return accService.createXULToolbarSeparatorAccessible(this);
  19.             else
  20.               return accService.createXULToolbarAccessible(this);
  21.           ]]>
  22.         </getter>
  23.       </property>
  24.     </implementation>
  25.   </binding>
  26.   
  27.   <binding id="toolbox" extends="chrome://global/content/widgets/toolbar.xml#toolbar-base">  
  28.     <implementation>
  29.       <field name="palette">
  30.         null
  31.       </field>
  32.  
  33.       <field name="toolbarset">
  34.         null
  35.       </field>
  36.       
  37.       <field name="customToolbarCount">
  38.         0
  39.       </field>
  40.       
  41.       <constructor>
  42.         <![CDATA[
  43.           // Look to see if there is a toolbarset.
  44.           this.toolbarset = this.firstChild;
  45.           while (this.toolbarset && this.toolbarset.localName != "toolbarset")
  46.             this.toolbarset = toolbarset.nextSibling;
  47.           
  48.           if (this.toolbarset) {
  49.             // Create each toolbar described by the toolbarset.
  50.             var index = 0;
  51.             while (toolbarset.hasAttribute("toolbar"+(++index))) {
  52.               var toolbarInfo = toolbarset.getAttribute("toolbar"+index);
  53.               var infoSplit = toolbarInfo.split(":");
  54.               this.appendCustomToolbar(infoSplit[0], infoSplit[1]);
  55.             }
  56.           }
  57.         ]]>
  58.       </constructor>
  59.       
  60.       <method name="appendCustomToolbar">
  61.         <parameter name="aName"/>
  62.         <parameter name="aCurrentSet"/>
  63.         <body>
  64.           <![CDATA[            
  65.             var toolbar = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
  66.                                                   "toolbar");
  67.             toolbar.id = "__customToolbar_" + aName.replace(" ", "");
  68.             toolbar.setAttribute("customizable", "true");
  69.             toolbar.setAttribute("customindex", ++this.customToolbarCount);
  70.             toolbar.setAttribute("toolbarname", aName);
  71.             toolbar.setAttribute("currentset", aCurrentSet);
  72.             toolbar.setAttribute("mode", this.getAttribute("mode"));
  73.             toolbar.setAttribute("iconsize", this.getAttribute("iconsize"));
  74.             toolbar.setAttribute("context", this.toolbarset.getAttribute("context"));
  75.                         
  76.             this.insertBefore(toolbar, this.toolbarset);
  77.             return toolbar;
  78.           ]]>
  79.         </body>
  80.       </method>
  81.     </implementation>
  82.   </binding>
  83.   
  84.   <binding id="toolbar" extends="chrome://global/content/widgets/toolbar.xml#toolbar-base">
  85.     <implementation>
  86.       <field name="firstPermanentChild">
  87.         null
  88.       </field>
  89.       <field name="lastPermanentChild">
  90.         null
  91.       </field>
  92.       
  93.       <property name="toolbarName"
  94.                 onget="return this.getAttribute('toolbarname');"
  95.                 onset="this.setAttribute('toolbarname', val); return val;"/>
  96.       
  97.       <constructor>
  98.         <![CDATA[
  99.           this.firstPermanentChild = this.firstChild;
  100.           this.lastPermanentChild = this.lastChild;
  101.           
  102.           // Searching for the toolbox palette in the toolbar binding because
  103.           // toolbars are constructed first.
  104.           var toolbox = this.parentNode;
  105.           
  106.           if (!toolbox.palette) {
  107.             // Look to see if there is a toolbarpalette.
  108.             var node = toolbox.firstChild;
  109.             while (node) {
  110.               if (node.localName == "toolbarpalette")
  111.                 break;
  112.               node = node.nextSibling;
  113.             }
  114.             
  115.             if (!node)
  116.               return;
  117.  
  118.             // Hold on to the palette but remove it from the document.
  119.             toolbox.palette = node;       
  120.             toolbox.removeChild(node);
  121.           }
  122.           
  123.           // Build up our contents from the palette.
  124.           var currentSet = this.getAttribute("currentset");
  125.           if (!currentSet)
  126.             currentSet = this.getAttribute("defaultset");
  127.           if (currentSet)
  128.             this.currentSet = currentSet;
  129.         ]]>
  130.       </constructor>
  131.  
  132.       <property name="currentSet">
  133.         <getter>
  134.           <![CDATA[
  135.             var node = this.firstChild;
  136.             var currentSet = "";
  137.             while (node) {
  138.               if (node.id &&
  139.                   node.localName == "toolbaritem" || 
  140.                   node.localName == "toolbarbutton" ||
  141.                   node.localName == "toolbarseparator" ||
  142.                   node.localName == "toolbarspring" ||
  143.                   node.localName == "toolbarspacer")
  144.               {
  145.                 if (currentSet)
  146.                   currentSet += ",";
  147.  
  148.                 if (node.localName == "toolbarseparator")
  149.                   currentSet += "separator";
  150.                 else if (node.localName == "toolbarspring")
  151.                   currentSet += "spring";
  152.                 else if (node.localName == "toolbarspacer")
  153.                   currentSet += "spacer";
  154.                 else
  155.                   currentSet += node.id;
  156.               }
  157.               node = node.nextSibling;
  158.             }
  159.             
  160.             return currentSet ? currentSet : "__empty";
  161.           ]]>
  162.         </getter>
  163.         
  164.         <setter>
  165.           <![CDATA[
  166.             // Remove all items before the first permanent child and after the last permanent child.
  167.             while (this.lastChild) {
  168.               if (this.lastChild == this.lastPermanentChild ||
  169.                   (this.lastChild.localName == "toolbarpaletteitem" &&
  170.                   this.lastChild.firstChild == this.lastPermanentChild))
  171.                 break;
  172.               this.removeChild(this.lastChild);
  173.             }
  174.  
  175.             while (this.firstChild) {
  176.               if (this.firstChild == this.firstPermanentChild ||
  177.                   (this.firstChild.localName == "toolbarpaletteitem" &&
  178.                   this.firstChild.firstChild == this.firstPermanentChild))
  179.                 break;
  180.               this.removeChild(this.firstChild);
  181.             }
  182.  
  183.             var firstChildID = this.firstPermanentChild ? this.firstPermanentChild.id : "";
  184.             var lastChildID = this.lastPermanentChild ? this.lastPermanentChild.id : "";
  185.  
  186.             if (val == "__empty")
  187.               return;
  188.  
  189.             if (val) {
  190.               var itemIds = val.split(",");
  191.               var before = true;
  192.               for (var i = 0; i < itemIds.length; i++) {
  193.                 if (itemIds[i] == firstChildID || itemIds[i] == lastChildID)
  194.                   before = false;
  195.                 else
  196.                   this.insertItem(itemIds[i], null, null, before);
  197.               }
  198.             }
  199.           ]]>
  200.         </setter>
  201.       </property>
  202.       
  203.       <method name="insertItem">
  204.         <parameter name="aId"/>
  205.         <parameter name="aBeforeElt"/>
  206.         <parameter name="aWrapper"/>
  207.         <parameter name="aBeforePermanent"/>
  208.         <body>
  209.           <![CDATA[
  210.             var newItem = null;
  211.             
  212.             // Create special cases of palette items.
  213.             if (aId == "separator") {
  214.               newItem = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
  215.                                                  "toolbarseparator");
  216.               var uniqueId = (new Date()).getTime()+this.childNodes.length;
  217.               newItem.id = "separator" + uniqueId;
  218.             } else if (aId == "spring") {
  219.               newItem = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
  220.                                                  "toolbarspring");
  221.               var uniqueId = (new Date()).getTime()+this.childNodes.length;
  222.               newItem.flex = 1;
  223.               newItem.id = "spring" + uniqueId;
  224.             } else if (aId == "spacer") {
  225.               newItem = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
  226.                                                  "toolbarspacer");
  227.               var uniqueId = (new Date()).getTime()+this.childNodes.length;
  228.               newItem.id = "spacer" + uniqueId;
  229.             } else {
  230.               // Attempt to locate an item with a matching id within palette.
  231.               var paletteItem = this.parentNode.palette.firstChild;
  232.               while (paletteItem) {
  233.                 var paletteId = paletteItem.id;
  234.                 if (paletteId == aId) {
  235.                   newItem = paletteItem.cloneNode(true);
  236.                   break;
  237.                 }
  238.                 paletteItem = paletteItem.nextSibling;
  239.               }
  240.             }
  241.             
  242.             if (!newItem)
  243.               return;
  244.  
  245.             var insertItem = newItem;
  246.             
  247.             // Wrap the item in another node if so inclined.
  248.             if (aWrapper) {
  249.               aWrapper.appendChild(newItem);
  250.               insertItem = aWrapper;
  251.             }
  252.             
  253.             // Insert the palette item into the toolbar.
  254.             if (aBeforeElt)
  255.               this.insertBefore(insertItem, aBeforeElt);
  256.             else if (aBeforePermanent && this.firstPermanentChild)
  257.                 this.insertBefore(insertItem, this.firstPermanentChild);
  258.             else
  259.                 this.appendChild(insertItem);
  260.                
  261.             return newItem;
  262.           ]]>
  263.         </body>
  264.       </method>      
  265.     </implementation>
  266.   </binding>
  267.  
  268.   <binding id="menubar" extends="chrome://global/content/widgets/toolbar.xml#toolbar-base" display="xul:menubar">
  269.     <implementation implements="nsIAccessibleProvider">
  270.       <property name="accessible">
  271.         <getter>
  272.           <![CDATA[
  273.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  274.             return accService.createXULMenubarAccessible(this);
  275.           ]]>
  276.         </getter>
  277.        </property>
  278.  
  279.     </implementation>
  280.   </binding>
  281.  
  282.   <binding id="toolbardecoration" extends="chrome://global/content/widgets/toolbar.xml#toolbar-base"/>
  283.  
  284.   <binding id="toolbarpaletteitem" extends="chrome://global/content/widgets/toolbar.xml#toolbar-base" display="xul:button">
  285.     <content>
  286.       <xul:hbox class="toolbarpaletteitem-box" flex="1" xbl:inherits="type,place">
  287.         <children/>
  288.       </xul:hbox>
  289.     </content>
  290.   </binding>
  291.     
  292.   <binding id="toolbarpaletteitem-palette" extends="chrome://global/content/widgets/toolbar.xml#toolbarpaletteitem">
  293.     <content>
  294.       <xul:hbox class="toolbarpaletteitem-box" xbl:inherits="type,place">
  295.         <children/>
  296.       </xul:hbox>
  297.       <xul:label xbl:inherits="value=title"/>
  298.     </content>
  299.   </binding>
  300.  
  301. </bindings>          
  302.  
  303.