none
toggle on/off togglebutton in word ribbon

    Question

  • Dear all,

    I have several buttons and  togglebutton in Word Ribbon XML. I am experiencing problem to toggle off togglebutton right after other button has been clicked. Well, I can send ESC Key to toggle off the togglebutton but then the action perform by other button (onAction) callback will not work ( e.g. OpenFileDialog will immediatedly closed) when the togglebutton is toggled off.

    Sending Esc key might word  if I can check the status of the toggle button (on/off). Is there anyway to accomplish this? I add onAction callback function to the togglebutton, but it is not executed ( Perhaps  since the togglebutton is associated with Word build- in function).

    Thanks in advance.

                    <button id="buttonAttach" 
                        size="large" 
                        label ="Attach" 
                        screentip="Attach"   
                        supertip="Attach files to document" 
                        getEnabled="GetButtonEnabled" 
                        onAction="OnButtonAttach" 
                        imageMso="AttachFile" /> 
     
                    <toggleButton idMso="InkFeltTipPen"    
                        size="large" />  
    Tuesday, February 17, 2009 11:26 AM

Answers

  • Hi Santus

    I'm not 100% sure I understand, so I'm going to restate your problem and you check whether I've got it right:

    You have a Ribbon in which (at least) two controls are defined: a button and a toggle button (as you show in the XML code). When someone clicks the button, you want to be sure the toggle button is "off"?

    If this is a built-in control, then you should be able to toggle it off by sending the appropriate command to the object model. I'm not really familiar with the inking part of the Word, and it's not really covered well in the object model, so I don't recognize what the idMso InkFeltTipPen should do. Does this turn inking on/off? (Inking doesn't "belong" to Word, it's something from Windows, so there's not much support in the object model.)

    If you start Word as an end-user, then run the macro recorder, click this button, stop the macro recorder, then look at the macro it recorded - with any luck you can see what object and method the button is associated with. You should be able to access the macro recorder through Word's Developer tab in the Ribbon. (I can't do this for you because inking only works with a Tablet, and this machine isn't a tablet.)

    If that doesn't yield anything, rather than sending Esc with SendKeys you could try the Alt+[letter] keyboard shortcut assigned to the button. As an end-user, if you press Alt, you'll see letters next to the Ribbon elements. locate the Tab+Control combination for this button. (For example: Alt+R, M triggers the "New Comment" button in the Review tab.)

    If all of this is still doesn't help, you may need to find out how to toggle inking through the Windows API. You might try the Innovate on Office forum for that.
    Cindy Meister, VSTO/Word MVP
    Tuesday, February 17, 2009 12:16 PM
    Moderator

All replies

  • Hi Santus

    I'm not 100% sure I understand, so I'm going to restate your problem and you check whether I've got it right:

    You have a Ribbon in which (at least) two controls are defined: a button and a toggle button (as you show in the XML code). When someone clicks the button, you want to be sure the toggle button is "off"?

    If this is a built-in control, then you should be able to toggle it off by sending the appropriate command to the object model. I'm not really familiar with the inking part of the Word, and it's not really covered well in the object model, so I don't recognize what the idMso InkFeltTipPen should do. Does this turn inking on/off? (Inking doesn't "belong" to Word, it's something from Windows, so there's not much support in the object model.)

    If you start Word as an end-user, then run the macro recorder, click this button, stop the macro recorder, then look at the macro it recorded - with any luck you can see what object and method the button is associated with. You should be able to access the macro recorder through Word's Developer tab in the Ribbon. (I can't do this for you because inking only works with a Tablet, and this machine isn't a tablet.)

    If that doesn't yield anything, rather than sending Esc with SendKeys you could try the Alt+[letter] keyboard shortcut assigned to the button. As an end-user, if you press Alt, you'll see letters next to the Ribbon elements. locate the Tab+Control combination for this button. (For example: Alt+R, M triggers the "New Comment" button in the Review tab.)

    If all of this is still doesn't help, you may need to find out how to toggle inking through the Windows API. You might try the Innovate on Office forum for that.
    Cindy Meister, VSTO/Word MVP
    Tuesday, February 17, 2009 12:16 PM
    Moderator
  • Hi Cindy,

    Thank you for the quick reply. Yes, you got my question right. Recording Macro unfortunately doesn't yield anything. I have tried sending the shortcut Alt+Y  for the tab and F+1 for inking (I have to send F+1 twice). It works find when the inking is already toggled on, otherwise it will show blinking as the inking is toggled on and off immediately. However, it is much better than sending Esc key. 

    I have a convern though, will the shortcuts (e.g Alt+Y for my tab) will always be the same in every machine?

    Thanks in advance
    Wednesday, February 18, 2009 1:10 AM
  • Sending F+1 seems to generate text F1 in the document, however sending F3 seems to fix the problem. Does anyone know what F3 is used for? I'm afraid it might generate other problem that I'm not aware of.
    Wednesday, February 18, 2009 5:08 AM
  • <<I have a convern though, will the shortcuts (e.g Alt+Y for my tab) will always be the same in every machine?>>

    No, these shortcuts are not guaranteed. If there are conflicts, then Word will change them. If you're creating your own Tab you can control the shortcut assignments within that tab. Then your only concern would be whether another add-in creates a Tab and assigns it the same shortcut.

    You can assign a keyboard shortcut by assigning the keytip attribute in the ribbon XML. Then you should be able to get something with one letter (instead of two letters - F1). Take a very close look at what keytips are displayed after you've pressed Alt+Y. You want to choose one that's not visible (used by another control).


    Cindy Meister, VSTO/Word MVP
    Wednesday, February 18, 2009 11:28 AM
    Moderator