]> Creatis software - creaImageIO.git/blob - src2/creaImageIOWxTreeView.cpp
5cd382543dfea9a8774dfffc25b7756ecfc73e3e
[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         clientpt.x+=(mColumnSelected)*(GetCtrl(0)->GetColumnWidth(mColumnSelected));
506         wxPoint screenpt = ClientToScreen(clientpt);
507         if(mColumnSelected!=0)
508         {
509     PopupMenu(menu, clientpt);
510         }
511
512   }
513     //================================================================
514   void WxTreeView::OnPopupFilter(wxCommandEvent& event)
515   {
516                 wxBusyCursor busy;
517                  GimmickDebugMessage(7,
518                         "WxTreeView::OnEndLabelEdit" 
519                         <<std::endl);
520           wxObject* ctrl = event.GetEventObject(); 
521                 unsigned int level = 0;
522                 for (level = 0; level<mLevelList.size(); ++level)
523                 {
524                 if ( GetCtrl(level) == senderCtrl ) break;
525                 }
526                 std::string filter = wxGetTextFromUser(_T("Enter the filter to apply"), _T("Filter On Column"));
527                 
528                 std::string att;
529                 
530                 long it = -1;
531                 UpdateLevel(level+1);
532                 
533                 for ( ;; )
534                 {
535                         bool contains=false;
536                         it = GetCtrl(level)->GetNextItem(it,
537                                                                                 wxLIST_NEXT_ALL);
538                         if ( it == -1 )
539                                 break;
540                         
541                         long adr = GetCtrl(level)->GetItemData(it);
542                         tree::Node* nod = ((ItemData*)adr)->node;
543                         att=(*nod).GetAttribute(mLevelList[level].key[mColumnSelected-1]);
544                         
545                         if(att.find(filter)>900)
546                         {
547                                 GetCtrl(level)->DeleteItem(it);
548                         }
549                         
550                 }
551                 GetGimmickView()->ClearSelection();
552   }
553   //================================================================
554
555   //================================================================
556   void WxTreeView::OnPopupSort(wxCommandEvent& event)
557   {
558                 wxBusyCursor busy;
559                 unsigned int level = 0;
560                 for (level = 0; level<mLevelList.size(); ++level)
561                 {
562                 if ( GetCtrl(level) == senderCtrl ) break;
563                 }
564                 if(event.GetId()==mAscendingID)
565                 {
566                         mDirection=true;
567                 }
568                 else if(event.GetId()==mDescendingID)
569                 {
570                         mDirection=false;
571                 }
572
573         OnSort(level);
574   }
575   //================================================================
576   void WxTreeView::OnSort(int level)
577   {       
578         //Obtain the column name and the level that needs to be organized
579
580         if(mColumnSelected!=0)
581         {        
582                 int l = level - 1;
583                 //GetCtrl(level)->DeleteItem(0);
584                 //Sets the data for the items to be sorted
585                 std::string att;
586                 unsigned int ty=0;
587                 int n = GetCtrl(level)->GetItemCount();
588                 for (int i = 0; i < n; i++)
589                 {
590                           
591                         //Gets current item data
592                         long adr = GetCtrl(level)->GetItemData(i);
593                         
594                         //Extracts the node and the type of attribute
595                         tree::Node* nod = ((ItemData*)adr)->node;
596                         if(i==0)
597                         {
598                                 (*nod).GetAttributeDescriptor(mLevelList[level].key[mColumnSelected-1]).DecodeType(ty);
599                         }
600                         //Obtains the organizing attribute
601                         att=(*nod).GetAttribute(mLevelList[level].key[mColumnSelected-1]);
602                         
603                         char* d= new char [att.size()+1];
604                         strcpy (d, att.c_str());
605
606                         //Creates array
607                         long* lp= new long[2];
608                         lp[0]=adr;
609                         lp[1]=(long)d;
610                          
611                         //Sets it as the data
612                         GetCtrl(level)->SetItemData(i,(long)lp);
613                 }       
614                   
615                 if(mDirection)
616                 {
617                         if(ty==1)
618                         {
619                                 GetCtrl(level)->SortItems(CompareFunctionInts, 0);
620                         }
621                         else
622                         {
623                                 GetCtrl(level)->SortItems(CompareFunctionStrings, 0);
624                         }
625                         
626                 }
627                 else
628                 {
629                         if(ty==1)
630                         {
631                                 GetCtrl(level)->SortItems(CompareFunctionInts, 1);
632                         }
633                         else
634                         {
635                                 GetCtrl(level)->SortItems(CompareFunctionStrings, 1);
636                         }
637                 }
638
639                 //Resets original data
640                 std::vector<tree::Node*>::iterator selection;
641                 std::vector<long> change;
642                 long it = -1;
643                 for ( ;; )
644                 {
645                         it = GetCtrl(level)->GetNextItem(it,
646                                                                                 wxLIST_NEXT_ALL);
647                         if ( it == -1 )
648                                 break;
649                         
650                         //Gets current item data, extracts the node and resets it
651                         long item = GetCtrl(level)->GetItemData(it);
652                         GetCtrl(level)->SetItemData(it,((long*)item)[0]);
653                         tree::Node* n= ((ItemData*)((long*)item)[0])->node;
654                         if(level<mLevelList.size()-1)
655                         {
656                                 for(selection=mSelected.begin();selection!=mSelected.end();++selection)
657                                 {
658                                         if((*selection)->GetAttribute("ID").compare(n->GetAttribute("ID"))==0)
659                                         {
660                                                 change.push_back(it);   
661                                         }
662                                 }
663                         }
664                         else
665                         {
666                                 for(selection=mLastLevelSelected.begin();selection!=mLastLevelSelected.end();++selection)
667                                 {
668                                         if((*selection)->GetAttribute("ID").compare(n->GetAttribute("ID"))==0)
669                                         {
670                                                 change.push_back(it);   
671                                         }
672                                 }
673                         }
674                         
675                         
676                 }
677                 //Resets the selected items
678                 std::vector<long>::iterator selectedIts;
679                 for(selectedIts=change.begin();selectedIts!=change.end();++selectedIts)
680                 {
681                         GetCtrl(level)->SetItemState(*selectedIts,wxLIST_STATE_SELECTED, wxLIST_MASK_STATE 
682                 | wxLIST_MASK_TEXT |wxLIST_MASK_IMAGE | wxLIST_MASK_DATA | wxLIST_MASK_WIDTH | wxLIST_MASK_FORMAT);
683                         
684                 }
685                 //GetCtrl(level)->InsertItem(0,_T("Filter:"));
686         }
687         
688    }
689   //================================================================
690   void WxTreeView::OnBeginLabelEdit(wxListEvent& event)
691   {
692         GimmickDebugMessage(7,
693                         "WxTreeView::OnBeginLabelEdit" 
694                         <<std::endl);
695         if(event.m_itemIndex!=0)
696         {
697                 event.Veto();
698         }
699
700   }
701
702   //================================================================
703   void WxTreeView::OnEndLabelEdit(wxListEvent& event)
704   {
705           GimmickDebugMessage(7,
706                         "WxTreeView::OnEndLabelEdit" 
707                         <<std::endl);
708           wxObject* ctrl = event.GetEventObject(); 
709                 unsigned int level = 0;
710                 for (level = 0; level<mLevelList.size(); ++level)
711                 {
712                 if ( GetCtrl(level) == ctrl ) break;
713                 }
714                 std::string filter = crea::wx2std(event.m_item.m_text.c_str());
715                 
716                 std::string att;
717                 
718                 long it = -1;
719                 UpdateLevel(level+1);
720                 
721                 for ( ;; )
722                 {
723                         bool contains=false;
724                         it = GetCtrl(level)->GetNextItem(it,
725                                                                                 wxLIST_NEXT_ALL);
726                         if ( it == -1 )
727                                 break;
728                         if(it!=0)
729                         {
730                                 long adr = GetCtrl(level)->GetItemData(it);
731                                 for (int j=1;j<GetCtrl(level)->GetColumnCount()-1&&!contains;j++)
732                                 {
733                                 tree::Node* nod = ((ItemData*)adr)->node;
734                                 att=(*nod).GetAttribute(mLevelList[level].key[j-1]);
735                         
736                                 if(att.find(filter)<900)
737                                 {
738                                         contains=true;
739                                 }
740                                 }
741                                 if(!contains)
742                                 {
743                                         GetCtrl(level)->DeleteItem(it);
744                                 }
745                         }
746                 }
747                 GetGimmickView()->ClearSelection();
748                 //GetCtrl(level)->DeleteAllItems();
749
750   }
751   //================================================================
752   void WxTreeView::ValidateSelectedImages(bool isSelection)
753   {
754     GimmickDebugMessage(7,
755                         "WxTreeView::ValidateSelectedImages" 
756                         <<std::endl);
757     std::vector<tree::Node*> sel(GetSelected(mLevelList.size()+1));
758         GetGimmickView()->OnSelectionChange(sel,isSelection,(mLastSelected-1), mProcess);
759  
760   }
761   //================================================================
762
763
764   //================================================================
765   void WxTreeView::GetNodes(std::vector<tree::Node*>& nodes, bool direction)
766   {
767         long item = mLastSelected;
768         int level=mLevelList.size()-1;
769         //Gets current item data
770         long adr = GetCtrl(level)->GetItemData(item);
771         //Extracts the node
772         tree::Node* nod = ((ItemData*)adr)->node;
773     for ( ;; )
774     {
775                 if(direction)
776                 {
777                         item = GetCtrl(level)->GetNextItem(item,
778                                      wxLIST_NEXT_ABOVE);
779                 }
780                 else
781                 {
782                         item = GetCtrl(level)->GetNextItem(item,
783                                      wxLIST_NEXT_BELOW);
784                 }
785         if ( item == -1  )
786                 {
787             break;
788                 }
789                 if(GetCtrl(level)->GetItemState(item, wxLIST_STATE_SELECTED)==0 && item!=0)
790                 {
791                         adr = GetCtrl(level)->GetItemData(item);
792                         nod = ((ItemData*)adr)->node;
793                         nodes.push_back(nod);
794                 }
795     }
796
797   }
798
799   //================================================================
800   void WxTreeView::GetSelectedAsString(std::vector<std::string>&s)
801   {
802           int level=mLevelList.size();
803         std::vector<tree::Node*> sel=GetSelected(level+1);
804         std::vector<tree::Node*>::iterator i;
805         
806     for (i=sel.begin(); i!=sel.end(); ++i)
807       {
808                   std::string filename=(*i)->GetAttribute("FullFileName");
809                   s.push_back(filename);
810           }
811   }
812
813    //================================================================
814   void WxTreeView::SetColor(int l, int item)
815   {
816           int colorId=12;
817           GetCtrl(l)->SetItemTextColour(item, wxColourDatabase().Find
818                    (crea::std2wx(mColorPalette[colorId])));
819           GetCtrl(l)->SetItemState(item,wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED);  /*
820           int colorId=0;
821           //Setting the color according to the parent
822                 if(l==0)
823                 {
824                 item.SetBackgroundColour
825                   (wxColourDatabase().Find
826                    (crea::std2wx(mColorPalette[colorId]))); 
827                 mColorMap.insert
828                   (NodeColorPair
829                    (*j,wxColourDatabase().Find
830                     (crea::std2wx(mColorPalette[colorId]))));
831                 if(colorId<64)
832                   {
833                     colorId++;
834                   }
835                 else
836                         {
837                           colorId=0;
838                         }
839                 }
840                 else if(l!=mLevelList.size()-1)
841                   {
842                     item.SetBackgroundColour(mColorMap[*i]); 
843                         mColorMap.insert(NodeColorPair(*j,mColorMap[*i]));
844                 }
845                 else
846                 {
847                         item.SetBackgroundColour(mColorMap[*i]); 
848                 }*/
849   }
850   //================================================================
851   void WxTreeView::CreateColorPalette()
852   {
853   GimmickDebugMessage(6,"WxTreeView::CreateColorPalette");
854   mColorPalette.push_back("WHITE");
855   mColorPalette.push_back("LIGHT GREY");
856   mColorPalette.push_back("AQUAMARINE");
857   mColorPalette.push_back("MEDIUM FOREST GREEN");
858   mColorPalette.push_back("INDIAN RED");
859   mColorPalette.push_back("KHAKI");
860   mColorPalette.push_back("ORANGE");
861   mColorPalette.push_back("LIGHT BLUE");
862   mColorPalette.push_back("LIGHT STEEL BLUE");
863   mColorPalette.push_back("PINK");
864   mColorPalette.push_back("PLUM");
865   mColorPalette.push_back("PURPLE");
866   mColorPalette.push_back("RED");
867   mColorPalette.push_back("SEA GREEN");
868   mColorPalette.push_back("SIENNA");
869   mColorPalette.push_back("SKY BLUE");
870   mColorPalette.push_back("SLATE BLUE");
871   mColorPalette.push_back("SPRING GREEN");
872   mColorPalette.push_back("TAN");
873   mColorPalette.push_back("THISTLE");
874   mColorPalette.push_back("TURQUOISE");
875   mColorPalette.push_back("VIOLET");
876   mColorPalette.push_back("VIOLET RED");
877   mColorPalette.push_back("WHEAT");
878   mColorPalette.push_back("YELLOW");
879   mColorPalette.push_back("YELLOW GREEN");
880   mColorPalette.push_back("BLUE");
881   mColorPalette.push_back("BLUE VIOLET");
882   mColorPalette.push_back("BROWN");
883   mColorPalette.push_back("CADET BLUE");
884   mColorPalette.push_back("CORAL");
885   mColorPalette.push_back("CORNFLOWER BLUE");
886   mColorPalette.push_back("CYAN");
887   mColorPalette.push_back("DARK GREY");
888   mColorPalette.push_back("DARK GREEN");
889   mColorPalette.push_back("DARK OLIVE GREEN");
890   mColorPalette.push_back("DARK ORCHID");
891   mColorPalette.push_back("DARK SLATE BLUE");
892   mColorPalette.push_back("DARK SLATE GREY");
893   mColorPalette.push_back("DARK TURQUOISE");
894   mColorPalette.push_back("FIREBRICK");
895   mColorPalette.push_back("FOREST GREEN");
896   mColorPalette.push_back("GOLD");
897   mColorPalette.push_back("GOLDENROD");
898   mColorPalette.push_back("GREY");
899   mColorPalette.push_back("GREEN");
900   mColorPalette.push_back("GREEN YELLOW");
901   mColorPalette.push_back("LIME GREEN");
902   mColorPalette.push_back("MAGENTA");
903   mColorPalette.push_back("MAROON");
904   mColorPalette.push_back("MEDIUM AQUAMARINE");
905   mColorPalette.push_back("MEDIUM BLUE");
906   mColorPalette.push_back("MEDIUM GOLDENROD");
907   mColorPalette.push_back("MEDIUM ORCHID");
908   mColorPalette.push_back("MEDIUM SEA GREEN");
909   mColorPalette.push_back("MEDIUM SLATE BLUE");
910   mColorPalette.push_back("MEDIUM SPRING GREEN");
911   mColorPalette.push_back("MEDIUM TURQUOISE");
912   mColorPalette.push_back("MEDIUM VIOLET RED");
913   mColorPalette.push_back("MIDNIGHT BLUE");
914   mColorPalette.push_back("NAVY");
915   mColorPalette.push_back("ORANGE RED");
916   mColorPalette.push_back("ORCHID, PALE GREEN");
917   mColorPalette.push_back("STEEL BLUE");
918   mColorPalette.push_back("BLACK");
919
920
921   }
922   //================================================================
923   BEGIN_EVENT_TABLE(WxTreeView, wxPanel)   
924   /*
925     EVT_SIZE(MyFrame::OnSize)
926
927     EVT_MENU(LIST_QUIT, MyFrame::OnQuit)
928     EVT_MENU(LIST_ABOUT, MyFrame::OnAbout)
929     EVT_MENU(LIST_LIST_VIEW, MyFrame::OnListView)
930     EVT_MENU(LIST_REPORT_VIEW, MyFrame::OnReportView)
931     EVT_MENU(LIST_ICON_VIEW, MyFrame::OnIconView)
932     EVT_MENU(LIST_ICON_TEXT_VIEW, MyFrame::OnIconTextView)
933     EVT_MENU(LIST_SMALL_ICON_VIEW, MyFrame::OnSmallIconView)
934     EVT_MENU(LIST_SMALL_ICON_TEXT_VIEW, MyFrame::OnSmallIconTextView)
935     EVT_MENU(LIST_VIRTUAL_VIEW, MyFrame::OnVirtualView)
936     EVT_MENU(LIST_SMALL_VIRTUAL_VIEW, MyFrame::OnSmallVirtualView)
937
938     EVT_MENU(LIST_FOCUS_LAST, MyFrame::OnFocusLast)
939     EVT_MENU(LIST_TOGGLE_FIRST, MyFrame::OnToggleFirstSel)
940     EVT_MENU(LIST_DESELECT_ALL, MyFrame::OnDeselectAll)
941     EVT_MENU(LIST_SELECT_ALL, MyFrame::OnSelectAll)
942     EVT_MENU(LIST_DELETE, MyFrame::OnDelete)
943     EVT_MENU(LIST_ADD, MyFrame::OnAdd)
944     EVT_MENU(LIST_EDIT, MyFrame::OnEdit)
945     EVT_MENU(LIST_DELETE_ALL, MyFrame::OnDeleteAll)
946     EVT_MENU(LIST_SORT, MyFrame::OnSort)
947     EVT_MENU(LIST_SET_FG_COL, MyFrame::OnSetFgColour)
948     EVT_MENU(LIST_SET_BG_COL, MyFrame::OnSetBgColour)
949     EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel)
950     EVT_MENU(LIST_SHOW_COL_INFO, MyFrame::OnShowColInfo)
951     EVT_MENU(LIST_SHOW_SEL_INFO, MyFrame::OnShowSelInfo)
952     EVT_MENU(LIST_FREEZE, MyFrame::OnFreeze)
953     EVT_MENU(LIST_THAW, MyFrame::OnThaw)
954     EVT_MENU(LIST_TOGGLE_LINES, MyFrame::OnToggleLines)
955     EVT_MENU(LIST_MAC_USE_GENERIC, MyFrame::OnToggleMacUseGeneric)
956
957     EVT_UPDATE_UI(LIST_SHOW_COL_INFO, MyFrame::OnUpdateShowColInfo)
958     EVT_UPDATE_UI(LIST_TOGGLE_MULTI_SEL, MyFrame::OnUpdateToggleMultiSel)
959 END_EVENT_TABLE()
960
961 BEGIN_EVENT_TABLE(MyListCtrl, wxListCtrl)
962     EVT_LIST_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnBeginDrag)
963     EVT_LIST_BEGIN_RDRAG(LIST_CTRL, MyListCtrl::OnBeginRDrag)
964         */
965     EVT_LIST_BEGIN_LABEL_EDIT(-1, WxTreeView::OnBeginLabelEdit)
966     EVT_LIST_END_LABEL_EDIT(-1, WxTreeView::OnEndLabelEdit)
967         /*
968     EVT_LIST_DELETE_ITEM(LIST_CTRL, MyListCtrl::OnDeleteItem)
969     EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, MyListCtrl::OnDeleteAllItems)
970 #if WXWIN_COMPATIBILITY_2_4
971     EVT_LIST_GET_INFO(LIST_CTRL, MyListCtrl::OnGetInfo)
972     EVT_LIST_SET_INFO(LIST_CTRL, MyListCtrl::OnSetInfo)
973 #endif
974   */
975     EVT_LIST_ITEM_SELECTED(-1, WxTreeView::OnSelectedChanged)
976   
977     EVT_LIST_ITEM_DESELECTED(-1, WxTreeView::OnSelectedChanged)
978         /*
979     EVT_LIST_KEY_DOWN(LIST_CTRL, MyListCtrl::OnListKeyDown)
980     EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, MyListCtrl::OnActivated)
981     EVT_LIST_ITEM_FOCUSED(LIST_CTRL, MyListCtrl::OnFocused)
982 */
983     EVT_LIST_COL_RIGHT_CLICK(-1, WxTreeView::OnColClick)
984         
985     EVT_LIST_COL_CLICK(-1, WxTreeView::OnColClick)
986         /*
987     EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, MyListCtrl::OnColBeginDrag)
988     EVT_LIST_COL_DRAGGING(LIST_CTRL, MyListCtrl::OnColDragging)
989     EVT_LIST_COL_END_DRAG(LIST_CTRL, MyListCtrl::OnColEndDrag)
990
991     EVT_LIST_CACHE_HINT(LIST_CTRL, MyListCtrl::OnCacheHint)
992
993 #if USE_CONTEXT_MENU
994     EVT_CONTEXT_MENU(MyListCtrl::OnContextMenu)
995 #endif
996     EVT_CHAR(MyListCtrl::OnChar)
997
998     EVT_RIGHT_DOWN(MyListCtrl::OnRightClick)
999   */
1000 END_EVENT_TABLE()
1001   
1002 } // EO namespace creaImageIO
1003