1 #include <creaImageIOWxTreeView.h>
2 #include <creaImageIOSystem.h>
3 #include <wx/splitter.h>
7 //=====================================================================
9 WxTreeView::WxTreeView(TreeHandler* handler,
15 GimmickDebugMessage(1,"WxTreeView::WxTreeView"
19 // Split part below toolbar into notebook for views and panel
20 // for preview, messages...
22 // mSplitter = new wxSplitterWindow( this , -1);
25 wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
27 int ctrl_style = wxLC_REPORT;
28 int col_style = wxLIST_FORMAT_LEFT;
30 // Creating the ListCtrl for the levels > 0 (not for Root level)
32 i < handler->GetTree().GetNumberOfLevels();
35 GimmickDebugMessage(5,"Creating ListCtrl for level "<<i
38 wxListCtrl* ctrl = new wxListCtrl(this,
45 // Create the columns : one for each attribute of the level
47 tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
48 for (a = handler->GetTree().GetAttributeDescriptorList(i).begin();
49 a != handler->GetTree().GetAttributeDescriptorList(i).end();
52 GimmickDebugMessage(5,"Creating column "<<col<<" : "
55 ctrl->InsertColumn(col,
56 crea::std2wx(a->GetName()),
58 level.key.push_back(a->GetKey());
59 // ctrl->SetColumnWidth(col, wxLIST_AUTOSIZE );
62 mLevelList.push_back(level);
63 sizer->Add( ctrl ,1, wxGROW ,0);
73 //=====================================================================
75 //=====================================================================
77 WxTreeView::~WxTreeView()
79 GimmickDebugMessage(1,"WxTreeView::~WxTreeView"
82 //=====================================================================
85 //=====================================================================
90 //=====================================================================
92 //=====================================================================
94 void WxTreeView::UpdateLevel( int level )
96 GimmickDebugMessage(1,
97 GetTreeHandler()->GetTree().GetLabel()
98 <<" view : updating level "<<level
101 // the selection of upper level
102 std::vector<tree::Node*> sel;
105 sel.push_back(GetTreeHandler()->GetTree().GetTree());
109 int n = GetCtrl(l-1)->GetItemCount();
110 for (int i = 0; i < n; i++)
112 if ( GetCtrl(l-1)->GetItemState(i,wxLIST_STATE_SELECTED))
114 long adr = GetCtrl(l-1)->GetItemData(i);
115 tree::Node* n = ((ItemData*)adr)->node;
121 // to speed up inserting we hide the control temporarily
123 GetCtrl(l)->DeleteAllItems();
125 std::vector<tree::Node*>::iterator i;
126 for (i=sel.begin(); i!=sel.end(); ++i)
128 GimmickDebugMessage(2,
129 "adding children of '"
134 GetTreeHandler()->LoadChildren(*i,1);
135 tree::Node::ChildrenListType::reverse_iterator j;
136 for (j = (*i)->GetChildrenList().rbegin();
137 j!= (*i)->GetChildrenList().rend();
141 item.SetMask(wxLIST_MASK_STATE |
143 // wxLIST_MASK_IMAGE |
145 // wxLIST_MASK_WIDTH |
149 ItemData* data = new ItemData;
153 long id = GetCtrl(l)->InsertItem(item);
155 for (int k=0; k<GetCtrl(l)->GetColumnCount(); k++)
157 std::string val = (*j)->GetAttribute(mLevelList[l].key[k]);
158 if (val.size()==0) val = "?";
159 GetCtrl(l)->SetItem(id,k, crea::std2wx(val));
160 GetCtrl(l)->SetColumnWidth(k, wxLIST_AUTOSIZE );
169 if (level<mLevelList.size()) UpdateLevel(level+1);
171 //=====================================================================
174 //================================================================
175 void WxTreeView::OnSelected(wxListEvent& event)
177 GimmickDebugMessage(1,
178 GetTreeHandler()->GetTree().GetLabel()
179 <<" view : item selected "
184 info.m_itemId = event.m_itemIndex;
187 // retrieve the level
188 wxObject* obj = event.GetEventObject();
189 unsigned int level = 0;
190 for (level = 0; level<mLevelList.size(); ++level)
192 if ( GetCtrl(level) == obj ) break;
194 GimmickDebugMessage(1,
197 if (level<mLevelList.size()-1) UpdateLevel( level + 2 );
200 //================================================================
204 BEGIN_EVENT_TABLE(WxTreeView, wxPanel)
206 EVT_SIZE(MyFrame::OnSize)
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)
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)
238 EVT_UPDATE_UI(LIST_SHOW_COL_INFO, MyFrame::OnUpdateShowColInfo)
239 EVT_UPDATE_UI(LIST_TOGGLE_MULTI_SEL, MyFrame::OnUpdateToggleMultiSel)
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)
254 EVT_LIST_ITEM_SELECTED(-1, WxTreeView::OnSelected)
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)
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)
267 EVT_LIST_CACHE_HINT(LIST_CTRL, MyListCtrl::OnCacheHint)
270 EVT_CONTEXT_MENU(MyListCtrl::OnContextMenu)
272 EVT_CHAR(MyListCtrl::OnChar)
274 EVT_RIGHT_DOWN(MyListCtrl::OnRightClick)
278 } // EO namespace creaImageIO