StarOffice software add-ins and extensions are often integrated into StarOffice's menus and
toolbars so users can employ the functionality. This article introduces a new API in the StarOffice 8 Software Development Kit (SDK) that enables you to do that integration. Note: This API is not available in StarOffice 7 or OpenOffice.org 1.1.
Contents
Before you begin Download the complete TextDemo.java sample application used in the article Programming With the StarOffice 8 Software Development Kit. If you are not familiar with the StarOffice SDK, first read the article. It describes how to set up a Java environment to use StarOffice APIs. It also describes how to use StarOffice functionality in a Java application. A sample application is available: createMenuAndToolbar.java Using the UI Configuration Managers
The Menu and Toolbar API provides full access to all elements of the StarOffice software's menu, toolbar, and keyboard-shortcut configuration. This enables you to
The Service
Each UI Configuration Manager provides the Creating a Top-Level Menu
A menu is a tree structure of menu elements that starts with a root element. This has a container of menu elements, which could have another container of elements. In other words, a top-level menu has a menu which could have other (sub-) menus. A familiar example is the File > New menu/submenu.
The root structure for the menu is a MenuProperty[0] = new PropertyValue(); MenuProperty[0].Name = "CommandURL"; MenuProperty[0].Value = ".uno:SunDC"; MenuProperty[1] = new PropertyValue(); MenuProperty[1].Name = "Label"; MenuProperty[1].Value = "Sun Developer Connection"; MenuProperty[2] = new PropertyValue(); MenuProperty[2].Name = "Type"; MenuProperty[2].Value = 0; MenuProperty[3] = new PropertyValue(); MenuProperty[3].Name = "ItemDescriptorContainer"; MenuProperty[3].Value = xCfgMgrFactory.createInstanceWithContext( xContext );
This
The itemProperty[0] = new PropertyValue(); itemProperty[0].Name = "CommandURL"; itemProperty[0].Value = "macro:///Standard.Module1.myMacro()"; itemProperty[1] = new PropertyValue(); itemProperty[1].Name = "Label"; itemProperty[1].Value = "myMacro"; itemProperty[2] = new PropertyValue(); itemProperty[2].Name = "Type"; itemProperty[2].Value = 0;
The structures for the root element and for a menu item are now defined. The next step is to apply it to the StarOffice menu structure, using the
IndexContainer topLevelMenu = (XIndexContainer)
UnoRuntime.queryInterface(
XIndexContainer.class,
topLevelMenuProperty[3].Value );
topLevelMenu.insertByIndex( 0, menuItemProperty );
The method
However, the menu has not yet been applied to the StarOffice menu. This is done by the
XIndexContainer xCfgMgrContainer = (XIndexContainer)
UnoRuntime.queryInterface( XIndexContainer.class,
xCfgMgrFactory );
xCfgMgrContainer.insertByIndex(
xAllMenuesFactory.getCount(),
topLevelMenuProperty );
After doing this, the new menu still does not show up: The user interface setting is just a copy of the menu setting. This new menu setting has to replace the settings that are currently used. Do this with the The new menu is now available for all text documents. Creating a Toolbar
The internal structure of a toolbar is simpler than a menu, as toolbars cannot have sub-toolbars. The image on a toolbar button must be accessible however, or there can be problems in acquiring the image. To avoid this, you can "recycle" an image from the large number of images that StarOffice provides, as this article does. Any Portable Network Graphic (PNG) image of the right size is acceptable. The list of existing images (with their URLs) can be determined in Tools > Customize. Choose the Toolbars tab, then select Modify > Change Icon. Hover with your pointer over the icon you like, and its tooltip help will show the internal StarOffice URL.
To use an image on a toolbar, retrieve the image manager with the
XImageManager xImgMgr = (XImageManager)
UnoRuntime.queryInterface( XImageManager.class,
xCfgMgr.getImageManager());
String[ ] imgURL = new String[1];
imgURL[0] = ".uno:CloseDoc";
n
XGraphic[ ] xGraphic = xImgMgr.getImages( ((short) 0), imgURL );
String[ ] imgCmd = new String[1];
imgCmd[0] = "macro:///Standard.Module1.myMacro()";
xImgMgr.insertImages( ((short) 0), imgCmd, xGraphic );
The
The property
XPropertySet xToolbarProperties = (XPropertySet)
UnoRuntime.queryInterface( XPropertySet.class,
xNewToolbarFactory );
xToolbarProperties.setPropertyValue("UIName", "SunDC Toolbar" );
The
XSingleComponentFactory xCfgMgrFactory = (XSingleComponentFactory)
UnoRuntime.queryInterface(
XSingleComponentFactory.class,
xNewToolbarFactory );
XIndexContainer xCfgMgrContainer = (XIndexContainer)
UnoRuntime.queryInterface( XIndexContainer.class,
xNewToolbarFactory );
xCfgMgrContainer.insertByIndex( 0, toolbarItemProperty );
This completes the definition of a new toolbar. The next step makes the toolbar available to
the other toolbars. In contrast to the Making New Menus and Toolbars Persistent
The new menu and toolbars are not persistent. They disappear when StarOffice is closed. Use the Summary
This article shows how to create new menus and toolbars using the StarOffice SDK. It also shows you how to integrate these new interfaces in the StarOffice display, and how to make them persistent. For More Information
Programming with the StarOffice 8 Software Development Kit About the Author
Kay Koll is a technical marketing specialist for Desktop Solutions at Sun Microsystems in Hamburg, Germany. | |||||||||||||||||||
|
| ||||||||||||