Static PopupMenu callbacks and DLL


#1

I'm working on an audio plugin project and want to use PopupMenu asynchronously.

Inside a mouseDown handler, I do the following:

    if( isEnabled() && e.mods.isPopupMenu() )
    {
        PopupMenu m;
        m.addItem ( 1, "A" );
        m.addItem ( 2, "B" );
       
        m.showAt( Rectangle<int>( e.getMouseDownScreenPosition(), e.getMouseDownScreenPosition() ), 0, 0, 0, 0,
                  ModalCallbackFunction::forComponent<Component>( PluginEditor::contextMenuClicked, this ) );   
    }

The interface for the callback function asks for a static member, which works perfectly until one uses a second plugin instance. In my case, this callback function needs to *do something* with one specific PluginEditor instance (and not all of them). The only apparent work-around for me is to point to the latest instance statically (to access the instance and not just the class), but this only makes it worse. Oh well, and a synchronous PopupMenu isn't an option either afaik.

I do not understand why this function must be static and how to use it safely in an audio plug-in scenario (more accurately: In a dll). Does anyone know of a proven way to handle this case?

 


#2

I don't understand your question - the whole point of the ModalCallbackFunction::forComponent method is that it tracks the component you're interested in, and passes that pointer to the callback function. There are lots of examples of this in the demo and the rest of the codebase.


#3

Oh thanks for mentioning ModalCallbackFunction, it seems I over-thought the issue and completely missunderstood the purpose of ModalCallbackFunction. Sorry.