PtGenList
![]() |
![]() |
![]() |
![]() |
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_LIST_COLUMN_ELLIPSIS — If the text doesn't fit into the column, draw an ellipsis (...) instead of part of the text, in accordance with the column's alignment. For example, if the column is left-aligned, draw the ellipsis instead of the end of the text; if the column is right-aligned, draw the ellipsis instead of the beginning.
- Pt_LIST_COLUMN_ELLIPSIS_MIDDLE — Draw the ellipsis in the middle of the string. You must also set Pt_LIST_COLUMN_ELLIPSIS.
- Pt_LIST_COLUMN_ELLIPSIS_INVERT Invert the ellipsis position. You must also set Pt_LIST_COLUMN_ELLIPSIS.
- Pt_LIST_COLUMN_LEFT
- Pt_LIST_COLUMN_RIGHT
- Pt_LIST_COLUMN_CENTER
- Pt_LIST_COLUMN_DAMAGE_ALWAYS —
redraw the column when the column's position or size
changes, even if it doesn't seem necessary.
For example, if a right-aligned column is made narrower but its right edge doesn't move, there's no need to redraw the column. You can set the flag to force a redraw, which needs to be done if the column contains some elements that aren't right-aligned. This flag is usually set by the child class of PtGenList that knows what's drawn in the columns.
- Pt_LIST_COLUMN_NO_STRING — if set, PtGenListDrawString() skips over this column.
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:
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.
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:
- Pt_LIST_ITEM_DNDSELECTED_UP — the drop occurred above the item.
- Pt_LIST_ITEM_DNDSELECTED_DOWN — the drop occurred below the item.
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:
![]() |
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.
![]() |
![]() |
![]() |
![]() |

![[Previous]](prev.gif)
![[Contents]](contents.gif)
![[Index]](keyword_index.gif)
![[Next]](next.gif)

