Menubar button with popup menu or dropdown in OOBasic

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Menubar button with popup menu or dropdown in OOBasic

Post by JeJe »

A Menubar button with a popup menu is (I understand) possible with an xtoolbarcontroller but that can't be implemented with the OOBasic language.

Making a popup menu show when a menubar button is clicked is easy but a workaround is needed to:

- get it positioned
- so the menu shows when the button is pressed rather than clicked
- so a menu item can be selected with the mouse still held down

See attached demo for menu example.
A dropdown using a dialog could be accomplished in the same way.

(note only tested in OpenOffice)

'UPDATES
'14 01 20: added missed sub THANKS TO musikai
Attachments
Toolbar Button PopUp.odt
(18.18 KiB) Downloaded 344 times
Last edited by JeJe on Wed Jan 15, 2020 12:36 am, edited 1 time in total.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

Re: Menubar button with popup menu or dropdown in OOBasic

Post by musikai »

This is cool!!! Works also in LibreOffice. (This could tidy up my long list of Toolbar buttons in a nice way. Also the possibility of having separators is great!)

only when running

Code: Select all

SetToolbarItemRepeat
I get an error saying

Code: Select all

GetPropertyValueByName
isn't found

Good that you provided the link to hanya's findtoolbar in the code
viewtopic.php?f=20&t=56336
and there is the missing function:

Code: Select all

Function GetPropertyValueByName(aElements, sName) As Variant
  found = nothing
  for i = 0 to ubound(aElements) step 1
    if aElements(i).Name = sName then
      found = aElements(i).Value
    end if
  next
  GetPropertyValueByName = found
End Function
Is there a list of the different style possibilities by the PValue ?
I like the look of PValue=256 with the dropdown arrow but this doesn't seem to be compatible here. (pressing the button will show the menu but not pressing the arrow)
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Menubar button with popup menu or dropdown in OOBasic

Post by JeJe »

Thanks... that's wierd I didn't get the error... added to document. I originally wrote it without using those functions and I may revert to that if I do a rewrite.

The itemstyle constants are here:

https://www.openoffice.org/api/docs/com ... Style.html

The dropdown arrow will show but it needs xtoolbarcontroller to implement that... which we can't do with basic.

The useful ones seem to be
- setting the menu item to show text or icon or both text and icon
- setting repeat, which you may want to use for a normal button as well

You can't set either of these without using a macro to do it in OO.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply