GG::Edit Class Reference

This is a single-line text input control. More...

#include <Edit.h>

Inheritance diagram for GG::Edit:

GG::TextControl GG::Control GG::Wnd GG::MultiEdit List of all members.

Signal Types

typedef boost::signal< void(const std::string &)> EditedSignalType
typedef boost::signal< void(const std::string &)> FocusUpdateSignalType

Slot Types

typedef EditedSignalType::slot_type EditedSlotType
typedef FocusUpdateSignalType::slot_type FocusUpdateSlotType

Accessors

EditedSignalType EditedSignal
FocusUpdateSignalType FocusUpdateSignal
virtual Pt MinUsableSize () const
virtual Pt ClientUpperLeft () const
virtual Pt ClientLowerRight () const
const std::pair< int, int > & CursorPosn () const
Clr InteriorColor () const
Clr HiliteColor () const
Clr SelectedTextColor () const

Structors

 Edit (int x, int y, int w, const std::string &str, const boost::shared_ptr< Font > &font, Clr color, Clr text_color=CLR_BLACK, Clr interior=CLR_ZERO, Flags< WndFlag > flags=CLICKABLE)

Mutators

virtual void Render ()
virtual void LButtonDown (const Pt &pt, Flags< ModKey > mod_keys)
virtual void LDrag (const Pt &pt, const Pt &move, Flags< ModKey > mod_keys)
virtual void LClick (const Pt &pt, Flags< ModKey > mod_keys)
virtual void KeyPress (Key key, Flags< ModKey > mod_keys)
virtual void GainingFocus ()
virtual void LosingFocus ()
virtual void SetColor (Clr c)
void SetInteriorColor (Clr c)
void SetHiliteColor (Clr c)
void SetSelectedTextColor (Clr c)
virtual void SelectRange (int from, int to)
virtual void SelectAll ()
virtual void SetText (const std::string &str)
virtual void DefineAttributes (WndEditor *editor)

Structors

 Edit ()

Accessors

virtual bool MultiSelected () const
int FirstCharShown () const
bool RecentlyEdited () const
int CharIndexOf (int x) const
int FirstCharOffset () const
int ScreenPosOfChar (int idx) const
int LastVisibleChar () const
int LastButtonDownTime () const
bool InDoubleButtonDownMode () const
std::pair< int, int > DoubleButtonDownCursorPos () const

Mutators

std::pair< int, int > GetDoubleButtonDownWordIndices (int char_index)
std::pair< int, int > GetDoubleButtonDownDragWordIndices (int char_index)
void ClearDoubleButtonDownMode ()

Static Protected Attributes

static const int PIXEL_MARGIN

Detailed Description

This is a single-line text input control.

This is a simple edit box control. It inherits from TextControl, so it can be treated in many ways very similarly to a std::string. Note that the second set of constructors determine the height of the control based on the height of the font used and the value of the constant PIXEL_MARGIN. There are two types of signals emitted by an Edit control. The first is EditedSignal; this is emitted every time the contents of the Edit change. Sometimes, however, you don't want that. For instance, say you want to keep the value of the text in the Edit to between (numerical values) 100 and 300. If the Edit currently reads "200", the user may decide to highlight the "2", hit delete, then type a "1". If updates are immediate, you will receive notification that the Edit says "00" (an invalid value), when that is just a temporary value you don't care about. In such situations the other signal, FocusUpdateSignal, should be useful. It is only emitted when the Edit is losing the input focus and the contents have changed since it gained the input focus. So you would only receive a single update, namely "100", which is a valid number for that control, and you would receive it only when it is certain that the user is finished editing the text (when the focus changes). Note that both signals may be used at the same time, if desired.

Definition at line 49 of file Edit.h.


Member Typedef Documentation

typedef boost::signal<void (const std::string&)> GG::Edit::EditedSignalType

emitted whenever the contents of the Edit are altered (keypresses, deletes, etc.); provides the new contents of the Edit

Definition at line 53 of file Edit.h.

typedef boost::signal<void (const std::string&)> GG::Edit::FocusUpdateSignalType

emitted whenever the Edit loses the input focus, and its contents have changed since it gained the focus; provides the new contents of the Edit

Definition at line 54 of file Edit.h.

typedef EditedSignalType::slot_type GG::Edit::EditedSlotType

type of functor(s) invoked on a EditedSignalType

Definition at line 58 of file Edit.h.

typedef FocusUpdateSignalType::slot_type GG::Edit::FocusUpdateSlotType

type of functor(s) invoked on a FocusUpdateSignalType

Definition at line 59 of file Edit.h.


Constructor & Destructor Documentation

GG::Edit::Edit ( int  x,
int  y,
int  w,
const std::string &  str,
const boost::shared_ptr< Font > &  font,
Clr  color,
Clr  text_color = CLR_BLACK,
Clr  interior = CLR_ZERO,
Flags< WndFlag >  flags = CLICKABLE 
)

ctor that does not required height. Height is determined from the font and point size used.

GG::Edit::Edit (  )  [protected]

default ctor


Member Function Documentation

virtual Pt GG::Edit::MinUsableSize (  )  const [virtual]

returns the size of the minimum bounding box that can enclose the Wnd and still show all of its elements, plus enough room for interaction with those elements (if applicable).

For example, a TextControl's MinUsableSize() is just the area of its text, and a Scroll's RenderableMinSize() is the combined sizes of its up-button, down-button, and tab (plus a bit of room in which to drag the tab).

Reimplemented from GG::TextControl.

Reimplemented in GG::MultiEdit.

Referenced by GG::Spin< T >::MinUsableSize().

virtual Pt GG::Edit::ClientUpperLeft (  )  const [virtual]

returns upper-left corner of window's client area in screen coordinates (or of the entire area, if no client area is specified).

Virtual because different windows have different shapes (and so ways of calculating client area)

Reimplemented from GG::Wnd.

virtual Pt GG::Edit::ClientLowerRight (  )  const [virtual]

returns (one pixel past) lower-right corner of window's client area in screen coordinates (or of the entire area, if no client area is specified).

Virtual because different windows have different shapes (and so ways of calculating client area)

Reimplemented from GG::Wnd.

Reimplemented in GG::MultiEdit.

const std::pair<int, int>& GG::Edit::CursorPosn (  )  const

returns the current position of the cursor (first selected character to the last + 1 selected one)

Clr GG::Edit::InteriorColor (  )  const

returns the interior color of the control

Referenced by GG::Spin< T >::InteriorColor().

Clr GG::Edit::HiliteColor (  )  const

returns the color used to render hiliting around selected text

Referenced by GG::Spin< T >::HiliteColor().

Clr GG::Edit::SelectedTextColor (  )  const

returns the color used to render selected text

Referenced by GG::Spin< T >::SelectedTextColor().

virtual void GG::Edit::Render (  )  [virtual]

draws this Wnd.

Note that Wnds being dragged for a drag-and-drop operation are rendered twice -- once in-place as normal, once in the location of the drag operation, attached to the cursor. Such Wnds may wish to render themselves differently in those two cases. To determine which render is being performed, they can call GUI::GetGUI()->RenderingDragDropWnds().

Reimplemented from GG::TextControl.

Reimplemented in GG::MultiEdit.

virtual void GG::Edit::LButtonDown ( const Pt pt,
Flags< ModKey >  mod_keys 
) [virtual]

respond to left button down msg.

A window receives this whenever any input device button changes from up to down while over the window.

Note:
If this Wnd was created with the REPEAT_BUTTON_DOWN flag, this method may be called multiple times during a single button press-release cycle.
See also:
GG::GUI

Reimplemented from GG::Wnd.

Reimplemented in GG::MultiEdit.

virtual void GG::Edit::LDrag ( const Pt pt,
const Pt move,
Flags< ModKey >  mod_keys 
) [virtual]

respond to left button drag msg (even if this Wnd is not dragable).

Drag messages are only sent to the window over which the button was pressed at the beginning of the drag. A window receives this whenever any input device button is down and the cursor is moving while over the window. The window will also receive drag messages when the mouse is being dragged outside the window's area.

Reimplemented from GG::Wnd.

Reimplemented in GG::MultiEdit.

virtual void GG::Edit::LClick ( const Pt pt,
Flags< ModKey >  mod_keys 
) [virtual]

respond to release of left mouse button over this Wnd, if it was also originally depressed over this Wnd.

A Wnd will receive an LButtonUp() message whenever a drag that started over its area ends over its area as well.

Reimplemented from GG::Wnd.

virtual void GG::Edit::KeyPress ( Key  key,
Flags< ModKey >  mod_keys 
) [virtual]

respond to down-keystrokes (focus window only).

A window may receive KeyPress() messages passed up to it from its children. For instance, Control-derived classes pass KeyPress() messages to their Parent() windows by default.

Note:
Though mouse clicks consist of a press and a release, all Control classes by default respond immediately to KeyPress(), not KeyRelease(); in fact, by default no Wnd class does anything at all on a KeyRelease event.

Reimplemented from GG::Control.

Reimplemented in GG::MultiEdit.

virtual void GG::Edit::GainingFocus (  )  [virtual]

respond to this window gaining the input focus

Reimplemented from GG::Wnd.

virtual void GG::Edit::LosingFocus (  )  [virtual]

respond to this window losing the input focus

Reimplemented from GG::Wnd.

virtual void GG::Edit::SetColor ( Clr  c  )  [virtual]

just like Control::SetColor(), except that this one also adjusts the text color

Reimplemented from GG::TextControl.

void GG::Edit::SetInteriorColor ( Clr  c  ) 

sets the interior color of the control

Referenced by GG::Spin< T >::SetInteriorColor().

void GG::Edit::SetHiliteColor ( Clr  c  ) 

sets the color used to render hiliting around selected text

Referenced by GG::Spin< T >::SetHiliteColor().

void GG::Edit::SetSelectedTextColor ( Clr  c  ) 

sets the color used to render selected text

Referenced by GG::Spin< T >::SetSelectedTextColor().

virtual void GG::Edit::SelectRange ( int  from,
int  to 
) [virtual]

selects all text in the given range.

When from == to, this function just places the caret at from. Note that it is legal to pass values such that to < from. The difference is that from < to simulates a drag-selection from left to right, and to < from simulates one from right to left. The direction of the simulated drag affects which part of the text is visible at the end of the function call.

virtual void GG::Edit::SelectAll (  )  [virtual]

selects all text in the entire control.

This function leaves the beginning of the text in view; see SelectRange().

Reimplemented in GG::MultiEdit.

virtual void GG::Edit::SetText ( const std::string &  str  )  [virtual]

sets the text to str; may resize the window.

If the private member m_fit_to_text is true (i.e. if the second ctor type was used), calls to this function cause the window to be resized to whatever space the newly rendered text occupies.

Reimplemented from GG::TextControl.

Reimplemented in GG::MultiEdit.

virtual void GG::Edit::DefineAttributes ( WndEditor *  editor  )  [virtual]

provides the attributes of this object that are appropriate for a user to edit in a WndEditor; see WndEditor for details.

Reimplemented from GG::TextControl.

Reimplemented in GG::MultiEdit.

virtual bool GG::Edit::MultiSelected (  )  const [protected, virtual]

returns true if >= 1 characters selected

Reimplemented in GG::MultiEdit.

int GG::Edit::FirstCharShown (  )  const [protected]

returns the index of the first character visible in the Edit

bool GG::Edit::RecentlyEdited (  )  const [protected]

returns true iff the contents have been changed since the last time the focus was gained

int GG::Edit::CharIndexOf ( int  x  )  const [protected]

returns index into WindowText() of the character x pixels from left edge of visible portion of string

int GG::Edit::FirstCharOffset (  )  const [protected]

returns the pixel distance from the beginning of the string to just before the first visible character

int GG::Edit::ScreenPosOfChar ( int  idx  )  const [protected]

returns the screen x-coordinate of the left side of the character at index idx in WindowText()

int GG::Edit::LastVisibleChar (  )  const [protected]

actually, this returns the last + 1 visible char, for use in "for (i=0;i<last_vis_char;++i)", etc.

int GG::Edit::LastButtonDownTime (  )  const [protected]

returns the value of GUI::Ticks() at the last left button press

bool GG::Edit::InDoubleButtonDownMode (  )  const [protected]

returns true iff the button is still down after being pressed twice within GUI::DoubleClickInterval() ticks

std::pair<int, int> GG::Edit::DoubleButtonDownCursorPos (  )  const [protected]

returns the cursor position at the time of the most recent double-button-down

std::pair<int, int> GG::Edit::GetDoubleButtonDownWordIndices ( int  char_index  )  [protected]

Does a bit more than its name suggests.

Records the current time, and if it's within GUI::DoubleClickInterval() of the last button down time, returns the indices into WindowText() that delimit the word around index char_index. If not within the time limit, or if no such word exists, the returned range will be empty (its .first and .second members will be equal). This function should be called in LButtonDown() overrides.

std::pair<int, int> GG::Edit::GetDoubleButtonDownDragWordIndices ( int  char_index  )  [protected]

Returns the indices into WindowText() that delimit the word around index char_index.

If no such word exists, the returned range will be empty (its .first and .second members will be equal). This function should be called in LDrag() overrides, when InDoubleButtonDownMode() is true.

void GG::Edit::ClearDoubleButtonDownMode (  )  [protected]

Sets the value of InDoubleButtonDownMode() to false.

This should be called in LClick() overrides.


Member Data Documentation

EditedSignalType GG::Edit::EditedSignal [mutable]

returns the edited signal object for this Edit

Definition at line 77 of file Edit.h.

FocusUpdateSignalType GG::Edit::FocusUpdateSignal [mutable]

returns the focus update signal object for this Edit

Definition at line 78 of file Edit.h.

const int GG::Edit::PIXEL_MARGIN [static, protected]

the number of pixels to leave between the text and the control's frame

Definition at line 143 of file Edit.h.


The documentation for this class was generated from the following file:
Generated on Wed Mar 26 14:35:42 2008 for GG by  doxygen 1.5.2