none
Restarting Gadget itself or proper dock/undock.

    Question

  • Hello.

    I've looked through the topics but did not find answer for my question.

    I've making alarm clock gadget for my girlfriend - she asked me to make this gadget for her.

    Gadget is a round clock, when you click it - appearing 8 buttons, aside of main gadget. Buttons provides opportunities to add/remove/edit signals.

    And now - about my problem.

    How to 

    1) make gadget dock/undock itself? (by clicking on itself - not user controls)

    (flyout is not acceptable - because it appears directly right or left of main gadget - i need to place buttons above the main gadget window)

    2) how to dynamically move gadget, when we undock it?

    I've tried to change DropLocation variables in cache file, but it takes effect only after reloading the gadget! I've don't know how to restart gadget itself (only if reload all sidebar) - but reloading in any case - unlikely way.

    Any Ideas?

    P.S. Sorry for my awful English =))))



    • Edited by Comotoz Monday, May 14, 2012 11:42 PM
    Monday, May 14, 2012 11:40 PM

Answers

  • Unfortunately, again the only way I know how to do either is with "SendKeys."

    It is usually worthwhile letting go off the mouse and seeing what you can do with the keyboard and most things you can do with the keyboard you can do with SendKeys. Also you can simulate a right click to bring up the context menu with "Shift"+F10.

    Then on Vista you have options for "Detach"/"Attach" to the sidebar and "Move". On Seven you have "Move" and if you have onDock and onUndock handlers you will also have "Size". Look for the underlined letters for the keys.

    There are a few problems though. On Vista when you select move and then tap an arrow key the gadget will move 16px in the X-direction or 12px in the Y-direction but in Win7 the gadget will move 10px in both the X and Y directions. So while you can cater for that and have the example below working fine in Vista, in Win7 if you choose Dock or Undock after you move the gadget, it will likely zing back to it's original X-position and use some unknown formula to determine the Y-position. Strangely, if the gadget is first dragged with the mouse then the move button is used and then the dock/undock button, the movement is much less. Trying to write the drop locations in Settings.ini seems to have no effect for me as after the gadget has finished moving, these are overwritten. You could use the function you originally used to move the gadget to reset the position but the gadget would fly around the screen crazily. (The example below does not reset the position.)

    The "Move" control on this example is set to move the gadget as close as possible to the lower left corner of your screen.

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>test undock and move</title>
    <style type="text/css">
    <!--
    body {margin:0;width:130px;height:65px;background-color:#444;padding:5px;font:bold 12px/14px "Segoe UI";text-align:center;}
    #setDockState, #moveGadget {width:120px;padding:5px;background-color:#ccc;border:2px solid #222;cursor:pointer;}
    -->
    </style>
    <script type="text/jscript">
    var sysVersion=+System.Gadget.platformVersion.slice(4,5);
    function setText(){
     setDockState.innerText=(System.Gadget.docked)?"Undock":"Dock";
    }
    function dockUndock(){
     var wshShell=new ActiveXObject("WScript.Shell");
     if(sysVersion<7){
      if(System.Gadget.docked){wshShell.SendKeys("+{F10}D");}
      else{wshShell.SendKeys("+{F10}t");}
     }
     else{
      if(System.Gadget.docked){wshShell.SendKeys("+{F10}z{DOWN}~");}
      else{wshShell.SendKeys("+{F10}z~");}
     }
     wshShell=null;
    }
    function setPosition(){
     var scrLeft, scrTop, scrX, scrY, wshShell, mStepX, mStepY, moveX, moveY;
     scrLeft=window.screenLeft;
     scrTop=window.screenTop;
     scrX=screen.width;//not used in this example
     scrY=screen.height;
     mStepX=(sysVersion<7)?16:10;
     mStepY=(sysVersion<7)?12:10;
     wshShell=new ActiveXObject("WScript.Shell");
     moveX="LEFT "+Math.floor(scrLeft/mStepX);
     moveY="DOWN "+Math.floor((scrY-scrTop-document.body.offsetHeight)/mStepY);
     wshShell.SendKeys("+{F10}M{"+moveX+"}{"+moveY+"}~");
     wshShell=null;
    }
    function fx(){
     setDockState.onclick=dockUndock;
     moveGadget.onclick=setPosition;
    }
    System.Gadget.onUndock=function(){document.body.style.backgroundColor="#f00";setText();};
    System.Gadget.onDock=function(){document.body.style.backgroundColor="#444";setText();};
    </script>
    </head>
    <body onload="fx();">
    <div id="setDockState">Undock</div>
    <div  id="moveGadget">Move</div>
    </body>
    </html>


    • Edited by mystifeid Tuesday, May 15, 2012 6:04 AM
    • Marked as answer by Comotoz Tuesday, May 15, 2012 3:35 PM
    Tuesday, May 15, 2012 5:41 AM

All replies

  • Unfortunately, again the only way I know how to do either is with "SendKeys."

    It is usually worthwhile letting go off the mouse and seeing what you can do with the keyboard and most things you can do with the keyboard you can do with SendKeys. Also you can simulate a right click to bring up the context menu with "Shift"+F10.

    Then on Vista you have options for "Detach"/"Attach" to the sidebar and "Move". On Seven you have "Move" and if you have onDock and onUndock handlers you will also have "Size". Look for the underlined letters for the keys.

    There are a few problems though. On Vista when you select move and then tap an arrow key the gadget will move 16px in the X-direction or 12px in the Y-direction but in Win7 the gadget will move 10px in both the X and Y directions. So while you can cater for that and have the example below working fine in Vista, in Win7 if you choose Dock or Undock after you move the gadget, it will likely zing back to it's original X-position and use some unknown formula to determine the Y-position. Strangely, if the gadget is first dragged with the mouse then the move button is used and then the dock/undock button, the movement is much less. Trying to write the drop locations in Settings.ini seems to have no effect for me as after the gadget has finished moving, these are overwritten. You could use the function you originally used to move the gadget to reset the position but the gadget would fly around the screen crazily. (The example below does not reset the position.)

    The "Move" control on this example is set to move the gadget as close as possible to the lower left corner of your screen.

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>test undock and move</title>
    <style type="text/css">
    <!--
    body {margin:0;width:130px;height:65px;background-color:#444;padding:5px;font:bold 12px/14px "Segoe UI";text-align:center;}
    #setDockState, #moveGadget {width:120px;padding:5px;background-color:#ccc;border:2px solid #222;cursor:pointer;}
    -->
    </style>
    <script type="text/jscript">
    var sysVersion=+System.Gadget.platformVersion.slice(4,5);
    function setText(){
     setDockState.innerText=(System.Gadget.docked)?"Undock":"Dock";
    }
    function dockUndock(){
     var wshShell=new ActiveXObject("WScript.Shell");
     if(sysVersion<7){
      if(System.Gadget.docked){wshShell.SendKeys("+{F10}D");}
      else{wshShell.SendKeys("+{F10}t");}
     }
     else{
      if(System.Gadget.docked){wshShell.SendKeys("+{F10}z{DOWN}~");}
      else{wshShell.SendKeys("+{F10}z~");}
     }
     wshShell=null;
    }
    function setPosition(){
     var scrLeft, scrTop, scrX, scrY, wshShell, mStepX, mStepY, moveX, moveY;
     scrLeft=window.screenLeft;
     scrTop=window.screenTop;
     scrX=screen.width;//not used in this example
     scrY=screen.height;
     mStepX=(sysVersion<7)?16:10;
     mStepY=(sysVersion<7)?12:10;
     wshShell=new ActiveXObject("WScript.Shell");
     moveX="LEFT "+Math.floor(scrLeft/mStepX);
     moveY="DOWN "+Math.floor((scrY-scrTop-document.body.offsetHeight)/mStepY);
     wshShell.SendKeys("+{F10}M{"+moveX+"}{"+moveY+"}~");
     wshShell=null;
    }
    function fx(){
     setDockState.onclick=dockUndock;
     moveGadget.onclick=setPosition;
    }
    System.Gadget.onUndock=function(){document.body.style.backgroundColor="#f00";setText();};
    System.Gadget.onDock=function(){document.body.style.backgroundColor="#444";setText();};
    </script>
    </head>
    <body onload="fx();">
    <div id="setDockState">Undock</div>
    <div  id="moveGadget">Move</div>
    </body>
    </html>


    • Edited by mystifeid Tuesday, May 15, 2012 6:04 AM
    • Marked as answer by Comotoz Tuesday, May 15, 2012 3:35 PM
    Tuesday, May 15, 2012 5:41 AM
  • Thank you! In spite of strangeness implementation of this method - it's working, so it's makes me happy.

    And one more little question - where i can look for complete list of gadget object reference - for example on msdn page (http://msdn.microsoft.com/en-us/library/windows/desktop/ff486357(v=vs.85).aspx) - there is no 

    "System.Gadget.platformVersion"

     
    Tuesday, May 15, 2012 3:45 PM
  • It's strange all right ! But while you are moving it, you can maybe make it do a few laps of your screen !

    For the platformVersion property, on the page you linked to, click on the link that says "System.Gadget" then on the page that appears, look under Properties.

    There are three main reference pages for gadgets - you already linked to the first one - Gadget Object Reference. The other two are System Object Reference and Presentation Object Reference

    Good luck !

    Tuesday, May 15, 2012 4:06 PM
  • Ooops... I've accidentally miss "platformVersion" in properties. My fault... About three reference pages - i know. Thank you.
    Tuesday, May 15, 2012 4:46 PM