Unable to Customise Context Menus in PowerPoint 2007?

I started working for a new client a couple of weeks ago. This client provides a customised solution for PowerPoint with many weird and wonderful functions. Part of the work I’m doing here is helping them migrate their solution to work with PowerPoint 2007.

While I’ve discovered many wacky behaviours that have come about due to the new rendering engine used in Office 2007, I hadn’t thrown my hands in the air and said “I can’t do it” until the other day. Something as simple as adding a button into a context menu when a user right-clicks a picture just would not work. There was already code in the project that did this for earlier version of PowerPoint, but no matter what I did it would not work for 2007.

Needless to say, I started seeking help, thinking that I was just missing something. Coatsie to the rescue! Well, sort of… 🙂

Unable to customise context menus in PowerPoint 2007

Andrew’s post basically shows how desperate I was by publishing my original email. Pathetic, hey…? 🙂

Anyway, the result was that you simply can’t do it. Adding items to the context menu is considered “feature depricated” so the new rendering engine forbids it and moves on. So how to overcome this? From Andrew’s post…

In summary, Microsoft recommends that you model your UI on Office’s own built-in Ribbon UI, specifically around the use of Contextual Tabs as the mechanism for displaying contextually relevant content. For each object type that the add-in supports, a tab could be added to the appropriate contextual tab set that would contain the Add-In-specific tools for working with that object. With this type of design, the UI would better match the UI of Office 2007, and the end-users could potentially not require much extra training on top of the training for Office 2007 itself. For more information, please check out the Office Fluent UI Style Guide at the Office Fluent Ribbon Developer Portal.

So the solution… Contextual Tab Sets! Now, I’m sure if I asked a room of 50 people what they were less than 2 would put their hand up. And googling it doesn’t help too much either.

In short, there are the regular tabs in the Office Ribbon, and Contextual Tabs. The regular tabs are the ones that are always there. The contextual ones are the ones that only show up when something has been selected in the designer. They’re usually highlighted a different colour too, so that they stand out.

One example of this is when you select a picture and a new Formatting tab pops up under the heading of Picture Tools. The Contextual Tab Set here is Picture Tools and the contextual tab is the Formatting tab.

One cool thing about the new Ribbon and all that Extensibility that’s provided for Office is that you can easily add (and remove) tabs in a contextual tab set. There are plenty of samples out there that do Ribbon customisation, especially on Office Fluent User Interface Developer Portal. Though, not many of them show how to do this.

I won’t go into creating a Ribbon Extensibility solution, instead I’ll just mention that all you have to do is create an Add-In for PowerPoint in Visual Studio (preferably 2008) with VSTO and override the Add-In’s CreateRibbonExtensibilityObject() method to return an object that implements IRibbonExtensibility. This object will implement the method GetCustomUI to return a string representation of the Ribbon XML.

Using the Custom UI XML, we can specify a Ribbon that simply adds a tab to any of these Contextual Tab Sets. The following snippet adds a “Custom” tab to the Drawing Tools tab set. The tab has a Hello World button in the Custom Group tab group.

<customUI xmlns=”http://schemas.microsoft.com/office/2006/01/customui”>
  <ribbon>
    <contextualTabs>
      <tabSet idMso=”TabSetDrawingTools”>
        <tab id=”TabCustom” label=”Custom”>
          <group id=”GroupCustomGroup” label=”Custom Group”>
            <button id=”ButtonHelloWorld” tag=”hello World” label=”Hello World”
                    screentip=”Displays a Hello World message box” onAction=”OnHelloWorld” />
          </group>
        </tab>
      </tabSet>
    </contextualTabs>
  </ribbon>
</customUI>

So once you have an add-in that provides a Ribbon representation similar to this, you will see that setting focus to a shape gives you the Drawing Tools Contextual Tab Set with the Formatting and Custom tabs.

According to the information Andrew received, this is basically the way to provide any contextual functionality in Office going forward. I still think it’s broken, but what can we do other than complain? 🙂

Advertisement

Posted on 18 May, 2008, in Uncategorized. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: