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);
93 FillItems( iSelection,lstIn );
95 // for (i=0;i<lstIn.size(); i++)
97 // itemcontainer->Append( bbtk::std2wx( lstIn[i] ) );
99 // itemcontainer->SetSelection(iSelection);
102 //-------------------------------------------------------------------------
103 ComboBoxWidget::~ComboBoxWidget()
107 //--------------------------------------------------------------------------
108 void ComboBoxWidget::VerifyDeselect(int iSelection)
110 if ((iSelection>=0) && (mBox->bbGetInputDeselect()==true) )
114 ((wxListBox*)itemcontainer)->Deselect( iSelection );
119 //--------------------------------------------------------------------------
120 void ComboBoxWidget::OnComboBoxSelection(int iSelection)
124 mBox->bbSetInputSelection( iSelection );
125 mBox->bbSetOutputOut( iSelection );
127 // Patch to clean the spaces at the begining
128 std::string tmpStr = bbtk::wx2std( itemcontainer->GetString(iSelection) );
129 if (tmpStr.length()>0) { while(tmpStr[0]==' ') tmpStr.erase(0,1); }
130 mBox->bbSetOutputOutString( tmpStr );
131 // mBox->bbSetOutputOutString( bbtk::wx2std( itemcontainer->GetString(iSelection) ) );
133 mBox->bbSignalOutputModification();
134 VerifyDeselect(iSelection);
137 wxChoice *wxchoise=(wxChoice *)itemcontainer;
138 wxchoise->SetToolTip( itemcontainer->GetString(iSelection) );
142 // mBox->bbSignalOutputModification("Out");
143 // mBox->bbSignalOutputModification("OutString");
147 //--------------------------------------------------------------------------
148 void ComboBoxWidget::OnComboBox(wxEvent& event)
150 OnComboBoxSelection( itemcontainer->GetSelection() );
153 //--------------------------------------------------------------------------
154 void ComboBoxWidget::FillItems( int iSelection, std::vector< std::string > lstIn )
156 int i,size=lstIn.size();
158 // Patch to put spaces at the beginin
160 // Looking for the longest string
161 for (i=0 ;i<size; i++)
163 if ( strLength < (int) lstIn[i].length() ) { strLength=lstIn[i].length(); }
165 // Adding spaces at the bigining to the others strings in the list to have the same size
167 for (i=0 ;i<size; i++)
169 len2 = strLength - lstIn[i].length();
170 for (ii=0;ii<len2;ii++)
172 lstIn[i]=" "+lstIn[i]; // 3 space characters
176 itemcontainer->Clear();
177 for (i=0;i<size; i++)
179 itemcontainer->Append( bbtk::std2wx( lstIn[i] ) );
181 if (iSelection>=0) itemcontainer->SetSelection(iSelection);
185 ((wxChoice*)itemcontainer)->SetAutoLayout( true );
186 ((wxChoice*)itemcontainer)->Layout( );
190 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ComboBox)
191 BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,bbtk::WxBlackBox);
194 // 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)
196 void ComboBox::Process()
198 int iSelection = bbGetInputSelection();
199 if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=bbGetInputIn().size()-1; }
200 // if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=0; }
201 ComboBoxWidget *w = (ComboBoxWidget*)bbGetOutputWidget();
202 w->FillItems( iSelection, bbGetInputIn() );
203 bbSetInputSelection( iSelection );
204 bbSetOutputOut( iSelection );
205 int size = bbGetInputIn().size();
206 if ( (iSelection>=0) && ( iSelection<size) )
208 bbSetOutputOutString( bbGetInputIn()[ iSelection ] );
210 w->VerifyDeselect(iSelection);
213 // 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)
215 void ComboBox::CreateWidget(wxWindow* parent)
217 ComboBoxWidget *w = new ComboBoxWidget(
220 bbGetInputSelection() ,
224 bbGetInputWinWidth(), bbGetInputWinHeight() );
225 bbSetOutputOut( bbGetInputSelection() );
226 if (bbGetInputIn().size()> bbGetInputSelection() )
228 bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
230 bbSetOutputWidget( w );
233 // 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)
235 void ComboBox::bbUserSetDefaultValues()
237 bbSetInputSelection(0);
240 bbSetInputWinWidth(10);
241 bbSetInputWinHeight(45);
242 bbSetInputDeselect(false);
245 // 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)
247 void ComboBox::bbUserInitializeProcessing()
251 // 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)
253 void ComboBox::bbUserFinalizeProcessing()