FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

MENUS

Know the popup menu secrets


Since System 7, the OS has included an Apple CDEF for popup menus, the ID is defined as an FB constant (_popupMenuCDEFProc = 1008), which is actually 16 times the CDEF ID which is 63. It is documented in IM back to the old Volume VI, and is called using NewControl. It will accept the resource ID of a menu resource, etc.

Using the system supplied CDEF is probably the only way of ensuring compatibility with the Appearance Manager, etc., although the older PopupMenu CDEF 2.0 that I usually use does display properly in OS 8/8.1. I never use the PG popups because the spacing is not correct, and I find a CDEF easier to deal with once it is set up.

I have a PG uCOD/FLTR combo that I was working on that uses the system CDEF. I don't have the spacing working exactly the way I want it, but you are welcome to look at it if you wish. It allows you to place a drawn popup in a PG project, and puts the filter in your project, mapping the popup to a user-supplied FB button number.

Chris Young


Try this to show System 8 pop-ups.
You'll probably have to handle the events yourself although it looks relatively easy.

DIM wPtr&,popMenuHandle&
DIM menuRect.8
DIM title$

WINDOW 1
GET WINDOW 1,wPtr&
LONG IF wPtr&
  CALL SETRECT(menuRect,10,10,450,30)
 title$ = "Test Pop-up Menu"
 MENUresID% = 17920 '17920 = built in STAZ help menu. Create your own MENU resource
 TEXT _sysFont,12 'pop-up font
 popMenuHandle& = FN NEWCONTROL(wPtr&,menuRect,title$,_False,0,MENUresID%,FN STRINGWIDTH(title$)+8,1018,_nil)
 CALL SHOWCONTROL(popMenuHandle&)
END IF

DO
 HANDLEEVENTS
UNTIL LEN(INKEY$)
IF popMenuHandle& THEN CALL DISPOSECONTROL(popMenuHandle&)
SYSTEM

John M.


If you change the ref at the end of this call, FB will look after the popup for you, and even send you a button event when it is selected:

popMenuHandle& = FN NEWCONTROL(wPtr&,menuRect,title$,_False,0,MENUresID%,FN STRINGWIDTH(title$)+8,1018,_nil) <-

Change: _nil to: IDtoUse% * 65536

Where IDtoUse% is the button number you want to use. (Make sure you don't create a button with the same ID!)

You can do this trick with most CDEFs, the number is something to do with FBs internals, I just hacked until I found it (Sorry Staz)

Jamin


I forgot to say thanks; it appears just as easy to do this as it does staz'z popups. I'm having a bit of trouble with managing multiple popups, but that's something I need to work with.

However, after doing a little investigation in the appearance manager includes it appears that the value you're using: 1018, should actually be 1008. It works just the same, which did surprise me a little. 1008 was one of the constants in there... btw.

I am having a little graphical glitch come up; the way I've got it set up(like a pref dialog type thing), i can do this right after building the control:
call setctlvalue(popupptr&,menuitemsel%)
and say, menuitemsel% is the 3rd item down; it will in fact check the item and set it as the default(which is exactly what I was hoping it to do), but it also leaves the first item in the list checked, unless you were to select the first item again and select something else, then it looks fine again. It appears setting the default value when setting up the control(for me at least) doesn't work correctly.

<< If you change the ref at the end of this call, FB will look after the popup for you, and even send you a button event when it is selected: >>

Actually, I did my own little bit of debugging with my dialog routine, and found that they just respond as if they were button #0; which is ok for this particular project. I'll keep that in mind tho, but I wonder if it will be compatible with future versions of fb...

TJ Grant


Well 1008 is actually the "base" id of the control. It has several options that can be "added". One of these option is _useWFont (which results in 1018), which forces the Pop-up to use the current window font. This way you can build a small _geveva, 9 pop-up or a regular _sysFont,12 style pop-up. The other available options relate to the title position and justifications (left,right,etc.).

John


Look up _popupMenuCDEFProc in the Constants tool. You will see that: 1008 = the PopUp Menu CDEF.
To this add 1 to make the menu a fixed width (_popupFixedWidth = 1) Add 8 to use the window font in the menu (_popupUseWFont = 8) Not sure what 2 or 4 do (_popupReserved and _popupUseAddResMenu) but you could use any number from 1008 to 1023.

Also if you replace the "0" after _False below:

popMenuHandle& = FN NEWCONTROL(wPtr&,menuRect,title$,_False,0,MENUresID%,FN STRINGWIDTH(title$)+8,1018,_nil)

with any of the constants in the Constants tool that start with "_popupTitlexxx", you can change the style and justification of the popup's title.

And if you want the popup menu to draw at a specific point, then in place of "FN STRINGWIDTH(title$)+8" use the width that you want to reserve for the title (popupRect.left% - menuRect.left%)

Finally you can also use:

popMenuHandle& = FN GETNEWCONTROL(cntrlResID%, wPtr&)

where cntrlResID% is the number of a "CNTL" resource template that easily lets you fill in all of the values used in FN NEWCONTROL.

Mark