1 #include <creaImageIOWxTreeView.h>
2 #include <creaImageIOGimmickView.h>
3 #include <creaImageIOSystem.h>
4 #include <wx/splitter.h>
6 ///Comparing function for ordering algorithm. Takes parameters as strings.
7 int wxCALLBACK CompareFunctionStrings(long item1, long item2, long sortData)
9 std::string s1((char*)((long*)item1)[1]);
10 std::string s2((char*)((long*)item2)[1]);
34 ///Comparing function for ordering algorithm. Takes parameters as ints.
35 int wxCALLBACK CompareFunctionInts(long item1, long item2, long sortData)
37 int val1=atoi((char*)((long*)item1)[1]);
38 int val2=atoi((char*)((long*)item2)[1]);
64 //=====================================================================
66 WxTreeView::WxTreeView(TreeHandler* handler,
71 TreeView(handler,gimmick)
73 GimmickDebugMessage(1,"WxTreeView::WxTreeView"
77 // Split part below toolbar into notebook for views and panel
78 // for preview, messages...
80 // mSplitter = new wxSplitterWindow( this , -1);
83 wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
85 int ctrl_style = wxLC_REPORT | /*wxLC_VRULES |*/ wxLC_EDIT_LABELS;
86 int col_style = wxLIST_FORMAT_LEFT;
88 // Creating the ListCtrl for the levels > 0 (not for Root level)
90 i < handler->GetTree().GetNumberOfLevels();
94 GimmickDebugMessage(5,"Creating view for level "<<i
98 // If the first level : parent = this
99 wxWindow* sparent = this;
100 // else parent = last splitter
101 if (i>1) sparent = mLevelList[i-2].wxSplitter;
103 level.wxSplitter = new wxSplitterWindow( sparent , -1);
104 // level.wxSplitter->SetMinimumPaneSize(100);
106 wxListCtrl* ctrl = new wxListCtrl(level.wxSplitter,
112 level.wxSplitter->Initialize(ctrl);
114 // Create the first column : number of children
116 std::string title = "#";
117 if (i<handler->GetTree().GetNumberOfLevels()-1)
119 title += handler->GetTree().GetLevelDescriptor(i+1).GetName();
120 if (title[title.size()-1]!='s')
123 ctrl->InsertColumn(0,crea::std2wx(title),col_style);
126 // Create the columns : one for each attribute of the level
128 tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
129 for (a = handler->GetTree().GetAttributeDescriptorList(i).begin();
130 a != handler->GetTree().GetAttributeDescriptorList(i).end();
134 GimmickDebugMessage(5,"Creating column "<<col<<" : "
137 ctrl->InsertColumn(col,
138 crea::std2wx(a->GetName()),
140 level.key.push_back(a->GetKey());
141 // ctrl->SetColumnWidth(col, wxLIST_AUTOSIZE );
147 mLevelList.push_back(level);
151 /// Initialize the first level splitter
153 sizer->Add( mLevelList[0].wxSplitter ,1, wxGROW ,0);
157 mSelectionMade=false;
159 CreateColorPalette();
167 //=====================================================================
169 //=====================================================================
171 WxTreeView::~WxTreeView()
173 GimmickDebugMessage(1,"WxTreeView::~WxTreeView"
176 //=====================================================================
179 //=====================================================================
186 //=====================================================================
187 std::vector<tree::Node*> WxTreeView::GetSelected(int level)
190 // the selection of upper level
191 std::vector<tree::Node*> sel;
195 sel.push_back(GetTreeHandler()->GetTree().GetTree());
199 int n = GetCtrl(l-1)->GetItemCount();
200 for (int i = 0; i < n; i++)
202 if ( GetCtrl(l-1)->GetItemState(i,wxLIST_STATE_SELECTED))
204 long adr = GetCtrl(l-1)->GetItemData(i);
205 tree::Node* n = ((ItemData*)adr)->node;
208 std::vector<tree::Node*>::iterator it;
210 it = sel.insert ( it , n );
223 //=====================================================================
225 ///Removes selected nodes on given level
226 void WxTreeView::RemoveSelected( int level )
228 std::vector<tree::Node*> sel=GetSelected(level+1);
230 if (wxMessageBox(_T("Delete file(s) ?"),
232 wxYES_NO,this ) == wxYES)
238 std::vector<tree::Node*>::iterator i;
239 for (i=sel.begin(); i!=sel.end(); ++i)
241 GimmickDebugMessage(2,
246 GetTreeHandler()->Remove(*i);
255 //=====================================================================
258 //=====================================================================
259 /// Updates a level of the view (adds or removes children, proganizes, etc.)
260 void WxTreeView::UpdateLevel( int level )
262 GimmickDebugMessage(1,
263 GetTreeHandler()->GetTree().GetLabel()
264 <<" view : updating level "<<level
268 RecursiveUpdateLevel(level);
270 for (i=0; i<level-1; i++)
272 if (!GetSplitter(i)->IsSplit())
273 GetSplitter(i)->SplitVertically( GetCtrl(i), GetSplitter(i+1),
276 if (GetSplitter(i)->IsSplit()) GetSplitter(i)->Unsplit();
279 //=====================================================================
281 /// Recursive method called upon by UpdateLevel to refresh all windows
282 void WxTreeView::RecursiveUpdateLevel( int level )
284 GimmickDebugMessage(2,
285 GetTreeHandler()->GetTree().GetLabel()
286 <<" view : updating level (recursive)"<<level
290 std::vector<tree::Node*> sel=GetSelected(level);
294 // to speed up inserting we hide the control temporarily
296 GetCtrl(l)->DeleteAllItems();
298 std::vector<tree::Node*>::iterator i;
299 //Adds the first item (filter)
300 GetCtrl(l)->InsertItem(0, _T("Filter:"));
301 for (i=sel.begin(); i!=sel.end(); ++i)
303 GimmickDebugMessage(2,
304 "adding children of '"
311 //Adds items (other than the first) and sets their attributes
312 GetTreeHandler()->LoadChildren(*i,1);
313 tree::Node::ChildrenListType::reverse_iterator j;
314 for (j = (*i)->GetChildrenList().rbegin();
315 j!= (*i)->GetChildrenList().rend();
319 item.SetMask(wxLIST_MASK_STATE |
321 // wxLIST_MASK_IMAGE |
323 // wxLIST_MASK_WIDTH |
327 ItemData* data = new ItemData;
336 long id=GetCtrl(l)->InsertItem(item);
338 //Setting first column (number of children)
339 std::ostringstream oss;
340 int n= GetTreeHandler()->GetNumberOfChildren(*j);
342 std::string s(oss.str());
343 item.SetText( crea::std2wx(s));
346 GetCtrl(l)->SetItem(item);
348 //Setting other attributes
349 for (int k=1; k<GetCtrl(l)->GetColumnCount(); k++)
352 std::string val = (*j)->GetAttribute(mLevelList[l].key[k-1]);
353 if (val.size()==0) val = "?";
354 item.SetText( crea::std2wx(val));
356 GetCtrl(l)->SetItem(item);
364 if (level<mLevelList.size()) UpdateLevel(level+1);
367 //=====================================================================
370 //================================================================
371 void WxTreeView::OnSelectedChanged(wxListEvent& event)
373 GimmickDebugMessage(1,
374 GetTreeHandler()->GetTree().GetLabel()
375 <<" view : item selected "
379 info.m_itemId = event.m_itemIndex;
380 mLastSelected=event.m_itemIndex;
381 // retrieve the level
382 wxObject* obj = event.GetEventObject();
383 unsigned int level = 0;
384 for (level = 0; level<mLevelList.size(); ++level)
386 if ( GetCtrl(level) == obj ) break;
388 GimmickDebugMessage(1,
392 if(event.m_itemIndex!=0)
394 if(level<mLevelList.size()-1)
396 mSelected=GetSelected(level+2);
400 mLastLevelSelected=GetSelected(level+2);
407 if (level<mLevelList.size()-1)
409 UpdateLevel( level + 2 );
410 GetGimmickView()->ClearSelection();
412 if (level==mLevelList.size()-2) SelectLowerLevel();
413 if (level==(mLevelList.size()-1)&&mProcess)
415 ValidateSelectedImages ();
420 if(event.GetEventType()==10145)
423 GetCtrl(level)->SetItemText(0,crea::std2wx(""));
424 GetCtrl(level)->EditLabel(event.m_itemIndex);
431 //================================================================
433 //================================================================
434 void WxTreeView::SelectLowerLevel()
437 int level=mLevelList.size()-1;
441 item = GetCtrl(level)->GetNextItem(item,
446 if(item==(GetCtrl(level)->GetItemCount()-1))
457 GetCtrl(level)->SetItemState(item,wxLIST_STATE_SELECTED, wxLIST_MASK_STATE
458 | wxLIST_MASK_TEXT |wxLIST_MASK_IMAGE | wxLIST_MASK_DATA | wxLIST_MASK_WIDTH | wxLIST_MASK_FORMAT);
466 //================================================================
468 //================================================================
469 void WxTreeView::OnColClick(wxListEvent& event)
471 //Obtain the column name and the level that needs to be organized
472 mColumnSelected=event.m_col;
473 GimmickDebugMessage(1,
474 " Column selected: " <<event.m_col
477 if(mColumnSelected!=0)
479 wxObject* ctrl = event.GetEventObject();
480 unsigned int level = 0;
481 for (level = 0; level<mLevelList.size(); ++level)
483 if ( GetCtrl(level) == ctrl ) break;
489 GetCtrl(level)->DeleteItem(0);
490 //Sets the data for the items to be sorted
493 int n = GetCtrl(level)->GetItemCount();
494 for (int i = 0; i < n; i++)
497 //Gets current item data
498 long adr = GetCtrl(level)->GetItemData(i);
499 //Extracts the node and the type of attribute
500 tree::Node* nod = ((ItemData*)adr)->node;
503 (*nod).GetAttributeDescriptor(mLevelList[level].key[mColumnSelected-1]).DecodeType(ty);
505 //Obtains the organizing attribute
506 att=(*nod).GetAttribute(mLevelList[level].key[mColumnSelected-1]);
508 char* d= new char [att.size()+1];
509 strcpy (d, att.c_str());
512 long* lp= new long[2];
516 //Sets it as the data
517 GetCtrl(level)->SetItemData(i,(long)lp);
524 GetCtrl(level)->SortItems(CompareFunctionInts, 0);
528 GetCtrl(level)->SortItems(CompareFunctionStrings, 0);
537 GetCtrl(level)->SortItems(CompareFunctionInts, 1);
541 GetCtrl(level)->SortItems(CompareFunctionStrings, 1);
546 //Resets original data
547 std::vector<tree::Node*>::iterator selection;
548 std::vector<long> change;
552 it = GetCtrl(level)->GetNextItem(it,
557 //Gets current item data, extracts the node and resets it
558 long item = GetCtrl(level)->GetItemData(it);
559 GetCtrl(level)->SetItemData(it,((long*)item)[0]);
560 tree::Node* n= ((ItemData*)((long*)item)[0])->node;
561 if(level<mLevelList.size()-1)
563 for(selection=mSelected.begin();selection!=mSelected.end();++selection)
565 if((*selection)->GetAttribute("ID").compare(n->GetAttribute("ID"))==0)
567 change.push_back(it);
573 for(selection=mLastLevelSelected.begin();selection!=mLastLevelSelected.end();++selection)
575 if((*selection)->GetAttribute("ID").compare(n->GetAttribute("ID"))==0)
577 change.push_back(it);
584 //Resets the selected items
585 std::vector<long>::iterator selectedIts;
586 for(selectedIts=change.begin();selectedIts!=change.end();++selectedIts)
588 GetCtrl(level)->SetItemState(*selectedIts,wxLIST_STATE_SELECTED, wxLIST_MASK_STATE
589 | wxLIST_MASK_TEXT |wxLIST_MASK_IMAGE | wxLIST_MASK_DATA | wxLIST_MASK_WIDTH | wxLIST_MASK_FORMAT);
592 GetCtrl(level)->InsertItem(0,_T("Filter:"));
596 //================================================================
597 void WxTreeView::OnBeginLabelEdit(wxListEvent& event)
599 GimmickDebugMessage(7,
600 "WxTreeView::OnBeginLabelEdit"
602 if(event.m_itemIndex!=0)
609 //================================================================
610 void WxTreeView::OnEndLabelEdit(wxListEvent& event)
612 GimmickDebugMessage(7,
613 "WxTreeView::OnEndLabelEdit"
615 wxObject* ctrl = event.GetEventObject();
616 unsigned int level = 0;
617 for (level = 0; level<mLevelList.size(); ++level)
619 if ( GetCtrl(level) == ctrl ) break;
621 std::string filter = crea::wx2std(event.m_item.m_text.c_str());
626 UpdateLevel(level+1);
631 it = GetCtrl(level)->GetNextItem(it,
637 long adr = GetCtrl(level)->GetItemData(it);
638 for (int j=1;j<GetCtrl(level)->GetColumnCount()-1&&!contains;j++)
640 tree::Node* nod = ((ItemData*)adr)->node;
641 att=(*nod).GetAttribute(mLevelList[level].key[j-1]);
643 if(att.find(filter)<900)
650 GetCtrl(level)->DeleteItem(it);
654 GetGimmickView()->ClearSelection();
655 //GetCtrl(level)->DeleteAllItems();
658 //================================================================
659 void WxTreeView::ValidateSelectedImages()
661 GimmickDebugMessage(7,
662 "WxTreeView::ValidateSelectedImages"
664 std::vector<tree::Node*> sel(GetSelected(mLevelList.size()+1));
665 GetGimmickView()->OnSelectionChange(sel);
668 //================================================================
671 //================================================================
672 void WxTreeView::GetNodes(std::vector<tree::Node*>& nodes, bool direction)
674 long item = mLastSelected;
675 int level=mLevelList.size()-1;
676 //Gets current item data
677 long adr = GetCtrl(level)->GetItemData(item);
679 tree::Node* nod = ((ItemData*)adr)->node;
684 item = GetCtrl(level)->GetNextItem(item,
689 item = GetCtrl(level)->GetNextItem(item,
696 if(GetCtrl(level)->GetItemState(item, wxLIST_STATE_SELECTED)==0 && item!=0)
698 adr = GetCtrl(level)->GetItemData(item);
699 nod = ((ItemData*)adr)->node;
700 nodes.push_back(nod);
706 //================================================================
707 void WxTreeView::GetSelectedAsString(std::vector<std::string>&s)
709 int level=mLevelList.size();
710 std::vector<tree::Node*> sel=GetSelected(level+1);
711 std::vector<tree::Node*>::iterator i;
713 for (i=sel.begin(); i!=sel.end(); ++i)
715 std::string filename=(*i)->GetAttribute("FullFileName");
716 s.push_back(filename);
720 //================================================================
721 void WxTreeView::SetColor(int l)
725 //Setting the color according to the parent
728 item.SetBackgroundColour
729 (wxColourDatabase().Find
730 (crea::std2wx(mColorPalette[colorId])));
733 (*j,wxColourDatabase().Find
734 (crea::std2wx(mColorPalette[colorId]))));
744 else if(l!=mLevelList.size()-1)
746 item.SetBackgroundColour(mColorMap[*i]);
747 mColorMap.insert(NodeColorPair(*j,mColorMap[*i]));
751 item.SetBackgroundColour(mColorMap[*i]);
754 //================================================================
755 void WxTreeView::CreateColorPalette()
757 GimmickDebugMessage(6,"WxTreeView::CreateColorPalette");
758 mColorPalette.push_back("WHITE");
759 mColorPalette.push_back("LIGHT GREY");
760 mColorPalette.push_back("AQUAMARINE");
761 mColorPalette.push_back("MEDIUM FOREST GREEN");
762 mColorPalette.push_back("INDIAN RED");
763 mColorPalette.push_back("KHAKI");
764 mColorPalette.push_back("ORANGE");
765 mColorPalette.push_back("LIGHT BLUE");
766 mColorPalette.push_back("LIGHT STEEL BLUE");
767 mColorPalette.push_back("PINK");
768 mColorPalette.push_back("PLUM");
769 mColorPalette.push_back("PURPLE");
770 mColorPalette.push_back("RED");
771 mColorPalette.push_back("SEA GREEN");
772 mColorPalette.push_back("SIENNA");
773 mColorPalette.push_back("SKY BLUE");
774 mColorPalette.push_back("SLATE BLUE");
775 mColorPalette.push_back("SPRING GREEN");
776 mColorPalette.push_back("TAN");
777 mColorPalette.push_back("THISTLE");
778 mColorPalette.push_back("TURQUOISE");
779 mColorPalette.push_back("VIOLET");
780 mColorPalette.push_back("VIOLET RED");
781 mColorPalette.push_back("WHEAT");
782 mColorPalette.push_back("YELLOW");
783 mColorPalette.push_back("YELLOW GREEN");
784 mColorPalette.push_back("BLUE");
785 mColorPalette.push_back("BLUE VIOLET");
786 mColorPalette.push_back("BROWN");
787 mColorPalette.push_back("CADET BLUE");
788 mColorPalette.push_back("CORAL");
789 mColorPalette.push_back("CORNFLOWER BLUE");
790 mColorPalette.push_back("CYAN");
791 mColorPalette.push_back("DARK GREY");
792 mColorPalette.push_back("DARK GREEN");
793 mColorPalette.push_back("DARK OLIVE GREEN");
794 mColorPalette.push_back("DARK ORCHID");
795 mColorPalette.push_back("DARK SLATE BLUE");
796 mColorPalette.push_back("DARK SLATE GREY");
797 mColorPalette.push_back("DARK TURQUOISE");
798 mColorPalette.push_back("FIREBRICK");
799 mColorPalette.push_back("FOREST GREEN");
800 mColorPalette.push_back("GOLD");
801 mColorPalette.push_back("GOLDENROD");
802 mColorPalette.push_back("GREY");
803 mColorPalette.push_back("GREEN");
804 mColorPalette.push_back("GREEN YELLOW");
805 mColorPalette.push_back("LIME GREEN");
806 mColorPalette.push_back("MAGENTA");
807 mColorPalette.push_back("MAROON");
808 mColorPalette.push_back("MEDIUM AQUAMARINE");
809 mColorPalette.push_back("MEDIUM BLUE");
810 mColorPalette.push_back("MEDIUM GOLDENROD");
811 mColorPalette.push_back("MEDIUM ORCHID");
812 mColorPalette.push_back("MEDIUM SEA GREEN");
813 mColorPalette.push_back("MEDIUM SLATE BLUE");
814 mColorPalette.push_back("MEDIUM SPRING GREEN");
815 mColorPalette.push_back("MEDIUM TURQUOISE");
816 mColorPalette.push_back("MEDIUM VIOLET RED");
817 mColorPalette.push_back("MIDNIGHT BLUE");
818 mColorPalette.push_back("NAVY");
819 mColorPalette.push_back("ORANGE RED");
820 mColorPalette.push_back("ORCHID, PALE GREEN");
821 mColorPalette.push_back("STEEL BLUE");
822 mColorPalette.push_back("BLACK");
826 //================================================================
827 BEGIN_EVENT_TABLE(WxTreeView, wxPanel)
829 EVT_SIZE(MyFrame::OnSize)
831 EVT_MENU(LIST_QUIT, MyFrame::OnQuit)
832 EVT_MENU(LIST_ABOUT, MyFrame::OnAbout)
833 EVT_MENU(LIST_LIST_VIEW, MyFrame::OnListView)
834 EVT_MENU(LIST_REPORT_VIEW, MyFrame::OnReportView)
835 EVT_MENU(LIST_ICON_VIEW, MyFrame::OnIconView)
836 EVT_MENU(LIST_ICON_TEXT_VIEW, MyFrame::OnIconTextView)
837 EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView)
838 EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView)
839 EVT_MENU(LIST_VIRTUAL_VIEW, MyFrame::OnVirtualView)
840 EVT_MENU(LIST_SMALL_VIRTUAL_VIEW, MyFrame::OnSmallVirtualView)
842 EVT_MENU(LIST_FOCUS_LAST, MyFrame::OnFocusLast)
843 EVT_MENU(LIST_TOGGLE_FIRST, MyFrame::OnToggleFirstSel)
844 EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll)
845 EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll)
846 EVT_MENU(LIST_DELETE, MyFrame::OnDelete)
847 EVT_MENU(LIST_ADD, MyFrame::OnAdd)
848 EVT_MENU(LIST_EDIT, MyFrame::OnEdit)
849 EVT_MENU(LIST_DELETE_ALL, MyFrame::OnDeleteAll)
850 EVT_MENU(LIST_SORT, MyFrame::OnSort)
851 EVT_MENU(LIST_SET_FG_COL, MyFrame::OnSetFgColour)
852 EVT_MENU(LIST_SET_BG_COL, MyFrame::OnSetBgColour)
853 EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel)
854 EVT_MENU(LIST_SHOW_COL_INFO, MyFrame::OnShowColInfo)
855 EVT_MENU(LIST_SHOW_SEL_INFO, MyFrame::OnShowSelInfo)
856 EVT_MENU(LIST_FREEZE, MyFrame::OnFreeze)
857 EVT_MENU(LIST_THAW, MyFrame::OnThaw)
858 EVT_MENU(LIST_TOGGLE_LINES, MyFrame::OnToggleLines)
859 EVT_MENU(LIST_MAC_USE_GENERIC, MyFrame::OnToggleMacUseGeneric)
861 EVT_UPDATE_UI(LIST_SHOW_COL_INFO, MyFrame::OnUpdateShowColInfo)
862 EVT_UPDATE_UI(LIST_TOGGLE_MULTI_SEL, MyFrame::OnUpdateToggleMultiSel)
865 BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
866 EVT_LIST_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnBeginDrag)
867 EVT_LIST_BEGIN_RDRAG(LIST_CTRL, MyListCtrl::OnBeginRDrag)
869 EVT_LIST_BEGIN_LABEL_EDIT(-1, WxTreeView::OnBeginLabelEdit)
870 EVT_LIST_END_LABEL_EDIT(-1, WxTreeView::OnEndLabelEdit)
872 EVT_LIST_DELETE_ITEM(LIST_CTRL, MyListCtrl::OnDeleteItem)
873 EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, MyListCtrl::OnDeleteAllItems)
874 #if WXWIN_COMPATIBILITY_2_4
875 EVT_LIST_GET_INFO(LIST_CTRL, MyListCtrl::OnGetInfo)
876 EVT_LIST_SET_INFO(LIST_CTRL, MyListCtrl::OnSetInfo)
879 EVT_LIST_ITEM_SELECTED(-1, WxTreeView::OnSelectedChanged)
881 EVT_LIST_ITEM_DESELECTED(-1, WxTreeView::OnSelectedChanged)
883 EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
884 EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated)
885 EVT_LIST_ITEM_FOCUSED(LIST_CTRL, MyListCtrl::OnFocused)
887 EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, MyListCtrl::OnColRightClick)
889 EVT_LIST_COL_CLICK(-1, WxTreeView::OnColClick)
891 EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnColBeginDrag)
892 EVT_LIST_COL_DRAGGING(LIST_CTRL, MyListCtrl::OnColDragging)
893 EVT_LIST_COL_END_DRAG(LIST_CTRL, MyListCtrl::OnColEndDrag)
895 EVT_LIST_CACHE_HINT(LIST_CTRL, MyListCtrl::OnCacheHint)
898 EVT_CONTEXT_MENU(MyListCtrl::OnContextMenu)
900 EVT_CHAR(MyListCtrl::OnChar)
902 EVT_RIGHT_DOWN(MyListCtrl::OnRightClick)
906 } // EO namespace creaImageIO