# ArrowButton

Derived from: public BControl

Declared in: ArrowButton.h

Library: none

## Overview

ArrowButton is patterned after BButton, with the exception that instead of invoking when the user clicks and releases, with the button press being cancelled if the user's mouse moves off the button, as BButton does, ArrowButton will immediately be invoked when the user clicks on it, and if the mouse moves off, then back on, the ArrowButton will be invoked again. If you want to scroll when the user holds down, respond to the invocation message by creating a BMessageRunner to send you messages at a fast interval, and as long as the ArrowButton's state is B_CONTROL_ON, continue to scroll. Once the state transitions to B_CONTROL_OFF, you can stop scrolling and stop or delete your BMessageRunner.

This class depends on the control framework defined in the BControl class. In particular, it calls these BControl functions:

- `SetValue()` to make each change in the BControl's value. This is a hook function that you can override to take collateral action when the value changes.
- `Invoke()` to post a message each time the button is clicked or operated from the keyboard. You can designate the object that should handle the message by calling BControl's `SetTarget()` function. A model for the message is set by the BButton constructor (or by BControl's `SetMessage()` function).
- `IsEnabled()` to determine how the button should be drawn and whether it's enabled to post a message. You can call BControl's `SetEnabled()` to enable and disable the button.

## Constructor and Destructor

### ArrowButton()

          ArrowButton(BRect frame, const char *name, const char *label, BMessage *message,
                ArrowOrientation orientation, uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
                uint32 flags = B_WILL_DRAW | B_NAVIGABLE)

Creates an ArrowButton. The arrow's orientation must be one of the following constants: ARROW_UP, ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT to indicate the direction that the arrow points. For ARROW_UP or ARROW_DOWN, the width of the frame BRect should be 14 and the height 15. For ARROW_LEFT or ARROW_RIGHT, the width should be 15 and the height 14.

The BMessage is sent when the ArrowButton is invoked by the user. The ArrowButton takes posesstion of, and responsibility for deleting, the message, so the caller should not delete it.

Construction from an archive is currently not implemented. It isn't high on my priorities, since archival is not something I'm making use of. If someone needs this functionality and fills it in, please send me the modified code so that others can benefit from it.

### ~ArrowButton()

          virtual ~ArrowButton()

Destroys the ArrowButton and frees all memory associated with it.

## Member Functions

### Archive()

          virtual status_t Archive(BMessage *archive, bool deep = true) const

Currently not implemented. It isn't high on my priorities, since archival is not something I'm making use of. If someone needs this functionality and fills it in, please send me the modified code so that others can benefit from it.

See also: `BArchivable::Archive()`, `Instantiate()` static function

### AttachedToWindow()

          virtual void AttachedToWindow()

Sets the control to look enabled or disabled, depending on whether or not the window is activated.

See also: `BView::AttachedToWindow()`, `BControl::AttachedToWindow()`

### Draw()

          virtual void Draw(BRect update_rect)

Draws the control to look activated, enabled but inactive, or disabled, depending on whether or not the window is activated and whether or not the user is pressing the ArrowButton.

See also: `BView::WindowActivated()`

### GetPreferredSize()

          virtual void GetPreferredSize(float *width, float *height)

Writes the preferred size of the ArrowButton into the variables that the width and height arguments refer to. `ResizeToPreferred()`, defined in the BView class, resizes a view's frame rectangle to the preferred size, keeping its left and top sides constant. An ArrowButton is automatically resized to its preferred width and height by `AttachedToWindow()`. For ARROW_UP or ARROW_DOWN, the width of the frame BRect should be 14 and the height 15. For ARROW_LEFT or ARROW_RIGHT, the width should be 15 and the height 14.

See also: `BView::WindowActivated()`

### MouseDown()

          virtual void MouseDown(BPoint point)

Activates the control.

See also: `BView::MouseDown()`

### SetEnabled()

          virtual void SetEnabled(bool on)

Sets the control to be and look enabled or disabled.

See also: `BControl::SetEnabled()`

### WindowActivated()

          virtual void WindowActivated(bool state)

Sets the control to look enabled or disabled, depending on whether or not the window is activated.

See also: `BView::WindowActivated()`

By Brian Tietz

Copyright 2000

Bug reports (including documentation errors) and feature requests can be sent to briant@timelinevista.com.