Audio plugin host https://kx.studio/carla
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.

juce_MenuBarModel.cpp 2.8KB

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