]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxComboBox.cxx
#2452 BBTK Feature New Normal - ComboBox in wx package
[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
13 namespace bbwx
14 {
15   //--------------------------------------------------------------------------
16   // The widget created by the box 
17   class ComboBoxWidget : public wxPanel
18   {
19   public:
20         ComboBoxWidget( ComboBox* box, wxWindow *parent, 
21                       int iSelection, 
22                       std::string title, 
23                       std::vector< std::string > lstIn );
24
25         ~ComboBoxWidget();
26
27         void OnComboBox(wxEvent& event);
28
29   private:
30     ComboBox      *mBox;
31          wxChoice               *wxchoice;
32   };
33   
34
35
36   //------------------------------------------------------------------------
37   //------------------------------------------------------------------------
38   //------------------------------------------------------------------------
39
40   //-------------------------------------------------------------------------
41   ComboBoxWidget::ComboBoxWidget( ComboBox* box,
42                wxWindow *parent,
43                int iSelection,
44                std::string title,
45                std::vector< std::string > lstIn )
46     :
47     wxPanel( parent, -1) ,
48     mBox(box)
49   {
50     wxPanel *panel      = this;
51
52
53     
54     //---------------------------------------------------------------------
55     // 1) Creation de wxChoise widget
56
57          wxchoice = new wxChoice ( panel , -1 );
58
59          Connect( wxchoice->GetId(), wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&))&ComboBoxWidget::OnComboBox ); 
60
61     int i;
62     for (i=0;i<lstIn.size(); i++)
63     {
64            wxchoice->Append(  bbtk::std2wx( lstIn[i] )  ); 
65          } // for i
66     wxchoice->SetSelection(iSelection);
67
68     //---------------------------------------------------------------------
69     // 2) Insertion of the components in the window
70     
71     // We use a FlexGridSizer
72     wxFlexGridSizer *sizer      = new wxFlexGridSizer(1);
73     if (title!="")
74     {
75            sizer->Add( new wxStaticText(panel,-1,  bbtk::std2wx(title) ) ); 
76     }
77     sizer->Add( wxchoice,1,wxGROW ); 
78     sizer->AddGrowableCol(0);
79     panel->SetSizer(sizer);
80
81 //    panel->SetAutoLayout(true);
82 //    panel->Layout();
83
84   }
85   //-------------------------------------------------------------------------
86   
87   ComboBoxWidget::~ComboBoxWidget()
88   {
89   }
90
91   //--------------------------------------------------------------------------
92   void ComboBoxWidget::OnComboBox(wxEvent& event)
93   {
94
95         int iSelection = wxchoice->GetSelection();
96     mBox->bbSetInputSelection( iSelection );
97
98     mBox->bbSetOutputOut( iSelection );
99     mBox->bbSetOutputOutString(    bbtk::wx2std( wxchoice->GetString(iSelection) )     );
100     mBox->bbSignalOutputModification("Out");
101     mBox->bbSignalOutputModification("OutString");
102   }
103
104
105 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ComboBox)
106 BBTK_BLACK_BOX_IMPLEMENTATION(ComboBox,bbtk::WxBlackBox);
107 //===== 
108 // 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)
109 //===== 
110 void ComboBox::Process()
111 {
112 }
113 //===== 
114 // 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)
115 //===== 
116 void ComboBox::CreateWidget(wxWindow* parent)
117 {
118
119 //   bbSetOutputWidget( new wxStaticText ( parent , -1 , _T("") ) );
120 //   bbSetOutputWidget( new wxComboBox ( parent , -1 , _T("ups") ) );  
121 //   bbSetOutputWidget( new wxChoice ( parent , -1 ) );  
122
123     ComboBoxWidget *w = new ComboBoxWidget(
124                                 this,
125                                                                         parent,
126                                 bbGetInputSelection() ,
127                                 bbGetInputTitle(),
128                                 bbGetInputIn() );
129
130    bbSetOutputOut( bbGetInputSelection() );
131    bbSetOutputOutString( bbGetInputIn()[ bbGetInputSelection() ] );
132    bbSetOutputWidget( w );
133
134
135 }
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::bbUserSetDefaultValues()
140 {
141         bbSetInputSelection(0);
142         bbSetInputTitle("");
143 }
144 //===== 
145 // 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)
146 //===== 
147 void ComboBox::bbUserInitializeProcessing()
148 {
149
150 }
151 //===== 
152 // 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)
153 //===== 
154 void ComboBox::bbUserFinalizeProcessing()
155 {
156
157 }
158 }
159 // EO namespace bbwx
160
161