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