]> Creatis software - creaImageIO.git/blob - src2/creaImageIOWxTreeView.cpp
*** empty log message ***
[creaImageIO.git] / src2 / creaImageIOWxTreeView.cpp
1 #include <creaImageIOWxTreeView.h>
2 #include <creaImageIOGimmickView.h>
3 #include <creaImageIOSystem.h>
4 #include <wx/splitter.h>
5 #include <wx/gdicmn.h>
6 ///Comparing function for ordering algorithm. Takes parameters as strings.
7 int wxCALLBACK CompareFunctionStrings(long item1, long item2, long sortData)
8 {       
9         std::string s1((char*)((long*)item1)[1]);
10         std::string s2((char*)((long*)item2)[1]);
11         if(sortData==1)
12         {
13                 // inverse the order
14                 if (s1 < s2)
15                         return 1;
16                 if (s1 > s2)
17                         return -1;
18
19                 return 0;
20         }
21         else
22         {
23                 if (s1 < s2)
24                         return -1;
25                 if (s1 > s2)
26                         return 1;
27
28                 return 0;
29
30         }
31         
32 }
33
34 ///Comparing function for ordering algorithm. Takes parameters as ints.
35 int wxCALLBACK CompareFunctionInts(long item1, long item2, long sortData)
36 {       
37         int val1=atoi((char*)((long*)item1)[1]);
38         int val2=atoi((char*)((long*)item2)[1]);
39         if(sortData==1)
40         {
41                 // inverse the order
42                 if (val1 < val2)
43                         return 1;
44                 if (val1 > val2)
45                         return -1;
46
47                 return 0;
48         }
49         else
50         {
51                 if (val1 < val2)
52                         return -1;
53                 if (val1 > val2)
54                         return 1;
55
56                 return 0;
57
58         }
59         
60 }
61
62 namespace creaImageIO
63 {
64   //=====================================================================
65   // CTor
66   WxTreeView::WxTreeView(TreeHandler* handler,
67                          GimmickView* gimmick,
68                          wxWindow* parent,
69                          const wxWindowID id)
70     : wxPanel(parent,id),
71       TreeView(handler,gimmick)
72   {
73     GimmickDebugMessage(1,"WxTreeView::WxTreeView"
74                         <<std::endl);
75
76     
77     // Split part below toolbar into notebook for views and panel
78     // for preview, messages...
79     // TO DO : Splitter
80     //    mSplitter = new wxSplitterWindow( this , -1);
81
82     // Global sizer
83     wxBoxSizer  *sizer = new wxBoxSizer(wxHORIZONTAL);
84     
85     int ctrl_style = wxLC_REPORT | wxLC_VRULES;
86     int col_style = wxLIST_FORMAT_LEFT;
87
88     // Creating the ListCtrl for the levels > 0 (not for Root level)
89     for (int i = 1;
90          i < handler->GetTree().GetNumberOfLevels();
91          ++i)
92       {
93
94         GimmickDebugMessage(5,"Creating view for level "<<i
95                             <<std::endl);
96         LevelType level;
97
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;
102
103         level.wxSplitter = new wxSplitterWindow( sparent , -1);
104         //          level.wxSplitter->SetMinimumPaneSize(100);
105         
106         wxListCtrl* ctrl = new wxListCtrl(level.wxSplitter,
107                                           i,
108                                           wxDefaultPosition, 
109                                           wxDefaultSize,
110                                           ctrl_style);
111         level.wxCtrl = ctrl;
112         level.wxSplitter->Initialize(ctrl);
113
114         // Create the first column : number of children
115         if(i<handler->GetTree().GetNumberOfLevels()-1)
116         {
117         std::string title = "#";
118         if (i<handler->GetTree().GetNumberOfLevels()-1)
119           {
120             title += handler->GetTree().GetLevelDescriptor(i+1).GetName();
121             if (title[title.size()-1]!='s')
122               title += "s";
123           }
124         ctrl->InsertColumn(0,crea::std2wx(title),col_style);
125         }
126
127         // Create the columns : one for each attribute of the level
128         int col = 1;
129         tree::LevelDescriptor::AttributeDescriptorListType::const_iterator a;
130         for (a  = handler->GetTree().GetAttributeDescriptorList(i).begin();
131              a != handler->GetTree().GetAttributeDescriptorList(i).end();
132              ++a)
133           {
134         
135                 GimmickDebugMessage(5,"Creating column "<<col<<" : "
136                                 <<a->GetName()
137                                 <<std::endl);
138                 ctrl->InsertColumn(col, 
139                                 crea::std2wx(a->GetName()),
140                                 col_style);
141                 level.key.push_back(a->GetKey());
142                 //          ctrl->SetColumnWidth(col, wxLIST_AUTOSIZE );
143                 col++;
144                 
145                 
146           }
147           
148         mLevelList.push_back(level);
149       }
150     
151 #if wxUSE_MENUS
152
153     menu =new wxMenu;
154         wxMenuItem* m1=menu->Append(wxID_ANY, _T("&Sort ascending"));
155         wxMenuItem* m2=menu->Append(wxID_ANY, _T("&Sort descending"));
156         wxMenuItem* m3=menu->Append(wxID_ANY, _T("&Filter"));
157         mAscendingID=m1->GetId();
158         mDescendingID=m2->GetId();
159         mFilterID=m3->GetId();
160         Connect( mAscendingID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnPopupSort) );
161         Connect( mDescendingID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnPopupSort) );
162         Connect( mFilterID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(WxTreeView::OnPopupFilter) );
163         
164 #endif // wxUSE_MENUS
165
166
167     /// Initialize the first level splitter
168  
169       sizer->Add( mLevelList[0].wxSplitter ,1, wxGROW  ,0);
170         mColumnSelected=1;
171         mLastSelected=0;
172         mDirection=true;
173         mSelectionMade=false;
174         mProcess=true;
175         //CreateColorPalette();
176     UpdateLevel(1);
177
178     SetSizer( sizer );     
179     SetAutoLayout(true);
180     Layout();
181
182   }
183   //=====================================================================
184
185   //=====================================================================
186   /// Destructor
187   WxTreeView::~WxTreeView()
188   {
189     GimmickDebugMessage(1,"WxTreeView::~WxTreeView"
190                         <<std::endl);
191   }
192   //=====================================================================
193   
194   
195   //=====================================================================
196   struct ItemData
197   {
198     tree::Node* node;
199         int id;
200   };
201  
202   //=====================================================================
203    std::vector<tree::Node*> WxTreeView::GetSelected(int level)
204   {
205     int l = level - 1;
206     // the selection of upper level
207     std::vector<tree::Node*> sel;
208         
209     if (level == 1) 
210       {
211         sel.push_back(GetTreeHandler()->GetTree().GetTree());
212       }
213     else 
214       {
215         int n = GetCtrl(l-1)->GetItemCount();
216         for (int i = 0; i < n; i++)
217           {
218             if ( GetCtrl(l-1)->GetItemState(i,wxLIST_STATE_SELECTED))
219               {
220                 long adr = GetCtrl(l-1)->GetItemData(i);
221                 tree::Node* n = ((ItemData*)adr)->node;
222                         if(mLastSelected==i)
223                         {
224                                 std::vector<tree::Node*>::iterator it;
225                                 it = sel.begin();
226                                 it = sel.insert ( it , n );
227                         }
228                         else
229                         {
230                                 sel.push_back(n);
231                         }
232               }
233           }     
234       }
235          
236           return sel;
237   }
238
239   //=====================================================================
240   
241   ///Removes selected nodes on given level
242   void WxTreeView::RemoveSelected( int level )
243   {
244           std::vector<tree::Node*> sel=GetSelected(level+1);
245           bool erase=false;
246           if (wxMessageBox(_T("Delete file(s) ?"),
247                          _T("Remove Files"),
248                          wxYES_NO,this ) == wxYES)
249           {
250             erase = true;
251           }
252           if(erase)
253           {
254                 std::vector<tree::Node*>::iterator i;
255                 for (i=sel.begin(); i!=sel.end(); ++i)
256                 {
257                         GimmickDebugMessage(2,
258                                         "deleting '"
259                                         <<(*i)->GetLabel()
260                                         <<"'"<<level
261                                         <<std::endl);
262                                 GetTreeHandler()->Remove(*i);
263                 }
264
265                 UpdateLevel(level);
266           }
267           
268   }
269     
270
271   //=====================================================================
272
273  
274   //=====================================================================
275   /// Updates a level of the view (adds or removes children, proganizes, etc.)
276   void WxTreeView::UpdateLevel( int level )
277   {
278     GimmickDebugMessage(1,
279                         GetTreeHandler()->GetTree().GetLabel()
280                         <<" view : updating level "<<level
281                         <<std::endl);
282     
283     wxBusyCursor busy;
284     RecursiveUpdateLevel(level);
285     int i;
286     for (i=0; i<level-1; i++)
287       {
288         if (!GetSplitter(i)->IsSplit()) 
289           GetSplitter(i)->SplitVertically(  GetCtrl(i), GetSplitter(i+1),
290                                             100 );
291       }
292     if (GetSplitter(i)->IsSplit()) GetSplitter(i)->Unsplit();    
293     
294   }
295   //=====================================================================
296   
297   /// Recursive method called upon by UpdateLevel to refresh all windows
298   void WxTreeView::RecursiveUpdateLevel( int level )
299   {
300           GimmickDebugMessage(2,
301                         GetTreeHandler()->GetTree().GetLabel()
302                         <<" view : updating level (recursive)"<<level
303                         <<std::endl);
304
305
306     std::vector<tree::Node*> sel=GetSelected(level);
307
308           int l = level - 1;
309  
310     // to speed up inserting we hide the control temporarily
311     GetCtrl(l)->Hide();
312     GetCtrl(l)->DeleteAllItems();
313     
314     std::vector<tree::Node*>::iterator i;
315         
316     //Adds the first item (filter)
317    
318         for (i=sel.begin(); i!=sel.end(); ++i)
319       {
320         GimmickDebugMessage(2,
321                             "adding children of '"
322                             <<(*i)->GetLabel()
323                             <<"'"
324                             <<std::endl);
325         int _id=1;
326         
327         //Adds items (other than the first) and sets their attributes 
328            GetCtrl(l)->InsertItem(0, _T(""));
329         GetTreeHandler()->LoadChildren(*i,1);
330         tree::Node::ChildrenListType::reverse_iterator j;
331         for (j = (*i)->GetChildrenList().rbegin(); 
332              j!= (*i)->GetChildrenList().rend(); 
333              ++j)
334           {
335                          wxListItem* item= new wxListItem;
336             item->SetMask(wxLIST_MASK_STATE | 
337                          wxLIST_MASK_TEXT |
338                          //                      wxLIST_MASK_IMAGE |
339                          wxLIST_MASK_DATA |
340                          //                      wxLIST_MASK_WIDTH |
341                          wxLIST_MASK_FORMAT
342                          );
343            
344             ItemData* data = new ItemData;
345             
346                 data->node = *j;
347                 item->SetId(_id);
348
349                 data->id = _id;
350             item->SetData(data);
351             
352                 _id++;
353                 
354                 
355                 //Setting first column (number of children)
356             std::ostringstream oss;
357             int n= 0; //GetTreeHandler()->GetNumberOfChildren(*j);
358             oss << n;
359             std::string s(oss.str());
360             item->SetText( crea::std2wx(s));            
361
362             item->SetColumn(0);
363                  GetCtrl(l)->InsertItem(*item);
364                 //GetCtrl(l)->SetItem(item);
365                 
366                 //Setting other attributes
367                 if(level<mLevelList.size())
368                 { 
369                 for (int k=1; k<GetCtrl(l)->GetColumnCount(); k++)
370               {
371                         std::string val = (*j)->GetAttribute(mLevelList[l].key[k-1]);
372                         if (val.size()==0) val = "?";
373                         item->SetText( crea::std2wx(val));
374                         item->SetColumn(k);
375                         GetCtrl(l)->SetItem(*item);
376                         // Unefficient
377                         //                      GetCtrl(l)->RefreshItem(*item);
378               } 
379                 }
380                 else
381                 {
382                         for (int k=0; k<GetCtrl(l)->GetColumnCount(); k++)
383               {
384                         std::string val = (*j)->GetAttribute(mLevelList[l].key[k]);
385                         if (val.size()==0) val = "?";
386                         item->SetText( crea::std2wx(val));
387                         item->SetColumn(k);
388                         GetCtrl(l)->SetItem(*item);     
389                         //                      GetCtrl(l)->RefreshItem(*item);
390               } 
391                 }
392                   
393           }
394         GetCtrl(l)->DeleteItem(0);
395       }
396     
397     GetCtrl(l)->Show();
398     
399     //  if (level<mLevelList.size()) UpdateLevel(level+1);
400         
401  }
402   //=====================================================================
403
404
405   //================================================================
406   void WxTreeView::OnSelectedChanged(wxListEvent& event)
407   { 
408     GimmickDebugMessage(1,
409                         GetTreeHandler()->GetTree().GetLabel()
410                         <<" view : item selected "
411                         <<std::endl);
412     
413     wxListItem info;
414     info.m_itemId = event.m_itemIndex;
415     mLastSelected = event.m_itemIndex;
416     // retrieve the level
417     wxObject* obj = event.GetEventObject();   
418     unsigned int level = 0;
419     for (level = 0; level<mLevelList.size(); ++level)
420       {
421         if ( GetCtrl(level) == obj ) break;
422       }
423     GimmickDebugMessage(1,
424                         " Level "<<level+1
425                         <<std::endl);
426     /*
427       if(event.m_itemIndex!=0)
428       {*/
429     
430     if(level<mLevelList.size()-1)
431       {
432         //mSelected=GetSelected(level+1); //2);
433       }
434     else if(mProcess)
435       {
436         //mLastLevelSelected=GetSelected(level+1); //2);
437       }
438     else
439       {
440         event.Veto();
441       }
442     
443     // Update the children level (if selection not at last level)
444     if (level<mLevelList.size()-1) 
445       {
446         UpdateLevel( level + 2 ); 
447         // Reset the viewer setting the default image
448         GetGimmickView()->ClearSelection();
449       }
450     // Select all images if the selection is at series level
451     if (level==mLevelList.size()-2) SelectLowerLevel();
452     // Validate selected images if the selection is at image level
453     if (level==(mLevelList.size()-1)&&mProcess) 
454       {
455         if(event.GetEventType()==10145)
456           {
457             ValidateSelectedImages (true);
458           }
459         else
460           {
461             ValidateSelectedImages (false);
462           }
463       }
464     //SetColor(level,event.m_itemIndex);
465     /*}
466       else
467       {
468       if(event.GetEventType()==10145)
469       {
470       
471       GetCtrl(level)->SetItemText(0,crea::std2wx(""));
472       GetCtrl(level)->EditLabel(event.m_itemIndex);
473       }
474       
475       }*/
476     
477     
478   }
479   //================================================================
480
481   //================================================================
482   void WxTreeView::SelectLowerLevel()
483   {
484         long item = -1;
485         int level=mLevelList.size()-1;
486         
487     for ( ;; )
488     {
489                 item = GetCtrl(level)->GetNextItem(item,
490                                      wxLIST_NEXT_ALL);
491         if ( item == -1 )
492             break;
493
494                 if(item==(GetCtrl(level)->GetItemCount()-1))
495                 {
496                         mProcess=true;
497                 }
498                 else
499                 {
500                         mProcess=false;
501                 }
502
503                 /*if(item!=0)
504                 {*/
505                 GetCtrl(level)->SetItemState(item,wxLIST_STATE_SELECTED, wxLIST_MASK_STATE 
506                 | wxLIST_MASK_TEXT |wxLIST_MASK_IMAGE | wxLIST_MASK_DATA | wxLIST_MASK_WIDTH | wxLIST_MASK_FORMAT);
507                 //}
508                 
509     }
510
511         
512   }
513
514   
515   //================================================================
516   //================================================================
517
518   void WxTreeView::OnMouseClick(wxMouseEvent& event)
519   { 
520            if (event.ButtonDown())
521            {
522            }
523           std::cout<<"HELLO WORLD"<<std::endl;
524   }
525   //================================================================
526   //================================================================
527
528   void WxTreeView::OnColClick(wxListEvent& event)
529   { 
530         mColumnSelected=event.m_col;
531         wxPoint clientpt;
532         clientpt.x = wxGetMousePosition().x - this->GetScreenPosition().x;
533         clientpt.y = wxGetMousePosition().y - this->GetScreenPosition().y;
534         senderCtrl = event.GetEventObject(); 
535         unsigned int level = 0;
536         for (level = 0; level<mLevelList.size(); ++level)
537         {
538         if ( GetCtrl(level) == senderCtrl ) break;
539         }
540         /*for(int i=0;i<mColumnSelected;i++)
541         {
542                 clientpt.x+=GetCtrl(level)->GetColumnWidth(i);
543         }
544         for(int i=0;i<level;i++)
545         {
546                 clientpt.x+=GetSplitter(i)->GetSashPosition();
547         }
548         clientpt.y+=level*2;    */
549         if(level==mLevelList.size()-1)
550         {
551                 mColumnSelected+=1;
552                 PopupMenu(menu, clientpt);
553         }
554         else if(mColumnSelected!=0)
555         {
556                 PopupMenu(menu, clientpt);
557         }
558
559   }
560     //================================================================
561   void WxTreeView::OnPopupFilter(wxCommandEvent& event)
562   {
563                 wxBusyCursor busy;
564                  GimmickDebugMessage(7,
565                         "WxTreeView::OnEndLabelEdit" 
566                         <<std::endl);
567           wxObject* ctrl = event.GetEventObject(); 
568                 unsigned int level = 0;
569                 for (level = 0; level<mLevelList.size(); ++level)
570                 {
571                 if ( GetCtrl(level) == senderCtrl ) break;
572                 }
573                 std::string filter = crea::wx2std(wxGetTextFromUser(_T("Enter the filter to apply"), _T("Filter On Column")));
574                 
575                 std::string att;
576                 
577                 long it = -1;
578                 UpdateLevel(level+1);
579                 
580                 std::vector<long> items;
581                 bool in=false;
582                 int del=0;
583                 for ( ;; )
584                 {
585                         it = GetCtrl(level)->GetNextItem(it,
586                                                                                 wxLIST_NEXT_ALL);
587                         if ( it == -1 )
588                                 break;
589                         
590                         long adr = GetCtrl(level)->GetItemData(it);
591                         tree::Node* nod = ((ItemData*)adr)->node;
592                         att=(*nod).GetAttribute(mLevelList[level].key[mColumnSelected-1]);
593                         
594                         
595                         if(att.find(filter)>900)
596                         {
597                                 
598                                 if(!in)
599                                 {
600                                         in=true;
601                                 }
602                                 else
603                                 {
604                                         del+=1;
605                                 }
606                                 
607                                 items.push_back(it-del);
608                         }
609                         
610                 }
611                 std::vector<long>::iterator iter;
612                 for(iter=items.begin();iter!=items.end();++iter)
613                 {
614                         GetCtrl(level)->DeleteItem(*iter);
615                 }
616                 GetGimmickView()->ClearSelection();
617   }
618   //================================================================
619
620   //================================================================
621   void WxTreeView::OnPopupSort(wxCommandEvent& event)
622   {
623                 wxBusyCursor busy;
624                 unsigned int level = 0;
625                 for (level = 0; level<mLevelList.size(); ++level)
626                 {
627                 if ( GetCtrl(level) == senderCtrl ) break;
628                 }
629                 if(event.GetId()==mAscendingID)
630                 {
631                         mDirection=true;
632                 }
633                 else if(event.GetId()==mDescendingID)
634                 {
635                         mDirection=false;
636                 }
637
638         OnSort(level);
639   }
640   //================================================================
641   void WxTreeView::OnSort(int level)
642   {       
643         //Obtain the column name and the level that needs to be organized
644
645         if(level==mLevelList.size()-1||mColumnSelected!=0)
646         {        
647                 int l = level - 1;
648                 //GetCtrl(level)->DeleteItem(0);
649                 //Sets the data for the items to be sorted
650                 std::string att;
651                 unsigned int ty=0;
652                 int n = GetCtrl(level)->GetItemCount();
653                 for (int i = 0; i < n; i++)
654                 {
655                           
656                         //Gets current item data
657                         long adr = GetCtrl(level)->GetItemData(i);
658                         
659                         //Extracts the node and the type of attribute
660                         tree::Node* nod = ((ItemData*)adr)->node;
661                         if(i==0)
662                         {
663                                 (*nod).GetAttributeDescriptor(mLevelList[level].key[mColumnSelected-1]).DecodeType(ty);
664                         }
665                         //Obtains the organizing attribute
666                         att=(*nod).GetAttribute(mLevelList[level].key[mColumnSelected-1]);
667                         
668                         char* d= new char [att.size()+1];
669                         strcpy (d, att.c_str());
670
671                         //Creates array
672                         long* lp= new long[2];
673                         lp[0]=adr;
674                         lp[1]=(long)d;
675                          
676                         //Sets it as the data
677                         GetCtrl(level)->SetItemData(i,(long)lp);
678                 }       
679                   
680                 if(mDirection)
681                 {
682                         if(ty==1)
683                         {
684                                 GetCtrl(level)->SortItems(CompareFunctionInts, 0);
685                         }
686                         else
687                         {
688                                 GetCtrl(level)->SortItems(CompareFunctionStrings, 0);
689                         }
690                         
691                 }
692                 else
693                 {
694                         if(ty==1)
695                         {
696                                 GetCtrl(level)->SortItems(CompareFunctionInts, 1);
697                         }
698                         else
699                         {
700                                 GetCtrl(level)->SortItems(CompareFunctionStrings, 1);
701                         }
702                 }
703
704                 //Resets original data
705                 std::vector<tree::Node*>::iterator selection;
706                 std::vector<long> change;
707                 long it = -1;
708                 for ( ;; )
709                 {
710                         it = GetCtrl(level)->GetNextItem(it,
711                                                                                 wxLIST_NEXT_ALL);
712                         if ( it == -1 )
713                                 break;
714                         
715                         //Gets current item data, extracts the node and resets it
716                         long item = GetCtrl(level)->GetItemData(it);
717                         GetCtrl(level)->SetItemData(it,((long*)item)[0]);
718                         tree::Node* n= ((ItemData*)((long*)item)[0])->node;
719                         if(level<mLevelList.size()-1)
720                         {
721                                 for(selection=mSelected.begin();selection!=mSelected.end();++selection)
722                                 {
723                                         if((*selection)->GetAttribute("ID").compare(n->GetAttribute("ID"))==0)
724                                         {
725                                                 change.push_back(it);   
726                                         }
727                                 }
728                         }
729                         else
730                         {
731                                 for(selection=mLastLevelSelected.begin();selection!=mLastLevelSelected.end();++selection)
732                                 {
733                                         if((*selection)->GetAttribute("ID").compare(n->GetAttribute("ID"))==0)
734                                         {
735                                                 change.push_back(it);   
736                                         }
737                                 }
738                         }
739                         
740                         
741                 }
742                 //Resets the selected items
743                 std::vector<long>::iterator selectedIts;
744                 for(selectedIts=change.begin();selectedIts!=change.end();++selectedIts)
745                 {
746                         GetCtrl(level)->SetItemState(*selectedIts,wxLIST_STATE_SELECTED, wxLIST_MASK_STATE 
747                 | wxLIST_MASK_TEXT |wxLIST_MASK_IMAGE | wxLIST_MASK_DATA | wxLIST_MASK_WIDTH | wxLIST_MASK_FORMAT);
748                         
749                 }
750                 //GetCtrl(level)->InsertItem(0,_T("Filter:"));
751         }
752         
753    }
754  
755   //================================================================
756   void WxTreeView::ValidateSelectedImages(bool isSelection)
757   {
758     GimmickDebugMessage(7,
759                         "WxTreeView::ValidateSelectedImages" 
760                         <<std::endl);
761     std::vector<tree::Node*> sel(GetSelected(mLevelList.size()+1));
762         GetGimmickView()->OnSelectionChange(sel,isSelection,(mLastSelected-1), mProcess);
763  
764   }
765   //================================================================
766
767
768   //================================================================
769   void WxTreeView::GetNodes(std::vector<tree::Node*>& nodes, bool direction)
770   {
771         long item = mLastSelected;
772         int level=mLevelList.size()-1;
773         //Gets current item data
774         long adr = GetCtrl(level)->GetItemData(item);
775         //Extracts the node
776         tree::Node* nod = ((ItemData*)adr)->node;
777     for ( ;; )
778     {
779                 if(direction)
780                 {
781                         item = GetCtrl(level)->GetNextItem(item,
782                                      wxLIST_NEXT_ABOVE);
783                 }
784                 else
785                 {
786                         item = GetCtrl(level)->GetNextItem(item,
787                                      wxLIST_NEXT_BELOW);
788                 }
789         if ( item == -1  )
790                 {
791             break;
792                 }
793                 if(GetCtrl(level)->GetItemState(item, wxLIST_STATE_SELECTED)==0 && item!=0)
794                 {
795                         adr = GetCtrl(level)->GetItemData(item);
796                         nod = ((ItemData*)adr)->node;
797                         nodes.push_back(nod);
798                 }
799     }
800
801   }
802
803   //================================================================
804   void WxTreeView::GetSelectedAsString(std::vector<std::string>&s)
805   {
806           int level=mLevelList.size();
807         std::vector<tree::Node*> sel=GetSelected(level+1);
808         std::vector<tree::Node*>::iterator i;
809         
810     for (i=sel.begin(); i!=sel.end(); ++i)
811       {
812                   std::string filename=(*i)->GetAttribute("FullFileName");
813                   s.push_back(filename);
814           }
815   }
816
817    //================================================================
818   void WxTreeView::SetColor(int l, int item)
819   {
820           int colorId=12;
821           GetCtrl(l)->SetItemTextColour(item, wxColourDatabase().Find
822                    (crea::std2wx(mColorPalette[colorId])));
823           GetCtrl(l)->SetItemState(item,wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED);  /*
824           int colorId=0;
825           //Setting the color according to the parent
826                 if(l==0)
827                 {
828                 item.SetBackgroundColour
829                   (wxColourDatabase().Find
830                    (crea::std2wx(mColorPalette[colorId]))); 
831                 mColorMap.insert
832                   (NodeColorPair
833                    (*j,wxColourDatabase().Find
834                     (crea::std2wx(mColorPalette[colorId]))));
835                 if(colorId<64)
836                   {
837                     colorId++;
838                   }
839                 else
840                         {
841                           colorId=0;
842                         }
843                 }
844                 else if(l!=mLevelList.size()-1)
845                   {
846                     item.SetBackgroundColour(mColorMap[*i]); 
847                         mColorMap.insert(NodeColorPair(*j,mColorMap[*i]));
848                 }
849                 else
850                 {
851                         item.SetBackgroundColour(mColorMap[*i]); 
852                 }*/
853   }
854   //================================================================
855   void WxTreeView::CreateColorPalette()
856   {
857   GimmickDebugMessage(6,"WxTreeView::CreateColorPalette");
858   mColorPalette.push_back("WHITE");
859   mColorPalette.push_back("LIGHT GREY");
860   mColorPalette.push_back("AQUAMARINE");
861   mColorPalette.push_back("MEDIUM FOREST GREEN");
862   mColorPalette.push_back("INDIAN RED");
863   mColorPalette.push_back("KHAKI");
864   mColorPalette.push_back("ORANGE");
865   mColorPalette.push_back("LIGHT BLUE");
866   mColorPalette.push_back("LIGHT STEEL BLUE");
867   mColorPalette.push_back("PINK");
868   mColorPalette.push_back("PLUM");
869   mColorPalette.push_back("PURPLE");
870   mColorPalette.push_back("RED");
871   mColorPalette.push_back("SEA GREEN");
872   mColorPalette.push_back("SIENNA");
873   mColorPalette.push_back("SKY BLUE");
874   mColorPalette.push_back("SLATE BLUE");
875   mColorPalette.push_back("SPRING GREEN");
876   mColorPalette.push_back("TAN");
877   mColorPalette.push_back("THISTLE");
878   mColorPalette.push_back("TURQUOISE");
879   mColorPalette.push_back("VIOLET");
880   mColorPalette.push_back("VIOLET RED");
881   mColorPalette.push_back("WHEAT");
882   mColorPalette.push_back("YELLOW");
883   mColorPalette.push_back("YELLOW GREEN");
884   mColorPalette.push_back("BLUE");
885   mColorPalette.push_back("BLUE VIOLET");
886   mColorPalette.push_back("BROWN");
887   mColorPalette.push_back("CADET BLUE");
888   mColorPalette.push_back("CORAL");
889   mColorPalette.push_back("CORNFLOWER BLUE");
890   mColorPalette.push_back("CYAN");
891   mColorPalette.push_back("DARK GREY");
892   mColorPalette.push_back("DARK GREEN");
893   mColorPalette.push_back("DARK OLIVE GREEN");
894   mColorPalette.push_back("DARK ORCHID");
895   mColorPalette.push_back("DARK SLATE BLUE");
896   mColorPalette.push_back("DARK SLATE GREY");
897   mColorPalette.push_back("DARK TURQUOISE");
898   mColorPalette.push_back("FIREBRICK");
899   mColorPalette.push_back("FOREST GREEN");
900   mColorPalette.push_back("GOLD");
901   mColorPalette.push_back("GOLDENROD");
902   mColorPalette.push_back("GREY");
903   mColorPalette.push_back("GREEN");
904   mColorPalette.push_back("GREEN YELLOW");
905   mColorPalette.push_back("LIME GREEN");
906   mColorPalette.push_back("MAGENTA");
907   mColorPalette.push_back("MAROON");
908   mColorPalette.push_back("MEDIUM AQUAMARINE");
909   mColorPalette.push_back("MEDIUM BLUE");
910   mColorPalette.push_back("MEDIUM GOLDENROD");
911   mColorPalette.push_back("MEDIUM ORCHID");
912   mColorPalette.push_back("MEDIUM SEA GREEN");
913   mColorPalette.push_back("MEDIUM SLATE BLUE");
914   mColorPalette.push_back("MEDIUM SPRING GREEN");
915   mColorPalette.push_back("MEDIUM TURQUOISE");
916   mColorPalette.push_back("MEDIUM VIOLET RED");
917   mColorPalette.push_back("MIDNIGHT BLUE");
918   mColorPalette.push_back("NAVY");
919   mColorPalette.push_back("ORANGE RED");
920   mColorPalette.push_back("ORCHID, PALE GREEN");
921   mColorPalette.push_back("STEEL BLUE");
922   mColorPalette.push_back("BLACK");
923
924
925   }
926   //================================================================
927   BEGIN_EVENT_TABLE(WxTreeView, wxPanel)   
928   /*
929     EVT_SIZE(MyFrame::OnSize)
930
931     EVT_MENU(LIST_QUIT, MyFrame::OnQuit)
932     EVT_MENU(LIST_ABOUT, MyFrame::OnAbout)
933     EVT_MENU(LIST_LIST_VIEW, MyFrame::OnListView)
934     EVT_MENU(LIST_REPORT_VIEW, MyFrame::OnReportView)
935     EVT_MENU(LIST_ICON_VIEW, MyFrame::OnIconView)
936     EVT_MENU(LIST_ICON_TEXT_VIEW, MyFrame::OnIconTextView)
937     EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView)
938     EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView)
939     EVT_MENU(LIST_VIRTUAL_VIEW, MyFrame::OnVirtualView)
940     EVT_MENU(LIST_SMALL_VIRTUAL_VIEW, MyFrame::OnSmallVirtualView)
941
942     EVT_MENU(LIST_FOCUS_LAST, MyFrame::OnFocusLast)
943     EVT_MENU(LIST_TOGGLE_FIRST, MyFrame::OnToggleFirstSel)
944     EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll)
945     EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll)
946     EVT_MENU(LIST_DELETE, MyFrame::OnDelete)
947     EVT_MENU(LIST_ADD, MyFrame::OnAdd)
948     EVT_MENU(LIST_EDIT, MyFrame::OnEdit)
949     EVT_MENU(LIST_DELETE_ALL, MyFrame::OnDeleteAll)
950     EVT_MENU(LIST_SORT, MyFrame::OnSort)
951     EVT_MENU(LIST_SET_FG_COL, MyFrame::OnSetFgColour)
952     EVT_MENU(LIST_SET_BG_COL, MyFrame::OnSetBgColour)
953     EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel)
954     EVT_MENU(LIST_SHOW_COL_INFO, MyFrame::OnShowColInfo)
955     EVT_MENU(LIST_SHOW_SEL_INFO, MyFrame::OnShowSelInfo)
956     EVT_MENU(LIST_FREEZE, MyFrame::OnFreeze)
957     EVT_MENU(LIST_THAW, MyFrame::OnThaw)
958     EVT_MENU(LIST_TOGGLE_LINES, MyFrame::OnToggleLines)
959     EVT_MENU(LIST_MAC_USE_GENERIC, MyFrame::OnToggleMacUseGeneric)
960
961     EVT_UPDATE_UI(LIST_SHOW_COL_INFO, MyFrame::OnUpdateShowColInfo)
962     EVT_UPDATE_UI(LIST_TOGGLE_MULTI_SEL, MyFrame::OnUpdateToggleMultiSel)
963 END_EVENT_TABLE()
964
965 BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
966     EVT_LIST_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnBeginDrag)
967     EVT_LIST_BEGIN_RDRAG(LIST_CTRL, MyListCtrl::OnBeginRDrag)
968         
969     EVT_LIST_BEGIN_LABEL_EDIT(-1, WxTreeView::OnBeginLabelEdit)
970     EVT_LIST_END_LABEL_EDIT(-1, WxTreeView::OnEndLabelEdit)
971         
972     EVT_LIST_DELETE_ITEM(LIST_CTRL, MyListCtrl::OnDeleteItem)
973     EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, MyListCtrl::OnDeleteAllItems)
974 #if WXWIN_COMPATIBILITY_2_4
975     EVT_LIST_GET_INFO(LIST_CTRL, MyListCtrl::OnGetInfo)
976     EVT_LIST_SET_INFO(LIST_CTRL, MyListCtrl::OnSetInfo)
977 #endif
978   */
979     EVT_LIST_ITEM_SELECTED(-1, WxTreeView::OnSelectedChanged)
980   
981     EVT_LIST_ITEM_DESELECTED(-1, WxTreeView::OnSelectedChanged)
982         /*
983     EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
984     EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated)
985     EVT_LIST_ITEM_FOCUSED(LIST_CTRL, MyListCtrl::OnFocused)
986 */
987     EVT_LIST_COL_RIGHT_CLICK(-1, WxTreeView::OnColClick)
988         
989     EVT_LIST_COL_CLICK(-1, WxTreeView::OnColClick)
990
991         //EVT_LEFT_DOWN(WxTreeView::OnMouseClick)
992         /*
993     EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnColBeginDrag)
994     EVT_LIST_COL_DRAGGING(LIST_CTRL, MyListCtrl::OnColDragging)
995     EVT_LIST_COL_END_DRAG(LIST_CTRL, MyListCtrl::OnColEndDrag)
996
997     EVT_LIST_CACHE_HINT(LIST_CTRL, MyListCtrl::OnCacheHint)
998
999 #if USE_CONTEXT_MENU
1000     EVT_CONTEXT_MENU(MyListCtrl::OnContextMenu)
1001 #endif
1002     EVT_CHAR(MyListCtrl::OnChar)
1003
1004     EVT_RIGHT_DOWN(MyListCtrl::OnRightClick)
1005   */
1006 END_EVENT_TABLE()
1007   
1008 } // EO namespace creaImageIO
1009