gcn::DropDown Class Reference

#include <dropdown.hpp>

Inheritance diagram for gcn::DropDown:

gcn::ActionListener gcn::BasicContainer gcn::KeyListener gcn::MouseListener gcn::FocusListener gcn::SelectionListener gcn::Widget gcn::DeathListener List of all members.

Detailed Description

An implementation of a drop downable list from which an item can be selected.

The drop down consists of an internal ScrollArea and an internal ListBox. The drop down also uses an internal FocusHandler to handle the focus of the internal ScollArea and the internal ListBox. The scroll area and the list box can be passed to the drop down if a custom scroll area and or a custom list box is preferable.

To be able display a list the drop down uses a user provided list model. A list model can be any class that implements the ListModel interface.

If an item is selected in the drop down a select event will be sent to all selection listeners of the drop down. If an item is selected by using a mouse click or by using the enter or space key an action event will be sent to all action listeners of the drop down.

Definition at line 91 of file dropdown.hpp.

Public Member Functions

virtual void action (const ActionEvent &actionEvent)
 Called when an action is recieved from a widget.
void addSelectionListener (SelectionListener *selectionListener)
 Adds a selection listener to the drop down.
void adjustHeight ()
 Adjusts the height of the drop down to fit the height of the drop down's parent's height.
virtual void death (const Event &event)
 Called when a widget dies.
virtual void draw (Graphics *graphics)
 Draws the widget.
 DropDown (ListModel *listModel=NULL, ScrollArea *scrollArea=NULL, ListBox *listBox=NULL)
 Contructor.
virtual void focusLost (const Event &event)
 Called when a widget loses focus.
virtual Rectangle getChildrenArea ()
 Gets the area of the widget that the widget's children occupy.
ListModelgetListModel ()
 Gets the list model used.
int getSelected () const
 Gets the selected item as an index in the list model.
virtual void keyPressed (KeyEvent &keyEvent)
 Called if a key is pressed when the widget has keyboard focus.
virtual void mouseDragged (MouseEvent &mouseEvent)
 Called when the mouse has moved and the mouse has previously been pressed on the widget.
virtual void mousePressed (MouseEvent &mouseEvent)
 Called when a mouse button has been pressed on the widget area.
virtual void mouseReleased (MouseEvent &mouseEvent)
 Called when a mouse button has been released on the widget area.
virtual void mouseWheelMovedDown (MouseEvent &mouseEvent)
 Called when the mouse wheel has moved down on the widget area.
virtual void mouseWheelMovedUp (MouseEvent &mouseEvent)
 Called when the mouse wheel has moved up on the widget area.
void removeSelectionListener (SelectionListener *selectionListener)
 Removes a selection listener from the drop down.
void setBackgroundColor (const Color &color)
 Sets the background color.
void setBaseColor (const Color &color)
 Sets the base color of the widget.
void setFont (Font *font)
 Sets the font for the widget.
void setForegroundColor (const Color &color)
 Sets the foreground color.
void setListModel (ListModel *listModel)
 Sets the list model to use when displaying the list.
void setSelected (int selected)
 Sets the selected item.
void setSelectionColor (const Color &color)
 Sets the selection color.
virtual void valueChanged (const SelectionEvent &event)
 Called when a value has been changed in a Widget.
virtual ~DropDown ()
 Destructor.

Protected Types

typedef SelectionListenerList::iterator SelectionListenerIterator
 Typedef.
typedef std::list< SelectionListener * > SelectionListenerList
 Typedef.

Protected Member Functions

void distributeValueChangedEvent ()
 Distributes a value changed event to all selection listeners of the drop down.
virtual void drawButton (Graphics *graphics)
 Draws the button of the drop down.
virtual void dropDown ()
 Sets the drop down to be dropped down.
virtual void foldUp ()
 Sets the drop down to be folded up.

Protected Attributes

bool mDroppedDown
 True if the drop down is dropped down, false otherwise.
int mFoldedUpHeight
 Holds what the height is if the drop down is folded up.
FocusHandler mInternalFocusHandler
 The internal focus handler used to keep track of focus for the internal list box.
bool mInternalListBox
 True if an internal list box is used, false if a list box has been passed to the drop down which the drop down should not deleted in it's destructor.
bool mInternalScrollArea
 True if an internal scroll area is used, false if a scroll area has been passed to the drop down which the drop down should not deleted in it's destructor.
bool mIsDragged
 True if the drop down is dragged.
ListBoxmListBox
 The list box used.
bool mPushed
 True if the drop down has been pushed with the mouse, false otherwise.
ScrollAreamScrollArea
 The scroll area used.
SelectionListenerList mSelectionListeners
 The selection listener's of the drop down.


Constructor & Destructor Documentation

gcn::DropDown::DropDown ( ListModel listModel = NULL,
ScrollArea scrollArea = NULL,
ListBox listBox = NULL 
)

Contructor.

Parameters:
listModel the ListModel to use.
scrollArea the ScrollArea to use.
listBox the listBox to use.
See also:
ListModel, ScrollArea, ListBox.

Definition at line 70 of file dropdown.cpp.

References gcn::Widget::addActionListener(), gcn::Widget::addFocusListener(), gcn::Widget::addKeyListener(), gcn::Widget::addMouseListener(), gcn::ListBox::addSelectionListener(), adjustHeight(), gcn::ListBox::getSelected(), mDroppedDown, mInternalFocusHandler, mInternalListBox, mInternalScrollArea, mIsDragged, mListBox, mPushed, mScrollArea, gcn::ScrollArea::setContent(), gcn::Widget::setFocusable(), gcn::BasicContainer::setInternalFocusHandler(), setListModel(), gcn::ListBox::setSelected(), and gcn::Widget::setWidth().


Member Function Documentation

void gcn::DropDown::action ( const ActionEvent actionEvent  )  [virtual]

Called when an action is recieved from a widget.

It is used to be able to recieve a notification that an action has occured.

Parameters:
actionEvent The event of the action.
Since:
0.6.0

Implements gcn::ActionListener.

Definition at line 505 of file dropdown.cpp.

References gcn::Widget::distributeActionEvent(), foldUp(), and gcn::Widget::releaseModalMouseInputFocus().

void gcn::DropDown::addSelectionListener ( SelectionListener selectionListener  ) 

Adds a selection listener to the drop down.

When the selection changes an event will be sent to all selection listeners of the drop down.

Parameters:
selectionListener the selection listener to add.
Since:
0.8.0

Definition at line 624 of file dropdown.cpp.

References mSelectionListeners.

void gcn::DropDown::adjustHeight (  ) 

Adjusts the height of the drop down to fit the height of the drop down's parent's height.

It's used to not make the drop down draw itself outside of it's parent if folded down.

Definition at line 417 of file dropdown.cpp.

References gcn::ScrollArea::getChildrenArea(), gcn::Widget::getChildrenArea(), gcn::Widget::getFont(), gcn::Font::getHeight(), gcn::Widget::getHeight(), gcn::Widget::getParent(), gcn::Widget::getWidth(), gcn::Widget::getY(), gcn::Rectangle::height, mDroppedDown, mListBox, mScrollArea, gcn::ScrollArea::setHeight(), gcn::Widget::setHeight(), gcn::Widget::setPosition(), gcn::Widget::setWidth(), gcn::ScrollArea::setWidth(), and gcn::Rectangle::width.

Referenced by dropDown(), DropDown(), foldUp(), and setListModel().

void gcn::DropDown::death ( const Event event  )  [virtual]

Called when a widget dies.

It is used to be able to recieve a notification when a death of a widget occurs.

Parameters:
event The event of the death.

Reimplemented from gcn::BasicContainer.

Definition at line 495 of file dropdown.cpp.

References gcn::BasicContainer::death(), gcn::Event::getSource(), and mScrollArea.

void gcn::DropDown::distributeValueChangedEvent (  )  [protected]

Distributes a value changed event to all selection listeners of the drop down.

Since:
0.8.0

Definition at line 634 of file dropdown.cpp.

References mSelectionListeners.

Referenced by valueChanged().

void gcn::DropDown::draw ( Graphics graphics  )  [virtual]

Draws the widget.

It is called by the parent widget when it is time for the widget to draw itself. The graphics object is set up so that all drawing is relative to the widget, i.e coordinate (0,0) is the top left corner of the widget. It is not possible to draw outside of a widget's dimension.

Parameters:
graphics aA graphics object to draw with.
Since:
0.1.0

Implements gcn::Widget.

Definition at line 144 of file dropdown.cpp.

References gcn::Color::a, drawButton(), gcn::BasicContainer::drawChildren(), gcn::Graphics::drawLine(), gcn::Graphics::drawRectangle(), gcn::Graphics::drawText(), gcn::Graphics::fillRectangle(), gcn::Widget::getBackgroundColor(), gcn::Widget::getBaseColor(), gcn::Graphics::getCurrentClipArea(), gcn::ListModel::getElementAt(), gcn::Widget::getFont(), gcn::Widget::getForegroundColor(), gcn::Widget::getHeight(), gcn::ListBox::getListModel(), gcn::ListBox::getSelected(), gcn::Widget::getSelectionColor(), gcn::Widget::getWidth(), gcn::Rectangle::height, gcn::Widget::isFocused(), mDroppedDown, mFoldedUpHeight, mListBox, gcn::Graphics::popClipArea(), gcn::Graphics::pushClipArea(), gcn::Graphics::setColor(), gcn::Graphics::setFont(), and gcn::Rectangle::width.

void gcn::DropDown::drawButton ( Graphics graphics  )  [protected, virtual]

Draws the button of the drop down.

Parameters:
graphics a Graphics object to draw with.

Definition at line 221 of file dropdown.cpp.

References gcn::Color::a, gcn::Graphics::drawLine(), gcn::Graphics::fillRectangle(), gcn::Widget::getBaseColor(), gcn::Graphics::getCurrentClipArea(), gcn::Widget::getForegroundColor(), gcn::Rectangle::height, mPushed, gcn::Graphics::setColor(), and gcn::Rectangle::width.

Referenced by draw().

void gcn::DropDown::focusLost ( const Event event  )  [virtual]

Called when a widget loses focus.

Parameters:
event Discribes the event.

Reimplemented from gcn::FocusListener.

Definition at line 488 of file dropdown.cpp.

References gcn::FocusHandler::focusNone(), foldUp(), and mInternalFocusHandler.

Rectangle gcn::DropDown::getChildrenArea (  )  [virtual]

Gets the area of the widget that the widget's children occupy.

Returns:
The area of the widget that the widget's children occupy.
Since:
0.1.0

Reimplemented from gcn::BasicContainer.

Definition at line 512 of file dropdown.cpp.

References gcn::Widget::getHeight(), gcn::Widget::getWidth(), mDroppedDown, and mFoldedUpHeight.

ListModel * gcn::DropDown::getListModel (  ) 

Gets the list model used.

Returns:
the ListModel used.
See also:
setListModel

Definition at line 412 of file dropdown.cpp.

References gcn::ListBox::getListModel(), and mListBox.

int gcn::DropDown::getSelected (  )  const

Gets the selected item as an index in the list model.

Returns:
the selected item as an index in the list model.
See also:
setSelected

Definition at line 289 of file dropdown.cpp.

References gcn::ListBox::getSelected(), and mListBox.

Referenced by keyPressed().

void gcn::DropDown::keyPressed ( KeyEvent keyEvent  )  [virtual]

Called if a key is pressed when the widget has keyboard focus.

If a key is held down the widget will generate multiple key presses.

Parameters:
keyEvent Discribes the event.

Reimplemented from gcn::KeyListener.

Definition at line 302 of file dropdown.cpp.

References gcn::InputEvent::consume(), gcn::Key::DOWN, dropDown(), gcn::Key::ENTER, gcn::KeyEvent::getKey(), getSelected(), gcn::Key::getValue(), mDroppedDown, setSelected(), gcn::Key::SPACE, and gcn::Key::UP.

void gcn::DropDown::mouseDragged ( MouseEvent mouseEvent  )  [virtual]

Called when the mouse has moved and the mouse has previously been pressed on the widget.

Parameters:
mouseEvent Describes the event.
Since:
0.6.0

Reimplemented from gcn::MouseListener.

Definition at line 393 of file dropdown.cpp.

References gcn::InputEvent::consume(), and mIsDragged.

void gcn::DropDown::mousePressed ( MouseEvent mouseEvent  )  [virtual]

Called when a mouse button has been pressed on the widget area.

NOTE: A mouse press is NOT equal to a mouse click. Use mouseClickMessage to check for mouse clicks.

Parameters:
mouseEvent Describes the event.
Since:
0.6.0

Reimplemented from gcn::MouseListener.

Definition at line 324 of file dropdown.cpp.

References dropDown(), foldUp(), gcn::MouseEvent::getButton(), gcn::Widget::getHeight(), gcn::Event::getSource(), gcn::Widget::getWidth(), gcn::MouseEvent::getX(), gcn::MouseEvent::getY(), gcn::MouseEvent::LEFT, mDroppedDown, mFoldedUpHeight, mPushed, gcn::Widget::releaseModalMouseInputFocus(), and gcn::Widget::requestModalMouseInputFocus().

void gcn::DropDown::mouseReleased ( MouseEvent mouseEvent  )  [virtual]

Called when a mouse button has been released on the widget area.

Parameters:
mouseEvent Describes the event.
Since:
0.6.0

Reimplemented from gcn::MouseListener.

Definition at line 363 of file dropdown.cpp.

References foldUp(), gcn::MouseEvent::getButton(), gcn::Widget::getHeight(), gcn::Widget::getWidth(), gcn::MouseEvent::getX(), gcn::MouseEvent::getY(), gcn::Widget::isModalMouseInputFocused(), gcn::MouseEvent::LEFT, mIsDragged, mPushed, and gcn::Widget::releaseModalMouseInputFocus().

void gcn::DropDown::mouseWheelMovedDown ( MouseEvent mouseEvent  )  [virtual]

Called when the mouse wheel has moved down on the widget area.

Parameters:
mousEvent Describes the event.
Since:
0.6.0

Reimplemented from gcn::MouseListener.

Definition at line 599 of file dropdown.cpp.

References gcn::InputEvent::consume(), gcn::ListBox::getSelected(), gcn::Event::getSource(), gcn::Widget::isFocused(), mListBox, and gcn::ListBox::setSelected().

void gcn::DropDown::mouseWheelMovedUp ( MouseEvent mouseEvent  )  [virtual]

Called when the mouse wheel has moved up on the widget area.

Parameters:
mouseEvent Describes the event.
Since:
0.6.0

Reimplemented from gcn::MouseListener.

Definition at line 586 of file dropdown.cpp.

References gcn::InputEvent::consume(), gcn::ListBox::getSelected(), gcn::Event::getSource(), gcn::Widget::isFocused(), mListBox, and gcn::ListBox::setSelected().

void gcn::DropDown::removeSelectionListener ( SelectionListener selectionListener  ) 

Removes a selection listener from the drop down.

Parameters:
selectionListener the selection listener to remove.
Since:
0.8.0

Definition at line 629 of file dropdown.cpp.

References mSelectionListeners.

void gcn::DropDown::setBackgroundColor ( const Color color  ) 

Sets the background color.

Parameters:
color The background Color.
See also:
setBackgroundColor
Since:
0.1.0

Reimplemented from gcn::Widget.

Definition at line 541 of file dropdown.cpp.

References mInternalListBox, mInternalScrollArea, mListBox, mScrollArea, and gcn::Widget::setBackgroundColor().

void gcn::DropDown::setBaseColor ( const Color color  ) 

Sets the base color of the widget.

Parameters:
color The baseground color.
See also:
getBaseColor
Since:
0.1.0

Reimplemented from gcn::Widget.

Definition at line 526 of file dropdown.cpp.

References mInternalListBox, mInternalScrollArea, mListBox, mScrollArea, and gcn::Widget::setBaseColor().

void gcn::DropDown::setFont ( Font font  ) 

Sets the font for the widget.

If NULL is passed, the global font will be used.

Parameters:
font The font to set for the widget.
See also:
getFont
Since:
0.1.0

Reimplemented from gcn::Widget.

Definition at line 571 of file dropdown.cpp.

References mInternalListBox, mInternalScrollArea, mListBox, mScrollArea, and gcn::Widget::setFont().

void gcn::DropDown::setForegroundColor ( const Color color  ) 

Sets the foreground color.

Parameters:
color The foreground color.
See also:
getForegroundColor
Since:
0.1.0

Reimplemented from gcn::Widget.

Definition at line 556 of file dropdown.cpp.

References mInternalListBox, mInternalScrollArea, mListBox, mScrollArea, and gcn::Widget::setForegroundColor().

void gcn::DropDown::setListModel ( ListModel listModel  ) 

Sets the list model to use when displaying the list.

Parameters:
listModel the list model to use.
See also:
getListModel

Definition at line 400 of file dropdown.cpp.

References adjustHeight(), gcn::ListBox::getSelected(), mListBox, gcn::ListBox::setListModel(), and gcn::ListBox::setSelected().

Referenced by DropDown().

void gcn::DropDown::setSelected ( int  selected  ) 

Sets the selected item.

The selected item is represented by an index from the list model.

Parameters:
selected the selected item as an index from the list model.
See also:
getSelected

Definition at line 294 of file dropdown.cpp.

References mListBox, and gcn::ListBox::setSelected().

Referenced by keyPressed().

void gcn::DropDown::setSelectionColor ( const Color color  ) 

Sets the selection color.

Parameters:
color The selection color.
See also:
getSelectionColor
Since:
0.6.0

Reimplemented from gcn::Widget.

Definition at line 609 of file dropdown.cpp.

References mInternalListBox, mListBox, and gcn::Widget::setSelectionColor().

void gcn::DropDown::valueChanged ( const SelectionEvent event  )  [virtual]

Called when a value has been changed in a Widget.

It is used to be able to recieve a notification that a value has been changed.

Parameters:
event The event of the value change.
Since:
0.8.0

Reimplemented from gcn::SelectionListener.

Definition at line 619 of file dropdown.cpp.

References distributeValueChangedEvent().


Member Data Documentation

int gcn::DropDown::mFoldedUpHeight [protected]

Holds what the height is if the drop down is folded up.

Used when checking if the list of the drop down was clicked or if the upper part of the drop down was clicked on a mouse click

Definition at line 275 of file dropdown.hpp.

Referenced by draw(), dropDown(), getChildrenArea(), and mousePressed().


The documentation for this class was generated from the following files:
Generated on Sun Jan 20 21:48:14 2008 for Guichan by  doxygen 1.5.2