home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 June / comonline0602.iso / software / cogitum / cociter.exe / CogitumH.___ / HTML / TOOLBARBUTTON.HTC < prev    next >
Encoding:
HTML Component  |  2001-08-08  |  9.1 KB  |  378 lines

  1. <PUBLIC:COMPONENT NAME="toolbar_button" URN="www.cogitum.com/toolbar_button.htc">
  2. <PUBLIC:ATTACH EVENT="oncontentready" ONEVENT="fnDraw()" FOR=element/>
  3. <PUBLIC:ATTACH EVENT="onpropertychange" ONEVENT="fnPropertyChange()" FOR="element"/>
  4. <PUBLIC:ATTACH EVENT="onmousedown" ONEVENT="fnMouseDown()" FOR="element"/>
  5. <PUBLIC:ATTACH EVENT="onmouseup" ONEVENT="fnMouseUp()" FOR="element"/>
  6. <PUBLIC:ATTACH EVENT="onclick" ONEVENT="fnMouseClick()" FOR="element"/>
  7. <PUBLIC:ATTACH EVENT="onmouseover" ONEVENT="fnMouseOver()" FOR="element"/>
  8. <PUBLIC:ATTACH EVENT="onmouseout" ONEVENT="fnMouseOut()" FOR="element"/>
  9. <PUBLIC:ATTACH EVENT="ondragstart" ONEVENT="fnDragStart()" FOR="element"/>
  10. <PUBLIC:PROPERTY NAME="ct_toolbar_button"    GET="fnIdentify"/>
  11. <PUBLIC:PROPERTY NAME="ct_checkbutton" INTERNALNAME="bCheckButton" />
  12. <PUBLIC:PROPERTY NAME="ct_state"       INTERNALNAME="bState"       />
  13. <PUBLIC:PROPERTY NAME="ct_disabled"    INTERNALNAME="bDisabled"    />
  14. <PUBLIC:PROPERTY NAME="ct_dropdown"      INTERNALNAME="bDropDown"  />
  15. <PUBLIC:PROPERTY NAME="ct_sticky"    INTERNALNAME="bSticky"  />
  16. <PUBLIC:PROPERTY NAME="ct_onclick"     INTERNALNAME="szOnClick"    />
  17. <PUBLIC:METHOD NAME="ct_unstick"    INTERNALNAME="fnUnStick"/>
  18. <PUBLIC:METHOD NAME="ct_stick_self"        INTERNALNAME="fnStickSelf"/>
  19. <PUBLIC:METHOD NAME="ct_unstick_self"        INTERNALNAME="fnUnStickSelf"/>
  20. <PUBLIC:METHOD NAME="ct_mouseover"    INTERNALNAME="fnMouseOverSelf"/>
  21. <PUBLIC:METHOD NAME="ct_mouseout"    INTERNALNAME="fnMouseOutSelf"/>
  22.  
  23.  
  24. <SCRIPT LANGUAGE="JScript">
  25. //
  26. //  Sticky button (ct_sticky (bSticky) = 1 else nothing special happens)
  27. // ---------------
  28. // Disable/Enable (set ct_disabled = 0/1) result in clearing of stick state (bSticked)
  29. //
  30. // bSticked store stickness state. It's internal variable.
  31. //  = 0 - normal functionality
  32. //  = 1 - button have sticked. Switch to this state on button click (script execute)
  33. //
  34. // In "sticked" state (bSticked = 1):
  35. //  - changes to the button other states stored in special variables (bActiveSticked, bPressedSticked)
  36. //    instead of normal variables (bActive, bPressed)
  37. //  - no changes happen to visual state of the button (no call to fnDraw())
  38. //  - if ct_sticky changes to 0 then it equals to ct_unstick() call
  39. //
  40. // To switch to normal state script should call button's ct_unstick() method after execution
  41. // On ct_unstick():
  42. //  - states from special variables (bActiveSticked, bPressedSticked) copied
  43. //    to normal ones (bActive, bPressed)
  44. //  - fnDraw() called to display all changes to the button since it was sticked
  45. //
  46. // Next calls to ct_unstick() do nothing.
  47. //
  48.  
  49. var szOnClick = "";    // script to execute on ONCLICK event
  50.  
  51. var bCheckButton = 0;    // the button is the check button (it fixes in pressed state)
  52. var bDropDown = 0;    // the button is the down arrow that call drop down list to select from
  53.             // ex. Back in Internet Explorer
  54. var bSticky = 0;    // if 1 then button stay pressed after ct_onclick executed until
  55.             // call to ct_stickyup
  56. var bSticked = 0;    // store current state of the button if it's sticky
  57. var bDisabled = 0;    // the button is disabled (does not response to actions)
  58. var bState = 0;        // mouse button is pressed (but not released) on the button
  59. var bActive = 0;    // mouse is over the button
  60. var bActiveSticked = 0;    // mouse is over the button that is in sticked state
  61. var bPressed = 0;    // the button have been pressed previously
  62. var bPressedSticked = 0;// the button that is in sticked state have been pressed previously
  63.  
  64. var activeCache = null;
  65. var grayCache     = null;
  66.  
  67. function fnToBoolean(someValue) {
  68.         if( someValue == "false" || someValue == false
  69.      || someValue == "0"     || someValue == 0
  70.      || isNaN(someValue) )
  71.     {
  72.         return false;
  73.     }
  74.         else
  75.     {
  76.         return true;
  77.     }
  78. };
  79.  
  80. function fnIdentify()
  81. {
  82. // this used for property ct_toolbar_button which is used to identify this behavior
  83. // always return 1
  84.  
  85.     return 1;
  86. }
  87.  
  88. //
  89. // use "eltSibling" in the code string passed to this function to refer to sibling object
  90. //
  91. function fnExecCodeOnSibling(szCode, bPrevious)
  92. {
  93.     if(!fnToBoolean(bDropDown))
  94.     {
  95.         var eltSibling = nextSibling;
  96.         //
  97.         if(eltSibling
  98.         && fnToBoolean(eltSibling.ct_toolbar_button)
  99.         && fnToBoolean(eltSibling.ct_dropdown) )
  100.         {
  101.             eval(szCode);
  102.         }
  103.     }
  104.     else if(bPrevious)
  105.     {
  106.         var eltSibling = previousSibling;
  107.         //
  108.         if(eltSibling
  109.         && fnToBoolean(eltSibling.ct_toolbar_button)
  110.         && !fnToBoolean(eltSibling.ct_dropdown) )
  111.         {
  112.             eval(szCode);
  113.         }
  114.     }
  115. }
  116.  
  117. function fnDraw()
  118. {
  119. /*
  120. if (activeCache == null) {
  121.  activeCache    = new Image();
  122.  activeCache.src= element.activesrc;
  123.  };
  124. if (grayCache == null) {
  125.  grayCache     = new Image();
  126.  grayCache.src     = element.graysrc;
  127. };
  128. */
  129.     if(!fnToBoolean(bCheckButton))
  130.         bState = 0;
  131. //
  132. // it's more correct to leave background setting to toolbar (as it can be image and so on)
  133. //    element.runtimeStyle.backgroundColor = "#C0C0C0";
  134. //    
  135.     if(fnToBoolean(bDisabled))
  136.     {
  137.         //element.runtimeStyle.filter = "Gray Chroma(color = #C0C0C0) Alpha(Opacity=25) DropShadow(color=white, offx=1, offy=1)";
  138.         element.src = element.graysrc;
  139.         if(fnToBoolean(bCheckButton) & fnToBoolean(bState))
  140.         {
  141.             element.runtimeStyle.borderRight = "1px solid white";
  142.             element.runtimeStyle.borderBottom = "1px solid white";
  143.             element.runtimeStyle.borderTop = "1px solid black";
  144.             element.runtimeStyle.borderLeft = "1px solid black";
  145.         }
  146.         else
  147.         {
  148.             element.runtimeStyle.border = "1px solid #C0C0C0";
  149.         }
  150.     }
  151.     else
  152.     {
  153.         if(fnToBoolean(bState) || bPressed)
  154.         {
  155.             element.runtimeStyle.borderRight = "1px solid white";
  156.             element.runtimeStyle.borderBottom = "1px solid white";
  157.             element.runtimeStyle.borderTop = "1px solid black";
  158.             element.runtimeStyle.borderLeft = "1px solid black";
  159.             //if(bActive)
  160.             //    element.runtimeStyle.filter = "";
  161.             //else
  162.             //    element.runtimeStyle.filter = "Gray";
  163.             if(bActive)
  164.                 element.src = element.activesrc;
  165.             else
  166.                 element.src = element.graysrc;
  167.  
  168.         }
  169.         else
  170.         {
  171.             if(bActive)
  172.             {
  173.                 //element.runtimeStyle.filter = "";
  174.  
  175.                 element.src = element.activesrc;
  176.  
  177.                 element.runtimeStyle.borderRight = "1px solid black";
  178.                 element.runtimeStyle.borderBottom = "1px solid black";
  179.                 element.runtimeStyle.borderTop = "1px solid white";
  180.                 element.runtimeStyle.borderLeft = "1px solid white";
  181.             }
  182.             else
  183.             {
  184.                 //element.runtimeStyle.filter = "Gray Chroma(color = #C0C0C0)";
  185.                                 element.src = element.graysrc;
  186.                 element.runtimeStyle.border = "1px solid #C0C0C0";
  187.             }
  188.         }
  189.     }
  190.  
  191. }
  192.  
  193. function fnPropertyChange()
  194. {
  195.     switch(window.event.propertyName)
  196.     {
  197.     case "ct_dropdown":
  198.         return;
  199.  
  200.     case "ct_checkbutton":
  201.         return;
  202.  
  203.     case "ct_state":
  204.         break;
  205.  
  206.     case "ct_disabled":
  207.         bPressed = 0;
  208.         bActive = 0;
  209.         bSticked = 0;
  210.         //
  211.         // you can't disable sibling button via dropdown button
  212.         // disable both only via main button (with picture)
  213.         // this done to don't produce endless loop
  214.         fnExecCodeOnSibling("eltSibling.ct_disabled = bDisabled;", 0)
  215.         //
  216.         break;
  217.  
  218.     case "ct_sticky":
  219.         if(fnToBoolean(bSticky))
  220.         {
  221.             fnUnStickSelf();
  222.             break;
  223.         }
  224.         else
  225.             return;
  226.  
  227.     default:
  228.         return;
  229.     }
  230.     fnDraw();
  231. }
  232.  
  233. function fnMouseDown()
  234. {
  235.     if(window.event.button & 1)    // pressed left button
  236.         if(!fnToBoolean(bDisabled))
  237.             if(bSticked)
  238.                 bPressedSticked = 1;
  239.             else
  240.             {
  241.                 bPressed = 1;
  242.                 fnDraw();
  243.             }
  244. }
  245.  
  246. function fnMouseUp()
  247. {
  248.     if(window.event.button & 1)    // pressed left button
  249.         if(!fnToBoolean(bDisabled))
  250.             if(bSticked)
  251.                 bPressedSticked = 0;
  252.             else
  253.                 if(bPressed)
  254.                 {
  255.                     if(fnToBoolean(bCheckButton))
  256.                     {
  257.                         if(fnToBoolean(bState))
  258.                             bState = 0;
  259.                         else
  260.                             bState = 1;
  261.                     }
  262.                     if(szOnClick.length > 0)
  263.                     {
  264.                         fnStick();
  265.                         window.execScript(szOnClick);
  266.                     }
  267.                     bPressed = 0;
  268.                     fnDraw();
  269.                 }
  270. }
  271.  
  272. //
  273. // called from sibling button if required
  274. //
  275. function fnMouseOverSelf()
  276. {
  277.     if(!fnToBoolean(bDisabled))
  278.     {
  279.         if(bSticked)
  280.         {
  281.             bActiveSticked = 1;
  282.         }
  283.         else
  284.         {
  285.             bActive = 1;
  286.             fnDraw();
  287.         }
  288.     }
  289. }
  290.  
  291. function fnMouseOver()
  292. {
  293.     if(!fnToBoolean(bDisabled))
  294.     {
  295.         fnMouseOverSelf();
  296.         fnExecCodeOnSibling("eltSibling.ct_mouseover();", 1)
  297.     }
  298. }
  299.  
  300. //
  301. // called from sibling button if required
  302. //
  303. function fnMouseOutSelf()
  304. {
  305.     if(!fnToBoolean(bDisabled))
  306.     {
  307.         if(bSticked)
  308.         {
  309.             bActiveSticked = 0;
  310.             bPressedSticked = 0;
  311.         }
  312.         else
  313.         {
  314.             bActive = 0;
  315.             bPressed = 0;
  316.             fnDraw();
  317.         }
  318.     }
  319. }
  320.  
  321. function fnMouseOut()
  322. {
  323.     if(!fnToBoolean(bDisabled))
  324.     {
  325.         fnMouseOutSelf();
  326.         fnExecCodeOnSibling("eltSibling.ct_mouseout();", 1)
  327.     }
  328. }
  329.  
  330. function fnMouseClick()
  331. {
  332. }
  333.  
  334. function fnDragStart()
  335. {
  336.     window.event.returnValue = false;
  337. }
  338.  
  339. function fnUnStickSelf()
  340. {
  341.     if(bSticked)
  342.     {
  343.         bSticked = 0;
  344.         bPressed = bPressedSticked;
  345.         bActive = bActiveSticked;
  346.         fnDraw();
  347.     }
  348. }
  349.  
  350. function fnUnStick()
  351. {
  352.     if(bSticked)
  353.     {
  354.         fnUnStickSelf();
  355.         fnExecCodeOnSibling("eltSibling.ct_unstick_self();", 1)
  356.     }
  357. }
  358.  
  359. function fnStickSelf()
  360. {
  361.     if(fnToBoolean(bSticky))
  362.     {
  363.         bSticked = 1;
  364.     }
  365. }
  366.  
  367. function fnStick()
  368. {
  369.     if(fnToBoolean(bSticky))
  370.     {
  371.         fnStickSelf();
  372.         fnExecCodeOnSibling("eltSibling.ct_stick_self();", 1)
  373.     }
  374. }
  375.  
  376. </SCRIPT>
  377. </PUBLIC:COMPONENT>
  378.