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