I was playing around with adding some native widgets to an NSViewComponent like so:
#import <Cocoa/Cocoa.h>
class NativeTextField : public juce::NSViewComponent
{
public:
NativeTextField()
{
setSize(200, 30);
textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, getWidth(), getHeight())];
setView(textField);
}
~NativeTextField() override
{
[textField release];
}
private:
NSTextField* textField;
};
MainComponent::MainComponent()
: comp{ std::make_unique<NativeTextField>() }
{
addAndMakeVisible(*comp);
}
void MainComponent::resized()
{
comp->setTopLeftPosition(20, 20);
}
This works to an extend - a native text box is shown in the parent component, you can type text into it, etc. However none of the keyboard shortcuts like copy, paste, select-all, work and the following error message is shown in the console:
Gui App Example[5134:5357872] [miscellany] CLIENT ERROR: TUINSRemoteViewController does not override -viewServiceDidTerminateWithError: and thus cannot react to catastrophic errors beyond logging them
Maybe this is expected with NSViewComponent? I’m not sure what the intended scope of its functionality is, but it sure would be nice if this worked as expected!
There’s also other weird behaviours with other native widgets like dropdowns, not specifically shortcuts in text fields.
