]> Creatis software - creaImageIO.git/blob - src2/creaImageIOWxTreeView.h
memory leak tracking
[creaImageIO.git] / src2 / creaImageIOWxTreeView.h
1 #ifndef __creaImageIOWxTreeView_h_INCLUDED__
2 #define __creaImageIOWxTreeView_h_INCLUDED__
3
4 #ifdef USE_WXWIDGETS
5
6 #include <creaImageIOTreeView.h>
7 #include <creaWx.h>
8
9 #include <wx/listctrl.h>
10 #include <wx/splitter.h>
11 //#include <vector>
12 const std::string empty_string("");
13 namespace creaImageIO
14 {
15
16           //=====================================================================
17   /// Data stored by the list items
18   struct ItemData
19   {
20     ItemData() : node(0), id(-1), attr(&empty_string) {}
21     // The corresponding Node
22     tree::Node* node;
23     // The id ?
24     int id;
25     // The pointer on the current attribute string to sort on
26     const std::string* attr;
27     // Was the item previously selected ?
28     // Useful for reselecting the item after sort
29     bool selected;
30   };
31   /**
32    * \ingroup View
33    */
34   //=====================================================================
35   
36   //=====================================================================
37   /// Abstract class that handles the view of a Tree through its TreeHandler
38   class WxTreeView : public wxPanel, virtual public TreeView
39     {
40     public:
41       /// Ctor
42       WxTreeView(TreeHandler*, GimmickView*, 
43                  wxWindow* parent, const wxWindowID id);
44       /// Virtual destructor
45       virtual ~WxTreeView();
46
47       
48       /// Updates the view of a level given the selected items of upper level
49       virtual void UpdateLevel( int );
50
51       ///Removes selected nodes on given level
52       virtual void RemoveSelected();
53
54           ///Returns the last selected level
55           virtual unsigned int GetLastSelectedLevel(){return mLastLevel;}
56
57       /// Callback for item selection
58       void OnItemSelected(wxListEvent& event);
59
60       /// Callback for item deselection
61       void OnItemDeSelected(wxListEvent& event);
62       
63       /// Callback for column click
64       void OnColClick(wxListEvent& event);
65       
66       /// Callback when the user needs the items sorted
67       void OnPopupSort(wxCommandEvent& event);
68       
69       ///Callback when the user need the items filtered
70       void OnPopupFilter(wxCommandEvent& event);
71
72           ///Callback when the user needs the item copied to the local disk
73       void OnLocalCopy(wxCommandEvent& event);
74
75           ///Callback when the user needs to edit a field
76       void OnEditField(wxCommandEvent& event);
77       
78       ///Callback on mouse click
79       void OnMouseClick(wxMouseEvent& event);
80
81           /// Displays a menu for items
82           void OnItemMenu(wxListEvent &event);
83           
84           /// Gets the attributes that are being shown and the ones that have been blocked on a specific level
85           void GetAttributes(std::vector<std::string>& areShown, std::vector<std::string>& notShown, int level);
86
87           ///Sets the non visible attributes and refreshes the GUI
88           void SetNonVisibleAttributes(const std::vector<std::string>& notShown, int level);
89
90           ///Creates a new listctrl
91           void CreateCtrl(std::vector<std::string>& notShown, int nlevel);
92   
93           ///Returns true if the attribute passed as a parameter is visible or not
94           bool IsAttributeVisible(const std::string& val, int level);
95       
96       /// Actual processing of item selection/deselection 
97       /// Called by OnItemSelected and OnItemDeSelected
98       //      void ProcessItem
99     private:
100       /// The struct holding the data for one level
101       /// Holds the wx control and other data
102       /// such as the vector of attribute keys corresponding to the columns
103       struct LevelType
104       {
105         // The List Control
106         wxListCtrl* wxCtrl;
107         wxSplitterWindow* wxSplitter;
108         std::vector<std::string> key;
109         // The vector of currently selected nodes of the level
110         std::vector<tree::Node*> Selected;
111         // True iff the vector Selected is up to date
112         bool SelectedUpToDate;
113         // The column used for sorting
114         unsigned int SortColumn;
115         ///Boolean that defines the direction of the sort
116         ///True is ascending order and false is descending
117         bool SortAscending;
118         //The vector of not shown attributes
119         std::vector<std::string> notShownAtts; 
120       };
121       /// The vector of levels : one for each level of the tree      
122       std::vector<LevelType> mLevelList;
123       
124       /// return the wxListCtrl of one level
125       wxListCtrl* GetCtrl(int l) { return mLevelList[l].wxCtrl; }
126       /// return the wxSplitter of one level
127       wxSplitterWindow* GetSplitter(int l) { return mLevelList[l].wxSplitter; }
128       //Returns the maximum number of levels
129       int GetNumberOfLevels(){ return mLevelList.size(); }
130       /// Gets the user selected data from the level passed as a parameter
131       /// Updates the vector if necessary
132       const std::vector<tree::Node*>& GetSelected(int level);
133       /// Set the bool SelectedUpToDate for level l
134       void SetSelectedUpToDate(int l, bool v) { mLevelList[l].SelectedUpToDate = v; }
135       /// Get the bool SelectedUpToDate for level l
136       bool GetSelectedUpToDate(int l) { return mLevelList[l].SelectedUpToDate; }
137        ///Validates the selected images
138       void ValidateSelectedImages(bool isSelection);   
139       ///Gets selected filenames
140       void GetSelectedAsString(std::vector<std::string>&s);
141           ///Gets the filenames of the given nodes and returns them on the given vector. Is recursive.
142           void GetFilenamesAsString(const std::vector<tree::Node*>& nodes, std::vector<std::string>&s);
143       /// Gets the next nodes on the list, be it up(true) or down(false).
144       void GetNodes(std::vector<tree::Node*>& nodes, bool direction);
145       /// Updates the view of a level given the selected items of upper level
146       /// Recursive method
147       virtual void RecursiveUpdateLevel( int );
148       ///Selects all the elements of a level 
149       void SelectAll(int level);
150       ///UnSelects all the elements of a level 
151       void UnSelectAll(int level);
152
153           void OnKeyDown(wxListEvent &event);
154       /// Sorts the level
155       void SortLevel(int level);
156       
157       /// Currently Selected Column
158       int mColumnSelected;
159       ///The last selected item on the list (left click)
160       long mLastSelected;
161
162           ///The last selected item on the list (right click)
163           long mLastRightSelected;
164
165           ///The last selected level (by right click)
166           int mLastRightLevel;
167       ///The color map
168       typedef std::map<tree::Node*,wxColour> ColorMap;
169       typedef std::pair<tree::Node*,wxColour> NodeColorPair;
170       ColorMap mColorMap;
171       ///Initial color palette
172       std::vector<std::string> mColorPalette;
173
174       wxMenu* menu;
175           
176       wxObject* senderCtrl;
177       int mAscendingID;
178       int mDescendingID;
179       int mFilterID;
180       unsigned int mLastLevel;
181       
182           wxMenu* menuItem;
183           int mAnonymizingID;
184           int mLocalCopyID;
185           int mEditFieldID;
186           
187       // If set to true then OnSelectedChanged returns immediately.
188       // Used to do avoid useless process during multiple selections 
189       // or sorting
190       bool mIgnoreSelectedChanged;
191
192       DECLARE_EVENT_TABLE()
193     };
194     // EO class WxTreeView
195     //=====================================================================
196
197
198
199 } // EO namespace creaImageIO
200
201
202 #endif // USE_WIDGETS
203 // EOF
204 #endif