Vaca::TreeNode Class Reference

#include <TreeNode.h>

Inheritance diagram for Vaca::TreeNode:

Vaca::Component Vaca::Referenceable Vaca::NonCopyable

List of all members.


Detailed Description

A TreeView node.

It has a text label, an image, a selected image asociated, and a state (collapsed/expanded). A node can be parent of sub-TreeNodes.

Public Types

typedef std::vector< TreeNode * > Container

Public Member Functions

 TreeNode (const String &text="", int imageIndex=-1, int selectedImageIndex=-1)
virtual ~TreeNode ()
void addNode (TreeNode *node)
 Adds a new sub-node (child) to this one.
void removeNode (TreeNode *node)
 Removes a child node.
TreeNodegetParent ()
Container getChildren ()
 Returns the collection of children.
TreeViewgetTreeView ()
virtual bool hasChildren ()
 Returns true if this node should have the plus sign to be expanded.
virtual String getText ()
 Returns the label's text for the node.
virtual int getImage ()
 Returns the index of the image that uses this node from the ImageList.
virtual int getSelectedImage ()
 Returns the index of the image in selected-state that uses this node from the ImageList.
void setText (const String &text)
 Sets the node's text.
void setImage (int imageIndex)
 Sets the node's image.
void setSelectedImage (int selectedImageIndex)
 Sets the node's image in selected-state.
bool isExpanded ()
void setExpanded (bool state)
void ensureVisibility ()
HTREEITEM getHandle ()

Static Public Member Functions

static TreeNodefromHandle (HWND hwnd, HTREEITEM htreeitem)

Protected Member Functions

virtual void onBeforeExpand (TreeViewEvent &ev)
virtual void onBeforeCollapse (TreeViewEvent &ev)
virtual void onBeforeSelect (TreeViewEvent &ev)
virtual void onBeforeLabelEdit (TreeViewEvent &ev)
virtual void onAfterExpand (TreeViewEvent &ev)
virtual void onAfterCollapse (TreeViewEvent &ev)
virtual void onAfterSelect (TreeViewEvent &ev)
virtual void onAfterLabelEdit (TreeViewEvent &ev)
 The default implementation changes the m_text field to be returned in getText() only if ev wasn't canceled.

Private Member Functions

void addToTreeView (TreeView *treeView)
 Connects the node and its children to the Win32 TreeView.
void removeFromTreeView ()
 Disconnects the node (and its children) from the Win32 TreeView.

Private Attributes

String m_text
int m_image
int m_selectedImage
TreeNodem_parent
Container m_children
HTREEITEM m_HTREEITEM
TreeViewm_owner
bool m_deleted

Friends

class TreeView
class TreeViewIterator


Member Typedef Documentation

typedef std::vector<TreeNode*> Vaca::TreeNode::Container


Constructor & Destructor Documentation

TreeNode::TreeNode ( const String text = "",
int  imageIndex = -1,
int  selectedImageIndex = -1 
)

TreeNode::~TreeNode (  )  [virtual]


Member Function Documentation

void TreeNode::addNode ( TreeNode node  ) 

Adds a new sub-node (child) to this one.

After calling this method node'll have this node as parent.

void TreeNode::removeNode ( TreeNode node  ) 

Removes a child node.

Warning:
The specified
Parameters:
node must be a child of the object this.

TreeNode * TreeNode::getParent (  ) 

TreeNode::Container TreeNode::getChildren (  ) 

Returns the collection of children.

TreeView * TreeNode::getTreeView (  ) 

bool TreeNode::hasChildren (  )  [virtual]

Returns true if this node should have the plus sign to be expanded.

The default implementation returns true if the m_children member has elements. If you override this method isn't necessary to call the base implementation.

 class MyTreeNode : public TreeNode
 {
 protected:
   bool hasChildren() {
     return ...;
   }
 };

String TreeNode::getText (  )  [virtual]

Returns the label's text for the node.

If you override this method isn't necessary to call the base implementation.

 class MyTreeNode : public TreeNode
 {
 protected:
   String getText() {
     return "...";
   }
 };

int TreeNode::getImage (  )  [virtual]

Returns the index of the image that uses this node from the ImageList.

If you override this method isn't necessary to call the base implementation.

 class MyTreeNode : public TreeNode
 {
 protected:
   int getImage() {
     int imageIndex = -1;
     // ... do some work here
     return imageIndex;
   }
 };

int TreeNode::getSelectedImage (  )  [virtual]

Returns the index of the image in selected-state that uses this node from the ImageList.

If you override this method isn't necessary to call the base implementation.

See also:
getImage()

void TreeNode::setText ( const String text  ) 

Sets the node's text.

It's useful only if you are using the default implementation of getText().

void TreeNode::setImage ( int  imageIndex  ) 

Sets the node's image.

It's useful only if you are using the default implementation of getImage().

void TreeNode::setSelectedImage ( int  selectedImageIndex  ) 

Sets the node's image in selected-state.

It's useful only if you are using the default implementation of getSelectedImage().

bool TreeNode::isExpanded (  ) 

void TreeNode::setExpanded ( bool  state  ) 

void TreeNode::ensureVisibility (  ) 

HTREEITEM TreeNode::getHandle (  ) 

TreeNode * TreeNode::fromHandle ( HWND  hwnd,
HTREEITEM  htreeitem 
) [static]

void TreeNode::onBeforeExpand ( TreeViewEvent ev  )  [protected, virtual]

void TreeNode::onBeforeCollapse ( TreeViewEvent ev  )  [protected, virtual]

void TreeNode::onBeforeSelect ( TreeViewEvent ev  )  [protected, virtual]

void TreeNode::onBeforeLabelEdit ( TreeViewEvent ev  )  [protected, virtual]

void TreeNode::onAfterExpand ( TreeViewEvent ev  )  [protected, virtual]

void TreeNode::onAfterCollapse ( TreeViewEvent ev  )  [protected, virtual]

void TreeNode::onAfterSelect ( TreeViewEvent ev  )  [protected, virtual]

void TreeNode::onAfterLabelEdit ( TreeViewEvent ev  )  [protected, virtual]

The default implementation changes the m_text field to be returned in getText() only if ev wasn't canceled.

void TreeNode::addToTreeView ( TreeView treeView  )  [private]

Connects the node and its children to the Win32 TreeView.

void TreeNode::removeFromTreeView (  )  [private]

Disconnects the node (and its children) from the Win32 TreeView.


Friends And Related Function Documentation

friend class TreeView [friend]

friend class TreeViewIterator [friend]


Member Data Documentation

int Vaca::TreeNode::m_image [private]

HTREEITEM Vaca::TreeNode::m_HTREEITEM [private]

bool Vaca::TreeNode::m_deleted [private]