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

  1. <?xml version="1.0"?>
  2.  
  3. <bindings   id="mailBindings"
  4.             xmlns="http://www.mozilla.org/xbl"
  5.             xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  6.  
  7.   <!-- dummy widget to force this file to load -->
  8.   <binding id="dummy" extends="xul:box"/>
  9.   <!-- Message Pane Widgets -->
  10.   <binding id="mail-emailaddress" extends="xul:box">
  11.     <content>
  12.           <xul:box inherits="orient" autostretch="never" flex="1">
  13.           <xul:text class="emailDisplayButton" popup="emailAddressPopup" context="emailAddressPopup" inherits="value,crop"/>
  14.           <xul:image class="emailDisplayImage"/>
  15.         </xul:box>
  16.     </content>
  17.     
  18.     <implementation>  
  19.       <property name="value"      onset="return document.getAnonymousNodes(this)[0].firstChild.setAttribute('value',val);"
  20.                                   onget="return document.getAnonymousNodes(this)[0].firstChild.getAttribute('value');"/>
  21.       <property name="crop"       onset="return document.getAnonymousNodes(this)[0].firstChild.setAttribute('crop',val);"
  22.                                   onget="return document.getAnonymousNodes(this)[0].firstChild.getAttribute('crop');"/>
  23.       <property name="disabled"   onset="return document.getAnonymousNodes(this)[0].firstChild.setAttribute('disabled',val);"
  24.                                   onget="return document.getAnonymousNodes(this)[0].firstChild.getAttribute('disabled');"/>
  25.       <property name="src"        onset="return document.getAnonymousNodes(this)[0].childNodes[1].setAttribute('src',val);"
  26.                                   onget="return document.getAnonymousNodes(this)[0].childNodes[1].getAttribute('src');"/>
  27.       <property name="imgalign"   onset="return document.getAnonymousNodes(this)[0].childNodes[1].setAttribute('imgalign',val);"
  28.                                   onget="return document.getAnonymousNodes(this)[0].childNodes[1].getAttribute('imgalign');"/>
  29.       <method name="setTextAttribute">
  30.         <parameter name="attributeName"/>
  31.         <parameter name="attributeValue"/>
  32.         <body>
  33.           <![CDATA[            
  34.             var textNode = document.getAnonymousNodes(this)[0].firstChild;
  35.             textNode.setAttribute(attributeName, attributeValue);
  36.           ]]>
  37.         </body>
  38.       </method>
  39.  
  40.       <method name="getTextAttribute">
  41.         <parameter name="attributeName"/>
  42.         <parameter name="attributeValue"/>
  43.         <body>
  44.           <![CDATA[            
  45.             var textNode = document.getAnonymousNodes(this)[0].firstChild;
  46.             return textNode.getAttribute(attributeName, attributeValue);
  47.           ]]>
  48.         </body>
  49.       </method>
  50.     </implementation>
  51.   </binding>
  52.  
  53.   <binding id="search-menulist-abstract" name="searchMenulistAbstract" extends="xul:box">
  54.     <content>
  55.       <xul:menulist class="search-menulist" inherits="flex" oncommand="this.parentNode.onSelect(event)">
  56.         <xul:menupopup class="search-menulist-popup"/>
  57.       </xul:menulist>
  58.     </content>
  59.  
  60.     <implementation>
  61.       <property readonly="true" name="validityManager">
  62.         <![CDATA[
  63.            Components.classes['@mozilla.org/mail/search/validityManager;1'].getService(Components.interfaces.nsIMsgSearchValidityManager);
  64.         ]]>
  65.       </property>
  66.       <property name="searchScope" onget="return this.internalScope;">
  67.         <!-- scope ID - retrieve the table -->
  68.         <setter>
  69.           <![CDATA[
  70.             // if scope isn't changing this is a noop
  71.             if (this.internalScope == val) return val;
  72.  
  73.             this.internalScope = val;
  74.             //dump("\trefreshList via .searchScope setter\n");
  75.             this.refreshList();
  76.             var targets = this.targets;
  77.             if (targets) {
  78.               for (var i=0; i< targets.length; i++) {
  79.                 targets[i].searchScope = val;
  80.               }
  81.             }
  82.             return val;
  83.           ]]>
  84.         </setter>
  85.       </property>
  86.  
  87.       <property name="validityTable" readonly="true" onget="return this.validityManager.getTable(this.searchScope)"/>
  88.  
  89.       <property name="valueStrings" readonly="true">
  90.         <getter>
  91.           <![CDATA[
  92.             var strings = new Array;
  93.             var ids = this.valueIds;
  94.             var bundle = this.stringBundle;
  95.             for (var i=0; i<ids.length; i++)
  96.                 strings[i] = this.stringBundle.GetStringFromID(ids[i]);
  97.             return strings;
  98.           ]]>
  99.         </getter>
  100.       </property>
  101.       <property name="targets" readonly="true">
  102.         <getter>
  103.           <![CDATA[
  104.             var forAttrs =  this.getAttribute("for");
  105.             if (!forAttrs) return null;
  106.             var targetIds = forAttrs.split(",");
  107.             if (targetIds.length == 0) return null;
  108.  
  109.             var targets = new Array;
  110.             var j=0;
  111.             for (var i=0; i<targetIds.length;i++) {
  112.               var target = document.getElementById(targetIds[i]);
  113.               if (target) targets[j++] = target;
  114.             }
  115.             return targets;
  116.           ]]>
  117.         </getter>
  118.       </property>
  119.  
  120.       <!-- value forwards to the internal menulist's "data" attribute -->
  121.       <property name="value" onget="return document.getAnonymousNodes(this)[0].selectedItem.getAttribute('data');">
  122.         <setter>
  123.           <![CDATA[
  124.             dump("\tsetting value on id=" + this.id + "\n");
  125.             var menulist = document.getAnonymousNodes(this)[0];
  126.             var dataItems = menulist.getElementsByAttribute("data", val);
  127.             if (dataItems.length > 0)
  128.                 menulist.selectedItem = dataItems[0];
  129.  
  130.             // now notify targets of new parent's value
  131.             var targets = this.targets;
  132.             if (targets) {
  133.               for (var i=0; i< targets.length; i++) {
  134.                 //dump("setting parentValue via abstract .value on <" + this.localName +">\n");
  135.                 targets[i].parentValue = val;
  136.               }
  137.             } else {
  138.                 //dump("Doh! No targets!\n");
  139.             }
  140.             return val;
  141.           ]]>
  142.         </setter>
  143.       </property>
  144.       <method name="refreshList">
  145.         <body>
  146.           <![CDATA[
  147.             var menuItemIds = this.valueIds;
  148.             var menuItemStrings = this.valueStrings;
  149.  
  150.             var menulist = document.getAnonymousNodes(this)[0];
  151.             var popup = menulist.firstChild;
  152.  
  153.             // save our old "data" so we can restore it later
  154.             var oldData = menulist.data;
  155.  
  156.             // remove the old popup children
  157.             while (popup.hasChildNodes())
  158.               popup.removeChild(popup.lastChild);
  159.  
  160.             var newSelection;
  161.             for (var i=0; i<menuItemIds.length; i++) {
  162.               // create the menuitem
  163.               var menuitem = document.createElement("menuitem");
  164.               menuitem.setAttribute("value", menuItemStrings[i]);
  165.               menuitem.setAttribute("data", menuItemIds[i]);
  166.               popup.appendChild(menuitem);
  167.  
  168.               // try to restore the selection
  169.               if (!newSelection || oldData == menuItemIds[i].toString()) {
  170.                 newSelection = menuitem;
  171.               }
  172.             }
  173.  
  174.             // now restore the selection
  175.             menulist.selectedItem = newSelection
  176.           ]]>
  177.         </body>
  178.       </method>
  179.       <method name="onSelect">
  180.         <parameter name="event"/>
  181.         <body>
  182.           <![CDATA[
  183.             var menulist = document.getAnonymousNodes(this)[0];
  184.  
  185.             // notify targets
  186.             var targets = this.targets;
  187.             if (targets) {
  188.               for (var i=0; i< targets.length; i++) {
  189.                 targets[i].parentValue = menulist.data;
  190.               }
  191.             }
  192.           ]]>
  193.         </body>
  194.       </method>
  195.     </implementation>
  196.   </binding>
  197.  
  198.   <!-- searchattribute - Subject, Sender, To, CC, etc. -->
  199.   <binding id="searchattribute" name="searchAttribute"
  200.            extends="chrome://messenger/content/mailWidgets.xml#search-menulist-abstract">
  201.     <implementation>
  202.       <property name="stringBundle">
  203.           <![CDATA[
  204.            srGetStrBundle("chrome://messenger/locale/search-attributes.properties");
  205.           ]]>
  206.       </property>
  207.       <property name="valueIds" readonly="true">
  208.         <getter>
  209.           <![CDATA[
  210.             var length = new Object;
  211.             return this.validityTable.getAvailableAttributes(length);
  212.           ]]>
  213.         </getter>
  214.       </property>
  215.     </implementation>
  216.   </binding>
  217.  
  218.   <!-- searchoperator - Contains, Is Less than, etc -->
  219.   <binding id="searchoperator" name="searchOperator"
  220.            extends="chrome://messenger/content/mailWidgets.xml#search-menulist-abstract">
  221.     <implementation>
  222.       <property name="stringBundle">
  223.           <![CDATA[
  224.             srGetStrBundle("chrome://messenger/locale/search-operators.properties");
  225.           ]]>
  226.       </property>
  227.       <property name="valueIds" readonly="true">
  228.         <getter>
  229.           <![CDATA[
  230.             var length = new Object;
  231.             return this.validityTable.getAvailableOperators(this.searchAttribute,length);
  232.           ]]>
  233.         </getter>
  234.       </property>
  235.       <property name="parentValue">
  236.         <setter>
  237.           <![CDATA[
  238.             if (this.searchAttribute == val) return val;
  239.             this.searchAttribute = val;
  240.             //dump("\trefreshList via .parentValue on " + this.localName + "\n");
  241.             this.refreshList();
  242.             return val;
  243.           ]]>
  244.         </setter>
  245.         <getter>
  246.           <![CDATA[
  247.             return this.searchAttribute;
  248.           ]]>
  249.         </getter>
  250.       </property>
  251.     </implementation>
  252.   </binding>
  253.  
  254.   <!-- searchvalue - a widget which dynamically changes it's user interface
  255.        depending on what type of data it's supposed to be showing
  256.        currently handles arbitrary text entry, and menulists for priority and
  257.        status
  258.   -->
  259.   <binding id="searchvalue" name="searchValue" extends="xul:deck">
  260.     <!-- yeah yeah, this stuff needs to be localized. I'm working on it! -->
  261.     <content>
  262.       <xul:textfield flex="1" class="search-value-textfield"/>
  263.       <xul:menulist flex="1" class="search-value-menulist">
  264.         <xul:menupopup class="search-value-popup">
  265.           <xul:menuitem data="2" stringTag="priorityLowest" class="search-value-menuitem"/>
  266.           <xul:menuitem data="3" stringTag="priorityLow" class="search-value-menuitem"/>
  267.           <xul:menuitem data="4" stringTag="priorityNormal" class="search-value-menuitem"/>
  268.           <xul:menuitem data="5" stringTag="priorityHigh" class="search-value-menuitem"/>
  269.           <xul:menuitem data="6" stringTag="priorityHighest" class="search-value-menuitem"/>
  270.         </xul:menupopup>
  271.       </xul:menulist>
  272.       <xul:menulist flex="1" class="search-value-menulist">
  273.         <xul:menupopup class="search-value-popup">
  274.           <xul:menuitem data="1" stringTag="replied" class="search-value-menuitem"/>
  275.           <xul:menuitem data ="2" stringTag="read" class="search-value-menuitem"/>
  276.           <xul:menuitem data ="1048576" stringTag="new" class="search-value-menuitem"/>
  277.           <xul:menuitem data ="65536" stringTag="forwarded" class="search-value-menuitem"/>
  278.         </xul:menupopup>
  279.       </xul:menulist>
  280.     </content>
  281.     <implementation>
  282.       <!-- parentValue forwards to the attribute -->
  283.       <property name="parentValue" onset="return this.searchAttribute=val;"
  284.                                    onget="return this.searchAttribute;"/>
  285.       <property name="searchAttribute" onget="return this.internalAttribute;">
  286.         <setter>
  287.           <![CDATA[
  288.             // noop if we're not changing it
  289.             if (this.internalAttribute == val) return val;
  290.             this.internalAttribute = val;
  291.             // we inherit from a deck, so just use it's index attribute
  292.             // to hide/show widgets
  293.             if (val == Components.interfaces.nsMsgSearchAttrib.Priority)
  294.               this.setAttribute("index", "1");
  295.             else if (val == Components.interfaces.nsMsgSearchAttrib.MsgStatus)
  296.               this.setAttribute("index", "2");
  297.             else
  298.               this.setAttribute("index", "0");
  299.             return val;
  300.           ]]>
  301.         </setter>
  302.       </property>
  303.       <property name="value" onget="return this.internalValue;">
  304.         <setter>
  305.           <![CDATA[
  306.           dump("\tsetting value on id=" + this.id + "\n");
  307.           // val is a nsIMsgSearchValue object
  308.           this.internalValue = val;
  309.           var attrib = val.attrib;
  310.           var nsMsgSearchAttrib = Components.interfaces.nsMsgSearchAttrib;
  311.           var children = document.getAnonymousNodes(this);
  312.           this.searchAttribute = attrib;
  313.           if (attrib == nsMsgSearchAttrib.Priority) {
  314.             dump("Setting priority to " + val.priority + "..\n");
  315.             var matchingPriority =
  316.                 children[1].getElementsByAttribute("data", val.priority);
  317.             dump("found " + matchingPriority.length + " matching priority nodes\n");
  318.             if (matchingPriority.length > 0)
  319.                 children[1].selectedItem = matchingPriority[0];
  320.           }
  321.           else if (attrib == nsMsgSearchAttrib.MsgStatus) {
  322.             var matchingStatus =
  323.               children[2].getElementsByAttribute("data", val.status);
  324.             if (matchingStatus.length > 0) 
  325.               children[2].selectedItem = matchingStatus[0];
  326.           }
  327.           else if (attrib == nsMsgSearchAttrib.AgeInDays)
  328.             children[0].value = val.age;
  329.           else
  330.             children[0].value = val.str;
  331.           return val;
  332.           ]]>
  333.         </setter>
  334.       </property>
  335.       <method name="save">
  336.         <body>
  337.           <![CDATA[
  338.             var searchValue = this.value;
  339.             var searchAttribute = this.searchAttribute;
  340.             var nsMsgSearchAttrib = Components.interfaces.nsMsgSearchAttrib;
  341.             var children = document.getAnonymousNodes(this);
  342.  
  343.             searchValue.attrib = searchAttribute;
  344.             if (searchAttribute == nsMsgSearchAttrib.Priority) {
  345.                dump("\tSaving priority " + children[1].selectedItem.data + "\n");
  346.                searchValue.priority = children[1].selectedItem.data;
  347.             }
  348.             else if (searchAttribute == nsMsgSearchAttrib.MsgStatus)
  349.                searchValue.status = children[2].selectedItem.data;
  350.             else if (searchAttribute == nsMsgSearchAttrib.AgeInDays)
  351.                searchValue.age = children[0].value;
  352.             else
  353.                searchValue.str = children[0].value;
  354.           ]]>
  355.         </body>
  356.       </method>
  357.       <method name="saveTo">
  358.         <parameter name="searchValue"/>
  359.         <body>
  360.           <![CDATA[
  361.             this.internalValue = searchValue;
  362.             this.save();
  363.           ]]>
  364.         </body>
  365.       </method>
  366.       <method name="fillStringsForChildren">
  367.         <parameter name="parentNode"/>
  368.         <parameter name="bundle"/>
  369.         <body>
  370.           <![CDATA[
  371.             var children = parentNode.childNodes;
  372.             var len=children.length;
  373.             for (var i=0; i<len; i++) {
  374.               var node = children[i];
  375.               var stringTag = node.getAttribute("stringTag");
  376.               if (stringTag) {
  377.                 node.setAttribute("value", bundle.GetStringFromName(stringTag));
  378.               }
  379.             }
  380.           ]]>
  381.         </body>
  382.       </method>
  383.     </implementation>
  384.     <handlers>
  385.       <handler event="bindingattached">
  386.       <![CDATA[
  387.         // initialize strings
  388.         var bundle = srGetStrBundle("chrome://messenger/locale/messenger.properties");
  389.         this.fillStringsForChildren(document.getAnonymousNodes(this)[1].firstChild, bundle);
  390.         this.fillStringsForChildren(document.getAnonymousNodes(this)[2].firstChild, bundle);
  391.       ]]>
  392.       </handler>
  393.     </handlers>
  394.   </binding>
  395.   <binding id="searchterm" name="searchTerm" extends="xul:box">
  396.     <implementation>
  397.       <!-- the actual nsIMsgSearchTerm object -->
  398.       <property name="searchTerm" onget="return this.internalSearchTerm">
  399.         <setter>
  400.           <![CDATA[
  401.             this.internalSearchTerm = val;
  402.  
  403.             var term = val;
  404.             // val is a nsIMsgSearchTerm
  405.             var searchAttribute=this.searchattribute;
  406.             var searchOperator=this.searchoperator;
  407.             var searchValue=this.searchvalue;
  408.  
  409.             // now reflect all attributes of the searchterm into the widgets
  410.             if (searchAttribute) searchAttribute.value = term.attrib;
  411.             if (searchOperator) searchOperator.value = val.op;
  412.             if (searchValue) searchValue.value = term.value;
  413.  
  414.             this.booleanAnd = val.booleanAnd;
  415.           ]]>
  416.         </setter>
  417.       </property>
  418.  
  419.       <property name="searchScope">
  420.         <getter>
  421.           <![CDATA[
  422.              var searchAttribute = this.searchattribute;
  423.              if (searchAttribute)
  424.                return searchAttribute.searchScope;
  425.              return undefined;
  426.            ]]>
  427.         </getter>
  428.         <setter>
  429.           <![CDATA[
  430.             var searchAttribute = this.searchattribute;
  431.             if (searchAttribute) searchAttribute.searchScope=val;
  432.            ]]>
  433.         </setter>
  434.       </property>
  435.       <!-- the three tags that make up a term - to use, set the
  436.            attribute in the XUL to the ID of the term.
  437.         -->
  438.       <property name="searchattribute" 
  439.                 onget="return document.getElementById(this.getAttribute('searchattribute'));"
  440.                 onset="this.setAttribute('searchattribute',val.id)"/>
  441.  
  442.       <property name="searchoperator" 
  443.                 onget="return document.getElementById(this.getAttribute('searchoperator'));"
  444.                 onset="this.setAttribute('searchoperator',val.id)"/>
  445.  
  446.       <property name="searchvalue" 
  447.                 onget="return document.getElementById(this.getAttribute('searchvalue'));"
  448.                 onset="this.setAttribute('searchvalue',val.id)"/>
  449.       <property name="booleanNodes">
  450.         <![CDATA[
  451.           null;
  452.         ]]>
  453.       </property>
  454.       <property name="stringBundle">
  455.           <![CDATA[
  456.              srGetStrBundle("chrome://messenger/locale/search.properties");
  457.           ]]>
  458.       </property>
  459.       <property name="booleanAnd" onget="return this.internalBooleanAnd">
  460.         <setter>
  461.           <![CDATA[
  462.             // whenever you set this, all nodes in booleanNodes
  463.             // are updated to reflect the string
  464.  
  465.             if (this.internalBooleanAnd == val) return;
  466.             this.internalBooleanAnd = val;
  467.  
  468.             var booleanNodes = this.booleanNodes;
  469.             if (!booleanNodes) return;
  470.  
  471.             var stringBundle = this.stringBundle;
  472.             var andString = val ? "And" : "Or";
  473.             for (var i=0; i<booleanNodes.length; i++) {
  474.               try {              
  475.                 var staticString =
  476.                     stringBundle.GetStringFromName("search" + andString + i);
  477.                 if (staticString && staticString.length>0)
  478.                     booleanNodes[i].setAttribute("value", staticString);
  479.               } catch (ex) { /* no error, means string not found */}
  480.             }
  481.           ]]>
  482.         </setter>
  483.       </property>
  484.       <method name="save">
  485.         <body>
  486.           <![CDATA[
  487.             var searchTerm = this.searchTerm;
  488.             searchTerm.attrib = this.searchattribute.value;
  489.             searchTerm.op = this.searchoperator.value;
  490.             if (this.searchvalue.value)
  491.               this.searchvalue.save();
  492.             else
  493.               this.searchvalue.saveTo(searchTerm.value);
  494.             searchTerm.value = this.searchvalue.value;
  495.             searchTerm.booleanAnd = this.booleanAnd;
  496.           ]]>
  497.         </body>
  498.       </method>
  499.       <!-- if you have a search term element with no search term -->
  500.       <method name="saveTo">
  501.         <parameter name="searchTerm"/>
  502.         <body>
  503.           <![CDATA[
  504.             this.internalSearchTerm = searchTerm;
  505.             this.save();
  506.           ]]>
  507.         </body>
  508.       </method>
  509.     </implementation>
  510.   </binding>
  511. </bindings>
  512.