ALBA
albaGUITree.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: ALBA (Agile Library for Biomedical Applications)
4 Module: albaGUITree
5 Authors: Silvano Imboden
6
7 Copyright (c) BIC
8 All rights reserved. See Copyright.txt or
9
10
11 This software is distributed WITHOUT ANY WARRANTY; without even
12 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the above copyright notice for more information.
14
15=========================================================================*/
16#ifndef __albaGUITree_H__
17#define __albaGUITree_H__
18//----------------------------------------------------------------------------
19// Include:
20//----------------------------------------------------------------------------
21#include <wx/laywin.h>
22#include <wx/image.h>
23#include <wx/imaglist.h>
24#include <wx/treectrl.h>
25#include <wx/hash.h>
26#include "albaEvent.h"
27#include "albaObserver.h"
28#include "albaGUINamedPanel.h"
29#include "albaServiceClient.h"
30#include "albaAbsLogicManager.h"
31
32//----------------------------------------------------------------------------
33// const :
34//----------------------------------------------------------------------------
35const int ID_TREE = 200;
36//----------------------------------------------------------------------------
37// albaGUITree :
38//----------------------------------------------------------------------------
97//----------------------------------------------------------------------------
98// albaGUITreeItemData :
100//----------------------------------------------------------------------------
101class albaGUITreeItemData : public wxTreeItemData {
102public:
103 albaGUITreeItemData(long long node_id, bool expanded) { m_NodeId = node_id; m_Expanded = expanded; };
104
106 long long GetNode() { return m_NodeId; };
107
110 bool GetExpanded() const { return m_Expanded; }
111
114 void SetExpanded(bool expanded) { m_Expanded = expanded; }
115
116protected:
117 long long m_NodeId;
119};
120
121
122class albaTreeCtrl : public wxTreeCtrl
123{
124public:
125 albaTreeCtrl(wxWindow *parent, wxWindowID id = wxID_ANY,
126 const wxPoint& pos = wxDefaultPosition,
127 const wxSize& size = wxDefaultSize,
128 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
129 const wxValidator& validator = wxDefaultValidator,
130 const wxString& name = wxASCII_STR(wxTreeCtrlNameStr));
131
132 virtual bool IsExpanded(const wxTreeItemId& item);
133
134 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
135
136 wxTreeItemId AppendItem(const wxTreeItemId& parent, const wxString& text, int image = -1, int selImage = -1, wxTreeItemData *data = NULL);
137
138 virtual void Expand(const wxTreeItemId& item);
139 virtual void Collapse(const wxTreeItemId& item);
140 virtual void CollapseAndReset(const wxTreeItemId& item);
141 virtual void Toggle(const wxTreeItemId& item);
142};
143
144
145class ALBA_EXPORT albaGUITree: public albaGUINamedPanel, public albaServiceClient
146{
147public:
148 albaGUITree (wxWindow* parent, wxWindowID id=-1, bool CloseButton = false, bool HideTitle = false);
149 virtual ~albaGUITree();
150
152 void Reset();
153
157 bool AddNode(long long node_id, long long parent_id , wxString label, bool expanded, int icon = 0);
158
160 bool DeleteNode(long long node_id);
161
163 bool SetNodeLabel(long long node_id, wxString label);
164
166 wxString GetNodeLabel(long long node_id);
167
169 bool NodeHasChildren(long long node_id);
170
172 long long GetNodeParent(long long node_id);
173
175 bool SetNodeParent(long long node_id, long long parent_id );
176
178 bool SetNodeIcon(long long node_id, int icon);
179
181 int GetNodeIcon(long long node_id);
182
184 bool SelectNode(long long node_id);
185
194 void SetImageList(wxImageList *img);
195
198 void SortChildren(long long node_id =0);
199
201 void SetAutoSort(bool enable) {m_Autosort=enable;};
202
204 bool GetAutoSort() {return m_Autosort;};
205
207 void CollapseNode(long long node_id);
208
210 void ExpandNode(long long node_id);
211
212 bool IsNodeExpanded(long long node_id);
213
215 void SetListener(albaObserver *listener) {m_Listener=listener;};
216
218 wxTreeItemId ItemFromNode(long long node_id);
219
221 long long NodeFromItem(wxTreeItemId& item);
222
223 void SetTreeStyle(long style) {m_NodeTree->SetWindowStyle(style);};
224 long GetTreeStyle() {return m_NodeTree->GetWindowStyle();};
225
227 bool NodeExist(long long node_id);
228
229protected:
231 virtual void OnSelectionChanged(wxTreeEvent& event);
232
234 void OnSize(wxSizeEvent& event);
235
237 void DeleteNode2(long long node_id);
238
240 void SetNodeParent2(long long node_id, long long parent_id );
241
243 int CheckIconId(int icon);
244
245 bool IsRootHidden() {return (GetTreeStyle() & wxTR_HIDE_ROOT) != 0; };
246
249 long long m_NodeRoot;
251 wxImageList *m_NodeImages;
252 wxHashTable *m_NodeTable;
254
255 //----------------------------------------------------------------------------
256 // albaGUITreeTableElement:
258 //----------------------------------------------------------------------------
259 class albaGUITreeTableElement: public wxObject
260 {
261 public:
262 albaGUITreeTableElement(wxTreeItemId item) {m_TreeItemId=item; };
263 wxTreeItemId GetItem() {return m_TreeItemId;};
264 void SetItem(wxTreeItemId item){m_TreeItemId=item; };
265 protected:
266 wxTreeItemId m_TreeItemId;
267 };
268
269DECLARE_EVENT_TABLE()
270}; // end of albaGUITree
271#endif
const int ID_TREE
Definition: albaGUITree.h:35
Class Name: albaGUINamedPanel.
albaGUITree allows a simplified and lot easier use of a wxWindows tree widget.
Definition: albaGUITree.h:101
void SetExpanded(bool expanded)
Sets Expanded virtual node state, , when a node has no child it result not expanded in any case,...
Definition: albaGUITree.h:114
bool GetExpanded() const
Returns Expanded virtual node state, when a node has no child it result not expanded in any case,...
Definition: albaGUITree.h:110
albaGUITreeItemData(long long node_id, bool expanded)
Definition: albaGUITree.h:103
long long GetNode()
Returns NodeId.
Definition: albaGUITree.h:106
specialized HashTable element used in albaGUITree to store a reference to a wxTreeItemId
Definition: albaGUITree.h:260
albaGUITreeTableElement(wxTreeItemId item)
Definition: albaGUITree.h:262
void SetItem(wxTreeItemId item)
Definition: albaGUITree.h:264
bool DeleteNode(long long node_id)
Delete the specified node, and its subtree.
void SetListener(albaObserver *listener)
Set the Listener that will receive event-notification, the Listener can be changed any time
Definition: albaGUITree.h:215
int GetNodeIcon(long long node_id)
Return the icon index for the node 'node_id'.
albaTreeCtrl * m_NodeTree
Definition: albaGUITree.h:250
wxHashTable * m_NodeTable
Definition: albaGUITree.h:252
void CollapseNode(long long node_id)
collapse the children of node_id
void SetImageList(wxImageList *img)
Set the images to be used for the nodes.
bool SetNodeLabel(long long node_id, wxString label)
Set the label for the node.
void Reset()
Clears all items in the tree.
virtual ~albaGUITree()
bool SelectNode(long long node_id)
Select the node.
bool IsRootHidden()
Definition: albaGUITree.h:245
bool m_Autosort
Definition: albaGUITree.h:248
void SetNodeParent2(long long node_id, long long parent_id)
Move a node, and its subtree.
virtual void OnSelectionChanged(wxTreeEvent &event)
Private function that notify the Listener of node selection and deselection.
wxImageList * m_NodeImages
Definition: albaGUITree.h:251
bool NodeHasChildren(long long node_id)
Check if the node has children.
void DeleteNode2(long long node_id)
Delete recursively a node and its subtree.
long long m_NodeRoot
Definition: albaGUITree.h:249
bool SetNodeParent(long long node_id, long long parent_id)
Move a node, and its subtree.
wxString GetNodeLabel(long long node_id)
Get the label for the node.
bool IsNodeExpanded(long long node_id)
void SetTreeStyle(long style)
Definition: albaGUITree.h:223
long long NodeFromItem(wxTreeItemId &item)
Return node id from node item.
void ExpandNode(long long node_id)
expand the children of node_id
void OnSize(wxSizeEvent &event)
When tree is used on a wxNotebook m_NodeTree must be called on Sizing .
bool GetAutoSort()
Get the autosort flag.
Definition: albaGUITree.h:204
void SortChildren(long long node_id=0)
Sort the children of node_id.
wxTreeItemId ItemFromNode(long long node_id)
Return the node item from node id.
bool NodeExist(long long node_id)
Return true if node exist.
int CheckIconId(int icon)
Check that id is a valid index in the imagelist - return the (eventually clamped) value.
long long GetNodeParent(long long node_id)
Return the parent id of the node.
bool SetNodeIcon(long long node_id, int icon)
Set the icon for the node.
albaGUITree(wxWindow *parent, wxWindowID id=-1, bool CloseButton=false, bool HideTitle=false)
albaObserver * m_Listener
Definition: albaGUITree.h:253
long GetTreeStyle()
Definition: albaGUITree.h:224
bool AddNode(long long node_id, long long parent_id, wxString label, bool expanded, int icon=0)
Create a new tree item with the specified parent,label and icon.
bool m_PreventNotify
Definition: albaGUITree.h:247
void SetAutoSort(bool enable)
if autosort is on - the tree is always kept sorted
Definition: albaGUITree.h:201
Interface implementing the Observer of the Subject/Observer design pattern.
Definition: albaObserver.h:36
virtual void Expand(const wxTreeItemId &item)
virtual bool IsExpanded(const wxTreeItemId &item)
virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
albaTreeCtrl(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTR_HAS_BUTTONS|wxTR_LINES_AT_ROOT, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxASCII_STR(wxTreeCtrlNameStr))
virtual void CollapseAndReset(const wxTreeItemId &item)
virtual void Collapse(const wxTreeItemId &item)
virtual void Toggle(const wxTreeItemId &item)
wxTreeItemId AppendItem(const wxTreeItemId &parent, const wxString &text, int image=-1, int selImage=-1, wxTreeItemData *data=NULL)