Code: Select all
'COLOR ICON MOD
sub testColoredIcon
'use a macro or command assigned to a toolbar or menu item. This will add a colored square icon like one of the squares in a colorpicker grid.
'choose color
col = rgb(200,170,100)
'choose macro and pass along with color to function
'form of macrourl = "vnd.sun.star.script:YourLibrary.YourModule.YourSubOrFunction?language=Basic&location=document" 'or = application
macrourl = "vnd.sun.star.script:Standard.AATest.ToolbarPopUPTest?language=Basic&location=document" 'my test macro
ColoredIconForMacro col, macrourl
end sub
sub ColoredIconForMacro(col,Macrourl)
'createImage using a Writer document shape and save image to a file
'note I add a 1 pixel border round color
oPathSettings = CreateUnoService( "com.sun.star.util.PathSettings" )
URL =oPathSettings.UserConfig & "/" & "TMPCol.png"
createColored_16x16_PNG(col,URL)
'load the image file and assign to the wanted macro
img = GetImageFromURL(URL)
oManager = thiscomponent.getUIConfigurationManager()
omanager.imagemanager.insertimages(0,array(macrourl),array(img))
'omanager.imagemanager.removeimages(0,array(url))
omanager.imagemanager.store 'make change persistant
kill convertfromurl(url) 'remove the file
end sub
Sub createColored_16x16_PNG(col,URL)
'adapted from
'http://www.ooowiki.de/DiagrammExport.html
'https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=82965
Dim oDoc, oVal(0) As New com.sun.star.beans.PropertyValue
Dim exportFilter, aFilterData(5) As New com.sun.star.beans.PropertyValue,aProps(2) As New com.sun.star.beans.PropertyValue
oVal(0).Name = "Hidden": oVal(0).Value = true
oDoc = stardesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, oval)
dz = createunostruct("com.sun.star.awt.Size")
dp = createunostruct("com.sun.star.awt.Point")
with odoc.currentcontroller.frame.componentwindow.info
pixx =.PixelPerMeterX
piyy =.PixelPerMetery
end with
dz.width = ((16 * 100000) / pixx)
dz.height = ((16 * 100000) / piyy)
dp.x= 0
dp.y = 0
oshape=odoc.createinstance("com.sun.star.drawing.RectangleShape") '"com.sun.star.drawing.ControlShape")
with oshape
'.shapetype = "com.sun.star.drawing.RectangleShape"
.fillcolor = col
.linecolor = col
.setsize(dz)
.setposition(dp)
.visible = true
end with
' odoc.text.string = " " & chr(10) & " "
odoc.drawpage.add(oshape)
exportFilter = createUnoService( "com.sun.star.drawing.GraphicExportFilter" )
exportFilter.setSourceDocument(oshape)
' Set the filter data
aFilterData(0).Name = "Level" '1=PS level 1, 2=PS level 2
aFilterData(0).Value = 2
aFilterData(1).Name = "ColorFormat" '1=color, 2=grayscale
aFilterData(1).Value = 1
aFilterData(2).Name = "TextMode" '0=glyph outlines, 1=no glyph outlines, see ooo bug 7918
aFilterData(2).Value = 1
aFilterData(3).Name = "Preview" '0=none, 1=TIFF, 2=EPSI, 3=TIFF+EPSI
aFilterData(3).Value = 0
aFilterData(4).Name = "CompressionMode" '1=LZW, 2=none
aFilterData(4).Value = 2
aProps(0).Name = "MediaType"
aProps(0).Value = mediaType
aProps(1).Name = "URL"
aProps(1).Value = url
aProps(2).Name = "FilterData"
aProps(2).Value = aFilterData()
exportFilter.filter( aProps() )
oDoc.close(true)
End Sub
'GetImageFromURL function from "Useful Macro Information For OpenOffice" By Andrew Pitonyak
Function GetImageFromURL( URL as String ) 'as Variant
Dim oMediaProperties(0) 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
REM Retrieve the com.sun.star.graphic.XGraphic instance
GetImageFromURL = oGraphicProvider.queryGraphic( oMediaProperties() )
End Function