Who do I belong to?

Doug Easterbrook doug at artsman.com
Sun Mar 23 16:54:06 UTC 2025


hi Mike

there are a number of ways to create a popup menu, including with sub menus and such.   I’ve got three for you.  WE use them all ,depending on what is convenient at the time



OWRITE POPUP MENU


the one that I’ve found most reliable by far is to use Michael’s owrite and his popupmenu features that are part of owrite — and I use this if I want a complex menu to do a lot of things.

the steps are:
- user clicks or right clicks on something on screen.  
- you build a menu (with name, callback, icon, other things you need, and/or sub menu (s)
- if the user pick something, the menu does a dispatch call to $execumenu on your window, with the parameter for the reference to the field
- you have a case statement that dispatches the menue call back to do what you want.

the actual oWrite call to popup a menu is this (which will pop up the 'pMenu') wherever you want

Do OWrite.$popupmenulist(pFieldRef.$framehwnd,pMenu,pDisplayBelow,pHorzOffset,pVertOffset) Returns result

very very flexible.



POPUP MENU FROM LIST


The other approach I’ve done is the following, which is useful for a quick menu on a button, kind of brute forced.  although you can put it in some common code someplace.  Downside, no icons or disabling some menu items, or popup menus.


do List.$define(menutext)
do list.$add('menu line 1')
if some condition
  do list.$add('menu line 2')
end if
calculate list.$line as 0

Popup menu from list list at 

and depending on the line number, if list, I will execute code  eg
switch list.$Line
case 0
  # nothing was picked
case 1
  # menu line 1 was picked
case 2
  # menu line 2 was picked
end switch




POPUP MENU [name of menu]

the third one that you can use is a prebuilt menu, which lets you have code behind the menu itself.  You can hide menu lines, enable, disable them, etc.   We actually use this a lot.

we’ve put some code behind the menu in the $construtc that tells us what object the user clicked on to get the menu to open.  This can be extended.

in the end, pWindowRef can be used to talk back to the field or what have you that the user clicked on.


popup menu 'myMenu' 


and in the $construct of the menu’s superclass

If not(isnull($cinst.$contextobj()))
Set reference iContextRef to $cinst.$contextobj()
Calculate iIsPrimaryCascadeMenu as kTrue
Else
Calculate iIsSecondaryCacadeMenu as kTrue
Set reference iContextRef to mouseover(kMItemref)
End If

# sets the value of iWindowref (the subwindow or window) that the context menu was invoked from.
# in all the context menus should call back to subwindow (or window) via    Should do iWindowRef.xxxx, not do$topwind
Do tStringFields.$getWindowRef(iContextRef,iWindowRef)



and the '$getWindowRef' code looks like this

Set reference pWindowRef to pContextRef

Repeat
If pWindowRef.$objtype=kSubwindow
Calculate Type as kSubwindow
End If

If len(Type)=0
Set reference pWindowRef to pWindowRef.$container
End If
Until len(Type)>0|isnull(pWindowRef)

If isnull(pWindowRef)
# Didn't find any subwindows so just return the main $wind() ref
Set reference pWindowRef to $topwind
End If
Quit method pWindowRef





Doug Easterbrook
doug at artsman.com
Phone (403) 650-1978

> On Mar 23, 2025, at 3:53 AM, Mike Matthews - Omnis via omnisdev-en <omnisdev-en at lists.omnis-dev.com> wrote:
> 
> Hello All,
> 
> If you add a popupMenu to a window, how do you pass the window instance to the menu?  I want the menu to call methods in the window it is placed on.
> 
> And I bet a few cheeky replies from some of you lot for the subject line :)
> 
> Ta
> 
> Mike Matthews
> 
> Lineal Software Solutions
> Commercial House, The Strand<x-apple-data-detectors://1/1> Barnstaple, Devon, EX31 1EU<x-apple-data-detectors://1/1>
> 
> omnis at lineal.co.uk<mailto:mike.matthews at lineal.co.uk>
> 
> www.lineal.co.uk<http://www.lineal.co.uk/>
> 
> www.sqlworks.co.uk<http://www.sqlworks.co/>
> 
> 
> 
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com



More information about the omnisdev-en mailing list