X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=packages%2Fwx%2Fsrc%2FbbwxComboBox.cxx;h=fe33889c4566fd674672e0e2d6522f308b550337;hb=0345dcb3faf8bb412c0996a5443cb9b9046423b3;hp=5b8ab4529fd67dc9d3f18f03cab898b5fd70eae2;hpb=f1f889cb5984a875203fb13008977d8bcc740258;p=bbtk.git diff --git a/packages/wx/src/bbwxComboBox.cxx b/packages/wx/src/bbwxComboBox.cxx index 5b8ab45..fe33889 100644 --- a/packages/wx/src/bbwxComboBox.cxx +++ b/packages/wx/src/bbwxComboBox.cxx @@ -12,6 +12,8 @@ #include #include +#include + namespace bbwx { //-------------------------------------------------------------------------- @@ -23,17 +25,22 @@ namespace bbwx int iSelection, std::string title, std::vector< std::string > lstIn, - int typeForm ); + 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); + + void OnSpinCtrlClick(wxCommandEvent& event); + private: int mTypeForm; ComboBox *mBox; - wxListBox *wxlistbox; - wxChoice *wxchoice; + wxItemContainer *itemcontainer; + wxSpinButton *mwxspinbutton; }; @@ -44,164 +51,227 @@ namespace bbwx //------------------------------------------------------------------------- ComboBoxWidget::ComboBoxWidget( ComboBox* box, - wxWindow *parent, - int iSelection, - std::string title, - std::vector< std::string > lstIn, - int typeForm) + wxWindow *parent, + int iSelection, + std::string title, + std::vector< std::string > lstIn, + int typeForm, + int sizeX, + int sizeY + ) : - wxPanel( parent, -1) , + wxPanel( parent, -1,wxDefaultPosition ) , mBox(box), mTypeForm(typeForm) { - wxPanel *panel = this; - wxlistbox = NULL; - wxchoice = NULL; - int i; - + mwxspinbutton = NULL; + itemcontainer = NULL; + wxPanel *panel = this; + int i; //--------------------------------------------------------------------- // 2) Insertion of the components in the window // We use a FlexGridSizer - wxFlexGridSizer *sizer = new wxFlexGridSizer(1); +// wxFlexGridSizer *sizerV = new wxFlexGridSizer(1); +// wxFlexGridSizer *sizerH1 = new wxFlexGridSizer(0); +// wxFlexGridSizer *sizerH2 = new wxFlexGridSizer(2); + wxFlexGridSizer *sizer = new wxFlexGridSizer(2); + if (title!="") { sizer->Add( new wxStaticText(panel,-1, bbtk::std2wx(title) ) ); + sizer->Add( new wxStaticText(panel,-1, _T("") ) ); } - sizer->AddGrowableCol(0); - panel->SetSizer(sizer); - //--------------------------------------------------------------------- - // 1) Creation de wxChoise widget - - if (mTypeForm==1) - { + 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, wxDefaultPosition,wxSize(sizeX,sizeY)); + itemcontainer=wxchoice; + sizer->Add( wxchoice,1,wxGROW ); + Connect( wxchoice->GetId(), + wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); + } + + if (mBox->bbGetInputWithSpinButton()==true) + { + mwxspinbutton = new wxSpinButton( panel, -1 ); + Connect( mwxspinbutton->GetId(), + wxEVT_SPIN, + (wxObjectEventFunction) + (void (wxPanel::*)(wxScrollEvent&)) + &ComboBoxWidget::OnSpinCtrlClick); + sizer->Add( mwxspinbutton,1,wxEXPAND ); + } + sizer->AddGrowableCol(0); - 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(); + panel->SetSizer(sizer); + FillItems( iSelection,lstIn ); } - //------------------------------------------------------------------------- - + + //------------------------------------------------------------------------- ComboBoxWidget::~ComboBoxWidget() { } - //-------------------------------------------------------------------------- - void ComboBoxWidget::OnComboBoxSelection(int iSelection) + void ComboBoxWidget::VerifyDeselect(int iSelection) { - mBox->bbSetInputSelection( iSelection ); - mBox->bbSetOutputOut( iSelection ); - mBox->bbSetOutputOutString( bbtk::wx2std( wxchoice->GetString(iSelection) ) ); - mBox->bbSignalOutputModification("Out"); - mBox->bbSignalOutputModification("OutString"); + if ((iSelection>=0) && (mBox->bbGetInputDeselect()==true) ) + { + if (mTypeForm==1) + { + ((wxListBox*)itemcontainer)->Deselect( iSelection ); + } // if mTypeForm + } // if iSelection } //-------------------------------------------------------------------------- - void ComboBoxWidget::OnComboBox(wxEvent& event) + void ComboBoxWidget::OnComboBoxSelection(int iSelection) { - int iSelection; - if (mTypeForm==1) - { - iSelection = wxlistbox->GetSelection(); - } else { - iSelection = wxchoice->GetSelection(); - } - OnComboBoxSelection(iSelection); + if (iSelection>=0) + { + mBox->bbSetInputSelection( iSelection ); + mBox->bbSetOutputOut( iSelection ); + +// Patch to clean the spaces at the begining + std::string tmpStr = bbtk::wx2std( itemcontainer->GetString(iSelection) ); + if (tmpStr.length()>0) { while(tmpStr[0]==' ') tmpStr.erase(0,1); } + mBox->bbSetOutputOutString( tmpStr ); +// mBox->bbSetOutputOutString( bbtk::wx2std( itemcontainer->GetString(iSelection) ) ); + + mBox->bbSignalOutputModification(); + VerifyDeselect(iSelection); + if (mTypeForm==0) + { + wxChoice *wxchoise=(wxChoice *)itemcontainer; + wxchoise->SetToolTip( itemcontainer->GetString(iSelection) ); + } // if mTypeForm + + +// mBox->bbSignalOutputModification("Out"); +// mBox->bbSignalOutputModification("OutString"); + } // if iSelection } + +//-------------------------------------------------------------------------- +void ComboBoxWidget::OnComboBox(wxEvent& event) +{ + int iSelection = itemcontainer->GetSelection(); + OnComboBoxSelection( iSelection ); + if (mBox->bbGetInputWithSpinButton()==true) + { + mwxspinbutton->SetValue( iSelection ); + } + +} + +//-------------------------------------------------------------------------- +void ComboBoxWidget::OnSpinCtrlClick(wxCommandEvent& event) +{ + int iSelection = mwxspinbutton->GetValue(); + itemcontainer->SetSelection(iSelection); + OnComboBoxSelection( iSelection ); +} + + //-------------------------------------------------------------------------- - void ComboBoxWidget::FillItems( - int iSelection, - std::vector< std::string > lstIn - ) +void ComboBoxWidget::FillItems( int iSelection, std::vector< std::string > lstIn ) +{ + int i,size = lstIn.size(); + + +#if defined(_WIN32) + // Patch to put spaces at the beginin +#else + // Patch to put spaces at the beginin + int strLength=-1; + // Looking for the longest string + for (i=0 ;iClear(); + for (i=0;iAppend( bbtk::std2wx( lstIn[i] ) ); + } // for i + if (iSelection>=0) + { + itemcontainer->SetSelection(iSelection); + if (mBox->bbGetInputWithSpinButton()==true) { - 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 - } + mwxspinbutton->SetRange( 0,size-1 ); + mwxspinbutton->SetValue( iSelection ); + } + + } // iSelection + + if (mTypeForm==0) + { + ((wxChoice*)itemcontainer)->SetAutoLayout( true ); + ((wxChoice*)itemcontainer)->Layout( ); + } // if mTypeForm +} 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; } +// if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=bbGetInputIn().size()-1; } + if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=0; } ComboBoxWidget *w = (ComboBoxWidget*)bbGetOutputWidget(); w->FillItems( iSelection, bbGetInputIn() ); bbSetInputSelection( iSelection ); bbSetOutputOut( iSelection ); - int size = bbGetInputIn().size(); - if ( (iSelection>0) && ( (size-1)<=iSelection) ) - { + if ( (iSelection>=0) && ( iSelectionVerifyDeselect(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) { - -// 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() ); - + bbGetInputForm(), + bbGetInputWinWidth(), bbGetInputWinHeight() ); bbSetOutputOut( bbGetInputSelection() ); - bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] ); + if (bbGetInputIn().size()> bbGetInputSelection() ) + { + bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] ); + } // if InputIn size 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) @@ -211,13 +281,16 @@ void ComboBox::bbUserSetDefaultValues() bbSetInputSelection(0); bbSetInputTitle(""); bbSetInputForm(0); + bbSetInputWinWidth(10); + bbSetInputWinHeight(45); + bbSetInputDeselect(false); + bbSetInputWithSpinButton(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)