123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095 |
- <!--/******************************************************************
- ** 文件名: KDButton.htc
- ** Copyright (c) 2005 金蝶国际软件集团有限公司 研发中心
- ** http://www.kingdee.com
- **
- ** 创建人: 叶汉良
- ** 日 期: 2005.07.20
- **
- ** 描述:按钮控件
- ** 版 本:Web V1.0
- ******************************************************************/-->
- <public:component tagName="KDButton" lightWeight=true>
- <public:attach event="oncontentready" onevent="kdButtonReady()"/>
- <public:attach event="onpropertychange" onevent="kdButtonPropertyChange()"/>
- <public:event name="onEvtClick" id = "evtClick"/>
- <public:event name="onEvtDblClick" id = "evtDblClick"/>
- <public:event name="onEvtMouseDown" id = "evtMouseDown"/>
- <public:event name="onEvtMouseUp" id = "evtMouseUp"/>
- <public:event name="onEvtMouseOver" id = "evtMouseOver"/>
- <public:event name="onEvtMouseOut" id = "evtMouseOut"/>
- <public:event name="onEvtMouseMove" id = "evtMouseMove"/>
- <public:event name="onEvtKeyDown" id = "evtKeyDown"/>
- <public:event name="onEvtKeyPress" id = "evtKeyPress"/>
- <public:event name="onEvtKeyUp" id = "evtKeyUp"/>
- <public:event name="onEvtFocus" id = "evtFocus"/>
- <public:event name="onEvtBlur" id = "evtBlur"/>
- <public:property name="imagePath" value="../images/"/>
- <public:property name="cssPath" value=""/>
- <public:property name="width" value="73"/>
- <public:property name="height" value="21"/>
- <public:property name="caption" value="Button"/>
- <public:property name="fontFamily" value="arial"/>
- <public:property name="fontSize" value="9pt"/>
- <public:property name="initFontColor" value="#000000"/>
- <public:property name="activeFontColor" value="#000000"/>
- <public:property name="moveFontColor" value="#000000"/>
- <public:property name="clickFontColor" value="#000000"/>
- <public:property name="disableFontColor" value="#6E6E6E"/>
- <public:property name="disable" value="false"/>
- <public:property name="name" value=""/>
- <public:property name="value" value=""/>
- <public:property name="id" value=""/>
- <public:property name="tabIndex1" value=""/>
- <public:property name="tips" value=""/>
- <public:property name="leftWidth" value="10"/>
- <public:property name="rightWidth" value="10"/>
- <public:property name="haveZH" value="true"/>
- <public:property name="initColor" value="#85A7CF,#B7CCE5,#FFFFFF,#EEEEEE,#EEEEEE,#E4E4E4,#D5D5D5,#4174BA,#4174BA"/>
- <public:property name="activeColor" value="#60A4F7,#A2CFFB,#FEFEFF,#F9F9F9,#EEEEEE,#E4E4E4,#D5D5D5,#0052C9,#0052C9"/>
- <public:property name="moveColor" value="#FFB368,#FFCC9F,#FEFEFF,#F9F9F9,#EEEEEE,#E4E4E4,#D5D5D5,#C96C00,#C96C00"/>
- <public:property name="clickColor" value="#FFC759,#FFD69D,#FFBC34,#DDDDDD,#EEEEEE,#EEEEEE,#F9F9F9,#FEFEFF,#C98900"/>
- <public:property name="disableColor" value="#B2B2B2,#CFCFCF,#FEFEFE,#F9F9F9,#EEEEEE,#E4E4E4,#D5D5D5,#646464,#646464"/>
- <public:property name="cursor" value="hand"/>
- <public:property name="borderWidth1" value="4"/>
- <public:method name="focus"/>
- <public:method name="click"/>
- <public:method name="getWidth"/>
- <script language="Javascript">
- var sFunction_Btn_Left1 = "";
- var sFunction_Btn_Left2 = "";
- var sFunction_Btn_Left3 = "";
- var sFunction_Btn_Left4 = "";
- var sFunction_Btn_Left5 = "";
- var sFunction_Btn_Right1 = "";
- var sFunction_Btn_Right2 = "";
- var sFunction_Btn_Right3 = "";
- var sFunction_Btn_Right4 = "";
- var sFunction_Btn_Right5 = "";
- var sFunction_Btn_Dot = "";
- var sFunction_Btn_Dot1 = "";
- var sTable = "<table cellspacing=0 cellpadding=0 border=0 style='table-layout:fixed;display:inline;'></table>";
- //鼠标已经按下
- var bMouseDown = false;
- //是否已经激活
- var bActive = false;
- //文档
- var oDoc = window.document;
- var aInitColor = new Array();
- var aActiveColor = new Array();
- var aMoveColor = new Array();
- var aClickColor = new Array();
- var aDisableColor = new Array();
- /**
- *控件初始化
- *
- */
- function kdButtonReady()
- {
- initCss();
- strToArray();
-
- oButtonE = oDoc.createElement("<input type='button' style='display:inline;width:0;height:0;'>");
- element.innerHTML = sTable;
- oTableE = element.children(0);
- oTableE.appendChild(oButtonE);
-
- oButtonE.name = name;
- oButtonE.value = value;
- oButtonE.id = id;
- oButtonE.tabIndex = tabIndex1;
- oButtonE.disabled = eval(disable);
-
- initTable(oTableE);
-
- //绑定事件
- oButtonE.onfocus = doButtonFocus;
- oButtonE.onblur = doButtonBlur;
- doEvent(oTableE);
- }
- /**
- *控件属性值发生变化的时候处理事件
- *
- */
- function kdButtonPropertyChange()
- {
- switch(event.propertyName.toString().toLowerCase())
- {
- case "disable":
- {
- var oDivE = element.children(0).rows(0).cells(1).children(0).children(0).children(0);
- if (eval(disable) == true)
- {
- element.children(0).style.cursor = "default";
- updateProperty(5);
- oDivE.children(0).rows(0).cells(1).style.color = disableFontColor;
- }
- else
- {
- element.children(0).style.cursor = cursor;
- updateProperty(1);
- oDivE.children(0).rows(0).cells(1).style.color = initFontColor;
- }
- element.children(0).children(1).disabled = eval(disable);
- break;
- }
- case "caption":
- {
- break;
- }
- default:
- break;
- }
- }
- /**
- *处理按钮的focus事件
- *
- */
- function doButtonFocus()
- {
- if (bMouseDown == false)
- {
- doFocus(element.children(0));
- }
- bMouseDown = false;
- }
- /**
- *处理按钮的focus事件
- *
- */
- function doButtonBlur()
- {
- if (bMouseDown == false)
- {
- doBlur(element.children(0));
- }
- bMouseDown = false;
- }
- /**
- *初始化设置相关的属性
- *
- */
- function initTable(oTable)
- {
- oTable.style.height = height;
-
- var oTrE = oTable.insertRow();
- var oTdLeftE = oTrE.insertCell();
- var oTdMiddleE = oTrE.insertCell();
- var oTdRightE = oTrE.insertCell();
- var oLeftImgE = oDoc.createElement("<img border=0>");
- var oRightImgE = oDoc.createElement("<img border=0>");
-
- oTdLeftE.style.height = height;
- oTdLeftE.style.width = leftWidth;
-
- oTdRightE.style.height = height;
- oTdRightE.style.width = rightWidth;
-
- oTdLeftE.appendChild(oLeftImgE);
- oTdRightE.appendChild(oRightImgE);
-
- oTdMiddleE.style.borderTopWidth = 1;
- oTdMiddleE.style.borderTopStyle = "solid";
- oTdMiddleE.style.borderBottomWidth = 1;
- oTdMiddleE.style.borderBottomStyle = "solid";
-
- oTdMiddleE.style.height = height;
- oTdMiddleE.align = "center";
- oTdMiddleE.verticalAlign = "middle";
- var oReturnValue = calcLabelWidth(caption,fontSize);
- oTdMiddleE.style.width = oReturnValue.width + 8;
- oTdMiddleE.style.wordBreak = "keep-all";
- var oTempTable = generateCaption(caption,oReturnValue.lastCharPos,oReturnValue.charWidth);
- var oDivE = genMiddleDivE();
- oTdMiddleE.appendChild(oDivE);
-
- oDivE.children(0).children(0).appendChild(oTempTable);
-
- if (eval(disable) == true)
- {
- oTable.style.cursor = "default";
- updateProperty(5);
- }
- else
- {
- oTable.style.cursor = cursor;
- updateProperty(1);
- }
-
- if (oTempTable.tips != null)
- {
- oTable.title = oTempTable.tips;
- }
-
- if (tips != null && tips != "")
- {
- if (oTable.title != null && oTable.title != "")
- {
- oTable.title += "\n" + tips;
- }
- else
- {
- oTable.title = tips;
- }
- }
-
- oTable.style.width = parseInt(leftWidth) + oTdMiddleE.style.pixelWidth + parseInt(rightWidth);
- }
- /**
- *生成按钮的中间层
- *
- */
- function genMiddleDivE()
- {
- var sDiv = "<div style='overflow:hidden;width:100%;border-left:solid 0;border-right:solid 0;border-top:solid 1;border-bottom:solid 1'>";
- var oDiv1 = oDoc.createElement(sDiv);
- var oDiv2 = oDoc.createElement(sDiv);
- var oDiv3 = oDoc.createElement(sDiv);
-
- if (borderWidth1 == "1")
- {
- oDiv1.style.borderWidth = 0;
- oDiv2.style.borderWidth = 0;
- oDiv3.style.borderWidth = 0;
-
- oDiv3.style.height = parseInt(height - 2) + "px";
-
- oDiv1.style.lineHeight = parseInt(height - 2) + "px";
- oDiv2.style.lineHeight = parseInt(height - 2) + "px";
- oDiv3.style.lineHeight = parseInt(height - 2) + "px";
- }
- else if (borderWidth1 == "2")
- {
- oDiv1.style.borderTopWidth = 1;
- oDiv1.style.borderBottomWidth = 1;
- oDiv2.style.borderWidth = 0;
- oDiv3.style.borderWidth = 0;
-
- oDiv3.style.height = parseInt(height - 4) + "px";
-
- oDiv1.style.lineHeight = parseInt(height - 4) + "px";
- oDiv2.style.lineHeight = parseInt(height - 4) + "px";
- oDiv3.style.lineHeight = parseInt(height - 4) + "px";
- }
- else if (borderWidth1 == "3")
- {
- oDiv1.style.borderTopWidth = 1;
- oDiv1.style.borderBottomWidth = 1;
- oDiv2.style.borderTopWidth = 1;
- oDiv2.style.borderBottomWidth = 1;
- oDiv3.style.borderWidth = 0;
-
- oDiv3.style.height = parseInt(height - 6) + "px";
-
- oDiv1.style.lineHeight = parseInt(height - 4) + "px";
- oDiv2.style.lineHeight = parseInt(height - 6) + "px";
- oDiv3.style.lineHeight = parseInt(height - 6) + "px";
- }
- else if (borderWidth1 = "4")
- {
- oDiv3.style.height = parseInt(height - 6) + "px";
-
- oDiv1.style.lineHeight = parseInt(height - 4) + "px";
- oDiv2.style.lineHeight = parseInt(height - 6) + "px";
- oDiv3.style.lineHeight = parseInt(height - 8) + "px";
- }
-
- oDiv2.appendChild(oDiv3);
- oDiv1.appendChild(oDiv2);
- return oDiv1;
- }
- /**
- *生成按钮的标题
- *@caption:标题
- *@lastCharPos:最后一个显示字符的位置
- *@width:显示的宽度
- *
- */
- function generateCaption(caption,lastCharPos,width)
- {
-
- var oCaptionTable = oDoc.createElement(sTable);
- var oTrE = oCaptionTable.insertRow();
- var oTdLeftE = oTrE.insertCell();
- var oTdMiddleE = oTrE.insertCell();
- var oTdRightE = oTrE.insertCell();
- var oImg1 = oDoc.createElement("<img border=0>");
- var oImg2 = oDoc.createElement("<img border=0>");
-
- var iCellHeight = calcTdHeight();
- oTdLeftE.style.height = iCellHeight;
- oTdMiddleE.style.height = iCellHeight;
- oTdRightE.style.height = iCellHeight;
- oTdLeftE.style.paddingTop = 1;
- oTdRightE.style.paddingTop = 1;
-
- oImg1.src = sFunction_Btn_Dot1;
- oImg2.src = sFunction_Btn_Dot1;
-
- oTdLeftE.style.width = 1;
- oTdRightE.style.width = 1;
-
- oTdLeftE.appendChild(oImg1);
- oTdRightE.appendChild(oImg2);
-
- oTdMiddleE.style.width = width - 2;
-
- oTdMiddleE.style.fontFamily = fontFamily;
- oTdMiddleE.style.fontSize = fontSize;
- oTdMiddleE.align = "center";
- oTdMiddleE.verticalAlign = "middle";
-
- if (eval(haveZH) == true)
- {
- oTdMiddleE.style.paddingTop = 1;
- }
-
- if (eval(disable) == true)
- {
- oTdMiddleE.style.color = disableFontColor;
- }
- else
- {
- oTdMiddleE.style.color = initFontColor;
- }
-
- if (caption.length > lastCharPos + 1)
- {
- oTdMiddleE.innerText = caption.substring(0,lastCharPos) + "…";
- oCaptionTable.tips = caption;
- }
- else
- {
- oTdMiddleE.innerText = caption;
- }
- return oCaptionTable;
- }
- /**
- *根据边框的宽度(borderWidth)计算最内层单元格的高度
- *
- */
- function calcTdHeight()
- {
- var iCellHeight = 0;
- var iPxIndex = height.indexOf("px");
- if (iPxIndex != -1)
- {
- height = height.substring(0,iPxIndex);
- }
- iCellHeight = parseInt(height - borderWidth1 * 2);
- return iCellHeight;
- }
- /**
- *根据状态更新显示
- *@status 1:初始;2:激活;3:滑过;4:点击;5:禁止状态
- *
- */
-
- function updateProperty(status)
- {
- var oDivE = null;
- switch(status)
- {
- case 1:
- {
- setProperty(sFunction_Btn_Left1,sFunction_Btn_Right1,aInitColor);
- break;
- }
- case 2:
- {
- setProperty(sFunction_Btn_Left2,sFunction_Btn_Right2,aActiveColor);
- break;
- }
- case 3:
- {
- setProperty(sFunction_Btn_Left3,sFunction_Btn_Right3,aMoveColor);
- oDivE = element.children(0).rows(0).cells(1).children(0).children(0).children(0);
- oDivE.style.paddingTop = "";
- break;
- }
- case 4:
- {
- setProperty(sFunction_Btn_Left4,sFunction_Btn_Right4,aClickColor);
- oDivE = element.children(0).rows(0).cells(1).children(0).children(0).children(0);
- oDivE.style.paddingTop = 1;
- break;
- }
- case 5:
- {
- setProperty(sFunction_Btn_Left5,sFunction_Btn_Right5,aDisableColor);
- break;
- }
- default:
- break;
- }
- }
- /**
- *设置属性
- *@leftImg:左边的图片
- *@rightImg:右边的图片
- *@aColor:为中间各个颜色的数组(9个颜色值)
- *
- */
- function setProperty(leftImg,rightImg,aColor)
- {
- var oTable = element.children(0);
- var oLeftImgE = oTable.rows(0).cells(0).children(0);
- var oRightImgE = oTable.rows(0).cells(2).children(0);
- var oTdE = oTable.rows(0).cells(1);
-
- oLeftImgE.src = leftImg;
- oRightImgE.src = rightImg;
- //注意中间的单元格分了层(每层的上下边框颜色不一样)
- oTdE.style.borderTopColor = aColor[0];
- oTdE.children(0).style.borderTopColor = aColor[1];
- oTdE.children(0).children(0).style.borderTopColor = aColor[2];
- oTdE.children(0).children(0).children(0).style.borderTopColor = aColor[3];
- oTdE.children(0).children(0).children(0).style.backgroundColor = aColor[4];
- oTdE.children(0).children(0).children(0).style.borderBottomColor = aColor[5];
- oTdE.children(0).children(0).style.borderBottomColor = aColor[6];
- oTdE.children(0).style.borderBottomColor = aColor[7];
- oTdE.style.borderBottomColor = aColor[8];
- }
- /**
- *初始化设置css
- *
- */
- function initCss()
- {
- var oStyle = element.currentStyle;
-
- if (oStyle.leftWidth != null)
- {
- leftWidth = oStyle.leftWidth;
- }
-
- if (oStyle.rightWidth != null)
- {
- rightWidth = oStyle.rightWidth;
- }
-
- if (oStyle.height != null && oStyle.height != "auto")
- {
- height = oStyle.height;
- }
-
- if (oStyle.borderWidth1 != null)
- {
- borderWidth1 = oStyle.borderWidth1;
- }
-
- if (oStyle.function_btn_left1 != null)
- {
- sFunction_Btn_Left1 = cssPath + oStyle.function_btn_left1;
- }
- else
- {
- sFunction_Btn_Left1 = imagePath + "function_btn_left1.gif";
- }
-
- if (oStyle.function_btn_left2 != null)
- {
- sFunction_Btn_Left2 = cssPath + oStyle.function_btn_left2;
- }
- else
- {
- sFunction_Btn_Left2 = imagePath + "function_btn_left2.gif";
- }
-
- if (oStyle.function_btn_left3 != null)
- {
- sFunction_Btn_Left3 = cssPath + oStyle.function_btn_left3;
- }
- else
- {
- sFunction_Btn_Left3 = imagePath + "function_btn_left3.gif";
- }
-
- if (oStyle.function_btn_left4 != null)
- {
- sFunction_Btn_Left4 = cssPath + oStyle.function_btn_left4;
- }
- else
- {
- sFunction_Btn_Left4 = imagePath + "function_btn_left4.gif";
- }
-
- if (oStyle.function_btn_left5 != null)
- {
- sFunction_Btn_Left5 = cssPath + oStyle.function_btn_left5;
- }
- else
- {
- sFunction_Btn_Left5 = imagePath + "function_btn_left5.gif";
- }
-
- if (oStyle.function_btn_right1 != null)
- {
- sFunction_Btn_Right1 = cssPath + oStyle.function_btn_right1;
- }
- else
- {
- sFunction_Btn_Right1 = imagePath + "function_btn_right1.gif";
- }
-
- if (oStyle.function_btn_right2 != null)
- {
- sFunction_Btn_Right2 = cssPath + oStyle.function_btn_right2;
- }
- else
- {
- sFunction_Btn_Right2 = imagePath + "function_btn_right2.gif";
- }
-
- if (oStyle.function_btn_right3 != null)
- {
- sFunction_Btn_Right3 = cssPath + oStyle.function_btn_right3;
- }
- else
- {
- sFunction_Btn_Right3 = imagePath + "function_btn_right3.gif";
- }
-
- if (oStyle.function_btn_right4 != null)
- {
- sFunction_Btn_Right4 = cssPath + oStyle.function_btn_right4;
- }
- else
- {
- sFunction_Btn_Right4 = imagePath + "function_btn_right4.gif";
- }
-
- if (oStyle.function_btn_right5 != null)
- {
- sFunction_Btn_Right5 = cssPath + oStyle.function_btn_right5;
- }
- else
- {
- sFunction_Btn_Right5 = imagePath + "function_btn_right5.gif";
- }
-
- if (oStyle.function_btn_dot != null)
- {
- sFunction_Btn_dot = cssPath + oStyle.function_btn_dot;
- }
- else
- {
- sFunction_Btn_Dot = imagePath + "function_btn_dot.gif";
- }
-
- if (oStyle.function_btn_dot1 != null)
- {
- sFunction_Btn_dot1 = cssPath + oStyle.function_btn_dot1;
- }
- else
- {
- sFunction_Btn_Dot1 = imagePath + "function_btn_dot1.gif";
- }
-
- if (oStyle.initColor != null)
- {
- initColor = oStyle.initColor;
- }
-
- if (oStyle.activeColor != null)
- {
- activeColor = oStyle.activeColor;
- }
-
- if (oStyle.moveColor != null)
- {
- moveColor = oStyle.moveColor;
- }
-
- if (oStyle.clickColor != null)
- {
- clickColor = oStyle.clickColor;
- }
-
- if (oStyle.disableColor != null)
- {
- disableColor = oStyle.disableColor;
- }
- }
- /**
- *逗号隔开的颜色字符串转换成数组(属性)
- *
- */
- function strToArray()
- {
- aInitColor = initColor.split(",");
- aActiveColor = activeColor.split(",");
- aMoveColor = moveColor.split(",");
- aClickColor = clickColor.split(",");
- aDisableColor = disableColor.split(",");
- }
- function calcLabelWidth(tabCaption,fontSize)
- {
- //字体取出pt后得出的大小
- var iFontSize = 9;
- //单字节字符显示宽度
- var iSingleCharWidth = 0;
- //tabCaption的长度
- var iLength = 0;
- //计算出来的宽度
- var iWidth = 0;
- //最后让显示字符位置
- var iLastCharPos = -1;
- //返回的对象
- var oReturnValue = new Object();
- //数字串间隔稍微需要+1
- var sNumber = "0123456789";
- //字符宽度
- var iCharWidth = 0;
-
- if (tabCaption == null)
- {
- tabCatpion = "";
- }
-
- if (fontSize == null)
- {
- fontSize == "9pt";
- }
- var iFontSize = parseInt(fontSize.substring(0,fontSize.indexOf("pt")));
-
- switch(iFontSize)
- {
- case 8:
- iSingleCharWidth = 5;
- break;
- case 9:
- iSingleCharWidth = 6;
- break;
- case 10:
- iSingleCharWidth = 7;
- break;
- case 11:
- case 12:
- iSingleCharWidth = 8;
- break;
- case 13:
- iSingleCharWidth = 9;
- break;
- case 14:
- case 15:
- iSingleCharWidth = 10;
- break;
- case 16:
- iSingleCharWidth = 11;
- break;
- default:
- iSingleCharWidth = 6;
- break;
- }
-
- iLength = tabCaption.length;
-
- for (var i = 0; i < iLength; i ++)
- {
- //是双字节字符
- if (/[^\x00-\xff]/g.test(tabCaption.substring(i,i + 1)))
- {
- iWidth += iSingleCharWidth * 2;
- }
- //数字
- else if (sNumber.indexOf(tabCaption.substring(i,i + 1)) != -1)
- {
- iWidth += iSingleCharWidth + 3;
- }
- else
- {
- iWidth += iSingleCharWidth;
- }
- //要计算是否超过最大宽度
- if (iWidth > 121)
- {
- iWidth = 121;
- iLastCharPos = i - 1;
- break;
- }
- iLastCharPos = i;
- }
-
- iCharWidth = iWidth + 8;
-
- if (iWidth < 45)
- {
- iWidth = 45;
- iLastCharPos = iLength;
- }
-
- oReturnValue.lastCharPos = iLastCharPos;
- oReturnValue.width = iWidth;
- oReturnValue.charWidth = iCharWidth;
- return oReturnValue;
- }
- /**
- *绑定各种事件
- *
- */
- function doEvent(oTable)
- {
- oTable.onmousedown = doMouseDown;
- oTable.onmouseup = doMouseUp;
- oTable.onmouseover = doMouseOver;
- oTable.onmouseout = doMouseOut;
- oTable.onmousemove = doMouseMove;
- oTable.onkeydown = doKeyDown;
- oTable.onkeypress = doKeyPress;
- oTable.onkeyup = doKeyUp;
- oTable.onselectstart = doSelectStart;
- oTable.onclick = doClick;
- oTable.ondblclick = doDblClick;
- oTable.onactivate = doActivate;
- oTable.ondeactivate = doDeactivate;
- oTable.oncontextmenu = doContextMenu;
-
- oTable.attachEvent("onfocus",function(){doFocus(oTable)});
- oTable.attachEvent("onblur",function(){doBlur(oTable)});
- }
- /**
- *屏蔽右键菜单
- *
- */
- function doContextMenu()
- {
- event.cancelBubble = true;
- event.returnValue = false;
- return false;
- }
- /**
- *激活状态
- *
- */
- function doActivate()
- {
- bActive = true;
- }
- /**
- *去激活状态
- *
- */
- function doDeactivate()
- {
- bActive = false;
- }
- /**
- *处理mousedown事件
- *
- */
- function doMouseDown()
- {
- if (eval(disable) == true)
- {
- return;
- }
-
- bMouseDown = true;
- updateProperty(4);
-
- var oTable = this.rows(0).cells(1).children(0).children(0).children(0).children(0);
- oTable.rows(0).cells(0).children(0).src = sFunction_Btn_Dot;
- oTable.rows(0).cells(2).children(0).src = sFunction_Btn_Dot;
- var evt = oDoc.createEventObject(event);
- evtMouseDown.fire(evt);
- }
- /**
- *处理mouseup事件
- *
- */
- function doMouseUp()
- {
- if (eval(disable) == true)
- {
- return;
- }
-
- bMouseDown = true;
-
- updateProperty(3);
-
- element.children(0).children(1).focus();
- var evt = oDoc.createEventObject(event);
- evtMouseUp.fire(evt);
- }
- /**
- *处理mouseover事件
- *
- */
- function doMouseOver()
- {
- if (eval(disable) == true)
- {
- return;
- }
-
- //注意处理td-->tr-->table事件传递的处理
- if (this.isOver == true)
- {
- return;
- }
-
- var evt = oDoc.createEventObject(event);
- updateProperty(3);
- evtMouseOver.fire(evt);
- this.isOver = true;
- }
- /**
- *处理mouseout事件
- *
- */
- function doMouseOut()
- {
- if (eval(disable) == true)
- {
- return;
- }
-
- var src = oDoc.elementFromPoint(event.clientX,event.clientY);
-
- if (src == null)
- {
- if (this != null)
- {
- this.isOver = false;
- }
- return;
- }
-
- while (src.tagName != "BODY")
- {
- if (src.parentElement == this)
- {
- return;
- }
- src = src.parentElement;
- }
-
- if (bActive == false)
- {
- updateProperty(1);
- }
- else
- {
- updateProperty(2);
- }
-
- this.isOver = false;
- var evt = oDoc.createEventObject(event);
- evtMouseOut.fire(evt);
- }
- /**
- *处理mousemove事件
- *
- */
- function doMouseMove()
- {
- if (eval(disable) == true)
- {
- return;
- }
-
- var evt = oDoc.createEventObject(event);
- evtMouseMove.fire(evt);
- }
- /**
- *处理keyDown事件
- *
- */
- function doKeyDown()
- {
- if (eval(disable) == true)
- {
- return;
- }
-
- var evt = oDoc.createEventObject(event);
- if (event.keyCode == 13)
- {
- evtClick.fire(evt);
- }
- evtKeyDown.fire(evt);
- }
- /**
- *处理keyPress事件
- *
- */
- function doKeyPress()
- {
- if (eval(disable) == true)
- {
- return;
- }
- var evt = oDoc.createEventObject(event);
- evtKeyPress.fire(evt);
- }
- /**
- *处理keyUp事件
- *
- */
- function doKeyUp()
- {
- if (eval(disable) == true)
- {
- return;
- }
- var evt = oDoc.createEventObject(event);
- evtKeyUp.fire(evt);
- }
- /**
- *处理selectStart事件
- *
- */
- function doSelectStart()
- {
- return false;
- }
- /**
- *处理click事件
- *
- */
- function doClick()
- {
- if (eval(disable) == true)
- {
- return;
- }
- var evt = oDoc.createEventObject(event);
- evtClick.fire(evt);
- }
- /**
- *处理dblclick事件
- *
- */
- function doDblClick()
- {
- if (eval(disable) == true)
- {
- return;
- }
- var evt = oDoc.createEventObject(event);
- evtDblClick.fire(evt);
- }
- /**
- *处理selectStart事件
- *
- */
- function doFocus(src)
- {
- if (eval(disable) == true)
- {
- return;
- }
- if (src == null)
- {
- src = src;
- }
- var evt = oDoc.createEventObject(event);
- updateProperty(2);
-
- var oTable = src.rows(0).cells(1).children(0).children(0).children(0).children(0);
- oTable.rows(0).cells(0).children(0).src = sFunction_Btn_Dot;
- oTable.rows(0).cells(2).children(0).src = sFunction_Btn_Dot;
- evtFocus.fire(evt);
- }
- /**
- *处理selectStart事件
- *
- */
- function doBlur(src)
- {
- if (eval(disable) == true)
- {
- return;
- }
-
- if (src == null)
- {
- src = src;
- }
-
- var evt = oDoc.createEventObject(event);
- updateProperty(1);
-
- var oTable = src.rows(0).cells(1).children(0).children(0).children(0).children(0);
- oTable.rows(0).cells(0).children(0).src = sFunction_Btn_Dot1;
- oTable.rows(0).cells(2).children(0).src = sFunction_Btn_Dot1;
- evtBlur.fire(evt);
- }
- /**
- *焦点函数
- *
- */
- function focus()
- {
- element.children(0).children(1).focus();
- }
- /**
- *点击函数
- *
- */
- function click()
- {
- if (eval(disable) == true)
- {
- return;
- }
- var evt = oDoc.createEventObject(event);
- evtClick.fire(evt);
- }
- /**
- *由于button的长度是计算出来的,所以不能直接应用width
- *
- */
- function getWidth()
- {
- return element.children(0).style.pixelWidth;
- }
- </script>
- </public:component>
|