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