X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=packages%2Fwx%2Fsrc%2FbbwxComboBox.cxx;fp=packages%2Fwx%2Fsrc%2FbbwxComboBox.cxx;h=5b8ab4529fd67dc9d3f18f03cab898b5fd70eae2;hb=427d8c0ac838ab789a57b28f62a7f9ff243e7b60;hp=0000000000000000000000000000000000000000;hpb=c2d2ccbc4bac635e5d0b802d9830efd94b060dab;p=bbtk.git diff --git a/packages/wx/src/bbwxComboBox.cxx b/packages/wx/src/bbwxComboBox.cxx new file mode 100644 index 0000000..5b8ab45 --- /dev/null +++ b/packages/wx/src/bbwxComboBox.cxx @@ -0,0 +1,232 @@ +//===== +// 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 ); + ~ComboBoxWidget(); + void OnComboBoxSelection(int iSelection); + void OnComboBox(wxEvent& event); + void FillItems( int iSelection, std::vector< std::string > lstIn); + + private: + int mTypeForm; + ComboBox *mBox; + wxListBox *wxlistbox; + wxChoice *wxchoice; + }; + + + + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + + //------------------------------------------------------------------------- + ComboBoxWidget::ComboBoxWidget( ComboBox* box, + wxWindow *parent, + int iSelection, + std::string title, + std::vector< std::string > lstIn, + int typeForm) + : + wxPanel( parent, -1) , + mBox(box), + mTypeForm(typeForm) + { + wxPanel *panel = this; + wxlistbox = NULL; + wxchoice = 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); + + //--------------------------------------------------------------------- + // 1) Creation de wxChoise widget + + if (mTypeForm==1) + { + + wxlistbox = new wxListBox ( panel , -1 ); + Connect( wxlistbox->GetId(), wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); + for (i=0;iAppend( bbtk::std2wx( lstIn[i] ) ); + } // for i + wxlistbox->SetSelection(iSelection); + sizer->Add( wxlistbox,1,wxGROW ); + + } else { + + wxchoice = new wxChoice ( panel , -1 ); + Connect( wxchoice->GetId(), wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); + for (i=0;iAppend( bbtk::std2wx( lstIn[i] ) ); + } // for i + wxchoice->SetSelection(iSelection); + sizer->Add( wxchoice,1,wxGROW ); + } +// panel->SetAutoLayout(true); +// panel->Layout(); + } + //------------------------------------------------------------------------- + + ComboBoxWidget::~ComboBoxWidget() + { + } + + + //-------------------------------------------------------------------------- + void ComboBoxWidget::OnComboBoxSelection(int iSelection) + { + mBox->bbSetInputSelection( iSelection ); + mBox->bbSetOutputOut( iSelection ); + mBox->bbSetOutputOutString( bbtk::wx2std( wxchoice->GetString(iSelection) ) ); + mBox->bbSignalOutputModification("Out"); + mBox->bbSignalOutputModification("OutString"); + } + + //-------------------------------------------------------------------------- + void ComboBoxWidget::OnComboBox(wxEvent& event) + { + int iSelection; + if (mTypeForm==1) + { + iSelection = wxlistbox->GetSelection(); + } else { + iSelection = wxchoice->GetSelection(); + } + OnComboBoxSelection(iSelection); + } +//-------------------------------------------------------------------------- + void ComboBoxWidget::FillItems( + int iSelection, + std::vector< std::string > lstIn + ) + { + int i; + if (mTypeForm==1) + { + wxlistbox->Clear(); + + for (i=0;iAppend( bbtk::std2wx( lstIn[i] ) ); + } // for i + + wxlistbox->SetSelection(iSelection); + } else { + wxchoice->Clear(); + for (i=0;iAppend( bbtk::std2wx( lstIn[i] ) ); + } // for i + wxchoice->SetSelection(iSelection); + } // if + } + +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 ] ); + } +// bbSignalOutputModification("Out"); +// bbSignalOutputModification("OutString"); +} + +//===== +// 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) +{ + +// bbSetOutputWidget( new wxStaticText ( parent , -1 , _T("") ) ); +// bbSetOutputWidget( new wxComboBox ( parent , -1 , _T("ups") ) ); +// bbSetOutputWidget( new wxChoice ( parent , -1 ) ); + + ComboBoxWidget *w = new ComboBoxWidget( + this, + parent, + bbGetInputSelection() , + bbGetInputTitle(), + bbGetInputIn(), + bbGetInputForm() ); + + 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); +} +//===== +// 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 + +