The tree view control is a dialog that displays a hierarchical list of items, such as the headings in a document, the entries in an index, or the files and directories on a disk. Each item consists of a label and an optional image bitmap, and can have a list of subitems associated with it. By clicking on an item, the user can expand and collapse the associated list of subitems.
Refer to OODTREE.REX in the OODIALOG\SAMPLES directory for an example.
The TreeControl class requires the class definition file oodwin32.cls:
::requires "oodwin32.cls"
Instances of the TreeControl class implement the methods listed in the TreeControl Instance Methods table.
Table 28-1. TreeControl Instance Methods
Method... | ...on page |
---|---|
Add | Add |
Child | Child |
Collapse | Collapse |
CollapseAndReset | CollapseAndReset |
Delete | Delete |
DeleteAll | DeleteAll |
DropHighlight | DropHighlight |
DropHighlighted | DropHighlighted |
Edit | Edit |
EndEdit | EndEdit |
EnsureVisible | EnsureVisible |
Expand | Expand |
FirstVisible | FirstVisible |
HitTest | HitTest |
Indent | Indent |
Indent= | Indent= |
Insert | Insert |
IsAncestor | IsAncestor |
ItemInfo | ItemInfo |
Items | Items |
MakeFirstVisible | MakeFirstVisible |
Modify | Modify |
MoveItem | MoveItem |
Next | Next |
NextVisible | NextVisible |
Parent | Parent |
Previous | Previous |
PreviousVisible | PreviousVisible |
RemoveImages | RemoveImages |
RestoreEditClass | RestoreEditClass |
Root | Root |
Select | Select |
Selected | Selected |
SetImages | SetImages |
SortChildren | SortChildren |
SubclassEdit | SubclassEdit |
Toggle | Toggle |
VisibleItems | VisibleItems |
The following sections describe the individual methods of the TreeControl class.
+-"LAST"--+ +-""---+ +-0-----+ >>-aTreeControl~Insert(--parent--,--+-after---+--,--+------+--,--+-------+--,--> +-"FIRST"-+ +-text-+ +-image-+ +-"SORT"--+ +-"0"-+ >--+----------+--,--+------------------------+--,--+-----+--)-->< +-selImage-+ | +--------------+ | +-"1"-+ | V | | +-"----+-EXPANDED-+-+--"-+ +-BOLD-----+
The Insert method inserts a new item in a tree view control.
The arguments are:
The handle to the parent item. If you specify "ROOT", the item is inserted at the root of the tree view control.
The handle to the item after which the new item is to be inserted or one of the following values:
Inserts the item at the beginning of the list.
Inserts the item at the end of the list. This is the default.
Inserts the item into the list in alphabetical order.
The text for the item. If you omit this argument, "" is assumed.
The index of the icon image in the tree view control's bitmap file to be used when the item is in the non-selected state. If you omit this argument, the icon with index 0 is used.
The index of the icon image in the tree view control's bitmap file to be used when the item is in the selected state. If you omit this argument, the icon specified for image is used.
Specifies the appearance and functionality of the item. It can be a combination of the following values, separated by a blank:
The item is currently expanded with all child items visible. This only applies to parent items.
The item is shown in bold.
If you omit this argument, the item is inserted in collapsed and normal form.
Indicates whether the item has child items associated with it:
The item has no child items, which is the default.
The item has one or more child items.
You can use this argument to show an item that does not have any child items, with an expand button. This allows you to save memory usage by dynamically loading and displaying the child items only when the user expands the item.
The handle to the new item, or 0 for all other cases.
The following example inserts child items when a specific root item is expanded. The text strings for the items are loaded from a file.
::method OnExpanding_IDC_TREE use arg tree, item itemFile = "root6.inp" curTree = self~GetTreeControl("IDC_TREE") itemInfo. = curTree~ItemInfo(item) if itemInfo.!TEXT = "Root 6" & \itemInfo.!STATE~POS("EXPANDED") then do do while lines(itemFile) line = linein(itemFile) command = "curTree~Insert(item, ,"||line||")" interpret command end curTree~Expand(item) end
+-------+ V | +-""---+ +-0-----+ >>-aTreeControl~Add(----+---+-+--,--+------+--,--+-------+--,---> +-,-+ +-text-+ +-image-+ +-"0"-+ >--+----------+--,--+------------------------+--,--+-----+--)-->< +-selImage-+ | +--------------+ | +-"1"-+ | V | | +-"----+-EXPANDED-+-+--"-+ +-BOLD-----+
The Add method adds a new item to a tree view control.
The arguments are:
The number of commas specifies at which parent the item is to be inserted. If you omit this argument, the item is inserted as a root item. Each additional comma inserts the item one level deeper than the item inserted previously. See the example in the following.
The text for the item. If you omit this argument, "" is assumed.
The index of the icon image in the tree view control's bitmap file to be used when the item is in the non-selected state. If you omit this argument, the icon with index 0 is used.
The index of the icon image in the tree view control's bitmap file to be used when the item is in the selected state. If you omit this argument, the icon specified for image is used.
Specifies the appearance and functionality of the item. It can be a combination of the following values, separated by a blank:
The item is currently expanded with all child items visible. This only applies to parent items.
The item is shown in bold.
If you omit this argument, the item is inserted in collapsed and normal form.
Indicates whether the item has child items associated with it:
The item has no child items, which is the default.
The item has one or more child items.
You can use this argument to show an item that does not have any child items, with an expand button. This allows you to save memory usage by dynamically loading and displaying the child items only when the user expands the item.
The handle to the new item, or 0 for all other cases.
To get the following tree view:
Peter
Mike
George
Monique
John
Chris
Maud
Ringo
Paul
Dave
Sam
Jeff
Mary
Helen
Michelle
Diana
your example must look as follows:
::method InitDialog InitDlgRet = self~InitDialog:super curTree = self~GetTreeControl("IDC_TREE") if curTree \= .Nil then do curTree~Add("Peter", , ,"BOLD EXPANDED") curTree~Add(,"Mike", , ,"EXPANDED") curTree~Add(, ,"George") curTree~Add(, ,"Monique") curTree~Add(, , ,"John") curTree~Add(, ,"Chris") curTree~Add(,"Maud") curTree~Add(,"Ringo") curTree~Add("Paul", , ,"BOLD EXPANDED") curTree~Add(,"Dave") curTree~Add(,"Sam") curTree~Add(,"Jeff") curTree~Add("Mary", , ,"BOLD EXPANDED") curTree~Add(,"Helen") curTree~Add(,"Michelle") curTree~Add(,"Diana") end
+-""---+ +-0-----+ >>-aTreeControl~Modify(--hItem--,--+------+--,--+-------+--,--+----------+--,--> +-text-+ +-image-+ +-selImage-+ +-"0"-+ >--+-------------------------------+--,--+-----+--)------------>< | +---------------------+ | +-"1"-+ | V | | +-"----+-BOLD------------+-+--"-+ +-NOTBOLD---------+ +-DROP------------+ +-NOTDROP---------+ +-SELECTED--------+ +-NOTSELECTED-----+ +-CUT-------------+ +-NOTCUT----------+ +-EXPANDEDONCE----+ +-NOTEXPANDEDONCE-+ +-EXPANDED--------+ +-NOTEXPANDED-----+
The Modify method sets some or all attributes of an item of a tree view control.
The arguments are:
The handle to the item to be modified.
The text for the item. If you omit this argument, "" is assumed.
The index of the icon image in the tree view control's bitmap file to be used when the item is in the non-selected state. If you omit this argument, the icon with index 0 is used.
The index of the icon image in the tree view control's bitmap file to be used when the item is in the selected state. If you omit this argument, the icon specified for image is used.
Specifies the appearance and functionality of the item. It can be one or more of the following values, separated by blanks:
The item is shown in bold.
The item is not bold.
The item is selected as a drag-and-drop target.
The item is not selected as a drag-and-drop target.
The item is selected. Its appearance depends on whether it has the focus and whether the system colors are used for the selection.
The item is not selected.
The item is selected as part of a cut-and-paste operation.
The item is not selected as part of a cut-and-paste operation.
The item's list of child items has been expanded at least once.
The item's list of child items has not been expanded at least once.
The item's list is currently expanded with all child items visible. This only applies to parent items.
The item's list is currently not expanded.
Indicates whether the item has child items associated with it:
The item has no child items, which is the default.
The item has one or more child items.
You can use this argument to show an item that does not have any child items, with an expand button. This allows you to save memory usage by dynamically loading and displaying the child items only when the user expands the item.
The item has been modified.
For all other cases.
The following example changes the text of the item to bold when it is selected:
::method OnSelChanging_IDC_TREE curTree = self~GetTreeControl("IDC_TREE") curTree~Modify(curTree~selected, , , ,"BOLD")
>>-aTreeControl~ItemInfo(--hItem--)----------------------------><
The ItemInfo method retrieves some or all attributes of an item of a tree view control.
The only argument is:
The handle to the item of which attributes are to be retrieved.
A compound variable that stores the attributes of the item, or -1 in all other cases. The compound variable can be:
The text of the item.
The item has children.
The item has no children.
The index of the icon image in the tree view control's bitmap file used when the item is in the non-selected state.
The index of the icon image in the tree view control's bitmap file used when the item is in the selected state.
An empty string or one or more of the following strings, separated by blanks:
The item's list is currently expanded with all child items visible. This only applies to parent items.
The item is in bold.
The item is selected.
The item's list has been expanded at least once. This only applies to parent items.
The item is selected as a drag-and-drop target.
The following example displays the attributes of the selected item:
::method Info curTree = self~GetTreeControl("IDC_TREE") itemInfo. = curTree~ItemInfo(curTree~Selected) say itemInfo.!TEXT say itemInfo.!CHILDREN say itemInfo.!IMAGE say itemInfo.!STATE
>>-aTreeControl~Items------------------------------------------><
The Items method retrieves the number of items in a tree view control.
The number of items.
The following example counts all items in a tree view control:
::method Count curTree = self~GetTreeControl("IDC_TREE") say curTree~Items
>>-aTreeControl~VisibleItems-----------------------------------><
The VisibleItems method obtains the number of items that can be fully visible in a tree view control. This number can be greater than the number of items in the control. The control calculates this value by dividing the height of the client window by the height of an item.
The number of items that can be fully visible. For example, if you can see all of 19 items and part of another item, the return value is 19, not 20.
The following example returns the number of items that can be fully visible:
::method Visible curTree = self~GetTreeControl("IDC_TREE") say curTree~VisibleItems
>>-aTreeControl~Root-------------------------------------------><
The Root method retrieves the first or topmost item of the tree view control.
The handle to the first item, or 0 in all other cases.
The following example displays the name of the root item:
::method RootName curTree = self~GetTreeControl("IDC_TREE") itemInfo. = curTree~ItemInfo(curTree~Root) say ItemInfo.!Text
>>-aTreeControl~Parent(--hItem--)------------------------------><
The Parent method retrieves the parent of the specified item.
The only argument is:
The handle to the item for which the parent is to be retrieved.
The handle to the parent item, or -1 if hItem is not specified or is 0, or 0 in all other cases.
The following example displays the name of the selected item's parent:
::method Parent curTree = self~GetTreeControl("IDC_TREE") itemInfo. = curTree~ItemInfo(curTree~Parent(curTree~Selected)) say ItemInfo.!Text
>>-aTreeControl~Child(--hItem--)-------------------------------><
The Child method retrieves the first child item of hItem.
The only argument is:
The handle to the item of which the first child is to be retrieved.
The handle to the first child item, or -1 if you omitted hItem, or 0 in all other cases.
The following example displays the name of parent of the selected item:
::method Child curTree = self~GetTreeControl("IDC_TREE") itemInfo. = curTree~ItemInfo(curTree~Child(curTree~Selected)) say ItemInfo.!Text
>>-aTreeControl~Selected---------------------------------------><
The Selected method retrieves the currently selected item.
The handle to the currently selected item, or 0 in all other cases.
The following example displays the name of the selected item:
::method SelectedName curTree = self~GetTreeControl("IDC_TREE") itemInfo. = curTree~ItemInfo(curTree~Selected) say ItemInfo.!Text
>>-aTreeControl~DropHighlighted--------------------------------><
The DropHighlighted method retrieves the item that is the target of a drag-and-drop operation.
The handle to the item, or 0 in all other cases.
>>-aTreeControl~FirstVisible-----------------------------------><
The FirstVisible method retrieves the first visible item in the client window of a tree view control.
The handle to the first visible item, or 0 in all other cases.
The following example displays the name of the first visible item:
::method FirstVisibleName curTree = self~GetTreeControl("IDC_TREE") itemInfo. = curTree~ItemInfo(curTree~FirstVisible) say ItemInfo.!Text
>>-aTreeControl~Next(--hItem--)--------------------------------><
The Next method retrieves the sibling item next to hItem.
The only argument is:
The handle to the item next to the sibling item to be retrieved.
The handle to the next sibling item, or -1 if you omitted hItem, or 0 in all other cases.
The following example displays the name of the selected item and its siblings:
::method SiblingNames curTree = self~GetTreeControl("IDC_TREE") nextItem = curTree~Selected do while nextItem \= 0 itemInfo. = curTree~ItemInfo(nextItem) say ItemInfo.!Text nextItem = curTree~Next(nextItem) end
>>-aTreeControl~NextVisible(--hItem--)-------------------------><
The NextVisible method retrieves the visible item following hItem.
The only argument is:
The handle to the item that precedes the visible item to be retrieved. hItem must also be visible.
The handle to the next visible item, or -1 if you omitted hItem, or 0 in all other cases.
>>-aTreeControl~Previous(--hItem--)----------------------------><
The Previous method retrieves the sibling item preceding hItem.
The only argument is:
The handle to the item that follows the sibling item to be retrieved.
The handle to the previous sibling item, or -1 if hItem is not specified or is 0, or 0 in all other cases.
>>-aTreeControl~PreviousVisible(--hItem--)---------------------><
The PreviousVisible method retrieves the visible item preceding hItem.
The only argument is:
The handle to the item that follows the visible child item to be retrieved. hItem must also be visible.
The handle to the previous visible child item, or -1 if hItem is not specified or is 0, or 0 in all other cases.
>>-aTreeControl~Delete(--hItem--)------------------------------><
The Delete method removes an item from a tree view control.
The only argument is:
The handle to the item to be deleted.
The item was deleted.
An error occurred.
hItem is 0 or is not a valid value.
The following example deletes the selected item and all its children, if any:
::method IDC_PB_DELETE curTree = self~GetTreeControl("IDC_TREE") curTree~Delete(curTree~Selected)
>>-aTreeControl~DeleteAll--------------------------------------><
The DeleteAll method removes all items from a tree view control.
The items were removed.
For all other cases.
>>-aTreeControl~Collapse(--hItem--)----------------------------><
The Collapse method collapses the list of child items associated with the specified parent item.
The only argument is:
The handle to the parent item to collapse.
The list of child items has collapsed.
hItem is not specified or is 0.
For all other cases.
The following example collapses the selected item:
::method CollapseSelected curTree = self~GetTreeControl("IDC_TREE") curTree~Collapse(curTree~Selected)
>>-aTreeControl~CollapseAndReset(--hItem--)--------------------><
The CollapseAndReset method collapses the list of child items associated with the specified parent item and removes the child items.
The only argument is:
The handle to the parent item to collapse.
The list of child items has collapsed and the child items have been removed.
hItem is not specified or is 0.
For all other cases.
The following example collapses the selected item and removes all its child items:
::method CollapseSelectedAndReset curTree = self~GetTreeControl("IDC_TREE") curTree~CollapseAndReset(curTree~Selected)
>>-aTreeControl~Expand(--hItem--)------------------------------><
The Expand method expands the list of child items associated with the specified parent item.
The only argument is:
The handle to the parent item to be expanded.
The parent item was expanded.
hItem is not specified or is 0.
For all other cases.
The following example expands the selected item:
::method ExpandSelected curTree = self~GetTreeControl("IDC_TREE") curTree~Expand(curTree~Selected)
>>-aTreeControl~Toggle(--hItem--)------------------------------><
The Toggle method collapses the list of the specified item if it was expanded, or expands it if it was collapsed.
The only argument is:
The handle to the item to be expanded or collapsed.
The item was expanded or collapsed.
hItem is not specified or is 0.
For all other cases.
The following example toggles between expanding and collapsing a selected item:
::method ToggleSelected curTree = self~GetTreeControl("IDC_TREE") curTree~Toggle(curTree~Selected)
>>-aTreeControl~EnsureVisible(--hItem--)-----------------------><
The EnsureVisible method ensures that a tree view item is visible, expanding the parent item or scrolling the tree view control, if necessary.
The only argument is:
The handle to the item to be visible.
The items in the tree view control were scrolled to ensure that the specified item is visible.
hItem is not specified or is 0.
For all other cases.
>>-aTreeControl~Indent-----------------------------------------><
The Indent method retrieves the amount, in pixels, by which the child items are indented relative to their parent item.
The amount indented, in pixels.
>>-aTreeControl~Indent=--indent--------------------------------><
The Indent= method sets the width of indentation for a tree view control and redraws the control to reflect the new width.
The only argument is:
The width of the indentation, in pixels. If you specify a width that is smaller than the system-defined minimum, it is set to the system-defined minimum.
-1 if indent is 0.
>>-aTreeControl~Edit(--hItem--)--------------------------------><
The Edit method starts editing the text of the specified item by replacing the text with a single-line edit control containing this text. It implicitly selects and focuses the specified item.
The only argument is:
The handle to the item to be edited.
The handle to the edit control used to edit the item text, or -1 if hItem is not specified or is 0, or 0 in all other cases.
>>-aTreeControl~EndEdit(--+--------+--)------------------------>< +-cancel-+
The EndEdit method ends the editing of the item label of the tree view.
The only argument is:
Indicates whether editing is canceled without being saved to the label. If you specify "1" or "YES", editing is canceled. Otherwise, the changes are saved to the label, which is the default.
Editing has ended successfully.
For all other cases.
>>-aTreeControl~SubclassEdit-----------------------------------><
The SubclassEdit method is used by the DefTreeEditHandler to correct the problem occurring when Esc or the Enter key is pressed in an active edit item.
>>-aTreeControl~RestoreEditClass-------------------------------><
The RestoreEditClass method is used by the DefTreeEditHandler to correct the problem occurring when Esc or the Enter key is pressed in an active edit item.
>>-aTreeControl~Select(--hItem--)------------------------------><
The Select method selects a specific item.
The only argument is:
The handle to the item to be selected.
The item was selected.
hItem was not specified or is 0.
For all other cases.
>>-aTreeControl~MakeFirstVisible(--hItem--)--------------------><
The MakeFirstVisible method ensures that hItem is visible and displays it at the top of the control's dialog, if possible. If the specified item is near the end of the control's hierarchy of items, it might not become the first visible item depending on how many items fit in the dialog.
The only argument is:
The handle to the item to be visible first.
The item is visible first.
hItem was not specified or is 0.
For all other cases.
>>-aTreeControl~DropHighlight(--hItem--)-----------------------><
The DropHighlight method redraws hItem in the style used to indicate the target of a drag-and-drop operation.
The only argument is:
The handle of the item to be redrawn.
The item was redrawn.
hItem was not specified or is 0.
For all other cases.
>>-aTreeControl~SortChildren(--hItem--)------------------------><
The SortChildren method sorts the child items of the specified parent item in a tree view control.
The only argument is:
The handle to the parent item the child items of which are to be sorted.
The child items were sorted.
hItem was not specified or is 0.
For all other cases.
+-0-----+ +-0------+ >>-aTreeControl~SetImages(--hItem--,--+-------+--,--+--------+--)->< +-width-+ +-height-+
The SetImages method sets the image list for a tree view control and redraws the control using the new images.
The arguments are:
The name of, or handle to, a bitmap file that is already loaded using the LoadBitmap method (see LoadBitmap).
The width of each image, in pixels. If you specify 0 or omit this argument, the height of the image in the image file is used as width.
The height of each image, in pixels. If you specify 0 or omit this argument, the height of the image in the image file is used.
The handle to the previous image list, or -1 if you did not specify bitmap, or 0 in all other cases.
The following example sets the image list during dialog initialization:
::method InitDialog expose bmpFile InitDlgRet = self~InitDialog:super curTree = self~GetTreeControl("IDC_TREE") if curTree \= .Nil then do curTree~SetImages(bmpFile,16,12) end return InitDlgRet
>>-aTreeControl~RemoveImages-----------------------------------><
The RemoveImages method destroys the image list of the tree view.
The image list was destroyed.
For all other cases.
>>-aTreeControl~HitTest(--x--,--y--)---------------------------><
The HitTest method determines the location of the specified point relative to the client area of a tree view control.
The arguments are:
The x-coordinate of the point.
The y-coordinate of the point.
0 if no item occupies the point, or one or more of the following strings if an item occupies the specified point:
The handle to the item that occupies the specified point.
Above the client area.
Below the client area.
In the client area but below the last item.
On the bitmap or label associated with an item.
On the button associated with an item.
On the icon associated with an item.
In the indentation associated with an item.
On the label (string) associated with an item.
In the area to the right of an item.
On the state icon for a tree view item that is in a user-defined state.
To the left of the client area.
To the right of the client area.
>>-aTreeControl~MoveItem(--hItem--,--hNewParent--,--redraw--+---------------+--)->< +-,--"NODELETE"-+ +-,--"SIBLINGS"-+
The MoveItem method moves an item to a new location.
The arguments are:
The handle to the item to be moved.
The handle to the new parent to which the item is to be moved.
The tree view control is updated.
One of the following options:
The item is copied to another location.
Siblings are moved together with the item.
The handle to the new parent, or 0 in all other cases.
>>-aTreeControl~IsAncestor(--hParent--,--hItem--)--------------><
The IsAncestor method checks if an item is an ancestor of another item.
The arguments are:
The ancestor.
The item to be checked.
1 if hParent is an ancestor of hItem.