]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxComboBox.cxx
e76d44f4d54443769211b03cf167c709b15d7eae
[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
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
64     //---------------------------------------------------------------------
65     // 2) Insertion of the components in the window
66     
67     // We use a FlexGridSizer
68     wxFlexGridSizer *sizer      = new wxFlexGridSizer(1);
69     if (title!="")
70     {
71            sizer->Add( new wxStaticText(panel,-1,  bbtk::std2wx(title) ) ); 
72     }
73     sizer->AddGrowableCol(0);
74     panel->SetSizer(sizer);
75
76    
77     //---------------------------------------------------------------------
78     // 1) Creation de wxChoise widget
79
80                 if (mTypeForm==1)
81                 {
82
83                         wxlistbox = new wxListBox ( panel , -1 );                       
84                         Connect( wxlistbox->GetId(), wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); 
85                 for (i=0;i<lstIn.size(); i++)
86                 {
87                         wxlistbox->Append(  bbtk::std2wx( lstIn[i] )  ); 
88                         } // for i
89                 wxlistbox->SetSelection(iSelection);
90                    sizer->Add( wxlistbox,1,wxGROW ); 
91
92                 } else {
93
94                         wxchoice = new wxChoice ( panel , -1 );
95                         Connect( wxchoice->GetId(), wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); 
96                 for (i=0;i<lstIn.size(); i++)
97                 {
98                         wxchoice->Append(  bbtk::std2wx( lstIn[i] )  ); 
99                         } // for i
100                 wxchoice->SetSelection(iSelection);
101                    sizer->Add( wxchoice,1,wxGROW ); 
102                 }
103
104
105 //    panel->SetAutoLayout(true);
106 //    panel->Layout();
107
108   }
109   //-------------------------------------------------------------------------
110   
111   ComboBoxWidget::~ComboBoxWidget()
112   {
113   }
114
115   //--------------------------------------------------------------------------
116   void ComboBoxWidget::OnComboBox(wxEvent& event)
117   {
118          int iSelection;
119          if (mTypeForm==1)
120          {
121                  iSelection = wxlistbox->GetSelection();
122          } else {
123                  iSelection = wxchoice->GetSelection();
124          }
125
126     mBox->bbSetInputSelection( iSelection );
127     mBox->bbSetOutputOut( iSelection );
128     mBox->bbSetOutputOutString(    bbtk::wx2std( wxchoice->GetString(iSelection) )     );
129     mBox->bbSignalOutputModification("Out");
130     mBox->bbSignalOutputModification("OutString");
131   }
132
133
134 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ComboBox)
135 BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,bbtk::WxBlackBox);
136 //===== 
137 // 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)
138 //===== 
139 void ComboBox::Process()
140 {
141 }
142 //===== 
143 // 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)
144 //===== 
145 void ComboBox::CreateWidget(wxWindow* parent)
146 {
147
148 //   bbSetOutputWidget( new wxStaticText ( parent , -1 , _T("") ) );
149 //   bbSetOutputWidget( new wxComboBox ( parent , -1 , _T("ups") ) );  
150 //   bbSetOutputWidget( new wxChoice ( parent , -1 ) );  
151
152     ComboBoxWidget *w = new ComboBoxWidget(
153                                 this,
154                                                                         parent,
155                                 bbGetInputSelection() ,
156                                 bbGetInputTitle(),
157                                 bbGetInputIn(),
158                                 bbGetInputForm() );
159
160    bbSetOutputOut( bbGetInputSelection() );
161    bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
162    bbSetOutputWidget( w );
163
164
165 }
166 //===== 
167 // 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)
168 //===== 
169 void ComboBox::bbUserSetDefaultValues()
170 {
171         bbSetInputSelection(0);
172         bbSetInputTitle("");
173         bbSetInputForm(0);
174 }
175 //===== 
176 // 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)
177 //===== 
178 void ComboBox::bbUserInitializeProcessing()
179 {
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::bbUserFinalizeProcessing()
186 {
187
188 }
189 }
190 // EO namespace bbwx
191
192