mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +00:00
NSViewComponentWithParent: Move to new file
This commit is contained in:
parent
8148421145
commit
14ef18c5b9
5 changed files with 134 additions and 97 deletions
|
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
#include <juce_audio_processors_headless/format_types/juce_LV2PluginFormatImpl.h>
|
#include <juce_audio_processors_headless/format_types/juce_LV2PluginFormatImpl.h>
|
||||||
#include <juce_gui_extra/native/juce_NSViewFrameWatcher_mac.h>
|
#include <juce_gui_extra/native/juce_NSViewFrameWatcher_mac.h>
|
||||||
|
#include <juce_audio_processors/utilities/juce_NSViewComponentWithParent.h>
|
||||||
|
|
||||||
namespace juce
|
namespace juce
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
#if JUCE_PLUGINHOST_VST3 && (JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD)
|
#if JUCE_PLUGINHOST_VST3 && (JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD)
|
||||||
|
|
||||||
#include <juce_audio_processors_headless/format_types/juce_VST3PluginFormatImpl.h>
|
#include <juce_audio_processors_headless/format_types/juce_VST3PluginFormatImpl.h>
|
||||||
|
#include <juce_audio_processors/utilities/juce_NSViewComponentWithParent.h>
|
||||||
|
|
||||||
namespace juce
|
namespace juce
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
#if JUCE_PLUGINHOST_VST
|
#if JUCE_PLUGINHOST_VST
|
||||||
|
|
||||||
#include <juce_audio_processors_headless/format_types/juce_VSTPluginFormatImpl.h>
|
#include <juce_audio_processors_headless/format_types/juce_VSTPluginFormatImpl.h>
|
||||||
|
#include <juce_audio_processors/utilities/juce_NSViewComponentWithParent.h>
|
||||||
|
|
||||||
namespace juce
|
namespace juce
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -69,103 +69,6 @@
|
||||||
#include <AudioUnit/AudioUnit.h>
|
#include <AudioUnit/AudioUnit.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace juce
|
|
||||||
{
|
|
||||||
|
|
||||||
#if JUCE_MAC
|
|
||||||
|
|
||||||
//==============================================================================
|
|
||||||
/* This is an NSViewComponent which holds a long-lived NSView which acts
|
|
||||||
as the parent view for plugin editors.
|
|
||||||
|
|
||||||
Note that this component does not auto-resize depending on the bounds
|
|
||||||
of the owned view. VST2 and VST3 plugins have dedicated interfaces to
|
|
||||||
request that the editor bounds are updated. We can call `setSize` on this
|
|
||||||
component from inside those dedicated callbacks.
|
|
||||||
*/
|
|
||||||
struct NSViewComponentWithParent : public NSViewComponent,
|
|
||||||
private AsyncUpdater
|
|
||||||
{
|
|
||||||
enum class WantsNudge { no, yes };
|
|
||||||
|
|
||||||
explicit NSViewComponentWithParent (WantsNudge shouldNudge)
|
|
||||||
: wantsNudge (shouldNudge)
|
|
||||||
{
|
|
||||||
auto* view = [[getViewClass().createInstance() init] autorelease];
|
|
||||||
object_setInstanceVariable (view, "owner", this);
|
|
||||||
setView (view);
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit NSViewComponentWithParent (AudioPluginInstance& instance)
|
|
||||||
: NSViewComponentWithParent (getWantsNudge (instance)) {}
|
|
||||||
|
|
||||||
~NSViewComponentWithParent() override
|
|
||||||
{
|
|
||||||
if (auto* view = static_cast<NSView*> (getView()))
|
|
||||||
object_setInstanceVariable (view, "owner", nullptr);
|
|
||||||
|
|
||||||
cancelPendingUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
JUCE_DECLARE_NON_COPYABLE (NSViewComponentWithParent)
|
|
||||||
JUCE_DECLARE_NON_MOVEABLE (NSViewComponentWithParent)
|
|
||||||
|
|
||||||
private:
|
|
||||||
WantsNudge wantsNudge = WantsNudge::no;
|
|
||||||
|
|
||||||
static WantsNudge getWantsNudge (AudioPluginInstance& instance)
|
|
||||||
{
|
|
||||||
PluginDescription pd;
|
|
||||||
instance.fillInPluginDescription (pd);
|
|
||||||
return pd.manufacturerName == "FabFilter" ? WantsNudge::yes : WantsNudge::no;
|
|
||||||
}
|
|
||||||
|
|
||||||
void handleAsyncUpdate() override
|
|
||||||
{
|
|
||||||
if (auto* peer = getTopLevelComponent()->getPeer())
|
|
||||||
{
|
|
||||||
auto* view = static_cast<NSView*> (getView());
|
|
||||||
const auto newArea = peer->getAreaCoveredBy (*this);
|
|
||||||
[view setFrame: makeCGRect (newArea.withHeight (newArea.getHeight() + 1))];
|
|
||||||
[view setFrame: makeCGRect (newArea)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct InnerNSView final : public ObjCClass<NSView>
|
|
||||||
{
|
|
||||||
InnerNSView()
|
|
||||||
: ObjCClass ("JuceInnerNSView_")
|
|
||||||
{
|
|
||||||
addIvar<NSViewComponentWithParent*> ("owner");
|
|
||||||
|
|
||||||
addMethod (@selector (isOpaque), [] (id, SEL) { return YES; });
|
|
||||||
|
|
||||||
addMethod (@selector (didAddSubview:), [] (id self, SEL, NSView*)
|
|
||||||
{
|
|
||||||
if (auto* owner = getIvar<NSViewComponentWithParent*> (self, "owner"))
|
|
||||||
if (owner->wantsNudge == WantsNudge::yes)
|
|
||||||
owner->triggerAsyncUpdate();
|
|
||||||
});
|
|
||||||
|
|
||||||
JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wundeclared-selector")
|
|
||||||
addMethod (@selector (clipsToBounds), [] (id, SEL) { return YES; });
|
|
||||||
JUCE_END_IGNORE_WARNINGS_GCC_LIKE
|
|
||||||
|
|
||||||
registerClass();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static InnerNSView& getViewClass()
|
|
||||||
{
|
|
||||||
static InnerNSView result;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace juce
|
|
||||||
|
|
||||||
#include "format/juce_AudioPluginFormatManagerHelpers.cpp"
|
#include "format/juce_AudioPluginFormatManagerHelpers.cpp"
|
||||||
#include "processors/juce_AudioProcessorEditor.cpp"
|
#include "processors/juce_AudioProcessorEditor.cpp"
|
||||||
#include "processors/juce_GenericAudioProcessorEditor.cpp"
|
#include "processors/juce_GenericAudioProcessorEditor.cpp"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,131 @@
|
||||||
|
/*
|
||||||
|
==============================================================================
|
||||||
|
|
||||||
|
This file is part of the JUCE framework.
|
||||||
|
Copyright (c) Raw Material Software Limited
|
||||||
|
|
||||||
|
JUCE is an open source framework subject to commercial or open source
|
||||||
|
licensing.
|
||||||
|
|
||||||
|
By downloading, installing, or using the JUCE framework, or combining the
|
||||||
|
JUCE framework with any other source code, object code, content or any other
|
||||||
|
copyrightable work, you agree to the terms of the JUCE End User Licence
|
||||||
|
Agreement, and all incorporated terms including the JUCE Privacy Policy and
|
||||||
|
the JUCE Website Terms of Service, as applicable, which will bind you. If you
|
||||||
|
do not agree to the terms of these agreements, we will not license the JUCE
|
||||||
|
framework to you, and you must discontinue the installation or download
|
||||||
|
process and cease use of the JUCE framework.
|
||||||
|
|
||||||
|
JUCE End User Licence Agreement: https://juce.com/legal/juce-8-licence/
|
||||||
|
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
|
||||||
|
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
|
||||||
|
|
||||||
|
Or:
|
||||||
|
|
||||||
|
You may also use this code under the terms of the AGPLv3:
|
||||||
|
https://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
|
|
||||||
|
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
|
||||||
|
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
|
||||||
|
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if JUCE_MAC
|
||||||
|
|
||||||
|
namespace juce
|
||||||
|
{
|
||||||
|
|
||||||
|
/* This is an NSViewComponent which holds a long-lived NSView which acts
|
||||||
|
as the parent view for plugin editors.
|
||||||
|
|
||||||
|
Note that this component does not auto-resize depending on the bounds
|
||||||
|
of the owned view. VST2 and VST3 plugins have dedicated interfaces to
|
||||||
|
request that the editor bounds are updated. We can call `setSize` on this
|
||||||
|
component from inside those dedicated callbacks.
|
||||||
|
*/
|
||||||
|
struct NSViewComponentWithParent : public NSViewComponent,
|
||||||
|
private AsyncUpdater
|
||||||
|
{
|
||||||
|
enum class WantsNudge { no, yes };
|
||||||
|
|
||||||
|
explicit NSViewComponentWithParent (WantsNudge shouldNudge)
|
||||||
|
: wantsNudge (shouldNudge)
|
||||||
|
{
|
||||||
|
auto* view = [[getViewClass().createInstance() init] autorelease];
|
||||||
|
object_setInstanceVariable (view, "owner", this);
|
||||||
|
setView (view);
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit NSViewComponentWithParent (AudioPluginInstance& instance)
|
||||||
|
: NSViewComponentWithParent (getWantsNudge (instance)) {}
|
||||||
|
|
||||||
|
~NSViewComponentWithParent() override
|
||||||
|
{
|
||||||
|
if (auto* view = static_cast<NSView*> (getView()))
|
||||||
|
object_setInstanceVariable (view, "owner", nullptr);
|
||||||
|
|
||||||
|
cancelPendingUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
JUCE_DECLARE_NON_COPYABLE (NSViewComponentWithParent)
|
||||||
|
JUCE_DECLARE_NON_MOVEABLE (NSViewComponentWithParent)
|
||||||
|
|
||||||
|
private:
|
||||||
|
WantsNudge wantsNudge = WantsNudge::no;
|
||||||
|
|
||||||
|
static WantsNudge getWantsNudge (AudioPluginInstance& instance)
|
||||||
|
{
|
||||||
|
PluginDescription pd;
|
||||||
|
instance.fillInPluginDescription (pd);
|
||||||
|
return pd.manufacturerName == "FabFilter" ? WantsNudge::yes : WantsNudge::no;
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleAsyncUpdate() override
|
||||||
|
{
|
||||||
|
if (auto* peer = getTopLevelComponent()->getPeer())
|
||||||
|
{
|
||||||
|
auto* view = static_cast<NSView*> (getView());
|
||||||
|
const auto newArea = peer->getAreaCoveredBy (*this);
|
||||||
|
[view setFrame: makeCGRect (newArea.withHeight (newArea.getHeight() + 1))];
|
||||||
|
[view setFrame: makeCGRect (newArea)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct InnerNSView final : public ObjCClass<NSView>
|
||||||
|
{
|
||||||
|
InnerNSView()
|
||||||
|
: ObjCClass ("JuceInnerNSView_")
|
||||||
|
{
|
||||||
|
addIvar<NSViewComponentWithParent*> ("owner");
|
||||||
|
|
||||||
|
addMethod (@selector (isOpaque), [] (id, SEL) { return YES; });
|
||||||
|
|
||||||
|
addMethod (@selector (didAddSubview:), [] (id self, SEL, NSView*)
|
||||||
|
{
|
||||||
|
if (auto* owner = getIvar<NSViewComponentWithParent*> (self, "owner"))
|
||||||
|
if (owner->wantsNudge == WantsNudge::yes)
|
||||||
|
owner->triggerAsyncUpdate();
|
||||||
|
});
|
||||||
|
|
||||||
|
JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wundeclared-selector")
|
||||||
|
addMethod (@selector (clipsToBounds), [] (id, SEL) { return YES; });
|
||||||
|
JUCE_END_IGNORE_WARNINGS_GCC_LIKE
|
||||||
|
|
||||||
|
registerClass();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static InnerNSView& getViewClass()
|
||||||
|
{
|
||||||
|
static InnerNSView result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace juce
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Add table
Add a link
Reference in a new issue