Browse Source

PopupMenu: Avoid giving focus back to previous component on dismiss

This change is designed to fix issues with views stealing focus and
being brought to the front when popup menus are dismissed.

To test this behaviour:
- Open two instances "a" and "b" of a plugin editor containing a
  ComboBox
- Click the ComboBox in editor "a", opening its PopupMenu
- Drag the titlebar of editor "b" to move it
- The PopupMenu should be dismissed, but editor "a" should *not* steal
  keyboard focus or be brought to the front
v6.1.6
reuk 4 years ago
parent
commit
c2f661171a
No known key found for this signature in database GPG Key ID: 9ADCD339CFC98A11
1 changed files with 12 additions and 21 deletions
  1. +12
    -21
      modules/juce_gui_basics/menus/juce_PopupMenu.cpp

+ 12
- 21
modules/juce_gui_basics/menus/juce_PopupMenu.cpp View File

@@ -2013,38 +2013,29 @@ struct PopupMenuCompletionCallback : public ModalComponentManager::Callback
if (PopupMenuSettings::menuWasHiddenBecauseOfAppChange)
return;
auto* focusComponent = getComponentToPassFocusTo();
const auto focusedIsNotMinimised = [focusComponent]
if (auto* focusComponent = Component::getCurrentlyFocusedComponent())
{
if (focusComponent != nullptr)
const auto focusedIsNotMinimised = [focusComponent]
{
if (auto* peer = focusComponent->getPeer())
return ! peer->isMinimised();
return false;
}();
return false;
}();
if (focusedIsNotMinimised)
{
if (auto* topLevel = focusComponent->getTopLevelComponent())
topLevel->toFront (true);
if (focusedIsNotMinimised)
{
if (auto* topLevel = focusComponent->getTopLevelComponent())
topLevel->toFront (true);
if (focusComponent->isShowing() && ! focusComponent->hasKeyboardFocus (true))
focusComponent->grabKeyboardFocus();
if (focusComponent->isShowing() && ! focusComponent->hasKeyboardFocus (true))
focusComponent->grabKeyboardFocus();
}
}
}
Component* getComponentToPassFocusTo() const
{
if (auto* current = Component::getCurrentlyFocusedComponent())
return current;
return prevFocused.get();
}
ApplicationCommandManager* managerOfChosenCommand = nullptr;
std::unique_ptr<Component> component;
WeakReference<Component> prevFocused { Component::getCurrentlyFocusedComponent() };
JUCE_DECLARE_NON_COPYABLE (PopupMenuCompletionCallback)
};


Loading…
Cancel
Save