Public Types | Public Member Functions

ToolbarItemComponent Class Reference

A component that can be used as one of the items in a Toolbar. More...

Inherits Button.

Inherited by ToolbarButton.

List of all members.

Public Types

enum  ToolbarEditingMode { normalMode = 0, editableOnToolbar, editableOnPalette }
 

Editing modes.

More...

Public Member Functions

 ToolbarItemComponent (int itemId, const String &labelText, bool isBeingUsedAsAButton)
 Constructor.
 ~ToolbarItemComponent ()
 Destructor.
int getItemId () const noexcept
 Returns the item type ID that this component represents.
ToolbargetToolbar () const
 Returns the toolbar that contains this component, or 0 if it's not currently inside one.
bool isToolbarVertical () const
 Returns true if this component is currently inside a toolbar which is vertical.
Toolbar::ToolbarItemStyle getStyle () const noexcept
 Returns the current style setting of this item.
virtual void setStyle (const Toolbar::ToolbarItemStyle &newStyle)
 Changes the current style setting of this item.
const Rectangle< int > getContentArea () const noexcept
 Returns the area of the component that should be used to display the button image or other contents of the item.
virtual bool getToolbarItemSizes (int toolbarThickness, bool isToolbarVertical, int &preferredSize, int &minSize, int &maxSize)=0
 This method must return the size criteria for this item, based on a given toolbar size and orientation.
virtual void paintButtonArea (Graphics &g, int width, int height, bool isMouseOver, bool isMouseDown)=0
 Your subclass should use this method to draw its content area.
virtual void contentAreaChanged (const Rectangle< int > &newBounds)=0
 Callback to indicate that the content area of this item has changed.
void setEditingMode (const ToolbarEditingMode newMode)
 Changes the editing mode of this component.
ToolbarEditingMode getEditingMode () const noexcept
 Returns the current editing mode of this component.
void paintButton (Graphics &g, bool isMouseOver, bool isMouseDown)
 Subclasses should override this to actually paint the button's contents.
void resized ()
 Called when this component's size has been changed.

Detailed Description

A component that can be used as one of the items in a Toolbar.

Each of the items on a toolbar must be a component derived from ToolbarItemComponent, and these objects are always created by a ToolbarItemFactory - see the ToolbarItemFactory class for further info about creating them.

The ToolbarItemComponent class is actually a button, but can be used to hold non-button components too. To do this, set the value of isBeingUsedAsAButton to false when calling the constructor, and override contentAreaChanged(), in which you can position any sub-components you need to add.

To add basic buttons without writing a special subclass, have a look at the ToolbarButton class.

See also:
ToolbarButton, Toolbar, ToolbarItemFactory

Member Enumeration Documentation

Editing modes.

These are used by setEditingMode(), but will be rarely needed in user code.

Enumerator:
normalMode 

Means that the component is active, inside a toolbar.

editableOnToolbar 

Means that the component is on a toolbar, but the toolbar is in customisation mode, and the items can be dragged around.

editableOnPalette 

Means that the component is on an new-item palette, so it can be dragged onto a toolbar to add it to that bar.


Constructor & Destructor Documentation

ToolbarItemComponent::ToolbarItemComponent ( int  itemId,
const String labelText,
bool  isBeingUsedAsAButton 
)

Constructor.

Parameters:
itemIdthe ID of the type of toolbar item which this represents
labelTextthe text to display if the toolbar's style is set to Toolbar::iconsWithText or Toolbar::textOnly
isBeingUsedAsAButtonset this to false if you don't want the button to draw itself with button over/down states when the mouse moves over it or clicks
ToolbarItemComponent::~ToolbarItemComponent (  )

Destructor.


Member Function Documentation

int ToolbarItemComponent::getItemId (  ) const

Returns the item type ID that this component represents.

This value is in the constructor.

Toolbar* ToolbarItemComponent::getToolbar (  ) const

Returns the toolbar that contains this component, or 0 if it's not currently inside one.

bool ToolbarItemComponent::isToolbarVertical (  ) const

Returns true if this component is currently inside a toolbar which is vertical.

See also:
Toolbar::isVertical
Toolbar::ToolbarItemStyle ToolbarItemComponent::getStyle (  ) const

Returns the current style setting of this item.

Styles are listed in the Toolbar::ToolbarItemStyle enum.

See also:
setStyle, Toolbar::getStyle
virtual void ToolbarItemComponent::setStyle ( const Toolbar::ToolbarItemStyle newStyle ) [virtual]

Changes the current style setting of this item.

Styles are listed in the Toolbar::ToolbarItemStyle enum, and are automatically updated by the toolbar that holds this item.

See also:
setStyle, Toolbar::setStyle
const Rectangle<int> ToolbarItemComponent::getContentArea (  ) const

Returns the area of the component that should be used to display the button image or other contents of the item.

This content area may change when the item's style changes, and may leave a space around the edge of the component where the text label can be shown.

See also:
contentAreaChanged
virtual bool ToolbarItemComponent::getToolbarItemSizes ( int  toolbarThickness,
bool  isToolbarVertical,
int &  preferredSize,
int &  minSize,
int &  maxSize 
) [pure virtual]

This method must return the size criteria for this item, based on a given toolbar size and orientation.

The preferredSize, minSize and maxSize values must all be set by your implementation method. If the toolbar is horizontal, these will be the width of the item; for a vertical toolbar, they refer to the item's height.

The preferredSize is the size that the component would like to be, and this must be between the min and max sizes. For a fixed-size item, simply set all three variables to the same value.

The toolbarThickness parameter tells you the depth of the toolbar - the same as calling Toolbar::getThickness().

The isToolbarVertical parameter tells you whether the bar is oriented horizontally or vertically.

Implemented in ToolbarButton.

virtual void ToolbarItemComponent::paintButtonArea ( Graphics g,
int  width,
int  height,
bool  isMouseOver,
bool  isMouseDown 
) [pure virtual]

Your subclass should use this method to draw its content area.

The graphics object that is passed-in will have been clipped and had its origin moved to fit the content area as specified get getContentArea(). The width and height parameters are the width and height of the content area.

If the component you're writing isn't a button, you can just do nothing in this method.

Implemented in ToolbarButton.

virtual void ToolbarItemComponent::contentAreaChanged ( const Rectangle< int > &  newBounds ) [pure virtual]

Callback to indicate that the content area of this item has changed.

This might be because the component was resized, or because the style changed and the space needed for the text label is different.

See getContentArea() for a description of what the area is.

Implemented in ToolbarButton.

void ToolbarItemComponent::setEditingMode ( const ToolbarEditingMode  newMode )

Changes the editing mode of this component.

This is used by the ToolbarItemPalette and related classes for making the items draggable, and is unlikely to be of much use in end-user-code.

ToolbarEditingMode ToolbarItemComponent::getEditingMode (  ) const

Returns the current editing mode of this component.

This is used by the ToolbarItemPalette and related classes for making the items draggable, and is unlikely to be of much use in end-user-code.

void ToolbarItemComponent::paintButton ( Graphics g,
bool  isMouseOverButton,
bool  isButtonDown 
) [virtual]

Subclasses should override this to actually paint the button's contents.

It's better to use this than the paint method, because it gives you information about the over/down state of the button.

Parameters:
gthe graphics context to use
isMouseOverButtontrue if the button is either in the 'over' or 'down' state
isButtonDowntrue if the button should be drawn in the 'down' position

Implements Button.

void ToolbarItemComponent::resized (  ) [virtual]

Called when this component's size has been changed.

A component can implement this method to do things such as laying out its child components when its width or height changes.

The method is called synchronously as a result of the setBounds or setSize methods, so repeatedly changing a components size will repeatedly call its resized method (unlike things like repainting, where multiple calls to repaint are coalesced together).

If the component is a top-level window on the desktop, its size could also be changed by operating-system factors beyond the application's control.

See also:
moved, setSize

Reimplemented from Component.

Reimplemented in ToolbarButton.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines