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

Reply via email to