none
PPT: Event when user changes viewtype

    Frage

  • Hi

    Is there a way to now when a user changes to the different views in Powerpoint 07/10? I have a vsto plugin which doesn't work in some of the views; Hand Out, Slide Sorter and Reading view. I wan't to hide my plugin when entering these views.

    thanks in advance,
    Martin

    Mittwoch, 29. Februar 2012 13:01

Antworten

  • Hi Martin,

    You need to consider Andrei's suggestion, which seems to me the only way to go. Add a Ribbon XML item for your VSTO add-in, and then re-purpose some built-in controls, you can refer to the code below:

    The XML part:

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <commands >
        <command idMso="ViewNormalViewPowerPoint" onAction ="NormalView_click"/>
        <command idMso ="ViewSlideSorterView" onAction="SorterView_click"/>
        <command idMso ="ViewNotesPageView" onAction ="NoteView_click"/>
      </commands>
      <ribbon>
        <tabs>
          <tab idMso="TabAddIns">      
            <group id ="group2"  label ="Group2" getVisible ="group_getVisible">
              <button id ="button2" label ="Button2"/>
              <button id ="button3" label ="Button3"/>
              <button id ="button4" label ="Button4"/>
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

    The Callbacks for the controls:

      private bool isVisible = true;
            public void SorterView_click(Office.IRibbonControl control, bool pressed, ref bool cancel)
            {
                isVisible = ! pressed;
                ribbon.InvalidateControl("group2");
                cancel = false;
            }
    
            public void NoteView_click(Office.IRibbonControl control, bool pressed, ref bool cancel)
            {
                isVisible = ! pressed;
                ribbon.InvalidateControl("group2");
                cancel = false;
            }
            public void NormalView_click(Office.IRibbonControl control, bool pressed, ref bool cancel)
            {
                isVisible = true;
                ribbon.InvalidateControl("group2");
                cancel = false;
            }  
            public bool group_getVisible(Office.IRibbonControl control)
            {
                return isVisible;
            }

    I assume that the meaning of you said "hide plugin" is making certain group invisible, this is why assign a Callback for the group control. If you mean something others, you can also implement this customization within these re-purpose procedures.

    I hope this helps.


    Calvin Gao[MSFT]
    MSDN Community Support | Feedback to us

    • Als Antwort markiert MartinMyth Donnerstag, 8. März 2012 09:30
    Donnerstag, 1. März 2012 09:08
  • Hi Martin,

    Sorry for not explaining this on my last reply.

    The technology we are using is called re-purposing built-in control, and to make it work, we need to know two things: idMso and callback signature.

    For idMso, you can download files from this site:

    http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=6627 (2010)

    http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=3582 (2007)

    For signatures, if the control is a toggle button, the signature should be:

    public void MethodName (IRibbonControl control, bool pressed, ref bool cancel)
    {
    
    }

    and if the control is a button, the signature should be:

    public void MethodName(IRibbonControl control, ref bool cancel)
    {
    }

    If you want to make your add-in work in both Office 2007 and 2010, you should be aware of that is not supported by VSTO, you can refer to this blog for more information:

    http://blogs.msdn.com/b/andreww/archive/2007/06/15/can-you-build-one-add-in-for-multiple-versions-of-office.aspx 

    I hope this helps.


    Calvin Gao[MSFT]
    MSDN Community Support | Feedback to us


    Montag, 5. März 2012 09:36
  • This is another possible approach to this. Hook into PowerPoint events

    - WindowActivate which can be used to check the view type.

    - SlideShowBegin/ SlideShowEnd 

    WindowActivate should work for detecting all views except the reading view which is not really a view but a slideshow running in a window with the ribbon hidden.


    Regards, Shyam

    • Als Antwort markiert MartinMyth Dienstag, 20. März 2012 15:12
    Freitag, 16. März 2012 14:55

Alle Antworten

  • Hello,

    There's no such event. I'd try to intercept clicking the corresponding Ribbon toggle buttons as described in Temporarily Repurpose Commands on the Office Fluent Ribbon.


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Mittwoch, 29. Februar 2012 13:56
  • Hi Martin,

    You need to consider Andrei's suggestion, which seems to me the only way to go. Add a Ribbon XML item for your VSTO add-in, and then re-purpose some built-in controls, you can refer to the code below:

    The XML part:

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <commands >
        <command idMso="ViewNormalViewPowerPoint" onAction ="NormalView_click"/>
        <command idMso ="ViewSlideSorterView" onAction="SorterView_click"/>
        <command idMso ="ViewNotesPageView" onAction ="NoteView_click"/>
      </commands>
      <ribbon>
        <tabs>
          <tab idMso="TabAddIns">      
            <group id ="group2"  label ="Group2" getVisible ="group_getVisible">
              <button id ="button2" label ="Button2"/>
              <button id ="button3" label ="Button3"/>
              <button id ="button4" label ="Button4"/>
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

    The Callbacks for the controls:

      private bool isVisible = true;
            public void SorterView_click(Office.IRibbonControl control, bool pressed, ref bool cancel)
            {
                isVisible = ! pressed;
                ribbon.InvalidateControl("group2");
                cancel = false;
            }
    
            public void NoteView_click(Office.IRibbonControl control, bool pressed, ref bool cancel)
            {
                isVisible = ! pressed;
                ribbon.InvalidateControl("group2");
                cancel = false;
            }
            public void NormalView_click(Office.IRibbonControl control, bool pressed, ref bool cancel)
            {
                isVisible = true;
                ribbon.InvalidateControl("group2");
                cancel = false;
            }  
            public bool group_getVisible(Office.IRibbonControl control)
            {
                return isVisible;
            }

    I assume that the meaning of you said "hide plugin" is making certain group invisible, this is why assign a Callback for the group control. If you mean something others, you can also implement this customization within these re-purpose procedures.

    I hope this helps.


    Calvin Gao[MSFT]
    MSDN Community Support | Feedback to us

    • Als Antwort markiert MartinMyth Donnerstag, 8. März 2012 09:30
    Donnerstag, 1. März 2012 09:08
  • hi guys, it seems like this solves my problem. But for me to show and hide the plugin correctly in all views (not the xml group but the layout I insert on the right sidebar) I need to know all the view type idMSO. 

    I can see that the Reading View is new to 2010, and my plugin should work for both 2007 and 2010. Will the plugin crash if I add a command with idMSO that doesn't match in 2007?

    I found some idMSO on this page for 2007:http://msdn.microsoft.com/en-us/library/dd953379(v=office.12).aspx 

    And I found out that I can go to File->Options->Customize Ribbon and hover over the view to find the idMSOs in 2010. But I can't get the ViewSlideShowReadingView to work. When I add this line of code in the ribbon.xml: <command idMso ="ViewSlideShowReadingView" onAction ="ReadingView_click"/> and implement the callback ReadingView_click like the following, nothing happens.

    public void ReadingView_click(MSOffice.IRibbonControl control, bool pressed, ref bool cancel)
    {
                isVisible = !pressed;
                ribbon.InvalidateControl("myGroup");
                cancel = false;
    }

    The view in Powerpoint doesn't change to the reading view and no breakpoints hits in my code. If I leave the ViewSlideShowReadingView out of the xml the Reading View work again. Is there a bug when re-purpose the Reading view?

    Montag, 5. März 2012 08:33
  • Hi Martin,

    Sorry for not explaining this on my last reply.

    The technology we are using is called re-purposing built-in control, and to make it work, we need to know two things: idMso and callback signature.

    For idMso, you can download files from this site:

    http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=6627 (2010)

    http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=3582 (2007)

    For signatures, if the control is a toggle button, the signature should be:

    public void MethodName (IRibbonControl control, bool pressed, ref bool cancel)
    {
    
    }

    and if the control is a button, the signature should be:

    public void MethodName(IRibbonControl control, ref bool cancel)
    {
    }

    If you want to make your add-in work in both Office 2007 and 2010, you should be aware of that is not supported by VSTO, you can refer to this blog for more information:

    http://blogs.msdn.com/b/andreww/archive/2007/06/15/can-you-build-one-add-in-for-multiple-versions-of-office.aspx 

    I hope this helps.


    Calvin Gao[MSFT]
    MSDN Community Support | Feedback to us


    Montag, 5. März 2012 09:36
  • Thanks Calvin! Working with the new signature (you missed the type declaration of cancel)

    One, maybe last, question: When going to Reading view state I see that the Normal View toggle button is still active just before the view goes fullscreen. this means that I don't know when the user exists the Reading View as I don't get any callbacks. Is there a workaround for this?

    Montag, 5. März 2012 10:19
  • How do I attach to the slideshow of the Reading view? 
    Dienstag, 6. März 2012 14:10
  • Thanks Calvin! Working with the new signature (you missed the type declaration of cancel)

    One, maybe last, question: When going to Reading view state I see that the Normal View toggle button is still active just before the view goes fullscreen. this means that I don't know when the user exists the Reading View as I don't get any callbacks. Is there a workaround for this?

    Hi,

    My previous made a mistake, I have already deleted it.

    Actually you can use Application.SlideShowEnd event to notify your add-in to enable some functionalities, you can register the event handler in ThisAddIn Class, see:

      private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                this.Application.SlideShowEnd += new PowerPoint.EApplication_SlideShowEndEventHandler(Application_SlideShowEnd);
            }
    
            void Application_SlideShowEnd(PowerPoint.Presentation Pres)
            {
                myRibbon.isVisible = true;
                myRibbon.ribbon.InvalidateControl("group2");
            }

    In addition, I wrote a simple sample for you, you can download from here:

    PARibbonGeneral (as I don't know what kind of functionality you want to disable and enable when changing view type, I use a simple ribbon group to demonstrate)

    I hope this helps and if you further question on this, please feel free to let me know.


    Calvin Gao[MSFT]
    MSDN Community Support | Feedback to us

    Mittwoch, 7. März 2012 03:43
  • Thanks for helping me out, Calvin. I have everything I need regarding this topic. 

    For others going from Ribbon Visual designer to Ribbon XML these topics might help you out:

    Donnerstag, 8. März 2012 09:35
  • For signatures, if the control is a toggle button, the signature should be:

    public void MethodName (IRibbonControl control, bool pressed, ref bool cancel)
    {
    
    }

    and if the control is a button, the signature should be:

    public void MethodName(IRibbonControl control, ref bool cancel)
    {
    }

    Calvin Gao[MSFT]
    MSDN Community Support | Feedback to us


    Hi again Calvin. When we are at it, where do I find documentation about the signatures for all control types? At least, what I'm looking for now is to repurpose the TabRecent control type, found on the File menu. And if it's possible to repurpose the File menu click, any hints would be appreciated. 

    Donnerstag, 8. März 2012 15:30
  • Hi again,

    I'm afraid you couldn't re-purpose built-in controls other than buttons and toggle buttons. You can have a look at this document for all the signatures for callbacks from ribbon XML (including re-purpose):

    http://msdn.microsoft.com/en-us/library/aa722523(v=office.12).aspx

    I hope this helps.

    In addition, thanks for the information you provided;) yes, using Ribbon Designer is much more easier in some aspects, such as designing, changing status and so on, however, there are several things Ribbon Designer unable to implement, which includes repurposing, changing backstage, using idQ and so on. This is why I prefer working with Ribbon XML through it's complicate ;) (also it's convenient to demonstrate on forum)

    Good day,


    Calvin Gao[MSFT]
    MSDN Community Support | Feedback to us

    Freitag, 9. März 2012 07:19
  • Hi, I'm afraid a new thing just came up regarding this topic. There are also view type buttons on the status bar, and when clicking those I don't get any callbacks. Is it possible, one way or another, to hook up on these buttons too?
    Mittwoch, 14. März 2012 08:54
  • Hello,

    Try to identify the view change by handling the CommandBars.OnUpdate event. As far as I understand this event, it occurs really often and this can be used to identify changes if there are no events associated with such changes. For instance, I used this event to get notified about user actions on Excel shapes. There're no events associated with actions such as "move a shape", "group/ungroup shapes", "select a shape" etc; but because the event occurs almost constantly, you can check the view state whenever the event occurs.

    Can you please let me know whether this approach works for you?


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Mittwoch, 14. März 2012 09:25
  • Hi Andrei,

    I've added the CommandBars.OnUpdate event. It also fires when the view is changing, but I find that the event is no longer firing after I've added my CustomTaskPane (sidepanel). Has the CommandBar object changed or something? I tried to subscribe to that event again when my CustomTaskPane.VisibleChanged event is firing, but nothing happens. 

    Any idea?

    Donnerstag, 15. März 2012 09:45
  • Hello,

    I suppose you need to re-check your code.


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader

    Please mark answers and useful posts to help other developers use the forums efficiently.

    Donnerstag, 15. März 2012 11:27
  • Hi Martin,

    Sorry for not explaining this on my last reply.

    The technology we are using is called re-purposing built-in control, and to make it work, we need to know two things: idMso and callback signature.

    For idMso, you can download files from this site:

    http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=6627 (2010)

    http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=3582 (2007)

    For signatures, if the control is a toggle button, the signature should be:

    public void MethodName (IRibbonControl control, bool pressed, ref bool cancel)
    {
    
    }

    and if the control is a button, the signature should be:

    public void MethodName(IRibbonControl control, ref bool cancel)
    {
    }

    If you want to make your add-in work in both Office 2007 and 2010, you should be aware of that is not supported by VSTO, you can refer to this blog for more information:

    http://blogs.msdn.com/b/andreww/archive/2007/06/15/can-you-build-one-add-in-for-multiple-versions-of-office.aspx 

    I hope this helps.


    Calvin Gao[MSFT]
    MSDN Community Support | Feedback to us


    Hi Calvin

    I don't get any callback for Notes Page, Slide Master, Handout Master or Notes Master in Office 2007. In Office 2010 it work great. In both versions the signatures should be the same since these buttons are ToggleButtons, right? I've checked the idMSO documents for both versions and on these view buttons I can't find any change.

    The Normal and Slide Sorter callbacks works fine in Office 2007 and 2010, with the same signatures. Am I doing something wrong?

    I got this confirmed by creating a completely new 2007 add-in and by repurpose all view buttons

    Donnerstag, 15. März 2012 14:32
  • This is another possible approach to this. Hook into PowerPoint events

    - WindowActivate which can be used to check the view type.

    - SlideShowBegin/ SlideShowEnd 

    WindowActivate should work for detecting all views except the reading view which is not really a view but a slideshow running in a window with the ribbon hidden.


    Regards, Shyam

    • Als Antwort markiert MartinMyth Dienstag, 20. März 2012 15:12
    Freitag, 16. März 2012 14:55
  • This is another possible approach to this. Hook into PowerPoint events

    - WindowActivate which can be used to check the view type.

    - SlideShowBegin/ SlideShowEnd 

    WindowActivate should work for detecting all views except the reading view which is not really a view but a slideshow running in a window with the ribbon hidden.


    Regards, Shyam

    Since my code is running on both 2007 and 2010 this is the only solution that works for me. Repurposing in 2007 is buggy and doesn't work as intended, so to detect view type changes the windowActivate is the event to do this type of handling. The event is called when switching between documents (I do a check on Presentation.FullName) and when changing views (Note that Reading view needs special handling in Office 2010).

    Thanks Shyam.

    Dienstag, 20. März 2012 15:11