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

2010-10-19 Thread Cor Nouws

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


-
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org



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

2010-10-19 Thread Carsten Driesner

Am 19.10.2010 14:10, schrieb Cor Nouws:

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?

Hi Cor,

From my point of view this is not a bug. A function in a toolbar or 
menu item contains a CommandURL which describe what command will be 
processed on activation. As the CommandURL is a unique identier for the 
function it can also be used for the help. The HelpID property was 
used for backward compatibility. Currently OOo normally uses the 
CommandURL to retrieve the tooltip/help content.
It's possible for an implementation to change the tooltip text (e.g. 
look at the undo function which shows the latest undo step as tooltip). 
This can only be done by the responsible DispatchProvider implementation 
using a full-featured UNO language (Java, C/C++, Python). I don't know a 
way to do it with Basic. The dispatch object must send a 
com.sun.star.frame.FeatureStateEvent and put a string object into the 
State member.


Regards,
Carsten

-
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org



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

2010-10-19 Thread Cor Nouws

Hi Carsten,

Carsten Driesner wrote (19-10-10 16:06)


 From my point of view this is not a bug. A function in a toolbar or
menu item contains a CommandURL which describe what command will be
processed on activation. As the CommandURL is a unique identier for the
function it can also be used for the help. The HelpID property was
used for backward compatibility. Currently OOo normally uses the
CommandURL to retrieve the tooltip/help content.


Ah, that explains it all. I did not look for specs on the HelpID, just 
considered it to work, since it shows a value.



It's possible for an implementation to change the tooltip text (e.g.
look at the undo function which shows the latest undo step as tooltip).
This can only be done by the responsible DispatchProvider implementation
using a full-featured UNO language (Java, C/C++, Python). I don't know a
way to do it with Basic. The dispatch object must send a
com.sun.star.frame.FeatureStateEvent and put a string object into the
State member.


Thanks for making this clear.

Regards,
Cor
--
 - giving openoffice.org its foundation :: The Document Foundation -
 - ideas/remarks for the community council? See
   http://wiki.services.openoffice.org/wiki/Community_Council


-
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org



Re: [api-dev] BASIC: Change toolbar button icon ?

2009-10-30 Thread Fernand Vanrie



Carsten, Jan

found the solution in Jan's post

sMyToolbarCmdId = 
vnd.sun.star.script:Toolbar.ToolbarButtons.Test?language=Basiclocation=document


thanks
fernand



Thanks for this cool peace of code, very usefull !

But :-)

My button installs fine but the macro behind the button (located in a 
document) is not working, i supose there is something wrong with the 
commandUIRL


The test() macro is located in a document in a Toolbarlib Library, 
in a ToolbarButtonsMod module


is use sMyToolbarCmdId = macro:///Toolbarlib.ToolbarButtonsMod.Test()
any idea ?

Thanks

Fernand



Hello Carsten,
Just for let you know that almost all your posts in d...@api are labeled
as important in my local archive :-)
Thanks for sharing.
Keep it up!!

ciao
Paolo M


Carsten Driesner ha scritto:
 

Jan Holst Jensen wrote:
   

Hi all.

I am trying to emulate a togglebutton/checkbox in a custom toolbar.
Right now I have settled for having two toolbar buttons with different
icons. Only one of them is visible and when it's pressed it toggles
the visibility of both buttons using the code below (which sets
visibility of a single button with a given label).

It works OK but only as long as the user doesn't fiddle with button
visibility :-). Is there a way of changing a toolbar button's icon
directly from Basic code ? I could not figure out how to do it.
  

Hi Jan,

Your solution looks it a little bit strange. You can set the image of a
toolbar button with the help of an image manager. Look at the following
Basic code which uses the image manager to set an image for a button
that references a Basic macro. I am sure you can adapt the code to your
needs.

Regards,
Carsten

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

Re: [api-dev] BASIC: Change toolbar button icon ?

2009-10-30 Thread Carsten Driesner

Jan Holst Jensen schrieb:

Carsten Driesner wrote:

Jan Holst Jensen wrote:

Hi all.

I am trying to emulate a togglebutton/checkbox in a custom toolbar. 
Right now I have settled for having two toolbar buttons with 
different icons. Only one of them is visible and when it's pressed 
it toggles the visibility of both buttons using the code below 
(which sets visibility of a single button with a given label).


It works OK but only as long as the user doesn't fiddle with button 
visibility :-). Is there a way of changing a toolbar button's icon 
directly from Basic code ? I could not figure out how to do it.

Hi Jan,

Your solution looks it a little bit strange. You can set the image of 
a toolbar button with the help of an image manager. Look at the 
following Basic code which uses the image manager to set an image for 
a button that references a Basic macro. I am sure you can adapt the 
code to your needs.


Hi Carsten.

Thanks for this. I was looking for something resembling Excel VBA 
where you just change the .FaceId property of a toolbar button which I 
can now see is definitely not the way to do it in OpenOffice.


As far as I can understand icons are instead associated with a command 
URL and not the user interface element. So if I change the command URL 
of a toolbar button the icon changes with it. This actually makes good 
sense for my usage scenario.

Hi Jan,

Yes, that's right. OpenOffice.org associates command URL and icon. The 
idea behind this:  A command which can reside in a menu, toolbar  or 
context menu should always be represented by the same icon. As the 
command URL reflects the action behind a user interface element it's 
logical to use it as the primary key to accessthe icon.


I have a toolbar button that is used to turn a feature on or off. When 
the button is pressed to turn the feature ON I change its command URL 
to point to the Sub that turns the feature OFF. This also changes the 
icon so the end user can see the current state of the feature (is it 
ON or OFF ?). As illustrated by the code below.
The code you attached to this mail looks much better now. Normally the 
state of a command in OpenOffice.org is defined by a part of  the 
controller implementation. It can use a 
com.sun.star.frame.FeatureStateEvent to update the state of a command. 
There you can set the state of a command to on or off. For example the 
Gallery button on the standard bar has a on/off state. Implementing a 
controller (Dispatch Provider) is, as far as I know, not possible with 
Basic. Therefore your solution is the best way and also much easier.


Regards,
Carsten

-
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org



Re: [api-dev] BASIC: Change toolbar button icon ?

2009-10-29 Thread Carsten Driesner

Jan Holst Jensen wrote:

Hi all.

I am trying to emulate a togglebutton/checkbox in a custom toolbar. 
Right now I have settled for having two toolbar buttons with different 
icons. Only one of them is visible and when it's pressed it toggles the 
visibility of both buttons using the code below (which sets visibility 
of a single button with a given label).


It works OK but only as long as the user doesn't fiddle with button 
visibility :-). Is there a way of changing a toolbar button's icon 
directly from Basic code ? I could not figure out how to do it.

Hi Jan,

Your solution looks it a little bit strange. You can set the image of a 
toolbar button with the help of an image manager. Look at the following 
Basic code which uses the image manager to set an image for a button 
that references a Basic macro. I am sure you can adapt the code to your 
needs.


Regards,
Carsten

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: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org



Re: [api-dev] BASIC: Change toolbar button icon ?

2009-10-29 Thread Paolo Mantovani
Hello Carsten,
Just for let you know that almost all your posts in d...@api are labeled
as important in my local archive :-)
Thanks for sharing.
Keep it up!!

ciao
Paolo M


Carsten Driesner ha scritto:
 Jan Holst Jensen wrote:
 Hi all.

 I am trying to emulate a togglebutton/checkbox in a custom toolbar.
 Right now I have settled for having two toolbar buttons with different
 icons. Only one of them is visible and when it's pressed it toggles
 the visibility of both buttons using the code below (which sets
 visibility of a single button with a given label).

 It works OK but only as long as the user doesn't fiddle with button
 visibility :-). Is there a way of changing a toolbar button's icon
 directly from Basic code ? I could not figure out how to do it.
 Hi Jan,
 
 Your solution looks it a little bit strange. You can set the image of a
 toolbar button with the help of an image manager. Look at the following
 Basic code which uses the image manager to set an image for a button
 that references a Basic macro. I am sure you can adapt the code to your
 needs.
 
 Regards,
 Carsten
 
 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: dev-unsubscr...@api.openoffice.org
 For additional commands, e-mail: dev-h...@api.openoffice.org
 
 .
 



Re: [api-dev] BASIC: Change toolbar button icon ?

2009-10-29 Thread Fernand Vanrie

Carsten,

Thanks for this cool peace of code, very usefull !

But :-)

My button installs fine but the macro behind the button (located in a 
document) is not working, i supose there is something wrong with the 
commandUIRL


The test() macro is located in a document in a Toolbarlib Library, in 
a ToolbarButtonsMod module


is use sMyToolbarCmdId = macro:///Toolbarlib.ToolbarButtonsMod.Test() 


any idea ?

Thanks

Fernand



Hello Carsten,
Just for let you know that almost all your posts in d...@api are labeled
as important in my local archive :-)
Thanks for sharing.
Keep it up!!

ciao
Paolo M


Carsten Driesner ha scritto:
  

Jan Holst Jensen wrote:


Hi all.

I am trying to emulate a togglebutton/checkbox in a custom toolbar.
Right now I have settled for having two toolbar buttons with different
icons. Only one of them is visible and when it's pressed it toggles
the visibility of both buttons using the code below (which sets
visibility of a single button with a given label).

It works OK but only as long as the user doesn't fiddle with button
visibility :-). Is there a way of changing a toolbar button's icon
directly from Basic code ? I could not figure out how to do it.
  

Hi Jan,

Your solution looks it a little bit strange. You can set the image of a
toolbar button with the help of an image manager. Look at the following
Basic code which uses the image manager to set an image for a button
that references a Basic macro. I am sure you can adapt the code to your
needs.

Regards,
Carsten

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