]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUIPackageBrowser2.cxx
re indent
[bbtk.git] / kernel / src / bbtkWxGUIPackageBrowser2.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWxGUIPackageBrowser2.cxx,v $
4   Language:  C++
5   Date:      $Date: 2010/04/28 22:19:59 $
6   Version:   $Revision: 1.20 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31
32 /* \brief Short description in one line
33  * 
34  * Long description which 
35  * can span multiple lines
36  */
37  
38 /**
39  * \file 
40  * \brief 
41  */
42 /**
43  * \class bbtk::
44  * \brief 
45  */
46
47
48 #ifdef _USE_WXWIDGETS_
49
50 #define CHECKBOXVIEW 1
51
52 #include "bbtkWxGUIPackageBrowser2.h"
53 //#include "ThirdParty/wx/treemultictrl/wxTreeMultiCtrl.h"
54 #include "bbtkInterpreter.h"
55 #include "bbtkBlackBoxInputDescriptor.h"
56 #include "bbtkBlackBoxOutputDescriptor.h"
57 #include "bbtkWxBlackBox.h"
58 //#include "wx/grid.h"
59 //#include <wx/statline.h>
60
61 #define LIST_CTRL 1000
62
63
64 namespace bbtk
65 {
66
67   BEGIN_EVENT_TABLE(WxGUIBlackBoxList, wxListCtrl)
68     EVT_LIST_BEGIN_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnBeginDrag)
69     EVT_LIST_BEGIN_RDRAG(LIST_CTRL, WxGUIBlackBoxList::OnBeginRDrag)
70     EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, WxGUIBlackBoxList::OnBeginLabelEdit)
71     EVT_LIST_END_LABEL_EDIT(LIST_CTRL, WxGUIBlackBoxList::OnEndLabelEdit)
72     EVT_LIST_DELETE_ITEM(LIST_CTRL, WxGUIBlackBoxList::OnDeleteItem)
73     EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, WxGUIBlackBoxList::OnDeleteAllItems)
74 #if WXWIN_COMPATIBILITY_2_4
75     EVT_LIST_GET_INFO(LIST_CTRL, WxGUIBlackBoxList::OnGetInfo)
76     EVT_LIST_SET_INFO(LIST_CTRL, WxGUIBlackBoxList::OnSetInfo)
77 #endif
78     EVT_LIST_ITEM_SELECTED(LIST_CTRL, WxGUIBlackBoxList::OnSelected)
79     EVT_LIST_ITEM_DESELECTED(LIST_CTRL, WxGUIBlackBoxList::OnDeselected)
80     EVT_LIST_KEY_DOWN(LIST_CTRL, WxGUIBlackBoxList::OnListKeyDown)
81     EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, WxGUIBlackBoxList::OnActivated)
82     EVT_LIST_ITEM_FOCUSED(LIST_CTRL, WxGUIBlackBoxList::OnFocused)
83     
84     EVT_LIST_COL_CLICK(LIST_CTRL, WxGUIBlackBoxList::OnColClick)
85     EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, WxGUIBlackBoxList::OnColRightClick)
86     EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnColBeginDrag)
87     EVT_LIST_COL_DRAGGING(LIST_CTRL, WxGUIBlackBoxList::OnColDragging)
88     EVT_LIST_COL_END_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnColEndDrag)
89     
90     EVT_LIST_CACHE_HINT(LIST_CTRL, WxGUIBlackBoxList::OnCacheHint)
91     
92 #if USE_CONTEXT_MENU
93     EVT_CONTEXT_MENU(WxGUIBlackBoxList::OnContextMenu)
94 #endif
95     EVT_CHAR(WxGUIBlackBoxList::OnChar)
96     
97     EVT_RIGHT_DOWN(WxGUIBlackBoxList::OnRightClick)
98     END_EVENT_TABLE()
99     
100     int wxCALLBACK MyCompareFunction(long item1, long item2, long WXUNUSED(sortData))
101   {
102     // inverse the order
103     if (item1 < item2)
104       return -1;
105     if (item1 > item2)
106       return 1;
107     
108     return 0;
109   }
110   
111   // WxGUIBlackBoxList
112   WxGUIBlackBoxList::WxGUIBlackBoxList(wxWindow *parent,
113                                  const wxWindowID id,
114                                  const wxPoint& pos,
115                                  const wxSize& size,
116                                  long style)
117     : wxListCtrl(parent, id, pos, size, style),
118       mUser(0),
119       m_attr(*wxBLUE, *wxLIGHT_GREY, wxNullFont)
120   {
121 #ifdef __POCKETPC__
122     EnableContextMenu();
123 #endif
124   }
125   
126   void WxGUIBlackBoxList::Insert(BlackBoxDescriptor::Pointer d)
127   {
128     if (GetColumnCount()!=3)
129       {
130         InsertColumn( 0, _("Package"), 
131                       wxLIST_FORMAT_LEFT, 60  ); 
132         InsertColumn( 1, _("Box"), 
133                       wxLIST_FORMAT_LEFT, 200 ); 
134         InsertColumn( 2, _("Description"), 
135                       wxLIST_FORMAT_LEFT, 500  ); 
136       }
137     
138     wxListItem kNewItem;
139     kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
140     
141     int nID = this->GetItemCount();
142     kNewItem.SetId(nID);
143     kNewItem.SetMask(wxLIST_MASK_DATA);
144     // TO DO : STORE SMART POINTER ?
145     kNewItem.SetData(d.get());  
146     //    BlackBoxDescriptor::Pointer* d2 = (BlackBoxDescriptor::Pointer*)kNewItem.GetData();
147     //    std::cout << "Descr = "<<d<<" = "<<d2<<std::endl;
148     this->InsertItem(kNewItem);
149     this->SetItem(nID, 0, std2wx(d->GetPackage()->GetName()) );
150     this->SetItem(nID, 1, std2wx(d->GetTypeName()) );
151     this->SetItem(nID, 2, std2wx(d->GetDescription()) );
152     
153     /*
154       if (nID % 2)
155       {
156       kNewItem.SetBackgroundColour(wxColour(192,192,192));
157       this->SetItem(kNewItem);
158       }
159     */
160     
161   }
162   
163   
164   void WxGUIBlackBoxList::OnCacheHint(wxListEvent& event)
165   {
166     //wxLogMessage( wxT("OnCacheHint: cache items %ld..%ld"),
167     //                  event.GetCacheFrom(), event.GetCacheTo() );
168   }
169   
170   void WxGUIBlackBoxList::SetColumnImage(int col, int image)
171   {
172     /*
173       wxListItem item;
174       item.SetMask(wxLIST_MASK_IMAGE);
175       item.SetImage(image);
176       SetColumn(col, item);
177     */
178   }
179
180   void WxGUIBlackBoxList::OnColClick(wxListEvent& event)
181   {
182     int col = event.GetColumn();
183
184     // set or unset image
185     static bool x = false;
186     x = !x;
187     SetColumnImage(col, x ? 0 : -1);
188
189     //    wxLogMessage( wxT("OnColumnClick at %d."), col );
190   }
191
192   void WxGUIBlackBoxList::OnColRightClick(wxListEvent& event)
193   {
194     int col = event.GetColumn();
195     if ( col != -1 )
196       {
197         SetColumnImage(col, -1);
198       }
199
200     // Show popupmenu at position
201     wxMenu menu(wxT("Test"));
202     menu.Append(-1, _T("&About"));
203     PopupMenu(&menu, event.GetPoint());
204
205     //wxLogMessage( wxT("OnColumnRightClick at %d."), event.GetColumn() );
206   }
207
208   void WxGUIBlackBoxList::LogColEvent(const wxListEvent& event, const wxChar *name)
209   {
210     //    const int col = event.GetColumn();
211
212     /*
213       wxLogMessage(wxT("%s: column %d (width = %d or %d)."),
214       name,
215       col,
216       event.GetItem().GetWidth(),
217       GetColumnWidth(col));
218     */
219   }
220
221   void WxGUIBlackBoxList::OnColBeginDrag(wxListEvent& event)
222   {
223     LogColEvent( event, wxT("OnColBeginDrag") );
224     /*
225       if ( event.GetColumn() == 0 )
226       {
227       //wxLogMessage(_T("Resizing this column shouldn't work."));
228
229       event.Veto();
230       }
231     */
232   }
233
234   void WxGUIBlackBoxList::OnColDragging(wxListEvent& event)
235   {
236     LogColEvent( event, wxT("OnColDragging") );
237   }
238
239   void WxGUIBlackBoxList::OnColEndDrag(wxListEvent& event)
240   {
241     LogColEvent( event, wxT("OnColEndDrag") );
242   }
243
244   void WxGUIBlackBoxList::OnBeginDrag(wxListEvent& event)
245   {
246           std::cout<<"RaC DRAG TABLE"<<std::endl;
247           
248           wxString text(wxT(this->GetItemText(event.GetIndex())));
249           wxListItem info;
250           info.m_itemId = event.m_itemIndex;
251           info.m_col = 0;
252           info.m_mask = wxLIST_MASK_DATA;
253           wxString sendtext(wxT(""));
254           if ( GetItem(info) )
255           {
256                   // TO DO : STORE SMART PTR ?
257                   BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
258                   if (d!=0)
259                   {
260                           sendtext += wxT(d->GetFullTypeName());
261                   }
262           }
263           else
264           {
265                   wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
266           }
267
268         
269           wxTextDataObject tdo(wxT(sendtext));
270           wxDropSource tds(tdo, this);
271           tds.DoDragDrop();
272
273
274     //    const wxPoint& pt = event.m_pointDrag;
275
276     //wxLogMessage( wxT("OnBeginDrag at (%d, %d), item %ld."),
277     //          pt.x, pt.y, HitTest(pt, flags) );
278   }
279
280   void WxGUIBlackBoxList::OnBeginRDrag(wxListEvent& event)
281   {
282     //wxLogMessage( wxT("OnBeginRDrag at %d,%d."),
283     //        event.m_pointDrag.x, event.m_pointDrag.y );
284   }
285
286   void WxGUIBlackBoxList::OnBeginLabelEdit(wxListEvent& event)
287   {
288     //wxLogMessage( wxT("OnBeginLabelEdit: %s"), event.m_item.m_text.c_str());
289   }
290
291   void WxGUIBlackBoxList::OnEndLabelEdit(wxListEvent& event)
292   {
293     //wxLogMessage( wxT("OnEndLabelEdit: %s"),
294     //        event.IsEditCancelled() ? _T("[cancelled]")
295     //                                      : event.m_item.m_text.c_str());
296   }
297
298   void WxGUIBlackBoxList::OnDeleteItem(wxListEvent& event)
299   {
300     LogEvent(event, _T("OnDeleteItem"));
301     std::cout << "cannot del"<<std::endl;
302     event.Veto();
303     //wxLogMessage( wxT("Number of items when delete event is sent: %d"), GetItemCount() );
304   }
305
306   void WxGUIBlackBoxList::OnDeleteAllItems(wxListEvent& event)
307   {
308     LogEvent(event, _T("OnDeleteAllItems"));
309     event.Veto();
310   }
311
312 #if WXWIN_COMPATIBILITY_2_4
313   void WxGUIBlackBoxList::OnGetInfo(wxListEvent& event)
314   {
315     wxString msg;
316
317     msg << _T("OnGetInfo (") << event.m_item.m_itemId << _T(", ") << event.m_item.m_col << _T(")");
318     if ( event.m_item.m_mask & wxLIST_MASK_STATE )
319       msg << _T(" wxLIST_MASK_STATE");
320     if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
321       msg << _T(" wxLIST_MASK_TEXT");
322     if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
323       msg << _T(" wxLIST_MASK_IMAGE");
324     if ( event.m_item.m_mask & wxLIST_MASK_DATA )
325       msg << _T(" wxLIST_MASK_DATA");
326     if ( event.m_item.m_mask & wxLIST_SET_ITEM )
327       msg << _T(" wxLIST_SET_ITEM");
328     if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
329       msg << _T(" wxLIST_MASK_WIDTH");
330     if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
331       msg << _T(" wxLIST_MASK_WIDTH");
332
333     if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
334       {
335         event.m_item.m_text = _T("My callback text");
336       }
337
338     //wxLogMessage(msg);
339   }
340
341   void WxGUIBlackBoxList::OnSetInfo(wxListEvent& event)
342   {
343     LogEvent(event, _T("OnSetInfo"));
344   }
345 #endif
346
347   void WxGUIBlackBoxList::OnSelected(wxListEvent& event)
348   {
349     if (mUser==0) return;
350
351     wxListItem info;
352     info.m_itemId = event.m_itemIndex;
353     info.m_col = 0;
354     info.m_mask = wxLIST_MASK_DATA;
355     if ( GetItem(info) )
356       {
357         // TO DO : STORE SMART PTR ?
358         BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
359         if (d!=0) mUser->WxGUIBlackBoxListUserOnSelected(d);
360       }
361     else
362       {
363         wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
364       }
365   }
366
367   void WxGUIBlackBoxList::OnDeselected(wxListEvent& event)
368   {
369     LogEvent(event, _T("OnDeselected"));
370   }
371
372   void WxGUIBlackBoxList::OnActivated(wxListEvent& event)
373   {
374     LogEvent(event, _T("OnActivated"));
375   }
376
377   void WxGUIBlackBoxList::OnFocused(wxListEvent& event)
378   {
379     LogEvent(event, _T("OnFocused"));
380
381     event.Skip();
382   }
383
384   void WxGUIBlackBoxList::OnListKeyDown(wxListEvent& event)
385   {
386     long item;
387
388     switch ( event.GetKeyCode() )
389       {
390       case 'c': // colorize
391       case 'C':
392         {
393           wxListItem info;
394           info.m_itemId = event.GetIndex();
395           if ( info.m_itemId == -1 )
396             {
397               // no item
398               break;
399             }
400
401           GetItem(info);
402
403           wxListItemAttr *attr = info.GetAttributes();
404           if ( !attr || !attr->HasTextColour() )
405             {
406               info.SetTextColour(*wxCYAN);
407
408               SetItem(info);
409
410               RefreshItem(info.m_itemId);
411             }
412         }
413         break;
414
415       case 'n': // next
416       case 'N':
417         item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
418         if ( item++ == GetItemCount() - 1 )
419           {
420             item = 0;
421           }
422
423         //wxLogMessage(_T("Focusing item %ld"), item);
424
425         SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
426         EnsureVisible(item);
427         break;
428
429       case 'r': // show bounding Rect
430       case 'R':
431         {
432           item = event.GetIndex();
433           wxRect r;
434           if ( !GetItemRect(item, r) )
435             {
436               //wxLogError(_T("Failed to retrieve rect of item %ld"), item);
437               break;
438             }
439
440           //wxLogMessage(_T("Bounding rect of item %ld is (%d, %d)-(%d, %d)"),
441           //   item, r.x, r.y, r.x + r.width, r.y + r.height);
442         }
443         break;
444
445       case WXK_DELETE:
446         item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
447         /*
448           while ( item != -1 )
449           {
450           DeleteItem(item);
451
452           //wxLogMessage(_T("Item %ld deleted"), item);
453
454           // -1 because the indices were shifted by DeleteItem()
455           item = GetNextItem(item - 1,
456           wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
457           }
458         */
459         break;
460
461       case WXK_INSERT:
462         if ( GetWindowStyle() & wxLC_REPORT )
463           {
464             if ( GetWindowStyle() & wxLC_VIRTUAL )
465               {
466                 SetItemCount(GetItemCount() + 1);
467               }
468             else // !virtual
469               {
470                 //InsertItemInReportView(event.GetIndex());
471               }
472           }
473         //else: fall through
474
475       default:
476         LogEvent(event, _T("OnListKeyDown"));
477
478         event.Skip();
479       }
480   }
481
482   void WxGUIBlackBoxList::OnChar(wxKeyEvent& event)
483   {
484     //wxLogMessage(_T("Got char event."));
485
486     switch ( event.GetKeyCode() )
487       {
488       case 'n':
489       case 'N':
490       case 'c':
491       case 'C':
492         // these are the keys we process ourselves
493         break;
494
495       default:
496         event.Skip();
497       }
498   }
499
500   void WxGUIBlackBoxList::OnRightClick(wxMouseEvent& event)
501   {
502     if ( !event.ControlDown() )
503       {
504         event.Skip();
505         return;
506       }
507
508     int flags;
509     long subitem;
510     //    long item = 
511     HitTest(event.GetPosition(), flags, &subitem);
512
513     wxString where;
514     switch ( flags )
515       {
516       case wxLIST_HITTEST_ABOVE:       where = _T("above");           break;
517       case wxLIST_HITTEST_BELOW:       where = _T("below");           break;
518       case wxLIST_HITTEST_NOWHERE:     where = _T("nowhere near");    break;
519       case wxLIST_HITTEST_ONITEMICON:  where = _T("on icon of");      break;
520       case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of");     break;
521       case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on");        break;
522       case wxLIST_HITTEST_TOLEFT:      where = _T("to the left of");  break;
523       case wxLIST_HITTEST_TORIGHT:     where = _T("to the right of"); break;
524       default: where = _T("not clear exactly where on");              break;
525       }
526
527     //wxLogMessage(_T("Right double click %s item %ld, subitem %ld"),
528     //             where.c_str(), item, subitem);
529   }
530
531   void WxGUIBlackBoxList::LogEvent(const wxListEvent& event, const wxChar *eventName)
532   {
533     //wxLogMessage(_T("Item %ld: %s (item text = %s, data = %ld)"),
534     //            event.GetIndex(), eventName,
535     //              event.GetText().c_str(), event.GetData());
536   }
537
538   wxString WxGUIBlackBoxList::OnGetItemText(long item, long column) const
539   {
540     /*
541       if ( GetItemCount() == WXSIZEOF(SMALL_VIRTUAL_VIEW_ITEMS) )
542       {
543       return SMALL_VIRTUAL_VIEW_ITEMS[item][column];
544       }
545       else
546       {
547     */
548     return wxString::Format(_T("Column %ld of item %ld"), column, item);
549     //  }
550   }
551
552   int WxGUIBlackBoxList::OnGetItemColumnImage(long item, long column) const
553   {
554     if (!column)
555       return 0;
556
557     if (!(item %3) && column == 1)
558       return 0;
559
560     return -1;
561   }
562
563   wxListItemAttr *WxGUIBlackBoxList::OnGetItemAttr(long item) const
564   {
565     return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
566   }
567
568
569 #if USE_CONTEXT_MENU
570   void WxGUIBlackBoxList::OnContextMenu(wxContextMenuEvent& event)
571   {
572     wxPoint point = event.GetPosition();
573     // If from keyboard
574     if (point.x == -1 && point.y == -1) {
575       wxSize size = GetSize();
576       point.x = size.x / 2;
577       point.y = size.y / 2;
578     } else {
579       point = ScreenToClient(point);
580     }
581     ShowContextMenu(point);
582   }
583 #endif
584
585   void WxGUIBlackBoxList::ShowContextMenu(const wxPoint& pos)
586   {
587     wxMenu menu;
588   
589     menu.Append(wxID_ABOUT, _T("&About"));
590     menu.AppendSeparator();
591     menu.Append(wxID_EXIT, _T("E&xit"));
592   
593     PopupMenu(&menu, pos.x, pos.y);
594   }
595   //================================================================
596
597
598
599   //================================================================
600   WxGUIBlackBoxInfo::WxGUIBlackBoxInfo(wxWindow* parent)
601     :
602     wxPanel(parent, -1),
603     mDescriptor()
604   {
605     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
606     
607     //    mName = new wxStaticText(this,-1,_T(""));
608     //    sizer->Add(mName,0,wxGROW);
609     mDescription = new wxStaticText(this,-1,_T(""));
610     sizer->Add(mDescription,0,wxGROW);
611     mAuthor = new wxStaticText(this,-1,_T(""));
612     sizer->Add(mAuthor,0,wxGROW);
613     mCategory = new wxStaticText(this,-1,_T(""));
614     sizer->Add(mCategory,0,wxGROW);
615
616     wxBoxSizer *inputs = 
617       new wxStaticBoxSizer
618       ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );    
619     mInputList = new wxListCtrl(this, -1,
620                                 wxDefaultPosition,
621                                 wxDefaultSize,
622                                 wxLC_REPORT //wxLC_LIST
623                                 | wxSUNKEN_BORDER);
624
625     inputs->Add(mInputList,1,wxGROW);
626     sizer->Add(inputs,1,wxGROW);
627
628     wxBoxSizer *outputs = 
629       new wxStaticBoxSizer
630       ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );    
631     mOutputList = new wxListCtrl(this, -1,
632                                  wxDefaultPosition,
633                                  wxDefaultSize,
634                                  wxLC_REPORT //wxLC_LIST
635                                  | wxSUNKEN_BORDER);
636     
637     outputs->Add(mOutputList,1,wxGROW);
638     sizer->Add(outputs,1,wxGROW);
639
640     SetSizer(sizer);
641     SetAutoLayout(true);
642     Layout();
643   }
644   //================================================================
645
646     
647   //================================================================
648   void WxGUIBlackBoxInfo::UpdateInfo(BlackBoxDescriptor* descr)
649   {
650
651     //    mName->SetLabel(std2wx(descr->GetTypeName()));
652     mDescription->SetLabel(std2wx(descr->GetDescription()));
653     mAuthor->SetLabel(std2wx(descr->GetAuthor()));
654     mCategory->SetLabel(std2wx(descr->GetCategory()));
655     
656     mInputList->ClearAll();
657     mInputList->InsertColumn( 0, _("Name"), 
658                                wxLIST_FORMAT_LEFT, 80  ); 
659     mInputList->InsertColumn( 1, _("Type"), 
660                                wxLIST_FORMAT_LEFT, 100 ); 
661     mInputList->InsertColumn( 2, _("Nature"), 
662                                wxLIST_FORMAT_LEFT, 100  ); 
663     mInputList->InsertColumn( 3, _("Description"), 
664                                wxLIST_FORMAT_LEFT, 500  ); 
665
666     mOutputList->ClearAll();
667     mOutputList->InsertColumn( 0, _("Name"), 
668                                wxLIST_FORMAT_LEFT, 80  ); 
669     mOutputList->InsertColumn( 1, _("Type"), 
670                                wxLIST_FORMAT_LEFT, 100 ); 
671     mOutputList->InsertColumn( 2, _("Nature"), 
672                                wxLIST_FORMAT_LEFT, 100  ); 
673     mOutputList->InsertColumn( 3, _("Description"), 
674                                wxLIST_FORMAT_LEFT, 500  ); 
675     
676
677     std::vector<BlackBoxInputOutputDescriptor*> user_defined;
678     std::vector<BlackBoxInputOutputDescriptor*> ubb_defined;
679     std::vector<BlackBoxInputOutputDescriptor*> wxbb_defined;
680     
681     const BlackBoxDescriptor::InputDescriptorMapType& imap = 
682       descr->GetInputDescriptorMap();
683     BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
684     for ( in = imap.begin();  in != imap.end(); ++in ) 
685       {
686         int iotype = 0;
687         if (in->second->GetCreatorTypeInfo() == 
688             typeid(AtomicBlackBoxDescriptor))
689           {
690             iotype = 1;
691           }
692         else if (in->second->GetCreatorTypeInfo() == 
693                  typeid(WxBlackBoxDescriptor))
694           {
695             iotype = 2;
696           }
697         if (iotype==0) user_defined.push_back(in->second);
698         else if (iotype==1) ubb_defined.push_back(in->second);
699         else if (iotype==2) wxbb_defined.push_back(in->second);
700         
701       }
702
703     std::vector<BlackBoxInputOutputDescriptor*>::iterator hi;
704     for (hi=user_defined.begin();hi!=user_defined.end();++hi) 
705       {
706         InsertInputOutput(mInputList,*hi);
707       }
708     for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi) 
709       {
710         InsertInputOutput(mInputList,*hi);
711       }
712     for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi) 
713       {
714         InsertInputOutput(mInputList,*hi);
715       }
716     
717     // Outputs
718     user_defined.clear();
719     ubb_defined.clear();
720     wxbb_defined.clear();
721     const BlackBoxDescriptor::OutputDescriptorMapType& omap = 
722       descr->GetOutputDescriptorMap();
723     BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
724     for ( out = omap.begin();  out != omap.end(); ++out ) 
725       {
726         int iotype = 0;
727         if (out->second->GetCreatorTypeInfo() == 
728             typeid(AtomicBlackBoxDescriptor))
729           {
730             iotype = 1;
731           }
732         else if (out->second->GetCreatorTypeInfo() == 
733                  typeid(WxBlackBoxDescriptor))
734           {
735             iotype = 2;
736           }
737        
738         if (iotype==0) user_defined.push_back(out->second);
739         else if (iotype==1) ubb_defined.push_back(out->second);
740         else if (iotype==2) wxbb_defined.push_back(out->second);
741
742       }
743     for (hi=user_defined.begin();hi!=user_defined.end();++hi) 
744       {
745         InsertInputOutput(mOutputList,*hi);
746       }
747     for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi) 
748       {
749         InsertInputOutput(mOutputList,*hi);
750       }
751     for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi) 
752       {
753         InsertInputOutput(mOutputList,*hi);
754       }
755   }
756   //================================================================
757
758
759   //================================================================
760   void WxGUIBlackBoxInfo::InsertInputOutput(wxListCtrl* l,
761                                             BlackBoxInputOutputDescriptor* d)
762   {
763     wxListItem kNewItem;
764     kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
765     int nID = l->GetItemCount();
766     //    std::cout << nID << std::endl;
767     kNewItem.SetId(nID);
768     //    kNewItem.SetMask(wxLIST_MASK_DATA);
769     //    kNewItem.SetData(d);  
770     l->InsertItem(kNewItem);
771     l->SetItem(nID, 0, std2wx(d->GetName()) );
772     l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
773     l->SetItem(nID, 2, std2wx(d->GetNature()) );
774     l->SetItem(nID, 3, std2wx(d->GetDescription()) );
775   }
776   //================================================================
777
778   //================================================================
779   WxGUIBlackBoxInfo::~WxGUIBlackBoxInfo()
780   {
781   }
782   //================================================================
783
784
785  enum 
786     {
787       id_f1,
788       id_f2,
789       id_f3,
790       id_f4,
791       id_f5,
792       id_f6,
793       id_f7,
794       id_f8,
795       id_fc1,
796       id_fc2,
797       id_fc3
798     };
799
800   //================================================================
801   WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
802                                               WxGUIPackageBrowser2User* user )
803     : wxPanel(parent, -1),
804       mUser(user),
805       mInterpreter()
806   {
807     m_mgr.SetManagedWindow(this);
808
809     //    wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
810     mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
811                                      wxDefaultPosition,
812                                      wxDefaultSize,
813                                      wxLC_REPORT //wxLC_LIST
814                                      | wxSUNKEN_BORDER);
815     mBoxList->SetUser(this);
816     mBoxList->SetBackgroundColour(*wxWHITE);
817
818     m_mgr.AddPane(mBoxList,
819                   wxAuiPaneInfo().Name(wxT("BoxList"))
820                   .Caption(wxT("Black Boxes"))
821                   .MinimizeButton(true)
822                   .MaximizeButton(true)
823                   .Center()
824                   .MinSize(wxSize(100,100))
825                   );     
826     //    sizer->Add(mBoxList,5,wxGROW);
827
828     mBoxInfo = new WxGUIBlackBoxInfo(this);
829     //    sizer->Add(mBoxInfo,3,wxGROW);
830
831     m_mgr.AddPane(mBoxInfo,
832                   wxAuiPaneInfo().Name(wxT("Box"))
833                   .Caption(wxT(""))
834                   .MinimizeButton(true)
835                   .MaximizeButton(true)
836                   .Bottom()
837                   .MinSize(wxSize(100,300))
838                   );     
839
840     wxPanel* filters = new wxPanel(this,-1);
841     wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );    
842     wxBoxSizer *fpack = 
843       new wxStaticBoxSizer
844       ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );    
845     mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
846                                     wxDefaultPosition,
847                                     wxDefaultSize,
848                                     wxTE_PROCESS_ENTER);
849     fpack->Add(mPackageFilter,1,wxGROW);
850     fsizer->Add(fpack,0,wxGROW);
851     wxBoxSizer *fname = 
852       new wxStaticBoxSizer
853       ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );    
854     mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
855                                     wxDefaultPosition,
856                                     wxDefaultSize,
857                                     wxTE_PROCESS_ENTER);
858     fname->Add(mNameFilter,1,wxGROW);
859     fsizer->Add(fname,0,wxGROW);
860     wxBoxSizer *fdescr = 
861       new wxStaticBoxSizer
862       ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
863     mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
864                                     wxDefaultPosition,
865                                     wxDefaultSize,
866                                     wxTE_PROCESS_ENTER);
867     fdescr->Add(mDescriptionFilter,1,wxGROW);
868     fsizer->Add(fdescr,0,wxGROW);
869     wxBoxSizer *fcat = 
870       new wxStaticBoxSizer
871       ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );    
872     mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
873                                     wxDefaultPosition,
874                                     wxDefaultSize,
875                                     wxTE_PROCESS_ENTER);
876     fcat->Add(mCategoryFilter,1,wxGROW);
877     fsizer->Add(fcat,0,wxGROW);
878     wxBoxSizer *fintype = 
879       new wxStaticBoxSizer
880       ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
881     mInputTypeFilter = new wxTextCtrl(filters,id_f5,_T(""),
882                                     wxDefaultPosition,
883                                     wxDefaultSize,
884                                     wxTE_PROCESS_ENTER);
885     fintype->Add(mInputTypeFilter,1,wxGROW);
886     fsizer->Add(fintype,0,wxGROW);
887     wxBoxSizer *fouttype = 
888       new wxStaticBoxSizer
889       ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
890     mOutputTypeFilter = new wxTextCtrl(filters,id_f6,_T(""),
891                                     wxDefaultPosition,
892                                     wxDefaultSize,
893                                     wxTE_PROCESS_ENTER);
894     fouttype->Add(mOutputTypeFilter,1,wxGROW);
895     fsizer->Add(fouttype,0,wxGROW);
896     wxBoxSizer *finnat = 
897       new wxStaticBoxSizer
898       ( new wxStaticBox(filters, wxID_ANY, _T("Input nature")),wxHORIZONTAL ); 
899     mInputNatureFilter = new wxTextCtrl(filters,id_f7,_T(""),
900                                         wxDefaultPosition,
901                                         wxDefaultSize,
902                                         wxTE_PROCESS_ENTER);
903     finnat->Add(mInputNatureFilter,1,wxGROW);
904     fsizer->Add(finnat,0,wxGROW);
905     wxBoxSizer *foutnat = 
906       new wxStaticBoxSizer
907       ( new wxStaticBox(filters, wxID_ANY,_T("Output nature")),wxHORIZONTAL ); 
908     mOutputNatureFilter = new wxTextCtrl(filters,id_f8,_T(""),
909                                         wxDefaultPosition,
910                                         wxDefaultSize,
911                                         wxTE_PROCESS_ENTER);
912     foutnat->Add(mOutputNatureFilter,1,wxGROW);
913     fsizer->Add(foutnat,0,wxGROW);
914
915     mShowWidgetsFilter = new wxCheckBox(filters,id_fc1,_T("Show widgets"));
916     mShowWidgetsFilter->SetValue(true);
917     fsizer->Add(mShowWidgetsFilter,0,wxGROW);
918
919     mShowAdaptorsFilter = new wxCheckBox(filters,id_fc2,_T("Show adaptors"));
920     mShowAdaptorsFilter->SetValue(false);
921     fsizer->Add(mShowAdaptorsFilter,0,wxGROW);
922
923     mShowGUIsFilter = new wxCheckBox(filters,id_fc3,_T("Show GUIs"));
924     mShowGUIsFilter->SetValue(false);
925     fsizer->Add(mShowGUIsFilter,0,wxGROW);
926
927     filters->SetSizer(fsizer);
928
929     m_mgr.AddPane(filters,
930                   wxAuiPaneInfo().Name(wxT("Filter"))
931                   .Caption(wxT("Filter"))
932                   .MinimizeButton(true)
933                   .MaximizeButton(true)
934                   .Right()
935                   .MinSize(wxSize(100,100)) );
936
937     //    sizer->Add(fsizer,1,wxGROW);
938     m_mgr.Update();
939
940     //    SetSizer(sizer);
941     SetAutoLayout(true);
942     Layout();
943     
944   }
945   //================================================================
946
947   //================================================================
948   void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
949   {
950     RebuildList();
951   }
952   //================================================================
953
954   //================================================================
955   // User callback when a box is selected in the list 
956   void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected
957   ( BlackBoxDescriptor* d)
958   {
959         //RaC
960         _actualSelected=d;
961
962     mBoxInfo->UpdateInfo(d);
963     std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
964     m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
965     m_mgr.Update();
966   }
967   
968   //================================================================
969
970   //================================================================
971   BlackBoxDescriptor* WxGUIPackageBrowser2::GetActualSelected()
972   {
973           return _actualSelected;
974   }
975
976   //================================================================
977
978   //================================================================
979   WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
980   {
981     mFactory.reset();
982     mInterpreter.reset();
983     //    Object::PrintObjectListInfo("");
984     m_mgr.UnInit();
985   }
986   //================================================================
987
988   //================================================================
989   void WxGUIPackageBrowser2::IncludeAll()
990   {
991     if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
992     mInterpreter->SetCommandLine(true);
993     std::stringstream* buf = new std::stringstream;
994     *buf << "exec freeze_no_error" << std::endl;
995     *buf << "message max 0" << std::endl; 
996     *buf << "include *" << std::endl;
997     mInterpreter->InterpretBuffer(buf);
998
999     Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
1000     BuildFromFactory(F);
1001   }
1002   //================================================================
1003
1004   //================================================================
1005   void WxGUIPackageBrowser2::BuildFromFactory(Factory::Pointer F)
1006   {
1007     mFactory = F;
1008     RebuildList();
1009   }  
1010
1011   //================================================================
1012
1013   //================================================================
1014   void WxGUIPackageBrowser2::RebuildList()
1015   {
1016     mBoxList->Hide();
1017     mBoxList->ClearAll();    
1018     
1019     const Factory::PackageMapType& M = mFactory->GetPackageMap();
1020     Factory::PackageMapType::const_iterator i;
1021     for (i=M.begin();i!=M.end();++i)
1022       {
1023         Package::Pointer P = i->second;
1024         if (P->GetName() == "user") continue;
1025         
1026         Package::DescriptorMapType::iterator j;
1027         for (j=P->GetDescriptorMap().begin();
1028              j!=P->GetDescriptorMap().end();
1029              ++j)
1030           {
1031             //      std::cout << "Insert "<<j->second->GetTypeName()<<std::endl;
1032             if (IsVisible(j->second))
1033               mBoxList->Insert(j->second);
1034           }
1035       }
1036     mBoxList->Show();
1037   }
1038   //================================================================
1039
1040   //================================================================
1041   bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor::Pointer d)
1042   {
1043     //    std::cout << "   '" << wx2std(mPackageFilter->GetValue())<<"'"<<std::endl;
1044     //    std::cout << "vs '" << d->GetPackage()->GetName() << "'"<<std::endl;
1045     if ((!mShowAdaptorsFilter->IsChecked())&&
1046         ((d->GetKind()==BlackBoxDescriptor::ADAPTOR)||
1047          (d->GetKind()==BlackBoxDescriptor::DEFAULT_ADAPTOR)))
1048       return false;
1049     if ((!mShowGUIsFilter->IsChecked())&&
1050         ((d->GetKind()==BlackBoxDescriptor::GUI)||
1051          (d->GetKind()==BlackBoxDescriptor::DEFAULT_GUI)))
1052       return false;
1053     if (d->GetPackage()->GetName().find( wx2std(mPackageFilter->GetValue()) ) 
1054         == std::string::npos ) return false;
1055    if (d->GetTypeName().find( wx2std(mNameFilter->GetValue()) ) 
1056         == std::string::npos ) return false;
1057    if (d->GetDescription().find( wx2std(mDescriptionFilter->GetValue()) ) 
1058         == std::string::npos ) return false;
1059    if (d->GetCategory().find( wx2std(mCategoryFilter->GetValue()) ) 
1060         == std::string::npos ) return false;
1061    if (!mShowWidgetsFilter->IsChecked())
1062      {
1063        bool found = false;
1064        const BlackBoxDescriptor::OutputDescriptorMapType& imap = 
1065          d->GetOutputDescriptorMap();
1066        BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1067        for ( in = imap.begin();  in != imap.end(); ++in ) 
1068          {
1069            if (in->second->GetName() == "Widget" )
1070              {
1071                found = true;
1072                break;
1073              }
1074          }
1075        if (found) return false;
1076      }
1077    if (mInputTypeFilter->GetValue().size()>0)
1078      {
1079        std::string s = wx2std(mInputTypeFilter->GetValue());
1080        bool found = false;
1081        const BlackBoxDescriptor::InputDescriptorMapType& imap = 
1082          d->GetInputDescriptorMap();
1083        BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1084        for ( in = imap.begin();  in != imap.end(); ++in ) 
1085          {
1086            if (in->second->GetTypeName().find(s)!=std::string::npos)
1087              {
1088                found = true;
1089                break;
1090              }
1091          }
1092        if (!found) return false;
1093      }
1094    if (mOutputTypeFilter->GetValue().size()>0)
1095      {
1096        std::string s = wx2std(mOutputTypeFilter->GetValue());
1097        bool found = false;
1098        const BlackBoxDescriptor::OutputDescriptorMapType& imap = 
1099          d->GetOutputDescriptorMap();
1100        BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1101        for ( in = imap.begin();  in != imap.end(); ++in ) 
1102          {
1103            if (in->second->GetTypeName().find(s)!=std::string::npos)
1104              {
1105                found = true;
1106                break;
1107              }
1108          }
1109        if (!found) return false;
1110      }
1111    if (mInputNatureFilter->GetValue().size()>0)
1112      {
1113        std::string s = wx2std(mInputNatureFilter->GetValue());
1114        bool found = false;
1115        const BlackBoxDescriptor::InputDescriptorMapType& imap = 
1116          d->GetInputDescriptorMap();
1117        BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
1118        for ( in = imap.begin();  in != imap.end(); ++in ) 
1119          {
1120            if (in->second->GetNature().find(s)!=std::string::npos)
1121              {
1122                found = true;
1123                break;
1124              }
1125          }
1126        if (!found) return false;
1127      }
1128    if (mOutputNatureFilter->GetValue().size()>0)
1129      {
1130        std::string s = wx2std(mOutputNatureFilter->GetValue());
1131        bool found = false;
1132        const BlackBoxDescriptor::OutputDescriptorMapType& imap = 
1133          d->GetOutputDescriptorMap();
1134        BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
1135        for ( in = imap.begin();  in != imap.end(); ++in ) 
1136          {
1137            if (in->second->GetNature().find(s)!=std::string::npos)
1138              {
1139                found = true;
1140                break;
1141              }
1142          }
1143        if (!found) return false;
1144      }
1145     return true;
1146   }
1147   //========================================================================
1148
1149   //========================================================================
1150   BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
1151     EVT_TEXT_ENTER(id_f1, WxGUIPackageBrowser2::OnFilter )
1152     EVT_TEXT_ENTER(id_f2, WxGUIPackageBrowser2::OnFilter )
1153     EVT_TEXT_ENTER(id_f3, WxGUIPackageBrowser2::OnFilter )
1154     EVT_TEXT_ENTER(id_f4, WxGUIPackageBrowser2::OnFilter )
1155     EVT_TEXT_ENTER(id_f5, WxGUIPackageBrowser2::OnFilter )
1156     EVT_TEXT_ENTER(id_f6, WxGUIPackageBrowser2::OnFilter )
1157     EVT_TEXT_ENTER(id_f7, WxGUIPackageBrowser2::OnFilter )
1158     EVT_TEXT_ENTER(id_f8, WxGUIPackageBrowser2::OnFilter )
1159     EVT_CHECKBOX( id_fc1, WxGUIPackageBrowser2::OnFilter )
1160     EVT_CHECKBOX( id_fc2, WxGUIPackageBrowser2::OnFilter )
1161     EVT_CHECKBOX( id_fc3, WxGUIPackageBrowser2::OnFilter )
1162     END_EVENT_TABLE()
1163   //========================================================================
1164
1165
1166
1167   //================================================================
1168   WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent, 
1169                                                           wxString title,
1170                                                           wxSize size)
1171       : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
1172   {
1173     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
1174
1175     mBrowser = new WxGUIPackageBrowser2(this);
1176     mBrowser->IncludeAll();
1177     sizer->Add(mBrowser,1,wxGROW);
1178     
1179     //    WxGUICommand* com = new WxGUICommand(this,this);
1180     //    sizer->Add(com);
1181     
1182     SetSizer(sizer);
1183
1184      // Creates the parent window of all bbtk windows as a child of this
1185 //    Wx::CreateTopWindow(this);
1186     // Add the method OnWxSignal as a Wx::Signal observer 
1187     //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
1188  
1189     SetAutoLayout(true);
1190     Layout();
1191   }
1192   //================================================================
1193
1194   //================================================================
1195   WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
1196   {
1197   }
1198   //================================================================
1199
1200 } // namespace bbtk
1201
1202
1203 #endif //_USE_WXWIDGETS_