Page 1 of 1

Menubar button with popup menu or dropdown in OOBasic

PostPosted: Tue Jan 14, 2020 2:49 am
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

Re: Menubar button with popup menu or dropdown in OOBasic

PostPosted: Tue Jan 14, 2020 11:57 pm
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   Expand viewCollapse view
SetToolbarItemRepeat

I get an error saying
Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
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)

Re: Menubar button with popup menu or dropdown in OOBasic

PostPosted: Wed Jan 15, 2020 12:47 am
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.