Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

348 lines
9.2 KiB

  1. <!-- ******************************************************** -->
  2. <!-- -->
  3. <!-- Copyright (c) 1999-2000 Microsoft Corporation -->
  4. <!-- -->
  5. <!-- scroll.htc -->
  6. <!-- -->
  7. <!-- Build Type : Free -->
  8. <!-- Build Number : 0707 -->
  9. <!-- Build Date : 07/07/2000 -->
  10. <!-- ******************************************************* -->
  11. <HTC>
  12. <PUBLIC:COMPONENT tagName="scrollBarBehaviour">
  13. <PUBLIC:PROPERTY NAME="value" />
  14. <PUBLIC:PROPERTY NAME="smallChange" />
  15. <PUBLIC:PROPERTY NAME="LargeChange" />
  16. <PUBLIC:PROPERTY NAME="Max" />
  17. <PUBLIC:PROPERTY NAME="Min" />
  18. <PUBLIC:PROPERTY NAME="Orientation" />
  19. <PUBLIC:PROPERTY NAME="Enabled" />
  20. <PUBLIC:METHOD NAME="handleMouseDown" />
  21. <PUBLIC:METHOD NAME="scrollLoop" />
  22. <PUBLIC:METHOD NAME="calcParams" />
  23. <PUBLIC:METHOD NAME="removeFocus" />
  24. <PUBLIC:EVENT NAME="onchange" ID=changeID />
  25. <PUBLIC:ATTACH EVENT="onreadystatechange" ONEVENT="scrollBarLoad()"/>
  26. <PUBLIC:ATTACH EVENT="onmousedown" ONEVENT="handleMouseDown()"/>
  27. <PUBLIC:ATTACH EVENT="onmousemove" FOR='document' ONEVENT="drag()"/>
  28. <PUBLIC:ATTACH EVENT="onmouseup" FOR='document' ONEVENT="handleMouseUp()"/>
  29. <PUBLIC:ATTACH EVENT="onresize" ONEVENT="resize()"/>
  30. <PUBLIC:ATTACH EVENT="onpropertychange" ONEVENT="propertyChangeHandler()"/>
  31. <PUBLIC:ATTACH EVENT="onkeydown" ONEVENT="keyPressHandler()"/>
  32. <SCRIPT LANGUAGE="jscript">
  33. var dragThumb=false;
  34. var myheight;
  35. var divMax = 0;
  36. var divMin = 0;
  37. var started;
  38. var smallChange = 1;
  39. var LargeChange = new Number(1);
  40. var jump;
  41. var value = new Number(0);
  42. var Max = 1;
  43. var Min = 0;
  44. var oldHeight=1;
  45. var fLoaded = false;
  46. var thumbToValue = 0;
  47. var thumbTop = 0;
  48. var scrollOn = false;
  49. var elementTop = 0;
  50. var direction;
  51. var change;
  52. var scrollAreaAvailable = 0;
  53. var largeJump = 0;
  54. var smallJump = 0;
  55. var oldValue = 0;
  56. var i = 0;
  57. var value = 0;
  58. var Enabled = false;
  59. function scrollBarLoad()
  60. {
  61. if(element.readyState != 'complete')
  62. return;
  63. str = '<DIV id="scrollArea" onmousedown="this.parentElement.removeFocus()" onmouseup="this.parentElement.removeFocus()" style="position:relative;background-color:silver;height:100%;width:100%">' +
  64. '<BUTTON style="margin:0;padding:0;position:absolute;top:0%;height:17" id="upper" onmousedown="this.parentElement.parentElement.removeFocus()" onmouseup="this.parentElement.parentElement.removeFocus()" onmousemove="this.parentElement.parentElement.removeFocus()"><IMG id="uppergif" src="images/up.gif" onmousedown="this.parentElement.parentElement.parentElement.removeFocus()" onmousemove="this.parentElement.parentElement.parentElement.removeFocus()" onmouseup="this.parentElement.parentElement.parentElement.removeFocus()"></IMG></BUTTON>' +
  65. '<BUTTON style="position:relative;top:18;width:100%" onmousedown="this.parentElement.parentElement.removeFocus()" onmousemove="this.parentElement.parentElement.removeFocus()" id="thumb"></BUTTON>' +
  66. '</DIV>' +
  67. '<BUTTON style="position:absolute;left:0;top:18;height:17" onmousedown="this.parentElement.removeFocus()" onmouseup="this.parentElement.removeFocus()" onmousemove="this.parentElement.removeFocus()" id="lower"><IMG id="lowergif" src="images/dwn.gif" onmousemove="this.parentElement.parentElement.removeFocus()" onmouseup="this.parentElement.parentElement.removeFocus()" onmousedown="this.parentElement.parentElement.removeFocus()" ></IMG></BUTTON>'
  68. element.innerHTML = str;
  69. lower.style.setExpression ("top", "scrollArea.style.pixelHeight-upper.style.pixelHeight") ;
  70. calcParams();
  71. thumbTop = thumb.offsetTop;
  72. value = 0;
  73. }
  74. function keyPressHandler()
  75. {
  76. if(Enabled == true)
  77. enterForDrillDown();
  78. }
  79. function propertyChangeHandler()
  80. {
  81. if(window.event.propertyName == 'value')
  82. {
  83. if(oldValue != value)
  84. {
  85. temp = (value/Max)*scrollAreaAvailable + upper.style.pixelHeight;
  86. if(!isNaN(temp))
  87. {
  88. thumb.style.posTop = Math.min(temp,divMax);
  89. thumbTop = thumb.offsetTop;
  90. fireChangeEvent();
  91. oldValue == value;
  92. }
  93. }
  94. }
  95. else if( ( window.event.propertyName == 'LargeChange') || (window.event.propertyName == 'Max') )
  96. {
  97. calcParams();
  98. }
  99. else if ( window.event.propertyName == 'Enabled')
  100. {
  101. if(Enabled == true)
  102. {
  103. lowergif.src = "images/dwn.gif";
  104. uppergif.src = "images/up.gif";
  105. lower.disabled = false;
  106. upper.disabled = false;
  107. thumb.style.display = '';
  108. if(value == 0)
  109. {
  110. thumb.style.posTop = upper.style.pixelHeight;
  111. thumbTop = thumb.offsetTop;
  112. }
  113. }
  114. else
  115. {
  116. lowergif.src = "images/dwngray.gif";
  117. uppergif.src = "images/upgray.gif";
  118. lower.disabled = true;
  119. upper.disabled = true;
  120. thumb.style.display = 'none';
  121. }
  122. }
  123. }
  124. function resize()
  125. {
  126. if(element.readyState != 'complete')
  127. return;
  128. document.recalc(true);
  129. calcParams()
  130. if(oldHeight != 1)
  131. {
  132. if ( thumb.offsetTop != upper.style.pixelHeight)
  133. {
  134. temp = thumb.offsetTop * (scrollAreaAvailable/oldHeight)+upper.style.pixelHeight;
  135. if (temp > divMax)
  136. temp = divMax;
  137. if (temp < divMin)
  138. temp = divMin;
  139. thumb.style.posTop = temp;
  140. thumbTop = thumb.offsetTop;
  141. }
  142. }
  143. oldHeight = scrollAreaAvailable;
  144. }
  145. function handleMouseDown()
  146. {
  147. if(divMax <= 0)
  148. calcParams();
  149. if(dragThumb == false)
  150. {
  151. if ( (window.event.srcElement.id == 'thumb') && (window.event.type == "mousedown") )
  152. {
  153. dragThumb = true;
  154. elementTop = element.offsetTop
  155. started = thumb.offsetTop;
  156. oldValue = value;
  157. }
  158. else
  159. {
  160. if(Enabled == true)
  161. {
  162. scrollOn = true;
  163. handleMouseOver();
  164. }
  165. }
  166. }
  167. else
  168. {
  169. dragThumb = false;
  170. }
  171. }
  172. function handleMouseOver()
  173. {
  174. if(scrollOn == false)
  175. return;
  176. if(divMax <= 0)
  177. calcParams();
  178. if(window.event.srcElement.id == 'upper')
  179. {
  180. scrollLoop('up',smallJump,smallChange);
  181. }
  182. else if (window.event.srcElement.id == 'lower')
  183. {
  184. scrollLoop('down',smallJump,smallChange);
  185. }
  186. else if(window.event.srcElement.id == 'scrollArea')
  187. {
  188. scrollArea.style.backgroundColor= "black";
  189. if(window.event.offsetY < thumb.offsetTop)
  190. {
  191. scrollLoop('up',largeJump,LargeChange);
  192. }
  193. else
  194. {
  195. if(window.event.offsetY > (thumb.offsetTop + thumb.style.pixelHeight))
  196. {
  197. scrollLoop('down',largeJump,LargeChange);
  198. }
  199. }
  200. scrollArea.style.backgroundColor= "silver";
  201. }
  202. }
  203. function scrollLoop(direction,jump,change)
  204. {
  205. oldValue = value;
  206. //alert(jump + ":" + change + ":" + thumbTop);
  207. if(direction == 'up')
  208. {
  209. thumbTop = Math.max(thumbTop - jump,divMin);
  210. value = Math.max(value - change,Min);
  211. }
  212. else
  213. {
  214. thumbTop = Math.min(thumbTop + jump,divMax);
  215. value = Math.min(value + change,Max - LargeChange);
  216. }
  217. thumb.style.posTop=Math.floor(thumbTop);
  218. if(value < 0 )
  219. value = 0;
  220. if(oldValue != value)
  221. {
  222. fireChangeEvent();
  223. oldValue = value;
  224. }
  225. // window.status = thumbTop;
  226. }
  227. function drag()
  228. {
  229. var newPos = window.event.clientY - elementTop - myheight;
  230. if(dragThumb==true)
  231. {
  232. if(newPos < divMin)
  233. {
  234. if(newPos < (divMin - 40))
  235. {
  236. thumb.style.posTop = started;
  237. thumbTop = started;
  238. dragThumb = false;
  239. }
  240. else
  241. {
  242. thumb.style.posTop = Math.max(newPos,divMin);
  243. }
  244. }
  245. else
  246. {
  247. if(newPos > (divMax + 40))
  248. {
  249. thumb.style.posTop = started;
  250. thumbTop = started;
  251. dragThumb = false;
  252. }
  253. else
  254. {
  255. thumb.style.posTop= Math.min(newPos,divMax);
  256. }
  257. }
  258. thumbTop = thumb.offsetTop;
  259. if( (thumbTop + thumb.style.pixelHeight) == (scrollAreaAvailable + upper.style.pixelHeight) )
  260. value = Math.max(Max - LargeChange,0);
  261. else
  262. value = Math.round((thumbTop - upper.style.pixelHeight )* thumbToValue);
  263. if (value < 0)
  264. value = 0;
  265. }
  266. thumb.title = value+1;
  267. //window.status = "Value:"+value + "ThumbTop:" + thumb.offsetTop + "ScrollArea:" + scrollAreaAvailable;
  268. // + "ThumbToValue:" + thumbToValue + "ScreenArea:" + scrollArea.style.pixelHeight;
  269. //" OffsetY: " +window.event.offsetY+" clientY: " + window.event.clientY + " newPos : " + newPos;
  270. }
  271. function fireChangeEvent()
  272. {
  273. changeEvent = createEventObject();
  274. changeID.fire(changeEvent);
  275. }
  276. function handleMouseUp()
  277. {
  278. //thumbTop = thumb.offsetTop;
  279. if(dragThumb == true)
  280. {
  281. dragThumb = false;
  282. if(oldValue != value)
  283. {
  284. fireChangeEvent();
  285. oldValue = value;
  286. }
  287. }
  288. scrollOn = false;
  289. }
  290. function calcParams()
  291. {
  292. scrollAreaAvailable = scrollArea.style.pixelHeight-upper.style.pixelHeight-lower.style.pixelHeight;
  293. if(Max<LargeChange) Max = LargeChange;
  294. largeJump = (LargeChange/Max)*(scrollAreaAvailable);
  295. smallJump = (smallChange/Max)*(scrollAreaAvailable);
  296. thumb.style.pixelHeight = Math.max(largeJump,6);
  297. myheight = thumb.style.pixelHeight/2;
  298. divMax = lower.offsetTop - thumb.style.pixelHeight;
  299. divMin = upper.offsetTop + upper.style.pixelHeight;
  300. thumbToValue = Max/(scrollAreaAvailable);
  301. thumbTop = thumb.offsetTop;
  302. }
  303. function removeFocus() {
  304. if((scrollOn == true)||(dragThumb == true))
  305. scrollArea.focus();
  306. }
  307. </SCRIPT>
  308. </PUBLIC:COMPONENT>
  309. </HTC>