2 // 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)
4 #include "bbwxComboBox.h"
5 #include "bbwxPackage.h"
11 #include <wx/choice.h>
12 #include <wx/control.h>
13 #include <wx/listbox.h>
17 //--------------------------------------------------------------------------
18 // The widget created by the box
19 class ComboBoxWidget : public wxPanel
22 ComboBoxWidget( ComboBox* box, wxWindow *parent,
25 std::vector< std::string > lstIn,
28 void OnComboBoxSelection(int iSelection);
29 void OnComboBox(wxEvent& event);
30 void FillItems( int iSelection, std::vector< std::string > lstIn);
41 //------------------------------------------------------------------------
42 //------------------------------------------------------------------------
43 //------------------------------------------------------------------------
45 //-------------------------------------------------------------------------
46 ComboBoxWidget::ComboBoxWidget( ComboBox* box,
50 std::vector< std::string > lstIn,
53 wxPanel( parent, -1) ,
57 wxPanel *panel = this;
62 //---------------------------------------------------------------------
63 // 2) Insertion of the components in the window
65 // We use a FlexGridSizer
66 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
69 sizer->Add( new wxStaticText(panel,-1, bbtk::std2wx(title) ) );
71 sizer->AddGrowableCol(0);
72 panel->SetSizer(sizer);
74 //---------------------------------------------------------------------
75 // 1) Creation de wxChoise widget
80 wxlistbox = new wxListBox ( panel , -1 );
81 Connect( wxlistbox->GetId(), wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox );
82 for (i=0;i<lstIn.size(); i++)
84 wxlistbox->Append( bbtk::std2wx( lstIn[i] ) );
86 wxlistbox->SetSelection(iSelection);
87 sizer->Add( wxlistbox,1,wxGROW );
91 wxchoice = new wxChoice ( panel , -1 );
92 Connect( wxchoice->GetId(), wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox );
93 for (i=0;i<lstIn.size(); i++)
95 wxchoice->Append( bbtk::std2wx( lstIn[i] ) );
97 wxchoice->SetSelection(iSelection);
98 sizer->Add( wxchoice,1,wxGROW );
100 // panel->SetAutoLayout(true);
103 //-------------------------------------------------------------------------
105 ComboBoxWidget::~ComboBoxWidget()
110 //--------------------------------------------------------------------------
111 void ComboBoxWidget::OnComboBoxSelection(int iSelection)
113 mBox->bbSetInputSelection( iSelection );
114 mBox->bbSetOutputOut( iSelection );
115 mBox->bbSetOutputOutString( bbtk::wx2std( wxchoice->GetString(iSelection) ) );
116 mBox->bbSignalOutputModification("Out");
117 mBox->bbSignalOutputModification("OutString");
120 //--------------------------------------------------------------------------
121 void ComboBoxWidget::OnComboBox(wxEvent& event)
126 iSelection = wxlistbox->GetSelection();
128 iSelection = wxchoice->GetSelection();
130 OnComboBoxSelection(iSelection);
132 //--------------------------------------------------------------------------
133 void ComboBoxWidget::FillItems(
135 std::vector< std::string > lstIn
143 for (i=0;i<lstIn.size(); i++)
145 wxlistbox->Append( bbtk::std2wx( lstIn[i] ) );
148 wxlistbox->SetSelection(iSelection);
151 for (i=0;i<lstIn.size(); i++)
153 wxchoice->Append( bbtk::std2wx( lstIn[i] ) );
155 wxchoice->SetSelection(iSelection);
159 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ComboBox)
160 BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,bbtk::WxBlackBox);
162 // 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)
164 void ComboBox::Process()
166 int iSelection = bbGetInputSelection();
167 if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=bbGetInputIn().size()-1; }
168 ComboBoxWidget *w = (ComboBoxWidget*)bbGetOutputWidget();
169 w->FillItems( iSelection, bbGetInputIn() );
170 bbSetInputSelection( iSelection );
171 bbSetOutputOut( iSelection );
173 int size = bbGetInputIn().size();
174 if ( (iSelection>0) && ( (size-1)<=iSelection) )
176 bbSetOutputOutString( bbGetInputIn()[ iSelection ] );
178 // bbSignalOutputModification("Out");
179 // bbSignalOutputModification("OutString");
183 // 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)
185 void ComboBox::CreateWidget(wxWindow* parent)
188 // bbSetOutputWidget( new wxStaticText ( parent , -1 , _T("") ) );
189 // bbSetOutputWidget( new wxComboBox ( parent , -1 , _T("ups") ) );
190 // bbSetOutputWidget( new wxChoice ( parent , -1 ) );
192 ComboBoxWidget *w = new ComboBoxWidget(
195 bbGetInputSelection() ,
200 bbSetOutputOut( bbGetInputSelection() );
201 bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
202 bbSetOutputWidget( w );
207 // 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)
209 void ComboBox::bbUserSetDefaultValues()
211 bbSetInputSelection(0);
216 // 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)
218 void ComboBox::bbUserInitializeProcessing()
223 // 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)
225 void ComboBox::bbUserFinalizeProcessing()