Caution: This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.

PtGenList

Generic superclass for list and tree widgets

Class hierarchy:

PtWidget --> PtBasic --> PtContainer --> PtCompound --> PtGenList

Immediate subclasses:

For more information, see the diagram of the widget hierarchy.

PhAB icon:

None -- not normally instantiated.

Public header:

<photon/PtGenList.h>

Description:

The PtGenList class is a superclass for creating list widgets. It's discussed in more detail in Building Custom Widgets.

PtGenList handles a vertical, left-aligned list of rectangular items that may have different sizes. You can select one or more items, depending on the selection policy (see Pt_ARG_SELECTION_MODE).

PtGenListItem_t is the data structure used for the items.

A PtGenList widget can have one child, provided it's a PtDivider widget. In this case, PtGenList attaches a callback to the child so that the columns are set automatically to match the children of PtDivider; the items are drawn below the divider. Some child classes of PtGenList, such as PtList and PtTree, use Tab characters as column separators.

Using scrollbars

PtGenList creates a scrollbar if the list's area isn't large enough to display all the items in the list. By default, the scrollbar is displayed only when necessary. You can control this behavior by setting the Pt_LIST_SCROLLBAR_ALWAYS or (the default) Pt_LIST_SCROLLBAR_AS_REQUIRED bits in Pt_ARG_LIST_FLAGS.

You can set or get a limited number of resources (mainly the colors) for the child PtScrollbar widget by using the list's Pt_ARG_LIST_SB_RES resource.

Current item

Most of the time, one of the items in a list widget is the current item. (On rare occasions, a list can have no current item but it can't have more than one.)

The concept of the current item is similar to the concept of widget focus; typically, the current item is drawn with a blue dotted line around it when its widget has focus. When you press Enter or Space, it's the current item that gets selected; depending on the widget's selection mode, this may also unselect any previously selected items and/or unselect the current item if it was already selected. For more information, see the description of Pt_ARG_SELECTION_MODE.

Cursor keys change the current item, scroll the list if necessary to make the new current item visible, and, depending on the widget's selection mode, may also select and unselect items. For instance, pressing the \/ key makes the next item the current item, and may select the new current item and unselect any previously selected items. Clicking on an item also makes it the current item and also may select or unselect items.

Holding down the Ctrl key when you click or press cursor keys will prevent any changes to the selection if you just want to walk the list without changing the selection.

Mouse actions

Mouse actions depend on the current selection mode.

Button action Result
Press Result depends on the value of Pt_ARG_SELECTION_MODE
Release Invokes callbacks.

Keyboard actions

Keyboard actions depend on the current selection mode.

Key Action
Enter Result depends on value of Pt_ARG_SELECTION_MODE
/\ Previous item
\/ Next item
Pg Up Previous page
Pg Dn Next page
Home First item
End Last item

New resources:

Resource C type Pt type Default
Pt_ARG_LIST_COLUMN_ATTR See below Array NULL
Pt_ARG_LIST_COLUMN_POS PtListColumn_t *, short Array NULL
Pt_ARG_LIST_DNDSEL_COLOR PgColor_t Scalar PgRGB(216, 216, 216)
Pt_ARG_LIST_FLAGS unsigned short Flag See below
Pt_ARG_LIST_FONT char * String "TextFont09"
Pt_ARG_LIST_ITEM_COUNT unsigned short Scalar 0 (read-only)
Pt_ARG_LIST_SB_RES PtArg_t *, int Array None
Pt_ARG_LIST_SCROLL_RATE unsigned char Scalar 2
Pt_ARG_LIST_SEL_COUNT unsigned short Scalar 0 (read-only)
Pt_ARG_LIST_TOTAL_HEIGHT unsigned Scalar 0 (read-only)
Pt_ARG_SCROLLBAR_WIDTH unsigned short Scalar 0 (see below)
Pt_ARG_SELECTION_FILL_COLOR PgColor_t Scalar PgRGB(142, 162, 155)
Pt_ARG_SELECTION_MODE unsigned short Scalar See below
Pt_ARG_SELECTION_TEXT_COLOR PgColor_t Scalar Pg_WHITE
Pt_ARG_TOP_ITEM_POS unsigned short Scalar 1
Pt_ARG_VISIBLE_COUNT unsigned short Scalar 0 (read-only)
Pt_CB_SCROLL_MOVE PtCallback_t * Link NULL

Pt_ARG_LIST_COLUMN_ATTR

C type Pt type Default
PtListColumnAttributes_t *, short Array NULL

An array of PtListColumnAttributes_t structures, each containing at least the following:

short flags;
Flags that define the alignment of the text and other behavior:

Pt_ARG_LIST_COLUMN_POS

C type Pt type Default
PtListColumn_t *, short Array NULL

An array of PtListColumn_t column structures. The structure contains at least the following:

short from, to;
They define the positions of the left and right edges of the column (relative to the left edge of widget's canvas).

Pt_ARG_LIST_DNDSEL_COLOR

C type Pt type Default
PgColor_t Scalar PgRGB(216, 216, 216)

The selection color in a drag-and-drop operation. See PgColor_t in the Photon Library Reference.

Pt_ARG_LIST_FLAGS

C type Pt type Default
unsigned short Flag Pt_LIST_BALLOONS_IN_COLUMNS | Pt_LIST_SCROLLBAR_AS_REQUIRED

Flags that control the appearance and behavior of the list. The possible values are:

Pt_LIST_BALLOON_AS_REQUIRED
Show a balloon if the contents of the list are clipped.
Pt_LIST_BALLOONS_IN_COLUMNS (on by default)
Display balloons for individual columns, not the entire row.
Pt_LIST_BOUNDARY_KEY_EVENTS
If this flag is clear (the default), cursor key events (/\, \/, Pg Up, Pg Down, Home, and End) are always consumed by the widget.

If this flag is set, a cursor key event is consumed only if it actually changes the current item. For example, an /\ or Home event isn't consumed if the first item in the list is already the current item.

Pt_LIST_HEADER_AUTORESIZE
Adjust the width of the PtDivider widget (if there is one) when the scrollbar is realized or unrealized.
Pt_LIST_NO_COLUMN_LINES
Don't display the lines that separate the columns in the list.
Pt_LIST_NOBLIT
Don't blit when Pt_ARG_TOP_ITEM_POS is changed.
Pt_LIST_NON_SELECT
Make the list read-only.
Pt_LIST_SCROLLBAR_ALWAYS
Always display a scrollbar.
Pt_LIST_SCROLLBAR_AS_REQUIRED (on by default)
Display a scrollbar only if required.
Pt_LIST_SCROLLBAR_AUTORESIZE
Resize the scrollbar automatically when the size of the header changes.
Pt_LIST_SCROLLBAR_GETS_FOCUS
Let the scrollbar get focus.
Pt_LIST_SHOW_BALLOON
Show list balloons.
Pt_LIST_SNAP
Make the list snap to fit the number of items. Note that the Pt_LIST_SNAP flag is cleared automatically if the items in the list don't have equal heights.

Pt_ARG_LIST_FONT

C type Pt type Default
char * String "TextFont09"

The font used for the items in the list.

Pt_ARG_LIST_ITEM_COUNT (read-only)

C type Pt type Default
unsigned short Scalar 0

The number of items.

Pt_ARG_LIST_SB_RES

C type Pt type Default
PtArg_t * Array None

An array of PtArg_t structures (see the Photon Library Reference) that are passed to the list's child PtScrollbar. Note that you can modify only a selected set of the scrollbar's resources:

Scrollbar resource Inherited from
Pt_ARG_CURSOR_COLOR PtWidget
Pt_ARG_CURSOR_TYPE PtWidget
Pt_ARG_COLOR PtBasic
Pt_ARG_FILL_COLOR PtBasic
Pt_ARG_FILL_PATTERN PtBasic
Pt_ARG_MIN_SLIDER_SIZE PtScrollbar
Pt_ARG_TRANS_PATTERN PtBasic
Pt_CB_REALIZED PtWidget
Pt_CB_UNREALIZED PtWidget

The PtGenList widget doesn't let you modify resources that might affect the position or size of the scrollbar. The main purpose of this resource is to change the colors of the scrollbar.

To get the Pt_ARG_LIST_SB_RES resource, your application must supply a buffer and pass its address and length to the PtSetArg() macro. For example, this code for a PtScrollbar widget:

PtGetResources( scrollbar, N, args );
      

is equivalent to this when the scrollbar is part of a PtGenList:

PtArg_t tmp;
PtSetArg( &tmp, Pt_ARG_LIST_SB_RES, args, N );
PtGetResources( list, 1, &tmp );
      

Pt_ARG_LIST_SCROLL_RATE

C type Pt type Default
unsigned char Scalar 2

If you drag in a list and move outside the widget, the list scrolls at a rate determined by the number of "button repeats". This resource specifies the number of button repeats that must be received before scrolling occurs. The default value is 2. To make the scrolling faster, set this resource to 1; to make scrolling slower, set this resource to a larger number.

Pt_ARG_LIST_SEL_COUNT (read-only)

C type Pt type Default
unsigned short Scalar 0

The number of selected items.

Pt_ARG_LIST_TOTAL_HEIGHT (read-only)

C type Pt type Default
unsigned Scalar 0

The total height (in pixels) of all items.

Pt_ARG_SCROLLBAR_WIDTH

C type Pt type Default
unsigned short Scalar 0 (see below)

The width of the accompanying scrollbar, if displayed. The minimum width is 6 pixels. If you set this resource to 0, the default width of 15 is used.

Pt_ARG_SELECTION_FILL_COLOR

C type Pt type Default
PgColor_t Scalar PgRGB(142, 162, 155)

The fill color for selected items. See PgColor_t in the Photon Library Reference.

Pt_ARG_SELECTION_MODE

C type Pt type Default
unsigned short Scalar See below

The selection mode. PtGenList lets you select items using the mouse or the keyboard. The descriptions below assume you're using a mouse. If a mouse isn't available, you can use the /\ and \/ keys on the numeric keypad to highlight items in a list. The widget accepts the current selection when you press Enter.

Pt_BROWSE_MODE (default)
To select an item using the mouse, either click on an item or drag the pointer down the list and release the mouse button when the correct item is highlighted. You can select only one item. If you drag the mouse, the list can scroll.
Pt_MULTIPLE_MODE
To select multiple items using the mouse, click on more than one item. When you click on a selected item, the item becomes unselected.
Pt_EXTENDED_MODE
Support click-Shift-click/drag and Ctrl-click combinations to select multiple items. To select all items between and including two items in a list, click on the first item, press the Shift key, then click on or drag to any other item in the list.

To select multiple disjoint items, hold down the Ctrl while clicking on selected items.

Pt_SINGLE_MODE
To select an item, point to the item, then click the mouse button. You can select only one item; if you select a second one, the first becomes unselected.
Pt_RANGE_MODE
To select a range of items, point to the first item, drag to the last item in the range, then release the mouse button. When you're dragging the mouse, the list can scroll.

The PtGenList widget supports several "predefined" selection modes, but you can also set "compose selection modes" using special flag values. To define a compose mode, start with one of the following values, which describe what kind of sets of items can be selected:

Pt_SELECTION_MODE_SINGLE
Select up to one item.
Pt_SELECTION_MODE_NONE
Callback functions take care of selecting items.
Pt_SELECTION_MODE_MULTIPLE
Each item can be selected independently.
Pt_SELECTION_MODE_RANGE
A range of items can be selected.

You can OR one of these values with zero or more of the following flags, which describe how the mouse and keyboard should work:

Pt_SELECTION_MODE_NOMOVE
Don't move the current item when you drag the mouse.
Pt_SELECTION_MODE_NOSCROLL
Don't scroll the widget if you drag the mouse above or below the widget.
Pt_SELECTION_MODE_NOREST
Don't restore the previous state if you release the mouse outside the widget.
Pt_SELECTION_MODE_NOCLEAR
If you click on an item, don't clear the previous selection (use with Pt_SELECTION_MODE_MULTIPLE mode only).
Pt_SELECTION_MODE_AUTO
The keyboard automatically selects the current item (unless you're pressing Ctrl).
Pt_SELECTION_MODE_NOFOCUS
If the Pt_SELECTION_MODE_AUTO flag is set, don't select the current item automatically when the widget gets focus.
Pt_SELECTION_MODE_TOGGLE
You can unselect an item by clicking on it (Pt_SELECTION_MODE_SINGLE and Pt_SELECTION_MODE_MULTIPLE modes only).

Note that zero isn't a valid value for the selection mode; neither is a mixture of predefined and compose values.

The "predefined" selection modes are equivalent to the following compose modes:

For Pt_BROWSE_MODE:
Pt_SELECTION_MODE_SINGLE | Pt_SELECTION_MODE_AUTO
For Pt_MULTIPLE_MODE:
Pt_SELECTION_MODE_MULTIPLE | Pt_SELECTION_MODE_NOMOVE | Pt_SELECTION_MODE_NOCLEAR | Pt_SELECTION_MODE_TOGGLE | Pt_SELECTION_MODE_NOSCROLL
For Pt_EXTENDED_MODE:
Pt_SELECTION_MODE_MULTIPLE | Pt_SELECTION_MODE_AUTO | Pt_SELECTION_MODE_NOMOVE | Pt_SELECTION_MODE_NOFOCUS
For Pt_SINGLE_MODE:
Pt_SELECTION_MODE_SINGLE | Pt_SELECTION_MODE_NOCLEAR
For Pt_RANGE_MODE:
Pt_SELECTION_MODE_RANGE | Pt_SELECTION_MODE_AUTO | Pt_SELECTION_MODE_NOFOCUS

Pt_ARG_SELECTION_TEXT_COLOR

C type Pt type Default
PgColor_t Scalar Pg_WHITE

The text color for selected items. See PgColor_t in the Photon Library Reference.

Pt_ARG_TOP_ITEM_POS

C type Pt type Default
unsigned short Scalar 1

The item index that appears at the top of the list. (The first item is 1.)

Pt_ARG_VISIBLE_COUNT (read-only)

C type Pt type Default
unsigned short Scalar 0

The number of items currently visible.

Pt_CB_SCROLL_MOVE

C type Pt type Default
PtCallback_t * Link NULL

A list of PtCallback_t structures that define the callbacks that the widget invokes when the top item position changes.

If the widget has the Pt_CALLBACKS_ACTIVE bit set in its Pt_ARG_FLAGS resource, these callbacks are also invoked when your application changes the top item position (Pt_ARG_TOP_ITEM_POS) by calling PtSetResource() or PtSetResources().

Each callback is passed a PtCallbackInfo_t structure that contains at least the following members:

reason
Pt_CB_SCROLL_MOVE
reason_subtype
Defines the source of the position change:
Pt_LIST_SCROLL_SCROLLBAR
The scrollbar was used.
Pt_LIST_SCROLL_LIST
The list was used directly.
event
A pointer to a PhEvent_t structure that describes the event that caused the callback to be invoked.
cbdata
A pointer to a PtScrollbarCallback_t structure that contains at least the following members:
unsigned action;
A value indicating what happened -- see below.
int position;
A value corresponding to the handle's location.

The action field can be one of the following:

Pt_SCROLL_DECREMENT
The scrollbar handle position has been decreased by one increment.
Pt_SCROLL_INCREMENT
The handle position has been increased by one increment.
Pt_SCROLL_PAGE_INCREMENT
The handle position has been increased by one page.
Pt_SCROLL_PAGE_DECREMENT
The handle position has been decreased by one page.
Pt_SCROLL_TO_MAX
The handle has been moved to the maximum value.
Pt_SCROLL_TO_MIN
The handle has been moved to the minimum value.
Pt_SCROLL_DRAGGED
The handle is being dragged.
Pt_SCROLL_RELEASED
The handle has been released after having been dragged.
Pt_SCROLL_SET
The change of position is the result of a call to PtSetResources() and the widget has the Pt_CALLBACKS_ACTIVE bit set in its Pt_ARG_FLAGS resource.
Pt_SCROLL_JUMP
You jumped to a specific location by Ctrl-clicking on the scrollbar.

These callbacks should return Pt_CONTINUE.

Inherited resources:

If the widget modifies an inherited resource, the "Default override" column indicates the new value. This modification affects any subclasses of the widget.

Resource Inherited from Default override
Pt_ARG_ANCHOR_FLAGS PtWidget
Pt_ARG_ANCHOR_OFFSETS PtWidget
Pt_ARG_AREA PtWidget
Pt_ARG_BANDWIDTH_THRESHOLD PtBasic Not used by this class.
Pt_ARG_BASIC_FLAGS PtBasic
Pt_ARG_BEVEL_WIDTH PtWidget 1
Pt_ARG_BITMAP_CURSOR PtWidget
Pt_ARG_BEVEL_COLOR PtBasic
Pt_ARG_BEVEL_CONTRAST PtBasic
Pt_ARG_COLOR PtBasic
Pt_ARG_CONTAINER_FLAGS PtContainer
Pt_ARG_CONTRAST PtBasic
Pt_ARG_CURSOR_COLOR PtWidget
Pt_ARG_CURSOR_OVERRIDE PtContainer
Pt_ARG_CURSOR_TYPE PtWidget
Pt_ARG_DARK_BEVEL_COLOR PtBasic
Pt_ARG_DARK_FILL_COLOR PtBasic
Pt_ARG_DATA PtWidget
Pt_ARG_DIM PtWidget
Pt_ARG_EFLAGS PtWidget
Pt_ARG_EXTENT PtWidget
Pt_ARG_FILL_COLOR PtBasic
Pt_ARG_FILL_PATTERN PtBasic
Pt_ARG_FLAGS PtWidget |= Pt_HIGHLIGHTED | Pt_ETCH_HIGHLIGHT | Pt_SET | Pt_GETS_FOCUS | Pt_FOCUS_RENDER
Pt_ARG_HEIGHT PtWidget
Pt_ARG_HELP_TOPIC PtWidget
Pt_ARG_HIGHLIGHT_ROUNDNESS PtBasic
Pt_ARG_INLINE_COLOR PtBasic
Pt_ARG_LIGHT_BEVEL_COLOR PtBasic
Pt_ARG_LIGHT_FILL_COLOR PtBasic
Pt_ARG_MARGIN_HEIGHT PtBasic 0
Pt_ARG_MARGIN_WIDTH PtBasic 0
Pt_ARG_MAXIMUM_DIM PtWidget
Pt_ARG_MINIMUM_DIM PtWidget
Pt_ARG_OUTLINE_COLOR PtBasic
Pt_ARG_POINTER PtWidget
Pt_ARG_POS PtWidget
Pt_ARG_RESIZE_FLAGS PtWidget 0
Pt_ARG_STYLE PtBasic
Pt_ARG_TITLE PtContainer
Pt_ARG_TITLE_FONT PtContainer
Pt_ARG_TRANS_PATTERN PtBasic
Pt_ARG_USER_DATA PtWidget
Pt_ARG_WIDTH PtWidget
Pt_CB_ACTIVATE PtBasic
Pt_CB_ARM PtBasic
Pt_CB_BALLOONS PtContainer
Pt_CB_BLOCKED PtWidget
Pt_CB_CHILD_ADDED_REMOVED PtContainer
Pt_CB_DESTROYED PtWidget
Pt_CB_DISARM PtBasic
Pt_CB_DND PtWidget See below.
Pt_CB_FILTER PtWidget
Pt_CB_GOT_FOCUS PtBasic
Pt_CB_HOTKEY PtWidget
Pt_CB_IS_DESTROYED PtWidget
Pt_CB_LOST_FOCUS PtBasic
Pt_CB_MENU PtBasic
Pt_CB_OUTBOUND PtWidget
Pt_CB_RAW PtWidget
Pt_CB_REALIZED PtWidget
Pt_CB_REPEAT PtBasic
Pt_CB_RESIZE PtContainer
Pt_CB_UNREALIZED PtWidget

Pt_CB_DND

For Pt_CB_DND callbacks for a PtGenList, the cbinfo->cbdata is a pointer to a PtListDndCallback_t structure, containing at least the following members:

PtDndCallbackInfo_t dnd_info
See the description of Pt_CB_DND for PtWidget.
PtGenListItem_t *item
The target item involved in the drag-and-drop operation.
int item_pos
The index of that item.
unsigned long flags
Possible values:

If neither of these is set, the drop occurred inside the item.

int action
This member is initially set to Pt_LIST_ITEM_DNDSELECTED_UP | Pt_LIST_ITEM_DNDSELECTED_DOWN | Pt_LIST_ITEM_DNDSELECTED_IN. You can unset some of these values to indicate that the drag-and-drop isn't accepted in that case. For example, if you unset Pt_LIST_ITEM_DNDSELECTED_IN, the drag-and-drop can't occur inside the item, only above or below.

Convenience functions:

The following convenience functions and data structure are useful when working with descendants of PtGenList:


Note: In general, the subclass specifies which of the convenience functions you can use. For example, PtList and PtTree don't let you call any of the PtGenList convenience functions except the ones that are redefined as their own convenience functions.

PtGenListAddItems()
Add items to a list.
PtGenListAllItems()
Get pointers to all the items in a list.
PtGenListClearSelection()
Clear the selection.
PtGenListCreateTextBalloon()
Create a popup balloon for an item in the list.
PtGenListDamageItem()
Redraw an item when its data has been changed.
PtGenListDrawBackground()
Draw the background of a list.
PtGenListDrawString()
Draw a string.
PtGenListFirstItem()
Return a pointer to the first item in a list.
PtGenListGetCurrent()
Return a pointer to the current item in a list.
PtGenListGetSelIndexes()
Get the indexes of the selected items.
PtGenListGoto()
Set the current item so that the new current item is visible.
PtGenListHold()
Prevent visible repair of a list widget.
PtGenListItem_t
PtGenList item structure
PtGenListItemIndex()
Find the index of an item.
PtGenListItemRealloc()
Reallocate memory for an item.
PtGenListLastItem()
Return a pointer to the last item in a list.
PtGenListLockItem()
Lock an item so it can be resized.
PtGenListRelease()
Release a hold on visible repairs of a list widget.
PtGenListRemoveItems()
Remove items from a list.
PtGenListResize()
Resize a list widget.
PtGenListSelect()
Select an item in a list.
PtGenListSelectedItems()
Get pointers to the selected items.
PtGenListSetColumnBalloon()
Adjust the balloon text to correspond to a given column.
PtGenListSetGflags()
Modify the gflags field of the widget.
PtGenListSetSelIndexes()
Set the selection indexes.
PtGenListShow()
Set the current position so a given item is visible.
PtGenListUnlockItem()
Unlock an item so it can be updated.
PtGenListUnselect()
Unselect an item in a list.

The following convenience functions are useful only if you're creating a custom list widget; they're described in the Creating a List Widget chapter of Building Custom Widget:

PtSuperClassGenListDraw()
Invoke the Draw List method in a superclass.
PtSuperClassGenListInflate()
Invoke the List Inflate method in a superclass.
PtSuperClassGenListKey()
Invoke the List Key method in a superclass.
PtSuperClassGenListMouse()
Invoke the List Mouse method in a superclass.
PtSuperClassGenListSelect()
Invoke the List Select method in a superclass.