home *** CD-ROM | disk | FTP | other *** search
/ PC & Mediji 2002 March / PCM_0203.iso / MEDIA / DEMO / M10USWEB.exe / RCDATA / CABINET / money.cab / TxtAreaCls.htc < prev    next >
Text File  |  2001-07-25  |  11KB  |  469 lines

  1. <PUBLIC:COMPONENT tagName=TextArea >
  2. <public:defaults 
  3.     viewLinkContent
  4.     tabStop = true 
  5.     viewMasterTab = true 
  6. />
  7. <PUBLIC:ATTACH EVENT="oncontentready" ONEVENT="Main()" />
  8. <PUBLIC:EVENT  NAME="onChange" ID="TxtAreaChange" />
  9. <PUBLIC:METHOD NAME="SetValue" />
  10. <PUBLIC:METHOD NAME="SetFocus" />
  11. <PUBLIC:METHOD NAME="GetValue" />
  12. <PUBLIC:METHOD NAME="Reset" />
  13. <PUBLIC:PROPERTY NAME="TextField" />
  14. <PRIVATE:PROPERTY NAME="IsDirty" />
  15. </PUBLIC:COMPONENT>
  16. <!----------------------------------------------------------
  17.     Copyright (c) 2001 Microsoft Corporation.
  18.     All rights reserved.
  19.  
  20.     Project:    Money
  21.     File:       TxtAreaCls.htc
  22.     Revised:    May 27 2001
  23.     Owner:      michealh
  24. --------------------------------------------------------- -->
  25. <HTML>
  26. <HEAD>
  27. <SCRIPT TYPE="text/jscript" LANGUAGE="JScript">
  28. <!--
  29.  
  30. @set @debug = false;
  31.  
  32. //********************************************************************
  33. function Reset()
  34. {
  35.     txtInput.value = "";
  36.     ShowCaption(true);
  37. }
  38. //********************************************************************
  39. function GetCaption()
  40. {
  41.     return element.caption;
  42. }
  43. //********************************************************************
  44. function GetColumnCount()
  45. {
  46.     if(element.cols)
  47.     {
  48.         var L_intClmns = parseInt(element.cols);
  49.         if(!isNaN(L_intClmns))
  50.         {
  51.             return L_intClmns;
  52.         }
  53.         else
  54.         {
  55.             var L_objMsg  = new Message("errInvalidCols");
  56.             var exception = new Exception(L_objMsg["nbr"],L_objMsg["txt"]);
  57.             throw exception;
  58.         }
  59.     }
  60.     else
  61.     {
  62.         return 30;
  63.     }
  64. }
  65. //********************************************************************
  66. function GetRowCount()
  67. {
  68.     if(element.rows)
  69.     {
  70.         var L_intRws = parseInt(element.rows);
  71.         if(!isNaN(L_intRws))
  72.         {
  73.             return L_intRws;
  74.         }
  75.         else
  76.         {
  77.             var L_objMsg  = new Message("errInvalidRows");
  78.             var exception = new Exception(L_objMsg["nbr"],L_objMsg["txt"]);
  79.             throw exception;
  80.         }
  81.     }
  82.     else
  83.     {
  84.         return 1;
  85.     }
  86. }
  87. //********************************************************************
  88. function GetMaxLength()
  89. {
  90.     if(element.maxlength)
  91.     {
  92.         var L_intMxLngth = parseInt(element.maxlength);
  93.         if(!isNaN(L_intMxLngth))
  94.         {
  95.             return L_intMxLngth;
  96.         }
  97.         else
  98.         { 
  99.             var L_objMsg  = new Message("errInvalidMaxLength");
  100.             var exception = new Exception(L_objMsg["nbr"],L_objMsg["txt"]);
  101.             throw exception;
  102.         }
  103.     }
  104.     else
  105.     {
  106.         return 255;
  107.     }
  108. }
  109. //********************************************************************
  110. function GetReadOnly()
  111. {
  112.     if(element.readonly)
  113.     {
  114.         var L_bolRdOnly = new Boolean();
  115.         L_bolRdOnly     = eval(element.readonly);
  116.         return L_bolRdOnly;
  117.     }
  118.     else
  119.     {
  120.         return false;
  121.     }
  122. }
  123. //********************************************************************
  124. function SetValue(objValue)
  125. {
  126.     ShowCaption(false);
  127.     txtInput.value = objValue;
  128.     RaiseEvent();
  129. }
  130. //********************************************************************
  131. function GetValue()
  132. {
  133.     return txtInput.value;
  134. }
  135. //********************************************************************
  136. function SetFocus()
  137. {
  138.     try
  139.     {
  140.         txtInput.focus();
  141.     }
  142.     catch(e)
  143.     {
  144.         return;
  145.     }
  146. }
  147. //********************************************************************
  148. function ShowCaption(bolShow)
  149. {
  150.     try
  151.     {
  152.         if(document.all.txtCaption)
  153.         {
  154.             document.all.txtCaption.style.top = (bolShow) ? "2pt" : -100;
  155.         }
  156.     }
  157.     catch(e)
  158.     {
  159.         return;
  160.     }
  161. }
  162. //********************************************************************
  163. function Main()
  164. {
  165.     IsDirty = false;
  166.     
  167.     var L_objTxtElmnt = new TextArea();
  168.     document.body.appendChild(L_objTxtElmnt);
  169.     TextField = L_objTxtElmnt;
  170.     if(element.caption)
  171.     {
  172.         var L_objCptn = new Caption();
  173.         document.body.appendChild(L_objCptn);
  174.         element.onblur = Element_Blur;
  175.     }
  176. }
  177. //********************************************************************
  178. function TextArea()
  179. {
  180.     var L_objTxtElmnt = document.createElement("TEXTAREA");
  181.     with(L_objTxtElmnt)
  182.     {
  183.         id               = "txtInput";
  184.         tabIndex         = 1;
  185.         style.overflow   = "hidden";
  186.         style.border     = "1pt solid #999999";
  187.         style.fontSize   = "8pt";
  188.         style.fontFamily = ResourceList.documentElement.selectSingleNode("properties/member[@name='TextArea']/style[@name='cssFontFamily']").text;
  189.         onchange         = TextArea_Change;
  190.         onkeydown        = TextArea_KeyDown;
  191.         onbeforepaste    = TextArea_BeforePaste;
  192.         onpaste          = TextArea_Paste;
  193.         onfocus          = TextArea_Focus;
  194.         oncontextmenu    = TextArea_ContextMenu;
  195.     }
  196.     try
  197.     {
  198.         L_objTxtElmnt.cols = GetColumnCount();
  199.     }
  200.     catch(exception)
  201.     {
  202.         if(exception instanceof Exception)
  203.         {
  204.             HandleException(exception.number,exception.description)
  205.         }
  206.         else
  207.         {
  208.             throw exception;
  209.         }
  210.     }
  211.     try
  212.     {
  213.         L_objTxtElmnt.readOnly = GetReadOnly();
  214.     }
  215.     catch(exception)
  216.     {
  217.         if(exception instanceof Exception)
  218.         {
  219.             HandleException(exception.number,exception.description)
  220.         }
  221.         else
  222.         {
  223.             throw exception;
  224.         }
  225.     }
  226.     try
  227.     {
  228.         L_objTxtElmnt.rows = GetRowCount();
  229.         L_objTxtElmnt.style.wordWrap = (1 == GetRowCount())
  230.             ?
  231.             "normal"
  232.             :
  233.             "break-word"
  234.             ;
  235.     }
  236.     catch(exception)
  237.     {
  238.         if(exception instanceof Exception)
  239.         {
  240.             HandleException(exception.number,exception.description)
  241.         }
  242.         else
  243.         {
  244.             throw exception;
  245.         }
  246.     }
  247.     try
  248.     {
  249.         L_objTxtElmnt.maxlength = GetMaxLength();
  250.     }
  251.     catch(exception)
  252.     {
  253.         if(exception instanceof Exception)
  254.         {
  255.             HandleException(exception.number,exception.description)
  256.         }
  257.         else
  258.         {
  259.             throw exception;
  260.         }
  261.     }
  262.     return L_objTxtElmnt;
  263. }
  264. //********************************************************************
  265. function Caption()
  266. {
  267.     var L_objCptn = document.createElement("DIV");
  268.     with(L_objCptn)
  269.     {
  270.         id               = "txtCaption";
  271.         style.position   = "absolute";
  272.         style.top        = "2pt";
  273.         style.left       = "4pt";
  274.         style.zIndex     = 2;
  275.         style.fontFamily = ResourceList.documentElement.selectSingleNode("properties/member[@name='Caption']/style[@name='cssFontFamily']").text;
  276.         style.fontSize   = "8pt";
  277.         style.color      = "#999999";
  278.         innerText        = GetCaption();
  279.         onclick          = SetFocus;
  280.     }
  281.     return L_objCptn;
  282. }
  283. //********************************************************************
  284. function Message(strMessageName)
  285. {
  286.     var L_objMsg    = new Object();
  287.     var L_objMsgNd  = ResourceList.documentElement.selectSingleNode("messages/msg[@name='" + strMessageName + "']");
  288.     L_objMsg["txt"] = L_objMsgNd.text;
  289.     L_objMsg["nbr"] = L_objMsgNd.getAttribute("number");
  290.     return L_objMsg;
  291. }
  292. //********************************************************************
  293. function Exception(intNumber,
  294.     strDescription)
  295. {
  296.     this.number      = intNumber;
  297.     this.description = strDescription;
  298. }
  299. //********************************************************************
  300. function HandleException(intNumber,
  301.     strDescription)
  302. {
  303.     /*@if(@debug)
  304.     alert("Error: " + intNumber + "\n\n" + strDescription);
  305.     @end @*/
  306. }
  307. //********************************************************************
  308. function Element_Blur()
  309. {
  310.     try
  311.     {
  312.         if(txtInput.value.length == 0)
  313.         {
  314.             ShowCaption(true);
  315.         }
  316.     }
  317.     catch(e)
  318.     {
  319.         return;
  320.     }
  321. }
  322. //********************************************************************
  323. function TextArea_Focus()
  324. {
  325.     try
  326.     {
  327.         ShowCaption(false);
  328.         txtInput.select();
  329.     }
  330.     catch(e)
  331.     {
  332.         return;
  333.     }
  334. }
  335. //********************************************************************
  336. function TextArea_KeyDown()
  337. {
  338.     var L_hWnEvnt   = window.event;
  339.     var L_objTxtRng = txtInput.createTextRange();
  340.     var L_bolCtrlKy = L_hWnEvnt.ctrlKey;
  341.     /*
  342.         The keydown event gives us the greatest breadth of
  343.         values to examine and cancel if necessary.  In this
  344.         case, we negate all but the BACKSPACE, DELETE, LEFT ARROW,
  345.         CTRL-C, and CTRL-X combinations if the text range length 
  346.         is equal to or greater than the value of the maxlength property.
  347.     */
  348.     if((13 == L_hWnEvnt.keyCode) && (1 == GetRowCount()))
  349.     {
  350.         L_hWnEvnt.keyCode      = 0;
  351.         L_hWnEvnt.returnValue  = false;
  352.         L_hWnEvnt.cancelBubble = true;
  353.     }
  354.     if(L_objTxtRng.text.length >= txtInput.maxlength)
  355.     {
  356.         if((L_hWnEvnt.keyCode != 8)
  357.             && (L_hWnEvnt.keyCode != 37) 
  358.             && (L_hWnEvnt.keyCode != 38) 
  359.             && (L_hWnEvnt.keyCode != 39) 
  360.             && (L_hWnEvnt.keyCode != 40) 
  361.             && (L_hWnEvnt.keyCode != 46) 
  362.             && !((L_hWnEvnt.keyCode == 67) && L_bolCtrlKy)
  363.             && !((L_hWnEvnt.keyCode == 88) && L_bolCtrlKy)) 
  364.         {
  365.             L_hWnEvnt.returnValue  = false;
  366.             L_hWnEvnt.cancelBubble = true;
  367.         }
  368.         if(L_objTxtRng.text.length > txtInput.maxlength)
  369.         {
  370.             L_objTxtRng.text = L_objTxtRng.text.substring(0,txtInput.maxlength);
  371.         }
  372.     }
  373.     else
  374.     {
  375.         RaiseEvent();
  376.     }
  377. }
  378. //********************************************************************
  379. function TextArea_BeforePaste()
  380. {
  381.     window.event.returnValue = false;
  382. }
  383. //********************************************************************
  384. function TextArea_Paste()
  385. {
  386.     if(txtInput.readOnly)
  387.     {
  388.         window.event.cancelBubble = true;
  389.         window.event.returnValue  = false;
  390.     }
  391.     else
  392.     {
  393.         var L_objTxtRng   = txtInput.createTextRange();
  394.         var L_objClpbrdDt = window.clipboardData.getData("Text");
  395.         /*
  396.             If the combined length of the current text range and
  397.             the clipboard value is greater than the field's maxlength 
  398.             value, we either fit as much of the clipboard in as we
  399.             can, or reject the command altogether.
  400.         */
  401.         if((L_objTxtRng.text.length + L_objClpbrdDt.length) > txtInput.maxlength)
  402.         {
  403.             var L_intSbStrLn = txtInput.maxlength - L_objTxtRng.text.length;
  404.             if(L_intSbStrLn > 0)
  405.             {
  406.                 L_objClpbrdDt = L_objClpbrdDt.substring(0,L_intSbStrLn);
  407.                 window.clipboardData.setData("Text",L_objClpbrdDt);
  408.             }
  409.             else
  410.             { 
  411.                 window.event.cancelBubble = true;
  412.                 window.event.returnValue  = false;
  413.             }
  414.         }
  415.         RaiseEvent();
  416.     }
  417. }
  418. //********************************************************************
  419. function TextArea_Change()
  420. {
  421.     /*
  422.         This backstops everything else, and is pretty ugly.
  423.     */
  424.     var L_objTxtRng = txtInput.createTextRange();
  425.     if(L_objTxtRng.text.length > txtInput.maxlength)
  426.     {
  427.         L_objTxtRng.text = L_objTxtRng.text.substring(0,txtInput.maxlength);
  428.     }
  429.     RaiseEvent();
  430. }
  431. //********************************************************************
  432. function TextArea_ContextMenu()
  433. {
  434.     window.event.returnValue  = true;
  435.     window.event.cancelBubble = true;
  436. }
  437. //********************************************************************
  438. function RaiseEvent()
  439. {
  440.     if(!IsDirty)
  441.     {
  442.         IsDirty = true;
  443.  
  444.         var L_hEvntObj = createEventObject();
  445.         L_hEvntObj.result = true;
  446.         TxtAreaChange.fire (L_hEvntObj);
  447.     }     
  448. }
  449. //-->
  450. </SCRIPT>
  451. <XML ID="ResourceList">
  452.     <MnyVwrRsrc xmlns="urn:schemas-microsoft.com:mnyvwr-resource">
  453.         <properties>
  454.             <member name="TextArea">
  455.                 <style name="cssFontFamily">Tahoma</style>
  456.             </member>
  457.             <member name="Caption">
  458.                 <style name="cssFontFamily">Tahoma</style>
  459.             </member>
  460.         </properties>
  461.         <messages>
  462.             <msg number="1" name="errInvalidRows">Invalid value assigned to TextArea rows property.</msg>
  463.             <msg number="2" name="errInvalidCols">Invalid value assigned to TextArea cols property.</msg>
  464.             <msg number="3" name="errInvalidMaxLength">Invalid value assigned to TextArea maxlength property.</msg>
  465.         </messages>
  466.     </MnyVwrRsrc>
  467. </XML>
  468. </HEAD><BODY></BODY></HTML>
  469.