Ich bin gerade an einem Basic Skript um über XContextMenuInterceptor das Kontextmenü (Rechtsklick Menü) um Elemente zu erweitern.
Dies gelingt mir inzwischen soweit, dass ich TriggerAction und TriggerActionSeparator Elemente einfügen kann und das entsprechende Makro aufgerufen wird.
Schön wäre es jetzt, auch ein Icon den Elementen voranstellen zu können und hier stoße ich auf Verständnisprobleme.
Das TriggerAction bietet für Icons das Attribut "Image" welchen mit den Datentype (?) com::sun:
Wie ich nun ein Image XBitmap zuweisen kann bleibt mir aber bisher schleierhaft, da ich bisher nichts darüber finden konnte, wie XBitmap die Bilder verwaltet.
Auch der Versuch, das Bild über den ImageManager zur Verfügung zu stellen, wie man es z.B. für Toolbars machen würde, sind bisher gescheidert.
Code: Alles auswählen
Sub imagemanager()
Dim sDocType$ : sDocType ="com.sun.star.text.TextDocument"
Dim sSupplier$
Dim oSupplier
Dim oModuleCfgMgr
Dim oImageMgr
Dim sCmdID
sCmdID = "vnd.sun.star.script:LOTTeMatheGrafik.LOTTeContextMenuGraphics.LOTTeChanceGraphEquation?language=Basic&location=application"
REM Retrieve the module configuration manager from the
REM central module configuration manager supplier
sSupplier = "com.sun.star.ui.ModuleUIConfigurationManagerSupplier"
oSupplier = CreateUnoService(sSupplier)
REM Retrieve the module configuration manager with module identifier
REM *** See com.sun.star.frame.ModuleManager for more information
oModuleCfgMgr = oSupplier.getUIConfigurationManager( sDocType )
oImageMgr = oModuleCfgMgr.getImageManager()
Dim oImageCmds(0)
Dim oImages(0)
Dim oImage
REM *** Check if image has already been added
If Not oImageMgr.hasImage( 0, sCmdID ) Then
REM Try to load the image from the file URL
oImage = GetImageFromURL( "file:///home/frank/swapIconSmall.bmp" )
If Not isNull( oImage ) Then
REM *** Insert new image into the Writer image manager
oImageCmds(0) = sCmdID
oImages(0) = oImage
oImageMgr.insertImages( 2, oImageCmds(), oImages() )
End If
Else
msgBox "Image bereits geladen.",0,"imagemanager"
End If
REM images in imagemanager
Dim sImage As String
Dim msg As String
Dim aImages As Variant
aImages = oImageMgr.getAllImageNames(2)
For Each sImage In aImages
If InStr(sImage,"LOTTe") >0 Then
msg =msg & sImage & Chr(10)
End If
Next
msgbox msg,1,"Images"
End Sub
Function GetImageFromURL( URL as String ) as Variant
Dim oMediaProperties(1) As New com.sun.star.beans.PropertyValue
Dim sProvider$ : sProvider = "com.sun.star.graphic.GraphicProvider"
Dim oGraphicProvider
REM Create graphic provider instance to load images from files.
oGraphicProvider = createUnoService( sProvider )
REM Set URL property so graphic provider is able to load the image
oMediaProperties(0).Name = "URL"
oMediaProperties(0).Value = URL
oMediaProperties(1).Name = "MimeType"
oMediaProperties(1).Value = "image/bmp"
REM Retrieve the com.sun.star.graphic.XGraphic instance
GetImageFromURL = oGraphicProvider.queryGraphic( oMediaProperties() )
End Function
Schöne Ostern
Frank