Visual Trees (HTreeEngine unit)

ThVisualTree and ThBOM_VisualTree controls, options, and events

ThVisualTree

Visual control for a separate ThTreeNode hierarchy. Refresh builds visible rows from non-hidden nodes and expanded branches; an empty-caption root is omitted from rows.
The control supports keyboard and mouse navigation, node execution, and optional checkbox selection. Use its published events to respond to those actions.
ThVisualTree = Class(TSYE_Control);

Create

Creates a default non-BOM Base node and owns it. The control also frees its current Base when destroyed. ThBOM_VisualTree instead adds BOM support to its default Base.
Constructor ThVisualTree.Create(AOwner: TComponent);

Assign_Base

Replaces Base, clears old visible rows, optionally frees the previous Base, and refreshes. Passing nil disconnects the tree. The control will free its current Base on destruction; this method does not set the new root's internal visual-tree pointer, so BOM callbacks on a separately created root are not connected by this call alone.
Procedure ThVisualTree.Assign_Base(NewBase: ThTreeNode; FreePrevBase: Boolean);

Calc_Tree_Height

Returns the total pixel height of up to Visible_Items_Count currently visible rows. Returns 0 for an empty tree or zero count.
Use the returned height when sizing a parent container to fit a chosen number of visible rows.
Function ThVisualTree.Calc_Tree_Height(Visible_Items_Count: Word): Cardinal;

Refresh

Rebuilds rows from Base and repaints. If GotoNode belongs to Base, expands its ancestors and moves the cursor to it. Refresh forces Base.Hidden=False and Base.Expanded=True.
Procedure ThVisualTree.Refresh(GotoNode: ThTreeNode = NIL);
Tree.Assign_Base(Root, False);
Root.Add_Child_Node('New item', '');
Tree.Refresh;

View_Json_Tree

Clears Base, copies a ThJsonNode tree as display captions, and refreshes. If Copy_Name_To_STag is True, stores source Name in rt_STag[1] and Value in rt_STag[2]. Requires an assigned Base.
Procedure ThVisualTree.View_Json_Tree(Json_Base: ThJsonNode; Copy_Name_To_STag: Boolean = False);

Visual properties

Control state and display options.
DeclarationMeaning
Property ThVisualTree.Base: ThTreeNode;
Assigned root; read-only.
Property ThVisualTree.CursorNode: ThTreeNode;
Focused visible node, or Base when no visible cursor exists.
Property ThVisualTree.Visible_Nodes_Count: Cardinal;
Number of current visible rows.
Property ThVisualTree.TabOrder;
Inherited tab order.
Property ThVisualTree.Always_Expanded: Boolean;
Displays all branches regardless of individual Expanded flags; default False.
Property ThVisualTree.Execute_Node_Single_Click: Boolean;
Also executes a node on a single click; default False.
Property ThVisualTree.Usage_Notes: String;
Published text field; no tree processing is attached to it.
Property ThVisualTree.Minimal_Row_Height: Word;
Minimum row height; default 26.

ThVisualTreeCheckbox

Checkbox modes. he_No_Selection disables UI selection; he_Parent_Select_Children propagates changes down and clears parent selection when a child is deselected; he_Stand_Alone changes only the clicked node.
ThVisualTreeCheckbox = (he_No_Selection, he_Parent_Select_Children, he_Stand_Alone);

Check_Boxes

Selects the checkbox mode. Default is he_No_Selection. Programmatic edits of ThTreeNode.Selected remain possible.
Property ThVisualTree.Check_Boxes: ThVisualTreeCheckbox;

ThVisualTreeEvent

Event handler signature for node-specific visual events.
ThVisualTreeEvent = Procedure (Node: ThTreeNode) OF Object;

Visual events

Published event properties of ThVisualTree.
With an Execute_Node handler assigned, pressing Enter or double-clicking a row calls it. Execute_Node_Single_Click also calls it on a single click when True.
DeclarationMeaning
Property ThVisualTree.Execute_Node: ThVisualTreeEvent;
Called when a node is executed.
Property ThVisualTree.Cursor_Moved: ThVisualTreeEvent;
Called when the cursor moves.
Property ThVisualTree.Selection_Changed: TNotifyEvent;
Called after a user checkbox change; Sender is the visual tree.
Property ThVisualTree.RightClick_Event: TNotifyEvent;
Called for a right click.
Property ThVisualTree.Node_Freed_Alert: ThVisualTreeEvent;
Called when a node attached to the visual tree is being freed.
Property ThVisualTree.Lost_Focus: TNotifyEvent;
Called when focus is lost.
Property ThVisualTree.Sort_Compare: ThTreeNode_SortEvent;
Fallback comparison callback for Sort_Childs(he_ExtEvent) when no explicit callback is passed.
Property ThVisualTree.OnKeyDown;
Inherited keyboard event.
Property ThVisualTree.OnKeyPress;
Inherited character event.

ThBOM_VisualTree

Visual tree with published callbacks for BOM actions. It inherits rendering and navigation from ThVisualTree; application handlers supply BOM-specific behavior.
ThBOM_VisualTree = Class(ThVisualTree);

BOM constructor

Initializes callback properties and gives the default Base a BOM object. The root BOM starts with Quantity_Per_Parent and TotalQuantity set to 1.
Constructor ThBOM_VisualTree.Create(AOwner: TComponent);

ThBOMevent_Add_Child

Called after Add_Child creates a node.
ThBOMevent_Add_Child = Procedure (NewNode: ThTreeNode; Catalogic_Number: String; Quantity_Per_Parent, Width, Height, Depth: Double) OF Object;

ThBOMevent_Run_Phantom

Builds a phantom branch when requested.
ThBOMevent_Run_Phantom = Procedure (NewNode: ThTreeNode; Phantom_Cat_Num: String) OF Object;

ThBOMevent_Init_Field_Value

May replace a newly added dynamic field value.
ThBOMevent_Init_Field_Value = Procedure (Node: ThTreeNode; PropName: RawByteString; Kind: ThtpKindType; VAR Value: Variant) OF Object;

ThBOMevent_Get_ValuesList

Supplies selectable values; ID -100 is used for prototype labels.
ThBOMevent_Get_ValuesList = Procedure (SelectFromMenuID: Integer; VAR ValuesList: String) OF Object;

ThBOMevent_Add_ProtoChild

Populates a prototype child.
ThBOMevent_Add_ProtoChild = Procedure (NewNode: ThTreeNode; ProtoTypeIndex: Word; Quantity_Per_Parent, Width, Height, Depth: Double) OF Object;

ThBOMevent_Get_Head_Value

Supplies a value for a missing dynamic field.
ThBOMevent_Get_Head_Value = Procedure (Node: ThTreeNode; PropName: RawByteString; VAR Value: Variant) OF Object;

ThBOMevent_String_Command

Executes an application-defined string command.
ThBOMevent_String_Command = Procedure (Node: ThTreeNode; Command, PropName, AssignTo: RawByteString) OF Object;

BOM events

Published callback properties. Assign handlers before calling BOM methods that require them.
DeclarationMeaning
Property ThBOM_VisualTree.BOM_Add_Child: ThBOMevent_Add_Child;
Used by ThBillOfMaterial.Add_Child.
Property ThBOM_VisualTree.BOM_Run_Phantom: ThBOMevent_Run_Phantom;
Used by Run_Phantom.
Property ThBOM_VisualTree.BOM_Init_Field_Value: ThBOMevent_Init_Field_Value;
Used after AddField.
Property ThBOM_VisualTree.BOM_Get_ValuesList: ThBOMevent_Get_ValuesList;
Used for prototype labels.
Property ThBOM_VisualTree.BOM_Add_ProtoChild: ThBOMevent_Add_ProtoChild;
Used by Add_Child_From_ProtoType.
Property ThBOM_VisualTree.BOM_Get_Value_From_Header: ThBOMevent_Get_Head_Value;
Used when Field[Name] does not exist locally.
Property ThBOM_VisualTree.BOM_Refresh_Node: ThVisualTreeEvent;
Used by ThBillOfMaterial.Refresh.
Property ThBOM_VisualTree.BOM_String_Command: ThBOMevent_String_Command;
Used by ThBillOfMaterial.String_Command.