# WoopsiUI::TextBox Class Reference

`#include <textbox.h>`

Inheritance diagram for WoopsiUI::TextBox:

List of all members.

## Public Member Functions
| TextBox (s16 x, s16 y, u16 width, u16 height, const WoopsiString &text, GadgetStyle *style=NULL)
virtual void | showCursor ()
virtual void | hideCursor ()
virtual void | setText (const WoopsiString &text)
virtual void | appendText (const WoopsiString &text)
virtual void | removeText (const u32 startIndex)
virtual void | removeText (const u32 startIndex, const u32 count)
virtual void | insertText (const WoopsiString &text, const u32 index)
virtual void | insertTextAtCursor (const WoopsiString &text)
virtual void | moveCursorToPosition (const s32 position)
virtual const s32 | getCursorPosition () const
virtual void | handleKeyboardPressEvent (const KeyboardEventArgs &e)
virtual void | handleKeyboardRepeatEvent (const KeyboardEventArgs &e)
virtual void | handleKeyPressEvent (const GadgetEventArgs &e)
virtual void | handleKeyRepeatEvent (const GadgetEventArgs &e)
bool | opensKeyboard () const
void | disableKeyboardPopup ()
void | enableKeyboardPopup ()
## Protected Member Functions
void | onBlur ()
virtual void | drawContents (GraphicsPort *port)
virtual void | repositionCursor (const s32 position)
void | moveCursorToClickLocation (s16 x, s16 y)
virtual void | drawBorder (GraphicsPort *port)
virtual void | onClick (s16 x, s16 y)
virtual void | onDoubleClick (s16 x, s16 y)
virtual void | onKeyPress (KeyCode keyCode)
virtual void | onKeyRepeat (KeyCode keyCode)
virtual void | processKey (const WoopsiKey *key)
virtual const u16 | getCursorXPos () const
virtual const u16 | getCursorWidth () const
virtual void | calculateTextPositionHorizontal ()
| TextBox (const TextBox &textbox)
## Protected Attributes
s32 | _cursorPos
bool | _showCursor
bool | _opensKeyboard

## Detailed Description

Single-line textbox gadget. Can align text both vertically and horizontally in different ways. The gadget gains this functionality by inheriting from the Label class. However, if the amount of text exceeds the dimensions of the gadget, the gadget will ignore its horizontal alignment settings and switch to left-aligned instead. This ensures that moving the cursor over the text will scroll through it correctly.

## Constructor & Destructor Documentation

WoopsiUI::TextBox::TextBox | ( | s16 | x,
|  | s16 | y,
|  | u16 | width,
|  | u16 | height,
|  | const WoopsiString & | text,
|  | GadgetStyle * | style = `NULL` |
| ) |  |  |

Constructor for a textbox containing a string.

Parameters:

  | x | The x co-ordinate of the text box, relative to its parent.
  | y | The y co-ordinate of the text box, relative to its parent.
  | width | The width of the textbox.
  | height | The height of the textbox.
  | text | Pointer to a string to display in the textbox.
  | style | The style that the gadget should use. If this is not specified, the gadget will use the values stored in the global defaultGadgetStyle object. The gadget will copy the properties of the style into its own internal style object.

WoopsiUI::TextBox::TextBox | ( | const TextBox & | textbox | ) | `[inline, protected]`

Copy constructor is protected to prevent usage.

## Member Function Documentation

virtual void WoopsiUI::TextBox::appendText | ( | const WoopsiString & | text | ) | `[virtual]`

Append new text to the end of the current text displayed in the label.

Parameters:

  | text | String to append.

Reimplemented from WoopsiUI::Label.

virtual void WoopsiUI::TextBox::calculateTextPositionHorizontal | ( |  | ) | `[protected, virtual]`

Calculate the horizontal position of the string based on its length and the alignment options. Alignment options are overridden if the width of the string exceeds the width of the textbox.

Reimplemented from WoopsiUI::Label.

void WoopsiUI::TextBox::disableKeyboardPopup | ( |  | ) | `[inline, virtual]`

Disables the keyboard popup when double-clicked.

Implements WoopsiUI::TextBoxBase.

virtual void WoopsiUI::TextBox::drawBorder | ( | GraphicsPort * | port | ) | `[protected, virtual]`

Draw the area of this gadget that falls within the clipping region. Called by the redraw() function to draw all visible regions.

Parameters:

  | port | The GraphicsPort to draw to.

See also:
  redraw()

Reimplemented from WoopsiUI::Label.

virtual void WoopsiUI::TextBox::drawContents | ( | GraphicsPort * | port | ) | `[protected, virtual]`

Draw the area of this gadget that falls within the clipping region. Called by the redraw() function to draw all visible regions.

Parameters:

  | port | The GraphicsPort to draw to.

See also:
  redraw()

Reimplemented from WoopsiUI::Label.

void WoopsiUI::TextBox::enableKeyboardPopup | ( |  | ) | `[inline, virtual]`

Enables the keyboard popup when double-clicked.

Implements WoopsiUI::TextBoxBase.

virtual const s32 WoopsiUI::TextBox::getCursorPosition | ( |  | ) | const`[inline, virtual]`

Get the cursor position. This is the index within the string that the cursor is currently positioned over.

Returns:
  position The cursor position.

Implements WoopsiUI::TextBoxBase.

virtual const u16 WoopsiUI::TextBox::getCursorWidth | ( |  | ) | const`[protected, virtual]`

Get the width of the cursor in pixels.

Returns:
  The width of the cursor in pixels.

virtual const u16 WoopsiUI::TextBox::getCursorXPos | ( |  | ) | const`[protected, virtual]`

Get the x co-ordinate of the cursor in pixels relative to the left-hand edge of the client rect.

Returns:
  The x co-ordinate of the cursor in pixels.

virtual void WoopsiUI::TextBox::handleKeyboardPressEvent | ( | const KeyboardEventArgs & | e | ) | `[virtual]`

Handle a keyboard press event.

Parameters:

  | e | The event data.

Reimplemented from WoopsiUI::KeyboardEventHandler.

virtual void WoopsiUI::TextBox::handleKeyboardRepeatEvent | ( | const KeyboardEventArgs & | e | ) | `[virtual]`

Handle a keyboard repeat event.

Parameters:

  | e | The event data.

Reimplemented from WoopsiUI::KeyboardEventHandler.

virtual void WoopsiUI::TextBox::handleKeyPressEvent | ( | const GadgetEventArgs & | e | ) | `[virtual]`

Handle a key press event.

Parameters:

  | e | The event data.

virtual void WoopsiUI::TextBox::handleKeyRepeatEvent | ( | const GadgetEventArgs & | e | ) | `[virtual]`

Handle a key repeat event.

Parameters:

  | e | The event data.

virtual void WoopsiUI::TextBox::hideCursor | ( |  | ) | `[virtual]`

Hides the cursor.

Implements WoopsiUI::TextBoxBase.

virtual void WoopsiUI::TextBox::insertText | ( | const WoopsiString & | text,
|  | const u32 | index |
| ) |  |  | `[virtual]`

Insert text at the specified index.

Parameters:

  | text | The text to insert.
  | index | Index at which to insert the text.

Reimplemented from WoopsiUI::Label.

virtual void WoopsiUI::TextBox::insertTextAtCursor | ( | const WoopsiString & | text | ) | `[virtual]`

Insert text at the current cursor position.

Parameters:

  | text | The text to insert.

Implements WoopsiUI::TextBoxBase.

void WoopsiUI::TextBox::moveCursorToClickLocation | ( | s16 | x,
|  | s16 | y |
| ) |  |  | `[protected]`

Move the cursor to the specified co-ordinates. The co-ordinates are expected to be the result of a click, and therefore in world-space rather than gadget-space.

virtual void WoopsiUI::TextBox::moveCursorToPosition | ( | const s32 | position | ) | `[virtual]`

Move the cursor to the text position specified. 0 indicates the start of the string. If position is greater than the length of the string, the cursor is moved to the end of the string.

Parameters:

  | position | The new cursor position.

Implements WoopsiUI::TextBoxBase.

void WoopsiUI::TextBox::onBlur | ( |  | ) | `[inline, protected, virtual]`

Redraws the gadget

Reimplemented from WoopsiUI::Gadget.

virtual void WoopsiUI::TextBox::onClick | ( | s16 | x,
|  | s16 | y |
| ) |  |  | `[protected, virtual]`

Moves the cursor to the clicked co-ordinates.

Parameters:

  | x | The x co-ordinates of the click.
  | y | The y co-ordinates of the click.

Reimplemented from WoopsiUI::Gadget.

virtual void WoopsiUI::TextBox::onDoubleClick | ( | s16 | x,
|  | s16 | y |
| ) |  |  | `[protected, virtual]`

Opens the keyboard on the bottom display.

Parameters:

  | x | The x co-ordinates of the click.
  | y | The y co-ordinates of the click.

Reimplemented from WoopsiUI::Gadget.

virtual void WoopsiUI::TextBox::onKeyPress | ( | KeyCode | keyCode | ) | `[protected, virtual]`

Moves the cursor left or right.

Parameters:

  | keyCode | The key that was pressed.

Reimplemented from WoopsiUI::Gadget.

virtual void WoopsiUI::TextBox::onKeyRepeat | ( | KeyCode | keyCode | ) | `[protected, virtual]`

Moves the cursor left or right.

Parameters:

  | keyCode | The key that repeated.

Reimplemented from WoopsiUI::Gadget.

bool WoopsiUI::TextBox::opensKeyboard | ( |  | ) | const`[inline, virtual]`

Check if the textbox opens the keyboard popup when double-clicked.

Returns:
  True if the keyboard pops up; false if not.

Implements WoopsiUI::TextBoxBase.

virtual void WoopsiUI::TextBox::processKey | ( | const WoopsiKey * | key | ) | `[protected, virtual]`

Handles keyboard key presses and key repeats.

Parameters:

  | key | Key that raised the event.

virtual void WoopsiUI::TextBox::removeText | ( | const u32 | startIndex,
|  | const u32 | count |
| ) |  |  | `[virtual]`

Remove specified number of characters from the string from the start index onwards.

Parameters:

  | startIndex | Index to remove from.
  | count | Number of characters to remove.

Implements WoopsiUI::TextBoxBase.

virtual void WoopsiUI::TextBox::removeText | ( | const u32 | startIndex | ) | `[virtual]`

Remove all characters from the string from the start index onwards.

Parameters:

  | startIndex | Index to remove from.

Implements WoopsiUI::TextBoxBase.

virtual void WoopsiUI::TextBox::repositionCursor | ( | const s32 | position | ) | `[protected, virtual]`

Moves the cursor without redrawing.

Parameters:

  | position | New cursor position.

virtual void WoopsiUI::TextBox::setText | ( | const WoopsiString & | text | ) | `[virtual]`

Set the text displayed in the label.

Parameters:

  | text | String to display.

Reimplemented from WoopsiUI::Label.

virtual void WoopsiUI::TextBox::showCursor | ( |  | ) | `[virtual]`

Shows the cursor.

Implements WoopsiUI::TextBoxBase.

## Member Data Documentation

s32 WoopsiUI::TextBox::_cursorPos`[protected]`

Position of the cursor within the string.

bool WoopsiUI::TextBox::_opensKeyboard`[protected]`

Set to false to disable keyboard popup when double-clicked.

bool WoopsiUI::TextBox::_showCursor`[protected]`

Set to true to make cursor visible.

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

- textbox.h