]> Creatis software - creaImageIO.git/blob - src2/creaImageIOWxTreeView.cpp
a258ce88c0b082165b888018ebbf76189b8493ea
[creaImageIO.git] / src2 / creaImageIOWxTreeView.cpp
1 #include <creaImageIOWxTreeView.h>
2 #include <creaImageIOSystem.h>
3 #include <wx/splitter.h>
4
5 namespace creaImageIO
6 {
7   //=====================================================================
8   // CTor
9   WxTreeView::WxTreeView(TreeHandler* handler,
10                          wxWindow* parent,
11                          const wxWindowID id)
12     : wxPanel(parent,id),
13       TreeView(handler)
14   {
15     GimmickDebugMessage(1,"WxTreeView::WxTreeView"
16                         <<std::endl);
17
18     
19     // Split part below toolbar into notebook for views and panel
20     // for preview, messages...
21     // TO DO : Splitter
22     //    mSplitter = new wxSplitterWindow( this , -1);
23
24     // Global sizer
25     wxBoxSizer  *sizer = new wxBoxSizer(wxHORIZONTAL);
26     
27     int ctrl_style = wxLC_REPORT;
28     int col_style = wxLIST_FORMAT_LEFT;
29
30     // Creating the ListCtrl for the levels > 0 (not for Root level)
31     for (int i = 1;
32          i < handler->GetTree().GetNumberOfLevels();
33          ++i)
34       {
35         GimmickDebugMessage(5,"Creating ListCtrl for level "<<i
36                             <<std::endl);
37         LevelType level;
38         wxListCtrl* ctrl = new wxListCtrl(this,
39                                           i,
40                                           wxDefaultPosition, 
41                                           wxDefaultSize,
42                                           ctrl_style);
43         level.wxCtrl = ctrl;
44
45         // Create the columns : one for each attribute of the level
46         int col = 0;
47         tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
48         for (a  = handler->GetTree().GetAttributeDescriptorList(i).begin();
49              a != handler->GetTree().GetAttributeDescriptorList(i).end();
50              ++a)
51           {
52             GimmickDebugMessage(5,"Creating column "<<col<<" : "
53                                 <<a->GetName()
54                                 <<std::endl);
55             ctrl->InsertColumn(col, 
56                                crea::std2wx(a->GetName()),
57                                col_style);
58             level.key.push_back(a->GetKey());
59             // ctrl->SetColumnWidth(col, wxLIST_AUTOSIZE );
60             col++;
61           }
62         mLevelList.push_back(level);
63         sizer->Add( ctrl ,1, wxGROW  ,0);
64       }
65     
66     UpdateLevel(1);
67
68     SetSizer( sizer );     
69     SetAutoLayout(true);
70     Layout();
71
72   }
73   //=====================================================================
74
75   //=====================================================================
76   /// Destructor
77   WxTreeView::~WxTreeView()
78   {
79     GimmickDebugMessage(1,"WxTreeView::~WxTreeView"
80                         <<std::endl);
81   }
82   //=====================================================================
83   
84   
85   //=====================================================================
86   struct ItemData
87   {
88     tree::Node* node;
89   };
90   //=====================================================================
91
92   //=====================================================================
93   /// 
94   void WxTreeView::UpdateLevel( int level )
95   {
96     GimmickDebugMessage(1,
97                         GetTreeHandler()->GetTree().GetLabel()
98                         <<" view : updating level "<<level
99                         <<std::endl);
100     int l = level - 1;
101     // the selection of upper level
102     std::vector<tree::Node*> sel;
103     if (level == 1) 
104       {
105         sel.push_back(GetTreeHandler()->GetTree().GetTree());
106       }
107     else 
108       {
109         int n = GetCtrl(l-1)->GetItemCount();
110         for (int i = 0; i < n; i++)
111           {
112             if ( GetCtrl(l-1)->GetItemState(i,wxLIST_STATE_SELECTED))
113               {
114                 long adr = GetCtrl(l-1)->GetItemData(i);
115                 tree::Node* n = ((ItemData*)adr)->node;
116                 sel.push_back(n);
117               }
118           }     
119       }
120
121     // to speed up inserting we hide the control temporarily
122     GetCtrl(l)->Hide();
123     GetCtrl(l)->DeleteAllItems();
124     
125     std::vector<tree::Node*>::iterator i;
126     for (i=sel.begin(); i!=sel.end(); ++i)
127       {
128         GimmickDebugMessage(2,
129                             "adding children of '"
130                             <<(*i)->GetLabel()
131                             <<"'"<<level
132                             <<std::endl);
133         
134         GetTreeHandler()->LoadChildren(*i,1);
135         tree::Node::ChildrenListType::reverse_iterator j;
136         for (j = (*i)->GetChildrenList().rbegin(); 
137              j!= (*i)->GetChildrenList().rend(); 
138              ++j)
139           {
140             wxListItem item;
141             item.SetMask(wxLIST_MASK_STATE | 
142                          wxLIST_MASK_TEXT |
143                          //                      wxLIST_MASK_IMAGE |
144                          wxLIST_MASK_DATA |
145                          //                      wxLIST_MASK_WIDTH |
146                          wxLIST_MASK_FORMAT
147                          );
148
149             ItemData* data = new ItemData;
150             data->node = *j;
151             item.SetData(data);
152             
153             long id = GetCtrl(l)->InsertItem(item);
154
155             for (int k=0; k<GetCtrl(l)->GetColumnCount(); k++)
156               {
157                 GetCtrl(l)->SetItem
158                   (id,k,
159                    crea::std2wx
160                    ( (*j)->GetAttribute(mLevelList[l].key[k]) ));
161               }
162             
163           }
164       }
165     
166     GetCtrl(l)->Show();
167
168     
169     if (level<mLevelList.size()) UpdateLevel(level+1);
170  }
171   //=====================================================================
172
173
174   //================================================================
175   void WxTreeView::OnSelected(wxListEvent& event)
176   { 
177     GimmickDebugMessage(1,
178                         GetTreeHandler()->GetTree().GetLabel()
179                         <<" view : item selected "
180                         <<std::endl);
181
182     
183     wxListItem info;
184     info.m_itemId = event.m_itemIndex;
185     
186
187     // retrieve the level
188     wxObject* obj = event.GetEventObject();   
189     unsigned int level = 0;
190     for (level = 0; level<mLevelList.size(); ++level)
191       {
192         if ( GetCtrl(level) == obj ) break;
193       }
194     GimmickDebugMessage(1,
195                         " Level "<<level+1
196                         <<std::endl);
197     if (level<mLevelList.size()-1) UpdateLevel( level + 2 ); 
198     
199   }
200   //================================================================
201
202
203
204   BEGIN_EVENT_TABLE(WxTreeView, wxPanel)
205   /*
206     EVT_SIZE(MyFrame::OnSize)
207
208     EVT_MENU(LIST_QUIT, MyFrame::OnQuit)
209     EVT_MENU(LIST_ABOUT, MyFrame::OnAbout)
210     EVT_MENU(LIST_LIST_VIEW, MyFrame::OnListView)
211     EVT_MENU(LIST_REPORT_VIEW, MyFrame::OnReportView)
212     EVT_MENU(LIST_ICON_VIEW, MyFrame::OnIconView)
213     EVT_MENU(LIST_ICON_TEXT_VIEW, MyFrame::OnIconTextView)
214     EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView)
215     EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView)
216     EVT_MENU(LIST_VIRTUAL_VIEW, MyFrame::OnVirtualView)
217     EVT_MENU(LIST_SMALL_VIRTUAL_VIEW, MyFrame::OnSmallVirtualView)
218
219     EVT_MENU(LIST_FOCUS_LAST, MyFrame::OnFocusLast)
220     EVT_MENU(LIST_TOGGLE_FIRST, MyFrame::OnToggleFirstSel)
221     EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll)
222     EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll)
223     EVT_MENU(LIST_DELETE, MyFrame::OnDelete)
224     EVT_MENU(LIST_ADD, MyFrame::OnAdd)
225     EVT_MENU(LIST_EDIT, MyFrame::OnEdit)
226     EVT_MENU(LIST_DELETE_ALL, MyFrame::OnDeleteAll)
227     EVT_MENU(LIST_SORT, MyFrame::OnSort)
228     EVT_MENU(LIST_SET_FG_COL, MyFrame::OnSetFgColour)
229     EVT_MENU(LIST_SET_BG_COL, MyFrame::OnSetBgColour)
230     EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel)
231     EVT_MENU(LIST_SHOW_COL_INFO, MyFrame::OnShowColInfo)
232     EVT_MENU(LIST_SHOW_SEL_INFO, MyFrame::OnShowSelInfo)
233     EVT_MENU(LIST_FREEZE, MyFrame::OnFreeze)
234     EVT_MENU(LIST_THAW, MyFrame::OnThaw)
235     EVT_MENU(LIST_TOGGLE_LINES, MyFrame::OnToggleLines)
236     EVT_MENU(LIST_MAC_USE_GENERIC, MyFrame::OnToggleMacUseGeneric)
237
238     EVT_UPDATE_UI(LIST_SHOW_COL_INFO, MyFrame::OnUpdateShowColInfo)
239     EVT_UPDATE_UI(LIST_TOGGLE_MULTI_SEL, MyFrame::OnUpdateToggleMultiSel)
240 END_EVENT_TABLE()
241
242 BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
243     EVT_LIST_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnBeginDrag)
244     EVT_LIST_BEGIN_RDRAG(LIST_CTRL, MyListCtrl::OnBeginRDrag)
245     EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnBeginLabelEdit)
246     EVT_LIST_END_LABEL_EDIT(LIST_CTRL, MyListCtrl::OnEndLabelEdit)
247     EVT_LIST_DELETE_ITEM(LIST_CTRL, MyListCtrl::OnDeleteItem)
248     EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, MyListCtrl::OnDeleteAllItems)
249 #if WXWIN_COMPATIBILITY_2_4
250     EVT_LIST_GET_INFO(LIST_CTRL, MyListCtrl::OnGetInfo)
251     EVT_LIST_SET_INFO(LIST_CTRL, MyListCtrl::OnSetInfo)
252 #endif
253   */
254     EVT_LIST_ITEM_SELECTED(-1, WxTreeView::OnSelected)
255   /*
256     EVT_LIST_ITEM_DESELECTED(LIST_CTRL, MyListCtrl::OnDeselected)
257     EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
258     EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated)
259     EVT_LIST_ITEM_FOCUSED(LIST_CTRL, MyListCtrl::OnFocused)
260
261     EVT_LIST_COL_CLICK(LIST_CTRL, MyListCtrl::OnColClick)
262     EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, MyListCtrl::OnColRightClick)
263     EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnColBeginDrag)
264     EVT_LIST_COL_DRAGGING(LIST_CTRL, MyListCtrl::OnColDragging)
265     EVT_LIST_COL_END_DRAG(LIST_CTRL, MyListCtrl::OnColEndDrag)
266
267     EVT_LIST_CACHE_HINT(LIST_CTRL, MyListCtrl::OnCacheHint)
268
269 #if USE_CONTEXT_MENU
270     EVT_CONTEXT_MENU(MyListCtrl::OnContextMenu)
271 #endif
272     EVT_CHAR(MyListCtrl::OnChar)
273
274     EVT_RIGHT_DOWN(MyListCtrl::OnRightClick)
275   */
276 END_EVENT_TABLE()
277   
278 } // EO namespace creaImageIO
279
280