# WoopsiUI::ListBox Class Reference

`#include <listbox.h>`

Inheritance diagram for WoopsiUI::ListBox:

List of all members.

## Public Member Functions
| ListBox (s16 x, s16 y, u16 width, u16 height, FontBase *font=NULL)
virtual void | addOption (const char *text, const u32 value)
virtual void | removeOption (const s32 index)
virtual void | removeAllOptions ()
virtual void | addOption (const char *text, const u32 value, const u16 normalTextColour, const u16 normalBackColour, const u16 selectedTextColour, const u16 selectedBackColour)
virtual void | selectOption (const s32 index)
virtual void | deselectOption (const s32 index)
virtual void | selectAllOptions ()
virtual void | deselectAllOptions ()
virtual void | draw (Rect clipRect)
virtual const s32 | getSelectedIndex () const
virtual void | setSelectedIndex (const s32 index)
virtual const ListData::ListDataItem * | getSelectedOption () const
virtual bool | click (s16 x, s16 y)
virtual bool | doubleClick (s16 x, s16 y)
virtual void | setAllowMultipleSelections (const bool allowMultipleSelections)
virtual const bool | allowsMultipleSelections () const
virtual void | resizeCanvas ()
virtual ListData::ListDataItem * | getOption (const s32 index)
virtual void | sort ()
virtual const s32 | getOptionCount () const
virtual const u16 | getOptionHeight () const
virtual void | setSortInsertedItems (const bool sortInsertedItems)
virtual void | handleListDataChangedEvent (const ListDataEventArgs &e)
virtual void | handleListDataSelectionChangedEvent (const ListDataEventArgs &e)
## Protected Member Functions
virtual | ~ListBox ()
virtual void | setOptionSelected (const s32 index, const bool selected)
| ListBox (const ListBox &listBox)
## Protected Attributes
ListData | _options
u8 | _optionPadding

## Detailed Description

Class providing a scrollable list of options. The ListBox can be set up to only allow one selection or multiple selections. Processes double-clicks and raises double-click events, so that a double-click on an option can be made to automatically select and close a window/etc. The options themselves have user-definable text and background colours for their selected and unselected states.

## Constructor & Destructor Documentation

WoopsiUI::ListBox::ListBox | ( | s16 | x,
|  | s16 | y,
|  | u16 | width,
|  | u16 | height,
|  | FontBase * | font = `NULL` |
| ) |  |  |

Constructor.

Parameters:

  | x | The x co-ordinate of the gadget.
  | y | The y co-ordinate of the gadget.
  | width | The width of the gadget.
  | height | The height of the gadget.
  | font | The font to use with the listbox.

virtual WoopsiUI::ListBox::~ListBox | ( |  | ) | `[protected, virtual]`

Destructor.

WoopsiUI::ListBox::ListBox | ( | const ListBox & | listBox | ) | `[inline, protected]`

Copy constructor is protected to prevent usage.

## Member Function Documentation

virtual void WoopsiUI::ListBox::addOption | ( | const char * | text,
|  | const u32 | value,
|  | const u16 | normalTextColour,
|  | const u16 | normalBackColour,
|  | const u16 | selectedTextColour,
|  | const u16 | selectedBackColour |
| ) |  |  | `[virtual]`

Add a new option to the gadget. Does not redraw the gadget.

Parameters:

  | text | Text to show in the option.
  | value | The value of the option.
  | normalTextColour | Colour to draw the text with when not selected.
  | normalBackColour | Colour to draw the background with when not selected.
  | selectedTextColour | Colour to draw the text with when selected.
  | selectedBackColour | Colour to draw the background with when selected.

virtual void WoopsiUI::ListBox::addOption | ( | const char * | text,
|  | const u32 | value |
| ) |  |  | `[virtual]`

Add a new option to the gadget using default colours. Does not redraw the gadget.

Parameters:

  | text | Text to show in the option.
  | value | The value of the option.

virtual const bool WoopsiUI::ListBox::allowsMultipleSelections | ( |  | ) | const`[inline, virtual]`

Sets whether multiple selections are possible or not. Does not redraw the gadget.

Returns:
  True if multiple selections are allowed.

virtual bool WoopsiUI::ListBox::click | ( | s16 | x,
|  | s16 | y |
| ) |  |  | `[virtual]`

Click this gadget at the supplied co-ordinates.

Parameters:

  | x | X co-ordinate of the click.
  | y | Y co-ordinate of the click.

Returns:
  True if the click was successful.

Reimplemented from WoopsiUI::Gadget.

virtual void WoopsiUI::ListBox::deselectAllOptions | ( |  | ) | `[virtual]`

Deselect all options. Redraws the gadget and raises a value changed event.

virtual void WoopsiUI::ListBox::deselectOption | ( | const s32 | index | ) | `[virtual]`

Select an option by its index. Does not deselect any other selected options. Redraws the gadget and raises a value changed event.

Parameters:

  | index | The index of the option to select.

virtual bool WoopsiUI::ListBox::doubleClick | ( | s16 | x,
|  | s16 | y |
| ) |  |  | `[virtual]`

Double-click this gadget at the supplied co-ordinates.

Parameters:

  | x | X co-ordinate of the click.
  | y | Y co-ordinate of the click.

Returns:
  True if the click was successful.

Reimplemented from WoopsiUI::Gadget.

virtual void WoopsiUI::ListBox::draw | ( | Rect | clipRect | ) | `[virtual]`

Draw the region of the menu within the clipping rect.

Parameters:

  | clipRect | The clipping rect to limit drawing to.

Reimplemented from WoopsiUI::ScrollingPanel.

virtual ListData::ListDataItem* WoopsiUI::ListBox::getOption | ( | const s32 | index | ) | `[inline, virtual]`

Get the specified option.

Returns:
  The specified option.

virtual const s32 WoopsiUI::ListBox::getOptionCount | ( |  | ) | const`[inline, virtual]`

Get the total number of options.

Returns:
  The number of options.

virtual const u16 WoopsiUI::ListBox::getOptionHeight | ( |  | ) | const`[virtual]`

Get the height of a single option.

Returns:
  The height of an option.

virtual const s32 WoopsiUI::ListBox::getSelectedIndex | ( |  | ) | const`[virtual]`

Get the selected index. Returns -1 if nothing is selected. If more than one option is selected, the index of the first selected option is returned.

Returns:
  The selected index.

virtual const ListData::ListDataItem* WoopsiUI::ListBox::getSelectedOption | ( |  | ) | const`[virtual]`

Get the selected option. Returns NULL if nothing is selected.

Returns:
  The selected option.

virtual void WoopsiUI::ListBox::handleListDataChangedEvent | ( | const ListDataEventArgs & | e | ) | `[virtual]`

Handles list data changed events.

Parameters:

  | e | Event arguments.

Implements WoopsiUI::ListDataEventHandler.

virtual void WoopsiUI::ListBox::handleListDataSelectionChangedEvent | ( | const ListDataEventArgs & | e | ) | `[virtual]`

Handles list selection changed events.

Parameters:

  | e | Event arguments.

Implements WoopsiUI::ListDataEventHandler.

virtual void WoopsiUI::ListBox::removeAllOptions | ( |  | ) | `[virtual]`

Remove all options from the gadget. Does not redraw the gadget.

virtual void WoopsiUI::ListBox::removeOption | ( | const s32 | index | ) | `[virtual]`

Remove an option from the gadget by its index. Does not redraw the gadget.

Parameters:

  | index | The index of the option to remove.

virtual void WoopsiUI::ListBox::resizeCanvas | ( |  | ) | `[virtual]`

Resize the scrolling canvas to encompass all options. Does not redraw the gadget.

virtual void WoopsiUI::ListBox::selectAllOptions | ( |  | ) | `[virtual]`

Select all options. Does nothing if the listbox does not allow multiple selections. Redraws the gadget and raises a value changed event.

virtual void WoopsiUI::ListBox::selectOption | ( | const s32 | index | ) | `[virtual]`

Select an option by its index. Does not deselect any other selected options. Redraws the gadget and raises a value changed event.

Parameters:

  | index | The index of the option to select.

virtual void WoopsiUI::ListBox::setAllowMultipleSelections | ( | const bool | allowMultipleSelections | ) | `[inline, virtual]`

Sets whether multiple selections are possible or not. Does not redraw the gadget.

Parameters:

  | allowMultipleSelections | True to allow multiple selections.

virtual void WoopsiUI::ListBox::setOptionSelected | ( | const s32 | index,
|  | const bool | selected |
| ) |  |  | `[protected, virtual]`

Select or deselect an option by its index. Does not deselect any other selected options. Set index to -1 to select nothing. Redraws the gadget and raises a value changed event.

Parameters:

  | index | The index of the option to select.
  | selected | True to select the option, false to deselect it.

virtual void WoopsiUI::ListBox::setSelectedIndex | ( | const s32 | index | ) | `[virtual]`

Sets the selected index. Specify -1 to select nothing. Resets any other selected options to deselected. Redraws the gadget and raises a value changed event.

Parameters:

  | index | The selected index.

virtual void WoopsiUI::ListBox::setSortInsertedItems | ( | const bool | sortInsertedItems | ) | `[inline, virtual]`

Sets whether or not items added to the list are automatically sorted on insert or not.

Parameters:

  | sortInsertedItems | True to enable sort on insertion.

virtual void WoopsiUI::ListBox::sort | ( |  | ) | `[virtual]`

Sort the options alphabetically by the text of the options.

## Member Data Documentation

u8 WoopsiUI::ListBox::_optionPadding`[protected]`

Padding between options.

ListData WoopsiUI::ListBox::_options`[protected]`

Option storage.

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

- C:/Documents and Settings/Administrator/Desktop/woopsi-src-0.40/Woopsi/libwoopsi/include/listbox.h