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,
27 int sizeX, int sizeY );
29 void OnComboBoxSelection(int iSelection);
30 void OnComboBox(wxEvent& event);
31 void FillItems( int iSelection, std::vector< std::string > lstIn);
32 void VerifyDeselect(int iSelection);
37 wxItemContainer* itemcontainer;
42 //------------------------------------------------------------------------
43 //------------------------------------------------------------------------
44 //------------------------------------------------------------------------
46 //-------------------------------------------------------------------------
47 ComboBoxWidget::ComboBoxWidget( ComboBox* box,
51 std::vector< std::string > lstIn,
57 wxPanel( parent, -1,wxDefaultPosition,wxSize(sizeX,sizeY) ) ,
61 wxPanel *panel = this;
65 //---------------------------------------------------------------------
66 // 2) Insertion of the components in the window
68 // We use a FlexGridSizer
69 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
72 sizer->Add( new wxStaticText(panel,-1, bbtk::std2wx(title) ) );
74 sizer->AddGrowableCol(0);
75 panel->SetSizer(sizer);
76 //---------------------------------------------------------------------
79 wxListBox *wxlistbox = new wxListBox ( panel , -1 , wxDefaultPosition,wxSize(sizeX,sizeY),0, NULL, wxLB_SINGLE );
80 itemcontainer=wxlistbox;
81 sizer->Add( wxlistbox,1,wxEXPAND );
82 Connect( wxlistbox->GetId(),
83 wxEVT_COMMAND_LISTBOX_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox );
84 } else if (mTypeForm==0) {
85 wxChoice *wxchoice = new wxChoice ( panel , -1 );
86 itemcontainer=wxchoice;
87 sizer->Add( wxchoice,1,wxGROW );
88 Connect( wxchoice->GetId(),
89 wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox );
91 for (i=0;i<lstIn.size(); i++)
93 itemcontainer->Append( bbtk::std2wx( lstIn[i] ) );
95 // itemcontainer->SetSelection(iSelection);
98 //-------------------------------------------------------------------------
99 ComboBoxWidget::~ComboBoxWidget()
103 //--------------------------------------------------------------------------
104 void ComboBoxWidget::VerifyDeselect(int iSelection)
106 if ((iSelection>=0) && (mBox->bbGetInputDeselect()==true) )
110 ((wxListBox*)itemcontainer)->Deselect( iSelection );
115 //--------------------------------------------------------------------------
116 void ComboBoxWidget::OnComboBoxSelection(int iSelection)
120 mBox->bbSetInputSelection( iSelection );
121 mBox->bbSetOutputOut( iSelection );
122 mBox->bbSetOutputOutString( bbtk::wx2std( itemcontainer->GetString(iSelection) ) );
123 mBox->bbSignalOutputModification();
125 VerifyDeselect(iSelection);
127 // mBox->bbSignalOutputModification("Out");
128 // mBox->bbSignalOutputModification("OutString");
132 //--------------------------------------------------------------------------
133 void ComboBoxWidget::OnComboBox(wxEvent& event)
135 OnComboBoxSelection( itemcontainer->GetSelection() );
137 //--------------------------------------------------------------------------
138 void ComboBoxWidget::FillItems( int iSelection, std::vector< std::string > lstIn )
141 itemcontainer->Clear();
142 for (i=0;i<lstIn.size(); i++)
144 itemcontainer->Append( bbtk::std2wx( lstIn[i] ) );
146 if (iSelection>=0) itemcontainer->SetSelection(iSelection);
149 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ComboBox)
150 BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,bbtk::WxBlackBox);
152 // 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)
154 void ComboBox::Process()
156 int iSelection = bbGetInputSelection();
157 if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=bbGetInputIn().size()-1; }
158 ComboBoxWidget *w = (ComboBoxWidget*)bbGetOutputWidget();
159 w->FillItems( iSelection, bbGetInputIn() );
160 bbSetInputSelection( iSelection );
161 bbSetOutputOut( iSelection );
162 int size = bbGetInputIn().size();
163 if ( (iSelection>0) && ( (size-1)<=iSelection) )
165 bbSetOutputOutString( bbGetInputIn()[ iSelection ] );
168 w->VerifyDeselect(iSelection);
171 // 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)
173 void ComboBox::CreateWidget(wxWindow* parent)
175 ComboBoxWidget *w = new ComboBoxWidget(
178 bbGetInputSelection() ,
182 bbGetInputWinWidth(), bbGetInputWinHeight() );
183 bbSetOutputOut( bbGetInputSelection() );
184 bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
185 bbSetOutputWidget( w );
188 // 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)
190 void ComboBox::bbUserSetDefaultValues()
192 bbSetInputSelection(0);
195 bbSetInputWinWidth(100);
196 bbSetInputWinHeight(200);
197 bbSetInputDeselect(false);
200 // 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)
202 void ComboBox::bbUserInitializeProcessing()
206 // 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)
208 void ComboBox::bbUserFinalizeProcessing()