[Solved] Toolbar button with icon

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Locked
nilman70
Posts: 5
Joined: Tue Nov 05, 2024 3:12 pm

[Solved] Toolbar button with icon

Post by nilman70 »

Is there any possibility to add a toolbar button with icon to a new toolbar using basic code?
Last edited by nilman70 on Wed Nov 06, 2024 5:18 pm, edited 2 times in total.
OpenOffice 3.1 on Windows Vista
JeJe
Volunteer
Posts: 3064
Joined: Wed Mar 09, 2016 2:40 pm

Re: Toolbarbutton with icon

Post by JeJe »

Sure, what are you trying to do?
Add a new toolbar to a single Writer document or to all Writer documents?
Is it an existing Writer command or your own macro you want to call?
Different code applies depending.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Zizi64
Volunteer
Posts: 11477
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Toolbarbutton with icon

Post by Zizi64 »

You can use a prepared Template for the new, "empty" documents. Just create the toolbar manually in scope of the document, and save it as a Template. Open that Template, when you need the additional toolbar.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
nilman70
Posts: 5
Joined: Tue Nov 05, 2024 3:12 pm

Re: Toolbarbutton with icon

Post by nilman70 »

JeJe wrote: Tue Nov 05, 2024 7:04 pm Sure, what are you trying to do?
Add a new toolbar to a single Writer document or to all Writer documents?
Is it an existing Writer command or your own macro you want to call?
Different code applies depending.
I have multiple template files for different languages, de, en, es, gr, etc.. And the template names would be template_de, template_en, template_es, etc. but with a common code to maintain which will depending on the language, i.e. name of the template file will create different toolbar buttons, as there are different language specific features, e.g. de has ligature or fraktur which en/es do not.
When a new writer document is opened for that template, based on the language (or name of the template), one or more different icon toolbar buttons will dynamically appear and clicking on them own macro code will get executed.
Of course, this could be done by adding all the needed buttons right in the beginning and disabling/deleting them or setting their command URL differently during the start based on the language. But I was looking into the possibility of doing all this dynamically.
OpenOffice 3.1 on Windows Vista
Bidouille
Volunteer
Posts: 641
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: Toolbarbutton with icon

Post by Bidouille »

Than a template, build an OXT seems to be a better solution.
Did you have a look to code snippet? viewtopic.php?t=108470&hilit=toolbar
nilman70
Posts: 5
Joined: Tue Nov 05, 2024 3:12 pm

Re: Toolbarbutton with icon

Post by nilman70 »

Bidouille wrote: Wed Nov 06, 2024 11:19 am Than a template, build an OXT seems to be a better solution.
Did you have a look to code snippet? viewtopic.php?t=108470&hilit=toolbar
Not yet, thanks, I will go through the code.
OpenOffice 3.1 on Windows Vista
nilman70
Posts: 5
Joined: Tue Nov 05, 2024 3:12 pm

Re: Toolbarbutton with icon

Post by nilman70 »

Thanks a lot ~Bidouille, I could get that snippet running with imagebutton, listbox, etc.
OpenOffice 3.1 on Windows Vista
JeJe
Volunteer
Posts: 3064
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Toolbar button with icon

Post by JeJe »

That code snippet of mine crashes so I wouldn't use it -- as said in the last post if you want to use a complex control on a toolbar you should instead use a dialog and set its parent on creation to the toolbar panel.

Adding a toolbar and normal buttons though is easier. The attached document shows how to do this for a module eg Writer module/all Writer documents. Run test and it should create a toolbar with buttons. Unfortunately the page I based my code on looks to be no longer available. Doing it for one document instead of a module, from memory which can be faulty I think you may have to do something similar but use the document frame's layoutmanager.

Why not just have the same button for all languages though - and in the macro it calls identify the language and run the relevant code?
Attachments
toolbar macro.odt
(11.93 KiB) Downloaded 125 times
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
nilman70
Posts: 5
Joined: Tue Nov 05, 2024 3:12 pm

Re: [Solved] Toolbar button with icon

Post by nilman70 »

Thanks ~Jeje, I will go through the code...
OpenOffice 3.1 on Windows Vista
Locked