]> Creatis software - creaImageIO.git/blob - src2/creaImageIOWxTreeView.h
4b97590f6cf33284eb6e17fb6a94f0b900defaec
[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       /// Callback for item selection
40       void OnItemSelected(wxListEvent& event);
41
42       /// Callback for item deselection
43       void OnItemDeSelected(wxListEvent& event);
44       
45       /// Callback for column click
46       void OnColClick(wxListEvent& event);
47       
48       /// Callback when the user needs the items sorted
49       void OnPopupSort(wxCommandEvent& event);
50       
51       ///Callback when the user need the items filtered
52       void OnPopupFilter(wxCommandEvent& event);
53       
54       ///Callback on mouse click
55       void OnMouseClick(wxMouseEvent& event);
56       
57       /// Actual processing of item selection/deselection 
58       /// Called by OnItemSelected and OnItemDeSelected
59       //      void ProcessItem
60     private:
61       /// The struct holding the data for one level
62       /// Holds the wx control and other data
63       /// such as the vector of attribute keys corresponding to the columns
64       struct LevelType
65       {
66         // The List Control
67         wxListCtrl* wxCtrl;
68         wxSplitterWindow* wxSplitter;
69         std::vector<std::string> key;
70         // The vector of currently selected nodes of the level
71         std::vector<tree::Node*> Selected;
72         // True iff the vector Selected is up to date
73         bool SelectedUpToDate;
74         // The column used for sorting
75         unsigned int SortColumn;
76         ///Boolean that defines the direction of the sort
77         ///True is ascending order and false is descending
78         bool SortAscending;
79         // 
80       };
81       /// The vector of levels : one for each level of the tree      
82       std::vector<LevelType> mLevelList;
83       
84       /// return the wxListCtrl of one level
85       wxListCtrl* GetCtrl(int l) { return mLevelList[l].wxCtrl; }
86       /// return the wxSplitter of one level
87       wxSplitterWindow* GetSplitter(int l) { return mLevelList[l].wxSplitter; }
88       //Returns the maximum number of levels
89       int GetNumberOfLevels(){ return mLevelList.size(); }
90       /// Gets the user selected data from the level passed as a parameter
91       /// Updates the vector if necessary
92       const std::vector<tree::Node*>& GetSelected(int level);
93       /// Set the bool SelectedUpToDate for level l
94       void SetSelectedUpToDate(int l, bool v) { mLevelList[l].SelectedUpToDate = v; }
95       /// Get the bool SelectedUpToDate for level l
96       bool GetSelectedUpToDate(int l) { return mLevelList[l].SelectedUpToDate; }
97        ///Validates the selected images
98       void ValidateSelectedImages(bool isSelection);   
99       ///Gets selected filenames
100       void GetSelectedAsString(std::vector<std::string>&s);
101       /// Gets the next nodes on the list, be it up(true) or down(false).
102       void GetNodes(std::vector<tree::Node*>& nodes, bool direction);
103       /// Updates the view of a level given the selected items of upper level
104       /// Recursive method
105       virtual void RecursiveUpdateLevel( int );
106       ///Sets the color of a selected item
107       void SetColor(int level, int item);
108       ///Creates the color palette for the first level
109       void CreateColorPalette();
110       ///Selects all the elements of a level 
111       void SelectAll(int level);
112       ///UnSelects all the elements of a level 
113       void UnSelectAll(int level);
114
115           void OnKeyDown(wxListEvent &event);
116       /// Sorts the level
117       void SortLevel(int level);
118       
119       /// Currently Selected Column
120       int mColumnSelected;
121       ///The last selected item on the list
122       long mLastSelected;
123       ///The color map
124       typedef std::map<tree::Node*,wxColour> ColorMap;
125       typedef std::pair<tree::Node*,wxColour> NodeColorPair;
126       ColorMap mColorMap;
127       ///Initial color palette
128       std::vector<std::string> mColorPalette;
129
130       wxMenu* menu;
131       wxObject* senderCtrl;
132       int mAscendingID;
133       int mDescendingID;
134       int mFilterID;
135       unsigned int mLastLevel;
136       
137       // If set to true then OnSelectedChanged returns immediately.
138       // Used to do avoid useless process during multiple selections 
139       // or sorting
140       bool mIgnoreSelectedChanged;
141
142
143       DECLARE_EVENT_TABLE()
144     };
145     // EO class WxTreeView
146     //=====================================================================
147
148
149
150 } // EO namespace creaImageIO
151
152
153 #endif // USE_WIDGETS
154 // EOF
155 #endif