Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
UppHub
Status & Roadmap
FAQ
Authors & License
Forums
Funding U++
Search on this site











SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo

EditField

 

class EditField : public Ctrl, private TextArrayOps

 

 

This widget is used whenever there is a type of value that can be edited in its textual representation. Of course, the most evident type of value is (W)String, but EditField can be used to edit any other type like Date, int, double. Adaptation of EditField is achieved by using Convert based object to transform Value to text and back.

 

 

Public Member List

 

static int GetViewHeight(Font font = StdFont())

Returns the correct height for EditField view with font used for edited text.

 


 

static int GetStdHeight(Font font = StdFont())

Returns the correct height for EditField with font used for edited text, including the standard static frame.

 


 

virtual void HighlightText(Vector<Highlight>& hl)

Provides a chance to change the text color and background for individual characters.

 


 

Callback1<Bar&WhenBar

This callback represents the context menu of EditField. The default is StdBar.

 


 

Callback WhenEnter

This callback is invoked if user presses Enter key while in EditField. If not empty, EditField also consumes Enter key (so that it is not passed up in Ctrl hierarchy). Default is empty.

 


 

Callback1<WString&WhenPasteFilter

This callback is invoked when Paste operation is performed and can be used to alter the text to be pasted. Default is no change to the text.

 


 

Callback1<Vector<Highlight>&> WhenHighlight

Called by default implementation of HighlightText. Provides a chance to change the text color and background for individual characters.

 


 

int Insert(int pos, const WString& text)

Inserts text at pos.

 


 

int Insert(int pos, const String& text)

int Insert(int pos, const char *text)

Inserts text at pos. Text is converted to unicode using the default charset.

 


 

void Remove(int pos, int n)

Removes n characters at pos.

 


 

void Insert(const WString& text)

Inserts text at cursor position.

 


 

void Insert(const String& text)

void Insert(const char *text)

Inserts text at cursor position. Text is converted to unicode using the default charset.

 


 

void Insert(int chr)

Inserts a single unicode chr at cursor position.

 


 

void Move(int newpos, bool select = false)

Moves the cursor to newpos. If select is true, selection is set between recent cursor position and newpos.

 


 

void SetSelection(int l = 0, int h = INT_MAX)

Sets the selection if l < h. If l or h exceed the available range (that is zero to length of text), they are bound to it. If l >= h, selection is canceled and l is the new cursor position.

 


 

bool GetSelection(int& l, int& hconst

Returns the current selection. If there is no selection, both l h return the current cursor position.

 


 

bool IsSelection() const

Returns true if there is a selection.

 


 

bool RemoveSelection()

If there is no selection, returns false, otherwise it removes selected text and returns true.

 


 

void CancelSelection()

Any selection is canceled (no characters are selected after this operation).

 


 

void Copy()

Copies selected text to clipboard.

 


 

void Undo()

Performs undo operation.

 


 

void Cut()

Cuts the selection.

 


 

void Paste()

Pastes the content of clipboard, if compatible, into the EditField.

 


 

void Erase()

Removes the content of EditField.

 


 

void SelectAll()

Selects the whole text in EditField.

 


 

void StdBar(Bar& menu)

Standard menu of EditField.

 


 

void SetText(const WString& text)

Sets the text.

 


 

void SetText(const String& t)

void SetText(const char *t)

Sets the text. Text is converted to unicode using the default charset.

 


 

const WString& GetText() const

Returns the text.

 


 

virtual int GetLength() const

Returns the length of text.

 


 

void Clear()

Sets the empty text.

 


 

void Reset()

Resets EditField to default state.

 


 

void Error(bool error)

If error is true, paints the content as if it was invalid (the same way as when assigned Convert returns ErrorValue).

 


 

EditField& Password(bool pwd = true)

Sets the password mode. In password mode all characters are displayed as asterisk. Returns *this.

 


 

bool IsPassword() const

Returns true if password mode is active.

 


 

EditField& SetFilter(int (*f)(int))

Sets the character filter f. All characters keystrokes are first altered by this function and used only if the result is not zero. Returns *this.

 


 

EditField& SetConvert(const Convert& c)

Sets the Value converter. By using the specific converters, EditField can be adapted for editing any type of values with text representation. Note that EditField stores just reference to c, therefore its lifetime must exceed the lifetime of EditField. Returns *this.

 


 

EditField& SetInactiveConvert(const Convert& c)

Sets the inactive Value converter. Such converter is used to format displayed value when edit control does not own the focus. Returns *this.

 


 

EditField& SetCharset(byte cs)

Sets the encoding to cs - only characters representable in given encoding are allowed in EditField. Note that this does not impact encoding of String values returned from EditField, only acts as another filter.

 


 

EditField& AutoFormat(bool b = true)

In AutoFormat mode, when focus goes out of editfield, text representation of value is reformated by current Convert - text is converted to Value and back. This mode is active by default. Returns *this.

 


 

EditField& NoAutoFormat()

Same as AutoFormat(false).

 


 

bool IsAutoFormat() const

Returns true is AutoFormat is active.

 


 

EditField& SetFont(Font _font)

Sets the font of displayed text. Returns *this.

 


 

EditField& SetColor(Color c)

Sets the color of displayed text. Returns *this.

 


 

EditField& SetBackground(Color c)

Sets the background color. Returns *this.

 


 

EditField& ClickSelect(bool b = true)

In ClickSelect mode, all the text of EditField is select when clicked by mouse. Returns *this.

 


 

bool IsClickSelect() const

Returns true if ClickSelect is active.

 


 

EditField& InitCaps(bool b = true)

In InitCaps mode, initial letters of entered text are uppercased. Returns *this.

 


 

bool IsInitCaps() const

Returns true if InitCaps is active.

 


 

EditField& NullText(const Image& icon, const char *text = t_("(default)"), Color ink = SColorDisabled)

EditField& NullText(const Image& icon, const char *text, Font fnt, Color ink)

EditField& NullText(const char *text = t_("(default)"), Color ink = SColorDisabled)

EditField& NullText(const char *text, Font fnt, Color ink)

In NullText mode, empty EditField displays text using ink color and fnt as a font, with icon. Returns *this.

 


 

EditField& MaxChars(int mc)

Limits maximum number of characters to mc. Returns *this.

 


 

int GetMaxChars() const

Returns the maximum number of characters limit set by MaxChars.

 


 

EditField& AutoSize(int maxcx = INT_MAX)

Resizes the width of EditField according to the length of text up to maxcx width.

 


 

EditField& NoBackground(bool b = true)

Sets the widget into transparent mode - background is not painted and Transparent is activated - a result, anything painted behind the widget is visible, allowing client code to provide any background it needs.

 


 

CharFilter GetFilter() const

Returns current character filter.

 


 

const Convert& GetConvert() const

Returns current converter.

 


 

Font GetFont() const

Returns current font.

 


 

EditField& AlignRight(bool b = true)

If b.is true, the text will be displayed aligned to the right. Left alignment is default.

 


 

bool IsNoBackground() const

Returns true if NoBackground is active.

 


 

bool IsAlignRight() const

Returns true if AlignRight is active.

 


 

bool ShowSpaces(bool b = true)

When active, EditField paints blue dots to show spaces.

 


 

EditField& NoInternalMargin(bool b = true)

Normally, EditField has small internal margin between frame and edited text. Calling this method with true removes it.

 


 

virtual int GetChar(int iconst

Returns the character at i index.

 


 

Rect GetCaretRect(int posconst

Returns the caret placement for character pos in EditField view coordinates.

 


 

Rect GetCaretRect() const

Same as GetCaretRect(cursor).

 


 

static const Style& StyleDefault()

Returns the default style used to draw edit fields.

 


 

EditField& SetStyle(const Style& s)

Sets the style to an EditField::Style s.

 

 

EditField::Style

 

struct Style : public ChStyle<Style> 

This structure defines the visual style of an EditField.

 

Do you want to contribute?