The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

IUP::Text - [GUI element] editable text field (single/multi-line, plain/rich-text)

DESCRIPTION

Creates an editable text field.

GTK Motif Windows
Classic
Windows
w/ Style
When SPIN=YES

Attributes Screenshot
$txt = IUP::Text->new( MULTILINE=>"YES", FORMATTING=>"YES");
$txt->SetAttribute( ADDFORMATTAG_HANDLE => IUP::User->new(
    ALIGNMENT=>"CENTER", 
    SPACEAFTER=>"10",
    FONTSIZE=>"24", 
    SELECTION=>"3,1:3,50",
));
$txt->SetAttribute( ADDFORMATTAG_HANDLE => IUP::User->new(
    BGCOLOR=>"255 128 64",
    UNDERLINE=>"SINGLE",
    WEIGHT=>"BOLD",
    SELECTION=>"3,7:3,11",
));
$txt->SetAttribute( ADDFORMATTAG_HANDLE => IUP::User->new(
    ITALIC=>"YES",
    STRIKEOUT=>"YES",
    SELECTION=>"2,1:2,12",
));

USAGE

CREATION - new() method

 $text = IUP::Text->new( VALUE=>"text text text" );

Returns: the identifier of the created element, or undef if an error occurs.

NOTE: You can pass to new() other ATTRIBUTE=>'value' or CALLBACKNAME=>\&func pairs relevant to this element - see IUP::Manual::02_Elements.

ATTRIBUTES

For more info about concept of attributes (setting/getting values etc.) see IUP::Manual::03_Attributes. Attributes specific to this element:

ALIGNMENT

[Windows and GTK Only] (non inheritable)

Text alignment. Possible values: "ALEFT", "ARIGHT", "ACENTER".

Default: "ALEFT". In Motif, text is always left aligned.

APPEND

(write-only)

Inserts a text at the end of the current text. In the Multiline, if APPENDNEWLINE=YES, a "\n" character will be automatically inserted before the appended text if the current text is not empty(APPENDNEWLINE default is YES). Ignored if set before map.

BGCOLOR

Background color of the text. Default: the global attribute TXTBGCOLOR.

BORDER

(creation only)

Shows a border around the text. Default: "YES".

CANFOCUS

(creation only) (non inheritable)

enables the focus traversal of the control. In Windows the control will still get the focus when clicked. Default: YES.

CARET

(non inheritable)

Position of the insertion point. Its format depends in MULTILINE=YES. The first position, lin or col, is "1".

For multiple lines a string with the "<lin>,<col>" format, where lin and col are integer numbers corresponding to the caret's position.

For single line a string in the "<col>" format, where col is an integer number corresponding to the caret's position.

When lin is greater than the number of lines, the caret is placed at the last line. When col is greater than the number of characters in the given line, the caret is placed after the last character of the line.

If the caret is not visible the text is scrolled to make it visible.

In Windows, if the element does not have the focus the returned value is the position of the first character of the current selection. The caret is only displayed if the element has the keyboard focus, but its position can be changed even if not visible. When changed it will also change the selection but the text will be scrolled only when it receives the focus.

XXX-needs-fix-after-adding-UTF8-support

CARETPOS

(non inheritable)

Also the position of the insertion point, but using a zero based character unique index "pos". Useful for indexing the VALUE string.

XXX-needs-fix-after-adding-UTF8-support

CLIPBOARD

(write-only)

clear, cut, copy or paste the selection to or from the clipboard. Values: "CLEAR", "CUT", "COPY" or "PASTE". In Windows UNDO is also available, and REDO is available when FORMATTING=YES.

COUNT

(read-only)

Returns the number of characters in the text. (since iup-3.5)

CUEBANNER

[Windows Only] (non inheritable)

Text that is displayed when there is no text at the control. It works as a textual cue, or tip to prompt the user for input. Valid only for MULTILINE=NO, and it is not available for Windows 2000.

DRAGDROP

[Windows and GTK Only] (non inheritable)

Enable or disable the drag&drop of files. Default: NO, but if DROPFILES_CB is defined when the element is mapped then it will be automatically enabled.

FGCOLOR

Text color. Default: the global attribute TXTFGCOLOR.

FILTER

[Windows Only] (non inheritable)

Allows a custom filter to process the characters: Can be LOWERCASE, UPPERCASE or NUMBER (only numbers allowed).

FORMATTING

[Windows and GTK Only] (non inheritable)

When enabled allow the use of text formatting attributes. In GTK is always enabled, but only when MULTILINE=YES. Default: NO.

INSERT

(write-only)

Inserts a text in the caret's position, also replaces the current selection if any. Ignored if set before map.

LINECOUNT

(read-only)

Returns the number of characters in the line where the caret is. When MULTILINE=NO returns always "1". (since iup-3.5)

LINEVALUE

(read-only)

Returns the text of the line where the caret is. It does not include the "\n" character. When MULTILINE=NO returns the same as VALUE. (since iup-3.5)

MASK

(non inheritable)

Defines a mask that will filter interactive text input.

MULTILINE

(creation only) (non inheritable)

Allows the edition of multiple lines. In single line mode some characters are invalid, like "\t", "\r" and "\n". Default: NO.

NC

Maximum number of characters allowed for keyboard input, larger text can still be set using attributes. The maximum value is the limit of the VALUE attribute. The "0" value is the same as maximum. Default: maximum.

OVERWRITE

[Windows and GTK Only] (non inheritable)

Turns the overwrite mode ON or OFF. Works only when FORMATTING=YES.

PADDING

Internal margin. Works just like the MARGIN attribute of the IUP::Hbox and IUP::Vbox containers, but uses a different name to avoid inheritance problems. Default value: "0x0". In Windows, only the horizontal value is used. (GTK 2.10 for single line)

PASSWORD

[Windows and GTK Only] (creation only, non inheritable)

Hide the typed character using an "*". Default: "NO".

READONLY

Allows the user only to read the contents, without changing it. Restricts keyboard input only, text value can still be changed using attributes. Navigation keys are still available. Possible values: "YES", "NO". Default: NO.

SCROLLBAR

(creation only)

Valid only when MULTILINE=YES. Associates an automatic horizontal and/or vertical scrollbar to the multiline. Can be: "VERTICAL", "HORIZONTAL", "YES" (both) or "NO" (none). Default: "YES". For all systems, when SCROLLBAR!=NO the natural size will always include its size even if the native system hides the scrollbar. If =item AUTOHIDE=YES scrollbars are visible only if they are necessary, by default AUTOHIDE=NO. In Windows when FORMATTING=NO, AUTOHIDE is not supported. In Motif AUTOHIDE is not supported.

SCROLLTO

(non inheritable, write only)

Scroll the text to make the given position visible. It uses the same format and reference of the CARET attribute ("lin:col" or "col" starting at 1).

SCROLLTOPOS

(non inheritable, write only)

Scroll the text to make the given position visible. It uses the same format and reference of the CARETPOS attribute ("pos" starting at 0).

SELECTEDTEXT

(non inheritable)

Selection text. Returns undef if there is no selection. When changed replaces the current selection. Similar to INSERT, but does nothing if there is no selection.

SELECTION

(non inheritable)

Selection interval. Returns undef if there is no selection. Its format depends in MULTILINE=YES. The first position, lin or col, is "1".

For multiple lines a string in the "<lin1>,<col1>:<lin2>,<col2>"format, where lin1, col1, lin2 and col2 are integer numbers corresponding to the selection's interval. col2 correspond to the character after the last selected character.

For single line a string in the "<col1>:<col2>" format, where col1 and col2 are integer numbers corresponding to the selection's interval. col2 correspond to the character after the last selected character.

In Windows, when changing the selection the caret position is also changed.

The values ALL and NONE are also accepted independently of MULTILINE.

XXX-needs-fix-after-adding-UTF8-support

SELECTIONPOS

(non inheritable)

Same as SELECTION but using a zero based character index "<pos1>:<pos2>". Useful for indexing the VALUE string. The values ALL and NONE are also accepted.

XXX-needs-fix-after-adding-UTF8-support

SIZE

(non inheritable)

Since the contents can be changed by the user, the Natural Size is not affected by the text contents . In IUP 2.x the Natural Size was defined by the number of lines in the text and the with of the largest line. For IUP 3, use VISIBLECOLUMNS and VISIBLELINES to control the Natural Size.

SPIN

(non inheritable, creation only)

Enables a spin control attached to the element. Default: NO. The spin increments and decrements an integer number. The editing in the element is still available.

SPINVALUE

(non inheritable)

The current value of the spin. The value is limited to the minimum and maximum values.

SPINMAX

(non inheritable)

The maximum value. Default: 100.

SPINMIN

(non inheritable)

The minimum value. Default: 0.

SPININC

(non inheritable)

The increment value. Default: 1.

SPINALIGN

(creation only)

The position of the spin. Can be LEFT or RIGHT. Default: RIGHT. In GTK is always RIGHT.

SPINWRAP

(creation only)

If the position reach a limit it continues from the opposite limit. Default: NO.

SPINAUTO

(creation only)

Enables the automatic update of the text contents. Default: YES. Use SPINAUTO=NO and the VALUE attribute during SPIN_CB to control the text contents when the spin is incremented.

In Windows, the increment is multiplied by 5 after 2 seconds and multiplied by 20 after 5 seconds of a spin button pressed. In GTK, the increment change is progressively accelerated when a spin button is pressed.

TABSIZE

[Windows and GTK Only]

Valid only when MULTILINE=YES. Controls the number of characters for a tab stop. Default: 8.

VALUE

(non inheritable)

Text entered by the user. The '\n' character indicates a new line, valid only when MULTILINE=YES. After the element is mapped and if there is no text will return the empty string "".

VALUEMASKED

(non inheritable) (write-only)

sets VALUE but first checks if it is validated by MASK. If not does nothing. (since iup-3.4)

VISIBLECOLUMNS

Defines the number of visible columns for the Natural Size, this means that will act also as minimum number of visible columns. It uses a wider character size then the one used for the SIZE attribute so strings will fit better without the need of extra columns. As for SIZE you can set to undef after map to use it as an initial value. Default 5

VISIBLELINES

When MULTILINE=YES defines the number of visible lines for the Natural Size, this means that will act also as minimum number of visible lines. As for SIZE you can set to undef after map to use it as an initial value. Default: 1

WORDWRAP

(creation only)

Valid only when MULTILINE=YES. If enabled will force a word wrap of lines that are greater than the with of the control, and the horizontal scrollbar will be removed. Default: NO.

The following common attributes are also accepted:

CALLBACKS

For more info about concept of callbacks (setting callback handlers etc.) see IUP::Manual::04_Callbacks. Callbacks specific to this element:

ACTION

Action generated when the text is edited, but before its value is actually changed. Can be generated when using the keyboard, undo system or from the clipboard.

Callback handler prototype:

 sub action_handler {
   my ($self, $c, $new_value) = @_;
   #...
 }

    $self: reference to the element (IUP::Text) that activated the event

    $c: valid alpha numeric character or 0.

    $new_value: Represents the new text value.

    Returns: IUP_CLOSE will be processed, but the change will be ignored. If IUP_IGNORE, the system will ignore the new value. If c is valid and returns a valid alpha numeric character, this new character will be used instead. The VALUE attribute can be changed only if IUP_IGNORE is returned.

BUTTON_CB

Action generated when any mouse button is pressed or released. Use ConvertXYToPos to convert (x,y) coordinates in character positioning.

CARET_CB

Action generated when the caret/cursor position is changed.

Callback handler prototype:

 sub caret_cb_handler {
   my ($self, $lin, $col, $pos) = @_;
   #...
 }

    $self: reference to the element (IUP::Text) that activated the event

    $lin, $col: line and column number (start at 1).

    $pos: 0 based character position.

    For single line controls lin is always 1, and pos is always col-1.

DROPFILES_CB

[Windows and GTK Only]

Action generated when one or more files are dropped in the element.

MOTION_CB

Action generated when the mouse is moved. Use ConvertXYToPos to convert (x,y) coordinates in character positioning.

SPIN_CB

Action generated when a spin button is pressed. Valid only when SPIN=YES. When this callback is called the ACTION callback is not called. The VALUE attribute can be changed during this callback only if SPINAUTO=NO.

Callback handler prototype:

 sub spin_cb_handler {
   my ($self, $pos) = @_;
   #...
 }

    $self: reference to the element (IUP::Text) that activated the event

    $pos: the value of the spin (after it was incremented).

    Returns: IUP_IGNORE is processed in Windows and Motif.

VALUECHANGED_CB

Called after the value was interactively changed by the user.

Callback handler prototype:

 sub valuechanged_cb_handler {
   my ($self) = @_;
   #...
 }

    $self: reference to the element (IUP::Text) that activated the event

The following common callbacks are also accepted:

Auxiliary Functions

TextConvertLinColToPos()

 $pos = $text->TextConvertLinColToPos($lin, $col);

Converts a (lin, col) character positioning into an absolute position. For single line controls pos is always col-1.

TextConvertPosToLinCol()

 ($lin, $col) = $text->TextConvertPosToLinCol($pos);

Converts an absolute position into a (lin, col) character positioning. For single line controls lin is always 1, and col is always pos+1.

NOTES

When MULTILINE=YES the Enter key will add a new line, and the Tab key will insert a Tab. So the "DEFAULTENTER" button will not be processed when the element has the keyboard focus, also to change focus to the next element press <Ctrl>+<Tab>.

In Windows, if you press a Ctrl+key combination that is not supported by the control, then a beep is sound.

XXX-needs-fix-after-adding-UTF8-support When using UTF-8 strings be aware that all attributes are indexed by characters, NOT by byte index, because some characters in UTF-8 can use more than one byte. This also applies to Windows if FORMATTING=YES depending on the Windows codepage (for example East Asian codepage where some characters take two bytes).

Here is a list of the common keys for all drivers. Other keys are available depending on the driver.

Navigation:

 Keys             Action             
 --------------------------------------------------
 Arrows           move by individual characters/lines
 Ctrl+Arrows      move by words/paragraphs
 Home/End         move to begin/end line
 Ctrl+Home/End    move to begin/end text
 PgUp/PgDn        move vertically by pages
 Ctrl+PgUp/PgDn   move horizontally by pages

Selection:

 Keys             Action             
 --------------------------------------------------
 Shift+Arrows     select charaters
 Ctrl+A           select all

Deleting:

 Keys             Action             
 --------------------------------------------------
 Del              delete the character at right
 Backspace        delete the character at left

Clipboard:

 Keys             Action             
 --------------------------------------------------
 Ctrl+C           copy
 Ctrl+X           cut
 Ctrl+V           paste

EXAMPLES

The element IUP::Text is used in the following sample scripts:

SEE ALSO

IUP::List

The original doc: iuptext.html