home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2004 June
/
CHIP_CD_2004-06.iso
/
bonus
/
buhgal
/
files
/
M12USWEB.exe
/
RCDATA
/
CABINET
/
money.cab
/
TxtAreaCls.htc
< prev
next >
Wrap
Text File
|
2003-06-18
|
11KB
|
477 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.
File: TxtAreaCls.htc
Revised: Oct 26 2001
--------------------------------------------------------- -->
<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 bClmns = parseInt(element.cols);
if(!isNaN(bClmns))
{
return bClmns;
}
else
{
var hMsg = new Message("errInvalidCols");
var exception = new Exception(hMsg["nbr"],hMsg["txt"]);
throw exception;
}
}
else
{
return 30;
}
}
//**************************************************
function GetRowCount()
{
if(element.rows)
{
var bRws = parseInt(element.rows);
if(!isNaN(bRws))
{
return bRws;
}
else
{
var hMsg = new Message("errInvalidRows");
var exception = new Exception(hMsg["nbr"],hMsg["txt"]);
throw exception;
}
}
else
{
return 1;
}
}
//**************************************************
function GetMaxLength()
{
if(element.maxlength)
{
var bMxLngth = parseInt(element.maxlength);
if(!isNaN(bMxLngth))
{
return bMxLngth;
}
else
{
var hMsg = new Message("errInvalidMaxLength");
var exception = new Exception(hMsg["nbr"],hMsg["txt"]);
throw exception;
}
}
else
{
return 128;
}
}
//**************************************************
function GetReadOnly()
{
if(element.readonly)
{
var fRdOnly = new Boolean();
fRdOnly = eval(element.readonly);
return fRdOnly;
}
else
{
return false;
}
}
//**************************************************
function GetInputMethod()
{
if(element.IMEditor)
{
return element.IMEditor;
}
else
{
return "disabled";
}
}
//**************************************************
function SetValue(hParam)
{
ShowCaption(false);
txtInput.value = hParam;
RaiseEvent();
}
//**************************************************
function GetValue()
{
return txtInput.value;
}
//**************************************************
function SetFocus()
{
try
{
txtInput.focus();
}
catch(e)
{
return;
}
}
//**************************************************
function ShowCaption(fShow)
{
try
{
if(document.all.txtCaption)
{
document.all.txtCaption.style.top = (fShow) ? "2pt" : -100;
}
}
catch(e)
{
return;
}
}
//**************************************************
function Main()
{
IsDirty = false;
var hTxt = new TextArea();
document.body.appendChild(hTxt);
TextField = hTxt;
if(element.caption)
{
var hCptn = new Caption();
document.body.appendChild(hCptn);
element.onblur = Element_Blur;
}
}
//**************************************************
function TextArea()
{
var hTxt = document.createElement("TEXTAREA");
hTxt.id = "txtInput";
hTxt.tabIndex = 1;
hTxt.style.overflow = "hidden";
hTxt.style.imeMode = GetInputMethod();
hTxt.style.border = "1pt solid #999999";
hTxt.style.fontSize = "8pt";
hTxt.style.fontFamily = ResourceList.documentElement.selectSingleNode("properties/member[@name='TextArea']/style[@name='cssFontFamily']").text;
hTxt.onchange = TextArea_Change;
hTxt.onkeydown = TextArea_KeyDown;
hTxt.onbeforepaste = TextArea_BeforePaste;
hTxt.onpaste = TextArea_Paste;
hTxt.onfocus = TextArea_Focus;
hTxt.oncontextmenu = TextArea_ContextMenu;
try
{
hTxt.cols = GetColumnCount();
}
catch(exception)
{
if(exception instanceof Exception)
{
HandleException(exception.number,exception.description)
}
else
{
throw exception;
}
}
try
{
hTxt.readOnly = GetReadOnly();
}
catch(exception)
{
if(exception instanceof Exception)
{
HandleException(exception.number,exception.description)
}
else
{
throw exception;
}
}
try
{
hTxt.rows = GetRowCount();
hTxt.style.wordWrap = (1 == GetRowCount())
?
"normal"
:
"break-word"
;
}
catch(exception)
{
if(exception instanceof Exception)
{
HandleException(exception.number,exception.description)
}
else
{
throw exception;
}
}
try
{
hTxt.maxlength = GetMaxLength();
}
catch(exception)
{
if(exception instanceof Exception)
{
HandleException(exception.number,exception.description)
}
else
{
throw exception;
}
}
return hTxt;
}
//**************************************************
function Caption()
{
var hCptn = document.createElement("DIV");
hCptn.id = "txtCaption";
hCptn.style.position = "absolute";
hCptn.style.top = "2pt";
hCptn.style.left = "4pt";
hCptn.style.zIndex = 2;
hCptn.style.fontFamily = ResourceList.documentElement.selectSingleNode("properties/member[@name='Caption']/style[@name='cssFontFamily']").text;
hCptn.style.fontSize = "8pt";
hCptn.style.color = "#999999";
hCptn.innerText = GetCaption();
hCptn.onclick = SetFocus;
return hCptn;
}
//**************************************************
function Message(szMsgName)
{
var hMsg = new Object();
var hRsrc = ResourceList.documentElement.selectSingleNode("messages/msg[@name='" + szMsgName + "']");
hMsg["txt"] = hRsrc.text;
hMsg["nbr"] = hRsrc.getAttribute("number");
return hMsg;
}
//**************************************************
function Exception(bNumber,
szDescription)
{
this.number = bNumber;
this.description = szDescription;
}
//**************************************************
function HandleException(bNumber,
szDescription)
{
/*@if(@debug)
alert("Error: " + bNumber + "\n\n" + szDescription);
@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 hEvnt = window.event;
var hTxtRng = txtInput.createTextRange();
var fCtrlKy = hEvnt.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 == hEvnt.keyCode) && (1 == GetRowCount()))
{
hEvnt.keyCode = 0;
hEvnt.returnValue = false;
hEvnt.cancelBubble = true;
}
if(hTxtRng.text.length >= txtInput.maxlength)
{
if((hEvnt.keyCode != 8)
&& (hEvnt.keyCode != 37)
&& (hEvnt.keyCode != 38)
&& (hEvnt.keyCode != 39)
&& (hEvnt.keyCode != 40)
&& (hEvnt.keyCode != 46)
&& !((hEvnt.keyCode == 67) && fCtrlKy)
&& !((hEvnt.keyCode == 88) && fCtrlKy))
{
hEvnt.returnValue = false;
hEvnt.cancelBubble = true;
}
if(hTxtRng.text.length > txtInput.maxlength)
{
hTxtRng.text = hTxtRng.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 hTxtRng = txtInput.createTextRange();
var hClpbrdDt = 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((hTxtRng.text.length + hClpbrdDt.length) > txtInput.maxlength)
{
var dbSbStrLn = txtInput.maxlength - hTxtRng.text.length;
if(dbSbStrLn > 0)
{
hClpbrdDt = hClpbrdDt.substring(0,dbSbStrLn);
window.clipboardData.setData("Text",hClpbrdDt);
}
else
{
window.event.cancelBubble = true;
window.event.returnValue = false;
}
}
RaiseEvent();
}
}
//**************************************************
function TextArea_Change()
{
/*
This backstops everything else, and is pretty ugly.
*/
var hTxtRng = txtInput.createTextRange();
if(hTxtRng.text.length > txtInput.maxlength)
{
hTxtRng.text = hTxtRng.text.substring(0,txtInput.maxlength);
}
RaiseEvent();
}
//**************************************************
function TextArea_ContextMenu()
{
window.event.returnValue = true;
window.event.cancelBubble = true;
}
//**************************************************
function RaiseEvent()
{
if(!IsDirty)
{
IsDirty = true;
var hEvnt = createEventObject();
hEvnt.result = true;
TxtAreaChange.fire (hEvnt);
}
}
//-->
</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>