KwikPeg Manuals
Home
PegTreeView
Examples
Examples
Index
Index


Members
Styles
Signals
Overview Derived from class PegWindow

The PegTreeView class provides a container window for a collection of objects to be displayed as a tree structured list. The container is populated with PegTreeNode objects.

Windows of the PegTreeView class have vertical and horizontal scroll bars automatically added to provide access to all nodes when there are more nodes present than can be displayed in the PegTreeView client area.

A PegTreeView object is a container object. Your application will interact directly with the PegTreeNode children of the PegTreeView container. Any number of PegTreeNode objects can be added to the tree.

The PegTreeView class supports navigation through the tree and selection of nodes using the screen pointer or keyboard.

The first (topmost) node in the tree is always present. It is created automatically by the PegTreeView constructor. Other nodes are added to this top node by your application to create the tree structured list of nodes.



 See Also

PegTreeNode



 Styles

The PegTreeView class supports the following style flags:

FF_NONE No frame.
FF_THIN Thin frame.
FF_THICK Thick 3D frame.
FF_RAISED Raised 3D frame.
FF_RECESSED Recessed 3D frame.


 Signals

The PegTreeView class generates the following signals:

PSF_NODE_SELECT Sent by PegTreeView when a TreeNode is selected.
PSF_NODE_DELETE Sent by selected TreeNode when the Delete key is detected.
PSF_NODE_OPEN Sent by selected TreeNode if opened by user.
PSF_NODE_CLOSE Sent by selected TreeNode if closed by user.
PSF_NODE_RCLICK Sent by selected TreeNode if right clicked.
 
In each case, the signal message contains the following information:
 
Message.pData  Pointer to the selected PegTreeNode object.
Message.iData  Object ID of the PegTreeView object.
Message.pSource  Pointer to the PegTreeView object.
 

Top of page


 Members

Constructors:

PegTreeView(const PegRect &Rect,
  WORD wStyle,
  const PEGCHAR *Text,
  PegBitmap *pMap = NULL)

This constructor creates a PegTreeView object at a specific location within a rectangle specified by parameter Rect. The window frame style must be defined. The text string for the topmost node of the tree must be provided. An optional bitmap to be associated with the topmost node may also be defined.

 

Public Functions:

void DestroyNode(PegTreeNode *Who)

This function removes the PegTreeNode object referenced by Who from the tree and deletes that object. If the indicated node has children, they are also removed and deleted.

The FindNode() function is often used in conjunction with DestroyNode() to remove a specific node as follows:

    DestroyNode(FindNode(1, "Temp"));
void Draw(void)

The PegTreeView class overrides the Draw() function to display the tree view connecting lines and node anchors.

void DrawNode(PegTreeNode *pStart,
  PegPoint Put, SIGNED iMaxMapWidth)

This function draws the node referenced by pStart. The node is positioned at the screen point indicated by parameter Put.

Parameter iMaxMapWidth defines the maximum width (in pixels) which the node's bitmap image can occupy. The node bitmap, if any, will be centered within this width.

PegTreeNode *FindNode(SIGNED iLevel,
  PEGCHAR *Text)

This function returns a pointer to the PegTreeNode object at indentation level iLevel which matches text string Text. If multiple nodes at that level match the text string, the returned pointer will reference the first (topmost) matching node.

Node indent levels start at 0. The only level 0 node is the top tree node. The first level of nodes under the top node are level 1 nodes. The next level of indented nodes are level 2 nodes, etc.

void GetHScrollInfo(PegScrollInfo *Put)

The PegTreeView class overrides the GetHScrollInfo() function to calculate the tree width based on the sum of the individual node widths and positions the horizontal scroll bar accordingly.

SIGNED GetIndent(void) {return miIndent;}

This function returns the current indent offset, in pixels. This function is used by internal drawing routines.

PegTreeNode *GetSelected(void)
  {return mpSelected;}

This function returns a pointer to the currently selected node, a PegTreeNode object.

void GetVScrollInfo(PegScrollInfo *Put)

The PegTreeView class overrides the GetVScrollInfo() function to calculate the tree height based on the sum of the individual node heights and positions the vertical scroll bar accordingly.

SIGNED Message(const PegMessage &Mesg)

The PegTreeView class overrides the Message() function to catch screen pointer and keyboard messages in order to navigate the tree and detect the selection of tree nodes.

PegTreeNode *RemoveNode(PegTreeNode *Who)

This function removes the PegTreeNode object referenced by Who from the tree. The object is NOT deleted. If the indicated node has children, they are also removed from the tree but remain attached to the node.

The FindNode() function is often used in conjunction with RemoveNode() to remove a specified node as follows:

    RemoveNode(FindNode(1, "Temp"));
void Reset(const PEGCHAR *Top)

This function resets the entire tree by removing and deleting all of the tree's nodes. The text for the tree's permanent topmost node is then set to the text string referenced by Top.

void Select(PegTreeNode *Who,
  BOOL bRedraw = TRUE)

This function marks the PegTreeNode object referenced by Who as the selected node. If parameter bRedraw is TRUE, the tree is redrawn to move the node selection indication to the newly selected node.

void SetIndent(SIGNED iVal)
  {miIndent = iVal;}

This function sets the indent offset (in pixels) at which each generation of child nodes is drawn to the value specified by iVal. This function is used by internal drawing routines.

virtual void ToggleBranch(PegTreeNode *Who)

This function opens the branch of the tree if the branch is closed or closes the branch if it is open.

PegTreeNode *TopNode(void)
  {return mpTopNode;}

This function returns a pointer to the topmost node in the tree. Using this PegTreeNode pointer, your application can traverse the entire tree.


Top of page


 Examples

The following example illustrates a PegTreeView window populated with PegTreeNode objects. The PegTreeView window is displayed in the client area of a PegNotebook page.



The following code fragment creates a PegTreeView window and populates the window with PegTreeNode objects. The top level node is labeled "Hockey Teams". Two level 1 nodes are created labeled "East Teams" and "West Teams". To each of these nodes are added several hockey team names.

extern PegBitmap gbTopNodeBitmap;
extern PegBitmap gbTeamBitmap;
extern PegBitmap gbCategoryBitmap;

void MyWindow::CreateTreeView(void)
{
    PegTreeView *pTree;
    pTree = new PegTreeView(mClient, FF_RECESSED,
        "Hockey Teams", &gbTopNodeBitmap);

    pTree->Id(IDW_HOCKEY_TREE);

    PegTreeNode *pNode = pTree->TopNode();

    pNode->Add(new PegTreeNode("East Teams",
        &gbCategoryBitmap));
    pNode->Add(new PegTreeNode("West Teams",
        &gbCategoryBitmap));

    // Get pointer to first level 1 node.

    pNode = pNode->First();

    // Add East teams to this node.

    pNode->Add(new PegTreeNode("Red Wings",
        &gbTeamBitmap));
    pNode->Add(new PegTreeNode("Blues",
        &gbTeamBitmap));
    pNode->Add(new PegTreeNode("Devils",
        &gbTeamBitmap);

    // Get pointer to next node.

    pNode = pNode->Next();

    // Add West teams to this node.

    pNode->Add(new PegTreeNode("Mighty Ducks",
        &gbTeamBitmap));
    pNode->Add(new PegTreeNode("Sharks",
        &gbTeamBitmap));
    pNode->Add(new PegTreeNode("Kings",
        &gbTeamBitmap));

    Add(pTree);
}



Top of page
KwikPeg Manuals
Home
Index
Index

 
Copyright © 2000-2003