//===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== #include "bbwxComboBox.h" #include "bbwxPackage.h" #include #include #include #include #include namespace bbwx { //-------------------------------------------------------------------------- // The widget created by the box class ComboBoxWidget : public wxPanel { public: ComboBoxWidget( ComboBox* box, wxWindow *parent, int iSelection, std::string title, std::vector< std::string > lstIn, int typeForm, int sizeX, int sizeY ); ~ComboBoxWidget(); void OnComboBoxSelection(int iSelection); void OnComboBox(wxEvent& event); void FillItems( int iSelection, std::vector< std::string > lstIn); void VerifyDeselect(int iSelection); private: int mTypeForm; ComboBox *mBox; wxItemContainer* itemcontainer; }; //------------------------------------------------------------------------ //------------------------------------------------------------------------ //------------------------------------------------------------------------ //------------------------------------------------------------------------- ComboBoxWidget::ComboBoxWidget( ComboBox* box, wxWindow *parent, int iSelection, std::string title, std::vector< std::string > lstIn, int typeForm, int sizeX, int sizeY ) : wxPanel( parent, -1,wxDefaultPosition,wxSize(sizeX,sizeY) ) , mBox(box), mTypeForm(typeForm) { wxPanel *panel = this; itemcontainer = NULL; int i; //--------------------------------------------------------------------- // 2) Insertion of the components in the window // We use a FlexGridSizer wxFlexGridSizer *sizer = new wxFlexGridSizer(1); if (title!="") { sizer->Add( new wxStaticText(panel,-1, bbtk::std2wx(title) ) ); } sizer->AddGrowableCol(0); panel->SetSizer(sizer); //--------------------------------------------------------------------- if (mTypeForm==1) { wxListBox *wxlistbox = new wxListBox ( panel , -1 , wxDefaultPosition,wxSize(sizeX,sizeY),0, NULL, wxLB_SINGLE ); itemcontainer=wxlistbox; sizer->Add( wxlistbox,1,wxEXPAND ); Connect( wxlistbox->GetId(), wxEVT_COMMAND_LISTBOX_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); } else if (mTypeForm==0) { wxChoice *wxchoice = new wxChoice ( panel , -1 ); itemcontainer=wxchoice; sizer->Add( wxchoice,1,wxGROW ); Connect( wxchoice->GetId(), wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); } for (i=0;iAppend( bbtk::std2wx( lstIn[i] ) ); } // for i // itemcontainer->SetSelection(iSelection); } //------------------------------------------------------------------------- ComboBoxWidget::~ComboBoxWidget() { } //-------------------------------------------------------------------------- void ComboBoxWidget::VerifyDeselect(int iSelection) { if ((iSelection>=0) && (mBox->bbGetInputDeselect()==true) ) { if (mTypeForm==1) { ((wxListBox*)itemcontainer)->Deselect( iSelection ); } // if mTypeForm } // if iSelection } //-------------------------------------------------------------------------- void ComboBoxWidget::OnComboBoxSelection(int iSelection) { if (iSelection>=0) { mBox->bbSetInputSelection( iSelection ); mBox->bbSetOutputOut( iSelection ); mBox->bbSetOutputOutString( bbtk::wx2std( itemcontainer->GetString(iSelection) ) ); mBox->bbSignalOutputModification(); VerifyDeselect(iSelection); // mBox->bbSignalOutputModification("Out"); // mBox->bbSignalOutputModification("OutString"); } // if iSelection } //-------------------------------------------------------------------------- void ComboBoxWidget::OnComboBox(wxEvent& event) { OnComboBoxSelection( itemcontainer->GetSelection() ); } //-------------------------------------------------------------------------- void ComboBoxWidget::FillItems( int iSelection, std::vector< std::string > lstIn ) { int i; itemcontainer->Clear(); for (i=0;iAppend( bbtk::std2wx( lstIn[i] ) ); } // for i if (iSelection>=0) itemcontainer->SetSelection(iSelection); } BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ComboBox) BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,bbtk::WxBlackBox); //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void ComboBox::Process() { int iSelection = bbGetInputSelection(); if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=bbGetInputIn().size()-1; } ComboBoxWidget *w = (ComboBoxWidget*)bbGetOutputWidget(); w->FillItems( iSelection, bbGetInputIn() ); bbSetInputSelection( iSelection ); bbSetOutputOut( iSelection ); int size = bbGetInputIn().size(); if ( (iSelection>0) && ( (size-1)<=iSelection) ) { bbSetOutputOutString( bbGetInputIn()[ iSelection ] ); } // if iSelection w->VerifyDeselect(iSelection); } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void ComboBox::CreateWidget(wxWindow* parent) { ComboBoxWidget *w = new ComboBoxWidget( this, parent, bbGetInputSelection() , bbGetInputTitle(), bbGetInputIn(), bbGetInputForm(), bbGetInputWinWidth(), bbGetInputWinHeight() ); bbSetOutputOut( bbGetInputSelection() ); bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] ); bbSetOutputWidget( w ); } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void ComboBox::bbUserSetDefaultValues() { bbSetInputSelection(0); bbSetInputTitle(""); bbSetInputForm(0); bbSetInputWinWidth(100); bbSetInputWinHeight(200); bbSetInputDeselect(false); } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void ComboBox::bbUserInitializeProcessing() { } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== void ComboBox::bbUserFinalizeProcessing() { } } // EO namespace bbwx