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>
15 #include <wx/spinbutt.h>
19 //--------------------------------------------------------------------------
20 // The widget created by the box
21 class ComboBoxWidget : public wxPanel
24 ComboBoxWidget( ComboBox* box, wxWindow *parent,
27 std::vector< std::string > lstIn,
29 int sizeX, int sizeY );
31 void OnComboBoxSelection(int iSelection);
32 void OnComboBox(wxEvent& event);
33 void FillItems( int iSelection, std::vector< std::string > lstIn);
34 void VerifyDeselect(int iSelection);
36 void OnSpinCtrlClick(wxCommandEvent& event);
42 wxItemContainer *itemcontainer;
43 wxSpinButton *mwxspinbutton;
48 //------------------------------------------------------------------------
49 //------------------------------------------------------------------------
50 //------------------------------------------------------------------------
52 //-------------------------------------------------------------------------
53 ComboBoxWidget::ComboBoxWidget( ComboBox* box,
57 std::vector< std::string > lstIn,
63 wxPanel( parent, -1,wxDefaultPosition ) ,
69 wxPanel *panel = this;
71 //---------------------------------------------------------------------
72 // 2) Insertion of the components in the window
74 // We use a FlexGridSizer
75 wxFlexGridSizer *sizer = new wxFlexGridSizer(2);
78 sizer->Add( new wxStaticText(panel,-1, bbtk::std2wx(title) ) );
80 //---------------------------------------------------------------------
83 wxListBox *wxlistbox = new wxListBox ( panel , -1 , wxDefaultPosition,wxSize(sizeX,sizeY),0, NULL, wxLB_SINGLE );
84 itemcontainer=wxlistbox;
85 sizer->Add( wxlistbox,1,wxEXPAND );
86 Connect( wxlistbox->GetId(),
87 wxEVT_COMMAND_LISTBOX_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox );
88 } else if (mTypeForm==0) {
89 wxChoice *wxchoice = new wxChoice ( panel , -1, wxDefaultPosition,wxSize(sizeX,sizeY));
90 itemcontainer=wxchoice;
91 sizer->Add( wxchoice,1,wxGROW );
92 Connect( wxchoice->GetId(),
93 wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox );
96 if (mBox->bbGetInputWithSpinButton()==true)
98 mwxspinbutton = new wxSpinButton( panel, -1 );
99 Connect( mwxspinbutton->GetId(),
101 (wxObjectEventFunction)
102 (void (wxPanel::*)(wxScrollEvent&))
103 &ComboBoxWidget::OnSpinCtrlClick);
105 sizer->Add( mwxspinbutton,1,wxEXPAND );
108 sizer->AddGrowableCol(0);
109 panel->SetSizer(sizer);
110 FillItems( iSelection,lstIn );
112 // for (i=0;i<lstIn.size(); i++)
114 // itemcontainer->Append( bbtk::std2wx( lstIn[i] ) );
116 // itemcontainer->SetSelection(iSelection);
119 //-------------------------------------------------------------------------
120 ComboBoxWidget::~ComboBoxWidget()
124 //--------------------------------------------------------------------------
125 void ComboBoxWidget::VerifyDeselect(int iSelection)
127 if ((iSelection>=0) && (mBox->bbGetInputDeselect()==true) )
131 ((wxListBox*)itemcontainer)->Deselect( iSelection );
136 //--------------------------------------------------------------------------
137 void ComboBoxWidget::OnComboBoxSelection(int iSelection)
141 mBox->bbSetInputSelection( iSelection );
142 mBox->bbSetOutputOut( iSelection );
144 // Patch to clean the spaces at the begining
145 std::string tmpStr = bbtk::wx2std( itemcontainer->GetString(iSelection) );
146 if (tmpStr.length()>0) { while(tmpStr[0]==' ') tmpStr.erase(0,1); }
147 mBox->bbSetOutputOutString( tmpStr );
148 // mBox->bbSetOutputOutString( bbtk::wx2std( itemcontainer->GetString(iSelection) ) );
150 mBox->bbSignalOutputModification();
151 VerifyDeselect(iSelection);
154 wxChoice *wxchoise=(wxChoice *)itemcontainer;
155 wxchoise->SetToolTip( itemcontainer->GetString(iSelection) );
159 // mBox->bbSignalOutputModification("Out");
160 // mBox->bbSignalOutputModification("OutString");
164 //--------------------------------------------------------------------------
165 void ComboBoxWidget::OnComboBox(wxEvent& event)
167 int iSelection = itemcontainer->GetSelection();
168 OnComboBoxSelection( iSelection );
169 if (mBox->bbGetInputWithSpinButton()==true)
171 mwxspinbutton->SetValue( iSelection );
176 //--------------------------------------------------------------------------
177 void ComboBoxWidget::OnSpinCtrlClick(wxCommandEvent& event)
179 int iSelection = mwxspinbutton->GetValue();
180 printf("EED ComboBoxWidget::OnSpinCtrlClick %d\n", iSelection );
181 itemcontainer->SetSelection(iSelection);
182 OnComboBoxSelection( iSelection );
185 if (mBox->bbGetInputType()==0)
187 mBox->bbSetOutputOut( mwxSpinCtrl->GetValue() );
189 mBox->bbSetOutputOut( mwxSpinButton->GetValue() );
192 // and signal that the output has changed
193 //if(_reactiveOnKeyStroke==1){
194 mBox->bbSignalOutputModification(std::string("Out"));
200 //--------------------------------------------------------------------------
201 void ComboBoxWidget::FillItems( int iSelection, std::vector< std::string > lstIn )
203 int i,size=lstIn.size();
207 // Patch to put spaces at the beginin
209 // Patch to put spaces at the beginin
211 // Looking for the longest string
212 for (i=0 ;i<size; i++)
214 if ( strLength < (int) lstIn[i].length() ) { strLength=lstIn[i].length(); }
216 // Adding spaces at the bigining to the others strings in the list to have the same size
218 for (i=0 ;i<size; i++)
220 len2 = strLength - lstIn[i].length();
221 for (ii=0;ii<len2;ii++)
223 lstIn[i]=" "+lstIn[i]; // spaces characters
226 #endif // defined(_WIN32)
228 itemcontainer->Clear();
229 for (i=0;i<size; i++)
231 itemcontainer->Append( bbtk::std2wx( lstIn[i] ) );
235 itemcontainer->SetSelection(iSelection);
236 if (mBox->bbGetInputWithSpinButton()==true)
238 mwxspinbutton->SetRange( 0,size-1 );
239 mwxspinbutton->SetValue( iSelection );
246 ((wxChoice*)itemcontainer)->SetAutoLayout( true );
247 ((wxChoice*)itemcontainer)->Layout( );
251 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ComboBox)
252 BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,bbtk::WxBlackBox);
255 // 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)
257 void ComboBox::Process()
259 int iSelection = bbGetInputSelection();
260 if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=bbGetInputIn().size()-1; }
261 // if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=0; }
262 ComboBoxWidget *w = (ComboBoxWidget*)bbGetOutputWidget();
263 w->FillItems( iSelection, bbGetInputIn() );
264 bbSetInputSelection( iSelection );
265 bbSetOutputOut( iSelection );
266 int size = bbGetInputIn().size();
267 if ( (iSelection>=0) && ( iSelection<size) )
269 bbSetOutputOutString( bbGetInputIn()[ iSelection ] );
271 w->VerifyDeselect(iSelection);
274 // 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)
276 void ComboBox::CreateWidget(wxWindow* parent)
278 ComboBoxWidget *w = new ComboBoxWidget(
281 bbGetInputSelection() ,
285 bbGetInputWinWidth(), bbGetInputWinHeight() );
286 bbSetOutputOut( bbGetInputSelection() );
287 if (bbGetInputIn().size()> bbGetInputSelection() )
289 bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
291 bbSetOutputWidget( w );
294 // 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)
296 void ComboBox::bbUserSetDefaultValues()
298 bbSetInputSelection(0);
301 bbSetInputWinWidth(10);
302 bbSetInputWinHeight(45);
303 bbSetInputDeselect(false);
304 bbSetInputWithSpinButton(false);
307 // 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)
309 void ComboBox::bbUserInitializeProcessing()
313 // 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)
315 void ComboBox::bbUserFinalizeProcessing()