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