Application RegisterRibbonX vs Document CustomUI

Started by paulv45, August 27, 2010, 10:01:08 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

paulv45

Visio 2010 SDK has a ribbon UI example based on Application.RegisterRibbonX.
Most web searches seem to point to using the document CustomUI property and I have had some success doing this.
Does anyone have wisdom to share on one vs the other?  Are there apps where one would be preferred over the other?
Are they somehow related to each other?  
My app involves custom UI supporting code as VBA in a stencil.
Thanks -- Paul

paulv45

Here's what I have discovered so far.  This is what I think is true.  Certainly welcome other input.

Application.RegisterRibbonX and Document.CustomUI accomplish pretty much the same thing in different but related ways.
In both cases you supply an XML ribbon definition for your ribbon.  The XML is the same in both cases.
With Document.CustomUI you save-close-reopen the document for the ribbon to become active.
With Application.RegisterRibbonX the ribbon becomes active at registration time.
For Application.RegisterRibbonX you are overriding the ribbon load machinery to make it use your own ribbon.
For Document.CustomUI I think what is actually happen is the built-in Application.RegisterRibbonX loads the ribbon defined by Document.CustomUI when the document opens.  In Document.CustomUI the ribbon actually becomes part of the drawing file.

The ribbon implementation involves a host of callbacks.  One gotcha I discovered is that the procedure signatures used when Document.CustomUI is being used are slightly different from those when you are using Application.RegisterRibbonX.  I have no explanation for this but it appears to be true.  One place the signatures are identified is: http://msdn.microsoft.com/en-us/library/ee691833.aspx where you use the VBA ones when using Document.CustomUI and the Visual Basic ones for Application.RegisterRibbbonX.

Hope this is accurate and helpful to others.
Paul

paulv45

I think I have discovered a problem with RegisterRibbonX if you want to repurpose commands.
The SDK example shows:
Public Sub CommandOnAction(ByVal control As IRibbonControl, _
   ByVal cancelDefault As Boolean)
as an example of a callback for repurposing standard Visio commands.
This appears to work except that since the signature for cancelDefault is ByVal and needs to be ByRef if you really want to pass the value back.
Indeed True/False has no effect on operation for me.  (Note also the SDK example has True/False reversed in its documentation, I think)
Just changing it to ByRef causes the callback never to fire -- assuming this is because it doesn't pass signature muster.
The CustomUI version is:
Public Sub CommandOnAction(ByVal control As IRibbonControl, ByRef cancelDefault)
and appears to work correctly.
The default for the RegisterRibbonX is CancelDefault=True and the behavior is that the default action is in fact canceled.  If this is what you want, you should be fine.  If not, your might try CustomUI or actually calling the default behavior from your repurpose if you can figure out how to do that.
Am I missing something that others have discovered that works?
Thanks -- Paul