KeyBoardFocus MAC/WIN


#1

Hello everybody I've got a little problem.

 I work in my Plugin with the class "TextEditor", but on Windows I had the problem, that they didnt get the keyboard focus. So I tried after some research a own TextEditor Class:

OwnTextEditor::OwnTextEditor (const String& componentName, const char passwordCharacter) :
    TextEditor (componentName, passwordCharacter),
    spippoling (false)
{
}


OwnPanTextEditor::~OwnTextEditor()
{
}

void OwnTextEditor::focusGained (FocusChangeType cause)
{
    if(spippoling)
        return;

    TextEditor::focusGained(cause);

    if(!isOnDesktop())
    {
        storedParentComponent = getParentComponent();
        jassert(storedParentComponent != 0);
        storedBoundsInParentComponent = getBounds();

        spippoling = true;
        addToDesktop(0);
        grabKeyboardFocus();
        spippoling = false;
    }
}

void OwnTextEditor::focusLost (FocusChangeType cause)
{
    if(spippoling)
        return;

    if(isOnDesktop())
    {
        jassert (storedParentComponent != 0);

        spippoling = true;
        storedParentComponent->addChildComponent(this);
        setBounds(storedBoundsInParentComponent);
        spippoling = false;
    }

    TextEditor::focusLost(cause);
}

This Class works well on windows and the editor gets the keyboard focus and I can write what I want.
But in on MAC-OSX this class didnt work, and if I click on the OwnTextEditor the Editor dissapers. Under MAC-OSX the "normal" TextEditor" works. Now I have been thinking about using the "Prae-Processor" to use under MAC the normal Editor and under WINDOWS my own.
But I dont want to do that!

I hope you can find my error, or any Ideas??


#2

Nobody any ideas?


#3

Not really sure what you mean, TBH.


#4

Jules, I recognized the code as the one I posted long ago here: http://www.juce.com/forum/topic/cubase-keyboard-input

He is referring to the fact that entering text in TextEditors may not work properly in some hosts, because they capture those key events for and don't pass them to plug-ins. The workaround he is using on Windows is to add the TextEditor to the desktop when it gains focus, and put it back in its original parent when the focus is lost (at least, that's what my original code did)

Funky_, this is an "evergreen" issue that doesn't seem to have a good solution yet. I actually still use the hacked TextEditor trick, and not only I use preprocessor #ifdefs to decide which editor to use on each platform, but I actually check at run-time what's the host that has loaded the plug-in, because both on Mac and on Windows there are hosts that behave differently from the "default" rule for the operating system.

My advice, anyway, is to avoid at all costs to sprinkle many #ifdefs in your code, one in every place where you use a text editor. It's much more efficient to write a global factory function, let's say

TextEditor* createPluginTextEditor (const String& componentName, const char passwordCharacter);

whose body will implement the logic behind deciding whether you need a regular TextEditor o a OwnTextEditor. This way, all you need to do if something in those rules changes, is to edit accordingly the body of that single function.

 


#5

I've tried out my plugin now in Reaper and i recognized, that the "normal" Texteditor does not work in Reaper. 

The editor does not get the EnterKeyStroke, so the "returnKeyPressed"-Callback is not called. 
If I set the option "Send all Keyboard Input to Plugin" in Reaper, nothing changes.

Is this a known Bug in Reaper? and how can this be avoided?