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