#include <string>
#include <wx/choice.h>
+#include <wx/control.h>
+#include <wx/listbox.h>
namespace bbwx
{
{
public:
ComboBoxWidget( ComboBox* box, wxWindow *parent,
- int iSelection,
- std::string title,
- std::vector< std::string > lstIn );
-
+ 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:
- ComboBox *mBox;
- wxChoice *wxchoice;
+ int mTypeForm;
+ ComboBox *mBox;
+ wxItemContainer* itemcontainer;
};
//-------------------------------------------------------------------------
ComboBoxWidget::ComboBoxWidget( ComboBox* box,
- wxWindow *parent,
- int iSelection,
- std::string title,
- std::vector< std::string > lstIn )
+ wxWindow *parent,
+ int iSelection,
+ std::string title,
+ std::vector< std::string > lstIn,
+ int typeForm,
+ int sizeX,
+ int sizeY
+ )
:
- wxPanel( parent, -1) ,
- mBox(box)
+ wxPanel( parent, -1,wxDefaultPosition,wxSize(sizeX,sizeY) ) ,
+ mBox(box),
+ mTypeForm(typeForm)
{
- wxPanel *panel = this;
-
-
-
- //---------------------------------------------------------------------
- // 1) Creation de wxChoise widget
-
- wxchoice = new wxChoice ( panel , -1 );
-
- Connect( wxchoice->GetId(), wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox );
-
- int i;
- for (i=0;i<lstIn.size(); i++)
- {
- wxchoice->Append( bbtk::std2wx( lstIn[i] ) );
- } // for i
- wxchoice->SetSelection(iSelection);
+ wxPanel *panel = this;
+ itemcontainer = NULL;
+ int i;
//---------------------------------------------------------------------
// 2) Insertion of the components in the window
{
sizer->Add( new wxStaticText(panel,-1, bbtk::std2wx(title) ) );
}
- sizer->Add( wxchoice,1,wxGROW );
sizer->AddGrowableCol(0);
panel->SetSizer(sizer);
-
-// panel->SetAutoLayout(true);
-// panel->Layout();
-
+ //---------------------------------------------------------------------
+ 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;i<lstIn.size(); i++)
+ {
+ itemcontainer->Append( bbtk::std2wx( lstIn[i] ) );
+ } // for i
+// itemcontainer->SetSelection(iSelection);
}
- //-------------------------------------------------------------------------
-
+
+ //-------------------------------------------------------------------------
ComboBoxWidget::~ComboBoxWidget()
{
}
//--------------------------------------------------------------------------
- void ComboBoxWidget::OnComboBox(wxEvent& event)
+ void ComboBoxWidget::VerifyDeselect(int iSelection)
{
+ if ((iSelection>=0) && (mBox->bbGetInputDeselect()==true) )
+ {
+ if (mTypeForm==1)
+ {
+ ((wxListBox*)itemcontainer)->Deselect( iSelection );
+ } // if mTypeForm
+ } // if iSelection
+ }
- int iSelection = wxchoice->GetSelection();
- mBox->bbSetInputSelection( iSelection );
-
- mBox->bbSetOutputOut( iSelection );
- mBox->bbSetOutputOutString( bbtk::wx2std( wxchoice->GetString(iSelection) ) );
- mBox->bbSignalOutputModification("Out");
- mBox->bbSignalOutputModification("OutString");
+ //--------------------------------------------------------------------------
+ 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;i<lstIn.size(); i++)
+ {
+ itemcontainer->Append( 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);
//=====
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)
{
-
-// bbSetOutputWidget( new wxStaticText ( parent , -1 , _T("") ) );
-// bbSetOutputWidget( new wxComboBox ( parent , -1 , _T("ups") ) );
-// bbSetOutputWidget( new wxChoice ( parent , -1 ) );
-
ComboBoxWidget *w = new ComboBoxWidget(
this,
- parent,
+ parent,
bbGetInputSelection() ,
bbGetInputTitle(),
- bbGetInputIn() );
-
+ 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)
{
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)