openshot-audio  0.1.2
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
PopupMenu Class Reference

#include <juce_PopupMenu.h>

Classes

class  CustomComponent
 
struct  HelperClasses
 
class  Item
 
struct  LookAndFeelMethods
 
class  MenuItemIterator
 
class  Options
 

Public Types

enum  ColourIds {
  backgroundColourId = 0x1000700, textColourId = 0x1000600, headerTextColourId = 0x1000601, highlightedBackgroundColourId = 0x1000900,
  highlightedTextColourId = 0x1000800
}
 

Public Member Functions

 PopupMenu ()
 
 PopupMenu (const PopupMenu &other)
 
 ~PopupMenu ()
 
PopupMenuoperator= (const PopupMenu &other)
 
void clear ()
 
void addItem (int itemResultID, const String &itemText, bool isEnabled=true, bool isTicked=false)
 
void addItem (int itemResultID, const String &itemText, bool isEnabled, bool isTicked, const Image &iconToUse)
 
void addItem (int itemResultID, const String &itemText, bool isEnabled, bool isTicked, Drawable *iconToUse)
 
void addCommandItem (ApplicationCommandManager *commandManager, CommandID commandID, const String &displayName=String::empty)
 
void addColouredItem (int itemResultID, const String &itemText, Colour itemTextColour, bool isEnabled=true, bool isTicked=false, const Image &iconToUse=Image::null)
 
void addCustomItem (int itemResultID, Component *customComponent, int idealWidth, int idealHeight, bool triggerMenuItemAutomaticallyWhenClicked, const PopupMenu *optionalSubMenu=nullptr)
 
void addSubMenu (const String &subMenuName, const PopupMenu &subMenu, bool isEnabled=true)
 
void addSubMenu (const String &subMenuName, const PopupMenu &subMenu, bool isEnabled, const Image &iconToUse, bool isTicked=false, int itemResultID=0)
 
void addSubMenu (const String &subMenuName, const PopupMenu &subMenu, bool isEnabled, Drawable *iconToUse, bool isTicked=false, int itemResultID=0)
 
void addSeparator ()
 
void addSectionHeader (const String &title)
 
int getNumItems () const noexcept
 
bool containsCommandItem (int commandID) const
 
bool containsAnyActiveItems () const noexcept
 
void showMenuAsync (const Options &options, ModalComponentManager::Callback *callback)
 
void setLookAndFeel (LookAndFeel *newLookAndFeel)
 
void addCustomItem (int itemResultID, CustomComponent *customComponent, const PopupMenu *optionalSubMenu=nullptr)
 

Static Public Member Functions

static bool JUCE_CALLTYPE dismissAllActiveMenus ()
 

Friends

struct HelperClasses
 
class MenuBarComponent
 

Detailed Description

Creates and displays a popup-menu.

To show a popup-menu, you create one of these, add some items to it, then call its show() method, which returns the id of the item the user selects.

E.g.

void MyWidget::mouseDown (const MouseEvent& e)
{
m.addItem (1, "item 1");
m.addItem (2, "item 2");
const int result = m.show();
if (result == 0)
{
// user dismissed the menu without picking anything
}
else if (result == 1)
{
// user picked item 1
}
else if (result == 2)
{
// user picked item 2
}
}

Submenus are easy too:

void MyWidget::mouseDown (const MouseEvent& e)
{
PopupMenu subMenu;
subMenu.addItem (1, "item 1");
subMenu.addItem (2, "item 2");
PopupMenu mainMenu;
mainMenu.addItem (3, "item 3");
mainMenu.addSubMenu ("other choices", subMenu);
const int result = m.show();
...etc
}

Member Enumeration Documentation

A set of colour IDs to use to change the colour of various aspects of the menu.

These constants can be used either via the LookAndFeel::setColour() method for the look and feel that is set for this menu with setLookAndFeel()

See also
setLookAndFeel, LookAndFeel::setColour, LookAndFeel::findColour
Enumerator
backgroundColourId 

The colour to fill the menu's background with.

textColourId 

The colour for normal menu item text, (unless the colour is specified when the item is added).

headerTextColourId 

The colour for section header item text (see the addSectionHeader() method).

highlightedBackgroundColourId 

The colour to fill the background of the currently highlighted menu item.

highlightedTextColourId 

The colour to use for the text of the currently highlighted item.

Constructor & Destructor Documentation

PopupMenu::PopupMenu ( )

Creates an empty popup menu.

PopupMenu::PopupMenu ( const PopupMenu other)

Creates a copy of another menu.

PopupMenu::~PopupMenu ( )

Destructor.

Member Function Documentation

void PopupMenu::addColouredItem ( int  itemResultID,
const String itemText,
Colour  itemTextColour,
bool  isEnabled = true,
bool  isTicked = false,
const Image iconToUse = Image::null 
)

Appends a text item with a special colour.

This is the same as addItem(), but specifies a colour to use for the text, which will override the default colours that are used by the current look-and-feel. See addItem() for a description of the parameters.

void PopupMenu::addCommandItem ( ApplicationCommandManager commandManager,
CommandID  commandID,
const String displayName = String::empty 
)

Adds an item that represents one of the commands in a command manager object.

Parameters
commandManagerthe manager to use to trigger the command and get information about it
commandIDthe ID of the command
displayNameif this is non-empty, then this string will be used instead of the command's registered name
void PopupMenu::addCustomItem ( int  itemResultID,
Component customComponent,
int  idealWidth,
int  idealHeight,
bool  triggerMenuItemAutomaticallyWhenClicked,
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.

If triggerMenuItemAutomaticallyWhenClicked is true, the menu itself will handle detection of a mouse-click on your component, and use that to trigger the menu ID specified in itemResultID. If this is false, the menu item can't be triggered, so itemResultID is not used.

See also
CustomComponent
void PopupMenu::addCustomItem ( int  itemResultID,
CustomComponent customComponent,
const PopupMenu optionalSubMenu = nullptr 
)

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.

See also
CustomComponent
void PopupMenu::addItem ( int  itemResultID,
const String itemText,
bool  isEnabled = true,
bool  isTicked = false 
)

Appends a new text item for this menu to show.

Parameters
itemResultIDthe number that will be returned from the show() method if the user picks this item. The value should never be zero, because that's used to indicate that the user didn't select anything.
itemTextthe text to show.
isEnabledif false, the item will be shown 'greyed-out' and can't be picked
isTickedif true, the item will be shown with a tick next to it
See also
addSeparator, addColouredItem, addCustomItem, addSubMenu
void PopupMenu::addItem ( int  itemResultID,
const String itemText,
bool  isEnabled,
bool  isTicked,
const Image iconToUse 
)

Appends a new item with an icon.

Parameters
itemResultIDthe number that will be returned from the show() method if the user picks this item. The value should never be zero, because that's used to indicate that the user didn't select anything.
itemTextthe text to show.
isEnabledif false, the item will be shown 'greyed-out' and can't be picked
isTickedif true, the item will be shown with a tick next to it
iconToUseif this is a valid image, it will be displayed to the left of the item.
See also
addSeparator, addColouredItem, addCustomItem, addSubMenu
void PopupMenu::addItem ( int  itemResultID,
const String itemText,
bool  isEnabled,
bool  isTicked,
Drawable iconToUse 
)

Appends a new item with an icon.

Parameters
itemResultIDthe number that will be returned from the show() method if the user picks this item. The value should never be zero, because that's used to indicate that the user didn't select anything.
itemTextthe text to show.
isEnabledif false, the item will be shown 'greyed-out' and can't be picked
isTickedif true, the item will be shown with a tick next to it
iconToUsea Drawable object to use as the icon to the left of the item. The menu will take ownership of this drawable object and will delete it later when no longer needed
See also
addSeparator, addColouredItem, addCustomItem, addSubMenu
void PopupMenu::addSectionHeader ( const String title)

Adds a non-clickable text item to the menu.

This is a bold-font items which can be used as a header to separate the items into named groups.

void PopupMenu::addSeparator ( )

Appends a separator to the menu, to help break it up into sections.

The menu class is smart enough not to display separators at the top or bottom of the menu, and it will replace mutliple adjacent separators with a single one, so your code can be quite free and easy about adding these, and it'll always look ok.

void PopupMenu::addSubMenu ( const String subMenuName,
const PopupMenu subMenu,
bool  isEnabled = true 
)

Appends a sub-menu.

If the menu that's passed in is empty, it will appear as an inactive item. If the itemResultID argument is non-zero, then the sub-menu item itself can be clicked to trigger it as a command.

void PopupMenu::addSubMenu ( const String subMenuName,
const PopupMenu subMenu,
bool  isEnabled,
const Image iconToUse,
bool  isTicked = false,
int  itemResultID = 0 
)

Appends a sub-menu with an icon.

If the menu that's passed in is empty, it will appear as an inactive item. If the itemResultID argument is non-zero, then the sub-menu item itself can be clicked to trigger it as a command.

void PopupMenu::addSubMenu ( const String subMenuName,
const PopupMenu subMenu,
bool  isEnabled,
Drawable iconToUse,
bool  isTicked = false,
int  itemResultID = 0 
)

Appends a sub-menu with an icon.

If the menu that's passed in is empty, it will appear as an inactive item. If the itemResultID argument is non-zero, then the sub-menu item itself can be clicked to trigger it as a command.

The iconToUse parameter is a Drawable object to use as the icon to the left of the item. The menu will take ownership of this drawable object and will delete it later when no longer needed

void PopupMenu::clear ( )

Resets the menu, removing all its items.

bool PopupMenu::containsAnyActiveItems ( ) const
noexcept

Returns true if the menu contains any items that can be used.

bool PopupMenu::containsCommandItem ( int  commandID) const

Returns true if the menu contains a command item that triggers the given command.

bool JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus ( )
static

Closes any menus that are currently open.

This might be useful if you have a situation where your window is being closed by some means other than a user action, and you'd like to make sure that menus aren't left hanging around.

int PopupMenu::getNumItems ( ) const
noexcept

Returns the number of items that the menu currently contains.

(This doesn't count separators).

PopupMenu & PopupMenu::operator= ( const PopupMenu other)

Copies this menu from another one.

void PopupMenu::setLookAndFeel ( LookAndFeel newLookAndFeel)

Specifies a look-and-feel for the menu and any sub-menus that it has.

This can be called before show() if you need a customised menu. Be careful not to delete the LookAndFeel object before the menu has been deleted.

void PopupMenu::showMenuAsync ( const Options options,
ModalComponentManager::Callback callback 
)

Runs the menu asynchronously, with a user-provided callback that will receive the result.

Friends And Related Function Documentation

friend struct HelperClasses
friend
friend class MenuBarComponent
friend

The documentation for this class was generated from the following files: