Conserve Toolbar button HelpID ? (Was: Re: [api-dev] BASIC: Change toolbar button icon ?)

Cor Nouws <[email protected]>
Newsgroups gmane.comp.openoffice.devel.api
Message-ID <[email protected]>
Hi *,

A question related to an old thread.
I first quote the useful piece of code form Carsten, so that is clear 
where I talk about.

Carsten Driesner wrote (29-10-09 10:50)

> 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" )


Further on in this thread, Jan Hols Jensen posted a solution for his 
case, using the following

   > For J = 0 To UBound(ToolbarButtonProps())
   >   If ToolbarButtonProps(J).Name = "CommandURL" Then
   >     ToolbarButtonProps(J).Value = NewURL
   >   End If
   > Next

to change an existing button.
This works, however I find no way to keep the tool tip. which I guess is 
the HelpID.

Found this issue in IssueTracker, happening to offer a patch too:
http://qa.openoffice.org/issues/show_bug.cgi?id=91174

Could this indeed be a bug?

Regards,

Cor


> 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


-- 
  - giving openoffice.org its foundation :: The Document Foundation -
  - ideas/remarks for the community council? See
    http://wiki.services.openoffice.org/wiki/Community_Council
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.