Home |
Class PegTreeView HMI (Human-Machine Interface) Classes |
Class PegTreeViewPegTreeView, derived from PegWindow, displays a hierachial presentation of PegTreeNode objects. PegTreeView always uses automatic vertical and horizontal scrolling, so that whenever more nodes are present than can be displayed in the PegTreeView client area scroll bars are provided for panning the node display area. PegTreeView is actually a container object. When you create and display PegTreeView style windows, you will generally interact directly with the PegTreeNode children of the PegTreeView container. Any nesting level of PegTreeNode children can be displayed in the PegTreeView window. PegTreeView allows node selection using the mouse or the keyboard. The PegTreeView constructor accepts parameters for creating the first or top level node in the tree. PegTreeView immediately creates this top node, and it is always present. Additional nodes are added by adding them to this top node. The model for programming PegTreeView is very similar to the general PEG programming model, since in both cases you are working with tree structured lists of objects. class PegTreeView : public PegWindow { public: PegTreeView(const PegRect &Rect, PEGUINT wStyle, const PEGCHAR * Text, PegBitmap * pMap = NULL); PEGINT Message(const PegMessage &Mesg); void Draw(void); PegTreeNode * TopNode(void); void Select(PegTreeNode *, BOOL bDraw = TRUE); PegTreeNode * GetSelected(void); PegTreeNode * FindNode(int iLevel, PEGCHAR * Text); void Reset(const PEGCHAR * Top); void SetIndent(int iVal); int GetIndent(void); void GetVScrollInfo(PegScrollInfo * Put); void GetHScrollInfo(PegScrollInfo * Put); PegTreeNode * RemoveNode(PegTreeNode * Who); void DestroyNode(PegTreeNode * Who); PEGUINT GetMaxMapWidth(PegTreeNode * pTest); void DrawNode(PegTreeNode * pStart, PegPoint Put, int iMaxMapWidth); }; Demo program TreeView uses this class. Style FlagsFF_NONE, FF_THIN, FF_RAISED, FF_RECESSED, FF_THICK. SignalsPSF_NODE_DELETE, PSF_NODE_SELECT, PSF_NODE_OPEN, PSF_NODE_CLOSE. pData has a pointer to the selected node object. The PSF_NODE_DELETE signal is sent when the user presses the "Delete" key while a node is selected. It is the responsibility of the application software to actually remove and/or delete the selected node. ConstructorThe PegTreeView constructor accepts the initial TreeView position, frame style, and top node text. An optional bitmap or thumbnail to be associated with the top level node may also be defined. Method DestroyNodeRemoves the indicated node from the tree and deletes the node object. If the indicated node has children, they are also removed and destroyed. The FindNode() function is often used in conjunction with DestroyNode, to remove a specified node as follows: DestroyNode(FindNode(1, "Temp")); Method DrawPegTreeView overrides the Draw() function to display the tree view connecting lines and node anchors. Method DrawNodeDraws the node pointed to by pStart. Method FindNodeReturns a pointer to the TreeNode at the indicated nesting level with the matching text string. If multiple nodes at the correct nesting level have a matching text string, the first or topmost matching node pointer will be returned. Node nesting 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. Method GetIndentReturns the current indent level, in pixels. Method GetSelectedReturns a pointer to the selected node. Method GetHScrollInfoPegTreeView overrides the GetHScrollInfo function to calculate the tree width based on the sum of the individual node heights, and positions the horizontal scroll bar accordingly. Method GetVScrollInfoPegTreeView 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. Method MessagePegTreeView catches mouse and keyboard messages to test for node actions. Method RemoveNodeRemoves, but does not delete, the indicated node from the tree. If the node has children, the child 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")); Method ResetResets the entire tree by removing and deleting all of the tree's nodes. Method SelectSelects the indicated node via program control. Method SetIndentOverrides the default indent level in pixels of each generation of child nodes. Method TopNodeReturns the top tree node. From this pointer, the entire tree can be traversed. Method TrimFinds the node indicated by the string and removes all of that nodes children. ExamplesThe following is an example of a PegTreeView window populated with PegTreeNodes. In this case the PegTreeView window is used as the client for a PegNotebook page. This example is taken from WindowBuilder: The following function creates a PegTreeView control and populates the control with PegTreeNodes. The top level node is labeled "Hockey Teams". Two sub-nodes are created labeled "Good Teams" and "Bad Teams". To each of these nodes are added several hockey team names (no offense intended!). 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("Good Teams", &gbCategoryBitmap)); pNode->Add(new PegTreeNode("Bad Teams", &gbCategoryBitmap)); // get pointer to first sub-node: pNode = pNode->First(); // add good teams to this node: pNode->Add(new PegTreeNode("Red Wings", &gbTeamBitmap)); pNode->Add(new PegTreeNode("Blues", &gbTeamBitmap)); pNode->Add(new PegTreeNode("Stars", &gbTeamBitmap); // get pointer to next node: pNode = pNode->Next(); // add bad 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); }
|