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