Haiku API Bindings
View
Not logged in

Documentation | InterfaceKit | View

SYNOPSIS

Perl

Python

use HaikuR1::Application;
use HaikuR1::Window;
use HaikuR1::View;

# define MyApplication, MyWindow, and MyView subclass here

my $app = MyApplication->new($signature);
my $window = MyWindow->new(
    frame      => Rect->new($left, $top, $right, $bottom),
    title      => $title,
    type       => B_TITLED_WINDOW,
    flags      => B_QUIT_ON_WINDOW_CLOSE,
    workspaces => B_CURRENT_WORKSPACE,
);
my $view = MyView->new(
    frame        => Rect->new($vleft, $vtop, $vright, $vbottom),
    name         => $name,
    resizingMode => $resizing_mode,
    flags        = >$vflags,
);
$window->AddChild($view);

$window->Show();
$app->Run();

# wait for an event to Quit the app or window

DESCRIPTION

Exposes the BView object.

For more information on View, see the Be Book class description, the Be Book overview, and the Haiku Book class description.

METHODS

In addition to the methods described here, there are also drawing operations and Layout-related methods.

While the majority of the drawing functions are not necessary for using standard Views, there are a few that are of more general use:

Constructor

Creates a View.

Perl

Python

HaikuR1::View->new(
    frame        => $frame,
    name         => $name,
    resizingMode => $resizingMode,
    flags        => $flags,
);
HaikuR1::View->new(
    name   => $name,
    flags  => $flags,
    layout => $layout,
);
HaikuR1::View->new($archive);

Background bitmaps

SetViewBitmap

ClearViewBitmap

SetViewOverlay

ClearViewOverlay

Sets or clears the View's background or overlay Bitmap.

Perl

Python

$view->SetViewBitmap(
    bitmap => $bitmap,
    srcRect => $srcRect,
    dstRect => $dstRect,
    followFlags => $followFlags,
    options => $options,
);
$view->ClearViewBitmap();
$view->SetViewOverlay(
    bitmap => $bitmap,
    srcRect => $srcRect,
    dstRect => $dstRect,
    colorKey => $colorKey,
    followFlags => $followFlags,
    options => $options,
);
$view->ClearViewOverlay();

Bounds

Frame

LeftTop

Returns the View's bounding rectangle; Bounds returns it in the View's own coordinate system, while Frame returns it in the parent's coordinate system. The Bounds rectangle represents the visible rectangle; therefore it may not always originate at 0,0.

LeftTop returns the upper left coordinate of the View as a Point; this is the left top point of the Bounds rectangle.

Perl

Python

$view->Bounds();
$view->Frame();
$view->LeftTop();

Child Views

AddChild

ChildAt

CountChildren

Parent

NextSibling

PreviousSibling

FindView

RemoveChild

These methods do what you expect. ChildAt, Parent, NextSibling, and PreviousSibling return a View object.

Note that Parent will return NULL if the View's immediate parent is a Window instead of a View.

Perl

Python

$view->AddChild($view, $sibling);
$view->ChildAt($index);
$view->CountChildren();
$view->Parent();
$view->NextSibling();
$view->PreviousSibling();
$view->FindView($name);
$view->RemoveChild($view);

Coordinate Conversion

ConvertToScreen

ConvertFromScreen

ConvertToParent

ConvertFromParent

These methods do what you expect.

Perl

Python

$view->ConvertToScreen($viewPoint);
$view->ConvertToScreen($viewRect);
$view->ConvertFromScreen($screenPoint);
$view->ConvertFromScreen($screenRect);
$view->ConvertToParent($viewPoint);
$view->ConvertToParent($viewRect);
$view->ConvertFromParent($parentPoint);
$view->ConvertFromParent($parentRect);

CopyBits

Copies bits from one rectangle to another, scaling if necessary.

Perl

Python

$view->CopyBits($src, $dst);

DragMessage

For more information on dragging, see the BeBook section on Drag And Drop.

Starts a drag-and-drop session.

Perl

Python

$view->DragMessage(
    message     => $message,
    bitmap      => $bitmap,
    dragMode    => $dragMode,
    point       => $point,
    replyTarget => $replyTarget,
);
$view->DragMessage(
    message     => $message,
    rect        => $rect,
    replyTarget => $replyTarget,
);

EventMask

SetEventMask

SetMouseEventMask

Gets or sets the event mask, allowing the View to receive mouse events when the mouse isn't over the View, and/or keyboard events when the View does not have focus.

SetMouseEventMask can only be called during a MouseDown hook; in other cases it will do nothing and return B_ERROR. It will not work to call the hook yourself; it must be legitimate hook triggered in response to a B_MOUSE_DOWN message. The mask will be added to the current event mask for the remainder of the hook.

Perl

Python

$view->EventMask();
$view->SetEventMask($mask, $options);
$view->SetMouseEventMask($mask, $options);

FillRule

SetFillRule

Gets or sets the View's fill rule (the way it fills shapes).

Perl

Python

$view->FillRule();
$view->SetFillRule($rule);

Flags

SetFlags

Gets or sets the View's flags.

SetFlags can also also called as a hook.

Perl

Python

$view->Flags();
$view->SetFlags($flags);

Flushing and Synching

Flush

Sync

Flush sends all pending messages to the Application Server and immediately returns. Sync sends all pending messages to the Application Server and returns when they have all been processed.

Perl

Python

$view->Flush();
$view->Sync();

Font

ForceFontAliasing

GetFontHeight

These functions do what you expect. The return value of GetFontHeight is a font_height structure.

Perl

Python

$view->ForceFontAliasing($enable);
$view->GetFontHeight();

GetMouse

Gets the mouse location and state. Returns a Point and a numeric value, one of the mouse button constants.

Perl

Python

$view->GetMouse($checkMessageQueue);

Invalidate

DelayedInvalidate

Marks the View, or a portion of it, as invalid, so it will be redrawn.

Perl

Python

$view->Invalidate();
$view->Invalidate($rect);
$view->Invalidate($region);
$view->DelayedInvalidate($delay);
$view->DelayedInvalidate($delay, $rect);

IsFocus

Returns true if the View has the focus in its Window.

Perl

Python

$view->IsFocus();

IsHidden

Returns true if the View is hidden.

If looking_from is omitted, or is provided but is not an ancestor of the View, then if the View or any ancestor View is hidden, the function will return true (i.e., will indicate that the View is hidden). Note that ancestor here includes the owner Window; that is, if the owner Window is hidden, the View is also hidden.

If looking_from is provided and is an ancestor of the View, then it will only check ancestors between the View and looking_from; if all of these (including looking_from itself) are visible, then the View is visible from the point of view of looking_from (even if it is in fact not visible on the screen).

Perl

Python

$view->IsHidden();
$view->IsHidden($looking_from);

IsPrinting

Returns true if the View is printing.

Perl

Python

$view->IsPrinting();

MoveTo

MoveBy

Moves the View to or by the given coordinates.

Perl

Python

$view->MoveTo($where);
$view->MoveTo($x, $y);
$view->MoveBy($horizontal, $vertical);

Floating point numbers, the new coordinates or the offsets to the new coordinates.

ResizeTo

ResizeBy

Changes the View's size to or by the given dimensions.

Perl

Python

$view->ResizeTo($size);
$view->ResizeTo($width, $height);
$view->ResizeBy($width, $height);

ResizingMode

SetResizingMode

Gets or sets the View's resizing mode.

Perl

Python

$view->ResizingMode();
$view->SetResizingMode($mode);

ScrollBar

Returns the View's [ScrollBar](ScrollBar.html), or the
empty value if there is no Scrollbar.

Perl

Python

$view->ScrollBar($posture);

ScrollTo

ScrollBy

Scrolls the View to or by the given coordinates.

The Set methods also serve as hooks. If you override these methods in a subclass, be aware that while an rgb_color may be either a native list or a native map, when the hook is called from C++ code, a map will be passed to your hook.

Perl

Python

$view->ScrollTo($where);
$view->ScrollTo($x, $y);
$view->ScrollBy($x, $y);

ScrollWithMouseWheelDelta

This method is mostly used internally; you may need to use it in a hook in a custom View, but otherwise you will not need to call it yourself.

Perl

Python

$view->ScrollWithMouseWheelDelta($direction, $delta);

SetViewCursor

Sets the View's cursor.

Perl

Python

$view->SetViewCursor($cursor, $sync);

String Widths

TruncateString

StringWidth

GetStringWidths

These methods do what you expect.

Perl

Python

$view->TruncateString($string, $mode, $width);
$view->StringWidth($string);
$view->GetStringWidths($strings);

ToolTip

SetToolTip

ShowToolTip

HideToolTip

Sets the tooltip.

Perl

Python

$view->ToolTip($class);
$view->SetToolTip($tip);
$view->SetToolTip($text);
$view->ShowToolTip($tip);                                                                                                       
$view->HideToolTip();

Tracking Rectangles

BeginRectTracking

EndRectTracking

Starts or stops displaying a rectangular outline that follows the cursor.

Perl

Python

$view->BeginRectTracking($rect, $how);
$view->EndRectTracking();

Window

RemoveSelf

Window returns the View's owner Window.

RemoveSelf removes this View from the owner Window. Returns true if the View was successfully removed, false if the View could not be removed or if the View doesn't belong to a Window.

Perl

Python

$view->Window();
$view->RemoveSelf();

HOOKS

AllAttached

Called when all the View's child Views have been attached to a Window; a parent View will received this notification after its children.

Perl

Python

$view->AllAttached();

AllDetached

Called when all the View's child Views have been detached from a Window; a parent View will received this notification after its children.

Perl

Python

$view->AllDetached();

AttachedToWindow

Called when the View has been attached to a Window; a parent View will received this notification before its children.

Perl

Python

$view->AttachedToWindow();

DetachedFromWindow

Called when the View has been detached from a Window; a parent View will received this notification before its children.

Perl

Python

$view->DetachedFromWindow();

FrameMoved

Called when the View has moved within its owning Window.

Perl

Python

$view->FrameMoved($newPosition);

FrameResized

Called when the View has been resized.

Perl

Python

$view->FrameResized($newWidth, $newHeight);

GetPreferredSize

Gets the View's preferred size.

Perl

Python

$view->GetPreferredSize();

GetToolTipAt

Called when the user hovers over a point. You should return the ToolTip that should be shown.

Perl

Python

$view->GetToolTipAt($point);

Hide

Hides the View.

Perl

Python

$view->Hide();

KeyDown

Called when the user presses a key while the View has focus.

Perl

Python

$view->KeyDown($bytes);

KeyUp

Called when the user releases a key while the View has focus.

Perl

Python

$view->KeyUp($bytes);

MakeFocus

Makes the view focused (or not focused) within its Window.

Perl

Python

$view->MakeFocus($focused);

MouseDown

Called when the user presses the mouse button while the View has focus.

Perl

Python

$view->MouseDown($point);

MouseMoved

Called when the user moves the mouse button while the View has focus.

Perl

Python

$view->MouseMoved($point, $transit, $message);

MouseUp

Called when the user releases the mouse button while the View has focus.

Perl

Python

$view->MouseUp($point);

Pulse

Called periodically, at the rate set by the owning Window's pulse rate.

Perl

Python

$view->Pulse();

ResizeToPreferred

Called when the View should be resized to its preferred size.

Perl

Python

$view->ResizeToPreferred();

Show

Shows the View.

Perl

Python

$view->Show();

TargetedByScrollView

Called when the View becomes the target of a ScrollView.

Perl

Python

$view->TargetedByScrollView($scrollView);

WindowActivated

Called when the View's owning Window is activated or deactivated.

Perl

Python

$view->WindowActivated($state);

ARCHIVABLE INTERFACE

View inherits the methods and hooks of Archivable.

HANDLER INTERFACE

View inherits the methods and hooks of Handler.

CONSTANTS

Event mask

Perl

Python

use HaikuR1::View qw(:event_mask)

Event mask options

Perl

Python

use HaikuR1::View qw(:event_mask_options)

Mouse buttons

Perl

Python

use HaikuR1::View qw(:mouse_buttons)

Mouse transit

Perl

Python

use HaikuR1::View qw(:mouse_transit)

Resize modes

Perl

Python

use HaikuR1::View qw(:resizing)

Tracking

Perl

Python

use HaikuR1::View qw(:tracking)

View flags

Perl

Python

use HaikuR1::View qw(:flags)

SCRIPTING SUITE

The name of View's scripting suite is suite/vnd.Be-view.

View also inherits the following suites: