home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 June / CHIP_CD_2004-06.iso / bonus / buhgal / files / M12USWEB.exe / RCDATA / CABINET / money.cab / CmdBtnCls.htc < prev    next >
Text File  |  2003-06-18  |  10KB  |  424 lines

  1. <PUBLIC:COMPONENT tagName=CommandButton >
  2. <public:defaults 
  3.     viewLinkContent
  4.     tabStop = true 
  5.     viewMasterTab = true 
  6. />
  7. <PUBLIC:ATTACH EVENT="oncontentready" ONEVENT="Main()" />
  8. <PUBLIC:EVENT  NAME="onSelectKey" ID="MnyVwrSelectKey" />
  9. <PUBLIC:METHOD NAME="SetEnabled" />
  10. <PUBLIC:METHOD NAME="SetCaption" />
  11. <PRIVATE:PROPERTY NAME="IsEnabled" />
  12. </PUBLIC:COMPONENT>
  13. <!----------------------------------------------------------
  14.     Copyright (c) 2001 Microsoft Corporation.
  15.     All rights reserved.
  16.  
  17.     File:       CmdBtnCls.htc
  18.     Revised:    Oct 26 2001
  19. --------------------------------------------------------- -->
  20. <HTML xmlns:mnydraw="urn:schemas-microsoft-com:vml">
  21. <HEAD>
  22. <STYLE TYPE="text/css">
  23. <!--
  24. mnydraw\:*{behavior: url(#default#VML);}
  25. -->
  26. </STYLE>
  27. <SCRIPT TYPE="text/jscript" LANGUAGE="JScript">
  28. <!--
  29.  
  30. @set @debug = false;
  31.  
  32. var m_fIsActive = false;
  33.  
  34. //**************************************************
  35. function GetWidth()
  36. {
  37.     var szMsgId = null;
  38.     if(element.width)
  39.     {
  40.         var bWdth = parseInt(element.width);
  41.         if(!isNaN(bWdth))
  42.         {
  43.             return bWdth + "pt";
  44.         }
  45.         else
  46.         {
  47.             szMsgId = "errInvalidWidth";
  48.         }
  49.     }
  50.     else
  51.     {
  52.         szMsgId = "errInvalidWidth";
  53.     }
  54.     if(null != szMsgId)
  55.     {
  56.         var hMsg = new Message(szMsgId);
  57.         var exception = new Exception(hMsg["nbr"],hMsg["txt"]);
  58.         throw exception; 
  59.     }
  60. }
  61. //**************************************************
  62. function GetHeight()
  63. {
  64.     var szMsgId = null;
  65.     if(element.height)
  66.     {
  67.         var bHght = parseInt(element.height);
  68.         if(!isNaN(bHght))
  69.         {
  70.             return bHght + "pt";
  71.         }
  72.         else
  73.         {
  74.             szMsgId = "errInvalidHeight";
  75.         }
  76.     }
  77.     else
  78.     {
  79.         szMsgId = "errMissingHeight";
  80.     }
  81.     if(null != szMsgId)
  82.     {
  83.         var hMsg  = new Message(szMsgId);
  84.         var exception = new Exception(hMsg["nbr"],hMsg["txt"]);
  85.         throw exception; 
  86.     }
  87. }
  88. //**************************************************
  89. function SetCaption(szCaption)
  90. {
  91.     var szMsgId = null;
  92.     if(null != szCaption)
  93.     {
  94.         var iTkn = szCaption.indexOf("&");
  95.         if(iTkn != -1)
  96.         {
  97.             if((iTkn + 1) < szCaption.length)
  98.             {
  99.                 var chAcclKy = szCaption.charAt(iTkn + 1);
  100.                 var rxAccl   = new RegExp("&" + chAcclKy);
  101.                 var hAccl    = document.createElement("SPAN");
  102.                 if(document.all.htmAccelerator)
  103.                 {
  104.                     htmCaption.removeChild(htmCaption.children[0]);
  105.                 }
  106.                 hAccl.id                   = "htmAccelerator";
  107.                 hAccl.style.accelerator    = true;
  108.                 hAccl.style.textDecoration = "underline";
  109.                 htmCaption.innerText       = "";
  110.                 htmCaption.appendChild(hAccl);
  111.                 htmCaption.onkeyup         = Caption_KeyUp;
  112.                 htmAccelerator.innerText   = chAcclKy;
  113.                 htmCaption.innerHTML       = szCaption.replace(rxAccl,htmCaption.innerHTML);
  114.                 htmCaption.accessKey       = chAcclKy.toLowerCase();
  115.             }
  116.             else
  117.             {
  118.                 szMsgId = "errNoAccelCharKey";
  119.             }
  120.         }
  121.         else
  122.         {
  123.             htmCaption.innerText = szCaption;
  124.             htmCaption.accessKey = null;
  125.             htmCaption.onkeyup   = null;
  126.         }
  127.     }
  128.     else
  129.     {
  130.         szMsgId = "errNullCaption";
  131.     }
  132.     if(null != szMsgId)
  133.     {
  134.         var hMsg = new Message(szMsgId);
  135.         var exception = new Exception(hMsg["nbr"],hMsg["txt"]);
  136.         throw exception; 
  137.     }
  138. }
  139. //**************************************************
  140. function GetEnabled()
  141. {
  142.     if(element.enabled)
  143.     {
  144.         var fEnbld = new Boolean();
  145.         fEnbld = eval(element.enabled);
  146.         return fEnbld;
  147.     }
  148.     else
  149.     {
  150.         return true;
  151.     }
  152. }
  153. //**************************************************
  154. function SetEnabled(fState)
  155. {
  156.     IsEnabled = fState;
  157.     CommandButton_StaticState();
  158. }
  159. //**************************************************
  160. function Main()
  161. {
  162.     IsEnabled = GetEnabled();
  163.     
  164.     var hCmdBtn = new CommandButton();
  165.     document.body.appendChild(hCmdBtn);
  166.     
  167.     CommandButton_StaticState();
  168.     
  169.     document.body.onselectstart = function()
  170.     {
  171.         return false;
  172.     }
  173.     document.body.oncontextmenu = function()
  174.     {
  175.         return false;
  176.     }
  177.     try
  178.     {
  179.         SetCaption(element.caption);
  180.     }
  181.     catch(exception)
  182.     {
  183.         if(exception instanceof Exception)
  184.         {
  185.             HandleException(exception.number,exception.description)
  186.         }
  187.         else
  188.         {
  189.             throw exception;
  190.         }
  191.     }
  192. }
  193. //**************************************************
  194. function CommandButton()
  195. {
  196.     var hCptn   = new Caption();
  197.     var hCmdBtn = document.createElement("mnydraw:roundrect");
  198.     var hFill   = document.createElement("mnydraw:fill");
  199.     
  200.     hCmdBtn.id           = "htmCmdBtn";
  201.     hCmdBtn.tabIndex     = "1";
  202.     hCmdBtn.hideFocus    = true;
  203.     hCmdBtn.onfocus      = CommandButton_HoverState;
  204.     hCmdBtn.onblur       = CommandButton_StaticState;
  205.     hCmdBtn.onkeyup      = CommandButton_KeyUp;
  206.     hCmdBtn.onmouseover  = CommandButton_HoverState;
  207.     hCmdBtn.onmouseout   = CommandButton_StaticState;
  208.     hCmdBtn.onclick      = CommandButton_Click;
  209.     hCmdBtn.arcsize      = "0.1";
  210.     hCmdBtn.strokecolor  = "#738ac6";
  211.     hCmdBtn.strokeweight = "1pt";
  212.     hCmdBtn.setAttribute("backcolor","#9ecbfd");
  213.     hCmdBtn.setAttribute("hovercolor","#ffffff");
  214.     hFill.type           = "gradient";
  215.     hFill.method         = "linear sigma";
  216.     hFill.angle          = "180";
  217.     hFill.setAttribute("nacolor","#009afd");
  218.     hFill.setAttribute("backcolor","#009afd");
  219.     hFill.setAttribute("hovercolor","#9ecbfd");
  220.  
  221.     try
  222.     {
  223.         hCmdBtn.style.width = GetWidth();
  224.     }
  225.     catch(exception)
  226.     {
  227.         if(exception instanceof Exception)
  228.         {
  229.             HandleException(exception.number,exception.description)
  230.         }
  231.         else
  232.         {
  233.             throw exception;
  234.         }
  235.     }
  236.     try
  237.     {
  238.         hCmdBtn.style.height = GetHeight();
  239.     }
  240.     catch(exception)
  241.     {
  242.         if(exception instanceof Exception)
  243.         {
  244.             HandleException(exception.number,exception.description)
  245.         }
  246.         else
  247.         {
  248.             throw exception;
  249.         }
  250.     }
  251.     if(element.tooltiptext)
  252.     {
  253.         hCmdBtn.title = element.tooltiptext;
  254.     }
  255.     hCmdBtn.appendChild(hCptn);
  256.     hCmdBtn.appendChild(hFill);
  257.     
  258.     return hCmdBtn;
  259. }
  260. //**************************************************
  261. function Caption()
  262. {
  263.     var hCptn = document.createElement("DIV");
  264.     
  265.     hCptn.id               = "htmCaption";
  266.     hCptn.style.position   = "relative";
  267.     hCptn.style.top        = "2pt"; // Offset the button strokeweight
  268.     hCptn.style.left       = "2pt"; // to better center the caption.
  269.     hCptn.style.fontSize   = "8pt";
  270.     hCptn.style.fontFamily = ResourceList.documentElement.selectSingleNode("properties/member[@name='Caption']/style[@name='cssFontFamily']").text;
  271.     hCptn.style.fontWeight = "bold";
  272.     hCptn.style.textAlign  = "center";
  273.     hCptn.style.cursor     = "default";
  274.     hCptn.setAttribute("nacolor","#6898c8");
  275.     hCptn.setAttribute("forecolor","#000000");
  276.     try
  277.     {
  278.         hCptn.style.width = GetWidth();
  279.     }
  280.     catch(exception)
  281.     {
  282.         if(exception instanceof Exception)
  283.         {
  284.             HandleException(exception.number,exception.description)
  285.         }
  286.         else
  287.         {
  288.             throw exception;
  289.         }
  290.     }
  291.     return hCptn;
  292. }
  293. //**************************************************
  294. function Message(szMsgName)
  295. {
  296.     var hMsg    = new Object();
  297.     var hRsrc   = ResourceList.documentElement.selectSingleNode("messages/msg[@name='" + szMsgName + "']");
  298.     hMsg["txt"] = hRsrc.text;
  299.     hMsg["nbr"] = hRsrc.getAttribute("number");
  300.     return hMsg;
  301. }
  302. //**************************************************
  303. function Exception(bNumber,
  304.     szDescription)
  305. {
  306.     this.number = bNumber;
  307.     this.description = szDescription;
  308. }
  309. //**************************************************
  310. function HandleException(bNumber,
  311.     szDescription)
  312. {
  313.     /*@if(@debug)
  314.     alert("Error: " + bNumber + "\n\n" + szDescription);
  315.     @end @*/
  316. }
  317. //**************************************************
  318. function CommandButton_StaticState()
  319. {
  320.     htmCmdBtn.fillcolor = htmCmdBtn.getAttribute("backcolor");
  321.     htmCmdBtn.children[1].color2 = (IsEnabled) 
  322.         ? 
  323.         htmCmdBtn.children[1].getAttribute("backcolor") 
  324.         : 
  325.         htmCmdBtn.children[1].getAttribute("nacolor")
  326.         ;
  327.     htmCaption.style.color = (IsEnabled) 
  328.         ? 
  329.         htmCaption.getAttribute("forecolor")
  330.         : 
  331.         htmCaption.getAttribute("nacolor")
  332.         ;
  333. }
  334. //**************************************************
  335. function CommandButton_HoverState()
  336. {
  337.     if(IsEnabled)
  338.     {
  339.         this.fillcolor = this.getAttribute("hovercolor");
  340.         this.children[1].color2 = this.children[1].getAttribute("hovercolor");
  341.     }
  342. }
  343. //**************************************************
  344. function CommandButton_Click()
  345. {
  346.     if(!IsEnabled)
  347.     {
  348.         window.event.returnValue  = false;
  349.         window.event.cancelBubble = true;    
  350.     }
  351. }
  352. //**************************************************
  353. function CommandButton_KeyUp()
  354. {
  355.     if(IsEnabled)
  356.     {
  357.         var hEvnt = window.event;
  358.         if(hEvnt.keyCode == 13)
  359.         {
  360.             if(!m_fIsActive)
  361.             {
  362.                 m_fIsActive = true;
  363.                 RaiseEvent();
  364.             }
  365.             else
  366.             {
  367.                 m_fIsActive = false;
  368.             }
  369.         }
  370.         hEvnt.returnValue  = false;
  371.         hEvnt.cancelBubble = true;
  372.     }
  373. }
  374. //**************************************************
  375. function Caption_KeyUp()
  376. {
  377.     if(IsEnabled)
  378.     {
  379.         var hEvnt  = window.event;
  380.         var szAccl = htmAccelerator.innerText.toUpperCase();
  381.         if(hEvnt.altKey && (hEvnt.keyCode == szAccl.charCodeAt(0)))
  382.         {
  383.             if(!m_fIsActive)
  384.             {
  385.                 m_fIsActive = true;
  386.                 RaiseEvent();
  387.             }
  388.             else
  389.             {
  390.                 m_fIsActive = false;
  391.             }
  392.         }
  393.         hEvnt.returnValue  = false;
  394.         hEvnt.cancelBubble = true;
  395.     }
  396. }
  397. //**************************************************
  398. function RaiseEvent()
  399. {
  400.     var hEvnt = createEventObject();
  401.     hEvnt.result = true;
  402.     MnyVwrSelectKey.fire (hEvnt);     
  403. }
  404. //-->
  405. </SCRIPT>
  406. <XML ID="ResourceList">
  407.     <MnyVwrRsrc xmlns="urn:schemas-microsoft.com:mnyvwr-resource">
  408.         <properties>
  409.             <member name="Caption">
  410.                 <style name="cssFontFamily">Tahoma</style>
  411.             </member>
  412.         </properties>
  413.         <messages>
  414.             <msg number="1" name="errInvalidWidth">Invalid value assigned to CommandButton width property.</msg>
  415.             <msg number="2" name="errMissingWidth">No width property assigned to CommandButton.</msg>
  416.             <msg number="3" name="errInvalidHeight">Invalid value assigned to CommandButton height property.</msg>
  417.             <msg number="4" name="errMissingHeight">No height property assigned to CommandButton.</msg>
  418.             <msg number="5" name="errNoAccelCharKey"><![CDATA[The & token is used in the caption, but no accelerator key is specified.]]></msg>
  419.             <msg number="6" name="errNullCaption">Attempt to assign null value to CommandButton caption.</msg>
  420.         </messages>
  421.     </MnyVwrRsrc>
  422. </XML>
  423. </HEAD><BODY></BODY></HTML>
  424.