[futurebasic] Re: [FB] Hierarchical popup menus in Appearance runtime

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 2004 : Group Archive : Group : All Groups

From: Alain Pastor <apastor@...>
Date: Thu, 27 May 2004 17:56:52 +0200
Paul Bruneau wrote:

> 
> But I'm having trouble with Appearance popups. I want to use the correct 
> method, and am doing something like this:
> 
> First, the definition of the popup "button" in appearance:
> appearance button _myBevelButton,, _theResMenu, 0, 0, "Popup", @r, 
> _kControlBevelButtonSmallBevelProc
> 
> Then, here is the code that retrieves what the user selected (it is in a 
> Dialog (event) select structure):
> button( _myBevelButton, _fbGetBevelControlMenuVal )
> 
> This gets the item just fine. The problem is, how do I find out what 
> submenu might have been selected?
> 
> Does anyone have any Appearance popup submenu code they'd be willing to 
> share? Or a toolbox call they can point me to?

Paul,

Here is what I use in QuiXample where I have two popup bevel buttons, 
one of them including a hierarchical submenu. I'm not sure this is the 
best method but maybe you can do something out of it. I will simplify 
the code:

First the popup bevel button with the menu and submenu attached is 
defined in my code like the following:

Appearance Button _cAction, _activeBtn,_actionMenu,¬
  _kControlBehaviorCommandMenu,,"Action", (275,27)-(330,45),¬
  _kControlBevelButtonSmallBevelProc_kControlUsesOwningWindowsFontVariant

I have also a function that adds the submenu (in my case a font menu) to 
one of the item of the menu installed in the popup bevel button. It 
looks like this:

Clear Local Mode
Local Fn AddFontMenu
'~'9
Dim @ mCount   As UInt32
Dim   fontMenu As MenuRef

Long If Fn SetMenuItemHierarchicalID( Fn GetMenuHandle(_actionMenu),¬
                                     _fontItem, _fontMenu ) = _noErr
fontMenu = Fn GetMenuHandle( _fontMenu )
Long If fontMenu
Long If Fn CreateStandardFontMenu( fontMenu, 0, 0, 0, mCount) != _noErr
End If
End If
End If
End Fn

Now the tricky part is that the end user interaction is reported as a 
_btnClick dialog event. The prog intercepts the event more or less like so:

Local Fn doDialog
'~'9
Dim As Long   action, target

action = Dialog( 0 )
target = Dialog( action )

Long If action = _btnClick And target = _cAction
Fn ConvertBevelMenuChoiceToMenuChoice(target)
End If
End Fn

If the event concerns the popup bevel button, I call a function that 
will convert that event to a regular menu choice using an undocumented 
runtime function. This function is written like this:

Clear Local Mode
Local Fn ConvertBevelMenuChoiceToMenuChoice( btnID As Long )
'~'9
Dim   menuSel    As Point
Dim   ev         As EventRecord
Dim @ menuID     As SInt16
Dim @ actualSize As Long

Def GetButtonData( btnID, _kControlMenuPart, ¬
                   _kControlBevelButtonLastMenuTag, ¬
                    Sizeof(SInt16), @menuSel.v%, actualSize )
Long If menuSel.v%
Def GetButtonData( btnID, _kControlMenuPart, ¬
                   _kControlBevelButtonMenuValueTag, ¬
                   Sizeof(SInt16), @menuSel.h%, actualSize )
Long If menuSel.h%
ev.where = menuSel
ev.what  = _FBMenuEvent
Fn FBDoMacEvent( ev )
End If
End If
End Fn

Then in my menu handler, I can handle the menu choice as if it were made 
through any other regular menu. I guess you can write something more 
direct than what I do.


> 
> PS: Where is the best place to get Appearance documentation for FB?? 
> Apple's appearance stuff doesn't seem to relate to the FB Appearance 
> tools that we have, and I haven't found FB Appearance docs yet.
> 

You should own the Switching to Carbon book that was shipped with R7.
For more documentation you can browse the examples provided on the CD 
and more specifically those by Robert Purves. You have now QuiXample at 
your disposal for this endless quest. More food for thought: there are 
two complete apps on the CD with source code included, namely Storage 
bin and Code Styler.

Alain