Conditionally Displaying Custom Ribbon UI Tab

C

ckapilla

Hi,

I am working on a fairly complex Word Add-in that uses its own document
types (not .doc/.docx). In Word 2002/2003 we were able to show/hide our
custom toolbars programmatically based upon the document type that was being
edited. Using the Ribbon call-backs, is there any way to do this? Word itself
is able to do it because it adds the Add-Ins tab only when appropriate.
Perhaps another way to ask my question is, is there any way to determine when
the Add-Ins tab is visible?

thanks in advance for any help,

Chris
 
S

SvenC

Hi,
I am working on a fairly complex Word Add-in that uses its own
document types (not .doc/.docx). In Word 2002/2003 we were able to
show/hide our custom toolbars programmatically based upon the
document type that was being edited. Using the Ribbon call-backs, is
there any way to do this? Word itself is able to do it because it
adds the Add-Ins tab only when appropriate. Perhaps another way to
ask my question is, is there any way to determine when the Add-Ins
tab is visible?

You basically do this with callbacks. First you need to add the onLoad
attribute to your customUI element. That method is called back after the
ribbon was loaded, and it gets a IRibbonUI interface pointer as parameter.
Save that interface pointer for later use. You can call Invalidate or
InvalidateControl on the interface, to tell the whole ribbon or individual
controls, that they should query their state.
On your controls you need to add attributes like getVisible to specify
additional callbacks instead of fixed values like visible="false". Initially
all the callbacks are called and afterwards they are called when you use the
Invalidate methods.

Start with this article, to see what attributes are available and how to add
callback handlers:

http://msdn2.microsoft.com/en-us/library/aa338202.aspx
 
P

Patrick Schmid [MVP]

Implement the getVisible for your tab and the getEnabled callback for
all groups and items (if defined for an item). Then when you want to
hide it, return false for the getVisible and getEnabled callbacks,
otherwise true. You have to disable all items besides just hiding the
tab, because commands will be accessible via the QAT and the QAT
Customization dialog even if a tab is hidden. So disabling them prevents
a user from using functions he or she shouldn't have available.

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Outlook 2007 Performance Update: http://pschmid.net/blog/2007/04/13/105
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://ribboncustomizer.com
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed
 
C

ckapilla

Thanks for your reply; however my real problem is not about how to use
callbacks -- it is how to determine _inside_ the callback routine, what it
should return! i.e., how can I determine during the call-back what document
type was being edited in the instance of Word that issued the callback.

I have access to the Application object and the documents collection, so it
seems like that should do the trick, but I haven't seen how to determine who
the caller is.
 
C

ckapilla

thanks for your reply and those details, but please see my response to Sven
above -- I think our posts crossed in-transit.
 
S

SvenC

Thanks for your reply; however my real problem is not about how to use
callbacks -- it is how to determine _inside_ the callback routine,
what it should return! i.e., how can I determine during the call-back
what document type was being edited in the instance of Word that
issued the callback.

I have access to the Application object and the documents collection,
so it seems like that should do the trick, but I haven't seen how to
determine who the caller is.

Application.ActiveDocument gets you the current document. Does that help
you?
 
C

ckapilla

doh!

wish I could remove this thread to hide the evidence of this!

thanks for your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top