TTreeItem / TTVItem

Fuente: source/classes/treeitem.prg, source/classes/ttvitem.prg

TTreeItem implements a linked-list tree node for custom tree widgets. Each node stores a prompt, level, bitmaps, action codeblock, and cargo data, and maintains prev/next/child pointers via an associated TTree object. TTVItem wraps a native Win32 TreeView item (HTREEITEM) for use with the standard Windows tree control, providing insert, expand, edit, check-box and persistence operations.

TTreeItem — Linked-List Tree Node

Key DATA Members

DATATypeDescription
cPromptCharacterNode display text
oTreeObjectReference to the child TTree object (children), nil if leaf
lOpenedLogicalNode is expanded (children visible)
nLevelNumericIndentation level (0 = root)
hBmpOpenHandleBitmap handle for expanded state
hBmpCloseHandleBitmap handle for collapsed state
bActionCodeblockCode block executed when the node is activated
CargoAnyUser-defined data attached to the node

Methods

MethodDescription
New( cPrompt, nLevel, hBmpOpen, hBmpClose, bAction, uCargo, uValue )Create a new tree node at the specified level
Open()Expand the node to show children
Close()Collapse the node to hide children
Toggle()Toggle between open and closed state
Add( cPrompt )Add a sibling node after this one (linked-list insert)
AddChild( cPrompt, lFirst )Add a child node (creates or uses existing TTree)
Delete( oRoot )Remove this node from the list
MoveUp( oRoot )Move the node up in the list
MoveDown( oRoot )Move the node down in the list
Sort( oRoot, lAsc, lRecurs )Sort siblings by prompt, optionally recursive
Promote()Decrease indentation level by one
Demote()Increase indentation level by one
Parent( nParent )Find the ancestor at a given level
ByIndex[ n ]Access child/sub-node by index (operator [] overload)

TTVItem — TreeView Item Wrapper

Key DATA Members

DATATypeDescription
oParentObjectParent TTVItem (nil for root items)
hItemHandleHTREEITEM handle identifying the native tree item
aItemsArrayChild TTVItem objects
nImageNumericZero-based image index in the tree image list
CargoAnyUser-defined data
lBoldLogicalItem text is bold

Methods

MethodDescription
New( hItem, oTree, Cargo, cPrompt, nImage, oParent )Wrap an existing native tree item handle
Add( cPrompt, nImage, Cargo )Insert a child item into the native tree
Expand()Expand the tree item (TVE_EXPAND)
Collapse()Collapse the tree item (TVE_COLLAPSE)
Toggle()Toggle expand/collapse (TVE_TOGGLE)
Edit()Start in-place label editing (TVM_EDITLABEL)
SetCheck( lOnOff )Set or clear the check-box state
GetCheck()Get the current check-box state
GetText()Get the item display text
SetText( cText )Set the item display text
Bold()Make the item text bold
Normal()Remove bold formatting
Save()Serialize the item (prompt, image, cargo) to a string
Load( cInfo )Deserialize and restore the item from a saved string
MakeVisible()Scroll the tree to ensure this item is visible

Example: Tree Construction

#include "FiveWin.ch"

function Main()

   local oTreeView, oRoot, oItem1, oItem2

   // TTVItem example with native TreeView
   DEFINE WINDOW oWnd TITLE "Tree Demo" SIZE 400, 300

   oTreeView = TTreeView():New( 10, 10, 380, 280, oWnd )

   oRoot = TTVItem():New( TVInsertItem( oTreeView:hWnd, "Root", 0, 0 ),;
                          oTreeView, NIL, "Root", 0, NIL )

   oItem1 = oRoot:Add( "Child 1", 1, "data1" )
   oItem2 = oRoot:Add( "Child 2", 1, "data2" )

   oItem1:Add( "Grandchild", 2, "deep" )

   oRoot:Expand()

   ACTIVATE WINDOW oWnd CENTERED

return nil

Notes

Ver También