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