diff --git a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp index f85c9510f0..f654ba54f4 100644 --- a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp @@ -1472,8 +1472,9 @@ private: class EditorContextMenu : public HostProvidedContextMenu { public: - EditorContextMenu (VSTComSmartPtr contextMenuIn) - : contextMenu (contextMenuIn) {} + EditorContextMenu (AudioProcessorEditor& editorIn, + VSTComSmartPtr contextMenuIn) + : editor (editorIn), contextMenu (contextMenuIn) {} PopupMenu getEquivalentPopupMenu() const override { @@ -1542,10 +1543,12 @@ private: void showNativeMenu (Point pos) const override { - contextMenu->popup (pos.x, pos.y); + const auto scaled = pos * Component::getApproximateScaleFactorForComponent (&editor); + contextMenu->popup (scaled.x, scaled.y); } private: + AudioProcessorEditor& editor; VSTComSmartPtr contextMenu; }; @@ -1553,9 +1556,10 @@ private: { public: EditorHostContext (JuceAudioProcessor& processorIn, + AudioProcessorEditor& editorIn, Steinberg::Vst::IComponentHandler* handler, Steinberg::IPlugView* viewIn) - : processor (processorIn), componentHandler (handler), view (viewIn) {} + : processor (processorIn), editor (editorIn), componentHandler (handler), view (viewIn) {} std::unique_ptr getContextMenuForParameterIndex (const AudioProcessorParameter* parameter) const override { @@ -1569,11 +1573,12 @@ private: const auto idToUse = parameter != nullptr ? processor.getVSTParamIDForIndex (parameter->getParameterIndex()) : 0; const auto menu = VSTComSmartPtr (handler->createContextMenu (view, &idToUse)); - return std::make_unique (menu); + return std::make_unique (editor, menu); } private: JuceAudioProcessor& processor; + AudioProcessorEditor& editor; Steinberg::Vst::IComponentHandler* componentHandler = nullptr; Steinberg::IPlugView* view = nullptr; }; @@ -1586,7 +1591,6 @@ private: public: JuceVST3Editor (JuceVST3EditController& ec, JuceAudioProcessor& p) : EditorView (&ec, nullptr), - editorHostContext (p, ec.getComponentHandler(), this), owner (&ec), pluginInstance (*p.get()) { @@ -1925,7 +1929,12 @@ private: if (pluginEditor != nullptr) { - pluginEditor->setHostContext (&owner.editorHostContext); + editorHostContext = std::make_unique (*owner.owner->audioProcessor, + *pluginEditor, + owner.owner->getComponentHandler(), + &owner); + + pluginEditor->setHostContext (editorHostContext.get()); addAndMakeVisible (pluginEditor.get()); pluginEditor->setTopLeftPosition (0, 0); @@ -2071,6 +2080,7 @@ private: private: JuceVST3Editor& owner; + std::unique_ptr editorHostContext; FakeMouseMoveGenerator fakeMouseGenerator; Rectangle lastBounds; bool resizingChild = false, resizingParent = false; @@ -2094,8 +2104,6 @@ private: //============================================================================== ScopedJuceInitialiser_GUI libraryInitialiser; - EditorHostContext editorHostContext; - #if JUCE_LINUX || JUCE_BSD SharedResourcePointer messageThread; SharedResourcePointer eventHandler; diff --git a/modules/juce_audio_processors/processors/juce_AudioProcessorEditorHostContext.h b/modules/juce_audio_processors/processors/juce_AudioProcessorEditorHostContext.h index 1c4afdf7d7..8b01a7c5de 100644 --- a/modules/juce_audio_processors/processors/juce_AudioProcessorEditorHostContext.h +++ b/modules/juce_audio_processors/processors/juce_AudioProcessorEditorHostContext.h @@ -47,7 +47,13 @@ struct HostProvidedContextMenu */ virtual PopupMenu getEquivalentPopupMenu() const = 0; - /** Asks the host to display its native menu at a particular location. */ + /** Asks the host to display its native menu at a location relative + to the top left corner of the editor. + + The position you provide should be in logical pixels. To display + the menu next to the mouse cursor, call Component::getMouseXYRelative() + on your editor and pass the result to this function. + */ virtual void showNativeMenu (Point pos) const = 0; };