+ // Reselects the unselected
+ n = GetCtrl(level)->GetItemCount();
+ int after = 0;
+ for (int i = 0; i < n; i++)
+ {
+
+ //Gets current item data
+ ItemData* data = (ItemData*)GetCtrl(level)->GetItemData(i);
+
+ // long item = -1;
+ // for ( ;; )
+ // {
+ // item = GetCtrl(level)->GetNextItem(item,wxLIST_NEXT_ALL);
+ // if ( item == -1 ) break;
+ //Gets current item data
+ // ItemData* data = (ItemData*)GetCtrl(level)->GetItemData(item);
+ // was selected ?
+
+ if (data->selected)
+ {
+ nbselected--;
+ if (nbselected==0)
+ {
+ // if it is the last one we must process the selection
+ mIgnoreSelectedChanged = false;
+ }
+ GetCtrl(level)->SetItemState(i,
+ wxLIST_STATE_SELECTED,
+ wxLIST_MASK_STATE
+ | wxLIST_MASK_TEXT
+ | wxLIST_MASK_IMAGE
+ | wxLIST_MASK_DATA
+ | wxLIST_MASK_WIDTH
+ | wxLIST_MASK_FORMAT);
+ }
+ if (GetCtrl(level)->GetItemState(i,wxLIST_STATE_SELECTED)>0)
+ {
+ after++;
+ }
+
+
+ }
+ mIgnoreSelectedChanged = false;
+ GimmickDebugMessage(1,
+ "WxTreeView::SortLevel : "
+ <<after<<" selected after sorting"
+ <<std::endl);
+
+ }
+ //================================================================
+
+
+ //================================================================
+ void WxTreeView::ValidateSelectedImages(bool isSelection)
+ {
+ GimmickDebugMessage(7,
+ "WxTreeView::ValidateSelectedImages"
+ <<std::endl);
+ const std::vector<tree::Node*>& sel(GetSelected(mLevelList.size()+1));
+ GetGimmickView()->OnSelectionChange(sel,
+ isSelection,(mLastSelected-1),
+ !mIgnoreSelectedChanged);
+
+ }
+ //================================================================
+
+
+ //================================================================
+ void WxTreeView::GetNodes(std::vector<tree::Node*>& nodes, bool direction)
+ {
+ long item = mLastSelected;
+ int level=mLevelList.size()-1;
+ //Gets current item data
+ long adr = GetCtrl(level)->GetItemData(item);
+ //Extracts the node
+ tree::Node* nod = ((ItemData*)adr)->node;
+ for ( ;; )
+ {
+ if(direction)
+ {
+ item = GetCtrl(level)->GetNextItem(item,
+ wxLIST_NEXT_ABOVE);
+ }
+ else
+ {
+ item = GetCtrl(level)->GetNextItem(item,
+ wxLIST_NEXT_BELOW);
+ }
+ if ( item == -1 || item==0 )
+ {
+ break;
+ }
+ if(GetCtrl(level)->GetItemState(item, wxLIST_STATE_SELECTED)==0 )
+ {
+
+ adr = GetCtrl(level)->GetItemData(item);
+ nod = ((ItemData*)adr)->node;
+ nodes.push_back(nod);
+ }
+ }
+
+ }
+ //================================================================
+ //=================================================
+ void WxTreeView::OnKeyDown(wxListEvent &event)
+ {
+ if(event.GetKeyCode() == WXK_DELETE)
+ {
+ wxBusyCursor busy;
+
+ RemoveSelected();
+ GetGimmickView()->ClearSelection();
+ }
+
+ }
+ //================================================================
+
+ //================================================================
+ // Should be in another place : not specific !
+ void WxTreeView::GetSelectedAsString(std::vector<std::string>&s)
+ {
+ int level=mLevelList.size();
+ const std::vector<tree::Node*>& sel=GetSelected(level+1);
+ std::vector<tree::Node*>::const_iterator i;
+
+ for (i=sel.begin(); i!=sel.end(); ++i)
+ {
+ std::string filename=(*i)->GetAttribute("FullFileName");
+ s.push_back(filename);
+ }
+ }
+
+ //================================================================
+ void WxTreeView::GetFilenamesAsString(const std::vector<tree::Node*>& nodes, std::vector<std::string>&s)
+ {
+ std::vector<tree::Node*>::const_iterator i;
+
+ for (i=nodes.begin(); i!=nodes.end(); ++i)
+ {
+ if((*i)->GetLevel()<mLevelList.size())
+ {
+ GetTreeHandler()->LoadChildren(*i,0);
+ GetFilenamesAsString((*i)->GetChildrenList(),s);
+ }
+ else
+ {
+ std::string filename=(*i)->GetAttribute("FullFileName");
+ s.push_back(filename);
+ }
+ }
+ }
+
+ //================================================================
+
+ //================================================================
+ void WxTreeView::GetAttributes(std::vector<std::string>& areShown, std::vector<std::string>& notShown, int level)
+ {
+ areShown.clear();
+ notShown.clear();
+ tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
+ for (a = GetTreeHandler()->GetTree().GetAttributeDescriptorList(level).begin();
+ a != GetTreeHandler()->GetTree().GetAttributeDescriptorList(level).end();
+ ++a)
+ {
+ if(a->GetFlags()==creaImageIO::tree::AttributeDescriptor::EDITABLE && IsAttributeVisible(a->GetName(),level))
+ {
+ areShown.push_back(a->GetName());
+ }
+ }
+ notShown=mLevelList[level-1].notShownAtts;
+ }
+
+ //================================================================
+ void WxTreeView::SetNonVisibleAttributes(const std::vector<std::string>& notShown, int nlevel)
+ {
+ mLevelList[nlevel].notShownAtts=notShown;
+ }
+
+ //================================================================
+ void WxTreeView::CreateCtrl(std::vector<std::string>& notShown, int nlevel)
+ {
+ int ctrl_style = wxLC_REPORT | wxLC_VRULES;
+ int col_style = wxLIST_FORMAT_LEFT;
+ LevelType level;
+ mLevelList[nlevel].SelectedUpToDate = true;
+ mLevelList[nlevel].SortColumn = 0;
+ mLevelList[nlevel].key.clear();
+
+ mLevelList[nlevel].wxCtrl = new wxListCtrl(mLevelList[nlevel].wxSplitter,
+ nlevel,
+ wxDefaultPosition,
+ wxDefaultSize,
+ ctrl_style);
+ wxWindow* oldWin=mLevelList[nlevel].wxSplitter->GetWindow1();
+ mLevelList[nlevel].wxSplitter->ReplaceWindow(oldWin,mLevelList[nlevel].wxCtrl);
+ mLevelList[nlevel].wxSplitter->Initialize(mLevelList[nlevel].wxCtrl);
+
+ // Create the columns : one for each attribute of the level
+ int col = 0;
+ std::string title;
+
+ tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
+ for (a = GetTreeHandler()->GetTree().GetAttributeDescriptorList(nlevel+1).begin();
+ a != GetTreeHandler()->GetTree().GetAttributeDescriptorList(nlevel+1).end();
+ ++a)
+
+ {
+ if(a->GetFlags()!=creaImageIO::tree::AttributeDescriptor::PRIVATE && IsAttributeVisible(a->GetName(),nlevel+1))
+ {
+ title=a->GetName();
+ std::string temp = a->GetKey();
+ if (temp.compare("ID") != 0)
+ {
+ mLevelList[nlevel].wxCtrl->InsertColumn(col,
+ crea::std2wx(title),
+ col_style);
+ col++;
+ }
+ mLevelList[nlevel].key.push_back(a->GetKey());
+ }
+
+ }
+ oldWin->Destroy();
+ UpdateLevel(1);
+ }
+
+ //================================================================
+ bool WxTreeView::IsAttributeVisible(const std::string& val, int level)
+ {
+ std::vector<std::string> ns=mLevelList[level-1].notShownAtts;
+ std::vector<std::string>::iterator it;
+ bool found=false;
+ for(it=ns.begin();it!=ns.end()&&!found;++it)
+ {
+ if(val.compare(*it)==0)
+ {
+ found=true;
+ }
+ }
+
+ return !found;
+ }
+
+ //================================================================
+ //================================================================
+ BEGIN_EVENT_TABLE(WxTreeView, wxPanel)