/* _______ __ __ __ ______ __ __ _______ __ __
* / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
* / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
* / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
* / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
* /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
* \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
*
* Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson
*
* Js_./
* Per Larsson a.k.a finalman _RqZ{a<^_aa
* Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a//
* _Qhm`] _f "'c 1!5m
* Visit: http://guichan.darkbits.org )Qk
ws?a-?' ._/L #'
* binary forms, with or without )4d[#7r, . ' )d`)[
* modification, are permitted provided _Q-5'5W..j/?' -?!\)cam'
* that the following conditions are met: j<. a J@\
* this list of conditions and the j(]1u
#include
#include
#include "guisan/keylistener.hpp"
#include "guisan/mouselistener.hpp"
#include "guisan/platform.hpp"
#include "guisan/widget.hpp"
namespace gcn
{
/**
* A TextBox in which you can write and/or display a lines of text.
*
* NOTE: A plain TextBox is really uggly and looks much better inside a
* ScrollArea.
*/
class GCN_CORE_DECLSPEC TextBox :
public Widget,
public MouseListener,
public KeyListener
{
public:
/**
* Constructor.
*/
TextBox();
/**
* Constructor.
*
* @param text the text of the TextBox.
*/
TextBox(const std::string& text);
/**
* Sets the text.
*
* @param text the text of the TextBox.
*/
void setText(const std::string& text);
/**
* Gets the text.
* @return the text of the TextBox.
*/
[[nodiscard]] std::string getText() const;
/**
* Gets the row of a text.
*
* @return the text of a certain row in the TextBox.
*/
[[nodiscard]] const std::string& getTextRow(int row) const;
/**
* Sets the text of a certain row in a TextBox.
*
* @param row the row number.
* @param text the text of a certain row in the TextBox.
*/
void setTextRow(int row, const std::string& text);
/**
* Gets the number of rows in the text.
*
* @return the number of rows in the text.
*/
[[nodiscard]] unsigned int getNumberOfRows() const;
/**
* Gets the caret position in the text.
*
* @return the caret position in the text.
*/
[[nodiscard]] unsigned int getCaretPosition() const;
/**
* Sets the position of the caret in the text.
*
* @param position the position of the caret.
*/
void setCaretPosition(unsigned int position);
/**
* Gets the row the caret is in in the text.
*
* @return the row the caret is in in the text.
*/
[[nodiscard]] unsigned int getCaretRow() const;
/**
* Sets the row the caret should be in in the text.
*
* @param row the row number.
*/
void setCaretRow(int row);
/**
* Gets the column the caret is in in the text.
*
* @return the column the caret is in in the text.
*/
[[nodiscard]] unsigned int getCaretColumn() const;
/**
* Sets the column the caret should be in in the text.
*
* @param column the column number.
*/
void setCaretColumn(int column);
/**
* Sets the row and the column the caret should be in in the text.
*
* @param row the row number.
* @param column the column number.
*/
void setCaretRowColumn(int row, int column);
/**
* Scrolls the text to the caret if the TextBox is in a ScrollArea.
*/
virtual void scrollToCaret();
/**
* Checks if the TextBox is editable.
*
* @return true it the TextBox is editable.
*/
[[nodiscard]] bool isEditable() const;
/**
* Sets if the TextBox should be editable or not.
*
* @param editable true if the TextBox should be editable.
*/
void setEditable(bool editable);
/**
* Adds a text row to the text.
*
* @param row a row.
*/
virtual void addRow(std::string row);
/**
* Checks if the TextBox is opaque
*
* @return true if the TextBox is opaque
*/
[[nodiscard]] bool isOpaque() const;
/**
* Sets the TextBox to be opaque.
*
* @param opaque true if the TextBox should be opaque.
*/
void setOpaque(bool opaque);
// Inherited from Widget
void draw(Graphics* graphics) override;
void drawBorder(Graphics* graphics) override;
void fontChanged() override;
// Inherited from KeyListener
void keyPressed(KeyEvent& keyEvent) override;
// Inherited from MouseListener
void mousePressed(MouseEvent& mouseEvent) override;
void mouseDragged(MouseEvent& mouseEvent) override;
protected:
/**
* Draws the caret.
*
* @param graphics a Graphics object to draw with.
* @param x the x position.
* @param y the y position.
*/
virtual void drawCaret(Graphics* graphics, int x, int y);
/**
* Adjusts the TextBox size to fit the font size.
*/
virtual void adjustSize();
std::vector mTextRows;
int mCaretColumn;
int mCaretRow;
bool mEditable;
bool mOpaque;
};
}
#endif // end GCN_TEXTBOX_HPP