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);
36 wxItemContainer* itemcontainer;
41 //------------------------------------------------------------------------
42 //------------------------------------------------------------------------
43 //------------------------------------------------------------------------
45 //-------------------------------------------------------------------------
46 ComboBoxWidget::ComboBoxWidget( ComboBox* box,
50 std::vector< std::string > lstIn,
56 wxPanel( parent, -1) ,
60 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 sizer->AddGrowableCol(0);
74 panel->SetSizer(sizer);
75 //---------------------------------------------------------------------
78 wxListBox *wxlistbox = new wxListBox ( panel , -1 , wxDefaultPosition,wxSize(sizeX,sizeY),0, NULL, wxLB_SINGLE );
79 itemcontainer=wxlistbox;
80 sizer->Add( wxlistbox,1,wxEXPAND );
81 Connect( wxlistbox->GetId(),
82 wxEVT_COMMAND_LISTBOX_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox );
83 } else if (mTypeForm==0) {
84 wxChoice *wxchoice = new wxChoice ( panel , -1 );
85 itemcontainer=wxchoice;
86 sizer->Add( wxchoice,1,wxGROW );
87 Connect( wxchoice->GetId(),
88 wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox );
90 for (i=0;i<lstIn.size(); i++)
92 itemcontainer->Append( bbtk::std2wx( lstIn[i] ) );
94 itemcontainer->SetSelection(iSelection);
96 //-------------------------------------------------------------------------
98 ComboBoxWidget::~ComboBoxWidget()
103 //--------------------------------------------------------------------------
104 void ComboBoxWidget::OnComboBoxSelection(int iSelection)
108 mBox->bbSetInputSelection( iSelection );
109 mBox->bbSetOutputOut( iSelection );
110 mBox->bbSetOutputOutString( bbtk::wx2std( itemcontainer->GetString(iSelection) ) );
111 mBox->bbSignalOutputModification("Out");
112 mBox->bbSignalOutputModification("OutString");
116 //--------------------------------------------------------------------------
117 void ComboBoxWidget::OnComboBox(wxEvent& event)
119 OnComboBoxSelection( itemcontainer->GetSelection() );
121 //--------------------------------------------------------------------------
122 void ComboBoxWidget::FillItems( int iSelection, std::vector< std::string > lstIn )
125 itemcontainer->Clear();
126 for (i=0;i<lstIn.size(); i++)
128 itemcontainer->Append( bbtk::std2wx( lstIn[i] ) );
130 itemcontainer->SetSelection(iSelection);
133 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ComboBox)
134 BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,bbtk::WxBlackBox);
136 // 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)
138 void ComboBox::Process()
140 int iSelection = bbGetInputSelection();
141 if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=bbGetInputIn().size()-1; }
142 ComboBoxWidget *w = (ComboBoxWidget*)bbGetOutputWidget();
143 w->FillItems( iSelection, bbGetInputIn() );
144 bbSetInputSelection( iSelection );
145 bbSetOutputOut( iSelection );
147 int size = bbGetInputIn().size();
148 if ( (iSelection>0) && ( (size-1)<=iSelection) )
150 bbSetOutputOutString( bbGetInputIn()[ iSelection ] );
155 // 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)
157 void ComboBox::CreateWidget(wxWindow* parent)
159 ComboBoxWidget *w = new ComboBoxWidget(
162 bbGetInputSelection() ,
166 bbGetInputWinWidth(), bbGetInputWinHeight() );
167 bbSetOutputOut( bbGetInputSelection() );
168 bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
169 bbSetOutputWidget( w );
172 // 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)
174 void ComboBox::bbUserSetDefaultValues()
176 bbSetInputSelection(0);
179 bbSetInputWinWidth(100);
180 bbSetInputWinHeight(200);
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::bbUserInitializeProcessing()
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::bbUserFinalizeProcessing()