home *** CD-ROM | disk | FTP | other *** search
- <PUBLIC:HTC URN="shellctls"><METHOD name="SetExecButton" /><METHOD name="ShowButton" /><METHOD name="focus" /><METHOD name="blur" /><EVENT id=onSelectItem name="onSelectItem" /><EVENT id=onExecItem name="onExecItem" /><EVENT id=onComplete name="onComplete" /><ATTACH event="oncontentready" handler=_OnContentReady /><ATTACH event="ondragstart" handler=_CancelDragStart /><SCRIPT language="javascript">
- var _bLoading = true;
- var _iBtnPressed = -1;
- var _iBtnHot = -1;
- var _iBtnTabIndex = -1;
- var _iBtnCapture = -1;
- var _cButtons = 0;
- var _rgbtn = new Array();
- var _rgdivButtons = new Array();
- var _styleinfo = null;
- var _mpStyle = new Object();
- var _bHasFocus = false;
- var _bInternalFocusChange = false;
- var BS_PRESSED = 0x01;
- var BS_HOT = 0x02;
- var c_szStyle_ButtonNormal =
- ' style="' +
- 'position:relative; ' +
- 'padding:2px; ' +
- 'border-style:solid; ' +
- 'border-width:1px; ' +
- 'border-top-color:threedshadow; ' +
- 'border-left-color:threedshadow; ' +
- 'border-right-color:threedshadow; ' +
- 'border-bottom-color:threedshadow; ' +
- '"';
- var c_szStyle_ButtonText =
- ' style="' +
- 'position:relative; ' +
- 'color:white; ' +
- 'cursor:default; ' +
- '"';
- var c_szStyle_Background =
- ' style="' +
- 'position:relative; ' +
- 'width:87px; ' +
- 'height:100%; ' +
- 'padding:2px; ' +
- 'background-color:threedshadow; ' +
- '"';
- element.attachEvent("onerror", _OnError);
- _GetPropertyDefaults();
- function get_button() { return _iBtnPressed; }
- function put_button(iBtn)
- {
- if (_bLoading)
- return;
- _PushButton(parseInt(iBtn), 0);
- }
- function _OnContentReady()
- {
- _bLoading = false;
- _ScanSpecialElements();
- _CreateHTML();
- }
- function _OnDocumentLoad()
- {
- _Initialize();
- }
- function _GetPropertyDefaults()
- {
- if (element.currentButton)
- _iBtnPressed = parseInt(element.currentButton);
- }
- function _IDName(szID, idx)
- {
- return szID + idx + '_' + uniqueID;
- }
- function _StoreButton(elem, ibtn)
- {
- var btn = new Object;
- var szBtnIndex = ' _ibtn=' + ibtn;
- var L_PlacesGraphic_Text = 'Graphic';
- btn.id = elem.id;
- btn._idBtn = _IDName('idBtn', ibtn);
- btn._ibtn = ibtn;
- btn._idBR = _IDName('idBtnBR', ibtn);
- btn._bHidden = false;
- if ("undefined" != typeof elem.execItem)
- btn._bExecButton = true;
- else
- btn._bExecButton = false;
- btn.innerHTML =
- '<DIV id=' + btn._idBtn + c_szStyle_ButtonNormal + szBtnIndex + ' _btnState=0> ' +
- ' <CENTER id=' + _IDName('idCtr', ibtn) + szBtnIndex + '> ' +
- ' <IMG id=' + _IDName('idImg', ibtn) + ' style="position:relative" src=' + elem.img + szBtnIndex + ' title="" alt="' + L_PlacesGraphic_Text + '" >' +
- ' <BR>' +
- ' <SPAN id=' + _IDName('idSpan', ibtn) + c_szStyle_ButtonText + szBtnIndex + ' nofocusrect>' +
- elem.innerHTML +
- ' </SPAN>' +
- ' </CENTER> ' +
- '</DIV>';
- _rgbtn[ibtn] = btn;
- }
- function _ScanSpecialElements()
- {
- var i;
- var rgspan = element.all.tags("SPAN");
- var cspan = rgspan.length;
- for (i = 0; i < cspan; i++)
- {
- var span = rgspan[i];
- _StoreButton(span, _cButtons++);
- span.innerHTML = "";
- }
- }
- function _CreateHTML()
- {
- var i;
- var szButtons = '';
- element.style.visibility = 'hidden';
- for (i = 0; i < _cButtons; i++)
- {
- szButtons = szButtons + _rgbtn[i].innerHTML + '<BR id=' + _rgbtn[i]._idBR + '>';
- }
- element.innerHTML =
- '<DIV ' + c_szStyle_Background + ' _ibtn=-1> ' +
- szButtons +
- '</DIV>';
- var rgdivs = element.all.tags("DIV");
- for (i = 0; i < _cButtons; i++)
- {
- var elem = rgdivs[_rgbtn[i]._idBtn];
- _rgdivButtons[i] = elem;
- elem.attachEvent('onmouseover', _OnMouseOver);
- elem.attachEvent('onmouseout', _OnMouseOut);
- elem.attachEvent('onmousedown', _OnMouseDown);
- elem.attachEvent('onmouseup', _OnMouseUp);
- var spanCaption = _GetCaptionElem(i);
- spanCaption.attachEvent('onblur', _OnBlurDiv);
- spanCaption.attachEvent('onfocus', _OnFocusDiv);
- spanCaption.attachEvent('onkeydown', _OnKeyDownDiv);
- elem.all(_IDName('idCtr', i)).attachEvent('ondragstart', _CancelDragStart);
- }
- window.attachEvent("onload", _OnDocumentLoad);
- _FireComplete();
- element.style.visibility = 'visible';
- }
- function _Initialize()
- {
- if (-1 != _iBtnPressed)
- {
- var ibtn = _iBtnPressed;
- _iBtnPressed = -1;
- _PushButton(ibtn, 0);
- }
- window.document.attachEvent("onkeydown", _OnKeyDownDocument);
- }
- function _BtnFromElement(elem)
- {
- var ibtn = -1;
- if (elem && null == elem._ibtn)
- {
- while (elem)
- {
- if (elem._ibtn)
- break;
- elem = elem.parentElement;
- }
- }
- if (elem)
- ibtn = elem._ibtn;
- return ibtn;
- }
- function _BtnFromID(idBtn)
- {
- var ibtn;
- for (ibtn = 0; ibtn < _rgbtn.length; ibtn++)
- {
- if (idBtn == _rgbtn[ibtn].id)
- return ibtn;
- }
- return -1;
- }
- function _DrawButtonFrame(elem, szState)
- {
- switch (szState)
- {
- case 'normal':
- elem.style.borderTopColor = 'threedshadow';
- elem.style.borderLeftColor = 'threedshadow';
- elem.style.borderRightColor = 'threedshadow';
- elem.style.borderBottomColor = 'threedshadow';
- break;
- case 'hotitem':
- elem.style.borderTopColor = 'threedhighlight';
- elem.style.borderLeftColor = 'threedhighlight';
- elem.style.borderRightColor = 'threeddarkshadow';
- elem.style.borderBottomColor = 'threeddarkshadow';
- break;
- case 'pushed':
- elem.style.borderTopColor = 'threeddarkshadow';
- elem.style.borderLeftColor = 'threeddarkshadow';
- elem.style.borderRightColor = 'threedhighlight';
- elem.style.borderBottomColor = 'threedhighlight';
- break;
- }
- }
- function _DrawButton(ibtn, bDown)
- {
- var div = _rgdivButtons[ibtn];
- var bDownCur = (div._btnState & BS_PRESSED) ? true : false;
- var elemImg = div.all(_IDName('idImg', div._ibtn));
- var elemText = div.all(_IDName('idSpan', div._ibtn));
- if (bDownCur == bDown)
- return;
- if (bDown)
- {
- _DrawButtonFrame(div, 'pushed');
- elemImg.style.pixelLeft = elemImg.style.pixelLeft + 1;
- elemImg.style.pixelTop = elemImg.style.pixelTop + 1;
- elemText.style.pixelLeft = elemText.style.pixelLeft + 1;
- elemText.style.pixelTop = elemText.style.pixelTop + 1;
- div._btnState |= BS_PRESSED;
- }
- else
- {
- if (ibtn == _iBtnHot)
- _DrawButtonFrame(div, 'hotitem');
- else
- _DrawButtonFrame(div, 'normal');
- elemImg.style.pixelLeft = elemImg.style.pixelLeft - 1;
- elemImg.style.pixelTop = elemImg.style.pixelTop - 1;
- elemText.style.pixelLeft = elemText.style.pixelLeft - 1;
- elemText.style.pixelTop = elemText.style.pixelTop - 1;
- div._btnState &= ~ BS_PRESSED;
- }
- }
- function _GetCaptionElem(ibtn)
- {
- var spanCaption = null;
- var div = _rgdivButtons[ibtn];
- if (div)
- spanCaption = div.children[0].children[2];
- return spanCaption;
- }
- function _SetTabIndex(ibtn, bSetFocus)
- {
- if (ibtn == _iBtnTabIndex)
- return;
- var elem = _GetCaptionElem(_iBtnTabIndex);
- if (elem)
- elem.tabIndex = -1;
- elem = _GetCaptionElem(ibtn);
- if (elem)
- {
- elem.tabIndex = 0;
- if (bSetFocus)
- {
- _bInternalFocusChange = true;
- elem.focus();
- }
- }
- _iBtnTabIndex = ibtn;
- }
- var PBF_SETFOCUS = 0x01;
- var PBF_MOUSE = 0x02;
- function _PushButton(ibtn, dwFlags)
- {
- var btn = _rgbtn[ibtn];
- if (btn && btn._bHidden)
- {
- return;
- }
- if (btn && btn._bExecButton)
- {
- _DrawButton(ibtn, false);
- _FireExecItem(btn);
- }
- else
- {
- if ((dwFlags & PBF_MOUSE) && ibtn == _iBtnPressed)
- return;
- if (-1 != _iBtnPressed && ibtn != _iBtnPressed)
- {
- _DrawButton(_iBtnPressed, false);
- }
- _iBtnPressed = ibtn;
- _SetTabIndex(ibtn, dwFlags & PBF_SETFOCUS);
- if (0 <= _iBtnPressed && _iBtnPressed < _cButtons)
- {
- _DrawButton(_iBtnPressed, true);
- _FireSelectItem(btn);
- }
- }
- }
- var SHIF_SETTABINDEX = 0x01;
- var SHIF_RESETTABSTOP = 0x02;
- var SHIF_MOUSE = 0x04;
- function _SetHotItem(ibtn, dwFlags)
- {
- var div;
- if (ibtn == _iBtnHot)
- return;
- if (-1 != _iBtnHot && _iBtnHot != ibtn)
- {
- div = _rgdivButtons[_iBtnHot];
- if (_iBtnHot == _iBtnPressed)
- _DrawButtonFrame(div, 'pushed');
- else
- _DrawButtonFrame(div, 'normal');
- }
- if (-1 != ibtn)
- {
- div = _rgdivButtons[ibtn];
- if ( !(dwFlags & SHIF_MOUSE) || ibtn != _iBtnPressed)
- _DrawButtonFrame(div, 'hotitem');
- }
- _iBtnHot = ibtn;
- if (dwFlags & SHIF_SETTABINDEX)
- {
- if (dwFlags & SHIF_RESETTABSTOP)
- {
- _SetTabIndex(_iBtnPressed, false);
- }
- else
- {
- _SetTabIndex(ibtn, true);
- }
- }
- }
- function _FireSelectItem(btn)
- {
- var evt = createEventObject();
- evt.srcID = btn.id;
- onSelectItem.fire(evt);
- }
- function _FireExecItem(btn)
- {
- var evt = createEventObject();
- evt.srcID = btn.id;
- onExecItem.fire(evt);
- }
- function _FireComplete()
- {
- var evt = createEventObject();
- onComplete.fire(evt);
- }
- var LMOUSE_BUTTON = 1
- function _OnMouseDown()
- {
- var ibtn = _BtnFromElement(window.event.srcElement);
- var div;
- if (LMOUSE_BUTTON != window.event.button)
- return;
- _DrawButton(ibtn, true);
- _iBtnCapture = ibtn;
- div = _rgdivButtons[ibtn];
- div.setCapture(false);
- }
- function _OnMouseUp()
- {
- var ibtn = _BtnFromElement(window.event.srcElement);
- if (LMOUSE_BUTTON != window.event.button)
- return;
- if (-1 != _iBtnCapture)
- {
- var div = _rgdivButtons[_iBtnCapture];
- div.releaseCapture();
- if (_iBtnCapture != ibtn)
- _DrawButton(_iBtnCapture, (_iBtnPressed == _iBtnCapture));
- if (-1 != ibtn && ibtn == _iBtnCapture)
- _PushButton(ibtn, PBF_SETFOCUS | PBF_MOUSE);
- _iBtnCapture = -1;
- }
- }
- function _OnMouseOver()
- {
- var ibtnTo = _BtnFromElement(window.event.toElement);
- var ibtnFrom = _BtnFromElement(window.event.fromElement);
- if (-1 != _iBtnCapture)
- {
- if (ibtnTo == _iBtnCapture && ibtnFrom != _iBtnCapture)
- {
- _DrawButton(_iBtnCapture, true);
- }
- }
- else
- {
- _SetHotItem(ibtnTo, SHIF_MOUSE);
- }
- }
- function _OnMouseOut()
- {
- var event = window.event;
- var ibtnTo = _BtnFromElement(event.toElement);
- var ibtnFrom = _BtnFromElement(event.fromElement);
- if (ibtnTo != ibtnFrom)
- {
- _SetHotItem(-1, SHIF_MOUSE);
- if (ibtnFrom == _iBtnCapture && _iBtnCapture != _iBtnPressed)
- _DrawButton(_iBtnCapture, false);
- }
- }
- var CYCLE_PUSHED = 1;
- var CYCLE_HOT = 2;
- function _CycleButton(bDown, ibtnStart, cycle)
- {
- var ibtn = ibtnStart;
- var n = bDown ? 1 : -1;
- var btn;
- var cbtns = 0;
- while (true)
- {
- if (++cbtns > _cButtons)
- break;
- if (bDown)
- ibtn = (ibtn + 1) % _cButtons;
- else
- ibtn = ((ibtn - 1) + _cButtons) % _cButtons;
- btn = _rgbtn[ibtn];
- if (CYCLE_PUSHED == cycle)
- {
- if (ibtn == _iBtnPressed || btn._bExecButton || btn._bHidden)
- continue;
- else
- break;
- }
- else
- {
- if (btn._bHidden)
- continue;
- else
- break;
- }
- }
- return ibtn;
- }
- function _CycleHotItem(bDown)
- {
- _SetHotItem(_CycleButton(bDown, _iBtnHot, CYCLE_HOT), SHIF_SETTABINDEX);
- }
- function _CyclePushedButton(bDown)
- {
- _PushButton(_CycleButton(bDown, _iBtnPressed, CYCLE_PUSHED), 0);
- }
- function SetExecButton(idBtn, bVal)
- {
- var ibtn = _BtnFromID(idBtn);
- if (-1 != ibtn)
- {
- _rgbtn[ibtn]._bExecButton = bVal;
- }
- }
- function ShowButton(idBtn, bShow)
- {
- var ibtn = _BtnFromID(idBtn);
- if (-1 != ibtn)
- {
- var btn = _rgbtn[ibtn];
- if (btn)
- {
- var idBtnUnique = btn._idBtn;
- var elemBtn = element.all[idBtnUnique];
- if (bShow)
- {
- elemBtn.style.display = 'block';
- element.all[btn._idBR].style.display = 'block';
- }
- else
- {
- elemBtn.style.display = 'none';
- element.all[btn._idBR].style.display = 'none';
- }
- btn._bHidden = !bShow;
- }
- }
- }
- function focus()
- {
- var div = _rgdivButtons[_iBtnTabIndex];
- if (div)
- div.focus();
- }
- function blur()
- {
- var div = _rgdivButtons[_iBtnTabIndex];
- if (div)
- div.blur();
- }
- var KC_LEFT = 37;
- var KC_UP = 38;
- var KC_RIGHT = 39;
- var KC_DOWN = 40;
- var KC_SPACE = 32;
- var KC_RETURN = 13;
- var KC_TAB = 9;
- function _OnKeyDownDocument()
- {
- var evt = window.event;
- if (KC_TAB == evt.keyCode && evt.ctrlKey)
- {
- var bDir = evt.shiftKey ? false : true;
- _CyclePushedButton(bDir);
- evt.returnValue = false;
- }
- }
- function _OnKeyDownDiv()
- {
- var keyCode = window.event.keyCode;
- if (KC_UP == keyCode || KC_LEFT == keyCode)
- {
- _CycleHotItem(false);
- window.event.returnValue = false;
- }
- else if (KC_DOWN == keyCode || KC_RIGHT == keyCode)
- {
- _CycleHotItem(true);
- window.event.returnValue = false;
- }
- else if (KC_SPACE == keyCode || KC_RETURN == keyCode)
- {
- _PushButton(_iBtnHot, PBF_SETFOCUS);
- }
- }
- function _OnBlurDiv()
- {
- if (false == _bInternalFocusChange && true == _bHasFocus)
- {
- _bHasFocus = false;
- _SetHotItem(-1, SHIF_SETTABINDEX | SHIF_RESETTABSTOP);
- }
- }
- function _OnFocusDiv()
- {
- if (false == _bInternalFocusChange && false == _bHasFocus &&
- "complete" == window.document.readyState)
- {
- _bHasFocus = true;
- _CycleHotItem(true);
- }
- _bInternalFocusChange = false;
- }
- function _OnError(szMsg, szUrl, iLine)
- {
- alert("An unexpected error occurred.\n\n" + szMsg + "\n" + szUrl + "\nLine: " + iLine);
- return true;
- }
- function _CancelDragStart()
- {
- window.event.returnValue = false;
- }
- </SCRIPT><PROPERTY name="currentButton" get=get_button put=put_button /></PUBLIC:HTC>