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();
160 // Patch to put spaces at the beginin
162 // Patch to put spaces at the beginin
164 // Looking for the longest string
165 for (i=0 ;i<size; i++)
167 if ( strLength < (int) lstIn[i].length() ) { strLength=lstIn[i].length(); }
169 // Adding spaces at the bigining to the others strings in the list to have the same size
171 for (i=0 ;i<size; i++)
173 len2 = strLength - lstIn[i].length();
174 for (ii=0;ii<len2;ii++)
176 lstIn[i]=" "+lstIn[i]; // spaces characters
179 #endif // defined(_WIN32)
181 itemcontainer->Clear();
182 for (i=0;i<size; i++)
184 itemcontainer->Append( bbtk::std2wx( lstIn[i] ) );
186 if (iSelection>=0) itemcontainer->SetSelection(iSelection);
190 ((wxChoice*)itemcontainer)->SetAutoLayout( true );
191 ((wxChoice*)itemcontainer)->Layout( );
195 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ComboBox)
196 BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,bbtk::WxBlackBox);
199 // 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)
201 void ComboBox::Process()
203 int iSelection = bbGetInputSelection();
204 if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=bbGetInputIn().size()-1; }
205 // if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=0; }
206 ComboBoxWidget *w = (ComboBoxWidget*)bbGetOutputWidget();
207 w->FillItems( iSelection, bbGetInputIn() );
208 bbSetInputSelection( iSelection );
209 bbSetOutputOut( iSelection );
210 int size = bbGetInputIn().size();
211 if ( (iSelection>=0) && ( iSelection<size) )
213 bbSetOutputOutString( bbGetInputIn()[ iSelection ] );
215 w->VerifyDeselect(iSelection);
218 // 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)
220 void ComboBox::CreateWidget(wxWindow* parent)
222 ComboBoxWidget *w = new ComboBoxWidget(
225 bbGetInputSelection() ,
229 bbGetInputWinWidth(), bbGetInputWinHeight() );
230 bbSetOutputOut( bbGetInputSelection() );
231 if (bbGetInputIn().size()> bbGetInputSelection() )
233 bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
235 bbSetOutputWidget( w );
238 // 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)
240 void ComboBox::bbUserSetDefaultValues()
242 bbSetInputSelection(0);
245 bbSetInputWinWidth(10);
246 bbSetInputWinHeight(45);
247 bbSetInputDeselect(false);
250 // 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)
252 void ComboBox::bbUserInitializeProcessing()
256 // 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)
258 void ComboBox::bbUserFinalizeProcessing()