mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
PopupMenu: Pass unique_ptr rather than raw pointers to convey ownership semantics
This commit is contained in:
parent
dd935cac84
commit
76f3aec386
3 changed files with 23 additions and 19 deletions
|
|
@ -1237,7 +1237,7 @@ private:
|
|||
//==============================================================================
|
||||
struct NormalComponentWrapper : public PopupMenu::CustomComponent
|
||||
{
|
||||
NormalComponentWrapper (Component* comp, int w, int h, bool triggerMenuItemAutomaticallyWhenClicked)
|
||||
NormalComponentWrapper (Component& comp, int w, int h, bool triggerMenuItemAutomaticallyWhenClicked)
|
||||
: PopupMenu::CustomComponent (triggerMenuItemAutomaticallyWhenClicked),
|
||||
width (w), height (h)
|
||||
{
|
||||
|
|
@ -1530,22 +1530,26 @@ void PopupMenu::addColouredItem (int itemResultID, String itemText, Colour itemT
|
|||
addItem (std::move (i));
|
||||
}
|
||||
|
||||
void PopupMenu::addCustomItem (int itemResultID, CustomComponent* cc, const PopupMenu* subMenu)
|
||||
void PopupMenu::addCustomItem (int itemResultID,
|
||||
std::unique_ptr<CustomComponent> cc,
|
||||
std::unique_ptr<const PopupMenu> subMenu)
|
||||
{
|
||||
Item i;
|
||||
i.itemID = itemResultID;
|
||||
i.customComponent = cc;
|
||||
i.subMenu.reset (createCopyIfNotNull (subMenu));
|
||||
i.customComponent = cc.release();
|
||||
i.subMenu.reset (createCopyIfNotNull (subMenu.get()));
|
||||
addItem (std::move (i));
|
||||
}
|
||||
|
||||
void PopupMenu::addCustomItem (int itemResultID, Component* customComponent, int idealWidth, int idealHeight,
|
||||
bool triggerMenuItemAutomaticallyWhenClicked, const PopupMenu* subMenu)
|
||||
void PopupMenu::addCustomItem (int itemResultID,
|
||||
Component& customComponent,
|
||||
int idealWidth, int idealHeight,
|
||||
bool triggerMenuItemAutomaticallyWhenClicked,
|
||||
std::unique_ptr<const PopupMenu> subMenu)
|
||||
{
|
||||
addCustomItem (itemResultID,
|
||||
new HelperClasses::NormalComponentWrapper (customComponent, idealWidth, idealHeight,
|
||||
triggerMenuItemAutomaticallyWhenClicked),
|
||||
subMenu);
|
||||
auto comp = std::make_unique<HelperClasses::NormalComponentWrapper> (customComponent, idealWidth, idealHeight,
|
||||
triggerMenuItemAutomaticallyWhenClicked);
|
||||
addCustomItem (itemResultID, std::move (comp), std::move (subMenu));
|
||||
}
|
||||
|
||||
void PopupMenu::addSubMenu (String subMenuName, PopupMenu subMenu, bool isActive)
|
||||
|
|
|
|||
|
|
@ -323,22 +323,21 @@ public:
|
|||
|
||||
/** Appends a custom menu item.
|
||||
|
||||
This will add a user-defined component to use as a menu item. The component
|
||||
passed in will be deleted by this menu when it's no longer needed.
|
||||
This will add a user-defined component to use as a menu item.
|
||||
|
||||
Note that native macOS menus do not support custom components.
|
||||
|
||||
@see CustomComponent
|
||||
*/
|
||||
void addCustomItem (int itemResultID,
|
||||
CustomComponent* customComponent,
|
||||
const PopupMenu* optionalSubMenu = nullptr);
|
||||
std::unique_ptr<CustomComponent> customComponent,
|
||||
std::unique_ptr<const PopupMenu> optionalSubMenu = nullptr);
|
||||
|
||||
/** Appends a custom menu item that can't be used to trigger a result.
|
||||
|
||||
This will add a user-defined component to use as a menu item.
|
||||
It's the caller's responsibility to delete the component that is passed-in
|
||||
when it's no longer needed after the menu has been hidden.
|
||||
The caller must ensure that the passed-in component stays alive
|
||||
until after the menu has been hidden.
|
||||
|
||||
If triggerMenuItemAutomaticallyWhenClicked is true, the menu itself will handle
|
||||
detection of a mouse-click on your component, and use that to trigger the
|
||||
|
|
@ -348,11 +347,11 @@ public:
|
|||
Note that native macOS menus do support custom components.
|
||||
*/
|
||||
void addCustomItem (int itemResultID,
|
||||
Component* customComponent,
|
||||
Component& customComponent,
|
||||
int idealWidth,
|
||||
int idealHeight,
|
||||
bool triggerMenuItemAutomaticallyWhenClicked,
|
||||
const PopupMenu* optionalSubMenu = nullptr);
|
||||
std::unique_ptr<const PopupMenu> optionalSubMenu = nullptr);
|
||||
|
||||
/** Appends a sub-menu.
|
||||
|
||||
|
|
|
|||
|
|
@ -542,7 +542,8 @@ void Toolbar::showMissingItems()
|
|||
if (missingItemsButton->isShowing())
|
||||
{
|
||||
PopupMenu m;
|
||||
m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
|
||||
auto comp = std::make_unique<MissingItemsComponent> (*this, getThickness());
|
||||
m.addCustomItem (1, std::move (comp));
|
||||
m.showMenuAsync (PopupMenu::Options().withTargetComponent (missingItemsButton.get()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue