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 >
Wrap
Text File
|
2001-07-25
|
11KB
|
469 lines
<PUBLIC:COMPONENT tagName=TextArea >
<public:defaults
viewLinkContent
tabStop = true
viewMasterTab = true
/>
<PUBLIC:ATTACH EVENT="oncontentready" ONEVENT="Main()" />
<PUBLIC:EVENT NAME="onChange" ID="TxtAreaChange" />
<PUBLIC:METHOD NAME="SetValue" />
<PUBLIC:METHOD NAME="SetFocus" />
<PUBLIC:METHOD NAME="GetValue" />
<PUBLIC:METHOD NAME="Reset" />
<PUBLIC:PROPERTY NAME="TextField" />
<PRIVATE:PROPERTY NAME="IsDirty" />
</PUBLIC:COMPONENT>
<!----------------------------------------------------------
Copyright (c) 2001 Microsoft Corporation.
All rights reserved.
Project: Money
File: TxtAreaCls.htc
Revised: May 27 2001
Owner: michealh
--------------------------------------------------------- -->
<HTML>
<HEAD>
<SCRIPT TYPE="text/jscript" LANGUAGE="JScript">
<!--
@set @debug = false;
//********************************************************************
function Reset()
{
txtInput.value = "";
ShowCaption(true);
}
//********************************************************************
function GetCaption()
{
return element.caption;
}
//********************************************************************
function GetColumnCount()
{
if(element.cols)
{
var L_intClmns = parseInt(element.cols);
if(!isNaN(L_intClmns))
{
return L_intClmns;
}
else
{
var L_objMsg = new Message("errInvalidCols");
var exception = new Exception(L_objMsg["nbr"],L_objMsg["txt"]);
throw exception;
}
}
else
{
return 30;
}
}
//********************************************************************
function GetRowCount()
{
if(element.rows)
{
var L_intRws = parseInt(element.rows);
if(!isNaN(L_intRws))
{
return L_intRws;
}
else
{
var L_objMsg = new Message("errInvalidRows");
var exception = new Exception(L_objMsg["nbr"],L_objMsg["txt"]);
throw exception;
}
}
else
{
return 1;
}
}
//********************************************************************
function GetMaxLength()
{
if(element.maxlength)
{
var L_intMxLngth = parseInt(element.maxlength);
if(!isNaN(L_intMxLngth))
{
return L_intMxLngth;
}
else
{
var L_objMsg = new Message("errInvalidMaxLength");
var exception = new Exception(L_objMsg["nbr"],L_objMsg["txt"]);
throw exception;
}
}
else
{
return 255;
}
}
//********************************************************************
function GetReadOnly()
{
if(element.readonly)
{
var L_bolRdOnly = new Boolean();
L_bolRdOnly = eval(element.readonly);
return L_bolRdOnly;
}
else
{
return false;
}
}
//********************************************************************
function SetValue(objValue)
{
ShowCaption(false);
txtInput.value = objValue;
RaiseEvent();
}
//********************************************************************
function GetValue()
{
return txtInput.value;
}
//********************************************************************
function SetFocus()
{
try
{
txtInput.focus();
}
catch(e)
{
return;
}
}
//********************************************************************
function ShowCaption(bolShow)
{
try
{
if(document.all.txtCaption)
{
document.all.txtCaption.style.top = (bolShow) ? "2pt" : -100;
}
}
catch(e)
{
return;
}
}
//********************************************************************
function Main()
{
IsDirty = false;
var L_objTxtElmnt = new TextArea();
document.body.appendChild(L_objTxtElmnt);
TextField = L_objTxtElmnt;
if(element.caption)
{
var L_objCptn = new Caption();
document.body.appendChild(L_objCptn);
element.onblur = Element_Blur;
}
}
//********************************************************************
function TextArea()
{
var L_objTxtElmnt = document.createElement("TEXTAREA");
with(L_objTxtElmnt)
{
id = "txtInput";
tabIndex = 1;
style.overflow = "hidden";
style.border = "1pt solid #999999";
style.fontSize = "8pt";
style.fontFamily = ResourceList.documentElement.selectSingleNode("properties/member[@name='TextArea']/style[@name='cssFontFamily']").text;
onchange = TextArea_Change;
onkeydown = TextArea_KeyDown;
onbeforepaste = TextArea_BeforePaste;
onpaste = TextArea_Paste;
onfocus = TextArea_Focus;
oncontextmenu = TextArea_ContextMenu;
}
try
{
L_objTxtElmnt.cols = GetColumnCount();
}
catch(exception)
{
if(exception instanceof Exception)
{
HandleException(exception.number,exception.description)
}
else
{
throw exception;
}
}
try
{
L_objTxtElmnt.readOnly = GetReadOnly();
}
catch(exception)
{
if(exception instanceof Exception)
{
HandleException(exception.number,exception.description)
}
else
{
throw exception;
}
}
try
{
L_objTxtElmnt.rows = GetRowCount();
L_objTxtElmnt.style.wordWrap = (1 == GetRowCount())
?
"normal"
:
"break-word"
;
}
catch(exception)
{
if(exception instanceof Exception)
{
HandleException(exception.number,exception.description)
}
else
{
throw exception;
}
}
try
{
L_objTxtElmnt.maxlength = GetMaxLength();
}
catch(exception)
{
if(exception instanceof Exception)
{
HandleException(exception.number,exception.description)
}
else
{
throw exception;
}
}
return L_objTxtElmnt;
}
//********************************************************************
function Caption()
{
var L_objCptn = document.createElement("DIV");
with(L_objCptn)
{
id = "txtCaption";
style.position = "absolute";
style.top = "2pt";
style.left = "4pt";
style.zIndex = 2;
style.fontFamily = ResourceList.documentElement.selectSingleNode("properties/member[@name='Caption']/style[@name='cssFontFamily']").text;
style.fontSize = "8pt";
style.color = "#999999";
innerText = GetCaption();
onclick = SetFocus;
}
return L_objCptn;
}
//********************************************************************
function Message(strMessageName)
{
var L_objMsg = new Object();
var L_objMsgNd = ResourceList.documentElement.selectSingleNode("messages/msg[@name='" + strMessageName + "']");
L_objMsg["txt"] = L_objMsgNd.text;
L_objMsg["nbr"] = L_objMsgNd.getAttribute("number");
return L_objMsg;
}
//********************************************************************
function Exception(intNumber,
strDescription)
{
this.number = intNumber;
this.description = strDescription;
}
//********************************************************************
function HandleException(intNumber,
strDescription)
{
/*@if(@debug)
alert("Error: " + intNumber + "\n\n" + strDescription);
@end @*/
}
//********************************************************************
function Element_Blur()
{
try
{
if(txtInput.value.length == 0)
{
ShowCaption(true);
}
}
catch(e)
{
return;
}
}
//********************************************************************
function TextArea_Focus()
{
try
{
ShowCaption(false);
txtInput.select();
}
catch(e)
{
return;
}
}
//********************************************************************
function TextArea_KeyDown()
{
var L_hWnEvnt = window.event;
var L_objTxtRng = txtInput.createTextRange();
var L_bolCtrlKy = L_hWnEvnt.ctrlKey;
/*
The keydown event gives us the greatest breadth of
values to examine and cancel if necessary. In this
case, we negate all but the BACKSPACE, DELETE, LEFT ARROW,
CTRL-C, and CTRL-X combinations if the text range length
is equal to or greater than the value of the maxlength property.
*/
if((13 == L_hWnEvnt.keyCode) && (1 == GetRowCount()))
{
L_hWnEvnt.keyCode = 0;
L_hWnEvnt.returnValue = false;
L_hWnEvnt.cancelBubble = true;
}
if(L_objTxtRng.text.length >= txtInput.maxlength)
{
if((L_hWnEvnt.keyCode != 8)
&& (L_hWnEvnt.keyCode != 37)
&& (L_hWnEvnt.keyCode != 38)
&& (L_hWnEvnt.keyCode != 39)
&& (L_hWnEvnt.keyCode != 40)
&& (L_hWnEvnt.keyCode != 46)
&& !((L_hWnEvnt.keyCode == 67) && L_bolCtrlKy)
&& !((L_hWnEvnt.keyCode == 88) && L_bolCtrlKy))
{
L_hWnEvnt.returnValue = false;
L_hWnEvnt.cancelBubble = true;
}
if(L_objTxtRng.text.length > txtInput.maxlength)
{
L_objTxtRng.text = L_objTxtRng.text.substring(0,txtInput.maxlength);
}
}
else
{
RaiseEvent();
}
}
//********************************************************************
function TextArea_BeforePaste()
{
window.event.returnValue = false;
}
//********************************************************************
function TextArea_Paste()
{
if(txtInput.readOnly)
{
window.event.cancelBubble = true;
window.event.returnValue = false;
}
else
{
var L_objTxtRng = txtInput.createTextRange();
var L_objClpbrdDt = window.clipboardData.getData("Text");
/*
If the combined length of the current text range and
the clipboard value is greater than the field's maxlength
value, we either fit as much of the clipboard in as we
can, or reject the command altogether.
*/
if((L_objTxtRng.text.length + L_objClpbrdDt.length) > txtInput.maxlength)
{
var L_intSbStrLn = txtInput.maxlength - L_objTxtRng.text.length;
if(L_intSbStrLn > 0)
{
L_objClpbrdDt = L_objClpbrdDt.substring(0,L_intSbStrLn);
window.clipboardData.setData("Text",L_objClpbrdDt);
}
else
{
window.event.cancelBubble = true;
window.event.returnValue = false;
}
}
RaiseEvent();
}
}
//********************************************************************
function TextArea_Change()
{
/*
This backstops everything else, and is pretty ugly.
*/
var L_objTxtRng = txtInput.createTextRange();
if(L_objTxtRng.text.length > txtInput.maxlength)
{
L_objTxtRng.text = L_objTxtRng.text.substring(0,txtInput.maxlength);
}
RaiseEvent();
}
//********************************************************************
function TextArea_ContextMenu()
{
window.event.returnValue = true;
window.event.cancelBubble = true;
}
//********************************************************************
function RaiseEvent()
{
if(!IsDirty)
{
IsDirty = true;
var L_hEvntObj = createEventObject();
L_hEvntObj.result = true;
TxtAreaChange.fire (L_hEvntObj);
}
}
//-->
</SCRIPT>
<XML ID="ResourceList">
<MnyVwrRsrc xmlns="urn:schemas-microsoft.com:mnyvwr-resource">
<properties>
<member name="TextArea">
<style name="cssFontFamily">Tahoma</style>
</member>
<member name="Caption">
<style name="cssFontFamily">Tahoma</style>
</member>
</properties>
<messages>
<msg number="1" name="errInvalidRows">Invalid value assigned to TextArea rows property.</msg>
<msg number="2" name="errInvalidCols">Invalid value assigned to TextArea cols property.</msg>
<msg number="3" name="errInvalidMaxLength">Invalid value assigned to TextArea maxlength property.</msg>
</messages>
</MnyVwrRsrc>
</XML>
</HEAD><BODY></BODY></HTML>