The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. MenuBarModel::MenuBarModel() noexcept
  16. : manager (nullptr)
  17. {
  18. }
  19. MenuBarModel::~MenuBarModel()
  20. {
  21. setApplicationCommandManagerToWatch (nullptr);
  22. }
  23. //==============================================================================
  24. void MenuBarModel::menuItemsChanged()
  25. {
  26. triggerAsyncUpdate();
  27. }
  28. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* newManager)
  29. {
  30. if (manager != newManager)
  31. {
  32. if (manager != nullptr)
  33. manager->removeListener (this);
  34. manager = newManager;
  35. if (manager != nullptr)
  36. manager->addListener (this);
  37. }
  38. }
  39. void MenuBarModel::addListener (Listener* newListener)
  40. {
  41. listeners.add (newListener);
  42. }
  43. void MenuBarModel::removeListener (Listener* listenerToRemove)
  44. {
  45. // Trying to remove a listener that isn't on the list!
  46. // If this assertion happens because this object is a dangling pointer, make sure you've not
  47. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  48. jassert (listeners.contains (listenerToRemove));
  49. listeners.remove (listenerToRemove);
  50. }
  51. //==============================================================================
  52. void MenuBarModel::handleAsyncUpdate()
  53. {
  54. listeners.call ([this] (Listener& l) { l.menuBarItemsChanged (this); });
  55. }
  56. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  57. {
  58. listeners.call ([this, &info] (Listener& l) { l.menuCommandInvoked (this, info); });
  59. }
  60. void MenuBarModel::applicationCommandListChanged()
  61. {
  62. menuItemsChanged();
  63. }
  64. void MenuBarModel::handleMenuBarActivate (bool isActive)
  65. {
  66. menuBarActivated (isActive);
  67. listeners.call ([this, isActive] (Listener& l) { l.menuBarActivated (this, isActive); });
  68. }
  69. void MenuBarModel::menuBarActivated (bool) {}
  70. void MenuBarModel::Listener::menuBarActivated (MenuBarModel*, bool) {}
  71. } // namespace juce