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 ) ,
62 wxPanel *panel = this;
64 //---------------------------------------------------------------------
65 // 2) Insertion of the components in the window
67 // We use a FlexGridSizer
68 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
71 sizer->Add( new wxStaticText(panel,-1, bbtk::std2wx(title) ) );
73 //---------------------------------------------------------------------
76 wxListBox *wxlistbox = new wxListBox ( panel , -1 , wxDefaultPosition,wxSize(sizeX,sizeY),0, NULL, wxLB_SINGLE );
77 itemcontainer=wxlistbox;
78 sizer->Add( wxlistbox,1,wxEXPAND );
79 Connect( wxlistbox->GetId(),
80 wxEVT_COMMAND_LISTBOX_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox );
81 } else if (mTypeForm==0) {
82 wxChoice *wxchoice = new wxChoice ( panel , -1, wxDefaultPosition,wxSize(sizeX,sizeY));
83 itemcontainer=wxchoice;
84 sizer->Add( wxchoice,1,wxGROW );
85 Connect( wxchoice->GetId(),
86 wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox );
88 sizer->AddGrowableCol(0);
89 panel->SetSizer(sizer);
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();
124 VerifyDeselect(iSelection);
127 wxChoice *wxchoise=(wxChoice *)itemcontainer;
128 wxchoise->SetToolTip( itemcontainer->GetString(iSelection) );
132 // mBox->bbSignalOutputModification("Out");
133 // mBox->bbSignalOutputModification("OutString");
137 //--------------------------------------------------------------------------
138 void ComboBoxWidget::OnComboBox(wxEvent& event)
140 OnComboBoxSelection( itemcontainer->GetSelection() );
143 //--------------------------------------------------------------------------
144 void ComboBoxWidget::FillItems( int iSelection, std::vector< std::string > lstIn )
147 itemcontainer->Clear();
148 for (i=0;i<lstIn.size(); i++)
150 itemcontainer->Append( bbtk::std2wx( lstIn[i] ) );
152 if (iSelection>=0) itemcontainer->SetSelection(iSelection);
155 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ComboBox)
156 BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,bbtk::WxBlackBox);
159 // 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)
161 void ComboBox::Process()
163 int iSelection = bbGetInputSelection();
164 if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=bbGetInputIn().size()-1; }
165 // if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=0; }
166 ComboBoxWidget *w = (ComboBoxWidget*)bbGetOutputWidget();
167 w->FillItems( iSelection, bbGetInputIn() );
168 bbSetInputSelection( iSelection );
169 bbSetOutputOut( iSelection );
170 int size = bbGetInputIn().size();
171 if ( (iSelection>=0) && ( iSelection<size) )
173 bbSetOutputOutString( bbGetInputIn()[ iSelection ] );
175 w->VerifyDeselect(iSelection);
178 // 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)
180 void ComboBox::CreateWidget(wxWindow* parent)
182 ComboBoxWidget *w = new ComboBoxWidget(
185 bbGetInputSelection() ,
189 bbGetInputWinWidth(), bbGetInputWinHeight() );
190 bbSetOutputOut( bbGetInputSelection() );
191 if (bbGetInputIn().size()> bbGetInputSelection() )
193 bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
195 bbSetOutputWidget( w );
198 // 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)
200 void ComboBox::bbUserSetDefaultValues()
202 bbSetInputSelection(0);
205 bbSetInputWinWidth(10);
206 bbSetInputWinHeight(45);
207 bbSetInputDeselect(false);
210 // 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)
212 void ComboBox::bbUserInitializeProcessing()
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::bbUserFinalizeProcessing()