Tobias Krais wrote:
Hi all, esp. Carsten,
you had a look at this bug some weeks ago. At the moment this bug hurts
:-). Let me tell you why and maybe you can help me to find a workaround.
I want to add a toolbar item transient. My Addons.xcu is the same as the
one in the Bug. If I add this CommandURL to the toolbar, there is no
image, only Text (looks not that nice :-(). How can I add a toolbar item
transient, with a picture on it?
Is there a possiblity, to add a toolbar item via addons.xcu invisible?
So that I can make it transient visible with an icon on it?
Hi Tobias,
Sorry for the late answer but I was in vacation. We agreed that issue
72119 is an enhancement (images defined inside Addons.xcu are normally
only retrieved by add-on toolbars/menus), but I can totally understand
you that you want to get this implemented.
I can propose a way to set an image for your command. Look at the
following Basic example which associate an image for a Basic macro.
Regards,
Carsten
--
Carsten Driesner (cd) - Project Lead OpenOffice.org Framework
Framework wiki: http://wiki.services.openoffice.org/wiki/Framework
OpenOffice.org Engineering at Sun: http://blogs.sun.com/GullFOSS
---- Example ----
REM ***** BASIC *****
REM *** This example creates a new basic macro toolbar button on
REM *** the Writer standard bar. It doesn't add the button twice.
REM *** It uses the Writer image manager to set an external image
REM *** for the macro toolbar button.
Sub Main
REM *** String to reference toolbar
sToolbar = "private:resource/toolbar/standardbar"
REM *** Macro command to add
sMyToolbarCmdId = "macro:///Standard.Module1.Test()"
REM *** Retrieve the module configuration manager from central module
configuration manager supplier
oModuleCfgMgrSupplier =
createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
REM *** Retrieve the module configuration manager with module identifier
REM *** See com.sun.star.frame.ModuleManager for more information
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager(
"com.sun.star.text.TextDocument" )
oImageMgr = oModuleCfgMgr.getImageManager()
oToolbarSettings = oModuleCfgMgr.getSettings( sToolbar, true )
REM *** Look for our button. Can be identified by the CommandURL
property.
bHasAlreadyButton = false
nCount = oToolbarSettings.getCount()
for i = 0 to nCount-1
oToolbarButton() = oToolbarSettings.getByIndex( i )
nToolbarButtonCount = ubound(oToolbarButton())
for j = 0 to nToolbarButtonCount
if oToolbarButton(j).Name = "CommandURL" then
if oToolbarButton(j).Value = sMyToolbarCmdId
then
bHasAlreadyButton = true
end if
endif
next j
next i
Dim oImageCmds(0)
Dim oImages(0)
REM *** Check if image has already been added
if not oImageMgr.hasImage( 0, sMyToolbarCmdId ) then
REM *** Try to load the image from the file URL
oImage = GetImageFromURL( "file:///c:/test.bmp" )
if not isNull( oImage ) then
REM *** Insert new image into the Writer image manager
oImageCmds(0) = sMyToolbarCmdId
oImages(0) = oImage
oImageMgr.insertImages( 0, oImageCmds(), oImages() )
end if
end if
if not bHasAlreadyButton then
sString = "My Macro's"
oToolbarItem = CreateToolbarItem( sMyToolbarCmdId,
"Standard.Module1.Test" )
oToolbarSettings.insertByIndex( nCount, oToolbarItem )
oModuleCfgMgr.replaceSettings( sToolbar, oToolbarSettings )
end if
End Sub
Function GetImageFromURL( URL as String ) as Variant
Dim oMediaProperties(0) as new com.sun.star.beans.PropertyValue
REM *** Create graphic provider instance to load images from external
files
oGraphicProvider = createUnoService(
"com.sun.star.graphic.GraphicProvider" )
REM *** Set URL property so graphic provider is able to load the image
oMediaProperties(0).Name = "URL"
oMediaProperties(0).Value = URL
REM *** Retrieve the com.sun.star.graphic.XGraphic instance
GetImageFromURL = oGraphicProvider.queryGraphic( oMediaProperties() )
End Function
Function CreateToolbarItem( Command as String, Label as String ) as Variant
Dim aToolbarItem(3) as new com.sun.star.beans.PropertyValue
aToolbarItem(0).Name = "CommandURL"
aToolbarItem(0).Value = Command
aToolbarItem(1).Name = "Label"
aToolbarItem(1).Value = Label
aToolbarItem(2).Name = "Type"
aToolbarItem(2).Value = 0
aToolbarItem(3).Name = "Visible"
aToolbarItem(3).Value = true
CreateToolbarItem = aToolbarItem()
End Function
Sub Test
MsgBox "Test"
End Sub
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]