Documentation | InterfaceKit | TextView
SYNOPSIS
Perl
use HaikuR1::TextView; my $textview = HaikuR1::TextView->new( frame => $frame, name => $name, textRect => $textRect, resizingMode => $resizingMode, flags => $flags, ); $window->AddChild($textview);
Python
import HaikuR1.InterfaceKit.TextView textview = TextView( frame = frame, name = name, textRect = textRect, resizingMode = resizingMode, flags = flags, ) window.AddChild(textview)
DESCRIPTION
Exposes the BTextView
object.
For more information on TextView, see the Be Book class description, the Be Book overview, and the Haiku Book class description.
METHODS
Constructor
Creates a TextView.
Perl
HaikuR1::TextView->new( frame => $frame, name => $name, textRect => $textRect, resizingMode => $resizingMode, flags => $flags, ); HaikuR1::TextView->new( frame => $frame, name => $name, textRect => $textRect, font => $font, color => $color, resizingMode => $resizingMode, flags => $flags, ); HaikuR1::TextView->new($archive);
Python
TextView( frame = frame, name = name, textRect = textRect, resizingMode = resizingMode, flags = flags, ) TextView( frame = frame, name = name, textRect = textRect, font = font, color = color, resizingMode = resizingMode, flags = flags, ) TextView(archive)
frame
A Rect that indicates where on the parent Window the View should be. You should not specify a frame on a View that will be added to a parent which uses a Layout.
name
A string, the TextView's internal name.
textRect
A Rect in the TextView's coordinate system that determines where the text will be drawn; the
bottom
is never used; theright
is only used when text wrapping is turned on.resizingMode
An integer, the resizing mode. (See the resizing mode constants.) Should only be specified when there is a frame. Defaults to
B_FOLLOW_NONE
.flags
An integer, view flags. (See the view flag constants.)
archive
A Message, contains an archived version of the Button.
Edit operations
Cut
Copy
Paste
Clear
Undo
UndoState
These methods do what you expect. UndoState
returns two values: one of the
undo state constants and a boolean indicating whether the
available operation is a redo.
Cut
, Copy
, Paste
, and Undo
can also be called as hooks.
Perl
$textview->Cut($clipboard); $textview->Copy($clipboard); $textview->Paste($clipboard); $textview->Clear(); $textview->Undo($clipboard); $textview->UndoState();
Python
textview.Cut(clipboard) textview.Copy(clipboard) textview.Paste(clipboard) textview.Clear() textview.Undo(clipboard) textview.UndoState()
clipboard
A Clipboard object to use for the operations; the builtin responses to user interaction use the global
be_clipboard
object.
FindWord
Given an offset, returns the starting and ending offsets of the "word" at that offset. A "word" is a sequence of characters in the same category. TextView currenly recognizes the following categories:
whitespace
- space, tab, newline
graphical
= + @ # $ % ^ & \* \\ | < > / ~
quote
' "
punctuation
, . ? ! ; : -
open parens
( [ {
close parens
) ] }
everything else
This method can also be called as a hook.
Perl
$textview->FindWord($offset);
Python
textview.FindWord(offset)
offset
An integer offset (in bytes, not characters).
Insets
GetInsets
SetInsets
These methods are used with Layout-enabled TextViews.
Perl
$textview->GetInsets(); $textview->SetInsets( left => $left, top => $top, right => $right, bottom => $bottom, );
Python
textview.GetInsets() textview.SetInsets( left = left, top = top, right = right, bottom = bottom, )
left
,top
,right
,bottom
Floating point numbers.
Lines
CountLines
CurrentLine
GoToLine
LineWidth
LineHeight
CanEndLine
These functions do what you expect. Note that CurrentLine
and GoToLine
use a zero-based index.
CanEndLine
can also be called as a hook.
Perl
$textview->CountLines(); $textview->CurrentLine(); $textview->GoToLine($lineIndex); $textview->LineWidth($lineIndex); $textview->LineHeight($lineIndex); $textview->TextHeight($startLine, $endLine); $textview->CanEndLine($offset);
Python
textview.CountLines() textview.CurrentLine() textview.GoToLine(lineIndex) textview.LineWidth(lineIndex) textview.LineHeight(lineIndex) textview.TextHeight(startLine, endLine) textview.CanEndLine(offset)
lineIndex
An integer, the line index.
startLine
,endLine
Integers, starting and ending indexes for a range of lines.
offset
An integer offset in bytes (not characters).
Locations
LineAt
PointAt
OffsetAt
These methods do what you expect.
Perl
$textview->LineAt($offset); $textview->LineAtPoint($point); $textview->PointAt($offset); $textview->OffsetAt($line); $textview->OffsetAtPoint($point);
Python
textview.LineAt(offset) textview.LineAtPoint(point) textview.PointAt(offset) textview.OffsetAt(line) textview.OffsetAtPoint(point)
offset
An integer offset in bytes (not characters).
point
A Point in the TextView's coordinate system.
line
An integer, the zero-based line index.
Properties
IsStylable
SetStylable
TabWidth
SetTabWidth
IsSelectable
MakeSelectable
IsEditable
MakeEditable
DoesWordWrap
SetWordWrap
MaxBytes
SetMaxBytes
DisallowChar
AllowChar
Alignment
SetAlignment
DoesAutoindent
SetAutoindent
ColorSpace
SetColorSpace
IsResizable
MakeResizable
DoesUndo
SetDoesUndo
IsTypingHidden
HideTyping
These methods do what you expect. By default, a TextView:
- is selectable
- is editable
- is not stylable
- is left-aligned
- has a tab width of
28.0
- wraps lines
- does not autoindent
- allows up to
2 147 483 647
bytes (the maximum possible) - is not resizable
- disallows no characters
Perl
$textview->IsStylable(); $textview->SetStylable($stylable); $textview->TabWidth(); $textview->SetTabWidth($width); $textview->IsSelectable(); $textview->MakeSelectable($selectable); $textview->IsEditable(); $textview->MakeEditable($editable); $textview->DoesWordWrap(); $textview->SetWordWrap($wrap); $textview->MaxBytes(); $textview->SetMaxBytes($max); $textview->Alignment(); $textview->SetAlignment($flag); $textview->DoesAutoindent(); $textview->SetAutoindent($state); $textview->ColorSpace(); $textview->SetColorSpace($colors); $textview->IsResizable(); $textview->MakeResizable($resize, $resizeView); $textview->DoesUndo(); $textview->SetDoesUndo($undo); $textview->IsTypingHidden(); $textview->HideTyping($enabled);
Python
textview.IsStylable() textview.SetStylable(stylable) textview.TabWidth() textview.SetTabWidth(width) textview.IsSelectable() textview.MakeSelectable(selectable) textview.IsEditable() textview.MakeEditable(editable) textview.DoesWordWrap() textview.SetWordWrap(wrap) textview.MaxBytes() textview.SetMaxBytes(max) textview.Alignment() textview.SetAlignment(alignment) textview.DoesAutoindent() textview.SetAutoindent(state) textview.ColorSpace() textview.SetColorSpace(colors) textview.IsResizable() textview.MakeResizable(resize, resizeView) textview.DoesUndo() textview.SetDoesUndo(undo) textview.IsTypingHidden() textview.HideTyping(enabled)
stylable
,selectable
,editable
,wrap
,state
,resize
,undo
,enabled
A boolean, the state of the proprty in question.
width
A floating point number, the new tab width.
max
A 32-bit integer, the maximum bytes allowed in the TextView.
alignment
An integer alignment constant.
colors
An integer color space constant.
resizeView
An optional container View (for example, a ScrollView); if provided, the container view will be resized (and you should set it up to resize the TextView); otherwise, the TextView itself will be resized.
char
A character to disallow or re-allow. According to the Be Book, only single-byte characters are permitted.
Scrolling
ScrollToSelection
ScrollToOffset
These methods do what you expect.
Perl
$textview->ScrollToSelection(); $textview->ScrollToOffset($offset);
Python
textview.ScrollToSelection() textview.ScrollToOffset(offset)
offset
An integer offset in bytes (not characters).
Select
SelectAll
GetSelection
Highlight
Thse functions do what you expect. Select
can also be called as a hook.
Perl
$textview->Select($startOffset, $endOffset); $textview->SelectAll(); $textview->GetSelection(); $textview->Highlight($startOffset, $endOffset);
Python
textview.Select(startOffset, endOffset) textview.SelectAll() textview.GetSelection() textview.Highlight(startOffset, endOffset)
startOffset
,endOffset
Integer offsets (in bytes, not characters) to select or highlight.
Styles
GetFontAndColor
SetFontAndColor
RunArray
SetRunArray
FlattenRunArray
UnflattenRunArray
Set the styles, either via passing a font and color or by passing a list of styles.
Perl
$textview->GetFontAndColor($offset); $textview->SetFontAndColor($start, $end, $font, $mode, $color); $textview->SetFontAndColor($font, $mode, $color); $textview->SetRunArray($start, $end, $runs); $textview->FlattenRunArray($inArray); $textview->UnflattenRunArray($data);
Python
textview.GetFontAndColor(offset) textview.SetFontAndColor(start, end, font, mode, color) textview.SetFontAndColor(font, mode, color) textview.SetRunArray(start, end, runs) textview.FlattenRunArray(runs) textview.UnflattenRunArray(data)
offset
An integer offset in bytes (not characters).
start
,end
Integer offsets (in bytes, not characters).
font
A Font object.
mode
An integer font property constant indicating which properties of
font
should be used.color
An rgb_color.
runs
data
A byte string, a flattened text_run_array.
Text
GetText
ByteAt
TextLength
SetText
Insert
Delete
These functions do what you expect. Text
and SetText
operate on the entire
text of the TextView; the others specify portions of text.
Perl
$textview->Text(); $textview->GetText($offset, $length); $textview->ByteAt($offset); $textview->TextLength(); $textview->SetText( text => $text, runs => $runs, ); $textview->SetText( file => $file, runs => $runs, ); $textview->SetText( filename => $filename, offset => $offset, length => $length, runs => $runs, ); $textview->Insert($offset, $text, $runs); $textview->Insert($text, $runs); $textview->Delete($startOffset, $endOffset); $textview->Delete(); $textview->DisallowChar($char); $textview->AllowChar($char);
Python
textview.Text() textview.GetText(offset, length) textview.ByteAt(offset) textview.TextLength() textview.SetText( text = text, runs = runs, ) textview.SetText( file = file, runs = runs, ) textview.SetText( filename = filename, offset = offset, length = length, runs = runs, ) textview.Insert(offset, text, runs) textview.Insert(text, runs) textview.Delete(startOffset, endOffset) textview.Delete() textview.DisallowChar(char) textview.AllowChar(char)
text
A string.
file
A file object (Perl file handle, Python
file
); the contents of the file, from the current position to the end, will become the new text.filename
A string containing a filename; the contents of the file, starting at
offset
forlength
bytes, will become the new text.offset
An offset into a file or the TextView; if omitted from
SetText
, the text will be inserted before the current selection (but the selection will not be replaced).length
The number of bytes (not characters) to read from a file or pull from the TextView.
startOffset
,endOffset
The starting and ending offsets of the text to be deleted; note that is two offsets, not an offset and a length; if omitted, the current selection will be deleted.
runs
An optional text_run_array indicating the styles for the given text; will be ignored if the TextView is not stylable.
TextRect
SetTextRect
GetTextRegion
These functions do what you expect.
Perl
$textview->TextRect(); $textview->SetTextRect($rect); $textview->GetTextRegion($startOffset, $endOffset);
Python
textview.TextRect() textview.SetTextRect(rect) textview.GetTextRegion(startOffset, endOffset)
rect
A Rect, the new text rectangle.
startOffset
,endOffset
Integer offsets (in bytes, not characters).
HOOKS
AcceptsPaste
This is called when text is pasted into the TextView. Return true to allow, false to disallow.
(Currently, this hook is not called by the system.)
Perl
$textview->AcceptsPaste($clipboard);
Python
textview.AcceptsPaste(clipboard)
clipboard
A Clipboard object containing the data to be pasted.
AcceptsDrop
This is called when something is dropped into the TextView. Return true to allow, false to disallow.
Perl
$textview->AcceptsDrop($archive);
Python
textview.AcceptsDrop(archive)
archive
A Message contaning the dropped data.
DeleteText
Caled when text is deleted. You should call the base class version to do the actual deletion.
Perl
$textview->DeleteText($fromOffset, $toOffset);
Python
textview.DeleteText(fromOffset, toOffset)
fromOffset
toOffset
Integer offsets (in bytes, not characters).
GetDragParameters
Called when the TextView is about to be dragged. You should return three things: a Bitmap, a Point, and a Handler. These will be passed to View.DragMessage.
Perl
$textview->GetDragParameters();
Python
textview.GetDragParameters()
drag
A Message the drag message; you can add any necessary data to it.
InsertText
Called when text is inserted. You should call the base class version to do the actual insertion.
Perl
$textview->InsertText($text, $offset, $runs);
Python
textview.InsertText(text, offset, runs)
text
A string, the text to be inserted.
offset
An integer offset (in bytes, not characters).
runs
A text_run_array indicating the styles for the given text.
CONSTANTS
undo_state
Perl
use HaikuR1::TextView qw(:undo_state)
Python
Python does not support export tags.
- B_UNDO_UNAVAILABLE
- B_UNDO_TYPING
- B_UNDO_CUT
- B_UNDO_PASTE
- B_UNDO_CLEAR
- B_UNDO_DROP
SCRIPTING SUITE
The name of TextView's scripting suite is suite/vnd.Be-text-view
.
Properties
selection
B_GET_PROPERTY
,B_SET_PROPERTY
Two Int32 values, the start and end offsets of the selection
Text
B_GET_PROPERTY
,B_SET_PROPERTY
A string, the text in the TextView
Text
B_COUNT_PROPERTY
Gets the length of the test in the TextView
text_run_array
B_GET_PROPERTY
,B_SET_PROPERTY
A raw byte string, suitable for use with FlattenRunArray and UnflattenRunArray. (Currently is not working.)
TextView also inherits the following suites: