<?xml version="1.0"?>

<bindings id="xulBindings"
   xmlns="http://www.mozilla.org/xbl"
   xmlns:html="http://www.w3.org/TR/REC-html40"
   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  
  <binding name="thumb" extends="xul:box">
    <content>
      <xul:spring flex="1"/>
		  <xul:image inherits="src"/>
		  <xul:spring flex="1"/>
    </content>
  </binding>

  <binding name="scrollbar">
    <content>
      <xul:scrollbarbutton type="decrement">
	      <xul:image inherits="src"/>
	    </xul:scrollbarbutton>
      <xul:slider flex="1" inherits="curpos,maxpos,pageincrement,increment">
	      <xul:thumb inherits="align,src" flex="1"/>
      </xul:slider>
      <xul:scrollbarbutton type="increment">
	    <xul:image inherits="src"/>
	  </xul:scrollbarbutton>
    </content>
  </binding>

  <binding name="slider">
    <content>
	  <xul:button align="horizontal"/>
	</content>
  </binding>

  <binding name="tab">
    <content>
      <xul:image inherits="src" class="tab-left"/>
      <xul:text flex="1" inherits="value,crop,accesskey" crop="right" class="tab-text"/>
    </content>
  </binding>

  <binding name="menusOnMenuBar">
    <content excludes="template,observes,menupopup">
      <xul:image class="menubar-left"/>
      <xul:text class="menubar-text" inherits="value,accesskey,crop" crop="right"/>
    </content>
  </binding>

  <binding name="menus">
    <content autostretch="never" excludes="template,observes,menupopup">
      <xul:box class="menu-left" orient="vertical" autostretch="never">
        <xul:image/>
      </xul:box>
      <xul:text class="menu-text" flex="1" align="left" inherits="value,accesskey,crop" crop="right"/>
      <xul:text class="menu-accel" inherits="acceltext:value"/>
      <xul:box orient="vertical" autostretch="never" class="menu-right">
        <xul:image/>
      </xul:box>
    </content>
  </binding>

  <binding name="menulist">
    <content excludes="template,observes,menupopup">
      <xul:image class="menu-icon" inherits="src"/>
      <xul:text class="menu-text" flex="1" inherits="value,accesskey,crop" crop="right"/>
      <xul:image class="menu-dropmarker"/>
    </content>
	  <handlers>
      <handler type="command" capturer="true" value="this.selectedItem = event.target"/>
	  </handlers>
  </binding>

  <binding name="menubutton">
    <content excludes="template,observes,menupopup">
      <xul:button class="menu-button" allowevents="true" inherits="buttonaction:oncommand,src,value,crop,accesskey"/>
      <xul:image class="menu-dropmarker"/>
    </content>
  </binding>

  <binding name="menulist-editable">
    <content excludes="template,observes,menupopup">
      <xul:image class="menu-icon" inherits="src"/>
	    <html:input type="text" flex="1" class="menu-text" allowevents="true" inherits="value,disabled"/>
      <xul:image class="menu-dropmarker"/>
    </content>
	  <handlers>
      <handler type="command" capturer="true" value="this.selectedItem = event.target"/>
	  </handlers>
  </binding>

  <binding name="treecell-indented-folder">
    <content>
      <xul:treeindentation/>
      <xul:titledbutton class="twisty" allowevents="true"/>
      <xul:titledbutton class="tree-icon tree-button" inherits="crop,value,align,src" 
                    flex="1" align="left" crop="right"/>
    </content>
  </binding>

  <binding name="treecell-indented-leaf">
    <content>
      <xul:treeindentation/>
      <xul:titledbutton class="twisty" disabled="true" allowevents="true"/>
      <xul:titledbutton class="tree-icon tree-button" inherits="crop,value,align,src" 
                    flex="1" align="left" crop="right"/>
    </content>
  </binding>

  <binding name="treecell">
    <content>
      <xul:titledbutton class="tree-button" inherits="crop,value,align,src" 
                    flex="1" align="left" crop="right"/>
    </content>
  </binding>

  <binding name="treecell-header">
    <content>
      <xul:image class="tree-button" inherits="src"/>
      <xul:text class="tree-text" inherits="crop,value" flex="1" crop="right"/>
      <xul:image class="treeheader-sortdirection"/>
    </content>
  </binding>
  
  <binding name="basetext">
    <interface>
      <!-- public interface -->
      <property name="value"      onset="return this.setAttribute('value',val);"
                                  onget="return this.getAttribute('value');"/>
      <property name="crop"       onset="return this.setAttribute('crop',val);"
                                  onget="return this.getAttribute('crop');"/>
      <property name="disabled"   onset="return this.setAttribute('disabled',val);"
                                  onget="return this.getAttribute('disabled');"/>
      <property name="src"        onset="return this.setAttribute('src',val);"
                                  onget="return this.getAttribute('src');"/>
      <property name="accesskey"  onset="return this.setAttribute('accesskey',val);"
                                  onget="return this.getAttribute('accesskey');"/>
      <property name="imgalign"   onset="return this.setAttribute('imgalign',val);"
                                  onget="return this.getAttribute('imgalign');"/>
    </interface>      
  </binding>
  
  <binding name="checkbox" extends="resource:/chrome/xulBindings.xml#basetext">
    <content>
      <xul:box flex="1" class="internal-box" autostretch="never">
        <xul:box class="checkmark-box" autostretch="never">
          <xul:image inherits="src"/>
        </xul:box>
        <xul:html inherits="value" flex="1"/>
      </xul:box>
    </content>
    <interface>
      <!-- public interface -->
      <property name="checked"    onset="if (val) this.setAttribute('checked', 'true');
                                         else this.removeAttribute('checked');
                                         return val;"
                                  onget="var v = this.getAttribute('checked');
                                         if (v == 'true') return true; return false;"/>
    </interface>
    <handlers>
      <handler type="mouseup" value="this.checked = !this.checked;"/>
      <handler type="keypress" key=" " value="this.checked = !this.checked;"/>
    </handlers>
  </binding>

  <binding name="checkbox-iconic" extends="resource:/chrome/xulBindings.xml#checkbox">
    <content>
      <xul:box flex="1" class="internal-box" autostretch="never">
        <xul:box class="checkmark-box" autostretch="never">
          <xul:image/>
        </xul:box>
        <xul:image inherits="src" class="icon" />
        <xul:html inherits="value" flex="1"/>
      </xul:box>
    </content>
  </binding>
  
  <binding name="radio" extends="resource:/chrome/xulBindings.xml#checkbox">
    <content>
      <xul:box flex="1" class="internal-box" autostretch="never">
        <xul:box class="checkmark-box" autostretch="never">
          <xul:image inherits="src"/>
        </xul:box>
        <xul:html inherits="value" flex="1"/>
      </xul:box>
    </content>  
  </binding>
  
  <binding name="radio-iconic" extends="resource:/chrome/xulBindings.xml#radio">
    <content>
      <xul:box flex="1" class="internal-box" autostretch="never">
        <xul:box class="checkmark-box" autostretch="never">
          <xul:image/>
        </xul:box>
        <xul:image inherits="src" class="icon"/>
        <xul:html inherits="value" flex="1"/>
      </xul:box>
    </content>  
  </binding>  

  <binding name="radiogroup">
  	<handlers>
      <handler type="mouseup" value="try { this.selectedItem = event.target; } catch (e) {}"/>
	    <handler type="keypress" key=" " value="try { this.selectedItem = event.target; } catch (e) {}"/>
	  </handlers>
  </binding>

  <!-- XUL <button>s -->
  <binding name="buttonleft" extends="resource:/chrome/xulBindings.xml#basetext">
    <content excludes="observes,template">
  	  <xul:box class="internal-box" inherits="orient" autostretch="never" flex="1">
        <xul:image inherits="src"/>
        <xul:box orient="vertical" class="text-container" autostretch="never" flex="1">
          <xul:text inherits="value,accesskey,crop"/>
        </xul:box>
      </xul:box>
    </content>
  </binding>
  
  <binding name="buttonright" extends="resource:/chrome/xulBindings.xml#basetext">
    <content excludes="observes,template">
	    <xul:box autostretch="never" inherits="orient" class="internal-box" flex="1">
        <xul:box orient="vertical" class="text-container" autostretch="never" flex="1">
  	      <xul:text inherits="value,accesskey,crop"/>
        </xul:box>
        <xul:image inherits="src"/>
      </xul:box>
	  </content>
  </binding>
  
  <binding name="separator" extends="xul:spring"/>

  <!-- appending to the end so we don't make hyatt cry -->
  <binding name="progressmeter" extends="xul:box">
    <content excludes="observes,template">
      <xul:box class="internal-box" flex="1">
        <xul:stack flex="1">
          <xul:progressbar inherits="value">
            <xul:box class="progress-bar"/>
            <xul:box class="progress-remainder"/>
          </xul:progressbar>
          <xul:box>
            <xul:spring flex="1"/>
            <xul:text class="progress-text" inherits="progresstext:value"/>
            <xul:spring flex="1"/>
          </xul:box>
        </xul:stack>
      </xul:box>
    </content>
    <interface>
      <property name="progresstext"   onset="return this.setAttribute('progresstext',val);"
                                      onget="return this.getAttribute('progresstext');"/>
      <property name="value"          onset="return this.setAttribute('value',val);"
                                      onget="return this.getAttribute('value');"/>
    </interface>
  </binding>

  <binding name="textfield" extends="xul:box">
    <content excludes="observes,template">
      <xul:box flex="1">
        <html:input flex="1" inherits="value,type,maxlength,disabled,size,readonly"/>
      </xul:box>
    </content>
    <interface>
      <property name="value"      onset="return this.anonymousContent[0].firstChild.value = val;"
                                  onget="return this.anonymousContent[0].firstChild.value;"/>
      <property name="type"       onset="return this.anonymousContent[0].firstChild.type = val;"
                                  onget="return this.anonymousContent[0].firstChild.type;"/>
      <property name="maxlength"  onset="return this.anonymousContent[0].firstChild.maxlength = val;"
                                  onget="return this.anonymousContent[0].firstChild.maxlength;"/>
      <property name="disabled"   onset="return this.anonymousContent[0].firstChild.disabled = val;"
                                  onget="return this.anonymousContent[0].firstChild.disabled;"/>
      <property name="size"       onset="return this.anonymousContent[0].firstChild.size = val;"
                                  onget="return this.anonymousContent[0].firstChild.size;"/>
      <property name="readonly"   onset="return this.anonymousContent[0].firstChild.readonly = val;"
                                  onget="return this.anonymousContent[0].firstChild.readonly;"/>
    </interface>
    <handlers>
      <handler type="focus" value="this.setAttribute('focused','true');"/>
      <handler type="blur" value="this.removeAttribute('focused');"/>
    </handlers>    
  </binding>

  <binding name="textarea" extends="resource:/chrome/xulBindings.xml#textfield">
    <content excludes="observes,template">
      <xul:box flex="1">
        <html:textarea flex="1" inherits="value,disabled,rows,cols,readonly"/>
      </xul:box>
    </content>
  </binding>

  <binding name="text">
    <handlers>
      <handler type="click" value="var forElementID = this.getAttribute('for'); if(forElementID) var forElement = document.getElementById(forElementID); if(forElement) forElement.focus();"/>
    </handlers>
  </binding>
  
  <binding name="text-editable-display" extends="resource:/chrome/xulBindings.xml#text"/>
  
  <binding name="text-editable-edit" extends="xul:box">
    <content>
      <xul:box flex="1">
        <html:input type="text" inherits="value,type,maxlength,disabled,size,readonly"/>
      </xul:box>
    </content>
    <handlers>
      <handler type="blur" value="this.setAttribute('mode','display');"/>
    </handlers>
  </binding>

  <binding name="popups">
    <content>
      <xul:box class="internal-box" orient="vertical">
        <children/>
      </xul:box>
    </content>
  </binding>
  
  <binding name="toolbargrippy" extends="xul:image"/>

  <binding name="toolbox">
    <content orient="vertical">
      <xul:box orient="vertical" flex="1" class="internal-box">
        <children/>
      </xul:box>
      <xul:box class="collapsed-tray"/>
    </content>
    <interface>
      <method name="collapseToolbar">
        <argument name="toolbar"/>
        <body>
          var v = this.removeChild(toolbar);
          this.anonymousContent[1].appendChild(v);
        </body>
      </method>
      <method name="expandToolbar">
        <argument name="toolbar"/>
        <body>
          var v = this.anonymousContent[1].removeChild(toolbar);
          this.appendChild(v);
        </body>
      </method>
    </interface>
  </binding>

  <binding name="toolbar">
    <content>
      <xul:toolbargrippy onclick="var v = parentNode;
                                  var attr = v.getAttribute('collapsed');
                                  if (attr == 'true') {
                                    v.removeAttribute('collapsed');
                                    try {
                                      parentNode.parentNode.parentNode.expandToolbar(parentNode);
                                    }
                                    catch(e) {
                                      dump('huh?' + parentNode.parentNode.parentNode + '\n');
                                    }
                                  }
                                  else {
                                    v.setAttribute('collapsed', 'true');
                                    try {
                                      parentNode.parentNode.collapseToolbar(parentNode);
                                    }
                                    catch(e) {}
                                  }
                                  "/>
      <xul:box flex="1" class="toolbar-holder" inherits="collapsed">
        <children/>
      </xul:box>
    </content>
  </binding>

  <binding name="colorpicker" extends="xul:box">
    <interface>
      <property name="color" onset="return this.setAttribute('color', val);"
                             onget="return this.getAttribute('color');"/>
      <property name="selectedItem"/>
    </interface>

    <handlers>
      <handler type="click" value="dump('handler fired\n');"/>
    </handlers>

    <content>

      <xul:box flex="1" orient="vertical" onclick="parentNode.color = event.target.getAttribute('color');
                                                   try { parentNode.selectedItem.removeAttribute('selected'); } catch(e) { }
                                                   parentNode.selectedItem = event.target;
                                                   event.target.setAttribute('selected', 'true');">

      <xul:box align="horizontal">
        <xul:spring class="colorpickertile" style="background-color: #FFFFFF" color="#FFFFFF"/>
        <xul:spring class="colorpickertile" style="background-color: #FFCCCC" color="#FFCCCC"/>
        <xul:spring class="colorpickertile" style="background-color: #FFCC99" color="#FFCC99"/>
        <xul:spring class="colorpickertile" style="background-color: #FFFF99" color="#FFFF99"/>
        <xul:spring class="colorpickertile" style="background-color: #FFFFCC" color="#FFFFCC"/>
        <xul:spring class="colorpickertile" style="background-color: #99FF99" color="#99FF99"/>
        <xul:spring class="colorpickertile" style="background-color: #99FFFF" color="#99FFFF"/>
        <xul:spring class="colorpickertile" style="background-color: #CCFFFF" color="#CCFFFF"/>
        <xul:spring class="colorpickertile" style="background-color: #CCCCFF" color="#CCCCFF"/>
        <xul:spring class="colorpickertile" style="background-color: #FFCCFF" color="#FFCCFF"/>
      </xul:box>
      <xul:box align="horizontal">
        <xul:spring class="colorpickertile" style="background-color: #CCCCCC" color="#CCCCCC"/>
        <xul:spring class="colorpickertile" style="background-color: #FF6666" color="#FF6666"/>
        <xul:spring class="colorpickertile" style="background-color: #FFCC33" color="#FFCC33"/>
        <xul:spring class="colorpickertile" style="background-color: #FFFF66" color="#FFFF66"/>
        <xul:spring class="colorpickertile" style="background-color: #FFFF99" color="#FFFF99"/>
        <xul:spring class="colorpickertile" style="background-color: #66FF99" color="#66FF99"/>
        <xul:spring class="colorpickertile" style="background-color: #33FFFF" color="#33FFFF"/>
        <xul:spring class="colorpickertile" style="background-color: #66FFFF" color="#66FFFF"/>
        <xul:spring class="colorpickertile" style="background-color: #9999FF" color="#9999FF"/>
        <xul:spring class="colorpickertile" style="background-color: #FF99FF" color="#FF99FF"/>
      </xul:box>
      <xul:box align="horizontal">
        <xul:spring class="colorpickertile" style="background-color: #C0C0C0" color="#C0C0C0"/>
        <xul:spring class="colorpickertile" style="background-color: #FF0000" color="#FF0000"/>
        <xul:spring class="colorpickertile" style="background-color: #FF9900" color="#FF9900"/>
        <xul:spring class="colorpickertile" style="background-color: #FFCC66" color="#FFCC66"/>
        <xul:spring class="colorpickertile" style="background-color: #FFFF00" color="#FFFF00"/>
        <xul:spring class="colorpickertile" style="background-color: #33FF33" color="#33FF33"/>
        <xul:spring class="colorpickertile" style="background-color: #66CCCC" color="#66CCCC"/>
        <xul:spring class="colorpickertile" style="background-color: #33CCFF" color="#33CCFF"/>
        <xul:spring class="colorpickertile" style="background-color: #6666CC" color="#6666CC"/>
        <xul:spring class="colorpickertile" style="background-color: #CC66CC" color="#CC66CC"/>
      </xul:box>
      <xul:box align="horizontal">
        <xul:spring class="colorpickertile" style="background-color: #999999" color="#999999"/>
        <xul:spring class="colorpickertile" style="background-color: #CC0000" color="#CC0000"/>
        <xul:spring class="colorpickertile" style="background-color: #FF6600" color="#FF6600"/>
        <xul:spring class="colorpickertile" style="background-color: #FFCC33" color="#FFCC33"/>
        <xul:spring class="colorpickertile" style="background-color: #FFCC00" color="#FFCC00"/>
        <xul:spring class="colorpickertile" style="background-color: #33CC00" color="#33CC00"/>
        <xul:spring class="colorpickertile" style="background-color: #00CCCC" color="#00CCCC"/>
        <xul:spring class="colorpickertile" style="background-color: #3366FF" color="#3366FF"/>
        <xul:spring class="colorpickertile" style="background-color: #6633FF" color="#6633FF"/>
        <xul:spring class="colorpickertile" style="background-color: #CC33CC" color="#CC33CC"/>
      </xul:box>
      <xul:box align="horizontal">
        <xul:spring class="colorpickertile" style="background-color: #666666" color="#666666"/>
        <xul:spring class="colorpickertile" style="background-color: #990000" color="#990000"/>
        <xul:spring class="colorpickertile" style="background-color: #CC6600" color="#CC6600"/>
        <xul:spring class="colorpickertile" style="background-color: #CC9933" color="#CC9933"/>
        <xul:spring class="colorpickertile" style="background-color: #999900" color="#999900"/>
        <xul:spring class="colorpickertile" style="background-color: #009900" color="#009900"/>
        <xul:spring class="colorpickertile" style="background-color: #339999" color="#339999"/>
        <xul:spring class="colorpickertile" style="background-color: #3333FF" color="#3333FF"/>
        <xul:spring class="colorpickertile" style="background-color: #6600CC" color="#6600CC"/>
        <xul:spring class="colorpickertile" style="background-color: #993399" color="#993399"/>
      </xul:box>
      <xul:box align="horizontal">
        <xul:spring class="colorpickertile" style="background-color: #333333" color="#333333"/>
        <xul:spring class="colorpickertile" style="background-color: #660000" color="#660000"/>
        <xul:spring class="colorpickertile" style="background-color: #993300" color="#993300"/>
        <xul:spring class="colorpickertile" style="background-color: #996633" color="#996633"/>
        <xul:spring class="colorpickertile" style="background-color: #666600" color="#666600"/>
        <xul:spring class="colorpickertile" style="background-color: #006600" color="#006600"/>
        <xul:spring class="colorpickertile" style="background-color: #336666" color="#336666"/>
        <xul:spring class="colorpickertile" style="background-color: #000099" color="#000099"/>
        <xul:spring class="colorpickertile" style="background-color: #333399" color="#333399"/>
        <xul:spring class="colorpickertile" style="background-color: #663366" color="#663366"/>
      </xul:box>
      <xul:box align="horizontal">
        <xul:spring class="colorpickertile" style="background-color: #000000" color="#000000"/>
        <xul:spring class="colorpickertile" style="background-color: #330000" color="#330000"/>
        <xul:spring class="colorpickertile" style="background-color: #663300" color="#663300"/>
        <xul:spring class="colorpickertile" style="background-color: #663333" color="#663333"/>
        <xul:spring class="colorpickertile" style="background-color: #333300" color="#333300"/>
        <xul:spring class="colorpickertile" style="background-color: #003300" color="#003300"/>
        <xul:spring class="colorpickertile" style="background-color: #003333" color="#003333"/>
        <xul:spring class="colorpickertile" style="background-color: #000066" color="#000066"/>
        <xul:spring class="colorpickertile" style="background-color: #330099" color="#330099"/>
        <xul:spring class="colorpickertile" style="background-color: #330033" color="#330033"/>
      </xul:box>
      </xul:box>
    </content>
  </binding>
</bindings>

