00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00047 #ifdef _USE_WXWIDGETS_
00048
00049 #define CHECKBOXVIEW 1
00050
00051 #include "bbtkWxGUIPackageBrowser2.h"
00052
00053 #include "bbtkInterpreter.h"
00054 #include "bbtkBlackBoxInputDescriptor.h"
00055 #include "bbtkBlackBoxOutputDescriptor.h"
00056 #include "bbtkWxBlackBox.h"
00057
00058
00059
00060 #include "creaWx.h"
00061
00062 #define LIST_CTRL 1000
00063
00064
00065 namespace bbtk
00066 {
00067
00068 BEGIN_EVENT_TABLE(WxGUIBlackBoxList, wxListCtrl)
00069 EVT_LIST_BEGIN_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnBeginDrag)
00070 EVT_LIST_BEGIN_RDRAG(LIST_CTRL, WxGUIBlackBoxList::OnBeginRDrag)
00071 EVT_LIST_BEGIN_LABEL_EDIT(LIST_CTRL, WxGUIBlackBoxList::OnBeginLabelEdit)
00072 EVT_LIST_END_LABEL_EDIT(LIST_CTRL, WxGUIBlackBoxList::OnEndLabelEdit)
00073 EVT_LIST_DELETE_ITEM(LIST_CTRL, WxGUIBlackBoxList::OnDeleteItem)
00074 EVT_LIST_DELETE_ALL_ITEMS(LIST_CTRL, WxGUIBlackBoxList::OnDeleteAllItems)
00075 #if WXWIN_COMPATIBILITY_2_4
00076 EVT_LIST_GET_INFO(LIST_CTRL, WxGUIBlackBoxList::OnGetInfo)
00077 EVT_LIST_SET_INFO(LIST_CTRL, WxGUIBlackBoxList::OnSetInfo)
00078 #endif
00079 EVT_LIST_ITEM_SELECTED(LIST_CTRL, WxGUIBlackBoxList::OnSelected)
00080 EVT_LIST_ITEM_DESELECTED(LIST_CTRL, WxGUIBlackBoxList::OnDeselected)
00081 EVT_LIST_KEY_DOWN(LIST_CTRL, WxGUIBlackBoxList::OnListKeyDown)
00082 EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, WxGUIBlackBoxList::OnActivated)
00083 EVT_LIST_ITEM_FOCUSED(LIST_CTRL, WxGUIBlackBoxList::OnFocused)
00084
00085 EVT_LIST_COL_CLICK(LIST_CTRL, WxGUIBlackBoxList::OnColClick)
00086 EVT_LIST_COL_RIGHT_CLICK(LIST_CTRL, WxGUIBlackBoxList::OnColRightClick)
00087 EVT_LIST_COL_BEGIN_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnColBeginDrag)
00088 EVT_LIST_COL_DRAGGING(LIST_CTRL, WxGUIBlackBoxList::OnColDragging)
00089 EVT_LIST_COL_END_DRAG(LIST_CTRL, WxGUIBlackBoxList::OnColEndDrag)
00090
00091 EVT_LIST_CACHE_HINT(LIST_CTRL, WxGUIBlackBoxList::OnCacheHint)
00092
00093 #if USE_CONTEXT_MENU
00094 EVT_CONTEXT_MENU(WxGUIBlackBoxList::OnContextMenu)
00095 #endif
00096 EVT_CHAR(WxGUIBlackBoxList::OnChar)
00097
00098 EVT_RIGHT_DOWN(WxGUIBlackBoxList::OnRightClick)
00099 END_EVENT_TABLE()
00100
00101 int wxCALLBACK MyCompareFunction(long item1, long item2, long WXUNUSED(sortData))
00102 {
00103
00104 if (item1 < item2)
00105 return -1;
00106 if (item1 > item2)
00107 return 1;
00108
00109 return 0;
00110 }
00111
00112
00113 WxGUIBlackBoxList::WxGUIBlackBoxList(wxWindow *parent,
00114 const wxWindowID id,
00115 const wxPoint& pos,
00116 const wxSize& size,
00117 long style)
00118 : wxListCtrl(parent, id, pos, size, style),
00119 mUser(0),
00120 m_attr(*wxBLUE, *wxLIGHT_GREY, wxNullFont)
00121 {
00122 #ifdef __POCKETPC__
00123 EnableContextMenu();
00124 #endif
00125 }
00126
00127 void WxGUIBlackBoxList::Insert(BlackBoxDescriptor::Pointer d)
00128 {
00129 if (GetColumnCount()!=3)
00130 {
00131 InsertColumn( 0, _("Package"),
00132 wxLIST_FORMAT_LEFT, 90 );
00133 InsertColumn( 1, _("Box"),
00134 wxLIST_FORMAT_LEFT, 150 );
00135 InsertColumn( 2, _("Description"),
00136 wxLIST_FORMAT_LEFT, 500 );
00137 }
00138
00139 wxListItem kNewItem;
00140 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
00141
00142 int nID = this->GetItemCount();
00143 kNewItem.SetId(nID);
00144 kNewItem.SetMask(wxLIST_MASK_DATA);
00145
00146 kNewItem.SetData(d.get());
00147
00148
00149 this->InsertItem(kNewItem);
00150 this->SetItem(nID, 0, std2wx(d->GetPackage()->GetName()) );
00151 this->SetItem(nID, 1, std2wx(d->GetTypeName()) );
00152 this->SetItem(nID, 2, std2wx(d->GetDescription()) );
00153
00154
00155
00156
00157
00158
00159
00160
00161 }
00162
00163
00164 void WxGUIBlackBoxList::OnCacheHint(wxListEvent& event)
00165 {
00166
00167
00168 }
00169
00170 void WxGUIBlackBoxList::SetColumnImage(int col, int image)
00171 {
00172
00173
00174
00175
00176
00177
00178 }
00179
00180 void WxGUIBlackBoxList::OnColClick(wxListEvent& event)
00181 {
00182 int col = event.GetColumn();
00183
00184
00185 static bool x = false;
00186 x = !x;
00187 SetColumnImage(col, x ? 0 : -1);
00188
00189
00190 }
00191
00192 void WxGUIBlackBoxList::OnColRightClick(wxListEvent& event)
00193 {
00194 int col = event.GetColumn();
00195 if ( col != -1 )
00196 {
00197 SetColumnImage(col, -1);
00198 }
00199
00200
00201 wxMenu menu(wxT("Test"));
00202 menu.Append(-1, _T("&About"));
00203 PopupMenu(&menu, event.GetPoint());
00204
00205
00206 }
00207
00208 void WxGUIBlackBoxList::LogColEvent(const wxListEvent& event, const wxChar *name)
00209 {
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 }
00220
00221 void WxGUIBlackBoxList::OnColBeginDrag(wxListEvent& event)
00222 {
00223 LogColEvent( event, wxT("OnColBeginDrag") );
00224
00225
00226
00227
00228
00229
00230
00231
00232 }
00233
00234 void WxGUIBlackBoxList::OnColDragging(wxListEvent& event)
00235 {
00236 LogColEvent( event, wxT("OnColDragging") );
00237 }
00238
00239 void WxGUIBlackBoxList::OnColEndDrag(wxListEvent& event)
00240 {
00241 LogColEvent( event, wxT("OnColEndDrag") );
00242 }
00243
00244 void WxGUIBlackBoxList::OnBeginDrag(wxListEvent& event)
00245 {
00246 std::cout<<"RaC DRAG TABLE"<<std::endl;
00247
00248 wxString text(this->GetItemText(event.GetIndex()));
00249 wxListItem info;
00250 info.m_itemId = event.m_itemIndex;
00251 info.m_col = 0;
00252 info.m_mask = wxLIST_MASK_DATA;
00253 wxString sendtext(_T(""));
00254 if ( GetItem(info) )
00255 {
00256
00257 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
00258 if (d!=0)
00259 {
00260 sendtext += crea::std2wx(d->GetFullTypeName());
00261 }
00262 }
00263 else
00264 {
00265 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
00266 }
00267
00268 wxTextDataObject tdo(sendtext);
00269 wxDropSource tds(tdo, this);
00270 tds.DoDragDrop();
00271
00272
00273
00274
00275
00276 }
00277
00278 void WxGUIBlackBoxList::OnBeginRDrag(wxListEvent& event)
00279 {
00280
00281
00282 }
00283
00284 void WxGUIBlackBoxList::OnBeginLabelEdit(wxListEvent& event)
00285 {
00286
00287 }
00288
00289 void WxGUIBlackBoxList::OnEndLabelEdit(wxListEvent& event)
00290 {
00291
00292
00293
00294 }
00295
00296 void WxGUIBlackBoxList::OnDeleteItem(wxListEvent& event)
00297 {
00298 LogEvent(event, _T("OnDeleteItem"));
00299 std::cout << "cannot del"<<std::endl;
00300 event.Veto();
00301
00302 }
00303
00304 void WxGUIBlackBoxList::OnDeleteAllItems(wxListEvent& event)
00305 {
00306 LogEvent(event, _T("OnDeleteAllItems"));
00307 event.Veto();
00308 }
00309
00310 #if WXWIN_COMPATIBILITY_2_4
00311 void WxGUIBlackBoxList::OnGetInfo(wxListEvent& event)
00312 {
00313 wxString msg;
00314
00315 msg << _T("OnGetInfo (") << event.m_item.m_itemId << _T(", ") << event.m_item.m_col << _T(")");
00316 if ( event.m_item.m_mask & wxLIST_MASK_STATE )
00317 msg << _T(" wxLIST_MASK_STATE");
00318 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
00319 msg << _T(" wxLIST_MASK_TEXT");
00320 if ( event.m_item.m_mask & wxLIST_MASK_IMAGE )
00321 msg << _T(" wxLIST_MASK_IMAGE");
00322 if ( event.m_item.m_mask & wxLIST_MASK_DATA )
00323 msg << _T(" wxLIST_MASK_DATA");
00324 if ( event.m_item.m_mask & wxLIST_SET_ITEM )
00325 msg << _T(" wxLIST_SET_ITEM");
00326 if ( event.m_item.m_mask & wxLIST_MASK_WIDTH )
00327 msg << _T(" wxLIST_MASK_WIDTH");
00328 if ( event.m_item.m_mask & wxLIST_MASK_FORMAT )
00329 msg << _T(" wxLIST_MASK_WIDTH");
00330
00331 if ( event.m_item.m_mask & wxLIST_MASK_TEXT )
00332 {
00333 event.m_item.m_text = _T("My callback text");
00334 }
00335
00336
00337 }
00338
00339 void WxGUIBlackBoxList::OnSetInfo(wxListEvent& event)
00340 {
00341 LogEvent(event, _T("OnSetInfo"));
00342 }
00343 #endif
00344
00345 void WxGUIBlackBoxList::OnSelected(wxListEvent& event)
00346 {
00347 if (mUser==0) return;
00348
00349 wxListItem info;
00350 info.m_itemId = event.m_itemIndex;
00351 info.m_col = 0;
00352 info.m_mask = wxLIST_MASK_DATA;
00353 if ( GetItem(info) )
00354 {
00355
00356 BlackBoxDescriptor* d = (BlackBoxDescriptor*)(info.GetData());
00357 if (d!=0) mUser->WxGUIBlackBoxListUserOnSelected(d);
00358 }
00359 else
00360 {
00361 wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
00362 }
00363 }
00364
00365 void WxGUIBlackBoxList::OnDeselected(wxListEvent& event)
00366 {
00367 LogEvent(event, _T("OnDeselected"));
00368 }
00369
00370 void WxGUIBlackBoxList::OnActivated(wxListEvent& event)
00371 {
00372 LogEvent(event, _T("OnActivated"));
00373 }
00374
00375 void WxGUIBlackBoxList::OnFocused(wxListEvent& event)
00376 {
00377 LogEvent(event, _T("OnFocused"));
00378
00379 event.Skip();
00380 }
00381
00382 void WxGUIBlackBoxList::OnListKeyDown(wxListEvent& event)
00383 {
00384 long item;
00385
00386 switch ( event.GetKeyCode() )
00387 {
00388 case 'c':
00389 case 'C':
00390 {
00391 wxListItem info;
00392 info.m_itemId = event.GetIndex();
00393 if ( info.m_itemId == -1 )
00394 {
00395
00396 break;
00397 }
00398
00399 GetItem(info);
00400
00401 wxListItemAttr *attr = info.GetAttributes();
00402 if ( !attr || !attr->HasTextColour() )
00403 {
00404 info.SetTextColour(*wxCYAN);
00405
00406 SetItem(info);
00407
00408 RefreshItem(info.m_itemId);
00409 }
00410 }
00411 break;
00412
00413 case 'n':
00414 case 'N':
00415 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
00416 if ( item++ == GetItemCount() - 1 )
00417 {
00418 item = 0;
00419 }
00420
00421
00422
00423 SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
00424 EnsureVisible(item);
00425 break;
00426
00427 case 'r':
00428 case 'R':
00429 {
00430 item = event.GetIndex();
00431 wxRect r;
00432 if ( !GetItemRect(item, r) )
00433 {
00434
00435 break;
00436 }
00437
00438
00439
00440 }
00441 break;
00442
00443 case WXK_DELETE:
00444 item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457 break;
00458
00459 case WXK_INSERT:
00460 if ( GetWindowStyle() & wxLC_REPORT )
00461 {
00462 if ( GetWindowStyle() & wxLC_VIRTUAL )
00463 {
00464 SetItemCount(GetItemCount() + 1);
00465 }
00466 else
00467 {
00468
00469 }
00470 }
00471
00472
00473 default:
00474 LogEvent(event, _T("OnListKeyDown"));
00475
00476 event.Skip();
00477 }
00478 }
00479
00480 void WxGUIBlackBoxList::OnChar(wxKeyEvent& event)
00481 {
00482
00483
00484 switch ( event.GetKeyCode() )
00485 {
00486 case 'n':
00487 case 'N':
00488 case 'c':
00489 case 'C':
00490
00491 break;
00492
00493 default:
00494 event.Skip();
00495 }
00496 }
00497
00498 void WxGUIBlackBoxList::OnRightClick(wxMouseEvent& event)
00499 {
00500 if ( !event.ControlDown() )
00501 {
00502 event.Skip();
00503 return;
00504 }
00505
00506 int flags;
00507 long subitem;
00508
00509 HitTest(event.GetPosition(), flags, &subitem);
00510
00511 wxString where;
00512 switch ( flags )
00513 {
00514 case wxLIST_HITTEST_ABOVE: where = _T("above"); break;
00515 case wxLIST_HITTEST_BELOW: where = _T("below"); break;
00516 case wxLIST_HITTEST_NOWHERE: where = _T("nowhere near"); break;
00517 case wxLIST_HITTEST_ONITEMICON: where = _T("on icon of"); break;
00518 case wxLIST_HITTEST_ONITEMLABEL: where = _T("on label of"); break;
00519 case wxLIST_HITTEST_ONITEMRIGHT: where = _T("right on"); break;
00520 case wxLIST_HITTEST_TOLEFT: where = _T("to the left of"); break;
00521 case wxLIST_HITTEST_TORIGHT: where = _T("to the right of"); break;
00522 default: where = _T("not clear exactly where on"); break;
00523 }
00524
00525
00526
00527 }
00528
00529 void WxGUIBlackBoxList::LogEvent(const wxListEvent& event, const wxChar *eventName)
00530 {
00531
00532
00533
00534 }
00535
00536 wxString WxGUIBlackBoxList::OnGetItemText(long item, long column) const
00537 {
00538
00539
00540
00541
00542
00543
00544
00545
00546 return wxString::Format(_T("Column %ld of item %ld"), column, item);
00547
00548 }
00549
00550 int WxGUIBlackBoxList::OnGetItemColumnImage(long item, long column) const
00551 {
00552 if (!column)
00553 return 0;
00554
00555 if (!(item %3) && column == 1)
00556 return 0;
00557
00558 return -1;
00559 }
00560
00561 wxListItemAttr *WxGUIBlackBoxList::OnGetItemAttr(long item) const
00562 {
00563 return item % 2 ? NULL : (wxListItemAttr *)&m_attr;
00564 }
00565
00566
00567 #if USE_CONTEXT_MENU
00568 void WxGUIBlackBoxList::OnContextMenu(wxContextMenuEvent& event)
00569 {
00570 wxPoint point = event.GetPosition();
00571
00572 if (point.x == -1 && point.y == -1) {
00573 wxSize size = GetSize();
00574 point.x = size.x / 2;
00575 point.y = size.y / 2;
00576 } else {
00577 point = ScreenToClient(point);
00578 }
00579 ShowContextMenu(point);
00580 }
00581 #endif
00582
00583 void WxGUIBlackBoxList::ShowContextMenu(const wxPoint& pos)
00584 {
00585 wxMenu menu;
00586
00587 menu.Append(wxID_ABOUT, _T("&About"));
00588 menu.AppendSeparator();
00589 menu.Append(wxID_EXIT, _T("E&xit"));
00590
00591 PopupMenu(&menu, pos.x, pos.y);
00592 }
00593
00594
00595
00596
00597
00598 WxGUIBlackBoxInfo::WxGUIBlackBoxInfo(wxWindow* parent)
00599 :
00600 wxPanel(parent, -1),
00601 mDescriptor()
00602 {
00603 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00604
00605
00606
00607 mDescription = new wxStaticText(this,-1,_T(""));
00608 sizer->Add(mDescription,0,wxGROW);
00609 mAuthor = new wxStaticText(this,-1,_T(""));
00610 sizer->Add(mAuthor,0,wxGROW);
00611 mCategory = new wxStaticText(this,-1,_T(""));
00612 sizer->Add(mCategory,0,wxGROW);
00613
00614 wxBoxSizer *inputs =
00615 new wxStaticBoxSizer
00616 ( new wxStaticBox(this, wxID_ANY, _T("Inputs")), wxVERTICAL );
00617 mInputList = new wxListCtrl(this, -1,
00618 wxDefaultPosition,
00619 wxDefaultSize,
00620 wxLC_REPORT
00621 | wxSUNKEN_BORDER);
00622
00623 inputs->Add(mInputList,1,wxGROW);
00624 sizer->Add(inputs,1,wxGROW);
00625
00626 wxBoxSizer *outputs =
00627 new wxStaticBoxSizer
00628 ( new wxStaticBox(this, wxID_ANY, _T("Outputs")), wxVERTICAL );
00629 mOutputList = new wxListCtrl(this, -1,
00630 wxDefaultPosition,
00631 wxDefaultSize,
00632 wxLC_REPORT
00633 | wxSUNKEN_BORDER);
00634
00635 outputs->Add(mOutputList,1,wxGROW);
00636 sizer->Add(outputs,1,wxGROW);
00637
00638 SetSizer(sizer);
00639 SetAutoLayout(true);
00640 Layout();
00641 }
00642
00643
00644
00645
00646 void WxGUIBlackBoxInfo::UpdateInfo(BlackBoxDescriptor* descr)
00647 {
00648
00649
00650 mDescription->SetLabel(std2wx(descr->GetDescription()));
00651 mAuthor->SetLabel(std2wx(descr->GetAuthor()));
00652 mCategory->SetLabel(std2wx(descr->GetCategory()));
00653
00654 mInputList->ClearAll();
00655 mInputList->InsertColumn( 0, _("Name"),
00656 wxLIST_FORMAT_LEFT, 80 );
00657 mInputList->InsertColumn( 1, _("Type"),
00658 wxLIST_FORMAT_LEFT, 100 );
00659 mInputList->InsertColumn( 2, _("Nature"),
00660 wxLIST_FORMAT_LEFT, 100 );
00661 mInputList->InsertColumn( 3, _("Description"),
00662 wxLIST_FORMAT_LEFT, 500 );
00663
00664 mOutputList->ClearAll();
00665 mOutputList->InsertColumn( 0, _("Name"),
00666 wxLIST_FORMAT_LEFT, 80 );
00667 mOutputList->InsertColumn( 1, _("Type"),
00668 wxLIST_FORMAT_LEFT, 100 );
00669 mOutputList->InsertColumn( 2, _("Nature"),
00670 wxLIST_FORMAT_LEFT, 100 );
00671 mOutputList->InsertColumn( 3, _("Description"),
00672 wxLIST_FORMAT_LEFT, 500 );
00673
00674
00675 std::vector<BlackBoxInputOutputDescriptor*> user_defined;
00676 std::vector<BlackBoxInputOutputDescriptor*> ubb_defined;
00677 std::vector<BlackBoxInputOutputDescriptor*> wxbb_defined;
00678
00679 const BlackBoxDescriptor::InputDescriptorMapType& imap =
00680 descr->GetInputDescriptorMap();
00681 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
00682 for ( in = imap.begin(); in != imap.end(); ++in )
00683 {
00684 int iotype = 0;
00685 if (in->second->GetCreatorTypeInfo() ==
00686 typeid(AtomicBlackBoxDescriptor))
00687 {
00688 iotype = 1;
00689 }
00690 else if (in->second->GetCreatorTypeInfo() ==
00691 typeid(WxBlackBoxDescriptor))
00692 {
00693 iotype = 2;
00694 }
00695 if (iotype==0) user_defined.push_back(in->second);
00696 else if (iotype==1) ubb_defined.push_back(in->second);
00697 else if (iotype==2) wxbb_defined.push_back(in->second);
00698
00699 }
00700
00701 std::vector<BlackBoxInputOutputDescriptor*>::iterator hi;
00702 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
00703 {
00704 InsertInputOutput(mInputList,*hi);
00705 }
00706 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
00707 {
00708 InsertInputOutput(mInputList,*hi);
00709 }
00710 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
00711 {
00712 InsertInputOutput(mInputList,*hi);
00713 }
00714
00715
00716 user_defined.clear();
00717 ubb_defined.clear();
00718 wxbb_defined.clear();
00719 const BlackBoxDescriptor::OutputDescriptorMapType& omap =
00720 descr->GetOutputDescriptorMap();
00721 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator out;
00722 for ( out = omap.begin(); out != omap.end(); ++out )
00723 {
00724 int iotype = 0;
00725 if (out->second->GetCreatorTypeInfo() ==
00726 typeid(AtomicBlackBoxDescriptor))
00727 {
00728 iotype = 1;
00729 }
00730 else if (out->second->GetCreatorTypeInfo() ==
00731 typeid(WxBlackBoxDescriptor))
00732 {
00733 iotype = 2;
00734 }
00735
00736 if (iotype==0) user_defined.push_back(out->second);
00737 else if (iotype==1) ubb_defined.push_back(out->second);
00738 else if (iotype==2) wxbb_defined.push_back(out->second);
00739
00740 }
00741 for (hi=user_defined.begin();hi!=user_defined.end();++hi)
00742 {
00743 InsertInputOutput(mOutputList,*hi);
00744 }
00745 for (hi=wxbb_defined.begin();hi!=wxbb_defined.end();++hi)
00746 {
00747 InsertInputOutput(mOutputList,*hi);
00748 }
00749 for (hi=ubb_defined.begin();hi!=ubb_defined.end();++hi)
00750 {
00751 InsertInputOutput(mOutputList,*hi);
00752 }
00753 }
00754
00755
00756
00757
00758 void WxGUIBlackBoxInfo::InsertInputOutput(wxListCtrl* l,
00759 BlackBoxInputOutputDescriptor* d)
00760 {
00761 wxListItem kNewItem;
00762 kNewItem.SetAlign(wxLIST_FORMAT_LEFT);
00763 int nID = l->GetItemCount();
00764
00765 kNewItem.SetId(nID);
00766
00767
00768 l->InsertItem(kNewItem);
00769 l->SetItem(nID, 0, std2wx(d->GetName()) );
00770 l->SetItem(nID, 1, std2wx(d->GetTypeName()) );
00771 l->SetItem(nID, 2, std2wx(d->GetNature()) );
00772 l->SetItem(nID, 3, std2wx(d->GetDescription()) );
00773 }
00774
00775
00776
00777 WxGUIBlackBoxInfo::~WxGUIBlackBoxInfo()
00778 {
00779 }
00780
00781
00782
00783 enum
00784 {
00785 id_f1,
00786 id_f2,
00787 id_f3,
00788 id_f4,
00789 id_f5,
00790 id_f6,
00791 id_f7,
00792 id_f8,
00793 id_fc1,
00794 id_fc2,
00795 id_fc3
00796 };
00797
00798
00799 WxGUIPackageBrowser2::WxGUIPackageBrowser2( wxWindow *parent,
00800 WxGUIPackageBrowser2User* user )
00801 : wxPanel(parent, -1),
00802 mUser(user),
00803 mInterpreter()
00804 {
00805 _actualSelected=NULL;
00806 m_mgr.SetManagedWindow(this);
00807
00808
00809 mBoxList = new WxGUIBlackBoxList(this, LIST_CTRL,
00810 wxDefaultPosition,
00811 wxDefaultSize,
00812 wxLC_REPORT
00813 | wxSUNKEN_BORDER);
00814 mBoxList->SetUser(this);
00815 mBoxList->SetBackgroundColour(*wxWHITE);
00816
00817
00818
00819 m_mgr.AddPane(mBoxList,
00820 wxAuiPaneInfo().Name(wxT("BoxList"))
00821 .Caption(wxT("Black Boxes"))
00822 .MinimizeButton(true)
00823 .MaximizeButton(true)
00824 .Center()
00825 .MinSize(wxSize(100,100))
00826 .CloseButton(false)
00827 );
00828
00829
00830 mBoxInfo = new WxGUIBlackBoxInfo(this);
00831
00832
00833
00834 m_mgr.AddPane(mBoxInfo,
00835 wxAuiPaneInfo().Name(wxT("Box"))
00836 .Caption(wxT(""))
00837 .MinimizeButton(true)
00838 .MaximizeButton(true)
00839 .Bottom()
00840 .MinSize(wxSize(100,200))
00841 .CloseButton(false)
00842 );
00843
00844 wxPanel* filters = new wxPanel(this,-1);
00845 wxBoxSizer *fsizer = new wxBoxSizer(wxVERTICAL );
00846 wxBoxSizer *fpack =
00847 new wxStaticBoxSizer
00848 ( new wxStaticBox(filters, wxID_ANY, _T("Package")), wxHORIZONTAL );
00849 mPackageFilter = new wxTextCtrl(filters,id_f1,_T(""),
00850 wxDefaultPosition,
00851 wxDefaultSize,
00852 wxTE_PROCESS_ENTER);
00853 fpack->Add(mPackageFilter,1,wxGROW);
00854 fsizer->Add(fpack,0,wxGROW);
00855 wxBoxSizer *fname =
00856 new wxStaticBoxSizer
00857 ( new wxStaticBox(filters, wxID_ANY, _T("Name")), wxHORIZONTAL );
00858 mNameFilter = new wxTextCtrl(filters,id_f2,_T(""),
00859 wxDefaultPosition,
00860 wxDefaultSize,
00861 wxTE_PROCESS_ENTER);
00862 fname->Add(mNameFilter,1,wxGROW);
00863 fsizer->Add(fname,0,wxGROW);
00864 wxBoxSizer *fdescr =
00865 new wxStaticBoxSizer
00866 ( new wxStaticBox(filters, wxID_ANY, _T("Description")), wxHORIZONTAL );
00867 mDescriptionFilter = new wxTextCtrl(filters,id_f3,_T(""),
00868 wxDefaultPosition,
00869 wxDefaultSize,
00870 wxTE_PROCESS_ENTER);
00871 fdescr->Add(mDescriptionFilter,1,wxGROW);
00872 fsizer->Add(fdescr,0,wxGROW);
00873 wxBoxSizer *fcat =
00874 new wxStaticBoxSizer
00875 ( new wxStaticBox(filters, wxID_ANY, _T("Category")), wxHORIZONTAL );
00876 mCategoryFilter = new wxTextCtrl(filters,id_f4,_T(""),
00877 wxDefaultPosition,
00878 wxDefaultSize,
00879 wxTE_PROCESS_ENTER);
00880 fcat->Add(mCategoryFilter,1,wxGROW);
00881 fsizer->Add(fcat,0,wxGROW);
00882 wxBoxSizer *fintype =
00883 new wxStaticBoxSizer
00884 ( new wxStaticBox(filters, wxID_ANY, _T("Input type")), wxHORIZONTAL );
00885 mInputTypeFilter = new wxTextCtrl(filters,id_f5,_T(""),
00886 wxDefaultPosition,
00887 wxDefaultSize,
00888 wxTE_PROCESS_ENTER);
00889 fintype->Add(mInputTypeFilter,1,wxGROW);
00890 fsizer->Add(fintype,0,wxGROW);
00891 wxBoxSizer *fouttype =
00892 new wxStaticBoxSizer
00893 ( new wxStaticBox(filters, wxID_ANY, _T("Output type")), wxHORIZONTAL );
00894 mOutputTypeFilter = new wxTextCtrl(filters,id_f6,_T(""),
00895 wxDefaultPosition,
00896 wxDefaultSize,
00897 wxTE_PROCESS_ENTER);
00898 fouttype->Add(mOutputTypeFilter,1,wxGROW);
00899 fsizer->Add(fouttype,0,wxGROW);
00900 wxBoxSizer *finnat =
00901 new wxStaticBoxSizer
00902 ( new wxStaticBox(filters, wxID_ANY, _T("Input nature")),wxHORIZONTAL );
00903 mInputNatureFilter = new wxTextCtrl(filters,id_f7,_T(""),
00904 wxDefaultPosition,
00905 wxDefaultSize,
00906 wxTE_PROCESS_ENTER);
00907 finnat->Add(mInputNatureFilter,1,wxGROW);
00908 fsizer->Add(finnat,0,wxGROW);
00909 wxBoxSizer *foutnat =
00910 new wxStaticBoxSizer
00911 ( new wxStaticBox(filters, wxID_ANY,_T("Output nature")),wxHORIZONTAL );
00912 mOutputNatureFilter = new wxTextCtrl(filters,id_f8,_T(""),
00913 wxDefaultPosition,
00914 wxDefaultSize,
00915 wxTE_PROCESS_ENTER);
00916 foutnat->Add(mOutputNatureFilter,1,wxGROW);
00917 fsizer->Add(foutnat,0,wxGROW);
00918
00919 mShowWidgetsFilter = new wxCheckBox(filters,id_fc1,_T("Show widgets"));
00920 mShowWidgetsFilter->SetValue(true);
00921 fsizer->Add(mShowWidgetsFilter,0,wxGROW);
00922
00923 mShowAdaptorsFilter = new wxCheckBox(filters,id_fc2,_T("Show adaptors"));
00924 mShowAdaptorsFilter->SetValue(false);
00925 fsizer->Add(mShowAdaptorsFilter,0,wxGROW);
00926
00927 mShowGUIsFilter = new wxCheckBox(filters,id_fc3,_T("Show GUIs"));
00928 mShowGUIsFilter->SetValue(false);
00929 fsizer->Add(mShowGUIsFilter,0,wxGROW);
00930
00931 filters->SetSizer(fsizer);
00932
00933
00934 m_mgr.AddPane(filters,
00935 wxAuiPaneInfo().Name(wxT("Filter"))
00936 .Caption(wxT("Filter"))
00937 .MinimizeButton(true)
00938 .MaximizeButton(true)
00939 .Left()
00940 .MinSize(wxSize(100,100))
00941 .CloseButton(false)
00942 );
00943
00944
00945 m_mgr.Update();
00946
00947
00948 SetAutoLayout(true);
00949 Layout();
00950
00951 }
00952
00953
00954 Factory::Pointer WxGUIPackageBrowser2::GetFactory()
00955 {
00956 return mFactory;
00957 }
00958
00959
00960
00961
00962
00963 void WxGUIPackageBrowser2::OnFilter(wxCommandEvent&)
00964 {
00965 RebuildList();
00966 }
00967
00968
00969
00970
00971 void WxGUIPackageBrowser2::WxGUIBlackBoxListUserOnSelected
00972 ( BlackBoxDescriptor* d)
00973 {
00974
00975 _actualSelected=d;
00976
00977 mBoxInfo->UpdateInfo(d);
00978 std::string title = d->GetPackage()->GetName()+"::"+d->GetTypeName();
00979 m_mgr.GetPane(mBoxInfo).Caption(std2wx(title));
00980 m_mgr.Update();
00981 }
00982
00983
00984
00985
00986 BlackBoxDescriptor* WxGUIPackageBrowser2::GetActualSelected()
00987 {
00988 return _actualSelected;
00989 }
00990
00991
00992
00993
00994 WxGUIPackageBrowser2::~WxGUIPackageBrowser2()
00995 {
00996 mFactory.reset();
00997 mInterpreter.reset();
00998
00999 m_mgr.UnInit();
01000 }
01001
01002
01003
01004 void WxGUIPackageBrowser2::IncludeAll()
01005 {
01006 if (!mInterpreter) mInterpreter =bbtk::Interpreter::New();
01007 mInterpreter->SetCommandLine(true);
01008 std::stringstream* buf = new std::stringstream;
01009 *buf << "exec freeze_no_error" << std::endl;
01010 *buf << "message max 0" << std::endl;
01011 *buf << "include *" << std::endl;
01012 mInterpreter->InterpretBuffer(buf);
01013
01014 Factory::Pointer F = mInterpreter->GetExecuter()->GetFactory();
01015 BuildFromFactory(F);
01016 }
01017
01018
01019
01020 void WxGUIPackageBrowser2::BuildFromFactory(Factory::Pointer F)
01021 {
01022 mFactory = F;
01023 RebuildList();
01024 }
01025
01026
01027
01028
01029 void WxGUIPackageBrowser2::RebuildList()
01030 {
01031 mBoxList->Hide();
01032 mBoxList->ClearAll();
01033
01034 const Factory::PackageMapType& M = mFactory->GetPackageMap();
01035 Factory::PackageMapType::const_iterator i;
01036 for (i=M.begin();i!=M.end();++i)
01037 {
01038 Package::Pointer P = i->second;
01039 if (P->GetName() == "user") continue;
01040
01041 Package::DescriptorMapType::iterator j;
01042 for (j=P->GetDescriptorMap().begin();
01043 j!=P->GetDescriptorMap().end();
01044 ++j)
01045 {
01046
01047 if (IsVisible(j->second))
01048 mBoxList->Insert(j->second);
01049 }
01050 }
01051 mBoxList->Show();
01052 }
01053
01054
01055 bool WxGUIPackageBrowser2::findnpos(const std::string &strA, const std::string &strB )
01056 {
01057 if ((strB=="") || (strA=="") )
01058 {
01059 return false;
01060 }
01061
01062 bool ok=false;
01063 int i,size;
01064 std::string strAA=strA;
01065 std::string strBB=strB;
01066
01067
01068 size=strAA.length();
01069 for (i=0;i<size;i++)
01070 {
01071 if ((strAA[i]>='A')&&(strAA[i]<='Z'))
01072 {
01073 strAA[i]=strAA[i]+32;
01074 }
01075 }
01076
01077 size=strBB.length();
01078 for (i=0;i<size;i++)
01079 {
01080 if ((strBB[i]>='A')&&(strBB[i]<='Z'))
01081 {
01082 strBB[i]=strBB[i]+32;
01083 }
01084 }
01085
01086
01087 if ( strAA.find(strBB) == std::string::npos )
01088 {
01089 ok=true;
01090 }
01091
01092 return ok;
01093 }
01094
01095
01096 bool WxGUIPackageBrowser2::IsVisible(BlackBoxDescriptor::Pointer d)
01097 {
01098
01099
01100 if ((!mShowAdaptorsFilter->IsChecked())&&
01101 ((d->GetKind()==BlackBoxDescriptor::ADAPTOR)||
01102 (d->GetKind()==BlackBoxDescriptor::DEFAULT_ADAPTOR)))
01103 {
01104 return false;
01105 }
01106
01107 if ((!mShowGUIsFilter->IsChecked())&&
01108 ((d->GetKind()==BlackBoxDescriptor::GUI)||
01109 (d->GetKind()==BlackBoxDescriptor::DEFAULT_GUI)))
01110 {
01111 return false;
01112 }
01113
01114
01115 if ( findnpos(d->GetPackage()->GetName(),wx2std(mPackageFilter->GetValue())) == true )
01116 {
01117 return false;
01118 }
01119
01120
01121 if ( findnpos(d->GetTypeName(),wx2std(mNameFilter->GetValue())) == true )
01122 {
01123 return false;
01124 }
01125
01126
01127 if ( findnpos(d->GetDescription(),wx2std(mDescriptionFilter->GetValue())) == true )
01128 {
01129 return false;
01130 }
01131
01132
01133 if ( findnpos(d->GetCategory(),wx2std(mCategoryFilter->GetValue())) == true )
01134 {
01135 return false;
01136 }
01137
01138 if (!mShowWidgetsFilter->IsChecked())
01139 {
01140 bool found = false;
01141 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
01142 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
01143 for ( in = imap.begin(); in != imap.end(); ++in )
01144 {
01145 if (in->second->GetName() == "Widget" )
01146 {
01147 found = true;
01148 break;
01149 }
01150 }
01151 if (found)
01152 {
01153 return false;
01154 }
01155 }
01156
01157 if (mInputTypeFilter->GetValue().size()>0)
01158 {
01159 std::string s = wx2std(mInputTypeFilter->GetValue());
01160 bool found = false;
01161 const BlackBoxDescriptor::InputDescriptorMapType& imap = d->GetInputDescriptorMap();
01162 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
01163 for ( in = imap.begin(); in != imap.end(); ++in )
01164 {
01165
01166 if ( findnpos( in->second->GetTypeName() , s ) == true )
01167 {
01168 found = true;
01169 break;
01170 }
01171 }
01172 if (!found)
01173 {
01174 return false;
01175 }
01176 }
01177
01178 if (mOutputTypeFilter->GetValue().size()>0)
01179 {
01180 std::string s = wx2std(mOutputTypeFilter->GetValue());
01181 bool found = false;
01182 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
01183 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
01184 for ( in = imap.begin(); in != imap.end(); ++in )
01185 {
01186
01187 if ( findnpos( in->second->GetTypeName() , s ) == true )
01188 {
01189 found = true;
01190 break;
01191 }
01192 }
01193 if (!found)
01194 {
01195 return false;
01196 }
01197 }
01198
01199 if (mInputNatureFilter->GetValue().size()>0)
01200 {
01201 std::string s = wx2std(mInputNatureFilter->GetValue());
01202 bool found = false;
01203 const BlackBoxDescriptor::InputDescriptorMapType& imap = d->GetInputDescriptorMap();
01204 BlackBoxDescriptor::InputDescriptorMapType::const_iterator in;
01205 for ( in = imap.begin(); in != imap.end(); ++in )
01206 {
01207
01208 if ( findnpos( in->second->GetNature() , s ) == true )
01209 {
01210 found = true;
01211 break;
01212 }
01213 }
01214 if (!found)
01215 {
01216 return false;
01217 }
01218 }
01219
01220 if (mOutputNatureFilter->GetValue().size()>0)
01221 {
01222 std::string s = wx2std(mOutputNatureFilter->GetValue());
01223 bool found = false;
01224 const BlackBoxDescriptor::OutputDescriptorMapType& imap = d->GetOutputDescriptorMap();
01225 BlackBoxDescriptor::OutputDescriptorMapType::const_iterator in;
01226 for ( in = imap.begin(); in != imap.end(); ++in )
01227 {
01228
01229 if ( findnpos( in->second->GetNature() , s ) == true )
01230 {
01231 found = true;
01232 break;
01233 }
01234 }
01235 if (!found)
01236 {
01237 return false;
01238 }
01239 }
01240
01241 return true;
01242
01243 }
01244
01245
01246
01247 BEGIN_EVENT_TABLE(WxGUIPackageBrowser2, wxPanel)
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257 EVT_TEXT(id_f1, WxGUIPackageBrowser2::OnFilter )
01258 EVT_TEXT(id_f2, WxGUIPackageBrowser2::OnFilter )
01259 EVT_TEXT(id_f3, WxGUIPackageBrowser2::OnFilter )
01260 EVT_TEXT(id_f4, WxGUIPackageBrowser2::OnFilter )
01261 EVT_TEXT(id_f5, WxGUIPackageBrowser2::OnFilter )
01262 EVT_TEXT(id_f6, WxGUIPackageBrowser2::OnFilter )
01263 EVT_TEXT(id_f7, WxGUIPackageBrowser2::OnFilter )
01264 EVT_TEXT(id_f8, WxGUIPackageBrowser2::OnFilter )
01265
01266 EVT_CHECKBOX( id_fc1, WxGUIPackageBrowser2::OnFilter )
01267 EVT_CHECKBOX( id_fc2, WxGUIPackageBrowser2::OnFilter )
01268 EVT_CHECKBOX( id_fc3, WxGUIPackageBrowser2::OnFilter )
01269 END_EVENT_TABLE()
01270
01271
01272
01273
01274
01275 WxGUIPackageBrowser2Window::WxGUIPackageBrowser2Window( wxWindow *parent,
01276 wxString title,
01277 wxSize size)
01278 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
01279 {
01280 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
01281
01282 mBrowser = new WxGUIPackageBrowser2(this);
01283 mBrowser->IncludeAll();
01284 sizer->Add(mBrowser,1,wxGROW);
01285
01286
01287
01288
01289 SetSizer(sizer);
01290
01291
01292
01293
01294
01295
01296 SetAutoLayout(true);
01297 Layout();
01298 }
01299
01300
01301
01302 WxGUIPackageBrowser2Window::~WxGUIPackageBrowser2Window()
01303 {
01304 }
01305
01306
01307 }
01308
01309
01310 #endif //_USE_WXWIDGETS_