Dynamic Controls

The Ribbon is designed to be a static structure of tabs, groups, and controls; while you're working with Excel, all the controls in the Ribbon stay in the same place and have the same structure, size, and actions. The only parts of the Ribbon that could be considered dynamic are the contextual tabs, the Window list, and the File MRU — and even then, it's only the visibility of the contextual tabs that changes; their structure remains constant.

This philosophy is reflected in the design of RibbonX, with the restriction that your XML customization has to be defined up front and hard coded into your document files; you do not have a mechanism in VBA for providing the XML at run time. Indeed, if you agree with the philosophy, you wouldn't need to provide the XML at run time, because the getLabel, getImage, and other callbacks would be sufficient for any localization requirements.

There are, however, times when the philosophy breaks down—the Window menu is a built-in example. There might also be problems when migrating CommandBar code to use the Ribbon, if that code changed the command bar structures as workbooks were opened or closed, or worksheets were added and removed.

Fortunately, Microsoft recognized the requirement for a certain amount of dynamism in our UIs and provided four controls whose contents can be provided at run time. They are the comboBox, dropDown, gallery, and dynamicMenu controls. The content is provided using a set of callbacks, called when the controls are first displayed and when they're explicitly marked as invalid. They also have the extremely useful invalidateContentOnDrop attribute, which if true ensures the callbacks get called every time, just before the control is dropped down.

0 0

Post a comment