]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxComboBox.cxx
#3043 BBTK Bug New Normal - FilesFromDirectoryBox missing directories AND Refresh...
[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 OnComboBox(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::OnComboBox(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          OnComboBox(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     bbSetOutputOutString( bbGetInputIn()[ iSelection ] );
173 //    bbSignalOutputModification("Out");
174 //    bbSignalOutputModification("OutString");
175
176 }
177
178 //===== 
179 // 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)
180 //===== 
181 void ComboBox::CreateWidget(wxWindow* parent)
182 {
183
184 //   bbSetOutputWidget( new wxStaticText ( parent , -1 , _T("") ) );
185 //   bbSetOutputWidget( new wxComboBox ( parent , -1 , _T("ups") ) );  
186 //   bbSetOutputWidget( new wxChoice ( parent , -1 ) );  
187
188     ComboBoxWidget *w = new ComboBoxWidget(
189                                 this,
190                                                         parent,
191                                 bbGetInputSelection() ,
192                                 bbGetInputTitle(),
193                                 bbGetInputIn(),
194                                 bbGetInputForm() );
195
196    bbSetOutputOut( bbGetInputSelection() );
197    bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
198    bbSetOutputWidget( w );
199
200
201 }
202 //===== 
203 // 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)
204 //===== 
205 void ComboBox::bbUserSetDefaultValues()
206 {
207         bbSetInputSelection(0);
208         bbSetInputTitle("");
209         bbSetInputForm(0);
210 }
211 //===== 
212 // 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)
213 //===== 
214 void ComboBox::bbUserInitializeProcessing()
215 {
216
217 }
218 //===== 
219 // 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 //===== 
221 void ComboBox::bbUserFinalizeProcessing()
222 {
223
224 }
225 }
226 // EO namespace bbwx
227
228