KDButton.htc 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  1. <!--/******************************************************************
  2. ** 文件名: KDButton.htc
  3. ** Copyright (c) 2005 金蝶国际软件集团有限公司 研发中心
  4. ** http://www.kingdee.com
  5. **
  6. ** 创建人: 叶汉良
  7. ** 日 期: 2005.07.20
  8. **
  9. ** 描述:按钮控件
  10. ** 版 本:Web V1.0
  11. ******************************************************************/-->
  12. <public:component tagName="KDButton" lightWeight=true>
  13. <public:attach event="oncontentready" onevent="kdButtonReady()"/>
  14. <public:attach event="onpropertychange" onevent="kdButtonPropertyChange()"/>
  15. <public:event name="onEvtClick" id = "evtClick"/>
  16. <public:event name="onEvtDblClick" id = "evtDblClick"/>
  17. <public:event name="onEvtMouseDown" id = "evtMouseDown"/>
  18. <public:event name="onEvtMouseUp" id = "evtMouseUp"/>
  19. <public:event name="onEvtMouseOver" id = "evtMouseOver"/>
  20. <public:event name="onEvtMouseOut" id = "evtMouseOut"/>
  21. <public:event name="onEvtMouseMove" id = "evtMouseMove"/>
  22. <public:event name="onEvtKeyDown" id = "evtKeyDown"/>
  23. <public:event name="onEvtKeyPress" id = "evtKeyPress"/>
  24. <public:event name="onEvtKeyUp" id = "evtKeyUp"/>
  25. <public:event name="onEvtFocus" id = "evtFocus"/>
  26. <public:event name="onEvtBlur" id = "evtBlur"/>
  27. <public:property name="imagePath" value="../images/"/>
  28. <public:property name="cssPath" value=""/>
  29. <public:property name="width" value="73"/>
  30. <public:property name="height" value="21"/>
  31. <public:property name="caption" value="Button"/>
  32. <public:property name="fontFamily" value="arial"/>
  33. <public:property name="fontSize" value="9pt"/>
  34. <public:property name="initFontColor" value="#000000"/>
  35. <public:property name="activeFontColor" value="#000000"/>
  36. <public:property name="moveFontColor" value="#000000"/>
  37. <public:property name="clickFontColor" value="#000000"/>
  38. <public:property name="disableFontColor" value="#6E6E6E"/>
  39. <public:property name="disable" value="false"/>
  40. <public:property name="name" value=""/>
  41. <public:property name="value" value=""/>
  42. <public:property name="id" value=""/>
  43. <public:property name="tabIndex1" value=""/>
  44. <public:property name="tips" value=""/>
  45. <public:property name="leftWidth" value="10"/>
  46. <public:property name="rightWidth" value="10"/>
  47. <public:property name="haveZH" value="true"/>
  48. <public:property name="initColor" value="#85A7CF,#B7CCE5,#FFFFFF,#EEEEEE,#EEEEEE,#E4E4E4,#D5D5D5,#4174BA,#4174BA"/>
  49. <public:property name="activeColor" value="#60A4F7,#A2CFFB,#FEFEFF,#F9F9F9,#EEEEEE,#E4E4E4,#D5D5D5,#0052C9,#0052C9"/>
  50. <public:property name="moveColor" value="#FFB368,#FFCC9F,#FEFEFF,#F9F9F9,#EEEEEE,#E4E4E4,#D5D5D5,#C96C00,#C96C00"/>
  51. <public:property name="clickColor" value="#FFC759,#FFD69D,#FFBC34,#DDDDDD,#EEEEEE,#EEEEEE,#F9F9F9,#FEFEFF,#C98900"/>
  52. <public:property name="disableColor" value="#B2B2B2,#CFCFCF,#FEFEFE,#F9F9F9,#EEEEEE,#E4E4E4,#D5D5D5,#646464,#646464"/>
  53. <public:property name="cursor" value="hand"/>
  54. <public:property name="borderWidth1" value="4"/>
  55. <public:method name="focus"/>
  56. <public:method name="click"/>
  57. <public:method name="getWidth"/>
  58. <script language="Javascript">
  59. var sFunction_Btn_Left1 = "";
  60. var sFunction_Btn_Left2 = "";
  61. var sFunction_Btn_Left3 = "";
  62. var sFunction_Btn_Left4 = "";
  63. var sFunction_Btn_Left5 = "";
  64. var sFunction_Btn_Right1 = "";
  65. var sFunction_Btn_Right2 = "";
  66. var sFunction_Btn_Right3 = "";
  67. var sFunction_Btn_Right4 = "";
  68. var sFunction_Btn_Right5 = "";
  69. var sFunction_Btn_Dot = "";
  70. var sFunction_Btn_Dot1 = "";
  71. var sTable = "<table cellspacing=0 cellpadding=0 border=0 style='table-layout:fixed;display:inline;'></table>";
  72. //鼠标已经按下
  73. var bMouseDown = false;
  74. //是否已经激活
  75. var bActive = false;
  76. //文档
  77. var oDoc = window.document;
  78. var aInitColor = new Array();
  79. var aActiveColor = new Array();
  80. var aMoveColor = new Array();
  81. var aClickColor = new Array();
  82. var aDisableColor = new Array();
  83. /**
  84. *控件初始化
  85. *
  86. */
  87. function kdButtonReady()
  88. {
  89. initCss();
  90. strToArray();
  91. oButtonE = oDoc.createElement("<input type='button' style='display:inline;width:0;height:0;'>");
  92. element.innerHTML = sTable;
  93. oTableE = element.children(0);
  94. oTableE.appendChild(oButtonE);
  95. oButtonE.name = name;
  96. oButtonE.value = value;
  97. oButtonE.id = id;
  98. oButtonE.tabIndex = tabIndex1;
  99. oButtonE.disabled = eval(disable);
  100. initTable(oTableE);
  101. //绑定事件
  102. oButtonE.onfocus = doButtonFocus;
  103. oButtonE.onblur = doButtonBlur;
  104. doEvent(oTableE);
  105. }
  106. /**
  107. *控件属性值发生变化的时候处理事件
  108. *
  109. */
  110. function kdButtonPropertyChange()
  111. {
  112. switch(event.propertyName.toString().toLowerCase())
  113. {
  114. case "disable":
  115. {
  116. var oDivE = element.children(0).rows(0).cells(1).children(0).children(0).children(0);
  117. if (eval(disable) == true)
  118. {
  119. element.children(0).style.cursor = "default";
  120. updateProperty(5);
  121. oDivE.children(0).rows(0).cells(1).style.color = disableFontColor;
  122. }
  123. else
  124. {
  125. element.children(0).style.cursor = cursor;
  126. updateProperty(1);
  127. oDivE.children(0).rows(0).cells(1).style.color = initFontColor;
  128. }
  129. element.children(0).children(1).disabled = eval(disable);
  130. break;
  131. }
  132. case "caption":
  133. {
  134. break;
  135. }
  136. default:
  137. break;
  138. }
  139. }
  140. /**
  141. *处理按钮的focus事件
  142. *
  143. */
  144. function doButtonFocus()
  145. {
  146. if (bMouseDown == false)
  147. {
  148. doFocus(element.children(0));
  149. }
  150. bMouseDown = false;
  151. }
  152. /**
  153. *处理按钮的focus事件
  154. *
  155. */
  156. function doButtonBlur()
  157. {
  158. if (bMouseDown == false)
  159. {
  160. doBlur(element.children(0));
  161. }
  162. bMouseDown = false;
  163. }
  164. /**
  165. *初始化设置相关的属性
  166. *
  167. */
  168. function initTable(oTable)
  169. {
  170. oTable.style.height = height;
  171. var oTrE = oTable.insertRow();
  172. var oTdLeftE = oTrE.insertCell();
  173. var oTdMiddleE = oTrE.insertCell();
  174. var oTdRightE = oTrE.insertCell();
  175. var oLeftImgE = oDoc.createElement("<img border=0>");
  176. var oRightImgE = oDoc.createElement("<img border=0>");
  177. oTdLeftE.style.height = height;
  178. oTdLeftE.style.width = leftWidth;
  179. oTdRightE.style.height = height;
  180. oTdRightE.style.width = rightWidth;
  181. oTdLeftE.appendChild(oLeftImgE);
  182. oTdRightE.appendChild(oRightImgE);
  183. oTdMiddleE.style.borderTopWidth = 1;
  184. oTdMiddleE.style.borderTopStyle = "solid";
  185. oTdMiddleE.style.borderBottomWidth = 1;
  186. oTdMiddleE.style.borderBottomStyle = "solid";
  187. oTdMiddleE.style.height = height;
  188. oTdMiddleE.align = "center";
  189. oTdMiddleE.verticalAlign = "middle";
  190. var oReturnValue = calcLabelWidth(caption,fontSize);
  191. oTdMiddleE.style.width = oReturnValue.width + 8;
  192. oTdMiddleE.style.wordBreak = "keep-all";
  193. var oTempTable = generateCaption(caption,oReturnValue.lastCharPos,oReturnValue.charWidth);
  194. var oDivE = genMiddleDivE();
  195. oTdMiddleE.appendChild(oDivE);
  196. oDivE.children(0).children(0).appendChild(oTempTable);
  197. if (eval(disable) == true)
  198. {
  199. oTable.style.cursor = "default";
  200. updateProperty(5);
  201. }
  202. else
  203. {
  204. oTable.style.cursor = cursor;
  205. updateProperty(1);
  206. }
  207. if (oTempTable.tips != null)
  208. {
  209. oTable.title = oTempTable.tips;
  210. }
  211. if (tips != null && tips != "")
  212. {
  213. if (oTable.title != null && oTable.title != "")
  214. {
  215. oTable.title += "\n" + tips;
  216. }
  217. else
  218. {
  219. oTable.title = tips;
  220. }
  221. }
  222. oTable.style.width = parseInt(leftWidth) + oTdMiddleE.style.pixelWidth + parseInt(rightWidth);
  223. }
  224. /**
  225. *生成按钮的中间层
  226. *
  227. */
  228. function genMiddleDivE()
  229. {
  230. var sDiv = "<div style='overflow:hidden;width:100%;border-left:solid 0;border-right:solid 0;border-top:solid 1;border-bottom:solid 1'>";
  231. var oDiv1 = oDoc.createElement(sDiv);
  232. var oDiv2 = oDoc.createElement(sDiv);
  233. var oDiv3 = oDoc.createElement(sDiv);
  234. if (borderWidth1 == "1")
  235. {
  236. oDiv1.style.borderWidth = 0;
  237. oDiv2.style.borderWidth = 0;
  238. oDiv3.style.borderWidth = 0;
  239. oDiv3.style.height = parseInt(height - 2) + "px";
  240. oDiv1.style.lineHeight = parseInt(height - 2) + "px";
  241. oDiv2.style.lineHeight = parseInt(height - 2) + "px";
  242. oDiv3.style.lineHeight = parseInt(height - 2) + "px";
  243. }
  244. else if (borderWidth1 == "2")
  245. {
  246. oDiv1.style.borderTopWidth = 1;
  247. oDiv1.style.borderBottomWidth = 1;
  248. oDiv2.style.borderWidth = 0;
  249. oDiv3.style.borderWidth = 0;
  250. oDiv3.style.height = parseInt(height - 4) + "px";
  251. oDiv1.style.lineHeight = parseInt(height - 4) + "px";
  252. oDiv2.style.lineHeight = parseInt(height - 4) + "px";
  253. oDiv3.style.lineHeight = parseInt(height - 4) + "px";
  254. }
  255. else if (borderWidth1 == "3")
  256. {
  257. oDiv1.style.borderTopWidth = 1;
  258. oDiv1.style.borderBottomWidth = 1;
  259. oDiv2.style.borderTopWidth = 1;
  260. oDiv2.style.borderBottomWidth = 1;
  261. oDiv3.style.borderWidth = 0;
  262. oDiv3.style.height = parseInt(height - 6) + "px";
  263. oDiv1.style.lineHeight = parseInt(height - 4) + "px";
  264. oDiv2.style.lineHeight = parseInt(height - 6) + "px";
  265. oDiv3.style.lineHeight = parseInt(height - 6) + "px";
  266. }
  267. else if (borderWidth1 = "4")
  268. {
  269. oDiv3.style.height = parseInt(height - 6) + "px";
  270. oDiv1.style.lineHeight = parseInt(height - 4) + "px";
  271. oDiv2.style.lineHeight = parseInt(height - 6) + "px";
  272. oDiv3.style.lineHeight = parseInt(height - 8) + "px";
  273. }
  274. oDiv2.appendChild(oDiv3);
  275. oDiv1.appendChild(oDiv2);
  276. return oDiv1;
  277. }
  278. /**
  279. *生成按钮的标题
  280. *@caption:标题
  281. *@lastCharPos:最后一个显示字符的位置
  282. *@width:显示的宽度
  283. *
  284. */
  285. function generateCaption(caption,lastCharPos,width)
  286. {
  287. var oCaptionTable = oDoc.createElement(sTable);
  288. var oTrE = oCaptionTable.insertRow();
  289. var oTdLeftE = oTrE.insertCell();
  290. var oTdMiddleE = oTrE.insertCell();
  291. var oTdRightE = oTrE.insertCell();
  292. var oImg1 = oDoc.createElement("<img border=0>");
  293. var oImg2 = oDoc.createElement("<img border=0>");
  294. var iCellHeight = calcTdHeight();
  295. oTdLeftE.style.height = iCellHeight;
  296. oTdMiddleE.style.height = iCellHeight;
  297. oTdRightE.style.height = iCellHeight;
  298. oTdLeftE.style.paddingTop = 1;
  299. oTdRightE.style.paddingTop = 1;
  300. oImg1.src = sFunction_Btn_Dot1;
  301. oImg2.src = sFunction_Btn_Dot1;
  302. oTdLeftE.style.width = 1;
  303. oTdRightE.style.width = 1;
  304. oTdLeftE.appendChild(oImg1);
  305. oTdRightE.appendChild(oImg2);
  306. oTdMiddleE.style.width = width - 2;
  307. oTdMiddleE.style.fontFamily = fontFamily;
  308. oTdMiddleE.style.fontSize = fontSize;
  309. oTdMiddleE.align = "center";
  310. oTdMiddleE.verticalAlign = "middle";
  311. if (eval(haveZH) == true)
  312. {
  313. oTdMiddleE.style.paddingTop = 1;
  314. }
  315. if (eval(disable) == true)
  316. {
  317. oTdMiddleE.style.color = disableFontColor;
  318. }
  319. else
  320. {
  321. oTdMiddleE.style.color = initFontColor;
  322. }
  323. if (caption.length > lastCharPos + 1)
  324. {
  325. oTdMiddleE.innerText = caption.substring(0,lastCharPos) + "…";
  326. oCaptionTable.tips = caption;
  327. }
  328. else
  329. {
  330. oTdMiddleE.innerText = caption;
  331. }
  332. return oCaptionTable;
  333. }
  334. /**
  335. *根据边框的宽度(borderWidth)计算最内层单元格的高度
  336. *
  337. */
  338. function calcTdHeight()
  339. {
  340. var iCellHeight = 0;
  341. var iPxIndex = height.indexOf("px");
  342. if (iPxIndex != -1)
  343. {
  344. height = height.substring(0,iPxIndex);
  345. }
  346. iCellHeight = parseInt(height - borderWidth1 * 2);
  347. return iCellHeight;
  348. }
  349. /**
  350. *根据状态更新显示
  351. *@status 1:初始;2:激活;3:滑过;4:点击;5:禁止状态
  352. *
  353. */
  354. function updateProperty(status)
  355. {
  356. var oDivE = null;
  357. switch(status)
  358. {
  359. case 1:
  360. {
  361. setProperty(sFunction_Btn_Left1,sFunction_Btn_Right1,aInitColor);
  362. break;
  363. }
  364. case 2:
  365. {
  366. setProperty(sFunction_Btn_Left2,sFunction_Btn_Right2,aActiveColor);
  367. break;
  368. }
  369. case 3:
  370. {
  371. setProperty(sFunction_Btn_Left3,sFunction_Btn_Right3,aMoveColor);
  372. oDivE = element.children(0).rows(0).cells(1).children(0).children(0).children(0);
  373. oDivE.style.paddingTop = "";
  374. break;
  375. }
  376. case 4:
  377. {
  378. setProperty(sFunction_Btn_Left4,sFunction_Btn_Right4,aClickColor);
  379. oDivE = element.children(0).rows(0).cells(1).children(0).children(0).children(0);
  380. oDivE.style.paddingTop = 1;
  381. break;
  382. }
  383. case 5:
  384. {
  385. setProperty(sFunction_Btn_Left5,sFunction_Btn_Right5,aDisableColor);
  386. break;
  387. }
  388. default:
  389. break;
  390. }
  391. }
  392. /**
  393. *设置属性
  394. *@leftImg:左边的图片
  395. *@rightImg:右边的图片
  396. *@aColor:为中间各个颜色的数组(9个颜色值)
  397. *
  398. */
  399. function setProperty(leftImg,rightImg,aColor)
  400. {
  401. var oTable = element.children(0);
  402. var oLeftImgE = oTable.rows(0).cells(0).children(0);
  403. var oRightImgE = oTable.rows(0).cells(2).children(0);
  404. var oTdE = oTable.rows(0).cells(1);
  405. oLeftImgE.src = leftImg;
  406. oRightImgE.src = rightImg;
  407. //注意中间的单元格分了层(每层的上下边框颜色不一样)
  408. oTdE.style.borderTopColor = aColor[0];
  409. oTdE.children(0).style.borderTopColor = aColor[1];
  410. oTdE.children(0).children(0).style.borderTopColor = aColor[2];
  411. oTdE.children(0).children(0).children(0).style.borderTopColor = aColor[3];
  412. oTdE.children(0).children(0).children(0).style.backgroundColor = aColor[4];
  413. oTdE.children(0).children(0).children(0).style.borderBottomColor = aColor[5];
  414. oTdE.children(0).children(0).style.borderBottomColor = aColor[6];
  415. oTdE.children(0).style.borderBottomColor = aColor[7];
  416. oTdE.style.borderBottomColor = aColor[8];
  417. }
  418. /**
  419. *初始化设置css
  420. *
  421. */
  422. function initCss()
  423. {
  424. var oStyle = element.currentStyle;
  425. if (oStyle.leftWidth != null)
  426. {
  427. leftWidth = oStyle.leftWidth;
  428. }
  429. if (oStyle.rightWidth != null)
  430. {
  431. rightWidth = oStyle.rightWidth;
  432. }
  433. if (oStyle.height != null && oStyle.height != "auto")
  434. {
  435. height = oStyle.height;
  436. }
  437. if (oStyle.borderWidth1 != null)
  438. {
  439. borderWidth1 = oStyle.borderWidth1;
  440. }
  441. if (oStyle.function_btn_left1 != null)
  442. {
  443. sFunction_Btn_Left1 = cssPath + oStyle.function_btn_left1;
  444. }
  445. else
  446. {
  447. sFunction_Btn_Left1 = imagePath + "function_btn_left1.gif";
  448. }
  449. if (oStyle.function_btn_left2 != null)
  450. {
  451. sFunction_Btn_Left2 = cssPath + oStyle.function_btn_left2;
  452. }
  453. else
  454. {
  455. sFunction_Btn_Left2 = imagePath + "function_btn_left2.gif";
  456. }
  457. if (oStyle.function_btn_left3 != null)
  458. {
  459. sFunction_Btn_Left3 = cssPath + oStyle.function_btn_left3;
  460. }
  461. else
  462. {
  463. sFunction_Btn_Left3 = imagePath + "function_btn_left3.gif";
  464. }
  465. if (oStyle.function_btn_left4 != null)
  466. {
  467. sFunction_Btn_Left4 = cssPath + oStyle.function_btn_left4;
  468. }
  469. else
  470. {
  471. sFunction_Btn_Left4 = imagePath + "function_btn_left4.gif";
  472. }
  473. if (oStyle.function_btn_left5 != null)
  474. {
  475. sFunction_Btn_Left5 = cssPath + oStyle.function_btn_left5;
  476. }
  477. else
  478. {
  479. sFunction_Btn_Left5 = imagePath + "function_btn_left5.gif";
  480. }
  481. if (oStyle.function_btn_right1 != null)
  482. {
  483. sFunction_Btn_Right1 = cssPath + oStyle.function_btn_right1;
  484. }
  485. else
  486. {
  487. sFunction_Btn_Right1 = imagePath + "function_btn_right1.gif";
  488. }
  489. if (oStyle.function_btn_right2 != null)
  490. {
  491. sFunction_Btn_Right2 = cssPath + oStyle.function_btn_right2;
  492. }
  493. else
  494. {
  495. sFunction_Btn_Right2 = imagePath + "function_btn_right2.gif";
  496. }
  497. if (oStyle.function_btn_right3 != null)
  498. {
  499. sFunction_Btn_Right3 = cssPath + oStyle.function_btn_right3;
  500. }
  501. else
  502. {
  503. sFunction_Btn_Right3 = imagePath + "function_btn_right3.gif";
  504. }
  505. if (oStyle.function_btn_right4 != null)
  506. {
  507. sFunction_Btn_Right4 = cssPath + oStyle.function_btn_right4;
  508. }
  509. else
  510. {
  511. sFunction_Btn_Right4 = imagePath + "function_btn_right4.gif";
  512. }
  513. if (oStyle.function_btn_right5 != null)
  514. {
  515. sFunction_Btn_Right5 = cssPath + oStyle.function_btn_right5;
  516. }
  517. else
  518. {
  519. sFunction_Btn_Right5 = imagePath + "function_btn_right5.gif";
  520. }
  521. if (oStyle.function_btn_dot != null)
  522. {
  523. sFunction_Btn_dot = cssPath + oStyle.function_btn_dot;
  524. }
  525. else
  526. {
  527. sFunction_Btn_Dot = imagePath + "function_btn_dot.gif";
  528. }
  529. if (oStyle.function_btn_dot1 != null)
  530. {
  531. sFunction_Btn_dot1 = cssPath + oStyle.function_btn_dot1;
  532. }
  533. else
  534. {
  535. sFunction_Btn_Dot1 = imagePath + "function_btn_dot1.gif";
  536. }
  537. if (oStyle.initColor != null)
  538. {
  539. initColor = oStyle.initColor;
  540. }
  541. if (oStyle.activeColor != null)
  542. {
  543. activeColor = oStyle.activeColor;
  544. }
  545. if (oStyle.moveColor != null)
  546. {
  547. moveColor = oStyle.moveColor;
  548. }
  549. if (oStyle.clickColor != null)
  550. {
  551. clickColor = oStyle.clickColor;
  552. }
  553. if (oStyle.disableColor != null)
  554. {
  555. disableColor = oStyle.disableColor;
  556. }
  557. }
  558. /**
  559. *逗号隔开的颜色字符串转换成数组(属性)
  560. *
  561. */
  562. function strToArray()
  563. {
  564. aInitColor = initColor.split(",");
  565. aActiveColor = activeColor.split(",");
  566. aMoveColor = moveColor.split(",");
  567. aClickColor = clickColor.split(",");
  568. aDisableColor = disableColor.split(",");
  569. }
  570. function calcLabelWidth(tabCaption,fontSize)
  571. {
  572. //字体取出pt后得出的大小
  573. var iFontSize = 9;
  574. //单字节字符显示宽度
  575. var iSingleCharWidth = 0;
  576. //tabCaption的长度
  577. var iLength = 0;
  578. //计算出来的宽度
  579. var iWidth = 0;
  580. //最后让显示字符位置
  581. var iLastCharPos = -1;
  582. //返回的对象
  583. var oReturnValue = new Object();
  584. //数字串间隔稍微需要+1
  585. var sNumber = "0123456789";
  586. //字符宽度
  587. var iCharWidth = 0;
  588. if (tabCaption == null)
  589. {
  590. tabCatpion = "";
  591. }
  592. if (fontSize == null)
  593. {
  594. fontSize == "9pt";
  595. }
  596. var iFontSize = parseInt(fontSize.substring(0,fontSize.indexOf("pt")));
  597. switch(iFontSize)
  598. {
  599. case 8:
  600. iSingleCharWidth = 5;
  601. break;
  602. case 9:
  603. iSingleCharWidth = 6;
  604. break;
  605. case 10:
  606. iSingleCharWidth = 7;
  607. break;
  608. case 11:
  609. case 12:
  610. iSingleCharWidth = 8;
  611. break;
  612. case 13:
  613. iSingleCharWidth = 9;
  614. break;
  615. case 14:
  616. case 15:
  617. iSingleCharWidth = 10;
  618. break;
  619. case 16:
  620. iSingleCharWidth = 11;
  621. break;
  622. default:
  623. iSingleCharWidth = 6;
  624. break;
  625. }
  626. iLength = tabCaption.length;
  627. for (var i = 0; i < iLength; i ++)
  628. {
  629. //是双字节字符
  630. if (/[^\x00-\xff]/g.test(tabCaption.substring(i,i + 1)))
  631. {
  632. iWidth += iSingleCharWidth * 2;
  633. }
  634. //数字
  635. else if (sNumber.indexOf(tabCaption.substring(i,i + 1)) != -1)
  636. {
  637. iWidth += iSingleCharWidth + 3;
  638. }
  639. else
  640. {
  641. iWidth += iSingleCharWidth;
  642. }
  643. //要计算是否超过最大宽度
  644. if (iWidth > 121)
  645. {
  646. iWidth = 121;
  647. iLastCharPos = i - 1;
  648. break;
  649. }
  650. iLastCharPos = i;
  651. }
  652. iCharWidth = iWidth + 8;
  653. if (iWidth < 45)
  654. {
  655. iWidth = 45;
  656. iLastCharPos = iLength;
  657. }
  658. oReturnValue.lastCharPos = iLastCharPos;
  659. oReturnValue.width = iWidth;
  660. oReturnValue.charWidth = iCharWidth;
  661. return oReturnValue;
  662. }
  663. /**
  664. *绑定各种事件
  665. *
  666. */
  667. function doEvent(oTable)
  668. {
  669. oTable.onmousedown = doMouseDown;
  670. oTable.onmouseup = doMouseUp;
  671. oTable.onmouseover = doMouseOver;
  672. oTable.onmouseout = doMouseOut;
  673. oTable.onmousemove = doMouseMove;
  674. oTable.onkeydown = doKeyDown;
  675. oTable.onkeypress = doKeyPress;
  676. oTable.onkeyup = doKeyUp;
  677. oTable.onselectstart = doSelectStart;
  678. oTable.onclick = doClick;
  679. oTable.ondblclick = doDblClick;
  680. oTable.onactivate = doActivate;
  681. oTable.ondeactivate = doDeactivate;
  682. oTable.oncontextmenu = doContextMenu;
  683. oTable.attachEvent("onfocus",function(){doFocus(oTable)});
  684. oTable.attachEvent("onblur",function(){doBlur(oTable)});
  685. }
  686. /**
  687. *屏蔽右键菜单
  688. *
  689. */
  690. function doContextMenu()
  691. {
  692. event.cancelBubble = true;
  693. event.returnValue = false;
  694. return false;
  695. }
  696. /**
  697. *激活状态
  698. *
  699. */
  700. function doActivate()
  701. {
  702. bActive = true;
  703. }
  704. /**
  705. *去激活状态
  706. *
  707. */
  708. function doDeactivate()
  709. {
  710. bActive = false;
  711. }
  712. /**
  713. *处理mousedown事件
  714. *
  715. */
  716. function doMouseDown()
  717. {
  718. if (eval(disable) == true)
  719. {
  720. return;
  721. }
  722. bMouseDown = true;
  723. updateProperty(4);
  724. var oTable = this.rows(0).cells(1).children(0).children(0).children(0).children(0);
  725. oTable.rows(0).cells(0).children(0).src = sFunction_Btn_Dot;
  726. oTable.rows(0).cells(2).children(0).src = sFunction_Btn_Dot;
  727. var evt = oDoc.createEventObject(event);
  728. evtMouseDown.fire(evt);
  729. }
  730. /**
  731. *处理mouseup事件
  732. *
  733. */
  734. function doMouseUp()
  735. {
  736. if (eval(disable) == true)
  737. {
  738. return;
  739. }
  740. bMouseDown = true;
  741. updateProperty(3);
  742. element.children(0).children(1).focus();
  743. var evt = oDoc.createEventObject(event);
  744. evtMouseUp.fire(evt);
  745. }
  746. /**
  747. *处理mouseover事件
  748. *
  749. */
  750. function doMouseOver()
  751. {
  752. if (eval(disable) == true)
  753. {
  754. return;
  755. }
  756. //注意处理td-->tr-->table事件传递的处理
  757. if (this.isOver == true)
  758. {
  759. return;
  760. }
  761. var evt = oDoc.createEventObject(event);
  762. updateProperty(3);
  763. evtMouseOver.fire(evt);
  764. this.isOver = true;
  765. }
  766. /**
  767. *处理mouseout事件
  768. *
  769. */
  770. function doMouseOut()
  771. {
  772. if (eval(disable) == true)
  773. {
  774. return;
  775. }
  776. var src = oDoc.elementFromPoint(event.clientX,event.clientY);
  777. if (src == null)
  778. {
  779. if (this != null)
  780. {
  781. this.isOver = false;
  782. }
  783. return;
  784. }
  785. while (src.tagName != "BODY")
  786. {
  787. if (src.parentElement == this)
  788. {
  789. return;
  790. }
  791. src = src.parentElement;
  792. }
  793. if (bActive == false)
  794. {
  795. updateProperty(1);
  796. }
  797. else
  798. {
  799. updateProperty(2);
  800. }
  801. this.isOver = false;
  802. var evt = oDoc.createEventObject(event);
  803. evtMouseOut.fire(evt);
  804. }
  805. /**
  806. *处理mousemove事件
  807. *
  808. */
  809. function doMouseMove()
  810. {
  811. if (eval(disable) == true)
  812. {
  813. return;
  814. }
  815. var evt = oDoc.createEventObject(event);
  816. evtMouseMove.fire(evt);
  817. }
  818. /**
  819. *处理keyDown事件
  820. *
  821. */
  822. function doKeyDown()
  823. {
  824. if (eval(disable) == true)
  825. {
  826. return;
  827. }
  828. var evt = oDoc.createEventObject(event);
  829. if (event.keyCode == 13)
  830. {
  831. evtClick.fire(evt);
  832. }
  833. evtKeyDown.fire(evt);
  834. }
  835. /**
  836. *处理keyPress事件
  837. *
  838. */
  839. function doKeyPress()
  840. {
  841. if (eval(disable) == true)
  842. {
  843. return;
  844. }
  845. var evt = oDoc.createEventObject(event);
  846. evtKeyPress.fire(evt);
  847. }
  848. /**
  849. *处理keyUp事件
  850. *
  851. */
  852. function doKeyUp()
  853. {
  854. if (eval(disable) == true)
  855. {
  856. return;
  857. }
  858. var evt = oDoc.createEventObject(event);
  859. evtKeyUp.fire(evt);
  860. }
  861. /**
  862. *处理selectStart事件
  863. *
  864. */
  865. function doSelectStart()
  866. {
  867. return false;
  868. }
  869. /**
  870. *处理click事件
  871. *
  872. */
  873. function doClick()
  874. {
  875. if (eval(disable) == true)
  876. {
  877. return;
  878. }
  879. var evt = oDoc.createEventObject(event);
  880. evtClick.fire(evt);
  881. }
  882. /**
  883. *处理dblclick事件
  884. *
  885. */
  886. function doDblClick()
  887. {
  888. if (eval(disable) == true)
  889. {
  890. return;
  891. }
  892. var evt = oDoc.createEventObject(event);
  893. evtDblClick.fire(evt);
  894. }
  895. /**
  896. *处理selectStart事件
  897. *
  898. */
  899. function doFocus(src)
  900. {
  901. if (eval(disable) == true)
  902. {
  903. return;
  904. }
  905. if (src == null)
  906. {
  907. src = src;
  908. }
  909. var evt = oDoc.createEventObject(event);
  910. updateProperty(2);
  911. var oTable = src.rows(0).cells(1).children(0).children(0).children(0).children(0);
  912. oTable.rows(0).cells(0).children(0).src = sFunction_Btn_Dot;
  913. oTable.rows(0).cells(2).children(0).src = sFunction_Btn_Dot;
  914. evtFocus.fire(evt);
  915. }
  916. /**
  917. *处理selectStart事件
  918. *
  919. */
  920. function doBlur(src)
  921. {
  922. if (eval(disable) == true)
  923. {
  924. return;
  925. }
  926. if (src == null)
  927. {
  928. src = src;
  929. }
  930. var evt = oDoc.createEventObject(event);
  931. updateProperty(1);
  932. var oTable = src.rows(0).cells(1).children(0).children(0).children(0).children(0);
  933. oTable.rows(0).cells(0).children(0).src = sFunction_Btn_Dot1;
  934. oTable.rows(0).cells(2).children(0).src = sFunction_Btn_Dot1;
  935. evtBlur.fire(evt);
  936. }
  937. /**
  938. *焦点函数
  939. *
  940. */
  941. function focus()
  942. {
  943. element.children(0).children(1).focus();
  944. }
  945. /**
  946. *点击函数
  947. *
  948. */
  949. function click()
  950. {
  951. if (eval(disable) == true)
  952. {
  953. return;
  954. }
  955. var evt = oDoc.createEventObject(event);
  956. evtClick.fire(evt);
  957. }
  958. /**
  959. *由于button的长度是计算出来的,所以不能直接应用width
  960. *
  961. */
  962. function getWidth()
  963. {
  964. return element.children(0).style.pixelWidth;
  965. }
  966. </script>
  967. </public:component>