if (modifierKey)
{
int keyMods = 0;
if (modifierKey == VKEY_CONTROL) keyMods |= ModifierKeys::ctrlModifier;
if (modifierKey == VKEY_SHIFT) keyMods |= ModifierKeys::shiftModifier;
if (modifierKey == VKEY_ALT) keyMods |= ModifierKeys::altModifier;
ModifierKeys::getCurrentModifiers().withFlags (keyMods);
}
ssaue wrote:Thanks. I assume you are basically doing the same: A text editor in a new modal window?
ssaue wrote:By the way, have you tested your solution with Reaper? We have noticed that window popups disappear behind the VST editor due to a "pinned-on-top"-mechanism in Reaper. This messes up the popup menus of comboboxes for instance. Could the same happen with your modal editors?
Jakob wrote:The code I've posted on page 1 works perfectly for us. No complaints from users so far, and having quite a big user base with RTAS/VST/AU, Mac+PC. Only thing is that some special characters are caught by some hosts (the @ for example).
#include "juce.h"
class HadronLabel : public Label
{
public:
HadronLabel(const String& name = String::empty, const String& labelText = String::empty);
~HadronLabel();
private:
bool use_modal_editor_;
// Override to allow custom text editor
virtual void mouseDoubleClick(const MouseEvent& e);
virtual void textEditorReturnKeyPressed(TextEditor& editor);
virtual void textEditorEscapeKeyPressed(TextEditor& editor);
virtual void textEditorFocusLost(TextEditor& editor);
// Hide copy constructor and assignment operator
HadronLabel(const HadronLabel&);
const HadronLabel operator= (const HadronLabel&);
};
#include "HadronLabel.h"
HadronLabel::HadronLabel(const String& name, const String& labelText)
: Label(name, labelText)
, use_modal_editor_(false)
{
#if _WIN32
// Windows need special handling (unless sonar is the host)
const String hostPath(File::getSpecialLocation(File::hostApplicationPath).getFullPathName());
const String hostFilename(File(hostPath).getFileName());
bool is_sonar = hostFilename.containsIgnoreCase("SONAR");
use_modal_editor_ = !is_sonar;
#endif
}
HadronLabel::~HadronLabel()
{
}
void HadronLabel::mouseDoubleClick(const MouseEvent& e)
{
if (use_modal_editor_) {
if (isEditableOnDoubleClick() && ! e.mods.isPopupMenu()) {
ModalComponentManager::Callback* userCallback = 0;
ScopedPointer<ModalComponentManager::Callback> userCallbackDeleter (userCallback);
Component::SafePointer<Component> prevFocused (Component::getCurrentlyFocusedComponent());
Component::SafePointer<Component> prevTopLevel ((prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0);
ScopedPointer <TextEditor> texteditor = createEditorComponent();
texteditor->setColour(TextEditor::backgroundColourId, Colours::black);
texteditor->setWantsKeyboardFocus (true);
texteditor->setAlwaysOnTop (true);
// Find screen position
Rectangle<int> sr (getBounds ());
sr.setPosition (getScreenX(), getScreenY());
int fontheight = static_cast<int>(texteditor->getFont().getHeight()) + 4;
if (sr.getHeight() > fontheight) {
sr.translate (0, (sr.getHeight() - fontheight)/2);
sr.setHeight (fontheight);
}
texteditor->setBounds(sr);
texteditor->setText(getText(),false);
texteditor->setHighlightedRegion (Range <int> (0, getText().length ()));
texteditor->setVisible (true);
texteditor->grabKeyboardFocus();
texteditor->addToDesktop (ComponentPeer::windowIsTemporary, 0);
texteditor->addListener (this);
texteditor->enterModalState (false);
texteditor->grabKeyboardFocus();
texteditor->runModalLoop();
if (prevTopLevel != 0)
prevTopLevel->toFront (true);
if (prevFocused != 0)
prevFocused->grabKeyboardFocus();
}
}
else {
Label::mouseDoubleClick(e);
}
}
void HadronLabel::textEditorReturnKeyPressed(TextEditor& editor)
{
if (use_modal_editor_) {
setText(editor.getText(), true);
editor.exitModalState(0);
}
else {
Label::textEditorReturnKeyPressed(editor);
}
}
void HadronLabel::textEditorEscapeKeyPressed(TextEditor& editor)
{
if (use_modal_editor_) {
editor.exitModalState(0);
}
else {
Label::textEditorEscapeKeyPressed(editor);
}
}
void HadronLabel::textEditorFocusLost(TextEditor& editor)
{
if (use_modal_editor_) {
editor.exitModalState(0);
}
else {
Label::textEditorFocusLost(editor);
}
}
bdejong wrote:this should REALLY be fixed at the level of Juce as far as I'm concerned...
Users browsing this forum: No registered users and 2 guests