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 ) ,
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 //---------------------------------------------------------------------
77 wxListBox *wxlistbox = new wxListBox ( panel , -1 , wxDefaultPosition,wxSize(sizeX,sizeY),0, NULL, wxLB_SINGLE );
78 itemcontainer=wxlistbox;
79 sizer->Add( wxlistbox,1,wxEXPAND );
80 Connect( wxlistbox->GetId(),
81 wxEVT_COMMAND_LISTBOX_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox );
82 } else if (mTypeForm==0) {
83 wxChoice *wxchoice = new wxChoice ( panel , -1, wxDefaultPosition,wxSize(sizeX,sizeY));
84 itemcontainer=wxchoice;
85 sizer->Add( wxchoice,1,wxEXPAND );
87 Connect( wxchoice->GetId(),
88 wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox );
90 sizer->AddGrowableCol(0);
91 panel->SetSizer(sizer);
93 for (i=0;i<lstIn.size(); i++)
95 itemcontainer->Append( bbtk::std2wx( lstIn[i] ) );
97 // itemcontainer->SetSelection(iSelection);
100 //-------------------------------------------------------------------------
101 ComboBoxWidget::~ComboBoxWidget()
105 //--------------------------------------------------------------------------
106 void ComboBoxWidget::VerifyDeselect(int iSelection)
108 if ((iSelection>=0) && (mBox->bbGetInputDeselect()==true) )
112 ((wxListBox*)itemcontainer)->Deselect( iSelection );
117 //--------------------------------------------------------------------------
118 void ComboBoxWidget::OnComboBoxSelection(int iSelection)
122 mBox->bbSetInputSelection( iSelection );
123 mBox->bbSetOutputOut( iSelection );
124 mBox->bbSetOutputOutString( bbtk::wx2std( itemcontainer->GetString(iSelection) ) );
125 mBox->bbSignalOutputModification();
127 VerifyDeselect(iSelection);
129 // mBox->bbSignalOutputModification("Out");
130 // mBox->bbSignalOutputModification("OutString");
134 //--------------------------------------------------------------------------
135 void ComboBoxWidget::OnComboBox(wxEvent& event)
137 OnComboBoxSelection( itemcontainer->GetSelection() );
139 //--------------------------------------------------------------------------
140 void ComboBoxWidget::FillItems( int iSelection, std::vector< std::string > lstIn )
143 itemcontainer->Clear();
144 for (i=0;i<lstIn.size(); i++)
146 itemcontainer->Append( bbtk::std2wx( lstIn[i] ) );
148 if (iSelection>=0) itemcontainer->SetSelection(iSelection);
151 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ComboBox)
152 BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,bbtk::WxBlackBox);
154 // 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)
156 void ComboBox::Process()
158 int iSelection = bbGetInputSelection();
159 if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=bbGetInputIn().size()-1; }
160 ComboBoxWidget *w = (ComboBoxWidget*)bbGetOutputWidget();
161 w->FillItems( iSelection, bbGetInputIn() );
162 bbSetInputSelection( iSelection );
163 bbSetOutputOut( iSelection );
164 int size = bbGetInputIn().size();
165 if ( (iSelection>0) && ( (size-1)<=iSelection) )
167 bbSetOutputOutString( bbGetInputIn()[ iSelection ] );
170 w->VerifyDeselect(iSelection);
173 // 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)
175 void ComboBox::CreateWidget(wxWindow* parent)
177 ComboBoxWidget *w = new ComboBoxWidget(
180 bbGetInputSelection() ,
184 bbGetInputWinWidth(), bbGetInputWinHeight() );
185 bbSetOutputOut( bbGetInputSelection() );
186 bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
187 bbSetOutputWidget( w );
190 // 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)
192 void ComboBox::bbUserSetDefaultValues()
194 bbSetInputSelection(0);
197 bbSetInputWinWidth(100);
198 bbSetInputWinHeight(200);
199 bbSetInputDeselect(false);
202 // 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)
204 void ComboBox::bbUserInitializeProcessing()
208 // 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)
210 void ComboBox::bbUserFinalizeProcessing()