ALBA
|
#include <albaGUITree.h>
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 |
albaObserver * | m_Listener |
Protected Attributes inherited from albaGUINamedPanel | |
wxPanel * | m_Top |
albaGUILab * | m_Label |
wxBoxSizer * | m_Sizer |
wxBoxSizer * | m_TopSizer |
albaGUINamedPanel * | m_NextPanel |
wxColour | m_Color |
Additional Inherited Members | |
Public Attributes inherited from albaGUIPanel | |
albaGUIPanel * | m_NextPanel |
albaGUITree allows a simplified and lot easier use of a wxWindows tree widget.
albaGUITree doesn't use the wxWindows event-system: to receive event notification provide a albaObserver object by calling SetListener.
events generated by albaGUITree:
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.
albaGUITree::albaGUITree | ( | wxWindow * | parent, |
wxWindowID | id = -1 , |
||
bool | CloseButton = false , |
||
bool | HideTitle = false |
||
) |
|
virtual |
void albaGUITree::Reset | ( | ) |
Clears all items in the tree.
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.
bool albaGUITree::DeleteNode | ( | long long | node_id | ) |
Delete the specified node, and its subtree.
bool albaGUITree::SetNodeLabel | ( | long long | node_id, |
wxString | label | ||
) |
Set the label for the node.
wxString albaGUITree::GetNodeLabel | ( | long long | node_id | ) |
Get the label for the node.
Add by Mucci 19/09/2007
bool albaGUITree::NodeHasChildren | ( | long long | node_id | ) |
Check if the node has children.
Add by Mucci 19/09/2007
long long albaGUITree::GetNodeParent | ( | long long | node_id | ) |
Return the parent id of the node.
Add by Mucci 19/09/2007
bool albaGUITree::SetNodeParent | ( | long long | node_id, |
long long | parent_id | ||
) |
Move a node, and its subtree.
bool albaGUITree::SetNodeIcon | ( | long long | node_id, |
int | icon | ||
) |
Set the icon for the node.
int albaGUITree::GetNodeIcon | ( | long long | node_id | ) |
Return the icon index for the node 'node_id'.
bool albaGUITree::SelectNode | ( | long long | node_id | ) |
Select the node.
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
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.
|
inline |
if autosort is on - the tree is always kept sorted
Definition at line 152 of file albaGUITree.h.
|
inline |
Get the autosort flag.
Definition at line 155 of file albaGUITree.h.
void albaGUITree::CollapseNode | ( | long long | node_id | ) |
collapse the children of node_id
void albaGUITree::ExpandNode | ( | long long | node_id | ) |
expand the children of node_id
bool albaGUITree::IsNodeExpanded | ( | long long | node_id | ) |
|
inline |
Set the Listener that will receive event-notification, the Listener can be changed any time
Definition at line 166 of file albaGUITree.h.
wxTreeItemId albaGUITree::ItemFromNode | ( | long long | node_id | ) |
Return the node item from node id.
long long albaGUITree::NodeFromItem | ( | wxTreeItemId & | item | ) |
Return node id from node item.
|
inline |
Definition at line 175 of file albaGUITree.h.
|
inline |
Definition at line 176 of file albaGUITree.h.
bool albaGUITree::NodeExist | ( | long long | node_id | ) |
Return true if node exist.
|
protectedvirtual |
Private function that notify the Listener of node selection and deselection.
Reimplemented in albaGUIVMEChooserTree, and albaGUICheckTree.
|
protected |
When tree is used on a wxNotebook m_NodeTree must be called on Sizing .
|
protected |
Delete recursively a node and its subtree.
|
protected |
Move a node, and its subtree.
|
protected |
Check that id is a valid index in the imagelist - return the (eventually clamped) value.
|
inlineprotected |
Definition at line 197 of file albaGUITree.h.
|
protected |
Definition at line 199 of file albaGUITree.h.
|
protected |
Definition at line 200 of file albaGUITree.h.
|
protected |
Definition at line 201 of file albaGUITree.h.
|
protected |
Definition at line 202 of file albaGUITree.h.
Referenced by albaGUICheckTree::GetTree().
|
protected |
Definition at line 203 of file albaGUITree.h.
|
protected |
Definition at line 204 of file albaGUITree.h.
|
protected |
Definition at line 205 of file albaGUITree.h.