]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxComboBox.cxx
#3082 BBTK Bug New Normal - not compiling in CentOS 2.6
[bbtk.git] / packages / wx / src / bbwxComboBox.cxx
1 //===== 
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)
3 //===== 
4 #include "bbwxComboBox.h"
5 #include "bbwxPackage.h"
6
7
8 #include <vector>
9 #include <string>
10
11 #include <wx/choice.h>
12 #include <wx/control.h>
13 #include <wx/listbox.h>
14
15 namespace bbwx
16 {
17   //--------------------------------------------------------------------------
18   // The widget created by the box 
19   class ComboBoxWidget : public wxPanel
20   {
21   public:
22         ComboBoxWidget( ComboBox* box, wxWindow *parent, 
23                     int iSelection, 
24                     std::string title, 
25                     std::vector< std::string > lstIn, 
26                                         int typeForm );
27         ~ComboBoxWidget();
28         void OnComboBoxSelection(int iSelection);
29         void OnComboBox(wxEvent& event);
30         void FillItems( int iSelection, std::vector< std::string > lstIn);
31
32   private:
33     int                         mTypeForm;
34     ComboBox            *mBox;
35         wxListBox               *wxlistbox;
36         wxChoice                *wxchoice;
37   };
38   
39
40
41   //------------------------------------------------------------------------
42   //------------------------------------------------------------------------
43   //------------------------------------------------------------------------
44
45   //-------------------------------------------------------------------------
46   ComboBoxWidget::ComboBoxWidget( ComboBox* box,
47                wxWindow *parent,
48                int iSelection,
49                std::string title,
50                std::vector< std::string > lstIn,
51                                         int typeForm)
52     :
53     wxPanel( parent, -1) ,
54     mBox(box),
55     mTypeForm(typeForm)
56   {
57         wxPanel         *panel          = this;
58         wxlistbox                               = NULL;
59         wxchoice                                = NULL;
60         int i;
61
62     //---------------------------------------------------------------------
63     // 2) Insertion of the components in the window
64     
65     // We use a FlexGridSizer
66     wxFlexGridSizer *sizer      = new wxFlexGridSizer(1);
67     if (title!="")
68     {
69            sizer->Add( new wxStaticText(panel,-1,  bbtk::std2wx(title) ) ); 
70     }
71     sizer->AddGrowableCol(0);
72     panel->SetSizer(sizer);
73                 
74     //---------------------------------------------------------------------
75     // 1) Creation de wxChoise widget
76
77                 if (mTypeForm==1)
78                 {
79
80                         wxlistbox = new wxListBox ( panel , -1 );                       
81                         Connect( wxlistbox->GetId(), wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); 
82                 for (i=0;i<lstIn.size(); i++)
83                 {
84                                 wxlistbox->Append(  bbtk::std2wx( lstIn[i] )  ); 
85                         } // for i
86                 wxlistbox->SetSelection(iSelection);
87                    sizer->Add( wxlistbox,1,wxGROW ); 
88
89                 } else {
90
91                         wxchoice = new wxChoice ( panel , -1 );
92                         Connect( wxchoice->GetId(), wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); 
93                 for (i=0;i<lstIn.size(); i++)
94                 {
95                                 wxchoice->Append(  bbtk::std2wx( lstIn[i] )  ); 
96                         } // for i
97                 wxchoice->SetSelection(iSelection);
98                    sizer->Add( wxchoice,1,wxGROW ); 
99                 }
100 //    panel->SetAutoLayout(true);
101 //    panel->Layout();
102   }
103   //-------------------------------------------------------------------------
104   
105   ComboBoxWidget::~ComboBoxWidget()
106   {
107   }
108
109
110   //--------------------------------------------------------------------------
111   void ComboBoxWidget::OnComboBoxSelection(int iSelection)
112   {
113     mBox->bbSetInputSelection( iSelection );
114     mBox->bbSetOutputOut( iSelection );
115     mBox->bbSetOutputOutString(    bbtk::wx2std( wxchoice->GetString(iSelection) )     );
116     mBox->bbSignalOutputModification("Out");
117     mBox->bbSignalOutputModification("OutString");
118   }
119
120   //--------------------------------------------------------------------------
121   void ComboBoxWidget::OnComboBox(wxEvent& event)
122   {
123          int iSelection;
124          if (mTypeForm==1)
125          {
126                  iSelection = wxlistbox->GetSelection();
127          } else {
128                  iSelection = wxchoice->GetSelection();
129          }
130          OnComboBoxSelection(iSelection);
131   }
132 //--------------------------------------------------------------------------
133   void ComboBoxWidget::FillItems(
134                int iSelection,
135                std::vector< std::string > lstIn
136         )
137         {
138                 int i;
139                 if (mTypeForm==1)
140                 {
141                         wxlistbox->Clear();
142
143                 for (i=0;i<lstIn.size(); i++)
144                 {
145                                 wxlistbox->Append(  bbtk::std2wx( lstIn[i] )  ); 
146                         } // for i
147
148                 wxlistbox->SetSelection(iSelection);
149                 } else {
150                         wxchoice->Clear();
151                 for (i=0;i<lstIn.size(); i++)
152                 {
153                                 wxchoice->Append(  bbtk::std2wx( lstIn[i] )  ); 
154                         } // for i
155                 wxchoice->SetSelection(iSelection);
156                 } // if
157         } 
158
159 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ComboBox)
160 BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,bbtk::WxBlackBox);
161 //===== 
162 // 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)
163 //===== 
164 void ComboBox::Process()
165 {
166         int iSelection = bbGetInputSelection();
167         if (bbGetInputSelection() >= bbGetInputIn().size()) { iSelection=bbGetInputIn().size()-1; }
168         ComboBoxWidget *w = (ComboBoxWidget*)bbGetOutputWidget();
169         w->FillItems( iSelection, bbGetInputIn() );
170     bbSetInputSelection( iSelection );
171     bbSetOutputOut( iSelection );
172
173     int size = bbGetInputIn().size();
174     if  (  (iSelection>0) && ( (size-1)<=iSelection) ) 
175     { 
176        bbSetOutputOutString( bbGetInputIn()[ iSelection ] );
177     }
178 //    bbSignalOutputModification("Out");
179 //    bbSignalOutputModification("OutString");
180 }
181
182 //===== 
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)
184 //===== 
185 void ComboBox::CreateWidget(wxWindow* parent)
186 {
187
188 //   bbSetOutputWidget( new wxStaticText ( parent , -1 , _T("") ) );
189 //   bbSetOutputWidget( new wxComboBox ( parent , -1 , _T("ups") ) );  
190 //   bbSetOutputWidget( new wxChoice ( parent , -1 ) );  
191
192     ComboBoxWidget *w = new ComboBoxWidget(
193                                 this,
194                                                         parent,
195                                 bbGetInputSelection() ,
196                                 bbGetInputTitle(),
197                                 bbGetInputIn(),
198                                 bbGetInputForm() );
199
200    bbSetOutputOut( bbGetInputSelection() );
201    bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
202    bbSetOutputWidget( w );
203
204
205 }
206 //===== 
207 // 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)
208 //===== 
209 void ComboBox::bbUserSetDefaultValues()
210 {
211         bbSetInputSelection(0);
212         bbSetInputTitle("");
213         bbSetInputForm(0);
214 }
215 //===== 
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)
217 //===== 
218 void ComboBox::bbUserInitializeProcessing()
219 {
220
221 }
222 //===== 
223 // 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)
224 //===== 
225 void ComboBox::bbUserFinalizeProcessing()
226 {
227
228 }
229 }
230 // EO namespace bbwx
231
232