Menubar button with popup menu or dropdown in OOBasic

Creating Extension - 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 forum is not for asking questions about writing your own macros.

Menubar button with popup menu or dropdown in OOBasic

Postby JeJe » Tue Jan 14, 2020 2:49 am

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 51 times
Last edited by JeJe on Wed Jan 15, 2020 12:36 am, edited 1 time in total.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1152
Joined: Wed Mar 09, 2016 2:40 pm

Re: Menubar button with popup menu or dropdown in OOBasic

Postby musikai » Tue Jan 14, 2020 11:57 pm

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)
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/libreofficesongbookarchitect.html
musikai
Volunteer
 
Posts: 282
Joined: Wed Nov 11, 2015 12:19 am

Re: Menubar button with popup menu or dropdown in OOBasic

Postby JeJe » Wed Jan 15, 2020 12:47 am

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.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1152
Joined: Wed Mar 09, 2016 2:40 pm


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest