ALBA
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
albaGUITree Class Reference

#include <albaGUITree.h>

Inheritance diagram for albaGUITree:
Inheritance graph
[legend]
Collaboration diagram for albaGUITree:
Collaboration graph
[legend]

Classes

class  albaGUITreeItemData
 
class  albaGUITreeTableElement
 

Public Member Functions

 albaGUITree (wxWindow *parent, wxWindowID id=-1, bool CloseButton=false, bool HideTitle=false)
 
virtual ~albaGUITree ()
 
void Reset ()
 
bool AddNode (long long node_id, long long parent_id, wxString label, int icon=0)
 
bool DeleteNode (long long node_id)
 
bool SetNodeLabel (long long node_id, wxString label)
 
wxString GetNodeLabel (long long node_id)
 
bool NodeHasChildren (long long node_id)
 
long long GetNodeParent (long long node_id)
 
bool SetNodeParent (long long node_id, long long parent_id)
 
bool SetNodeIcon (long long node_id, int icon)
 
int GetNodeIcon (long long node_id)
 
bool SelectNode (long long node_id)
 
void SetImageList (wxImageList *img)
 
void SortChildren (long long node_id=0)
 
void SetAutoSort (bool enable)
 
bool GetAutoSort ()
 
void CollapseNode (long long node_id)
 
void ExpandNode (long long node_id)
 
bool IsNodeExpanded (long long node_id)
 
void SetListener (albaObserver *listener)
 
wxTreeItemId ItemFromNode (long long node_id)
 
long long NodeFromItem (wxTreeItemId &item)
 
void SetTreeStyle (long style)
 
long GetTreeStyle ()
 
bool NodeExist (long long node_id)
 
- Public Member Functions inherited from albaGUINamedPanel
 albaGUINamedPanel (wxWindow *parent, wxWindowID id=-1, bool CloseButton=false, bool HideTitle=false)
 
virtual ~albaGUINamedPanel ()
 
void Add (wxWindow *window, int option=0, int flag=wxEXPAND, int border=0)
 
void Add (wxSizer *sizer, int option=0, int flag=wxEXPAND, int border=0)
 
bool Remove (wxWindow *window)
 
bool Remove (wxSizer *sizer)
 
void SetTitle (wxString label)
 
void SetTitleColor (wxColour *color=NULL)
 
wxBoxSizer * GetTopSizer ()
 
wxPanel * GetTopPanel ()
 
- Public Member Functions inherited from albaGUIPanel
 albaGUIPanel (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name="panel")
 

Protected Member Functions

virtual void OnSelectionChanged (wxTreeEvent &event)
 
void OnSize (wxSizeEvent &event)
 
void DeleteNode2 (long long node_id)
 
void SetNodeParent2 (long long node_id, long long parent_id)
 
int CheckIconId (int icon)
 
bool IsRootHidden ()
 

Protected Attributes

bool m_PreventNotify
 
bool m_Autosort
 
long long m_NodeRoot
 
wxTreeCtrl * m_NodeTree
 
wxImageList * m_NodeImages
 
wxHashTable * m_NodeTable
 
albaObserverm_Listener
 
- Protected Attributes inherited from albaGUINamedPanel
wxPanel * m_Top
 
albaGUILabm_Label
 
wxBoxSizer * m_Sizer
 
wxBoxSizer * m_TopSizer
 
albaGUINamedPanelm_NextPanel
 
wxColour m_Color
 

Additional Inherited Members

- Public Attributes inherited from albaGUIPanel
albaGUIPanelm_NextPanel
 

Detailed Description

albaGUITree allows a simplified and lot easier use of a wxWindows tree widget.

implementation details:
the term "Node" refer to the object represented in the Tree, the term "Item" refer to the graphics object shown in the Tree.

Calling wxTreeCtrl::AddNode return an object of type wxTreeCtrlItem, these objects are to be kept somewhere to be able to edit or delete the items later. The easy solution is to store a pointer to wxTreeCtrlItem in the node, but this will mean that albaGUITree has some knowledge on the node objects thus making albaGUITree non-general-purposes and also that every node can be connected to one albaGUITree only.

The solution adopted here is to store all the wxTreeCtrlItem in a HashTable (m_NodeTable) indexed by the node_id's. Thus explicit conversion between node_ids and items has to be addressed.

ItemFromNode is implemented using m_NodeTable. Note that wxHashTable store only object of type albaGUITreeTableElement so a new class albaGUITreeTableItem was derived from wxHashTableItem to store a pointer to wxTreeCtrlItem

NodeFromItem may be implemented searching all the elements in m_NodeTable but this will be time-consuming, another solution is to store the node_id in the item. Items may store user-data in a class derived from wxTreeItemData, so a class albaGUITreeItemData was created for this purposes. A new albaGUITreeItemData object is created every time an item is inserted in the tree.

Further aspect: One Item may have a cross-icon that mean that it has children and thus can be opened, to show the cross-icon the developer must call SetItemHasChildren. wxTreeCtrl doesn't set-up the HasChildren flag itself, so when a node is added or deleted the HasChildren flag of the parent has to be kept consistent.Another flag control if a subtree is expanded or collapsed, this flag has to be kept consistent when moving a node.

Moving a node: wxTreeCtrl doesn't provide a way to change item's parent, so that operation has to be implemented explicitly. Delete and recreate the item doesn't work because delete the item destroy all the items in the subtree.The correct approach is to copy the item under the new parent, recursively move all the item in the subtree, and then delete the old item.During this operation the HasChildren flag, the IsExpanded flag and the HashTable contents has to be kept consistent.

Deleting a node: Deleting an item destroy all the sub-items,leaving the m_NodeTable inconsistent. To correctly implement the operation, DeleteNode must call itself recursively on the item subtree, then Delete the item and remove the corresponding m_NodeTable entry.

Definition at line 96 of file albaGUITree.h.

Constructor & Destructor Documentation

◆ albaGUITree()

albaGUITree::albaGUITree ( wxWindow *  parent,
wxWindowID  id = -1,
bool  CloseButton = false,
bool  HideTitle = false 
)

◆ ~albaGUITree()

virtual albaGUITree::~albaGUITree ( )
virtual

Member Function Documentation

◆ Reset()

void albaGUITree::Reset ( )

Clears all items in the tree.

◆ AddNode()

bool albaGUITree::AddNode ( long long  node_id,
long long  parent_id,
wxString  label,
int  icon = 0 
)

Create a new tree item with the specified parent,label and icon.

Set parent = 0 to create the root. 0 is not a valid node_id.

◆ DeleteNode()

bool albaGUITree::DeleteNode ( long long  node_id)

Delete the specified node, and its subtree.

◆ SetNodeLabel()

bool albaGUITree::SetNodeLabel ( long long  node_id,
wxString  label 
)

Set the label for the node.

◆ GetNodeLabel()

wxString albaGUITree::GetNodeLabel ( long long  node_id)

Get the label for the node.

Add by Mucci 19/09/2007

◆ NodeHasChildren()

bool albaGUITree::NodeHasChildren ( long long  node_id)

Check if the node has children.

Add by Mucci 19/09/2007

◆ GetNodeParent()

long long albaGUITree::GetNodeParent ( long long  node_id)

Return the parent id of the node.

Add by Mucci 19/09/2007

◆ SetNodeParent()

bool albaGUITree::SetNodeParent ( long long  node_id,
long long  parent_id 
)

Move a node, and its subtree.

◆ SetNodeIcon()

bool albaGUITree::SetNodeIcon ( long long  node_id,
int  icon 
)

Set the icon for the node.

◆ GetNodeIcon()

int albaGUITree::GetNodeIcon ( long long  node_id)

Return the icon index for the node 'node_id'.

◆ SelectNode()

bool albaGUITree::SelectNode ( long long  node_id)

Select the node.

◆ SetImageList()

void albaGUITree::SetImageList ( wxImageList *  img)

Set the images to be used for the nodes.

Must be set before adding any node. The default ImageList provide 4 icons : -1 gray dot -2 red dot -3 blue dot -4 yellow dot

◆ SortChildren()

void albaGUITree::SortChildren ( long long  node_id = 0)

Sort the children of node_id.

(not the subtree) give node_id = 0 to specify the root.

◆ SetAutoSort()

void albaGUITree::SetAutoSort ( bool  enable)
inline

if autosort is on - the tree is always kept sorted

Definition at line 152 of file albaGUITree.h.

◆ GetAutoSort()

bool albaGUITree::GetAutoSort ( )
inline

Get the autosort flag.

Definition at line 155 of file albaGUITree.h.

◆ CollapseNode()

void albaGUITree::CollapseNode ( long long  node_id)

collapse the children of node_id

◆ ExpandNode()

void albaGUITree::ExpandNode ( long long  node_id)

expand the children of node_id

◆ IsNodeExpanded()

bool albaGUITree::IsNodeExpanded ( long long  node_id)

◆ SetListener()

void albaGUITree::SetListener ( albaObserver listener)
inline

Set the Listener that will receive event-notification, the Listener can be changed any time

Definition at line 166 of file albaGUITree.h.

◆ ItemFromNode()

wxTreeItemId albaGUITree::ItemFromNode ( long long  node_id)

Return the node item from node id.

◆ NodeFromItem()

long long albaGUITree::NodeFromItem ( wxTreeItemId &  item)

Return node id from node item.

◆ SetTreeStyle()

void albaGUITree::SetTreeStyle ( long  style)
inline

Definition at line 175 of file albaGUITree.h.

◆ GetTreeStyle()

long albaGUITree::GetTreeStyle ( )
inline

Definition at line 176 of file albaGUITree.h.

◆ NodeExist()

bool albaGUITree::NodeExist ( long long  node_id)

Return true if node exist.

◆ OnSelectionChanged()

virtual void albaGUITree::OnSelectionChanged ( wxTreeEvent &  event)
protectedvirtual

Private function that notify the Listener of node selection and deselection.

Reimplemented in albaGUIVMEChooserTree, and albaGUICheckTree.

◆ OnSize()

void albaGUITree::OnSize ( wxSizeEvent &  event)
protected

When tree is used on a wxNotebook m_NodeTree must be called on Sizing .

◆ DeleteNode2()

void albaGUITree::DeleteNode2 ( long long  node_id)
protected

Delete recursively a node and its subtree.

◆ SetNodeParent2()

void albaGUITree::SetNodeParent2 ( long long  node_id,
long long  parent_id 
)
protected

Move a node, and its subtree.

◆ CheckIconId()

int albaGUITree::CheckIconId ( int  icon)
protected

Check that id is a valid index in the imagelist - return the (eventually clamped) value.

◆ IsRootHidden()

bool albaGUITree::IsRootHidden ( )
inlineprotected

Definition at line 197 of file albaGUITree.h.

Member Data Documentation

◆ m_PreventNotify

bool albaGUITree::m_PreventNotify
protected

Definition at line 199 of file albaGUITree.h.

◆ m_Autosort

bool albaGUITree::m_Autosort
protected

Definition at line 200 of file albaGUITree.h.

◆ m_NodeRoot

long long albaGUITree::m_NodeRoot
protected

Definition at line 201 of file albaGUITree.h.

◆ m_NodeTree

wxTreeCtrl* albaGUITree::m_NodeTree
protected

Definition at line 202 of file albaGUITree.h.

Referenced by albaGUICheckTree::GetTree().

◆ m_NodeImages

wxImageList* albaGUITree::m_NodeImages
protected

Definition at line 203 of file albaGUITree.h.

◆ m_NodeTable

wxHashTable* albaGUITree::m_NodeTable
protected

Definition at line 204 of file albaGUITree.h.

◆ m_Listener

albaObserver* albaGUITree::m_Listener
protected

Definition at line 205 of file albaGUITree.h.


The documentation for this class was generated from the following file: