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

  1. <?xml version="1.0"?>
  2.  
  3. <!DOCTYPE window [
  4.   <!ENTITY % textcontextDTD SYSTEM "chrome://global/locale/textcontext.dtd" >
  5.   %textcontextDTD;
  6. ]>
  7.  
  8. <bindings id="textboxBindings"
  9.    xmlns="http://www.mozilla.org/xbl"
  10.    xmlns:html="http://www.w3.org/1999/xhtml"
  11.    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  12.    xmlns:xbl="http://www.mozilla.org/xbl">
  13.  
  14.   <binding id="textbox" extends="xul:box">
  15.     <resources>
  16.       <stylesheet src="chrome://global/skin/textbox.css"/>
  17.     </resources>
  18.     
  19.     <content>
  20.       <xul:hbox class="textbox-input-box" flex="1">
  21.         <children/>
  22.         <html:input class="textbox-input" flex="1" anonid="input"
  23.                     xbl:inherits="onfocus,onblur,value,type,maxlength,disabled,size,readonly,tabindex,accesskey"/>
  24.       </xul:hbox>
  25.     </content>
  26.     
  27.     <implementation>
  28.       <field name="mInputField">null</field>
  29.       
  30.       <property name="inputField" readonly="true">
  31.         <getter><![CDATA[
  32.           if (!this.mInputField)    
  33.             this.mInputField = document.getAnonymousElementByAttribute(this, "anonid", "input");
  34.           return this.mInputField;
  35.         ]]></getter>
  36.       </property>
  37.       
  38.       <property name="value"      onset="this.inputField.value = val; return val;"
  39.                                   onget="return this.inputField.value;"/>
  40.       <property name="type"       onset="this.inputField.type = val; return val;"
  41.                                   onget="return this.inputField.type;"/>
  42.       <property name="maxlength"  onset="this.inputField.maxlength = val; return val;"
  43.                                   onget="return this.inputField.maxlength;"/>
  44.       <property name="disabled"   onset="this.inputField.disabled = val;
  45.                                          if (val) this.setAttribute('disabled', 'true');
  46.                                          else this.removeAttribute('disabled'); return val;"
  47.                                   onget="return this.inputField.disabled;"/>
  48.       <property name="size"       onset="this.inputField.size = val; return val;"
  49.                                   onget="return this.inputField.size;"/>
  50.       <property name="readonly"   onset="this.inputField.readonly = val;
  51.                                          if (val) this.setAttribute('readonly', 'true');
  52.                                          else this.removeAttribute('readonly'); return val;"
  53.                                   onget="return this.inputField.readonly;"/>
  54.       
  55.       <method name="select">
  56.         <body>
  57.           this.inputField.select();
  58.         </body>
  59.       </method>
  60.  
  61.       <property name="controllers"    readonly="true" onget="return this.inputField.controllers"/>
  62.       <property name="textLength"     readonly="true" onget="return this.inputField.textLength;"/>
  63.       <property name="selectionStart" onset="this.inputField.selectionStart = val; return val;"
  64.                                       onget="return this.inputField.selectionStart;"/>
  65.       <property name="selectionEnd"   onset="this.inputField.selectionEnd = val; return val;"
  66.                                       onget="return this.inputField.selectionEnd;"/>
  67.      
  68.       <method name="setSelectionRange">
  69.         <parameter name="aSelectionStart"/>
  70.         <parameter name="aSelectionEnd"/>
  71.         <body>
  72.           this.inputField.setSelectionRange( aSelectionStart, aSelectionEnd );
  73.         </body>
  74.       </method>
  75.  
  76.       <constructor action="var str = this.boxObject.getProperty('value'); 
  77.                                                 if (str) {
  78.                                                   this.inputField.value=str;
  79.                                                   this.boxObject.removeProperty('value');
  80.                                                 }"/>
  81.       <destructor action="if (this.inputField.value) this.boxObject.setProperty('value', this.inputField.value);"/>
  82.    
  83.     </implementation>
  84.     
  85.     <handlers>
  86.       <handler event="focus" phase="capturing">
  87.         <![CDATA[
  88.           if (!this.hasAttribute('focused')) {
  89.             if (document.commandDispatcher.focusedElement != this.inputField) 
  90.               this.inputField.focus();
  91.             this.setAttribute('focused','true');
  92.           }
  93.         ]]>
  94.       </handler>
  95.       
  96.       <handler event="blur" phase="capturing">
  97.         <![CDATA[
  98.           this.removeAttribute('focused');
  99.         ]]>
  100.       </handler>
  101.     </handlers>    
  102.   </binding>
  103.   
  104.   <binding id="timed-textbox" extends="chrome://global/content/bindings/textbox.xml#textbox">
  105.     <content>
  106.       <xul:hbox class="textbox-input-box" flex="1">
  107.         <html:input class="textbox-input" flex="1" anonid="input"
  108.                     xbl:inherits="onfocus,onblur,value,type,maxlength,disabled,size,readonly,tabindex"/>
  109.       </xul:hbox>
  110.     </content>
  111.     <implementation>
  112.       <field name="_timer">null</field>
  113.       <property name="callback"
  114.                 onset="this.setAttribute('callback', val); return val;"
  115.                 onget="return this.getAttribute('callback');"/>
  116.       <property name="timeout"
  117.                 onset="this.setAttribute('timeout', val); return val;"
  118.                 onget="var t = parseInt(this.getAttribute('timeout')); return t ? t : 0;"/>
  119.     </implementation>    
  120.     <handlers>
  121.       <handler event="input">
  122.         <![CDATA[
  123.           if (this._timer)
  124.             clearTimeout(this._timer);
  125.           this._timer = setTimeout(this.callback, this.timeout);
  126.         ]]>
  127.       </handler>
  128.       <handler event="keypress">
  129.         <![CDATA[
  130.           if (event.keyCode == 13) {
  131.             if (this._timer)
  132.               clearTimeout(this._timer);
  133.             eval(this.callback);
  134.           }
  135.         ]]>
  136.       </handler>
  137.     </handlers>
  138.   </binding>
  139.  
  140.   <binding id="textarea" extends="chrome://global/content/bindings/textbox.xml#textbox">
  141.     <content>
  142.       <xul:hbox class="textbox-input-box" flex="1">
  143.         <html:textarea class="textbox-textarea" flex="1" anonid="input"
  144.                        xbl:inherits="onfocus,onblur,value,disabled,rows,cols,readonly,wrap"/>
  145.       </xul:hbox>
  146.     </content>
  147.   </binding>
  148.  
  149.   <binding id="input-box">
  150.     <content context="_child">
  151.       <children/>
  152.       <xul:menupopup onpopupshowing="if (document.commandDispatcher.focusedElement != this.parentNode.firstChild) 
  153.                                        this.parentNode.firstChild.focus();
  154.                                      this.parentNode.doPopupItemEnabling(this);"
  155.                      oncommand="this.parentNode.doCommand(event.originalTarget.getAttribute('cmd'));">
  156.         <xul:menuitem label="&undoCmd.label;" accesskey="&undoCmd.accesskey;" cmd="cmd_undo"/>
  157.         <xul:menuseparator/>
  158.         <xul:menuitem label="&cutCmd.label;" accesskey="&cutCmd.accesskey;" cmd="cmd_cut"/>
  159.         <xul:menuitem label="©Cmd.label;" accesskey="©Cmd.accesskey;" cmd="cmd_copy"/>
  160.         <xul:menuitem label="&pasteCmd.label;" accesskey="&pasteCmd.accesskey;" cmd="cmd_paste"/>
  161.         <xul:menuitem label="&deleteCmd.label;" accesskey="&deleteCmd.accesskey;" cmd="cmd_delete"/>
  162.         <xul:menuseparator/>
  163.         <xul:menuitem label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;" cmd="cmd_selectAll"/>
  164.       </xul:menupopup>
  165.     </content>
  166.  
  167.     <implementation>
  168.       <method name="doPopupItemEnabling">
  169.         <parameter name="popupNode"/> 
  170.         <body>
  171.           <![CDATA[
  172.             var children = popupNode.childNodes;
  173.             for (var i = 0; i < children.length; i++) {              
  174.               var command = children[i].getAttribute("cmd");
  175.               if (command) {
  176.                 var controller = document.commandDispatcher.getControllerForCommand(command);
  177.                 var enabled = controller.isCommandEnabled(command);
  178.                 if (enabled)
  179.                   children[i].removeAttribute("disabled");
  180.                 else
  181.                   children[i].setAttribute("disabled", "true");               
  182.               }
  183.             }
  184.           ]]>
  185.         </body>
  186.       </method>
  187.  
  188.       <method name="doCommand">
  189.         <parameter name="command"/>
  190.         <body>
  191.           <![CDATA[
  192.             var controller = document.commandDispatcher.getControllerForCommand(command);
  193.             controller.doCommand(command);
  194.           ]]>
  195.         </body>
  196.       </method>
  197.     </implementation>
  198.   </binding>
  199.   
  200. </bindings>