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)
frameA 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.
nameA string, the TextView's internal name.
textRectA Rect in the TextView's coordinate system that determines where the text will be drawn; the
bottomis never used; therightis only used when text wrapping is turned on.resizingModeAn integer, the resizing mode. (See the resizing mode constants.) Should only be specified when there is a frame. Defaults to
B_FOLLOW_NONE.flagsAn integer, view flags. (See the view flag constants.)
archiveA 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()
clipboardA Clipboard object to use for the operations; the builtin responses to user interaction use the global
be_clipboardobject.
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)
offsetAn 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,bottomFloating 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)
lineIndexAn integer, the line index.
startLine,endLineIntegers, 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)
offsetAn integer offset in bytes (not characters).
pointA Point in the TextView's coordinate system.
lineAn 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 647bytes (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,enabledA boolean, the state of the proprty in question.
widthA floating point number, the new tab width.
maxA 32-bit integer, the maximum bytes allowed in the TextView.
alignmentAn integer alignment constant.
colorsAn integer color space constant.
resizeViewAn 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.
charA 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)
offsetAn 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,endOffsetInteger 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)
offsetAn integer offset in bytes (not characters).
start,endInteger offsets (in bytes, not characters).
fontA Font object.
modeAn integer font property constant indicating which properties of
fontshould be used.colorAn rgb_color.
runsdataA 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)
textA string.
fileA file object (Perl file handle, Python
file); the contents of the file, from the current position to the end, will become the new text.filenameA string containing a filename; the contents of the file, starting at
offsetforlengthbytes, will become the new text.offsetAn 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).lengthThe number of bytes (not characters) to read from a file or pull from the TextView.
startOffset,endOffsetThe 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.
runsAn 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)
rectA Rect, the new text rectangle.
startOffset,endOffsetInteger 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)
clipboardA 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)
archiveA 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)
fromOffsettoOffsetInteger 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()
dragA 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)
textA string, the text to be inserted.
offsetAn integer offset (in bytes, not characters).
runsA 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
selectionB_GET_PROPERTY,B_SET_PROPERTYTwo Int32 values, the start and end offsets of the selection
TextB_GET_PROPERTY,B_SET_PROPERTYA string, the text in the TextView
TextB_COUNT_PROPERTYGets the length of the test in the TextView
text_run_arrayB_GET_PROPERTY,B_SET_PROPERTYA raw byte string, suitable for use with FlattenRunArray and UnflattenRunArray. (Currently is not working.)
TextView also inherits the following suites: