Hi Carsten,
thanks for your fast answer and the example.
Carsten Driesner schrieb:
...
> 2. Can be accessed via the window state configuration.
You have to
> create the service
"com.sun.star.ui.WindowStateConfiguration" and
> retrieve the window states for a specific module (via
getByName(
> ModuleIdentifier ). There you can access the window
state information
> for every window based ui element using the private-URL
(f.e.
> "private:toolbar/standardbar" ).
>
But how to get that work, if these settings are not made for
modules,
but for a document?
Some month ago I did the same with GUI for a template and
wondered, why
other users didn't get the property "icons &
text" working with that
template.
I modified your example (thx to ms777 and Paolo) with a
graphic and a
shortcut, so that it will work for the document the code
belongs to
(except the last call).
Regards
Peter
Sub Main()
sGraphURL = "file:///c:/daten/lc20556.png"
REM *** would be nice to have a private URL here, see
thread
"XGraphicProvider and service MediaProperties"
REM ***
http://api.openoffice.org/s
ervlets/BrowseList?list=dev&by=thread&from=1609161
a>
sCommandURL =
"vnd.sun.star.script:Standard.Module1.Test?language=Bas
ic&location=document"
REM *** The name of our new custom toolbar. A custom
toolbar name MUST
REM *** start with "custom_"!
sToolbar =
"private:resource/toolbar/custom_toolbar1"
oDocCfgMgr = ThisComponent.getUIConfigurationManager
SetShortCut(oDocCfgMgr,sCommandURL)
SetToolbar(oDocCfgMgr,sCommandURL,sToolbar)
SetGraphic(oDocCfgMgr,sGraphURL,sCommandURL)
SetDockings(sToolbar)
SetVisualSettings(sToolbar)
End Sub
Sub SetShortCut(oDocCfgMgr,sCommandURL)
'shortCut for macro (by Paolo Mantovani)
oShortCutManager = oDocCfgMgr.GetShortCutManager
Dim aKeyEvent As New com.sun.star.awt.KeyEvent
With aKeyEvent
.Modifiers = com.sun.star.awt.KeyModifier.MOD1 +
com.sun.star.awt.KeyModifier.SHIFT
.KeyCode = com.sun.star.awt.Key.W
End With
oShortCutManager.setKeyEvent(aKeyEvent, sCommandURL)
oShortCutManager.store
End Sub
Sub SetGraphic(oDocCfgMgr,sGraphURL,sCommandURL)
'graphic for macro, by ms777
oIm = oDocCfgMgr.ImageManager
oProv =
CreateUNOService("com.sun.star.graphic.GraphicProvider&
quot;)
Dim mProps(0) as New com.sun.star.beans.PropertyValue
mProps(0).Name = "URL"
mProps(0).Value = sGraphURL
oGraph = oProv.queryGraphic(mProps())
if not
oIm.hasImage(com.sun.star.ui.ImageType.SIZE_DEFAULT,
sCommandURL) then
oIm.insertImages(
com.sun.star.ui.ImageType.SIZE_DEFAULT,
Array(sCommandURL), Array(oGraph))
oIm.store()
else
oIm.replaceImages(
com.sun.star.ui.ImageType.SIZE_DEFAULT,
Array(sCommandURL), Array(oGraph))
oIm.store()
endif
End Sub
Sub SetToolbar(oDocCfgMgr,sCommandURL,sToolbar)
REM *** Creates a new custom toolbar persistently for the
Document
REM *** Create a settings container which will define the
structure of
our new
REM *** custom toolbar.
oToolbarSettings = oDocCfgMgr.createSettings()
REM *** Set a title for our new custom toolbar
oToolbarSettings.UIName = "My little custom
toolbar"
REM *** Create a button for our new custom toolbar
oToolbarItem = CreateToolbarItem( sCommandURL,
"press here now" )
oToolbarSettings.insertByIndex( 0, oToolbarItem )
REM *** Set the settings for our new custom toolbar.
(replace/insert)
if ( oDocCfgMgr.hasSettings( sToolbar )) then
oDocCfgMgr.replaceSettings( sToolbar,
oToolbarSettings )
else
oDocCfgMgr.insertSettings( sToolbar,
oToolbarSettings )
endif
oDocCfgMgr.store
End Sub
Sub SetDockings(sToolbar)
oLayoutManager =
ThisComponent.CurrentController.Frame.LayoutManager
CurDockArea = oLayoutManager.GetCurrentDockingArea
cDockArea = com.sun.star.ui.DockingArea.DOCKINGAREA_TOP
Dim aPos as New com.sun.star.awt.Point
aPos.X = 0
aPos.Y = CurDockArea.Y + 1
oLayoutManager.dockWindow(sToolbar,cDockArea,aPos)
' oElem = oLayoutManager.GetElement(sToolbar)
' oElem.NoClose = True
End Sub
Sub SetVisualSettings(sToolbar)
oWindowState =
createUnoService("com.sun.star.ui.WindowStateConfigurat
ion")
oModuleCfgMgrSupplier =
createUnoService("com.sun.star.ui.ModuleUIConfiguration
ManagerSupplier")
oModulManager =
createUnoService("com.sun.star.frame.ModuleManager"
;)
sModule =
oModulManager.identify(ThisComponent.CurrentController.Frame
)
oModuleCfgMgr =
oModuleCfgMgrSupplier.getUIConfigurationManager(sModule)
REM *** Retrieve the module configuration manager with
the module
identifier
REM *** See com.sun.star.frame.ModuleManager for more
information
REM *** Retrieve the window state configuration for the
CurrentComponent
oBasicWindowState = oWindowState.getByName( sModule )
REM *** Set visual settings of our new toolbar ***
Dim aWindowStateData(1) as new
com.sun.star.beans.PropertyValue
REM *** Set new style for toolbar:
REM See org.openoffice.Office.UI.WindowState.xcs for
all possible
properties
REM *** Style: 0 = symbol buttons, 1 = text buttons, 2
=
symbols+text buttons
aWindowStateData(0).Name = "Style"
aWindowStateData(0).Value = 2
if oBasicWindowState.hasByName( sToolbar ) then
oBasicWindowState.replaceByName( sToolbar,
aWindowStateData )
else
oBasicWindowState.insertByName( sToolbar,
aWindowStateData )
endif
End Sub
Function CreateToolbarItem( Command as String, Label as
String ) as Variant
Dim aToolbarItem(4) 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 = "Style"
aToolbarItem(3).Value = 0
aToolbarItem(4).Name = "Visible"
aToolbarItem(4).Value = true
CreateToolbarItem = aToolbarItem()
End Function
Sub Test
MsgBox "Test"
End Sub
------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribe api.openoffice.org
For additional commands, e-mail: dev-help api.openoffice.org
|