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